Mercurial > projects > ddmd
annotate dmd/ExpStatement.d @ 155:a43c65469219
+ Statement.interpret()
+ ContinueStatement.interpret()
+ DoStatement.interpret()
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 17:31:22 +0200 |
parents | e28b18c23469 |
children | e3afd1303184 |
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 | |
25 class ExpStatement : Statement | |
26 { | |
27 Expression exp; | |
28 | |
29 this(Loc loc, Expression exp) | |
30 { | |
31 super(loc); | |
32 this.exp = exp; | |
33 } | |
34 | |
72 | 35 override Statement syntaxCopy() |
0 | 36 { |
37 Expression e = exp ? exp.syntaxCopy() : null; | |
38 ExpStatement es = new ExpStatement(loc, e); | |
39 return es; | |
40 } | |
41 | |
72 | 42 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 43 { |
44 if (exp) | |
45 exp.toCBuffer(buf, hgs); | |
46 buf.writeByte(';'); | |
47 if (!hgs.FLinit.init) | |
48 buf.writenl(); | |
49 } | |
50 | |
72 | 51 override Statement semantic(Scope sc) |
0 | 52 { |
53 if (exp) | |
54 { | |
55 //printf("ExpStatement::semantic() %s\n", exp->toChars()); | |
56 exp = exp.semantic(sc); | |
57 exp = resolveProperties(sc, exp); | |
58 exp.checkSideEffect(0); | |
59 exp = exp.optimize(0); | |
60 if (exp.op == TOK.TOKdeclaration && !isDeclarationStatement()) | |
61 { | |
62 Statement s = new DeclarationStatement(loc, exp); | |
63 return s; | |
64 } | |
65 //exp = exp.optimize(isDeclarationStatement() ? WANT.WANTvalue : 0); | |
66 } | |
67 return this; | |
68 } | |
69 | |
72 | 70 override Expression interpret(InterState istate) |
0 | 71 { |
79 | 72 version (LOG) |
73 { | |
63 | 74 printf("ExpStatement.interpret(%s)\n", exp ? exp.toChars() : ""); |
75 } | |
155 | 76 mixin(START); |
63 | 77 if (exp) |
78 { | |
79 Expression e = exp.interpret(istate); | |
80 if (e is EXP_CANT_INTERPRET) | |
81 { | |
82 //printf("-ExpStatement.interpret(): %p\n", e); | |
83 return EXP_CANT_INTERPRET; | |
84 } | |
85 } | |
86 return null; | |
0 | 87 } |
88 | |
72 | 89 override BE blockExit() |
0 | 90 { |
91 BE result = BE.BEfallthru; | |
92 | |
93 if (exp) | |
94 { | |
95 if (exp.op == TOK.TOKhalt) | |
96 return BE.BEhalt; | |
97 if (exp.op == TOK.TOKassert) | |
98 { | |
99 AssertExp a = cast(AssertExp)exp; | |
100 | |
101 if (a.e1.isBool(false)) // if it's an assert(0) | |
102 return BE.BEhalt; | |
103 } | |
104 if (exp.canThrow()) | |
105 result |= BE.BEthrow; | |
106 } | |
107 return result; | |
108 } | |
79 | 109 |
110 override bool isEmpty() | |
111 { | |
112 return (exp is null); | |
113 } | |
0 | 114 |
72 | 115 override int inlineCost(InlineCostState* ics) |
0 | 116 { |
117 return exp ? exp.inlineCost(ics) : 0; | |
118 } | |
119 | |
72 | 120 override Expression doInline(InlineDoState ids) |
0 | 121 { |
79 | 122 version (LOG) |
123 { | |
124 if (exp) writef("ExpStatement.doInline() '%s'\n", exp.toChars()); | |
0 | 125 } |
126 return exp ? exp.doInline(ids) : null; | |
127 } | |
128 | |
72 | 129 override Statement inlineScan(InlineScanState* iss) |
0 | 130 { |
131 version (LOG) { | |
132 printf("ExpStatement.inlineScan(%s)\n", toChars()); | |
133 } | |
134 if (exp) | |
135 exp = exp.inlineScan(iss); | |
136 return this; | |
137 } | |
138 | |
72 | 139 override void toIR(IRState* irs) |
0 | 140 { |
141 Blockx* blx = irs.blx; | |
142 | |
143 //printf("ExpStatement.toIR(), exp = %s\n", exp ? exp.toChars() : ""); | |
144 incUsage(irs, loc); | |
145 if (exp) | |
146 block_appendexp(blx.curblock, exp.toElem(irs)); | |
147 } | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
148 } |