Mercurial > projects > ldc
annotate dmd/template.h @ 933:d3a6f1a96731
Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 04 Feb 2009 00:04:09 +0100 |
parents | 330f999ade44 |
children | 39519a1ff603 |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
3 // Copyright (c) 1999-2008 by Digital Mars |
159 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #ifndef DMD_TEMPLATE_H | |
12 #define DMD_TEMPLATE_H | |
13 | |
14 #ifdef __DMC__ | |
15 #pragma once | |
16 #endif /* __DMC__ */ | |
17 | |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
18 #include <string> |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
19 |
159 | 20 #include "root.h" |
21 #include "arraytypes.h" | |
22 #include "dsymbol.h" | |
23 #include "mtype.h" | |
24 | |
25 | |
26 struct OutBuffer; | |
27 struct Identifier; | |
28 struct TemplateInstance; | |
29 struct TemplateParameter; | |
30 struct TemplateTypeParameter; | |
336 | 31 struct TemplateThisParameter; |
159 | 32 struct TemplateValueParameter; |
33 struct TemplateAliasParameter; | |
34 struct TemplateTupleParameter; | |
35 struct Type; | |
36 struct TypeTypeof; | |
37 struct Scope; | |
38 struct Expression; | |
39 struct AliasDeclaration; | |
40 struct FuncDeclaration; | |
41 struct HdrGenState; | |
42 enum MATCH; | |
43 | |
44 struct Tuple : Object | |
45 { | |
46 Objects objects; | |
47 | |
48 int dyncast() { return DYNCAST_TUPLE; } // kludge for template.isType() | |
49 }; | |
50 | |
51 | |
52 struct TemplateDeclaration : ScopeDsymbol | |
53 { | |
54 TemplateParameters *parameters; // array of TemplateParameter's | |
55 | |
56 TemplateParameters *origParameters; // originals for Ddoc | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
57 #if DMDV2 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
58 Expression *constraint; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
59 #endif |
336 | 60 Array instances; // array of TemplateInstance's |
159 | 61 |
62 TemplateDeclaration *overnext; // next overloaded TemplateDeclaration | |
63 TemplateDeclaration *overroot; // first in overnext list | |
64 | |
65 Scope *scope; | |
66 Dsymbol *onemember; // if !=NULL then one member of this template | |
67 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
68 TemplateDeclaration(Loc loc, Identifier *id, TemplateParameters *parameters, |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
69 #if DMDV2 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
70 Expression *constraint, |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
71 #endif |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
72 Array *decldefs); |
159 | 73 Dsymbol *syntaxCopy(Dsymbol *); |
74 void semantic(Scope *sc); | |
75 int overloadInsert(Dsymbol *s); | |
76 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
336 | 77 const char *kind(); |
159 | 78 char *toChars(); |
79 | |
80 void emitComment(Scope *sc); | |
81 // void toDocBuffer(OutBuffer *buf); | |
82 | |
83 MATCH matchWithInstance(TemplateInstance *ti, Objects *atypes, int flag); | |
84 int leastAsSpecialized(TemplateDeclaration *td2); | |
85 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
86 MATCH deduceFunctionTemplateMatch(Loc loc, Objects *targsi, Expression *ethis, Expressions *fargs, Objects *dedargs); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
87 FuncDeclaration *deduceFunctionTemplate(Scope *sc, Loc loc, Objects *targsi, Expression *ethis, Expressions *fargs, int flags = 0); |
159 | 88 void declareParameter(Scope *sc, TemplateParameter *tp, Object *o); |
89 | |
90 TemplateDeclaration *isTemplateDeclaration() { return this; } | |
91 | |
92 TemplateTupleParameter *isVariadic(); | |
93 int isOverloadable(); | |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
94 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
561
diff
changeset
|
95 // LDC |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
96 std::string intrinsicName; |
159 | 97 }; |
98 | |
99 struct TemplateParameter | |
100 { | |
101 /* For type-parameter: | |
102 * template Foo(ident) // specType is set to NULL | |
103 * template Foo(ident : specType) | |
104 * For value-parameter: | |
105 * template Foo(valType ident) // specValue is set to NULL | |
106 * template Foo(valType ident : specValue) | |
107 * For alias-parameter: | |
108 * template Foo(alias ident) | |
109 */ | |
110 | |
111 Loc loc; | |
112 Identifier *ident; | |
113 | |
114 Declaration *sparam; | |
115 | |
116 TemplateParameter(Loc loc, Identifier *ident); | |
117 | |
118 virtual TemplateTypeParameter *isTemplateTypeParameter(); | |
119 virtual TemplateValueParameter *isTemplateValueParameter(); | |
120 virtual TemplateAliasParameter *isTemplateAliasParameter(); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
121 #if DMDV2 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
122 virtual TemplateThisParameter *isTemplateThisParameter(); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
123 #endif |
159 | 124 virtual TemplateTupleParameter *isTemplateTupleParameter(); |
125 | |
126 virtual TemplateParameter *syntaxCopy() = 0; | |
127 virtual void declareParameter(Scope *sc) = 0; | |
128 virtual void semantic(Scope *) = 0; | |
129 virtual void print(Object *oarg, Object *oded) = 0; | |
130 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; | |
131 virtual Object *specialization() = 0; | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
132 virtual Object *defaultArg(Loc loc, Scope *sc) = 0; |
159 | 133 |
134 /* If TemplateParameter's match as far as overloading goes. | |
135 */ | |
136 virtual int overloadMatch(TemplateParameter *) = 0; | |
137 | |
138 /* Match actual argument against parameter. | |
139 */ | |
140 virtual MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) = 0; | |
141 | |
142 /* Create dummy argument based on parameter. | |
143 */ | |
144 virtual void *dummyArg() = 0; | |
145 }; | |
146 | |
147 struct TemplateTypeParameter : TemplateParameter | |
148 { | |
149 /* Syntax: | |
150 * ident : specType = defaultType | |
151 */ | |
152 Type *specType; // type parameter: if !=NULL, this is the type specialization | |
153 Type *defaultType; | |
154 | |
155 TemplateTypeParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType); | |
156 | |
157 TemplateTypeParameter *isTemplateTypeParameter(); | |
158 TemplateParameter *syntaxCopy(); | |
159 void declareParameter(Scope *sc); | |
160 void semantic(Scope *); | |
161 void print(Object *oarg, Object *oded); | |
162 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
163 Object *specialization(); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
164 Object *defaultArg(Loc loc, Scope *sc); |
159 | 165 int overloadMatch(TemplateParameter *); |
166 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
167 void *dummyArg(); | |
168 }; | |
169 | |
336 | 170 #if DMDV2 |
171 struct TemplateThisParameter : TemplateTypeParameter | |
172 { | |
173 /* Syntax: | |
174 * this ident : specType = defaultType | |
175 */ | |
176 Type *specType; // type parameter: if !=NULL, this is the type specialization | |
177 Type *defaultType; | |
178 | |
179 TemplateThisParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType); | |
180 | |
181 TemplateThisParameter *isTemplateThisParameter(); | |
182 TemplateParameter *syntaxCopy(); | |
183 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
184 }; | |
185 #endif | |
186 | |
159 | 187 struct TemplateValueParameter : TemplateParameter |
188 { | |
189 /* Syntax: | |
190 * valType ident : specValue = defaultValue | |
191 */ | |
192 | |
193 Type *valType; | |
194 Expression *specValue; | |
195 Expression *defaultValue; | |
196 | |
197 static Expression *edummy; | |
198 | |
199 TemplateValueParameter(Loc loc, Identifier *ident, Type *valType, Expression *specValue, Expression *defaultValue); | |
200 | |
201 TemplateValueParameter *isTemplateValueParameter(); | |
202 TemplateParameter *syntaxCopy(); | |
203 void declareParameter(Scope *sc); | |
204 void semantic(Scope *); | |
205 void print(Object *oarg, Object *oded); | |
206 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
207 Object *specialization(); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
208 Object *defaultArg(Loc loc, Scope *sc); |
159 | 209 int overloadMatch(TemplateParameter *); |
210 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
211 void *dummyArg(); | |
212 }; | |
213 | |
214 struct TemplateAliasParameter : TemplateParameter | |
215 { | |
216 /* Syntax: | |
217 * ident : specAlias = defaultAlias | |
218 */ | |
219 | |
220 Type *specAliasT; | |
221 Dsymbol *specAlias; | |
222 | |
223 Type *defaultAlias; | |
224 | |
225 static Dsymbol *sdummy; | |
226 | |
227 TemplateAliasParameter(Loc loc, Identifier *ident, Type *specAliasT, Type *defaultAlias); | |
228 | |
229 TemplateAliasParameter *isTemplateAliasParameter(); | |
230 TemplateParameter *syntaxCopy(); | |
231 void declareParameter(Scope *sc); | |
232 void semantic(Scope *); | |
233 void print(Object *oarg, Object *oded); | |
234 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
235 Object *specialization(); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
236 Object *defaultArg(Loc loc, Scope *sc); |
159 | 237 int overloadMatch(TemplateParameter *); |
238 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
239 void *dummyArg(); | |
240 }; | |
241 | |
242 struct TemplateTupleParameter : TemplateParameter | |
243 { | |
244 /* Syntax: | |
245 * ident ... | |
246 */ | |
247 | |
248 TemplateTupleParameter(Loc loc, Identifier *ident); | |
249 | |
250 TemplateTupleParameter *isTemplateTupleParameter(); | |
251 TemplateParameter *syntaxCopy(); | |
252 void declareParameter(Scope *sc); | |
253 void semantic(Scope *); | |
254 void print(Object *oarg, Object *oded); | |
255 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
256 Object *specialization(); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
257 Object *defaultArg(Loc loc, Scope *sc); |
159 | 258 int overloadMatch(TemplateParameter *); |
259 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
260 void *dummyArg(); | |
261 }; | |
262 | |
263 struct TemplateInstance : ScopeDsymbol | |
264 { | |
265 /* Given: | |
266 * foo!(args) => | |
267 * name = foo | |
268 * tiargs = args | |
269 */ | |
270 Identifier *name; | |
271 //Array idents; | |
272 Objects *tiargs; // Array of Types/Expressions of template | |
273 // instance arguments [int*, char, 10*10] | |
274 | |
275 Objects tdtypes; // Array of Types/Expressions corresponding | |
276 // to TemplateDeclaration.parameters | |
277 // [int, char, 100] | |
278 | |
279 TemplateDeclaration *tempdecl; // referenced by foo.bar.abc | |
280 TemplateInstance *inst; // refer to existing instance | |
281 ScopeDsymbol *argsym; // argument symbol table | |
282 AliasDeclaration *aliasdecl; // !=NULL if instance is an alias for its | |
283 // sole member | |
284 WithScopeSymbol *withsym; // if a member of a with statement | |
285 int semanticdone; // has semantic() been done? | |
336 | 286 int semantictiargsdone; // has semanticTiargs() been done? |
159 | 287 int nest; // for recursion detection |
288 int havetempdecl; // 1 if used second constructor | |
289 Dsymbol *isnested; // if referencing local symbols, this is the context | |
290 int errors; // 1 if compiled with errors | |
291 #ifdef IN_GCC | |
292 /* On some targets, it is necessary to know whether a symbol | |
293 will be emitted in the output or not before the symbol | |
294 is used. This can be different from getModule(). */ | |
295 Module * objFileModule; | |
296 #endif | |
297 | |
298 TemplateInstance(Loc loc, Identifier *temp_id); | |
299 TemplateInstance(Loc loc, TemplateDeclaration *tempdecl, Objects *tiargs); | |
300 static Objects *arraySyntaxCopy(Objects *objs); | |
301 Dsymbol *syntaxCopy(Dsymbol *); | |
302 void semantic(Scope *sc); | |
303 void semantic2(Scope *sc); | |
304 void semantic3(Scope *sc); | |
305 void inlineScan(); | |
306 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
307 Dsymbol *toAlias(); // resolve real symbol | |
336 | 308 const char *kind(); |
159 | 309 int oneMember(Dsymbol **ps); |
310 char *toChars(); | |
311 char *mangle(); | |
312 | |
336 | 313 void toObjFile(int multiobj); // compile to .obj file |
159 | 314 |
315 // Internal | |
316 static void semanticTiargs(Loc loc, Scope *sc, Objects *tiargs); | |
317 void semanticTiargs(Scope *sc); | |
318 TemplateDeclaration *findTemplateDeclaration(Scope *sc); | |
319 TemplateDeclaration *findBestMatch(Scope *sc); | |
320 void declareParameters(Scope *sc); | |
321 int isNested(Objects *tiargs); | |
322 Identifier *genIdent(); | |
323 | |
324 TemplateInstance *isTemplateInstance() { return this; } | |
325 AliasDeclaration *isAliasDeclaration(); | |
561
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
527
diff
changeset
|
326 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
561
diff
changeset
|
327 // LDC |
561
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
527
diff
changeset
|
328 TemplateInstance *tinst; // enclosing template instance |
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
527
diff
changeset
|
329 void printInstantiationTrace(); |
159 | 330 }; |
331 | |
332 struct TemplateMixin : TemplateInstance | |
333 { | |
334 Array *idents; | |
335 Type *tqual; | |
336 | |
337 Scope *scope; // for forward referencing | |
338 | |
339 TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Array *idents, Objects *tiargs); | |
340 Dsymbol *syntaxCopy(Dsymbol *s); | |
341 void semantic(Scope *sc); | |
342 void semantic2(Scope *sc); | |
343 void semantic3(Scope *sc); | |
344 void inlineScan(); | |
336 | 345 const char *kind(); |
159 | 346 int oneMember(Dsymbol **ps); |
347 int hasPointers(); | |
348 char *toChars(); | |
321 | 349 char *mangle(); |
159 | 350 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
351 | |
336 | 352 void toObjFile(int multiobj); // compile to .obj file |
159 | 353 |
354 TemplateMixin *isTemplateMixin() { return this; } | |
355 }; | |
356 | |
357 Expression *isExpression(Object *o); | |
358 Dsymbol *isDsymbol(Object *o); | |
359 Type *isType(Object *o); | |
360 Tuple *isTuple(Object *o); | |
361 Type *getType(Object *o); | |
362 Dsymbol *getDsymbol(Object *o); | |
363 | |
364 void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg); | |
365 | |
366 #endif /* DMD_TEMPLATE_H */ |