annotate dmd/expression/Util.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents 010eb8f0e18d
children af1bebfd96a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 109
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
6 import dmd.RealExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.DelegateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.VoidInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.NewExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.IndexExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.CommaExp;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
27 import dmd.CondExp;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
28 import dmd.Parameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.DefaultInitExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.MATCH;
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
39 import dmd.BUILTIN;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.declaration.Match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.FuncAliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import dmd.PREC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import dmd.TypeAArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 import dmd.Id;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 109
diff changeset
67 import dmd.PtrExp;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
68 import dmd.ErrorExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 import std.stdio : writef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
72 import core.stdc.math;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
73 import core.stdc.string;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 * Utility to build a function call out of this reference and argument.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Expression build_overload(Loc loc, Scope sc, Expression ethis, Expression earg, Identifier id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 //printf("build_overload(id = '%s')\n", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 //earg.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 //earg.type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 e = new DotIdExp(loc, ethis, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (earg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 e = new CallExp(loc, e, earg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 e = new CallExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 * Search for function funcid in aggregate ad.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 Dsymbol search_function(ScopeDsymbol ad, Identifier funcid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 TemplateDeclaration td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 s = ad.search(Loc(0), funcid, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Dsymbol s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 //printf("search_function: s = '%s'\n", s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 s2 = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 //printf("search_function: s2 = '%s'\n", s2.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 fd = s2.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (fd && fd.type.ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 return fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 td = s2.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 * Find function in overload list that exactly matches t.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 /***************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 * Visit each overloaded function in turn, and call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 * dg(param, f) on it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 * Exit when no more, or dg(param, f) returns 1.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 * 0 continue
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 * 1 done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
139 int overloadApply(FuncDeclaration fstart, int delegate(void*, FuncDeclaration) dg, void* param)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 FuncDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 Declaration d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 Declaration next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 for (d = fstart; d; d = next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 FuncAliasDeclaration fa = d.isFuncAliasDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (fa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
151 if (overloadApply(fa.funcalias, dg, param))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 next = fa.overnext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 AliasDeclaration a = d.isAliasDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 if (a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 Dsymbol s = a.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 next = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (next is a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (next is fstart)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 f = d.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (f is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 d.error("is aliased to a function");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 break; // BUG: should print error message?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
176 if (dg(param, f))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 next = f.overnext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 * Decide which function matches the arguments best.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 struct Param2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 Match* m;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
193 version(DMDV2) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Expression ethis;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
195 int property; // 0: unintialized
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
196 // 1: seen @property
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
197 // 2: not @property
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
198 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
201 int fp2(void* param, FuncDeclaration f)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
202 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
203 auto p = cast(Param2*)param;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 MATCH match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 if (f != m.lastf) // skip duplicates
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 m.anyf = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 TypeFunction tf = cast(TypeFunction)f.type;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
210
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
211 int property = (tf.isproperty) ? 1 : 2;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
212 if (p.property == 0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
213 p.property = property;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
214 else if (p.property != property)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
215 error(f.loc, "cannot overload both property and non-property functions");
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
216
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 match = tf.callMatch(f.needThis() ? ethis : null, arguments);
98
5c859d5fbe27 and more
Trass3r
parents: 84
diff changeset
218 //printf("test: match = %d\n", match);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if (match != MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 if (match > m.last)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 goto LfIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (match < m.last)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 goto LlastIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 /* See if one of the matches overrides the other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 if (m.lastf.overrides(f))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 goto LlastIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 else if (f.overrides(m.lastf))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 goto LfIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
234 version(DMDV2) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 /* Try to disambiguate using template-style partial ordering rules.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 * In essence, if f() and g() are ambiguous, if f() can call g(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 * but g() cannot call f(), then pick f().
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 * This is because f() is "more specialized."
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 MATCH c1 = f.leastAsSpecialized(m.lastf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 MATCH c2 = m.lastf.leastAsSpecialized(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 //printf("c1 = %d, c2 = %d\n", c1, c2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (c1 > c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 goto LfIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (c1 < c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 goto LlastIsBetter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
249 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 Lambiguous:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 m.nextf = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 m.count++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 LfIsBetter:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 m.last = match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 m.lastf = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 m.count = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 LlastIsBetter:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 struct Param1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 Type t; // type to match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 FuncDeclaration f; // return value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
275 int fp1(void*, FuncDeclaration f)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 if (t.equals(f.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 this.f = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 version (DMDV2) {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
284 /* Allow covariant matches, as long as the return type
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
285 * is just a const conversion.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
286 * This allows things like pure functions to match with an impure function type.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
287 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 if (t.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 TypeFunction tf = cast(TypeFunction)f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 if (tf.covariant(t) == 1 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 tf.nextOf().implicitConvTo(t.nextOf()) >= MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 this.f = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 void overloadResolveX(Match* m, FuncDeclaration fstart, Expression ethis, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 Param2 p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 p.m = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 p.ethis = ethis;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
308 p.property = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 p.arguments = arguments;
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
310 overloadApply(fstart, &p.fp2, &p);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 void templateResolve(Match* m, TemplateDeclaration td, Scope sc, Loc loc, Objects targsi, Expression ethis, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 assert(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 fd = td.deduceFunctionTemplate(sc, loc, targsi, ethis, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 m.anyf = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (m.last >= MATCH.MATCHexact)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 m.nextf = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 m.count++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 m.last = MATCH.MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 m.lastf = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 m.count = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 * Perform semantic() on an array of Expressions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 void arrayExpressionSemantic(Expressions exps, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 if (exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
343 foreach (ref Expression e; exps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
350 Expressions arrayExpressionToCommonType(Scope sc, Expressions exps, Type *pt)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
351 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
352 //version(DMDV1) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
353 // /* The first element sets the type
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
354 // */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
355 // Type *t0 = NULL;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
356 // for (size_t i = 0; i < exps->dim; i++)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
357 // { Expression *e = (Expression *)exps->data[i];
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
358 //
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
359 // if (!e->type)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
360 // { error("%s has no value", e->toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
361 // e = new ErrorExp();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
362 // }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
363 // e = resolveProperties(sc, e);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
364 //
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
365 // if (!t0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
366 // t0 = e->type;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
367 // else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
368 // e = e->implicitCastTo(sc, t0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
369 // exps->data[i] = (void *)e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
370 // }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
371 //
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
372 // if (!t0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
373 // t0 = Type::tvoid;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
374 // if (pt)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
375 // *pt = t0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
376 //
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
377 // // Eventually, we want to make this copy-on-write
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
378 // return exps;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
379 //}
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
380 version(DMDV2) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
381 /* The type is determined by applying ?: to each pair.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
382 */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
383 /* Still have a problem with:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
384 * ubyte[][] = [ cast(ubyte[])"hello", [1]];
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
385 * which works if the array literal is initialized top down with the ubyte[][]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
386 * type, but fails with this function doing bottom up typing.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
387 */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
388 //printf("arrayExpressionToCommonType()\n");
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
389 scope integerexp = new IntegerExp(0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
390 scope condexp = new CondExp(Loc(0), integerexp, null, null);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
391
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
392 Type t0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
393 Expression e0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
394 int j0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
395 foreach (size_t i, Expression e; exps)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
396 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
397 e = resolveProperties(sc, e);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
398 if (!e.type)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
399 { error("%s has no value", e.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
400 e = new ErrorExp();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
401 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
402
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
403 if (t0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
404 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
405 if (t0 != e.type)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
406 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
407 /* This applies ?: to merge the types. It's backwards;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
408 * ?: should call this function to merge types.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
409 */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
410 condexp.type = null;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
411 condexp.e1 = e0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
412 condexp.e2 = e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
413 condexp.semantic(sc);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
414 exps[j0] = condexp.e1;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
415 e = condexp.e2;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
416 j0 = i;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
417 e0 = e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
418 t0 = e0.type;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
419 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
420 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
421 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
422 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
423 j0 = i;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
424 e0 = e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
425 t0 = e.type;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
426 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
427 exps[i] = e;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
428 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
429
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
430 if (t0)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
431 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
432 foreach (ref Expression e; exps)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
433 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
434 e = e.implicitCastTo(sc, t0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
435 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
436 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
437 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
438 t0 = Type.tvoid; // [] is typed as void[]
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
439 if (pt)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
440 *pt = t0;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
441
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
442 // Eventually, we want to make this copy-on-write
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
443 return exps;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
444 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
445 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
446
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 * Preprocess arguments to function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
451 void preFunctionParameters(Loc loc, Scope sc, Expressions exps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 if (exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 expandTuples(exps);
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
456
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
457 foreach (size_t i, ref Expression arg; exps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 debug {
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
462 if (!global.gag) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 writef("1: \n");
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
464 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 arg.error("%s is not an expression", arg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 arg = new IntegerExp(arg.loc, 0, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 arg = resolveProperties(sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 //arg.rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 if (arg.type.ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 arg = new AddrExp(arg.loc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 arg = arg.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 /*************************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 * Given var, we need to get the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 * right 'this' pointer if var is in an outer class, but our
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 * existing 'this' pointer is in an inner class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 * e1 existing 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 * ad struct or class we need the correct 'this' for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 * var the specific member of ad we're accessing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 Expression getRightThis(Loc loc, Scope sc, AggregateDeclaration ad, Expression e1, Declaration var)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 //printf("\ngetRightThis(e1 = %s, ad = %s, var = %s)\n", e1.toChars(), ad.toChars(), var.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 Type t = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 //printf("e1.type = %s, var.type = %s\n", e1.type.toChars(), var.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 /* If e1 is not the 'this' pointer for ad
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 if (ad && !(t.ty == TY.Tpointer && t.nextOf().ty == TY.Tstruct && (cast(TypeStruct)t.nextOf()).sym == ad) && !(t.ty == TY.Tstruct && (cast(TypeStruct)t).sym == ad))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 ClassDeclaration cd = ad.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 ClassDeclaration tcd = t.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 /* e1 is the right this if ad is a base class of e1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 if (!cd || !tcd || !(tcd == cd || cd.isBaseOf(tcd, null)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 /* Only classes can be inner classes with an 'outer'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 * member pointing to the enclosing class instance
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 if (tcd && tcd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 /* e1 is the 'this' pointer for an inner class: tcd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 * Rewrite it as the 'this' pointer for the outer class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 e1 = new DotVarExp(loc, e1, tcd.vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 e1.type = tcd.vthis.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 // Do not call checkNestedRef()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 //e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 // Skip up over nested functions, and get the enclosing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 // class type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 int n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 for (s = tcd.toParent(); s && s.isFuncDeclaration(); s = s.toParent())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 FuncDeclaration f = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 if (f.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 //printf("rewriting e1 to %s's this\n", f.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 n++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 e1 = new VarExp(loc, f.vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 if (s && s.isClassDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 e1.type = s.isClassDeclaration().type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 if (n > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 /* Can't find a path from e1 to ad
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 e1.error("this for %s needs to be type %s not type %s", var.toChars(), ad.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 * Given a symbol that could be either a FuncDeclaration or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 * a function template, resolve it to a function symbol.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 * sc instantiation scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 * loc instantiation location
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 * targsi initial list of template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 * ethis if !null, the 'this' pointer argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 * fargs arguments to function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 * flags 1: do not issue error message on no match, just return null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 FuncDeclaration resolveFuncCall(Scope sc, Loc loc, Dsymbol s,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 Objects tiargs,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 Expression ethis,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 Expressions arguments,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 return null; // no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 FuncDeclaration f = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 f = f.overloadResolve(loc, ethis, arguments);
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 TemplateDeclaration td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 assert(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 f = td.deduceFunctionTemplate(sc, loc, tiargs, null, arguments, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 * Now that we know the exact type of the function we're calling,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 * the arguments[] need to be adjusted:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 * 1. implicitly convert argument to the corresponding parameter type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 * 2. add default arguments for any missing arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 * 3. do default promotions on arguments corresponding to ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 * 4. add hidden _arguments[] argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 * 5. call copy constructor for struct value arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
599 void functionParameters(Loc loc, Scope sc, TypeFunction tf, Expressions arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 uint n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
603 //printf("functionParameters()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 assert(arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 size_t nargs = arguments ? arguments.dim : 0;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
606 size_t nparams = Parameter.dim(tf.parameters);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 if (nargs > nparams && tf.varargs == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 error(loc, "expected %zu arguments, not %zu for non-variadic function type %s", nparams, nargs, tf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 int done = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 for (size_t i = 0; i < n; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 if (i < nargs)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
619 arg = arguments[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 arg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 if (i < nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
627 auto p = Parameter.getNth(tf.parameters, i);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 if (!arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 if (!p.defaultArg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 if (tf.varargs == 2 && i + 1 == nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 error(loc, "expected %d function arguments, not %d", nparams, nargs);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
637 return;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 arg = p.defaultArg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 arg = arg.copy();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
641 version (DMDV2)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
642 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
643 arg = arg.resolveLoc(loc, sc); // __FILE__ and __LINE__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 }
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
645 arguments.push(arg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 nargs++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 if (tf.varargs == 2 && i + 1 == nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 //printf("\t\tvarargs == 2, p.type = '%s'\n", p.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 if (arg.implicitConvTo(p.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 if (nargs != nparams)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
655 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 error(loc, "expected %zu function arguments, not %zu", nparams, nargs);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
657 return;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
658 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 tb = p.type.toBasetype(); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 Type tret = p.isLazyArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 switch (tb.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 { // Create a static array variable v of type arg.type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 /* GCC 4.0 does not like zero length arrays used like
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 this; pass a null array value instead. Could also
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 just make a one-element array. */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 if (nargs - i == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 arg = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 Identifier id = Lexer.uniqueId("__arrayArg");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 Type t = new TypeSArray((cast(TypeArray)tb).next, new IntegerExp(nargs - i));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 t = t.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 VarDeclaration v = new VarDeclaration(loc, t, id, new VoidInitializer(loc));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 v.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 v.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 //sc.insert(v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 Expression c = new DeclarationExp(Loc(0), v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 c.type = v.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 for (size_t u = i; u < nargs; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
692 auto a = arguments[u];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 if (tret && !(cast(TypeArray)tb).next.equals(a.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 a = a.toDelegate(sc, tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 Expression e = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 e = new IndexExp(loc, e, new IntegerExp(u + 1 - nparams));
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
698 auto ae = new AssignExp(loc, e, a);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 ae.op = TOK.TOKconstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 if (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 c = new CommaExp(loc, c, ae);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 c = ae;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 arg = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 if (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 arg = new CommaExp(loc, c, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 case TY.Tclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 { /* Set arg to be:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 * new Tclass(arg0, arg1, ..., argn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 Expressions args = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 args.setDim(nargs - i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 for (size_t u = i; u < nargs; u++)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
723 args[u - i] = arguments[u];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 arg = new NewExp(loc, null, null, p.type, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 if (!arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 error(loc, "not enough arguments");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 arg = arg.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 //printf("\targ = '%s'\n", arg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 arguments.setDim(i + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 done = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 if (!(p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 if (p.type != arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 //printf("arg.type = %s, p.type = %s\n", arg.type.toChars(), p.type.toChars());
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
749 if (arg.op == TOKtype)
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
750 arg.error("cannot pass type %s as function argument", arg.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 arg = arg.implicitCastTo(sc, p.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 arg = arg.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 if (p.storageClass & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 arg = arg.toLvalue(sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 else if (p.storageClass & STC.STCout)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 arg = arg.modifiableLvalue(sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
764 tb = arg.type.toBasetype();
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
765 version(SARRAYVALUE) {} else
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
766 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 // Convert static arrays to pointers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if (tb.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 arg = arg.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 }
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 98
diff changeset
772 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 if (tb.ty == TY.Tstruct && !(p.storageClass & (STC.STCref | STC.STCout)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 arg = callCpCtor(loc, sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 // Convert lazy argument to a delegate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 if (p.storageClass & STC.STClazy)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 arg = arg.toDelegate(sc, p.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 /* Look for arguments that cannot 'escape' from the called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 * function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 if (!tf.parameterEscapes(p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 /* Function literals can only appear once, so if this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 * appearance was scoped, there cannot be any others.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 if (arg.op == TOK.TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 FuncExp fe = cast(FuncExp)arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 fe.fd.tookAddressOf = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 /* For passing a delegate to a scoped parameter,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 * this doesn't count as taking the address of it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 * We only worry about 'escaping' references to the function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 else if (arg.op == TOK.TOKdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 DelegateExp de = cast(DelegateExp)arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 if (de.e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 VarExp ve = cast(VarExp)de.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 FuncDeclaration f = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 f.tookAddressOf--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 //printf("tookAddressOf = %d\n", f.tookAddressOf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 // If not D linkage, do promotions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 if (tf.linkage != LINK.LINKd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 // Promote bytes, words, etc., to ints
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 arg = arg.integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 // Promote floats to doubles
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 switch (arg.type.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 case TY.Tfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 arg = arg.castTo(sc, Type.tfloat64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 case TY.Timaginary32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 arg = arg.castTo(sc, Type.timaginary64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 // Convert static arrays to dynamic arrays
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 tb = arg.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 if (tb.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 TypeSArray ts = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 Type ta = ts.next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 if (ts.size(arg.loc) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 arg = new NullExp(arg.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 arg.type = ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 arg = arg.castTo(sc, ta);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 version (DMDV2) {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
861 if (tb.ty == Tstruct)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 arg = callCpCtor(loc, sc, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 }
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
865 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
867 // Give error for overloaded function addresses
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
868 if (arg.op == TOKsymoff)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
869 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
870 SymOffExp se = cast(SymOffExp)arg;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
871 version (DMDV2) {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
872 bool aux = (se.hasOverloads != 0);
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
873 } else {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
874 bool aux = true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 }
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
876 if (aux && !se.var.isFuncDeclaration().isUnique())
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
877 arg.error("function %s is overloaded", arg.toChars());
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
878 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
879
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
880 arg.rvalue();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
881 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 64
diff changeset
882
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 arg = arg.optimize(WANT.WANTvalue);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
884 arguments[i] = arg;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 if (done)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 // If D linkage and variadic, add _arguments[] as first argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 if (tf.linkage == LINK.LINKd && tf.varargs == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
892 assert(arguments.dim >= nparams);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
893 auto e = createTypeInfoArray(sc, &arguments[nparams], arguments.dim - nparams);
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
894 arguments.insert(0, e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
898 /******************************
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
899 * Perform canThrow() on an array of Expressions.
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
900 */
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
901
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
902 version (DMDV2) {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
903 bool arrayExpressionCanThrow(Expressions exps)
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
904 {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
905 if (exps)
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
906 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
907 foreach (e; exps)
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
908 {
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
909 if (e && e.canThrow())
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
910 return true;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
911 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
912 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
913 return false;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
914 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
915 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
916
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 * Expand tuples.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 void expandTuples(Expressions exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 //printf("expandTuples()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 if (exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 for (size_t i = 0; i < exps.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
928 auto arg = exps[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 if (!arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 // Look for tuple with 0 members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 if (arg.op == TOK.TOKtype)
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
934 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
935 auto e = cast(TypeExp)arg;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 if (e.type.toBasetype().ty == TY.Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
938 auto tt = cast(TypeTuple)e.type.toBasetype();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 if (!tt.arguments || tt.arguments.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 exps.remove(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 if (i == exps.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 i--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 // Inline expand all the tuples
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 while (arg.op == TOK.TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
954 auto te = cast(TupleExp)arg;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 exps.remove(i); // remove arg
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
957 exps.insert(i, te.exps); // replace with tuple contents
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 if (i == exps.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 return; // empty tuple, no more arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
962 arg = exps[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 /**************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 * Write out argument types to buf.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 void argExpTypesToCBuffer(OutBuffer buf, Expressions arguments, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 scope OutBuffer argbuf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
978 foreach (size_t i, Expression arg; arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 buf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 argbuf.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 arg.type.toCBuffer2(argbuf, hgs, MOD.MODundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 buf.write(argbuf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 * Determine if scope sc has package level access to s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 bool hasPackageAccess(Scope sc, Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 printf("hasPackageAccess(s = '%s', sc = '%p')\n", s.toChars(), sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 for (; s; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 if (s.isPackage() && !s.isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 printf("\tthis is in package '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 if (s && s == sc.module_.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 printf("\ts is in same package as sc\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 printf("\tno package access\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 /*********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 * Call copy constructor for struct value argument.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 Expression callCpCtor(Loc loc, Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 Type tb = e.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 assert(tb.ty == Tstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 StructDeclaration sd = (cast(TypeStruct)tb).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 if (sd.cpctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 /* Create a variable tmp, and replace the argument e with:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 * (tmp = e),tmp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 * and let AssignExp() handle the construction.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 * This is not the most efficent, ideally tmp would be constructed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 * directly onto the stack.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 Identifier idtmp = Lexer.uniqueId("__tmp");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 VarDeclaration tmp = new VarDeclaration(loc, tb, idtmp, new ExpInitializer(Loc(0), e));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 Expression ae = new DeclarationExp(loc, tmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 e = new CommaExp(loc, ae, new VarExp(loc, tmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 * Create a static array of TypeInfo references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 * corresponding to an array of Expression's.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 * Used to supply hidden _arguments[] value for variadic D functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 Expression createTypeInfoArray(Scope sc, Expression* exps, int dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1061 static if (true)
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1062 {
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1063 /* Get the corresponding TypeInfo_Tuple and
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1064 * point at its elements[].
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1065 */
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1066
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1067 /* Create the TypeTuple corresponding to the types of args[]
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1068 */
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1069 auto args = new Parameters;
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1070 args.setDim(dim);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1071 for (size_t i = 0; i < dim; i++)
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1072 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1073 auto arg = new Parameter(STCin, exps[i].type, null, null);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1074 args[i] = arg;
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1075 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1076 TypeTuple tup = new TypeTuple(args);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1077 Expression e = tup.getTypeInfo(sc);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1078 e = e.optimize(WANTvalue);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1079 assert(e.op == TOKsymoff); // should be SymOffExp
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1080
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1081 version (BREAKABI)
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1082 {
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1083 /*
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1084 * Should just pass a reference to TypeInfo_Tuple instead,
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1085 * but that would require existing code to be recompiled.
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1086 * Source compatibility can be maintained by computing _arguments[]
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1087 * at the start of the called function by offseting into the
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1088 * TypeInfo_Tuple reference.
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1089 */
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1090
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1091 }
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1092 else
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1093 {
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1094 // Advance to elements[] member of TypeInfo_Tuple
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1095 SymOffExp se = cast(SymOffExp)e;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1096 se.offset += PTRSIZE + PTRSIZE;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1097
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1098 // Set type to TypeInfo[]*
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1099 se.type = Type.typeinfo.type.arrayOf().pointerTo();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1100
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1101 // Indirect to get the _arguments[] value
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1102 e = new PtrExp(Loc(0), se);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1103 e.type = se.type.next;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1104 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1105 return e;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1106 } // of static if (true)
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1107 else
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1108 {
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1109 /* Improvements:
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1110 * 1) create an array literal instead,
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1111 * as it would eliminate the extra dereference of loading the
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1112 * static variable.
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1113 */
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1114
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1115 ArrayInitializer ai = new ArrayInitializer(Loc(0));
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1116 VarDeclaration v;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1117 Type t;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1118 Expression e;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1119 scope OutBuffer buf = new OutBuffer();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1120 Identifier id;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1121 string name;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1122
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1123 // Generate identifier for _arguments[]
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1124 buf.writestring("_arguments_");
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1125 for (int i = 0; i < dim; i++)
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1126 {
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1127 t = exps[i].type;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1128 t.toDecoBuffer(buf);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1129 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1130 buf.writeByte(0);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1131 id = Lexer.idPool(buf.extractString());
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1132
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1133 Module m = sc.module_;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1134 Dsymbol s = m.symtab.lookup(id);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1135
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1136 if (s && s.parent == m)
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1137 {
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1138 // Use existing one
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1139 v = s.isVarDeclaration();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1140 assert(v);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1141 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1142 else
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1143 {
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1144 // Generate new one
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1145
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1146 for (int i = 0; i < dim; i++)
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1147 {
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1148 t = exps[i].type;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1149 e = t.getTypeInfo(sc);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1150 ai.addInit(new IntegerExp(i), new ExpInitializer(0, e));
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1151 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1152
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1153 t = Type.typeinfo.type.arrayOf();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1154 ai.type = t;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1155 v = new VarDeclaration(0, t, id, ai);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1156 m.members.push(v);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1157 m.symtabInsert(v);
57
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1158 sc = sc.push();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1159 sc.linkage = LINKc;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1160 sc.stc = STCstatic | STCcomdat;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1161 ai.semantic(sc, t);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1162 v.semantic(sc);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1163 v.parent = m;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1164 sc = sc.pop();
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1165 }
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1166 e = new VarExp(0, v);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1167 e = e.semantic(sc);
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1168 return e;
3adbb28755e8 createTypeInfoArray implemented
korDen
parents: 53
diff changeset
1169 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 * Evaluate builtin function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 * Return result: null if cannot evaluate it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1177 extern(C) extern real sinl(real);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1178 extern(C) extern real cosl(real);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1179 extern(C) extern real tanl(real);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1180 extern(C) extern real sqrtl(real);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1181 extern(C) extern real fabsl(real);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1182
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 Expression eval_builtin(BUILTIN builtin, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1185 assert(arguments && arguments.dim);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1186 auto arg0 = arguments[0];
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1187 Expression e = null;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1188 switch (builtin)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1189 {
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1190 case BUILTINsin:
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1191 if (arg0.op == TOKfloat64)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1192 e = new RealExp(Loc(0), sinl(arg0.toReal()), arg0.type);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1193 break;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1194
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1195 case BUILTINcos:
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1196 if (arg0.op == TOKfloat64)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1197 e = new RealExp(Loc(0), cosl(arg0.toReal()), arg0.type);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1198 break;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1199
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1200 case BUILTINtan:
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1201 if (arg0.op == TOKfloat64)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1202 e = new RealExp(Loc(0), tanl(arg0.toReal()), arg0.type);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1203 break;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1204
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1205 case BUILTINsqrt:
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1206 if (arg0.op == TOKfloat64)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1207 e = new RealExp(Loc(0), sqrtl(arg0.toReal()), arg0.type);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1208 break;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1209
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1210 case BUILTINfabs:
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1211 if (arg0.op == TOKfloat64)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1212 e = new RealExp(Loc(0), fabsl(arg0.toReal()), arg0.type);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1213 break;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1214 }
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1215 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 Expression fromConstInitializer(int result, Expression e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 //printf("fromConstInitializer(result = %x, %s)\n", result, e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 //static int xx; if (xx++ == 10) assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 Expression e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 if (e1.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 VarDeclaration v = ve.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 e = expandVar(result, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 if (e.type != e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 // Type 'paint' operation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 e = e.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 e.type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
1236 e.loc = e1.loc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 * If variable has a const initializer,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 * return that initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 Expression expandVar(int result, VarDeclaration v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 //printf("expandVar(result = %d, v = %p, %s)\n", result, v, v ? v.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 if (!v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 if (v.isConst() || v.isInvariant() || v.storage_class & STC.STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 if (!v.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 //error("ICE");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 Type tb = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 if (result & WANT.WANTinterpret || v.storage_class & STC.STCmanifest || (tb.ty != TY.Tsarray && tb.ty != TY.Tstruct))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 if (v.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 if (v.inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 if (v.storage_class & STC.STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 v.error("recursive initialization of constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 Expression ei = v.init.toExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 if (!ei)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 if (ei.op == TOK.TOKconstruct || ei.op == TOK.TOKblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 AssignExp ae = cast(AssignExp)ei;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 ei = ae.e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 if (ei.isConst() != 1 && ei.op != TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 if (ei.type != v.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 if (v.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 v.inuse++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 e = ei.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 e = e.semantic(v.scope_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 e = e.implicitCastTo(v.scope_, v.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 // enabling this line causes test22 in test suite to fail
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 //ei.type = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 v.scope_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 v.inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 else if (!ei.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 // Should remove the copy() operation by
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 // making all mods to expressions copy-on-write
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 e = ei.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 // BUG: what if const is initialized in constructor?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 e = v.type.defaultInit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 e.loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 if (e.type != v.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 e = e.castTo(null, v.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 v.inuse++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 e = e.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 v.inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 //if (e) printf("\te = %s, e.type = %s\n", e.toChars(), e.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 * Check access to d for expression e.d
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 void accessCheck(Loc loc, Scope sc, Expression e, Declaration d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 printf("accessCheck(%s . %s)\n", e.toChars(), d.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 printf("\te.type = %s\n", e.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 //printf("accessCheck(%s)\n", d.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 if (!e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 if (d.prot() == PROT.PROTprivate && d.getModule() != sc.module_ ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 d.prot() == PROT.PROTpackage && !hasPackageAccess(sc, d))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 error(loc, "%s %s.%s is not accessible from %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 d.kind(), d.getModule().toChars(), d.toChars(), sc.module_.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 else if (e.type.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 // Do access check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 cd = cast(ClassDeclaration)((cast(TypeClass)e.type).sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 if (e.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 ClassDeclaration cd2 = sc.func.toParent().isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 if (cd2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 cd = cd2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 cd.accessCheck(loc, sc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 else if (e.type.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 // Do access check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 StructDeclaration cd = cast(StructDeclaration)((cast(TypeStruct)e.type).sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 cd.accessCheck(loc, sc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 * Given array of arguments and an aggregate type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 * if any of the argument types are missing, attempt to infer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 * them from the aggregate type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1389 void inferApplyArgTypes(TOK op, Parameters arguments, Expression aggr)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 if (!arguments || !arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 /* Return if no arguments need types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 for (size_t u = 0; 1; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 if (u == arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1401 auto arg = arguments[u];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1408 auto arg = arguments[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 Type taggr = aggr.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 if (!taggr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 Type tab = taggr.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 switch (tab.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 case TY.Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 if (arguments.dim == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 arg.type = Type.tsize_t; // key type
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1422 arg = arguments[1];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 if (!arg.type && tab.ty != TY.Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 arg.type = tab.nextOf(); // value type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 case TY.Taarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1430 auto taa = cast(TypeAArray)tab;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 if (arguments.dim == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 arg.type = taa.index; // key type
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1436 arg = arguments[1];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 arg.type = taa.next; // value type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 case TY.Tclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 ad = (cast(TypeClass)tab).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 goto Laggr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 case TY.Tstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 ad = (cast(TypeStruct)tab).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 goto Laggr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 Laggr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 if (arguments.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 /* Look for a head() or rear() overload
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 Identifier id = (op == TOK.TOKforeach) ? Id.Fhead : Id.Ftoe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 Dsymbol s = search_function(ad, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 FuncDeclaration fd = s ? s.isFuncDeclaration() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 if (s && s.isTemplateDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 goto Lapply;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 arg.type = fd.type.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 Lapply:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 { /* Look for an
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 * int opApply(int delegate(ref Type [, ...]) dg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 * overload
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 Dsymbol s = search_function(ad, (op == TOK.TOKforeach_reverse) ? Id.applyReverse : Id.apply);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 FuncDeclaration fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 inferApplyArgTypesX(fd, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 TemplateDeclaration td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 inferApplyArgTypesZ(td, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 case TY.Tdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 if (0 && aggr.op == TOK.TOKdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 DelegateExp de = cast(DelegateExp)aggr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 FuncDeclaration fd = de.func.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 inferApplyArgTypesX(fd, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 inferApplyArgTypesY(cast(TypeFunction)tab.nextOf(), arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 break; // ignore error, caught later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 struct Param3
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 * Recursive helper function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 * analogous to func.overloadResolveX().
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
1527 int fp3(void*, FuncDeclaration f)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1529 auto tf = cast(TypeFunction)f.type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 if (inferApplyArgTypesY(tf, arguments) == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 if (arguments.dim == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1539 Parameters arguments;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1542 void inferApplyArgTypesX(FuncDeclaration fstart, Parameters arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 Param3 p3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 p3.arguments = arguments;
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 16
diff changeset
1546 overloadApply(fstart, &p3.fp3, cast(void*)arguments);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 * Infer arguments from type of function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 * 0 match for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 * 1 no match for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1556 int inferApplyArgTypesY(TypeFunction tf, Parameters arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 size_t nparams;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1559 Parameter p;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1561 if (Parameter.dim(tf.parameters) != 1)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1564 p = Parameter.getNth(tf.parameters, 0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 if (p.type.ty != TY.Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 tf = cast(TypeFunction)p.type.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 assert(tf.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 /* We now have tf, the type of the delegate. Match it against
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 * the arguments, filling in missing argument types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 */
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1574 nparams = Parameter.dim(tf.parameters);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 if (nparams == 0 || tf.varargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 goto Lnomatch; // not enough parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 if (arguments.dim != nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 goto Lnomatch; // not enough parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 for (size_t u = 0; u < nparams; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1582 auto arg = arguments[u];
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1583 auto param = Parameter.getNth(tf.parameters, u);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 if (arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586 if (!arg.type.equals(param.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 /* Cannot resolve argument types. Indicate an
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 * error by setting the number of arguments to 0.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1590 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591 arguments.dim = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 arg.type = param.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 Lmatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 Lnomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 /**************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 * Write expression out to buf, but wrap it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 * in ( ) if its precedence is less than pr.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611 void expToCBuffer(OutBuffer buf, HdrGenState* hgs, Expression e, PREC pr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 //if (precedence[e.op] == 0) e.dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 if (precedence[e.op] < pr ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 /* Despite precedence, we don't allow a<b<c expressions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 * They must be parenthesized.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 (pr == PREC.PREC_rel && precedence[e.op] == pr))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 buf.writeByte('(');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 e.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 buf.writeByte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 e.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 /**************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 * Write out argument list to buf.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 void argsToCBuffer(OutBuffer buf, Expressions arguments, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1636 foreach (size_t i, Expression arg; arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 if (arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 buf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 expToCBuffer(buf, hgs, arg, PREC.PREC_assign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1646 }
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1647
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1648 ulong getMask(ulong v)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1649 {
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1650 ulong u = 0;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1651 if (v >= 0x80)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1652 u = 0xFF;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1653 while (u < v)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1654 u = (u << 1) | 1;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 17
diff changeset
1655 return u;
64
4290d870944a More fixes
korDen
parents: 57
diff changeset
1656 }
4290d870944a More fixes
korDen
parents: 57
diff changeset
1657
4290d870944a More fixes
korDen
parents: 57
diff changeset
1658 /******************************
4290d870944a More fixes
korDen
parents: 57
diff changeset
1659 * Perform scanForNestedRef() on an array of Expressions.
4290d870944a More fixes
korDen
parents: 57
diff changeset
1660 */
4290d870944a More fixes
korDen
parents: 57
diff changeset
1661
4290d870944a More fixes
korDen
parents: 57
diff changeset
1662 void arrayExpressionScanForNestedRef(Scope sc, Expressions a)
4290d870944a More fixes
korDen
parents: 57
diff changeset
1663 {
4290d870944a More fixes
korDen
parents: 57
diff changeset
1664 //printf("arrayExpressionScanForNestedRef(%p)\n", a);
4290d870944a More fixes
korDen
parents: 57
diff changeset
1665 if (a)
4290d870944a More fixes
korDen
parents: 57
diff changeset
1666 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
1667 foreach (e; a)
64
4290d870944a More fixes
korDen
parents: 57
diff changeset
1668 {
4290d870944a More fixes
korDen
parents: 57
diff changeset
1669 if (e)
4290d870944a More fixes
korDen
parents: 57
diff changeset
1670 {
4290d870944a More fixes
korDen
parents: 57
diff changeset
1671 e.scanForNestedRef(sc);
4290d870944a More fixes
korDen
parents: 57
diff changeset
1672 }
4290d870944a More fixes
korDen
parents: 57
diff changeset
1673 }
4290d870944a More fixes
korDen
parents: 57
diff changeset
1674 }
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1675 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1676
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1677 void realToMangleBuffer(OutBuffer buf, real value)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1678 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1679 /* Rely on %A to get portable mangling.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1680 * Must munge result to get only identifier characters.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1681 *
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1682 * Possible values from %A => mangled result
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1683 * NAN => NAN
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1684 * -INF => NINF
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1685 * INF => INF
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1686 * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1687 * 0X1.9P+2 => 19P2
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1688 */
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1689
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1690 if (isnan(value))
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1691 buf.writestring("NAN"); // no -NAN bugs
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1692 else
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1693 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1694 char buffer[32];
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1695 int n = sprintf(buffer.ptr, "%LA", value);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1696 assert(n > 0 && n < buffer.sizeof);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1697 for (int i = 0; i < n; i++)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1698 { char c = buffer[i];
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1699
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1700 switch (c)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1701 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1702 case '-':
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1703 buf.writeByte('N');
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1704 break;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1705
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1706 case '+':
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1707 case 'X':
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1708 case '.':
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1709 break;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1710
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1711 case '0':
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1712 if (i < 2)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1713 break; // skip leading 0X
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1714 default:
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1715 buf.writeByte(c);
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1716 break;
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1717 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1718 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1719 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1720 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1721
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1722 /********************************
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1723 * Test to see if two reals are the same.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1724 * Regard NaN's as equivalent.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1725 * Regard +0 and -0 as different.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1726 */
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1727
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1728 int RealEquals(real x1, real x2)
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1729 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1730 return (isnan(x1) && isnan(x2)) ||
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1731 /* In some cases, the REALPAD bytes get garbage in them,
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1732 * so be sure and ignore them.
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1733 */
010eb8f0e18d further work on dmd test suite
korDen
parents: 126
diff changeset
1734 memcmp(&x1, &x2, REALSIZE - REALPAD) == 0;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
1735 }