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