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