Mercurial > projects > ddmd
annotate dmd/ExpStatement.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.ExpStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.Statement; | |
6 import dmd.AssertExp; | |
7 import dmd.Expression; | |
8 import dmd.OutBuffer; | |
9 import dmd.HdrGenState; | |
10 import dmd.Scope; | |
11 import dmd.InterState; | |
12 import dmd.InlineCostState; | |
13 import dmd.InlineDoState; | |
14 import dmd.InlineScanState; | |
15 import dmd.IRState; | |
16 import dmd.BE; | |
17 import dmd.TOK; | |
63 | 18 import dmd.GlobalExpressions; |
0 | 19 import dmd.DeclarationStatement; |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
20 import dmd.Util : printf; |
0 | 21 |
22 import dmd.backend.Blockx; | |
23 import dmd.backend.Util; | |
24 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 |
0 | 27 class ExpStatement : Statement |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 Expression exp; |
32 | |
33 this(Loc loc, Expression exp) | |
34 { | |
178 | 35 register(); |
0 | 36 super(loc); |
37 this.exp = exp; | |
38 } | |
39 | |
178 | 40 /* |
41 ~this() | |
42 { | |
43 delete exp; | |
44 } | |
45 */ | |
72 | 46 override Statement syntaxCopy() |
0 | 47 { |
48 Expression e = exp ? exp.syntaxCopy() : null; | |
49 ExpStatement es = new ExpStatement(loc, e); | |
50 return es; | |
51 } | |
52 | |
72 | 53 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 54 { |
55 if (exp) | |
56 exp.toCBuffer(buf, hgs); | |
57 buf.writeByte(';'); | |
58 if (!hgs.FLinit.init) | |
59 buf.writenl(); | |
60 } | |
61 | |
72 | 62 override Statement semantic(Scope sc) |
0 | 63 { |
64 if (exp) | |
65 { | |
66 //printf("ExpStatement::semantic() %s\n", exp->toChars()); | |
67 exp = exp.semantic(sc); | |
68 exp = resolveProperties(sc, exp); | |
69 exp.checkSideEffect(0); | |
70 exp = exp.optimize(0); | |
71 if (exp.op == TOK.TOKdeclaration && !isDeclarationStatement()) | |
72 { | |
73 Statement s = new DeclarationStatement(loc, exp); | |
74 return s; | |
75 } | |
76 //exp = exp.optimize(isDeclarationStatement() ? WANT.WANTvalue : 0); | |
77 } | |
78 return this; | |
79 } | |
80 | |
72 | 81 override Expression interpret(InterState istate) |
0 | 82 { |
79 | 83 version (LOG) |
84 { | |
63 | 85 printf("ExpStatement.interpret(%s)\n", exp ? exp.toChars() : ""); |
86 } | |
155 | 87 mixin(START); |
63 | 88 if (exp) |
89 { | |
90 Expression e = exp.interpret(istate); | |
91 if (e is EXP_CANT_INTERPRET) | |
92 { | |
93 //printf("-ExpStatement.interpret(): %p\n", e); | |
94 return EXP_CANT_INTERPRET; | |
95 } | |
96 } | |
97 return null; | |
0 | 98 } |
99 | |
72 | 100 override BE blockExit() |
0 | 101 { |
102 BE result = BE.BEfallthru; | |
103 | |
104 if (exp) | |
105 { | |
106 if (exp.op == TOK.TOKhalt) | |
107 return BE.BEhalt; | |
108 if (exp.op == TOK.TOKassert) | |
109 { | |
110 AssertExp a = cast(AssertExp)exp; | |
111 | |
112 if (a.e1.isBool(false)) // if it's an assert(0) | |
113 return BE.BEhalt; | |
114 } | |
115 if (exp.canThrow()) | |
116 result |= BE.BEthrow; | |
117 } | |
118 return result; | |
119 } | |
79 | 120 |
121 override bool isEmpty() | |
122 { | |
123 return (exp is null); | |
124 } | |
0 | 125 |
72 | 126 override int inlineCost(InlineCostState* ics) |
0 | 127 { |
128 return exp ? exp.inlineCost(ics) : 0; | |
129 } | |
130 | |
72 | 131 override Expression doInline(InlineDoState ids) |
0 | 132 { |
79 | 133 version (LOG) |
134 { | |
135 if (exp) writef("ExpStatement.doInline() '%s'\n", exp.toChars()); | |
0 | 136 } |
137 return exp ? exp.doInline(ids) : null; | |
138 } | |
139 | |
72 | 140 override Statement inlineScan(InlineScanState* iss) |
0 | 141 { |
142 version (LOG) { | |
143 printf("ExpStatement.inlineScan(%s)\n", toChars()); | |
144 } | |
145 if (exp) | |
146 exp = exp.inlineScan(iss); | |
147 return this; | |
148 } | |
149 | |
72 | 150 override void toIR(IRState* irs) |
0 | 151 { |
152 Blockx* blx = irs.blx; | |
153 | |
154 //printf("ExpStatement.toIR(), exp = %s\n", exp ? exp.toChars() : ""); | |
155 incUsage(irs, loc); | |
156 if (exp) | |
157 block_appendexp(blx.curblock, exp.toElem(irs)); | |
158 } | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
159 } |