annotate dmd/CallExp.d @ 66:efb1e5bdf63c

more implementations
author korDen
date Mon, 23 Aug 2010 20:38:30 +0400
parents 4290d870944a
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
4 import dmd.Cast;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.BUILTIN;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.OverExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.CSX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.DsymbolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.DotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TemplateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.StructLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.DotTemplateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.DotTemplateInstanceExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.DelegateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.TypeAArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.RemoveExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.UnaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 import dmd.PREC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
74 import std.stdio;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
75
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 class CallExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 this(Loc loc, Expression e, Expressions exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 super(loc, TOK.TOKcall, CallExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 this.arguments = exps;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 this(Loc loc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 super(loc, TOK.TOKcall, CallExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 this(Loc loc, Expression e, Expression earg1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 super(loc, TOK.TOKcall, CallExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Expressions arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 arguments.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 arguments.data[0] = cast(void*)earg1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 this.arguments = arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 this(Loc loc, Expression e, Expression earg1, Expression earg2)
66
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
103 {
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
104 super(loc, TOK.TOKcall, CallExp.sizeof, e);
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
105
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
106 Expressions arguments = new Expressions();
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
107 arguments.setDim(2);
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
108 arguments.data[0] = cast(void*)earg1;
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
109 arguments.data[1] = cast(void*)earg2;
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
110
efb1e5bdf63c more implementations
korDen
parents: 64
diff changeset
111 this.arguments = arguments;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 return new CallExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 TypeFunction tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 FuncDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 int istemp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 Objects targsi; // initial list of template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 TemplateInstance tierror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 printf("CallExp.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 return this; // semantic() already run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 if (arguments && arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 Expression earg = cast(Expression)arguments.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 earg.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (earg.type) earg.type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 if (e1.op == TOK.TOKdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 DelegateExp de = cast(DelegateExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 e1 = new DotVarExp(de.loc, de.e1, de.func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 return semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 /* Transform:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 * array.id(args) into .id(array,args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 * aa.remove(arg) into delete aa[arg]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (e1.op == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 // BUG: we should handle array.a.b.c.e(args) too
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 DotIdExp dotid = cast(DotIdExp)(e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 dotid.e1 = dotid.e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 assert(dotid.e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (dotid.e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 TY e1ty = dotid.e1.type.toBasetype().ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 if (e1ty == TY.Taarray && dotid.ident == Id.remove)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (!arguments || arguments.dim != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 error("expected key as argument to aa.remove()");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 Expression key = cast(Expression)arguments.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 key = key.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 key = resolveProperties(sc, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 key.rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 TypeAArray taa = cast(TypeAArray)dotid.e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 key = key.implicitCastTo(sc, taa.index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 return new RemoveExp(loc, dotid.e1, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 else if (e1ty == TY.Tarray || e1ty == TY.Tsarray || e1ty == TY.Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (!arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 arguments.shift(cast(void*)dotid.e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 e1 = new DotIdExp(dotid.loc, new IdentifierExp(dotid.loc, Id.empty), dotid.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 e1 = new IdentifierExp(dotid.loc, dotid.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 /* This recognizes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 * foo!(tiargs)(funcargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (e1.op == TOK.TOKimport && !e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 ScopeExp se = cast(ScopeExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 TemplateInstance ti = se.sds.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 if (ti && !ti.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 /* Attempt to instantiate ti. If that works, go with it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 * If not, go with partial explicit specialization.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 ti.semanticTiargs(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 uint errors = global.errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 global.gag++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 ti.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 global.gag--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 if (errors != global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 /* Didn't work, go with partial explicit specialization
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 global.errors = errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 targsi = ti.tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 tierror = ti; // for error reporting
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 e1 = new IdentifierExp(loc, ti.name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 /* This recognizes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 * expr.foo!(tiargs)(funcargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 if (e1.op == TOK.TOKdotti && !e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 DotTemplateInstanceExp se = cast(DotTemplateInstanceExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 TemplateInstance ti = se.ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 if (!ti.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 /* Attempt to instantiate ti. If that works, go with it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 * If not, go with partial explicit specialization.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 ti.semanticTiargs(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 Expression etmp = e1.trySemantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 if (etmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 e1 = etmp; // it worked
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 else // didn't work
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 targsi = ti.tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 tierror = ti; // for error reporting
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 e1 = new DotIdExp(loc, se.e1, ti.name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 istemp = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 Lagain:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 //printf("Lagain: %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 f = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 if (e1.op == TOK.TOKthis || e1.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 // semantic() run later for these
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 /* Look for e1 being a lazy parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 if (e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (ve.var.storage_class & STC.STClazy)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 TypeFunction tff = new TypeFunction(null, ve.var.type, 0, LINK.LINKd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 TypeDelegate t = new TypeDelegate(tff);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 ve.type = t.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 if (e1.op == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 // Perhaps this should be moved to ScopeExp.semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 ScopeExp se = cast(ScopeExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 e1 = new DsymbolExp(loc, se.sds);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 ///static if (true) { // patch for #540 by Oskar Linde
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 else if (e1.op == TOK.TOKdotexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 DotExp de = cast(DotExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 if (de.e2.op == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 // This should *really* be moved to ScopeExp.semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 ScopeExp se = cast(ScopeExp)de.e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 de.e2 = new DsymbolExp(loc, se.sds);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 de.e2 = de.e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (de.e2.op == TOK.TOKtemplate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 TemplateExp te = cast(TemplateExp)de.e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 e1 = new DotTemplateExp(loc,de.e1,te.td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 if (e1.op == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 CommaExp ce = cast(CommaExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 e1 = ce.e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 e1.type = ce.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 ce.e2 = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 ce.type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 return ce.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 t1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 if (e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 // Check for call operator overload
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 if (t1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 if (t1.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 ad = (cast(TypeStruct)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 // First look for constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (ad.ctor && arguments && arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 // Create variable that will get constructed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 Identifier idtmp = Lexer.uniqueId("__ctmp");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 VarDeclaration tmp = new VarDeclaration(loc, t1, idtmp, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 Expression av = new DeclarationExp(loc, tmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 av = new CommaExp(loc, av, new VarExp(loc, tmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 CtorDeclaration cf = ad.ctor.isCtorDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 if (cf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 e = new DotVarExp(loc, av, cf, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 TemplateDeclaration td = ad.ctor.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 assert(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 e = new DotTemplateExp(loc, av, td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 e = new CallExp(loc, e, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 /* Constructors return a pointer to the instance
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 e = new PtrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 // No constructor, look for overload of opCall
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 if (search_function(ad, Id.call))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 goto L1; // overload of opCall, therefore it's a call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 if (e1.op != TOK.TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 error("%s %s does not overload ()", ad.kind(), ad.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 /* It's a struct literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 Expression e = new StructLiteralExp(loc, cast(StructDeclaration)ad, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 e.type = e1.type; // in case e1.type was a typedef
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 else if (t1.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 ad = (cast(TypeClass)t1).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 // Rewrite as e1.call(arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 Expression e = new DotIdExp(loc, e1, Id.call);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 e = new CallExp(loc, e, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 arrayExpressionSemantic(arguments, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 preFunctionArguments(loc, sc, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 if (e1.op == TOK.TOKdotvar && t1.ty == TY.Tfunction ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 e1.op == TOK.TOKdottd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 DotVarExp dve;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 DotTemplateExp dte;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 UnaExp ue = cast(UnaExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 if (e1.op == TOK.TOKdotvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 // Do overload resolution
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 dve = cast(DotVarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 f = dve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 assert(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 f = f.overloadResolve(loc, ue.e1, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 ad = f.toParent().isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 dte = cast(DotTemplateExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 TemplateDeclaration td = dte.td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 assert(td);
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 // Should fix deduceFunctionTemplate() so it works on null argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 f = td.deduceFunctionTemplate(sc, loc, targsi, ue.e1, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 if (!f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 ad = td.toParent().isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 if (f.needThis())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 ue.e1 = getRightThis(loc, sc, ad, ue.e1, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 /* Cannot call public functions from inside invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 * (because then the invariant would have infinite recursion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 if (sc.func && sc.func.isInvariantDeclaration() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 ue.e1.op == TOK.TOKthis && f.addPostInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 error("cannot call public/export function %s from invariant", f.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 checkPurity(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 accessCheck(loc, sc, ue.e1, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 if (!f.needThis())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 VarExp ve = new VarExp(loc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 e1 = new CommaExp(loc, ue.e1, ve);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 e1.type = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 if (e1.op == TOK.TOKdotvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 dve.var = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 e1 = new DotVarExp(loc, dte.e1, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 e1.type = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 printf("ue.e1 = %s\n", ue.e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 printf("f = %s\n", f.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 printf("t = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 printf("e1 = %s\n", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 printf("e1.type = %s\n", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 // Const member function can take const/immutable/mutable this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 if (!(f.type.isConst()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 // Check for const/immutable compatibility
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 Type tthis = ue.e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 if (tthis.ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 tthis = tthis.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 static if (false) { // this checking should have been already done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 if (f.type.isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 if (tthis.mod != MOD.MODinvariant)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 error("%s can only be called with an immutable object", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 else if (f.type.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 if (tthis.mod != MOD.MODinvariant && tthis.mod != MOD.MODshared && tthis.mod != (MOD.MODshared | MOD.MODconst))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 error("shared %s can only be called with a shared or immutable object", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 if (tthis.mod != MOD.MODundefined)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 //printf("mod = %x\n", tthis.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 error("%s can only be called with a mutable object, not %s", e1.toChars(), tthis.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 /* Cannot call mutable method on a final struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 if (tthis.ty == TY.Tstruct &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 ue.e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 VarExp v = cast(VarExp)ue.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 if (v.var.storage_class & STC.STCfinal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 error("cannot call mutable method on final struct");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 // See if we need to adjust the 'this' pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 AggregateDeclaration add = f.isThis();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 ClassDeclaration cd = ue.e1.type.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 if (add && cd && add.isClassDeclaration() && add != cd && ue.e1.op != TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 ue.e1 = ue.e1.castTo(sc, add.type); //new CastExp(loc, ue.e1, add.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 ue.e1 = ue.e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 else if (e1.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 // Base class constructor call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 ClassDeclaration cd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 cd = sc.func.toParent().isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 if (!cd || !cd.baseClass || !sc.func.isCtorDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 error("super class constructor call must be in a constructor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 if (!cd.baseClass.ctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 error("no super class constructor for %s", cd.baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 if (!sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 if (sc.callSuper & (CSX.CSXthis | CSX.CSXsuper))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 error("reference to this before super()");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 if (sc.noctor || sc.callSuper & CSX.CSXlabel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 error("constructor calls not allowed in loops or after labels");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 if (sc.callSuper & (CSX.CSXsuper_ctor | CSX.CSXthis_ctor))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 error("multiple constructor calls");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 sc.callSuper |= CSX.CSXany_ctor | CSX.CSXsuper_ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 f = resolveFuncCall(sc, loc, cd.baseClass.ctor, null, null, arguments, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 checkPurity(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 e1 = new DotVarExp(e1.loc, e1, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 else if (e1.op == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 // same class constructor call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 AggregateDeclaration cd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 cd = sc.func.toParent().isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 if (!cd || !sc.func.isCtorDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 error("constructor call must be in a constructor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 if (!sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 if (sc.callSuper & (CSXthis | CSXsuper))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 error("reference to this before super()");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 if (sc.noctor || sc.callSuper & CSX.CSXlabel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 error("constructor calls not allowed in loops or after labels");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 if (sc.callSuper & (CSX.CSXsuper_ctor | CSX.CSXthis_ctor))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 error("multiple constructor calls");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 sc.callSuper |= CSX.CSXany_ctor | CSX.CSXthis_ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 f = resolveFuncCall(sc, loc, cd.ctor, null, null, arguments, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 checkPurity(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 e1 = new DotVarExp(e1.loc, e1, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 // BUG: this should really be done by checking the static
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 // call graph
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 if (f == sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 error("cyclic constructor call");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 else if (e1.op == TOK.TOKoverloadset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 OverExp eo = cast(OverExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 FuncDeclaration ff = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 for (int j = 0; j < eo.vars.a.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 Dsymbol s = cast(Dsymbol)eo.vars.a.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 FuncDeclaration f2 = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 if (f2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 f2 = f2.overloadResolve(loc, null, arguments, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 TemplateDeclaration td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 assert(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 f2 = td.deduceFunctionTemplate(sc, loc, targsi, null, arguments, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 if (f2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 if (ff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 /* Error if match in more than one overload set,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 * even if one is a 'better' match than the other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 ScopeDsymbol.multiplyDefined(loc, ff, f2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 ff = f2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 if (!ff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 /* No overload matches, just set ff and rely on error
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 * message being generated later.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 ff = cast(FuncDeclaration)eo.vars.a.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 e1 = new VarExp(loc, ff);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 else if (!t1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 error("function expected before (), not '%s'", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 else if (t1.ty != TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 if (t1.ty == TY.Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 TypeDelegate td = cast(TypeDelegate)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 assert(td.next.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 tf = cast(TypeFunction)(td.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 if (sc.func && sc.func.isPure() && !tf.ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 error("pure function '%s' cannot call impure delegate '%s'", sc.func.toChars(), e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 goto Lcheckargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 else if (t1.ty == TY.Tpointer && (cast(TypePointer)t1).next.ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 Expression e = new PtrExp(loc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 t1 = (cast(TypePointer)t1).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 if (sc.func && sc.func.isPure() && !(cast(TypeFunction)t1).ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 error("pure function '%s' cannot call impure function pointer '%s'", sc.func.toChars(), e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 e.type = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 e1 = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 else if (e1.op == TOK.TOKtemplate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 TemplateExp te = cast(TemplateExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 f = te.td.deduceFunctionTemplate(sc, loc, targsi, null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 if (!f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 if (tierror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 tierror.error("errors instantiating template"); // give better error message
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 if (f.needThis() && hasThis(sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 // Supply an implicit 'this', as in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 // this.ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 e1 = new DotTemplateExp(loc, (new ThisExp(loc)).semantic(sc), te.td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 e1 = new VarExp(loc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 error("function expected before (), not %s of type %s", e1.toChars(), e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 else if (e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 // Do overload resolution
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 f = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 assert(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 if (ve.hasOverloads)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 f = f.overloadResolve(loc, null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 checkDeprecated(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 checkPurity(sc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 if (f.needThis() && hasThis(sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 // Supply an implicit 'this', as in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 // this.ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 e1 = new DotVarExp(loc, new ThisExp(loc), f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 accessCheck(loc, sc, null, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 ve.var = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 // ve.hasOverloads = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 ve.type = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 t1 = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 assert(t1.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 tf = cast(TypeFunction)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 Lcheckargs:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 assert(tf.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 type = tf.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 if (!arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 functionArguments(loc, sc, tf, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 error("forward reference to inferred return type of function call %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 if (f && f.tintro)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 Type t = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 TypeFunction tff = cast(TypeFunction)f.tintro;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 if (tff.next.isBaseOf(t, &offset) && offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 type = tff.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 return castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 //printf("CallExp::optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 // Optimize parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 for (size_t i = 0; i < arguments.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 Expression ee = cast(Expression)arguments.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 ee = ee.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 arguments.data[i] = cast(void*)ee;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 if (e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 FuncDeclaration fd = (cast(VarExp)e1).var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 BUILTIN b = fd.isBuiltin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 if (b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 e = eval_builtin(b, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 if (!e) // failed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 e = this; // evaluate at runtime
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 else if (result & WANT.WANTinterpret)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 Expression eresult = fd.interpret(null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 if (eresult && eresult !is EXP_VOID_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 e = eresult;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 error("cannot evaluate %s at compile time", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
819 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
821 Expression e = EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
822
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
823 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
824 printf("CallExp.interpret() %.*s\n", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
825 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
826 if (e1.op == TOKdotvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
827 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
828 Expression pthis = (cast(DotVarExp)e1).e1;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
829 FuncDeclaration fd = (cast(DotVarExp)e1).var.isFuncDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
830 TypeFunction tf = fd ? cast(TypeFunction)fd.type : null;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
831 if (tf)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
832 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
833 // Member function call
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
834 if(pthis.op == TOKthis)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
835 pthis = istate.localThis;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
836 Expression eresult = fd.interpret(istate, arguments, pthis);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
837 if (eresult)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
838 e = eresult;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
839 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
840 e = EXP_VOID_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
841 else
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
842 error("cannot evaluate %s at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
843 return e;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
844 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
845 error("cannot evaluate %s at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
846 return EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
847 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
848 if (e1.op == TOKvar)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
849 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
850 FuncDeclaration fd = (cast(VarExp)e1).var.isFuncDeclaration();
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
851 if (fd)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
852 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
853 ///version (DMDV2) {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
854 BUILTIN b = fd.isBuiltin();
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
855 if (b)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
856 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
857 scope Expressions args = new Expressions();
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
858 args.setDim(arguments.dim);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
859 for (size_t i = 0; i < args.dim; i++)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
860 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
861 Expression earg = cast(Expression)arguments.data[i];
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
862 earg = earg.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
863 if (earg == EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
864 return earg;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
865 args.data[i] = cast(void*)earg;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
866 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
867 e = eval_builtin(b, args);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
868 if (!e)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
869 e = EXP_CANT_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
870 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
871 else
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
872 ///}
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
873 // Inline .dup
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
874 if (fd.ident == Id.adDup && arguments && arguments.dim == 2)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
875 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
876 e = cast(Expression)arguments.data[1];
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
877 e = e.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
878 if (e !is EXP_CANT_INTERPRET)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
879 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
880 e = expType(type, e);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
881 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
882 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
883 else
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
884 {
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
885 Expression eresult = fd.interpret(istate, arguments);
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
886 if (eresult)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
887 e = eresult;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
888 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors)
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
889 e = EXP_VOID_INTERPRET;
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
890 else
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
891 error("cannot evaluate %s at compile time", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
892 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
893 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
894 }
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
895 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 bool checkSideEffect(int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 if (flag != 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 if (e1.checkSideEffect(2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 /* If any of the arguments have side effects, this expression does
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 for (size_t i = 0; i < arguments.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 Expression e = cast(Expression)arguments.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 if (e.checkSideEffect(2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 /* If calling a function or delegate that is typed as pure,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 * then this expression has no side effects.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 Type t = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 if (t.ty == TY.Tfunction && (cast(TypeFunction)t).ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 if (t.ty == TY.Tdelegate && (cast(TypeFunction)(cast(TypeDelegate)t).next).ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 expToCBuffer(buf, hgs, e1, precedence[op]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 buf.writeByte('(');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 argsToCBuffer(buf, arguments, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 buf.writeByte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 void dump(int indent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 //printf("CallExp::toElem('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 assert(e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 elem* ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 int directcall;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 Type ectype = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 elem* ehidden = irs.ehidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 irs.ehidden = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 directcall = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 fd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 if (e1.op == TOK.TOKdotvar && t1.ty != TY.Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 DotVarExp dve = cast(DotVarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 fd = dve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 Expression ex = dve.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 switch (ex.op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 case TOK.TOKsuper: // super.member() calls directly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 case TOK.TOKdottype: // type.member() calls directly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 directcall = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 case TOK.TOKcast:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 ex = (cast(CastExp)ex).e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 //ex.dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 ec = dve.e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 ectype = dve.e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 else if (e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 fd = (cast(VarExp)e1).var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 if (fd && fd.ident == Id.alloca && !fd.fbody && fd.linkage == LINK.LINKc && arguments && arguments.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 Expression arg = cast(Expression)arguments.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 arg = arg.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 if (arg.isConst() && arg.type.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 long sz = arg.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 if (sz > 0 && sz < 0x40000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 // It's an alloca(sz) of a fixed amount.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 // Replace with an array allocated on the stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 // of the same size: char[sz] tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 Symbol* stmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 .type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 assert(!ehidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 t = type_allocn(TYM.TYarray, tschar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 t.Tdim = cast(uint)sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 stmp = symbol_genauto(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 ec = el_ptr(stmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 el_setLoc(ec,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 return ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 ec = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 ec = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 ec = callfunc(loc, irs, directcall, type, ec, ectype, fd, t1, ehidden, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 el_setLoc(ec,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 return ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 void scanForNestedRef(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
1030 //printf("CallExp.scanForNestedRef(Scope *sc): %s\n", toChars());
4290d870944a More fixes
korDen
parents: 63
diff changeset
1031 e1.scanForNestedRef(sc);
4290d870944a More fixes
korDen
parents: 63
diff changeset
1032 arrayExpressionScanForNestedRef(sc, arguments);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 int isLvalue()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 // if (type.toBasetype().ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 // return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 Type tb = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 if (tb.ty == Tfunction && (cast(TypeFunction)tb).isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 return 1; // function returns a reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 Expression toLvalue(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 if (isLvalue())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 return Expression.toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 bool canThrow()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 //printf("CallExp::canThrow() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 if (e1.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 /* If any of the arguments can throw, then this expression can throw
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 for (size_t i = 0; i < arguments.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 Expression e = cast(Expression)arguments.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 if (e && e.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 if (global.errors && !e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 return false; // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 /* If calling a function or delegate that is typed as nothrow,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 * then this expression cannot throw.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 * Note that pure functions can throw.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 Type t = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 if (t.ty == TY.Tfunction && (cast(TypeFunction)t).isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 if (t.ty == TY.Tdelegate && (cast(TypeFunction)(cast(TypeDelegate)t).next).isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 CallExp ce = cast(CallExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 ce.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 ce.arguments = arrayExpressiondoInline(arguments, ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 return ce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 Expression inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 //printf("CallExp.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 arrayInlineScan(iss, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 if (e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 FuncDeclaration fd = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 if (fd && fd != iss.fd && fd.canInline(0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 e = fd.doInline(iss, null, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 else if (e1.op == TOKdotvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 DotVarExp dve = cast(DotVarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 FuncDeclaration fd = dve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 if (fd && fd != iss.fd && fd.canInline(1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 if (dve.e1.op == TOKcall &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 dve.e1.type.toBasetype().ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 /* To create ethis, we'll need to take the address
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 * of dve.e1, but this won't work if dve.e1 is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 * a function call.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 e = fd.doInline(iss, dve.e1, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141