annotate dmd/TemplateDeclaration.d @ 126:1765f3ef917d

ClassDeclarations, Arguments -> Vector
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Fri, 03 Sep 2010 23:25:55 +0100
parents 347de076ad34
children e6e542f37b94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 113
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.TemplateThisParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.TemplateTupleParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Tuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Initializer;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
38 import dmd.Json;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.TemplateValueParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.TemplateParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.TemplateTypeParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 * Determine if TemplateDeclaration is variadic.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 TemplateTupleParameter isVariadic(TemplateParameters parameters)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 size_t dim = parameters.dim;
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
57 TemplateTupleParameter tp = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
59 if (dim)
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
60 tp = parameters[dim - 1].isTemplateTupleParameter();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
62 return tp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 void ObjectToCBuffer(OutBuffer buf, HdrGenState* hgs, Object oarg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
67 //printf("ObjectToCBuffer()\n");
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
68 Type t = isType(oarg);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
69 Expression e = isExpression(oarg);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
70 Dsymbol s = isDsymbol(oarg);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
71 Tuple v = isTuple(oarg);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
72 if (t)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
73 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 //printf("\tt: %s ty = %d\n", t.toChars(), t.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 t.toCBuffer(buf, null, hgs);
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
76 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
77 else if (e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 e.toCBuffer(buf, hgs);
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
79 else if (s)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
80 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 string p = s.ident ? s.ident.toChars() : s.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 buf.writestring(p);
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
83 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
84 else if (v)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
85 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 Objects args = v.objects;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 for (size_t i = 0; i < args.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 buf.writeByte(',');
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
91 Object o = args[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 ObjectToCBuffer(buf, hgs, o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
94 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
95 else if (!oarg)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
96 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 buf.writestring("null");
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
98 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
99 else
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
100 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 debug writef("bad Object = %p\n", oarg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 assert(0);
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
103 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 class TemplateDeclaration : ScopeDsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
108 TemplateParameters parameters; // array of TemplateParameter's
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
110 TemplateParameters origParameters; // originals for Ddoc
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
111 Expression constraint;
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
112 Array instances; // array of TemplateInstance's
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
114 TemplateDeclaration overnext; // next overloaded TemplateDeclaration
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
115 TemplateDeclaration overroot; // first in overnext list
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
117 int semanticRun; // 1 semantic() run
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
119 Dsymbol onemember; // if !=NULL then one member of this template
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
121 int literal; // this template declaration is a literal
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
123 this(Loc loc, Identifier id, TemplateParameters parameters, Expression constraint, Dsymbols decldefs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 printf("TemplateDeclaration(this = %p, id = '%s')\n", this, id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (parameters)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 for (int i = 0; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 TemplateParameter tp = cast(TemplateParameter)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //printf("\tparameter[%d] = %p\n", i, tp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 TemplateTypeParameter ttp = tp.isTemplateTypeParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (ttp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 printf("\tparameter[%d] = %s : %s\n", i, tp.ident.toChars(), ttp.specType ? ttp.specType.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 this.parameters = parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 this.origParameters = parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 this.constraint = constraint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 this.members = decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 instances = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
154 override Dsymbol syntaxCopy(Dsymbol)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
156 //printf("TemplateDeclaration.syntaxCopy()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
157 TemplateDeclaration td;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
158 TemplateParameters p;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
159 Dsymbols d;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
160
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
161 p = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
162 if (parameters)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
163 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
164 p = new TemplateParameters();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
165 p.setDim(parameters.dim);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
166 for (int i = 0; i < p.dim; i++)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
167 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
168 auto tp = parameters[i];
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
169 p[i] = tp.syntaxCopy();
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
170 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
171 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
172
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
173 Expression e = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
174 if (constraint)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
175 e = constraint.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
176 d = Dsymbol.arraySyntaxCopy(members);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
177 td = new TemplateDeclaration(loc, ident, p, e, d);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
178 return td;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
181 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 printf("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 return; // semantic() already run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 semanticRun = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 error("cannot declare template at function scope %s", sc.func.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (/*global.params.useArrayBounds &&*/ sc.module_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 // Generate this function as it may be used
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 // when template is instantiated in other modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 sc.module_.toModuleArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (/*global.params.useAssert &&*/ sc.module_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 // Generate this function as it may be used
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 // when template is instantiated in other modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 sc.module_.toModuleAssert();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 /* Remember Scope for later instantiations, but make
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 * a copy since attributes can change.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 */
87
b17640f0e4e8 Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents: 79
diff changeset
214 this.scope_ = sc.clone();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 this.scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 // Set up scope for parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 ScopeDsymbol paramsym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 paramsym.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 Scope paramscope = sc.push(paramsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 paramscope.parameterSpecialization = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 paramscope.stc = STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (!parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (global.params.doDocComments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 origParameters = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 origParameters.setDim(parameters.dim);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
231 foreach (size_t i, TemplateParameter tp; parameters)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
233 origParameters[i] = tp.syntaxCopy();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
237 foreach (tp; parameters)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 tp.declareParameter(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
242 foreach (size_t i, TemplateParameter tp; parameters)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 tp.semantic(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 if (i + 1 != parameters.dim && tp.isTemplateTupleParameter())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 error("template tuple parameter must be last one");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 paramscope.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 if (Dsymbol.oneMembers(members, &s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (s && s.ident && s.ident.equals(ident))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 onemember = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 s.parent = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 /* BUG: should check:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 * o no virtual functions or non-static data members of classes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
269 /**********************************
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
270 * Overload existing TemplateDeclaration 'this' with the new one 's'.
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
271 * Return !=0 if successful; i.e. no conflict.
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
272 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
273 override bool overloadInsert(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
275 TemplateDeclaration *pf;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
276 TemplateDeclaration f;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
277
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
278 version (LOG) {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
279 printf("TemplateDeclaration.overloadInsert('%.*s')\n", s.toChars());
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
280 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
281 f = s.isTemplateDeclaration();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
282 if (!f)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
283 return false;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
284
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
285 TemplateDeclaration pthis = this;
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
286 for (pf = &pthis; *pf; pf = &(*pf).overnext)
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
287 {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
288 static if (false) {
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
289 // Conflict if TemplateParameter's match
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
290 // Will get caught anyway later with TemplateInstance, but
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
291 // should check it now.
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
292 if (f.parameters.dim != f2.parameters.dim)
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
293 goto Lcontinue;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
294
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
295 for (int i = 0; i < f.parameters.dim; i++)
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
296 {
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
297 TemplateParameter p1 = cast(TemplateParameter)f.parameters.data[i];
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
298 TemplateParameter p2 = cast(TemplateParameter)f2.parameters.data[i];
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
299
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
300 if (!p1.overloadMatch(p2))
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
301 goto Lcontinue;
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
302 }
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
303
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
304 version (LOG) {
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
305 printf("\tfalse: conflict\n");
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
306 }
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
307 return false;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
308
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
309 Lcontinue:
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
310 ;
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
311 }
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
312 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
313
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
314 f.overroot = this;
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
315 *pf = f;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
316 version (LOG) {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
317 printf("\ttrue: no conflict\n");
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
318 }
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
319
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
320 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
323 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 {
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
325 static if (false) // Should handle template functions
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
326 {
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
327 if (onemember && onemember.isFuncDeclaration())
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
328 buf.writestring("foo ");
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
329 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
330 buf.writestring(kind());
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
331 buf.writeByte(' ');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
332 buf.writestring(ident.toChars());
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
333 buf.writeByte('(');
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
334 foreach (size_t i, TemplateParameter tp; parameters)
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
335 {
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
336 if (hgs.ddoc)
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
337 tp = origParameters[i];
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
338 if (i)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
339 buf.writeByte(',');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
340 tp.toCBuffer(buf, hgs);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
341 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
342 buf.writeByte(')');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
343 version(DMDV2)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
344 {
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
345 if (constraint)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
346 { buf.writestring(" if (");
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
347 constraint.toCBuffer(buf, hgs);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
348 buf.writeByte(')');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
349 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
350 }
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
351
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
352 if (hgs.hdrgen)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
353 {
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
354 hgs.tpltMember++;
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
355 buf.writenl();
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
356 buf.writebyte('{');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
357 buf.writenl();
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
358 foreach (Dsymbol s; members)
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
359 s.toCBuffer(buf, hgs);
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
360
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
361 buf.writebyte('}');
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
362 buf.writenl();
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
363 hgs.tpltMember--;
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
364 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
367 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
368 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
369 //writef("TemplateDeclaration.toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
370
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
371 buf.writestring("{\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
372
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
373 JsonProperty(buf, Pname, toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
374 JsonProperty(buf, Pkind, kind());
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
375 if (comment)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
376 JsonProperty(buf, Pcomment, comment);
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
377
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
378 if (loc.linnum)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
379 JsonProperty(buf, Pline, loc.linnum);
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
380
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
381 JsonString(buf, Pmembers);
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
382 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
383 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
384 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
385 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
386 if (offset != buf.offset)
96
acd69f84627e further work
Trass3r
parents: 90
diff changeset
387 { buf.writestring(",\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
388 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
389 }
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
390 s.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
391 }
96
acd69f84627e further work
Trass3r
parents: 90
diff changeset
392 JsonRemoveComma(buf);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
393 buf.writestring("]\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
394
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
395 buf.writestring("}\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
396 }
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
397
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
398 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
400 return (onemember && onemember.isAggregateDeclaration())
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
401 ? onemember.kind()
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
402 : "template";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
405 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
407 OutBuffer buf = new OutBuffer();
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
408 HdrGenState hgs;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
409
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
410 /// memset(&hgs, 0, hgs.sizeof);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
411 buf.writestring(ident.toChars());
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
412 buf.writeByte('(');
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
413 foreach (size_t i, TemplateParameter tp; parameters)
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
414 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
415 if (i)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
416 buf.writeByte(',');
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
417 tp.toCBuffer(buf, &hgs);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
418 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
419 buf.writeByte(')');
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
420 version (DMDV2) {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
421 if (constraint)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
422 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
423 buf.writestring(" if (");
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
424 constraint.toCBuffer(buf, &hgs);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
425 buf.writeByte(')');
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
426 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
427 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
428 buf.writeByte(0);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 8
diff changeset
429 return buf.extractString();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
432 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 }
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
436
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
437 // void toDocBuffer(OutBuffer *buf);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 * Given that ti is an instance of this TemplateDeclaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 * deduce the types of the parameters to this, and store
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 * those deduced types in dedtypes[].
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 * flag 1: don't do semantic() because of dummy types
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 * 2: don't change types in matchArg()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 * dedtypes deduced arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 * Return match level.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
450 MATCH matchWithInstance(TemplateInstance ti, Objects dedtypes, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 int dedtypes_dim = dedtypes.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 version (LOGM) {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
456 printf("\n+TemplateDeclaration.matchWithInstance(this = %.*s, ti = %.*s, flag = %d)\n", toChars(), ti.toChars(), flag);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 printf("dedtypes.dim = %d, parameters.dim = %d\n", dedtypes_dim, parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 if (ti.tiargs.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 printf("ti.tiargs.dim = %d, [0] = %p\n", ti.tiargs.dim, ti.tiargs.data[0]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 dedtypes.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 int parameters_dim = parameters.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 int variadic = isVariadic() !is null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 // If more arguments than parameters, no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 if (ti.tiargs.dim > parameters_dim && !variadic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 version (LOGM) {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
473 printf(" no match: more arguments than parameters\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 49
diff changeset
475 return MATCHnomatch;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 assert(dedtypes_dim == parameters_dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 assert(dedtypes_dim >= ti.tiargs.dim || variadic);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 // Set up scope for parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 assert(cast(size_t)cast(void*)scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 ScopeDsymbol paramsym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 paramsym.parent = scope_.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 Scope paramscope = scope_.push(paramsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 paramscope.stc = STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 // Attempt type deduction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 m = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 for (int i = 0; i < dedtypes_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 MATCH m2;
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
493 auto tp = parameters[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 Declaration sparam;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 //printf("\targument [%d]\n", i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 version (LOGM) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 //printf("\targument [%d] is %s\n", i, oarg ? oarg.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 TemplateTypeParameter *ttp = tp.isTemplateTypeParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 if (ttp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 printf("\tparameter[%d] is %s : %s\n", i, tp.ident.toChars(), ttp.specType ? ttp.specType.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, &sparam);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, &sparam, (flag & 2) ? 1 : 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 //printf("\tm2 = %d\n", m2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 if (m2 == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 printf("\tmatchArg() for parameter %i failed\n", i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 if (m2 < m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 m = m2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 if (!flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 sparam.semantic(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 if (!paramscope.insert(sparam))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 if (!flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 /* Any parameter left without a type gets the type of
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 * its corresponding arg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 for (int i = 0; i < dedtypes_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
535 if (!dedtypes[i])
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 assert(i < ti.tiargs.dim);
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
538 dedtypes[i] = ti.tiargs[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 if (m && constraint && !(flag & 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 { /* Check to see if constraint is satisfied.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 Expression e = constraint.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 paramscope.flags |= SCOPE.SCOPEstaticif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 e = e.semantic(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 if (e.isBool(true)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 } else if (e.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 e.error("constraint %s is not constant or does not evaluate to a bool", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 version (LOGM) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 // Print out the results
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 printf("--------------------------\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 printf("template %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 printf("instance %s\n", ti.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 if (m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 for (int i = 0; i < dedtypes_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 TemplateParameter tp = cast(TemplateParameter)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 Object oarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 printf(" [%d]", i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 if (i < ti.tiargs.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 oarg = cast(Object)ti.tiargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 oarg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 tp.print(oarg, cast(Object)dedtypes.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 version (LOGM) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 printf(" match = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 goto Lret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 Lnomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 version (LOGM) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 printf(" no match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 m = MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 Lret:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 paramscope.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 version (LOGM) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 printf("-TemplateDeclaration.matchWithInstance(this = %p, ti = %p) = %d\n", this, ti, m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
606 /********************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
607 * Determine partial specialization order of 'this' vs td2.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
608 * Returns:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
609 * match this is at least as specialized as td2
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
610 * 0 td2 is more specialized than this
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
611 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
612 MATCH leastAsSpecialized(TemplateDeclaration td2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 {
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
614 /* This works by taking the template parameters to this template
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
615 * declaration and feeding them to td2 as if it were a template
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
616 * instance.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
617 * If it works, then this template is at least as specialized
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
618 * as td2.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
619 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
620
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
621 scope TemplateInstance ti = new TemplateInstance(Loc(0), ident); // create dummy template instance
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
622 scope Objects dedtypes = new Objects();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
623
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
624 version (LOG_LEASTAS) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
625 printf("%s.leastAsSpecialized(%s)\n", toChars(), td2.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
626 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
627
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
628 // Set type arguments to dummy template instance to be types
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
629 // generated from the parameters to this template declaration
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
630 ti.tiargs = new Objects();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
631 ti.tiargs.setDim(parameters.dim);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
632 for (int i = 0; i < ti.tiargs.dim; i++)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
633 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
634 auto tp = parameters[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
635
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
636 auto p = tp.dummyArg();
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
637 if (p)
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
638 ti.tiargs[i] = p;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
639 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
640 ti.tiargs.setDim(i);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
641 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
642
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
643 // Temporary Array to hold deduced types
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
644 //dedtypes.setDim(parameters.dim);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
645 dedtypes.setDim(td2.parameters.dim);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
646
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
647 // Attempt a type deduction
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
648 MATCH m = td2.matchWithInstance(ti, dedtypes, 1);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
649 if (m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
650 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
651 /* A non-variadic template is more specialized than a
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
652 * variadic one.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
653 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
654 if (isVariadic() && !td2.isVariadic())
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
655 goto L1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
656
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
657 version (LOG_LEASTAS) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
658 printf(" matches %d, so is least as specialized\n", m);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
659 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
660 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
661 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
662 L1:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
663 version (LOG_LEASTAS) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
664 printf(" doesn't match, so is not as specialized\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
665 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 50
diff changeset
666 return MATCHnomatch;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 /*************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 * Match function arguments against a specific template function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 * loc instantiation location
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 * targsi Expression/Type initial list of template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 * ethis 'this' argument if !null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 * fargs arguments to function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 * dedargs Expression/Type deduced template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 * match level
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
681 MATCH deduceFunctionTemplateMatch(Loc loc, Objects targsi, Expression ethis, Expressions fargs, Objects dedargs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 size_t nfparams;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 size_t nfargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 size_t nargsi; // array size of targsi
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 int fptupindex = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 int tuple_dim = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 MATCH match = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 FuncDeclaration fd = onemember.toAlias().isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 Arguments fparameters; // function parameter list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 int fvarargs; // function varargs
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 scope Objects dedtypes = new Objects(); // for T:T*, the dedargs is the T*, dedtypes is the T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
694 static if (false)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
695 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 printf("\nTemplateDeclaration.deduceFunctionTemplateMatch() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 for (i = 0; i < fargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 Expression e = cast(Expression)fargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 printf("\tfarg[%d] is %s, type is %s\n", i, e.toChars(), e.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 printf("fd = %s\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 printf("fd.type = %p\n", fd.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 assert(cast(size_t)cast(void*)scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 dedargs.setDim(parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 dedargs.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 dedtypes.setDim(parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 dedtypes.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 // Set up scope for parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 ScopeDsymbol paramsym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 paramsym.parent = scope_.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 Scope paramscope = scope_.push(paramsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 TemplateTupleParameter tp = isVariadic();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
721 static if (false)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
722 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 for (i = 0; i < dedargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 printf("\tdedarg[%d] = ", i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 Object oarg = cast(Object)dedargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 if (oarg) printf("%s", oarg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 nargsi = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 if (targsi)
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
735 {
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
736 // Set initial template arguments
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 nargsi = targsi.dim;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
738 size_t n = parameters.dim;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 if (tp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 n--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 if (nargsi > n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 if (!tp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 /* The extra initial template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 * now form the tuple argument.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 */
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
749 auto t = new Tuple();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 assert(parameters.dim);
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
751 dedargs[parameters.dim - 1] = t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 tuple_dim = nargsi - n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 t.objects.setDim(tuple_dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 for (size_t i = 0; i < tuple_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
757 t.objects[i] = targsi[n + i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 declareParameter(paramscope, tp, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 n = nargsi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
764 memcpy(dedargs.ptr, targsi.ptr, n * (*dedargs.ptr).sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 for (size_t i = 0; i < n; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 assert(i < parameters.dim);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
769 auto tp2 = parameters[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 Declaration sparam = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 m = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 //printf("\tdeduceType m = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 if (m == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 match = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 sparam.semantic(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 if (!paramscope.insert(sparam))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
785 static if (false)
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
786 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 for (i = 0; i < dedargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 printf("\tdedarg[%d] = ", i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 Object oarg = cast(Object)dedargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 if (oarg) printf("%s", oarg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 if (fd.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 assert(fd.type.ty == Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 TypeFunction fdtype = cast(TypeFunction)fd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 fparameters = fdtype.parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 fvarargs = fdtype.varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 CtorDeclaration fctor = fd.isCtorDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 assert(fctor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 fparameters = fctor.arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 fvarargs = fctor.varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 nfparams = Argument.dim(fparameters); // number of function parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 nfargs = fargs ? fargs.dim : 0; // number of function arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 /* Check for match of function arguments with variadic template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 * parameter, such as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 *
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 * template Foo(T, A...) { void Foo(T t, A a); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 * void main() { Foo(1,2,3); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 if (tp) // if variadic
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 74
diff changeset
822 if (nfparams == 0 && nfargs != 0) // if no function parameters
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
824 auto t = new Tuple();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 //printf("t = %p\n", t);
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
826 dedargs[parameters.dim - 1] = t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 declareParameter(paramscope, tp, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 else if (nfargs < nfparams - 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 /* Figure out which of the function parameters matches
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 * the tuple template parameter. Do this by matching
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 * type identifiers.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 * Set the index of this function parameter to fptupindex.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 for (fptupindex = 0; fptupindex < nfparams; fptupindex++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 {
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
841 auto fparam = fparameters[fptupindex];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 if (fparam.type.ty != Tident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 continue;
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
844 auto tid = cast(TypeIdentifier)fparam.type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 if (!tp.ident.equals(tid.ident) || tid.idents.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 if (fvarargs) // variadic function doesn't
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 goto Lnomatch; // go with variadic template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 /* The types of the function arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 * now form the tuple argument.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 */
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
854 auto t = new Tuple();
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
855 dedargs[parameters.dim - 1] = t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 tuple_dim = nfargs - (nfparams - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 t.objects.setDim(tuple_dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 for (size_t i = 0; i < tuple_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 {
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 87
diff changeset
861 auto farg = fargs[fptupindex + i];
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
862 t.objects[i] = farg.type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 declareParameter(paramscope, tp, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 fptupindex = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 if (nfparams == nfargs) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 } else if (nfargs > nfparams) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 if (fvarargs == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 goto Lnomatch; // too many args, no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 match = MATCHconvert; // match ... with a conversion
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 // Match 'ethis' to any TemplateThisParameter's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 if (ethis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 for (size_t i = 0; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
887 auto tp2 = parameters[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 TemplateThisParameter ttp = tp2.isTemplateThisParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 if (ttp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 Type t = new TypeIdentifier(Loc(0), ttp.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 m = ethis.type.deduceType(paramscope, t, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 if (!m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 match = m; // pick worst match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 // Loop through the function parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 for (size_t i = 0; i < nfparams; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 /* Skip over function parameters which wound up
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 * as part of a template tuple parameter.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 if (i == fptupindex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 if (fptupindex == nfparams - 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 i += tuple_dim - 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 Argument fparam = Argument.getNth(fparameters, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 if (i >= nfargs) // if not enough arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 if (fparam.defaultArg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 /* Default arguments do not participate in template argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 * deduction.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 {
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 87
diff changeset
932 auto farg = fargs[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 printf("\tfarg.type = %s\n", farg.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 printf("\tfparam.type = %s\n", fparam.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 Type argtype = farg.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 /* Allow string literals which are type [] to match with [dim]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 if (farg.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 StringExp se = cast(StringExp)farg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 if (!se.committed && argtype.ty == Tarray &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 fparam.type.toBasetype().ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 argtype = new TypeSArray(argtype.nextOf(), new IntegerExp(se.loc, se.len, Type.tindex));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 argtype = argtype.semantic(se.loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 argtype = argtype.invariantOf();
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 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 m = argtype.deduceType(paramscope, fparam.type, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 //printf("\tdeduceType m = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 /* If no match, see if there's a conversion to a delegate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 if (!m && fparam.type.toBasetype().ty == Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 TypeDelegate td = cast(TypeDelegate)fparam.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 TypeFunction tf = cast(TypeFunction)td.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 if (!tf.varargs && Argument.dim(tf.parameters) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 m = farg.type.deduceType(paramscope, tf.next, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 if (!m && tf.next.toBasetype().ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 m = MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 //printf("\tm2 = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 if (m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 match = m; // pick worst match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 /* The following code for variadic arguments closely
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 * matches TypeFunction.callMatch()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 if (!(fvarargs == 2 && i + 1 == nfparams))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 /* Check for match with function parameter T...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 Type tb = fparam.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 switch (tb.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 // Perhaps we can do better with this, see TypeFunction.callMatch()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 case Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 TypeSArray tsa = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 ulong sz = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 if (sz != nfargs - i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 case Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 TypeArray ta = cast(TypeArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 for (; i < nfargs; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 {
90
39648eb578f6 more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 87
diff changeset
1007 auto arg = fargs[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 assert(arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 /* If lazy array of delegates,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 * convert arg(s) to delegate(s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 Type tret = fparam.isLazyArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 if (tret)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 if (ta.next.equals(arg.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 m = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 m = arg.implicitConvTo(tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 if (m == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 if (tret.toBasetype().ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 m = MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 m = arg.type.deduceType(paramscope, ta.next, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 //m = arg.implicitConvTo(ta.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 if (m == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 match = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 case Tclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 case Tident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 goto Lmatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 Lmatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 /* Fill in any missing arguments with their defaults.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 for (size_t i = nargsi; i < dedargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1057 auto tp2 = parameters[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 //printf("tp2[%d] = %s\n", i, tp2.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 /* For T:T*, the dedargs is the T*, dedtypes is the T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 * But for function templates, we really need them to match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 */
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
1062 Object oarg = dedargs[i];
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
1063 Object oded = dedtypes[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 //printf("1dedargs[%d] = %p, dedtypes[%d] = %p\n", i, oarg, i, oded);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 //if (oarg) printf("oarg: %s\n", oarg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 //if (oded) printf("oded: %s\n", oded.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 if (!oarg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 if (oded)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 if (tp2.specialization())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 /* The specialization can work as long as afterwards
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 * the oded == oarg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 Declaration sparam;
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
1077 dedargs[i] = oded;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 MATCH m2 = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 //printf("m2 = %d\n", m2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 if (!m2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 if (m2 < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 match = m2; // pick worst match
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
1084 if (dedtypes[i] !is oded)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 error("specialization not allowed for deduced parameter %s", tp2.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 oded = tp2.defaultArg(loc, paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 if (!oded)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 declareParameter(paramscope, tp2, oded);
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 90
diff changeset
1095 dedargs[i] = oded;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 if (constraint)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 { /* Check to see if constraint is satisfied.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 Expression e = constraint.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 paramscope.flags |= SCOPE.SCOPEstaticif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 e = e.semantic(paramscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 e = e.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 if (e.isBool(true)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 } else if (e.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 goto Lnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 e.error("constraint %s is not constant or does not evaluate to a bool", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 for (i = 0; i < dedargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 Type t = cast(Type)dedargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 printf("\tdedargs[%d] = %d, %s\n", i, t.dyncast(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 paramscope.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 //printf("\tmatch %d\n", match);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 return match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 Lnomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 paramscope.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 //printf("\tnomatch\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1135
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 /*************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 * Given function arguments, figure out which template function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 * to expand, and return that function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 * If no match, give error message and return null.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 * sc instantiation scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 * loc instantiation location
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 * targsi initial list of template arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 * ethis if !null, the 'this' pointer argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 * fargs arguments to function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 * flags 1: do not issue error message on no match, just return null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 FuncDeclaration deduceFunctionTemplate(Scope sc, Loc loc, Objects targsi, Expression ethis, Expressions fargs, int flags = 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 MATCH m_best = MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 TemplateDeclaration td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 TemplateDeclaration td_best = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 Objects tdargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 TemplateInstance ti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 printf("TemplateDeclaration.deduceFunctionTemplate() %s\n", toChars());
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1159 printf(" targsi:\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 if (targsi)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 for (int i = 0; i < targsi.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 Object arg = cast(Object)targsi.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 printf("\t%s\n", arg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 }
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1168 printf(" fargs:\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 for (int i = 0; i < fargs.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 Expression arg = cast(Expression)fargs.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 printf("\t%s %s\n", arg.type.toChars(), arg.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 //printf("\tty = %d\n", arg.type.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 for (TemplateDeclaration td = this; td; td = td.overnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 if (!td.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 error("forward reference to template %s", td.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 if (!td.onemember || !td.onemember.toAlias().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 error("is not a function template");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 scope Objects dedargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 m = td.deduceFunctionTemplateMatch(loc, targsi, ethis, fargs, dedargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 //printf("deduceFunctionTemplateMatch = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 if (!m) // if no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 if (m < m_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 goto Ltd_best;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 if (m > m_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 goto Ltd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 // Disambiguate by picking the most specialized TemplateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 MATCH c1 = td.leastAsSpecialized(td_best);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 MATCH c2 = td_best.leastAsSpecialized(td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 //printf("c1 = %d, c2 = %d\n", c1, c2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 if (c1 > c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 goto Ltd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 else if (c1 < c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 goto Ltd_best;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 goto Lambig;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 Lambig: // td_best and td are ambiguous
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 td_ambig = td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 Ltd_best: // td_best is the best match so far
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 Ltd: // td is the new best match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 td_ambig = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 assert(cast(size_t)cast(void*)td.scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 td_best = td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 m_best = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 tdargs.setDim(dedargs.dim);
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
1231 memcpy(tdargs.ptr, dedargs.ptr, tdargs.dim * (void*).sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 if (!td_best)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 if (!(flags & 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 error(loc, "does not match any function template declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 if (td_ambig)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 error(loc, "matches more than one function template declaration:\n %s\nand:\n %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 td_best.toChars(), td_ambig.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 /* The best match is td_best with arguments tdargs.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 * Now instantiate the template.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 assert(cast(size_t)cast(void*)td_best.scope_ > 0x10000);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 ti = new TemplateInstance(loc, td_best, tdargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 ti.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 fd = ti.toAlias().isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 return fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 if (!(flags & 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 HdrGenState hgs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 scope OutBuffer bufa = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 Objects args = targsi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 if (args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 for (int i = 0; i < args.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 bufa.writeByte(',');
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
1272 Object oarg = args[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 ObjectToCBuffer(bufa, &hgs, oarg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 argExpTypesToCBuffer(buf, fargs, &hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 error(loc, "cannot deduce template function from argument types !(%s)(%s)", bufa.toChars(), buf.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 /**************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 * Declare template parameter tp with value o, and install it in the scope sc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1287 void declareParameter(Scope sc, TemplateParameter tp, Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 //printf("TemplateDeclaration.declareParameter('%s', o = %p)\n", tp.ident.toChars(), o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 Type targ = isType(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 Expression ea = isExpression(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 Dsymbol sa = isDsymbol(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 Tuple va = isTuple(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 // See if tp.ident already exists with a matching definition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 Dsymbol scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 s = sc.search(loc, tp.ident, &scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 if (s && scopesym == sc.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 TupleDeclaration td = s.isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 if (va && td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 Tuple tup = new Tuple();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 assert(false); // < not implemented
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 ///tup.objects = *td.objects;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 if (match(va, tup, this, sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 if (targ)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 //printf("type %s\n", targ.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 s = new AliasDeclaration(Loc(0), tp.ident, targ);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 else if (sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 //printf("Alias %s %s;\n", sa.ident.toChars(), tp.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 s = new AliasDeclaration(Loc(0), tp.ident, sa);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 else if (ea)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 // tdtypes.data[i] always matches ea here
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 Initializer init = new ExpInitializer(loc, ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 TemplateValueParameter tvp = tp.isTemplateValueParameter();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 Type t = tvp ? tvp.valType : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 VarDeclaration v = new VarDeclaration(loc, t, tp.ident, init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 v.storage_class = STCmanifest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 s = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 else if (va)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 //printf("\ttuple\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 s = new TupleDeclaration(loc, tp.ident, va.objects);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 debug writefln(o.toString());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 error("declaration %s is already defined", tp.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1355 override TemplateDeclaration isTemplateDeclaration() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1357 TemplateTupleParameter isVariadic()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 return .isVariadic(parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361
63
cab4c37afb89 A bunch of implementations
korDen
parents: 51
diff changeset
1362 /***********************************
cab4c37afb89 A bunch of implementations
korDen
parents: 51
diff changeset
1363 * We can overload templates.
cab4c37afb89 A bunch of implementations
korDen
parents: 51
diff changeset
1364 */
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1365 override bool isOverloadable()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 {
104
a1cf34da9ebe + TemplateDeclaration.toCBuffer
Trass3r
parents: 94
diff changeset
1367 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1369 }