annotate dmd/PtrExp.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents b0d41ff5e0df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.PtrExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.Identifier;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
11 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
13 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
14 import dmd.HdrGenState;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.AddrExp;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
19 import dmd.PREC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.StructLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.expression.Ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.mTY;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
32 import dmd.backend.OPER;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
33
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
34 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
35
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 class PtrExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
38 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
39
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 this(Loc loc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
42 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 super(loc, TOK.TOKstar, PtrExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 // if (e.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 // type = ((TypePointer *)e.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this(Loc loc, Expression e, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
50 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 super(loc, TOKstar, PtrExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 printf("PtrExp::semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (!e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 writef("PtrExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 Expression e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 Type tb = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 switch (tb.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 case Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 type = (cast(TypePointer)tb).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 case Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 case Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 type = (cast(TypeArray)tb).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 e1 = e1.castTo(sc, type.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 error("can only * a pointer, not a '%s'", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
91 override bool isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
93 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
95
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
96 override void checkEscapeRef()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
97 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
98 e1.checkEscape();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
99 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
100
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
101 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 tym = tybasic(e1.ET.Tty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 if (!(tyscalar(tym) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 tym == TYstruct ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 tym == TYarray && e.Eoper == TOKaddr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 synerr(EM_lvalue); // lvalue expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
115 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 //printf("PtrExp.modifiableLvalue() %s, type %s\n", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (e1.op == TOKsymoff)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
120 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 SymOffExp se = cast(SymOffExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 se.var.checkModify(loc, sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 //return toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 return Expression.modifiableLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
129 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
131 buf.writeByte('*');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
132 expToCBuffer(buf, hgs, e1, precedence[op]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 //printf("PtrExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 e = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 e = el_una(OPER.OPind, type.totym(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (tybasic(e.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 e.Enumbytes = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
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 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
152 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 //printf("PtrExp.optimize(result = x%x) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 // Convert *&ex to ex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 if (e1.op == TOK.TOKaddress)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
158 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 ex = (cast(AddrExp)e1).e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (type.equals(ex.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 e = ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 e = ex.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 // Constant fold *(&structliteral + offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (e1.op == TOK.TOKadd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 e = Ptr(type, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 if (e !is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 if (e1.op == TOK.TOKsymoff)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
182 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 SymOffExp se = cast(SymOffExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 VarDeclaration v = se.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 Expression e = expandVar(result, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (e && e.op == TOK.TOKstructliteral)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 135
diff changeset
187 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 StructLiteralExp sle = cast(StructLiteralExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 e = sle.getField(type, se.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 if (e && e !is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
197 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
202 override Identifier opId()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207