annotate dmd/ExpStatement.d @ 72:2e2a5c3f943a

reduced warnings by adding override to the methods think this also normalizes different line endings used all over the place
author Trass3r
date Sat, 28 Aug 2010 16:19:48 +0200
parents cab4c37afb89
children 43073c7c7769
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.AssertExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
17 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.DeclarationStatement;
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
19 import dmd.Util : printf;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 class ExpStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
34 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Expression e = exp ? exp.syntaxCopy() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 ExpStatement es = new ExpStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 return es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
41 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 exp.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 buf.writeByte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 if (!hgs.FLinit.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
50 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 //printf("ExpStatement::semantic() %s\n", exp->toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 exp.checkSideEffect(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 exp = exp.optimize(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (exp.op == TOK.TOKdeclaration && !isDeclarationStatement())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Statement s = new DeclarationStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 //exp = exp.optimize(isDeclarationStatement() ? WANT.WANTvalue : 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
69 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
71 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
72 printf("ExpStatement.interpret(%s)\n", exp ? exp.toChars() : "");
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
73 }
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
74 mixin(START!());
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
75 if (exp)
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
76 {
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
77 Expression e = exp.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
78 if (e is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
79 {
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
80 //printf("-ExpStatement.interpret(): %p\n", e);
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
81 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
82 }
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
83 }
cab4c37afb89 A bunch of implementations
korDen
parents: 16
diff changeset
84 return null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 BE result = BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (exp.op == TOK.TOKhalt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return BE.BEhalt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (exp.op == TOK.TOKassert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 AssertExp a = cast(AssertExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (a.e1.isBool(false)) // if it's an assert(0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 return BE.BEhalt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 if (exp.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
108 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 return exp ? exp.inlineCost(ics) : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
113 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 if (exp) printf("ExpStatement.doInline() '%s'\n", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return exp ? exp.doInline(ids) : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
121 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 printf("ExpStatement.inlineScan(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 exp = exp.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
131 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //printf("ExpStatement.toIR(), exp = %s\n", exp ? exp.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 block_appendexp(blx.curblock, exp.toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
140 }