annotate dmd/IsExp.d @ 94:3a0b150c9841

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