annotate dmd/CommaExp.d @ 163:fe932c1a9563

*.interpret functions implemenation
author korDen
date Thu, 23 Sep 2010 13:55:20 +0400
parents af1bebfd96a4
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.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
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.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.IntRange;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Expression;
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
10 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 class CommaExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
27 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
37 override void checkEscape()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 e2.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
42 override void checkEscapeRef()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
43 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
44 e2.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
45 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
46
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
47 override IntRange getIntRange()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
53 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 return e2.isLvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
58 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 e2 = e2.toLvalue(sc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
64 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 e2 = e2.modifiableLvalue(sc, e);
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 bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return e2.isBool(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
75 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (flag == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 // Don't check e1 until we cast(void) the a,b code generation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 return e2.checkSideEffect(flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
86 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
88 return e2.implicitConvTo(t);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
91 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
93 Expression e2c = e2.castTo(sc, t);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
94 Expression e;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
95
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
96 if (e2c != e2)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
97 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
98 e = new CommaExp(loc, e1, e2c);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
99 e.type = e2c.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
100 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
101 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
102 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
103 e = this;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
104 e.type = e2.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
105 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
106 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
109 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 e1 = e1.optimize(result & WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
128 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
130 version (LOG) {
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
131 printf("CommaExp.interpret() %.*s\n", toChars());
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
132 }
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
133 Expression e = e1.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
134 if (e !is EXP_CANT_INTERPRET)
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
135 e = e2.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
136 return e;
0
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 elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 assert(e1 && e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 elem* eleft = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 elem* eright = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 elem* e = el_combine(eleft, eright);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 el_setLoc(e, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
149 }