annotate dmd/NewExp.d @ 179:cd48cb899aee

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