Mercurial > projects > ldc
annotate dmd/template.h @ 557:aef77ae1d32c
Enable unwind code on darwin.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 29 Aug 2008 14:16:18 +0200 |
parents | cecfee2d01a8 |
children | d4e95db0e62b |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2006 by Digital Mars | |
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 | |
57 | |
336 | 58 Array instances; // array of TemplateInstance's |
159 | 59 |
60 TemplateDeclaration *overnext; // next overloaded TemplateDeclaration | |
61 TemplateDeclaration *overroot; // first in overnext list | |
62 | |
63 Scope *scope; | |
64 Dsymbol *onemember; // if !=NULL then one member of this template | |
65 | |
66 TemplateDeclaration(Loc loc, Identifier *id, TemplateParameters *parameters, Array *decldefs); | |
67 Dsymbol *syntaxCopy(Dsymbol *); | |
68 void semantic(Scope *sc); | |
69 int overloadInsert(Dsymbol *s); | |
70 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
336 | 71 const char *kind(); |
159 | 72 char *toChars(); |
73 | |
74 void emitComment(Scope *sc); | |
75 // void toDocBuffer(OutBuffer *buf); | |
76 | |
77 MATCH matchWithInstance(TemplateInstance *ti, Objects *atypes, int flag); | |
78 int leastAsSpecialized(TemplateDeclaration *td2); | |
79 | |
80 MATCH deduceFunctionTemplateMatch(Objects *targsi, Expressions *fargs, Objects *dedargs); | |
81 FuncDeclaration *deduceFunctionTemplate(Scope *sc, Loc loc, Objects *targsi, Expressions *fargs); | |
82 void declareParameter(Scope *sc, TemplateParameter *tp, Object *o); | |
83 | |
84 TemplateDeclaration *isTemplateDeclaration() { return this; } | |
85 | |
86 TemplateTupleParameter *isVariadic(); | |
87 int isOverloadable(); | |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
88 |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
89 // LLVMDC |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
90 std::string intrinsicName; |
159 | 91 }; |
92 | |
93 struct TemplateParameter | |
94 { | |
95 /* For type-parameter: | |
96 * template Foo(ident) // specType is set to NULL | |
97 * template Foo(ident : specType) | |
98 * For value-parameter: | |
99 * template Foo(valType ident) // specValue is set to NULL | |
100 * template Foo(valType ident : specValue) | |
101 * For alias-parameter: | |
102 * template Foo(alias ident) | |
103 */ | |
104 | |
105 Loc loc; | |
106 Identifier *ident; | |
107 | |
108 Declaration *sparam; | |
109 | |
110 TemplateParameter(Loc loc, Identifier *ident); | |
111 | |
112 virtual TemplateTypeParameter *isTemplateTypeParameter(); | |
113 virtual TemplateValueParameter *isTemplateValueParameter(); | |
114 virtual TemplateAliasParameter *isTemplateAliasParameter(); | |
115 virtual TemplateTupleParameter *isTemplateTupleParameter(); | |
116 | |
117 virtual TemplateParameter *syntaxCopy() = 0; | |
118 virtual void declareParameter(Scope *sc) = 0; | |
119 virtual void semantic(Scope *) = 0; | |
120 virtual void print(Object *oarg, Object *oded) = 0; | |
121 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; | |
122 virtual Object *specialization() = 0; | |
123 virtual Object *defaultArg(Scope *sc) = 0; | |
124 | |
125 /* If TemplateParameter's match as far as overloading goes. | |
126 */ | |
127 virtual int overloadMatch(TemplateParameter *) = 0; | |
128 | |
129 /* Match actual argument against parameter. | |
130 */ | |
131 virtual MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) = 0; | |
132 | |
133 /* Create dummy argument based on parameter. | |
134 */ | |
135 virtual void *dummyArg() = 0; | |
136 }; | |
137 | |
138 struct TemplateTypeParameter : TemplateParameter | |
139 { | |
140 /* Syntax: | |
141 * ident : specType = defaultType | |
142 */ | |
143 Type *specType; // type parameter: if !=NULL, this is the type specialization | |
144 Type *defaultType; | |
145 | |
146 TemplateTypeParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType); | |
147 | |
148 TemplateTypeParameter *isTemplateTypeParameter(); | |
149 TemplateParameter *syntaxCopy(); | |
150 void declareParameter(Scope *sc); | |
151 void semantic(Scope *); | |
152 void print(Object *oarg, Object *oded); | |
153 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
154 Object *specialization(); | |
155 Object *defaultArg(Scope *sc); | |
156 int overloadMatch(TemplateParameter *); | |
157 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
158 void *dummyArg(); | |
159 }; | |
160 | |
336 | 161 #if DMDV2 |
162 struct TemplateThisParameter : TemplateTypeParameter | |
163 { | |
164 /* Syntax: | |
165 * this ident : specType = defaultType | |
166 */ | |
167 Type *specType; // type parameter: if !=NULL, this is the type specialization | |
168 Type *defaultType; | |
169 | |
170 TemplateThisParameter(Loc loc, Identifier *ident, Type *specType, Type *defaultType); | |
171 | |
172 TemplateThisParameter *isTemplateThisParameter(); | |
173 TemplateParameter *syntaxCopy(); | |
174 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
175 }; | |
176 #endif | |
177 | |
159 | 178 struct TemplateValueParameter : TemplateParameter |
179 { | |
180 /* Syntax: | |
181 * valType ident : specValue = defaultValue | |
182 */ | |
183 | |
184 Type *valType; | |
185 Expression *specValue; | |
186 Expression *defaultValue; | |
187 | |
188 static Expression *edummy; | |
189 | |
190 TemplateValueParameter(Loc loc, Identifier *ident, Type *valType, Expression *specValue, Expression *defaultValue); | |
191 | |
192 TemplateValueParameter *isTemplateValueParameter(); | |
193 TemplateParameter *syntaxCopy(); | |
194 void declareParameter(Scope *sc); | |
195 void semantic(Scope *); | |
196 void print(Object *oarg, Object *oded); | |
197 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
198 Object *specialization(); | |
199 Object *defaultArg(Scope *sc); | |
200 int overloadMatch(TemplateParameter *); | |
201 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
202 void *dummyArg(); | |
203 }; | |
204 | |
205 struct TemplateAliasParameter : TemplateParameter | |
206 { | |
207 /* Syntax: | |
208 * ident : specAlias = defaultAlias | |
209 */ | |
210 | |
211 Type *specAliasT; | |
212 Dsymbol *specAlias; | |
213 | |
214 Type *defaultAlias; | |
215 | |
216 static Dsymbol *sdummy; | |
217 | |
218 TemplateAliasParameter(Loc loc, Identifier *ident, Type *specAliasT, Type *defaultAlias); | |
219 | |
220 TemplateAliasParameter *isTemplateAliasParameter(); | |
221 TemplateParameter *syntaxCopy(); | |
222 void declareParameter(Scope *sc); | |
223 void semantic(Scope *); | |
224 void print(Object *oarg, Object *oded); | |
225 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
226 Object *specialization(); | |
227 Object *defaultArg(Scope *sc); | |
228 int overloadMatch(TemplateParameter *); | |
229 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
230 void *dummyArg(); | |
231 }; | |
232 | |
233 struct TemplateTupleParameter : TemplateParameter | |
234 { | |
235 /* Syntax: | |
236 * ident ... | |
237 */ | |
238 | |
239 TemplateTupleParameter(Loc loc, Identifier *ident); | |
240 | |
241 TemplateTupleParameter *isTemplateTupleParameter(); | |
242 TemplateParameter *syntaxCopy(); | |
243 void declareParameter(Scope *sc); | |
244 void semantic(Scope *); | |
245 void print(Object *oarg, Object *oded); | |
246 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
247 Object *specialization(); | |
248 Object *defaultArg(Scope *sc); | |
249 int overloadMatch(TemplateParameter *); | |
250 MATCH matchArg(Scope *sc, Objects *tiargs, int i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam); | |
251 void *dummyArg(); | |
252 }; | |
253 | |
254 struct TemplateInstance : ScopeDsymbol | |
255 { | |
256 /* Given: | |
257 * foo!(args) => | |
258 * name = foo | |
259 * tiargs = args | |
260 */ | |
261 Identifier *name; | |
262 //Array idents; | |
263 Objects *tiargs; // Array of Types/Expressions of template | |
264 // instance arguments [int*, char, 10*10] | |
265 | |
266 Objects tdtypes; // Array of Types/Expressions corresponding | |
267 // to TemplateDeclaration.parameters | |
268 // [int, char, 100] | |
269 | |
270 TemplateDeclaration *tempdecl; // referenced by foo.bar.abc | |
271 TemplateInstance *inst; // refer to existing instance | |
272 ScopeDsymbol *argsym; // argument symbol table | |
273 AliasDeclaration *aliasdecl; // !=NULL if instance is an alias for its | |
274 // sole member | |
275 WithScopeSymbol *withsym; // if a member of a with statement | |
276 int semanticdone; // has semantic() been done? | |
336 | 277 int semantictiargsdone; // has semanticTiargs() been done? |
159 | 278 int nest; // for recursion detection |
279 int havetempdecl; // 1 if used second constructor | |
280 Dsymbol *isnested; // if referencing local symbols, this is the context | |
281 int errors; // 1 if compiled with errors | |
282 #ifdef IN_GCC | |
283 /* On some targets, it is necessary to know whether a symbol | |
284 will be emitted in the output or not before the symbol | |
285 is used. This can be different from getModule(). */ | |
286 Module * objFileModule; | |
287 #endif | |
288 | |
289 TemplateInstance(Loc loc, Identifier *temp_id); | |
290 TemplateInstance(Loc loc, TemplateDeclaration *tempdecl, Objects *tiargs); | |
291 static Objects *arraySyntaxCopy(Objects *objs); | |
292 Dsymbol *syntaxCopy(Dsymbol *); | |
293 void semantic(Scope *sc); | |
294 void semantic2(Scope *sc); | |
295 void semantic3(Scope *sc); | |
296 void inlineScan(); | |
297 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
298 Dsymbol *toAlias(); // resolve real symbol | |
336 | 299 const char *kind(); |
159 | 300 int oneMember(Dsymbol **ps); |
301 char *toChars(); | |
302 char *mangle(); | |
303 | |
336 | 304 void toObjFile(int multiobj); // compile to .obj file |
159 | 305 |
306 // Internal | |
307 static void semanticTiargs(Loc loc, Scope *sc, Objects *tiargs); | |
308 void semanticTiargs(Scope *sc); | |
309 TemplateDeclaration *findTemplateDeclaration(Scope *sc); | |
310 TemplateDeclaration *findBestMatch(Scope *sc); | |
311 void declareParameters(Scope *sc); | |
312 int isNested(Objects *tiargs); | |
313 Identifier *genIdent(); | |
314 | |
315 TemplateInstance *isTemplateInstance() { return this; } | |
316 AliasDeclaration *isAliasDeclaration(); | |
317 }; | |
318 | |
319 struct TemplateMixin : TemplateInstance | |
320 { | |
321 Array *idents; | |
322 Type *tqual; | |
323 | |
324 Scope *scope; // for forward referencing | |
325 | |
326 TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Array *idents, Objects *tiargs); | |
327 Dsymbol *syntaxCopy(Dsymbol *s); | |
328 void semantic(Scope *sc); | |
329 void semantic2(Scope *sc); | |
330 void semantic3(Scope *sc); | |
331 void inlineScan(); | |
336 | 332 const char *kind(); |
159 | 333 int oneMember(Dsymbol **ps); |
334 int hasPointers(); | |
335 char *toChars(); | |
321 | 336 char *mangle(); |
159 | 337 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
338 | |
336 | 339 void toObjFile(int multiobj); // compile to .obj file |
159 | 340 |
341 TemplateMixin *isTemplateMixin() { return this; } | |
342 }; | |
343 | |
344 Expression *isExpression(Object *o); | |
345 Dsymbol *isDsymbol(Object *o); | |
346 Type *isType(Object *o); | |
347 Tuple *isTuple(Object *o); | |
348 Type *getType(Object *o); | |
349 Dsymbol *getDsymbol(Object *o); | |
350 | |
351 void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg); | |
352 | |
353 #endif /* DMD_TEMPLATE_H */ |