annotate dmd/IsExp.d @ 42:24674203f62c

IsExp.syntaxCopy implemented
author korDen
date Sat, 21 Aug 2010 07:19:03 +0400
parents 427f8aa74d28
children adf6f7f216ea
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 {
42
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
58 // This section is identical to that in TemplateDeclaration.syntaxCopy()
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
59 TemplateParameters p = null;
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
60 if (parameters)
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
61 {
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
62 p = new TemplateParameters();
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
63 p.setDim(parameters.dim);
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
64 for (int i = 0; i < p.dim; i++)
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
65 {
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
66 TemplateParameter tp = cast(TemplateParameter)parameters.data[i];
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
67 p.data[i] = cast(void*)tp.syntaxCopy();
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
68 }
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
69 }
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
70
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
71 return new IsExp(loc,
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
72 targ.syntaxCopy(),
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
73 id,
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
74 tok,
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
75 tspec ? tspec.syntaxCopy() : null,
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
76 tok2,
24674203f62c IsExp.syntaxCopy implemented
korDen
parents: 13
diff changeset
77 p);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Type tded;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 /* is(targ id tok tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 * is(targ id == tok2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 //printf("IsExp.semantic(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (id && !(sc.flags & SCOPE.SCOPEstaticif))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 error("can only declare type aliases within static if conditionals");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Type t = targ.trySemantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 goto Lno; // errors, so condition is false
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 targ = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (tok2 != TOK.TOKreserved)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 switch (tok2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 case TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (targ.ty != Ttypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 tded = (cast(TypeTypedef)targ).sym.basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 case TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 if (targ.ty != Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 if ((cast(TypeStruct)targ).sym.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 case TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (targ.ty != Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (!(cast(TypeStruct)targ).sym.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 case TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if ((cast(TypeClass)targ).sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 case TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (!(cast(TypeClass)targ).sym.isInterfaceDeclaration())
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 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 case TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (!targ.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 case TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 case TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 if (!targ.isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 case TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 if (!targ.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 case TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 // If class or interface, get the base class and interfaces
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 if (targ.ty != Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 { ClassDeclaration cd = (cast(TypeClass)targ).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 Arguments args = new Arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 args.reserve(cd.baseclasses.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 for (size_t i = 0; i < cd.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 BaseClass b = cast(BaseClass)cd.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 args.push(cast(void*)new Argument(STCin, b.type, null, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 tded = new TypeTuple(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 case TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if (targ.ty != Tenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 tded = (cast(TypeEnum)targ).sym.memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 case TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 if (targ.ty != Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 tded = (cast(TypeDelegate)targ).next; // the underlying function type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 case TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (targ.ty != Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 /* Generate tuple from function parameter types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 assert(tded.ty == Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 Arguments params = (cast(TypeFunction)tded).parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 size_t dim = Argument.dim(params);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 Arguments args = new Arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 args.reserve(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 Argument arg = Argument.getNth(params, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 assert(arg && arg.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 args.push(cast(void*)new Argument(arg.storageClass, arg.type, null, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 tded = new TypeTuple(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 case TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 /* Get the 'return type' for the function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 * delegate, or pointer to function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 if (targ.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 tded = (cast(TypeFunction)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 else if (targ.ty == Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 { tded = (cast(TypeDelegate)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 tded = (cast(TypeFunction)tded).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 else if (targ.ty == Tpointer &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 (cast(TypePointer)targ).next.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 { tded = (cast(TypePointer)targ).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 tded = (cast(TypeFunction)tded).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 else if (id && tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 /* Evaluate to true if targ matches tspec.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 * If true, declare id as an alias for the specialized type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 assert(parameters && parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 scope Objects dedtypes = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 dedtypes.setDim(parameters.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 dedtypes.zero();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 m = targ.deduceType(null, tspec, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (m == MATCHnomatch ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 (m != MATCHexact && tok == TOKequal))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 tded = cast(Type)dedtypes.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (!tded)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 scope Objects tiargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 tiargs.setDim(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 tiargs.data[0] = cast(void*)targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 /* Declare trailing parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 for (int i = 1; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 TemplateParameter tp = cast(TemplateParameter)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 Declaration s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 m = tp.matchArg(sc, tiargs, i, parameters, dedtypes, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (m == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 error("declaration %s is already defined", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 Object o = cast(Object)dedtypes.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 Dsymbol s = TemplateDeclaration.declareParameter(loc, sc, tp, o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 if (sc.sd)
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
281 s.addMember(sc, sc.sd, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 else if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 /* Declare id as an alias for type targ. Evaluate to true
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 tded = targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 else if (tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 /* Evaluate to true if targ matches tspec
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 * is(targ == tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 * is(targ : tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 tspec = tspec.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 //printf("targ = %s\n", targ.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 //printf("tspec = %s\n", tspec.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 if (tok == TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (targ.implicitConvTo(tspec))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 else /* == */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 if (targ.equals(tspec))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 goto Lyes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 Lyes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 Dsymbol s = new AliasDeclaration(loc, id, tded);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 error("declaration %s is already defined", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 if (sc.sd)
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
327 s.addMember(sc, sc.sd, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 //printf("Lyes\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 return new IntegerExp(loc, 1, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 Lno:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 //printf("Lno\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 return new IntegerExp(loc, 0, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342