annotate dmd/TemplateInstance.d @ 79:43073c7c7769

updated to 2.035 also implemented a few missing functions still crashes in Import.importAll though
author Trass3r
date Mon, 30 Aug 2010 03:57:51 +0200
parents ad4792a1cfd6
children be2ab491772e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.TemplateParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.WithScopeSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Tuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.MATCH;
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
39 import dmd.templates.Util;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.glue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Tuple isTuple(Object o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 //return dynamic_cast<Tuple *>(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 ///if (!o || o.dyncast() != DYNCAST_TUPLE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 /// return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 return cast(Tuple)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 * If o1 matches o2, return 1.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 * Else, return 0.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 bool match(Object o1, Object o2, TemplateDeclaration tempdecl, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Type t1 = isType(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Type t2 = isType(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Expression e1 = isExpression(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Expression e2 = isExpression(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Dsymbol s1 = isDsymbol(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Dsymbol s2 = isDsymbol(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 Tuple v1 = isTuple(o1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Tuple v2 = isTuple(o2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 //printf("\t match t1 %p t2 %p, e1 %p e2 %p, s1 %p s2 %p, v1 %p v2 %p\n", t1,t2,e1,e2,s1,s2,v1,v2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 /* A proper implementation of the various equals() overrides
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 * should make it possible to just do o1.equals(o2), but
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 * we'll do that another day.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (t1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 /* if t1 is an instance of ti, then give error
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 * about recursive expansions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 Dsymbol s = t1.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 if (s && s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 TemplateInstance ti1 = s.parent.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (ti1 && ti1.tempdecl == tempdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 for (Scope sc1 = sc; sc1; sc1 = sc1.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (sc1.scopesym == ti1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 error("recursive template expansion for template argument %s", t1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return true; // fake a match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 //printf("t1 = %s\n", t1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 //printf("t2 = %s\n", t2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (!t2 || !t1.equals(t2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 else if (e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (e1 && e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 printf("match %d\n", e1.equals(e2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 e1.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 e2.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e1.type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e2.type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (!e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (!e1.equals(e2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 else if (s1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 //printf("%p %s, %p %s\n", s1, s1.toChars(), s2, s2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (!s2 || !s1.equals(s2) || s1.parent != s2.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 VarDeclaration vv1 = s1.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 VarDeclaration vv2 = s2.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 if (vv1 && vv2 && vv1.storage_class & vv2.storage_class & STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 ExpInitializer ei1 = vv1.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 ExpInitializer ei2 = vv2.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (ei1 && ei2 && !ei1.exp.equals(ei2.exp))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 else if (v1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (!v2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (v1.objects.dim != v2.objects.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 for (size_t i = 0; i < v1.objects.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (!match(cast(Object)v1.objects.data[i], cast(Object)v2.objects.data[i], tempdecl, sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 //printf("match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 return true; // match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 Lnomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 //printf("nomatch\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 return false; // nomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 class TemplateInstance : ScopeDsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 /* Given:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 * foo!(args) =>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 * name = foo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 * tiargs = args
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 Identifier name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 //Array idents;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 Objects tiargs; // Array of Types/Expressions of template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 // instance arguments [int*, char, 10*10]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 Objects tdtypes; // Array of Types/Expressions corresponding
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 // to TemplateDeclaration.parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 // [int, char, 100]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 TemplateDeclaration tempdecl; // referenced by foo.bar.abc
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 TemplateInstance inst; // refer to existing instance
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 TemplateInstance tinst; // enclosing template instance
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 ScopeDsymbol argsym; // argument symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 AliasDeclaration aliasdecl; // !=null if instance is an alias for its
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 // sole member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 WithScopeSymbol withsym; // if a member of a with statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 int semanticRun; // has semantic() been done?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 int semantictiargsdone; // has semanticTiargs() been done?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 int nest; // for recursion detection
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 int havetempdecl; // 1 if used second constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 Dsymbol isnested; // if referencing local symbols, this is the context
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 int errors; // 1 if compiled with errors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 /* On some targets, it is necessary to know whether a symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 will be emitted in the output or not before the symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 is used. This can be different from getModule(). */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 Module objFileModule;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 this(Loc loc, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 super(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 printf("TemplateInstance(this = %p, ident = '%s')\n", this, ident ? ident.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 this.name = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 tdtypes = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 /*****************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 * This constructor is only called when we figured out which function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 * template to instantiate.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 this(Loc loc, TemplateDeclaration td, Objects tiargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 super(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 printf("TemplateInstance(this = %p, tempdecl = '%s')\n", this, td.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 this.name = td.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 this.tiargs = tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 this.tempdecl = td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 this.semantictiargsdone = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 this.havetempdecl = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 assert(cast(size_t)cast(void*)tempdecl.scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 tdtypes = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 static Objects arraySyntaxCopy(Objects objs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
233 Objects a = null;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
234 if (objs)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
235 { a = new Objects();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
236 a.setDim(objs.dim);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
237 for (size_t i = 0; i < objs.dim; i++)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
238 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
239 a.data[i] = cast(void*)objectSyntaxCopy(cast(Object)objs.data[i]);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
240 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
241 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
242 return a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
245 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
247 TemplateInstance ti;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
248
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
249 if (s)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
250 ti = cast(TemplateInstance)s;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
251 else
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
252 ti = new TemplateInstance(loc, name);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
253
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
254 ti.tiargs = arraySyntaxCopy(tiargs);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
255
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
256 ScopeDsymbol.syntaxCopy(ti);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
257 return ti;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
260 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (!global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 /* Trying to soldier on rarely generates useful messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 * at this point.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 printf("\n+TemplateInstance.semantic('%s', this=%p)\n", toChars(), this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if (inst) // if semantic() was already run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 printf("-TemplateInstance.semantic('%s', this=%p) already run\n", inst.toChars(), inst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 // get the enclosing template instance from the scope tinst
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 tinst = sc.tinst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 if (semanticRun != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 error(loc, "recursive template expansion");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 // inst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 semanticRun = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 printf("\tdo semantic\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 if (havetempdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 assert(cast(size_t)cast(void*)tempdecl.scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 // Deduce tdtypes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 tdtypes.setDim(tempdecl.parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 if (!tempdecl.matchWithInstance(this, tdtypes, 2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 error("incompatible arguments for template instantiation");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 inst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 /* Run semantic on each argument, place results in tiargs[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 * (if we havetempdecl, then tiargs is already evaluated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 semanticTiargs(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 tempdecl = findTemplateDeclaration(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (tempdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 tempdecl = findBestMatch(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (!tempdecl || global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 inst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 //printf("error return %p, %d\n", tempdecl, global.errors);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 return; // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 hasNestedArgs(tiargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 /* See if there is an existing TemplateInstantiation that already
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 * implements the typeargs. If so, just refer to that one instead.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 for (size_t i = 0; i < tempdecl.instances.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 TemplateInstance ti = cast(TemplateInstance)tempdecl.instances.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 printf("\t%s: checking for match with instance %d (%p): '%s'\n", toChars(), i, ti, ti.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 assert(tdtypes.dim == ti.tdtypes.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 // Nesting must match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 if (isnested !is ti.isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 //printf("test2 isnested %s ti.isnested %s\n", isnested ? isnested.toChars() : "", ti.isnested ? ti.isnested.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 if (isnested && sc.parent != ti.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 for (size_t j = 0; j < tdtypes.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 Object o1 = cast(Object)tdtypes.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 Object o2 = cast(Object)ti.tdtypes.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 if (!match(o1, o2, tempdecl, sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 // It's a match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 inst = ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 parent = ti.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 printf("\tit's a match with instance %p\n", inst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 /* So, we need to implement 'this' instance.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 printf("\timplement template instance '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 uint errorsave = global.errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 inst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 int tempdecl_instance_idx = tempdecl.instances.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 tempdecl.instances.push(cast(void*)this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 parent = tempdecl.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 //printf("parent = '%s'\n", parent.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 ident = genIdent(); // need an identifier for name mangling purposes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 if (isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 parent = isnested;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 //printf("parent = '%s'\n", parent.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 // Add 'this' to the enclosing scope's members[] so the semantic routines
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 // will get called on the instance members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 int dosemantic3 = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
404 Dsymbols a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 Scope scx = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 for (scx = sc; scx; scx = scx.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 if (scx.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 //if (scx && scx.scopesym) printf("3: scx is %s %s\n", scx.scopesym.kind(), scx.scopesym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 if (scx && scx.scopesym &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 scx.scopesym.members && !scx.scopesym.isTemplateMixin()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 /// static if (false) { // removed because it bloated compile times
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 /// /* The problem is if A imports B, and B imports A, and both A
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 /// * and B instantiate the same template, does the compilation of A
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 /// * or the compilation of B do the actual instantiation?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 /// *
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 /// * see bugzilla 2500.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 /// */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 /// && !scx.module.selfImports()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 //printf("\t1: adding to %s %s\n", scx.scopesym.kind(), scx.scopesym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 a = scx.scopesym.members;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 { Module m = sc.module_.importedFrom;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 //printf("\t2: adding to module %s instead of module %s\n", m.toChars(), sc.module.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 a = m.members;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 if (m.semanticRun >= 3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 dosemantic3 = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 for (int i = 0; 1; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 if (i == a.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
443 a.push(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
447 if (this is a[i]) // if already in Array
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 // Copy the syntax trees from the TemplateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 members = Dsymbol.arraySyntaxCopy(tempdecl.members);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 // Create our own scope for the template parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 Scope scope_ = tempdecl.scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 if (!tempdecl.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 error("template instantiation %s forward references template declaration %s\n", toChars(), tempdecl.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 printf("\tcreate scope for template parameters '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 argsym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 argsym.parent = scope_.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 scope_ = scope_.push(argsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 // scope.stc = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 // Declare each template parameter as an alias for the argument type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 Scope paramscope = scope_.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 paramscope.stc = STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 declareParameters(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 paramscope.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 // Add members of template instance to template instance symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 // parent = scope.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 symtab = new DsymbolTable();
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
481 bool memnum = false;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
482 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 printf("\t[%d] adding member '%s' %p kind %s to '%s', memnum = %d\n", i, s.toChars(), s, s.kind(), this.toChars(), memnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 memnum |= s.addMember(scope_, this, memnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 printf("adding members done\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 /* See if there is only one member of template instance, and that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 * member has the same name as the template instance.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 * If so, this template instance becomes an alias for that member.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 //printf("members.dim = %d\n", members.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 if (members.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 if (Dsymbol.oneMembers(members, &s) && s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 //printf("s.kind = '%s'\n", s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 //s.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 //printf("'%s', '%s'\n", s.ident.toChars(), tempdecl.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 if (s.ident && s.ident.equals(tempdecl.ident))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 //printf("setting aliasdecl\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 aliasdecl = new AliasDeclaration(loc, s.ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 // Do semantic() analysis on template instance members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 printf("\tdo semantic() on template instance members '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 Scope sc2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 sc2 = scope_.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 //printf("isnested = %d, sc.parent = %s\n", isnested, sc.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 sc2.parent = /*isnested ? sc.parent :*/ this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 sc2.tinst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 try
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
527 // static int nest;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 //printf("%d\n", nest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 if (++nest > 500)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 global.gag = 0; // ensure error message gets printed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 error("recursive expansion");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
535 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 //printf("\t[%d] semantic on '%s' %p kind %s in '%s'\n", i, s.toChars(), s, s.kind(), this.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 //printf("test: isnested = %d, sc2.parent = %s\n", isnested, sc2.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 // if (isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 // s.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 //printf("test3: isnested = %d, s.parent = %s\n", isnested, s.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 s.semantic(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 //printf("test4: isnested = %d, s.parent = %s\n", isnested, s.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 sc2.module_.runDeferredSemantic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 --nest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 }
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
548 catch (Exception e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 global.gag = 0; // ensure error message gets printed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 error("recursive expansion");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 /* If any of the instantiation members didn't get semantic() run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 * on them due to forward references, we cannot run semantic2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 * or semantic3() yet.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 for (size_t i = 0; i < Module.deferred.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 Dsymbol sd = cast(Dsymbol)Module.deferred.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 if (sd.parent is this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 goto Laftersemantic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 /* The problem is when to parse the initializer for a variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 * Perhaps VarDeclaration.semantic() should do it like it does
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 * for initializers inside a function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 // if (sc.parent.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 /* BUG 782: this has problems if the classes this depends on
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 * are forward referenced. Find a way to defer semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 * on this template.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 semantic2(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 if (sc.func || dosemantic3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
581 try
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
582 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
583 // static int nest; // TODO:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
584 if (++nest > 300)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
585 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
586 global.gag = 0; // ensure error message gets printed
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
587 error("recursive expansion");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
588 fatal();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
589 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
590 semantic3(sc2);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
591 --nest;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
592 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
593 catch (Exception e)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
594 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
595 global.gag = 0; // ensure error message gets printed
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
596 error("recursive expansion");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
597 fatal();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
598 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 Laftersemantic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 sc2.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 scope_.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 // Give additional context info if error occurred during instantiation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 if (global.errors != errorsave)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 error("error instantiating");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 if (tinst && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 tinst.printInstantiationTrace();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 errors = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 if (global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 tempdecl.instances.remove(tempdecl_instance_idx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 printf("-TemplateInstance.semantic('%s', this=%p)\n", toChars(), this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
625 override void semantic2(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 if (semanticRun >= 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 semanticRun = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 version (LOG) {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
634 printf("+TemplateInstance.semantic2('%s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 if (!errors && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 sc = tempdecl.scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 assert(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 sc = sc.push(argsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 sc = sc.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 sc.tinst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
645 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 printf("\tmember '%s', kind = '%s'\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 s.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 version (LOG) {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
658 printf("-TemplateInstance.semantic2('%s')\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
662 override void semantic3(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 printf("TemplateInstance.semantic3('%s'), semanticRun = %d\n", toChars(), semanticRun);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 //if (toChars()[0] == 'D') *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 if (semanticRun >= 3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 semanticRun = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 if (!errors && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 sc = tempdecl.scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 sc = sc.push(argsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 sc = sc.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 sc.tinst = this;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
677 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 s.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
684 override void inlineScan()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 printf("TemplateInstance.inlineScan('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 if (!errors && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
691 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 s.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
696 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 Identifier id = name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 buf.writestring(id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 buf.writestring("!(");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 if (nest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 buf.writestring("...");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 nest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 Objects args = tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 for (i = 0; i < args.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 buf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 Object oarg = cast(Object)args.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 ObjectToCBuffer(buf, hgs, oarg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 nest--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 buf.writeByte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
721 override Dsymbol toAlias() // resolve real symbol
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
723 version (LOG)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
724 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
725 writef("TemplateInstance.toAlias()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 if (!inst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 error("cannot resolve forward reference");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
730 errors = 1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 if (inst !is this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 return inst.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 if (aliasdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 return aliasdecl.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 return inst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
745 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
747 return "template instance";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
750 override bool oneMember(Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
752 *ps = null;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
753 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
756 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 HdrGenState hgs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 toCBuffer(buf, &hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 return buf.extractString();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
765 override string mangle()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
767 OutBuffer buf = new OutBuffer();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
768 string id;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
769
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
770 static if (0) {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
771 printf("TemplateInstance.mangle() %s", toChars());
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
772 if (parent)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
773 printf(" parent = %s %s", parent.kind(), parent.toChars());
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
774 printf("\n");
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
775 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
776 id = ident ? ident.toChars() : toChars();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
777 if (!tempdecl)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
778 error("is not defined");
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
779 else if (tempdecl.parent)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
780 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
781 string p = tempdecl.parent.mangle();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
782 if (p[0] == '_' && p[1] == 'D')
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
783 p = p[2..$];
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
784 buf.writestring(p);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
785 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
786 buf.printf("%d%s", id.length, id);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
787 id = buf.toChars();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
788 buf.data = null;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
789 //printf("TemplateInstance.mangle() %s = %s\n", toChars(), id);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
790 return id;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 void printInstantiationTrace()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
795 if (global.gag)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
796 return;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
799 override void toObjFile(int multiobj) // compile to .obj file
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 printf("TemplateInstance.toObjFile('%s', this = %p)\n", toChars(), this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 if (!errors && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 if (multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 // Append to list of object files to be written later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 obj_append(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
811 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 s.toObjFile(multiobj);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 // Internal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 * flags 1: replace const variables with their initializers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 static void semanticTiargs(Loc loc, Scope sc, Objects tiargs, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 // Run semantic on each argument, place results in tiargs[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 //printf("+TemplateInstance.semanticTiargs() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 if (!tiargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 for (size_t j = 0; j < tiargs.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 Object o = cast(Object)tiargs.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 Type ta = isType(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 Expression ea = isExpression(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 Dsymbol sa = isDsymbol(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 //printf("1: tiargs.data[%d] = %p, %p, %p, ea=%p, ta=%p\n", j, o, isDsymbol(o), isTuple(o), ea, ta);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 if (ta)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 //printf("type %s\n", ta.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 // It might really be an Expression or an Alias
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 ta.resolve(loc, sc, &ea, &ta, &sa);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 ea = ea.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 /* This test is to skip substituting a const var with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 * its initializer. The problem is the initializer won't
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 * match with an 'alias' parameter. Instead, do the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 * const substitution in TemplateValueParameter.matchArg().
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 if (ea.op != TOKvar || flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 ea = ea.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 tiargs.data[j] = cast(void*)ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 else if (sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 tiargs.data[j] = cast(void*)sa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 TupleDeclaration d = sa.toAlias().isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 if (d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 size_t dim = d.objects.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 tiargs.remove(j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 tiargs.insert(j, d.objects);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 j--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 else if (ta)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 Ltype:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 if (ta.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 // Expand tuple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 TypeTuple tt = cast(TypeTuple)ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 size_t dim = tt.arguments.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 tiargs.remove(j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 tiargs.reserve(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 Argument arg = cast(Argument)tt.arguments.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 tiargs.insert(j + i, cast(void*)arg.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 j--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 tiargs.data[j] = cast(void*)ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 assert(global.errors);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 tiargs.data[j] = cast(void*)Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 else if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 if (!ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 assert(global.errors);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 ea = new IntegerExp(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 assert(ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 ea = ea.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 if (ea.op != TOKvar || flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 ea = ea.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 tiargs.data[j] = cast(void*)ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 if (ea.op == TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 ta = ea.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 goto Ltype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 if (ea.op == TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 // Expand tuple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 TupleExp te = cast(TupleExp)ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 size_t dim = te.exps.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 tiargs.remove(j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 tiargs.reserve(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 tiargs.insert(j + i, te.exps.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 j--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 else if (sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 TemplateDeclaration td = sa.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 if (td && !td.semanticRun && td.literal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 td.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 //printf("1: tiargs.data[%d] = %p\n", j, tiargs.data[j]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 printf("-TemplateInstance.semanticTiargs('%s', this=%p)\n", toChars(), this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 for (size_t j = 0; j < tiargs.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 Object o = cast(Object)tiargs.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 Type ta = isType(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 Expression ea = isExpression(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 Dsymbol sa = isDsymbol(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 Tuple va = isTuple(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 printf("\ttiargs[%d] = ta %p, ea %p, sa %p, va %p\n", j, ta, ea, sa, va);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 void semanticTiargs(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 //printf("+TemplateInstance.semanticTiargs() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 if (semantictiargsdone)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 semantictiargsdone = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 semanticTiargs(loc, sc, tiargs, 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 * Find template declaration corresponding to template instance.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 TemplateDeclaration findTemplateDeclaration(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 //printf("TemplateInstance.findTemplateDeclaration() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 if (!tempdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 /* Given:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 * foo!( ... )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 * figure out which TemplateDeclaration foo refers to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 Dsymbol scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 Identifier id = name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 s = sc.search(loc, id, &scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 error("identifier '%s' is not defined", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 printf("It's an instance of '%s' kind '%s'\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 if (s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 printf("s.parent = '%s'\n", s.parent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 withsym = scopesym.isWithScopeSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 /* We might have found an alias within a template when
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 * we really want the template.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 TemplateInstance ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 if (s.parent &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 (ti = s.parent.isTemplateInstance()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 if (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 (ti.name == id ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 ti.toAlias().ident == id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 ti.tempdecl
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 /* This is so that one can refer to the enclosing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 * template, even if it has the same name as a member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 * of the template, if it has a !(arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 tempdecl = ti.tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 if (tempdecl.overroot) // if not start of overloaded list of TemplateDeclaration's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 tempdecl = tempdecl.overroot; // then get the start
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 s = tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 /* It should be a TemplateDeclaration, not some other symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 tempdecl = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 if (!tempdecl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 if (!s.parent && global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 if (!s.parent && s.getType())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 Dsymbol s2 = s.getType().toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 if (!s2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 error("%s is not a template declaration, it is a %s", id.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 s = s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 //if (!s.parent) printf("s = %s %s\n", s.kind(), s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 //assert(s.parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 TemplateInstance ti2 = s.parent ? s.parent.isTemplateInstance() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 if (ti2 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 (ti2.name == id ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 ti2.toAlias().ident == id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 ti2.tempdecl
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 /* This is so that one can refer to the enclosing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 * template, even if it has the same name as a member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 * of the template, if it has a !(arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 tempdecl = ti2.tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 if (tempdecl.overroot) // if not start of overloaded list of TemplateDeclaration's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 tempdecl = tempdecl.overroot; // then get the start
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 error("%s is not a template declaration, it is a %s", id.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 assert(tempdecl.isTemplateDeclaration());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 TemplateDeclaration findBestMatch(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 /* Since there can be multiple TemplateDeclaration's with the same
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 * name, look for the best match.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 TemplateDeclaration td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 TemplateDeclaration td_best = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 MATCH m_best = MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 scope Objects dedtypes = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 printf("TemplateInstance.findBestMatch()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 // First look for forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 for (TemplateDeclaration td = tempdecl; td; td = td.overnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 if (!td.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 if (td.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 // Try to fix forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 td.semantic(td.scope_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 if (!td.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 error("%s forward references template declaration %s\n", toChars(), td.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 for (TemplateDeclaration td = tempdecl; td; td = td.overnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 //if (tiargs.dim) printf("2: tiargs.dim = %d, data[0] = %p\n", tiargs.dim, tiargs.data[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 // If more arguments than parameters,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 // then this is no match.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 if (td.parameters.dim < tiargs.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 if (!td.isVariadic())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 dedtypes.setDim(td.parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 dedtypes.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 assert(td.semanticRun);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 m = td.matchWithInstance(this, dedtypes, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 //printf("matchWithInstance = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 if (!m) // no match at all
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 if (m < m_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 goto Ltd_best;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 if (m > m_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 goto Ltd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 // Disambiguate by picking the most specialized TemplateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 MATCH c1 = td.leastAsSpecialized(td_best);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 MATCH c2 = td_best.leastAsSpecialized(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 //printf("c1 = %d, c2 = %d\n", c1, c2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 if (c1 > c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 goto Ltd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 else if (c1 < c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 goto Ltd_best;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 goto Lambig;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 Lambig: // td_best and td are ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 td_ambig = td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 Ltd_best: // td_best is the best match so far
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 Ltd: // td is the new best match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 td_best = td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 m_best = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 tdtypes.setDim(dedtypes.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 memcpy(tdtypes.data, dedtypes.data, tdtypes.dim * (void*).sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 if (!td_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 if (tempdecl && !tempdecl.overnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 // Only one template, so we can give better error message
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 error("%s does not match template declaration %s", toChars(), tempdecl.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 error("%s does not match any template declaration", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 if (td_ambig)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 error("%s matches more than one template declaration, %s and %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 toChars(), td_best.toChars(), td_ambig.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 /* The best match is td_best
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 tempdecl = td_best;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 /* Cast any value arguments to be same type as value parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 for (size_t i = 0; i < tiargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 Object o = cast(Object)tiargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 Expression ea = isExpression(o); // value argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 assert(tp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 TemplateValueParameter tvp = tp.isTemplateValueParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 if (tvp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 assert(ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 ea = ea.castTo(tvp.valType);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 ea = ea.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 tiargs.data[i] = cast(Object)ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 printf("\tIt's a match with template declaration '%s'\n", tempdecl.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 /****************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 * Declare parameters of template instance, initialize them with the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 * template instance arguments.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 void declareParameters(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1214 //printf("TemplateInstance.declareParameters()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 for (int i = 0; i < tdtypes.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 //Object o = cast(Object)tiargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 Object o = cast(Object)tdtypes.data[i]; // initializer for tp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 //printf("\ttdtypes[%d] = %p\n", i, o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 tempdecl.declareParameter(sc, tp, o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 * Determines if a TemplateInstance will need a nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 * generation of the TemplateDeclaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 bool hasNestedArgs(Objects args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 bool nested = false;
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1233 //printf("TemplateInstance.hasNestedArgs('%s')\n", tempdecl.ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 /* A nested instance happens when an argument references a local
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 * symbol that is on the stack.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 for (size_t i = 0; i < args.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 Object o = cast(Object)args.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 Expression ea = isExpression(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 Dsymbol sa = isDsymbol(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 Tuple va = isTuple(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 if (ea.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 sa = (cast(VarExp)ea).var;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 goto Lsa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 if (ea.op == TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 sa = (cast(FuncExp)ea).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 goto Lsa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 else if (sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 Lsa:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 Declaration d = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 TemplateDeclaration td = sa.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 if (td && td.literal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 d = sa.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 if (d && !d.isDataseg() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 !(d.storage_class & STCmanifest) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 (!d.isFuncDeclaration() || d.isFuncDeclaration().isNested()) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 !isTemplateMixin())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 // if module level template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276 if (tempdecl.toParent().isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 Dsymbol dparent = sa.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 if (!isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 isnested = dparent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 else if (isnested != dparent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 /* Select the more deeply nested of the two.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 * Error if one is not nested inside the other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 for (Dsymbol p = isnested; p; p = p.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 if (p == dparent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 goto L1; // isnested is most nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 for (Dsymbol p = dparent; p; p = p.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 if (p == isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 isnested = dparent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 goto L1; // dparent is most nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 error("%s is nested in both %s and %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 toChars(), isnested.toChars(), dparent.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 //printf("\tnested inside %s\n", isnested.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 nested |= 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 error("cannot use local '%s' as parameter to non-global template %s", d.toChars(), tempdecl.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 else if (va)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 nested |= hasNestedArgs(va.objects);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 return nested;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 * This instance needs an identifier for name mangling purposes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 * Create one by taking the template declaration name and adding
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 * the type signature for it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 Identifier genIdent()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 string id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 Objects args;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1329 //printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 id = tempdecl.ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 buf.printf("__T%d%s", id.length, id); ///!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 args = tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 for (int i = 0; i < args.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 Object o = cast(Object)args.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 Type ta = isType(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 Expression ea = isExpression(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 Dsymbol sa = isDsymbol(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 Tuple va = isTuple(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 //printf("\to [%d] %p ta %p ea %p sa %p va %p\n", i, o, ta, ea, sa, va);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 if (ta)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 buf.writeByte('T');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 if (ta.deco)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 buf.writestring(ta.deco);
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 debug writef("ta = %d, %s\n", ta.ty, ta.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 assert(global.errors);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 else if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 Lea:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 long v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 real r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 ea = ea.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 if (ea.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 sa = (cast(VarExp)ea).var;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 ea = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 goto Lsa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 if (ea.op == TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 sa = (cast(FuncExp)ea).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 ea = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 goto Lsa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 buf.writeByte('V');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 if (ea.op == TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 ea.error("tuple is not a valid template value argument");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 /* Use deco that matches what it would be for a function parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 buf.writestring(ea.type.deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 // Use type of parameter, not type of argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 assert(tp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 TemplateValueParameter tvp = tp.isTemplateValueParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 assert(tvp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 buf.writestring(tvp.valType.deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 ea.toMangleBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 else if (sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 Lsa:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 buf.writeByte('S');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 Declaration d = sa.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 if (d && (!d.type || !d.type.deco))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 error("forward reference of %s", d.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 VarDeclaration v = sa.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 if (v && v.storage_class & STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 ExpInitializer ei = v.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 if (ei)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 ea = ei.exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 goto Lea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 string p = sa.mangle();
62
6557375aff35 InExp.opId_r
korDen
parents: 23
diff changeset
1414 ///buf.printf("%zu%s", p.length, p);
6557375aff35 InExp.opId_r
korDen
parents: 23
diff changeset
1415 buf.printf("%su%s", p.length, p);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 else if (va)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 assert(i + 1 == args.dim); // must be last one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 args = va.objects;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 i = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 buf.writeByte('Z');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 id = buf.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 buf.data = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 //printf("\tgenIdent = %s\n", id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 return new Identifier(id, TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
1433 override TemplateInstance isTemplateInstance() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 62
diff changeset
1435 override AliasDeclaration isAliasDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 }
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1439 }