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;
|
|
17 import dmd.DeclarationStatement;
|
|
18
|
|
19 import dmd.backend.Blockx;
|
|
20 import dmd.backend.Util;
|
|
21
|
|
22 class ExpStatement : Statement
|
|
23 {
|
|
24 Expression exp;
|
|
25
|
|
26 this(Loc loc, Expression exp)
|
|
27 {
|
|
28 super(loc);
|
|
29 this.exp = exp;
|
|
30 }
|
|
31
|
|
32 Statement syntaxCopy()
|
|
33 {
|
|
34 Expression e = exp ? exp.syntaxCopy() : null;
|
|
35 ExpStatement es = new ExpStatement(loc, e);
|
|
36 return es;
|
|
37 }
|
|
38
|
|
39 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
40 {
|
|
41 if (exp)
|
|
42 exp.toCBuffer(buf, hgs);
|
|
43 buf.writeByte(';');
|
|
44 if (!hgs.FLinit.init)
|
|
45 buf.writenl();
|
|
46 }
|
|
47
|
|
48 Statement semantic(Scope sc)
|
|
49 {
|
|
50 if (exp)
|
|
51 {
|
|
52 //printf("ExpStatement::semantic() %s\n", exp->toChars());
|
|
53 exp = exp.semantic(sc);
|
|
54 exp = resolveProperties(sc, exp);
|
|
55 exp.checkSideEffect(0);
|
|
56 exp = exp.optimize(0);
|
|
57 if (exp.op == TOK.TOKdeclaration && !isDeclarationStatement())
|
|
58 {
|
|
59 Statement s = new DeclarationStatement(loc, exp);
|
|
60 return s;
|
|
61 }
|
|
62 //exp = exp.optimize(isDeclarationStatement() ? WANT.WANTvalue : 0);
|
|
63 }
|
|
64 return this;
|
|
65 }
|
|
66
|
|
67 Expression interpret(InterState* istate)
|
|
68 {
|
|
69 assert(false);
|
|
70 }
|
|
71
|
|
72 BE blockExit()
|
|
73 {
|
|
74 BE result = BE.BEfallthru;
|
|
75
|
|
76 if (exp)
|
|
77 {
|
|
78 if (exp.op == TOK.TOKhalt)
|
|
79 return BE.BEhalt;
|
|
80 if (exp.op == TOK.TOKassert)
|
|
81 {
|
|
82 AssertExp a = cast(AssertExp)exp;
|
|
83
|
|
84 if (a.e1.isBool(false)) // if it's an assert(0)
|
|
85 return BE.BEhalt;
|
|
86 }
|
|
87 if (exp.canThrow())
|
|
88 result |= BE.BEthrow;
|
|
89 }
|
|
90 return result;
|
|
91 }
|
|
92
|
|
93 int inlineCost(InlineCostState* ics)
|
|
94 {
|
|
95 return exp ? exp.inlineCost(ics) : 0;
|
|
96 }
|
|
97
|
|
98 Expression doInline(InlineDoState ids)
|
|
99 {
|
|
100 version (LOG) {
|
|
101 if (exp) printf("ExpStatement.doInline() '%s'\n", exp.toChars());
|
|
102 }
|
|
103 return exp ? exp.doInline(ids) : null;
|
|
104 }
|
|
105
|
|
106 Statement inlineScan(InlineScanState* iss)
|
|
107 {
|
|
108 version (LOG) {
|
|
109 printf("ExpStatement.inlineScan(%s)\n", toChars());
|
|
110 }
|
|
111 if (exp)
|
|
112 exp = exp.inlineScan(iss);
|
|
113 return this;
|
|
114 }
|
|
115
|
|
116 void toIR(IRState* irs)
|
|
117 {
|
|
118 Blockx* blx = irs.blx;
|
|
119
|
|
120 //printf("ExpStatement.toIR(), exp = %s\n", exp ? exp.toChars() : "");
|
|
121 incUsage(irs, loc);
|
|
122 if (exp)
|
|
123 block_appendexp(blx.curblock, exp.toElem(irs));
|
|
124 }
|
|
125 } |