annotate dmd/IsExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 427f8aa74d28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.IsExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeEnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TemplateParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TypeTypedef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 class IsExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 /* is(targ id tok tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 * is(targ id == tok2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 Type targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Identifier id; // can be null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 TOK tok; // ':' or '=='
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 Type tspec; // can be null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 TOK tok2; // 'struct', 'union', 'typedef', etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 TemplateParameters parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this(Loc loc, Type targ, Identifier id, TOK tok, Type tspec, TOK tok2, TemplateParameters parameters)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 super(loc, TOK.TOKis, IsExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this.targ = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 this.id = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 this.tok = tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 this.tspec = tspec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 this.tok2 = tok2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 this.parameters = parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Type tded;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 /* is(targ id tok tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 * is(targ id == tok2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 //printf("IsExp.semantic(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 if (id && !(sc.flags & SCOPE.SCOPEstaticif))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 error("can only declare type aliases within static if conditionals");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 Type t = targ.trySemantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 goto Lno; // errors, so condition is false
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 targ = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (tok2 != TOK.TOKreserved)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 switch (tok2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 case TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (targ.ty != Ttypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 tded = (cast(TypeTypedef)targ).sym.basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 case TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (targ.ty != Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if ((cast(TypeStruct)targ).sym.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 case TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (targ.ty != Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (!(cast(TypeStruct)targ).sym.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 case TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if ((cast(TypeClass)targ).sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 case TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (!(cast(TypeClass)targ).sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 case TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (!targ.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 case TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 case TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (!targ.isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 case TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (!targ.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 case TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 // If class or interface, get the base class and interfaces
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 { ClassDeclaration cd = (cast(TypeClass)targ).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Arguments args = new Arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 args.reserve(cd.baseclasses.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 for (size_t i = 0; i < cd.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 BaseClass b = cast(BaseClass)cd.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 args.push(cast(void*)new Argument(STCin, b.type, null, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 tded = new TypeTuple(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 case TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 if (targ.ty != Tenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 tded = (cast(TypeEnum)targ).sym.memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 case TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (targ.ty != Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 tded = (cast(TypeDelegate)targ).next; // the underlying function type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 case TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (targ.ty != Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 /* Generate tuple from function parameter types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 assert(tded.ty == Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 Arguments params = (cast(TypeFunction)tded).parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 size_t dim = Argument.dim(params);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 Arguments args = new Arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 args.reserve(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 Argument arg = Argument.getNth(params, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 assert(arg && arg.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 args.push(cast(void*)new Argument(arg.storageClass, arg.type, null, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 tded = new TypeTuple(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 case TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 /* Get the 'return type' for the function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 * delegate, or pointer to function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (targ.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 tded = (cast(TypeFunction)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 else if (targ.ty == Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 { tded = (cast(TypeDelegate)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 tded = (cast(TypeFunction)tded).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 else if (targ.ty == Tpointer &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 (cast(TypePointer)targ).next.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 { tded = (cast(TypePointer)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 tded = (cast(TypeFunction)tded).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 else if (id && tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 /* Evaluate to true if targ matches tspec.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 * If true, declare id as an alias for the specialized type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 assert(parameters && parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 scope Objects dedtypes = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 dedtypes.setDim(parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 dedtypes.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 m = targ.deduceType(null, tspec, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 if (m == MATCHnomatch ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 (m != MATCHexact && tok == TOKequal))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 tded = cast(Type)dedtypes.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 if (!tded)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 scope Objects tiargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 tiargs.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 tiargs.data[0] = cast(void*)targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 /* Declare trailing parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 for (int i = 1; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 TemplateParameter tp = cast(TemplateParameter)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 Declaration s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 m = tp.matchArg(sc, tiargs, i, parameters, dedtypes, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 if (m == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 error("declaration %s is already defined", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 Object o = cast(Object)dedtypes.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 Dsymbol s = TemplateDeclaration.declareParameter(loc, sc, tp, o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (sc.sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 s.addMember(sc, sc.sd, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 else if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 /* Declare id as an alias for type targ. Evaluate to true
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 else if (tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 /* Evaluate to true if targ matches tspec
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 * is(targ == tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 * is(targ : tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 tspec = tspec.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 //printf("targ = %s\n", targ.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 //printf("tspec = %s\n", tspec.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (tok == TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (targ.implicitConvTo(tspec))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 else /* == */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 if (targ.equals(tspec))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 Lyes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 Dsymbol s = new AliasDeclaration(loc, id, tded);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 error("declaration %s is already defined", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 if (sc.sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 s.addMember(sc, sc.sd, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 //printf("Lyes\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 return new IntegerExp(loc, 1, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 Lno:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 //printf("Lno\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 return new IntegerExp(loc, 0, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323