annotate dmd/IsExp.d @ 187:b0d41ff5e0df

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