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