annotate dmd/NewExp.d @ 90:39648eb578f6

more Expressions work
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 20:27:56 +0100
parents be2ab491772e
children e28b18c23469
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: 64
diff changeset
1 module dmd.NewExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
4 import dmd.NewDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.CtorDeclaration;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
6 import dmd.ClassDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
7 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
8 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
9 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
10 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
11 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
12 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
13 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
14 import dmd.ArrayTypes;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.TypePointer;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
45 import std.string : toStringz;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
46
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 class NewExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
49 /* thisexp.new(newargs) newtype(arguments)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
50 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
51 Expression thisexp; // if !null, 'this' for class being allocated
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
52 Expressions newargs; // Array of Expression's to call new operator
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
53 Type newtype;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
54 Expressions arguments; // Array of Expression's
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
55
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
56 CtorDeclaration member; // constructor function
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
57 NewDeclaration allocator; // allocator function
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 int onstack; // allocate on stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 this(Loc loc, Expression thisexp, Expressions newargs, Type newtype, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 super(loc, TOK.TOKnew, NewExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 this.thisexp = thisexp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 this.newargs = newargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 this.newtype = newtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 this.arguments = arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
69 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
71 return new NewExp(loc,
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
72 thisexp ? thisexp.syntaxCopy() : null,
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
73 arraySyntaxCopy(newargs),
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 0
diff changeset
74 newtype.syntaxCopy(), arraySyntaxCopy(arguments));
0
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: 64
diff changeset
77 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 ClassDeclaration cdthis = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 printf("NewExp.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 printf("\tthisexp = %s\n", thisexp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 printf("\tnewtype: %s\n", newtype.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (type) // if semantic() already run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Lagain:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 thisexp = thisexp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 cdthis = thisexp.type.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 sc = sc.push(cdthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 type = newtype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 error("'this' for nested class must be a class type, not %s", thisexp.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 type = newtype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 type = newtype.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 newtype = type; // in case type gets cast to something else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 tb = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 //printf("tb: %s, deco = %s\n", tb.toChars(), tb.deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 arrayExpressionSemantic(newargs, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 preFunctionArguments(loc, sc, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 arrayExpressionSemantic(arguments, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 preFunctionArguments(loc, sc, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (thisexp && tb.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 error("e.new is only for allocating nested classes, not %s", tb.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 if (tb.ty == Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 TypeFunction tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 TypeClass tc = cast(TypeClass)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 ClassDeclaration cd = tc.sym.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (cd.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 error("cannot create instance of interface %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 else if (cd.isAbstract())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 error("cannot create instance of abstract class %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 for (int j = 0; j < cd.vtbl.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 FuncDeclaration fd = (cast(Dsymbol)cd.vtbl.data[j]).isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (fd && fd.isAbstract())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 error("function %s is abstract", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 checkDeprecated(sc, cd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 { /* We need a 'this' pointer for the nested class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 * Ensure we have the right one.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 Dsymbol s = cd.toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 ClassDeclaration cdn = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 FuncDeclaration fdn = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 //printf("cd isNested, cdn = %s\n", cdn ? cdn.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 if (cdn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (!cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 // Supply an implicit 'this' and try again
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 thisexp = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 for (Dsymbol sp = sc.parent; 1; sp = sp.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 if (!sp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 error("outer class %s 'this' needed to 'new' nested class %s", cdn.toChars(), cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 ClassDeclaration cdp = sp.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (!cdp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 if (cdp == cdn || cdn.isBaseOf(cdp, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 // Add a '.outer' and try again
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 thisexp = new DotIdExp(loc, thisexp, Id.outer);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 if (!global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 //printf("cdthis = %s\n", cdthis.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 if (cdthis != cdn && !cdn.isBaseOf(cdthis, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 error("'this' for nested class must be of type %s, not %s", cdn.toChars(), thisexp.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 for (Dsymbol *sf = sc.func; 1; sf= sf.toParent2().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (!sf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 error("outer class %s 'this' needed to 'new' nested class %s", cdn.toChars(), cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 printf("sf = %s\n", sf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 AggregateDeclaration *ad = sf.isThis();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 if (ad && (ad == cdn || cdn.isBaseOf(ad.isClassDeclaration(), null)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 ///static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 else if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 error("e.new is only for allocating nested classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 else if (fdn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 // make sure the parent context fdn of cd is reachable from sc
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 for (Dsymbol sp = sc.parent; 1; sp = sp.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 if (fdn is sp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 FuncDeclaration fsp = sp ? sp.isFuncDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 if (!sp || (fsp && fsp.isStatic()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 error("outer function context of %s is needed to 'new' nested class %s", fdn.toPrettyChars(), cd.toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 ///} else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 /// else if (fdn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 /// /* The nested class cd is nested inside a function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 /// * we'll let getEthis() look for errors.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 /// */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 /// //printf("nested class %s is nested inside function %s, we're in %s\n", cd.toChars(), fdn.toChars(), sc.func.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 /// if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 /// // Because thisexp cannot be a function frame pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 /// error("e.new is only for allocating nested classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 else if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 error("e.new is only for allocating nested classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 FuncDeclaration f = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 if (cd.ctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 f = resolveFuncCall(sc, loc, cd.ctor, null, null, arguments, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 member = f.isCtorDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 assert(member);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 cd.accessCheck(loc, sc, member);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 tf = cast(TypeFunction)f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (!arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 functionArguments(loc, sc, tf, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 if (arguments && arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 error("no constructor for %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (cd.aggNew)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 // Prepend the size argument to newargs[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 Expression e = new IntegerExp(loc, cd.size(loc), Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (!newargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 newargs = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
264 newargs.shift(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 f = cd.aggNew.overloadResolve(loc, null, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 allocator = f.isNewDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 assert(allocator);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 tf = cast(TypeFunction)f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 functionArguments(loc, sc, tf, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 if (newargs && newargs.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 error("no allocator for %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 else if (tb.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 TypeStruct ts = cast(TypeStruct)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 StructDeclaration sd = ts.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 TypeFunction tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 FuncDeclaration f = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (sd.ctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 f = resolveFuncCall(sc, loc, sd.ctor, null, null, arguments, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 member = f.isCtorDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 assert(member);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 sd.accessCheck(loc, sc, member);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 tf = cast(TypeFunction)f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 // type = tf.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (!arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 functionArguments(loc, sc, tf, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (arguments && arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 error("no constructor for %s", sd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 if (sd.aggNew)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 // Prepend the uint size argument to newargs[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 Expression e = new IntegerExp(loc, sd.size(loc), Type.tuns32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 if (!newargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 newargs = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
315 newargs.shift(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 f = sd.aggNew.overloadResolve(loc, null, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 allocator = f.isNewDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 assert(allocator);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 tf = cast(TypeFunction)f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 functionArguments(loc, sc, tf, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 e = new VarExp(loc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e = new CallExp(loc, e, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 e.type = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (newargs && newargs.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 error("no allocator for %s", sd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 type = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 else if (tb.ty == Tarray && (arguments && arguments.dim))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 for (size_t j = 0; j < arguments.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 if (tb.ty != Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 error("too many arguments for array");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 arguments.dim = i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
350 auto arg = arguments[j];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 arg = resolveProperties(sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 arg = arg.implicitCastTo(sc, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 arg = arg.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 if (arg.op == TOKint64 && cast(long)arg.toInteger() < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 error("negative array index %s", arg.toChars());
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
356 arguments[j] = arg;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 tb = (cast(TypeDArray)tb).next.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 else if (tb.isscalar())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 if (arguments && arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 error("no constructor for %s", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 type = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 error("new can only create structs, dynamic arrays or class objects, not %s's", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 type = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 //printf("NewExp: '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 //printf("NewExp:type '%s'\n", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
379 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 thisexp = thisexp.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 // Optimize parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 if (newargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 {
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
387 foreach (ref Expression e; newargs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 e = e.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 {
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
395 foreach (ref Expression e; arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 e = e.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
403 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 Type ectype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 //printf("NewExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 t = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 //printf("\ttype = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 //if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 //printf("\tmember = %s\n", member.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 if (t.ty == Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 Symbol* csym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 t = newtype.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 assert(t.ty == Tclass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 TypeClass tclass = cast(TypeClass)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 ClassDeclaration cd = tclass.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 /* Things to do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 * 1) ex: call allocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 * 2) ey: set vthis for nested classes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 * 3) ez: call constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 elem *ex = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 elem *ey = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 elem *ez = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 if (allocator || onstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 elem *ei;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 Symbol *si;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 if (onstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 /* Create an instance of the class on the stack,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 * and call it stmp.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 * Set ex to be the &stmp.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 Symbol* s = symbol_calloc(toStringz(tclass.sym.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 s.Sclass = SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 s.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 s.Sstruct.Sflags |= 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 s.Sstruct.Salignsize = tclass.sym.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 s.Sstruct.Sstructalign = cast(ubyte)tclass.sym.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 s.Sstruct.Sstructsize = tclass.sym.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 .type* tc = type_alloc(TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 tc.Ttag = cast(Classsym*)s; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 tc.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 s.Stype = tc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 Symbol *stmp = symbol_genauto(tc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 ex = el_ptr(stmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 ex = el_var(allocator.toSymbol());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 ex = callfunc(loc, irs, 1, type, ex, allocator.type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 allocator, allocator.type, null, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 si = tclass.sym.toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 ei = el_var(si);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 ey = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 ez = el_copytree(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 else if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 ez = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 ex = el_una(OPind, TYstruct, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 ex = el_bin(OPstreq, TYnptr, ex, ei);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 ex.Enumbytes = cd.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 ex = el_una(OPaddr, TYnptr, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 ectype = tclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 csym = cd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 ex = el_bin(OPcall,TYnptr,el_var(rtlsym[RTLSYM_NEWCLASS]),el_ptr(csym));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 ectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 ey = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 ez = el_copytree(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 else if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 ez = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 //elem_print(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 //elem_print(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 //elem_print(ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 ClassDeclaration cdthis = thisexp.type.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 assert(cdthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 //printf("cd = %s\n", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 //printf("cdthis = %s\n", cdthis.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 assert(cd.isNested());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Dsymbol cdp = cd.toParent2(); // class we're nested in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 elem* ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 //printf("member = %p\n", member);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 //printf("cdp = %s\n", cdp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 //printf("cdthis = %s\n", cdthis.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 if (cdp != cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 int i = cdp.isClassDeclaration().isBaseOf(cdthis, &offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 assert(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 ethis = thisexp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 if (offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 ethis = el_bin(OPadd, TYnptr, ethis, el_long(TYint, offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 if (!cd.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 error("forward reference to %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 ey = el_bin(OPadd, TYnptr, ey, el_long(TYint, cd.vthis.offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 ey = el_una(OPind, TYnptr, ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 ey = el_bin(OPeq, TYnptr, ey, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 //printf("ex: "); elem_print(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 //printf("ey: "); elem_print(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 //printf("ez: "); elem_print(ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 else if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 /* Initialize cd.vthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 * *(ey + cd.vthis.offset) = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 ey = setEthis(loc, irs, ey, cd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 // Call constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 ez = callfunc(loc, irs, 1, type, ez, ectype, member, member.type, null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 e = el_combine(ex, ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 e = el_combine(e, ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 else if (t.ty == Tpointer && t.nextOf().toBasetype().ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 Symbol* csym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 t = newtype.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 assert(t.ty == Tstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 TypeStruct tclass = cast(TypeStruct)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 StructDeclaration cd = tclass.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 /* Things to do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 * 1) ex: call allocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 * 2) ey: set vthis for nested classes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 * 3) ez: call constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 elem* ex = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 elem* ey = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 elem* ez = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 if (allocator)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 elem *ei;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 Symbol *si;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 ex = el_var(allocator.toSymbol());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 ex = callfunc(loc, irs, 1, type, ex, allocator.type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 allocator, allocator.type, null, newargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 si = tclass.sym.toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 ei = el_var(si);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 ey = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 ez = el_copytree(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 else if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 ez = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 if (!member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 /* Statically intialize with default initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 ex = el_una(OPind, TYstruct, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 ex = el_bin(OPstreq, TYnptr, ex, ei);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 ex.Enumbytes = cd.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 ex = el_una(OPaddr, TYnptr, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 ectype = tclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 ulong elemsize = cd.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 // call _d_newarrayT(ti, 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 e = el_long(TYsize_t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 e = el_param(e, type.getTypeInfo(null).toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 int rtl = t.isZeroInit(Loc(0)) ? RTLSYM_NEWARRAYT : RTLSYM_NEWARRAYIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 // The new functions return an array, so convert to a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 // ex . (unsigned)(e >> 32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 e = el_bin(OPshr, TYdarray, e, el_long(TYint, 32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 ex = el_una(OP64_32, TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 ectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 ey = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 ez = el_copytree(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 else if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 ez = el_same(&ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 //elem_print(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 //elem_print(ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 //elem_print(ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 if (cd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 /* Initialize cd.vthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 * *(ey + cd.vthis.offset) = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 ey = setEthis(loc, irs, ey, cd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 if (member)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 // Call constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 ez = callfunc(loc, irs, 1, type, ez, ectype, member, member.type, null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 /* Structs return a ref, which gets automatically dereferenced.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 * But we want a pointer to the instance.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 ez = el_una(OPaddr, TYnptr, ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 e = el_combine(ex, ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 e = el_combine(e, ez);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 else if (t.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 TypeDArray tda = cast(TypeDArray)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 assert(arguments && arguments.dim >= 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 if (arguments.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 // Single dimension array allocations
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
665 auto arg = arguments[0]; // gives array length
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 e = arg.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 ulong elemsize = tda.next.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 // call _d_newT(ti, arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 e = el_param(e, type.getTypeInfo(null).toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 int rtl = tda.next.isZeroInit(Loc(0)) ? RTLSYM_NEWARRAYT : RTLSYM_NEWARRAYIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 // Multidimensional array allocations
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 e = el_long(TYint, arguments.dim);
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
678 foreach (Expression arg; arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 e = el_param(arg.toElem(irs), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 assert(t.ty == Tarray);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 t = t.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 assert(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 e = el_param(e, type.getTypeInfo(null).toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 int rtl = t.isZeroInit(Loc(0)) ? RTLSYM_NEWARRAYMT : RTLSYM_NEWARRAYMIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 else if (t.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 TypePointer tp = cast(TypePointer)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 ulong elemsize = tp.next.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 Expression di = tp.next.defaultInit(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 ulong disize = di.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 // call _d_newarrayT(ti, 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 e = el_long(TYsize_t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 e = el_param(e, type.getTypeInfo(null).toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 int rtl = tp.next.isZeroInit(Loc(0)) ? RTLSYM_NEWARRAYT : RTLSYM_NEWARRAYIT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 // The new functions return an array, so convert to a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 // e . (unsigned)(e >> 32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 e = el_bin(OPshr, TYdarray, e, el_long(TYint, 32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 e = el_una(OP64_32, t.totym(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
720 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
725 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
730 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
732 //printf("NewExp.scanForNestedRef(Scope *sc): %s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
733
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
734 if (thisexp)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
735 thisexp.scanForNestedRef(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
736 arrayExpressionScanForNestedRef(sc, newargs);
64
4290d870944a More fixes
korDen
parents: 53
diff changeset
737 arrayExpressionScanForNestedRef(sc, arguments);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
741 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 return 1;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
744 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
746
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 //int inlineCost(InlineCostState *ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
749 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 //printf("NewExp.doInline(): %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 NewExp ne = cast(NewExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 if (thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 ne.thisexp = thisexp.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 ne.newargs = arrayExpressiondoInline(ne.newargs, ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 ne.arguments = arrayExpressiondoInline(ne.arguments, ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 return ne;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
759 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
760
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 //Expression inlineScan(InlineScanState *iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763