annotate dmd/CommaExp.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents fe932c1a9563
children cd48cb899aee
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 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 163
diff changeset
24 register();
e3afd1303184 Many small bugs fixed
korDen
parents: 163
diff changeset
25
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
29 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 BinExp.semanticp(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
39 override void checkEscape()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 e2.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
44 override void 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 e2.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
47 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
48
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
49 override IntRange getIntRange()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return e2.isLvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
60 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 e2 = e2.toLvalue(sc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
66 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 e2 = e2.modifiableLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
72 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 return e2.isBool(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
77 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (flag == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 // Don't check e1 until we cast(void) the a,b code generation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return e2.checkSideEffect(flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
88 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
90 return e2.implicitConvTo(t);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
93 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
95 Expression e2c = e2.castTo(sc, t);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
96 Expression e;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
97
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
98 if (e2c != e2)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
99 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
100 e = new CommaExp(loc, e1, e2c);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
101 e.type = e2c.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
102 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
103 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
104 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
105 e = this;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
106 e.type = e2.type;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
107 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
108 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
111 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 e1 = e1.optimize(result & WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
130 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
132 version (LOG) {
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
133 printf("CommaExp.interpret() %.*s\n", toChars());
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
134 }
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
135 Expression e = e1.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
136 if (e !is EXP_CANT_INTERPRET)
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
137 e = e2.interpret(istate);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 135
diff changeset
138 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
141 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 assert(e1 && e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 elem* eleft = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 elem* eright = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 elem* e = el_combine(eleft, eright);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 el_setLoc(e, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
151 }