Mercurial > projects > ddmd
annotate dmd/Parser.d @ 131:206db751bd4c
dmdfe 2.037 compiles now
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Fri, 10 Sep 2010 00:27:37 +0100 |
parents | 60bb0fe4563e |
children | c494af1dba80 |
rev | line source |
---|---|
0 | 1 module dmd.Parser; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Lexer; |
5 import dmd.PostBlitDeclaration; | |
6 import dmd.FileInitExp; | |
7 import dmd.LineInitExp; | |
8 import dmd.EnumMember; | |
9 import dmd.CtorDeclaration; | |
10 import dmd.ShlAssignExp; | |
11 import dmd.ShrAssignExp; | |
12 import dmd.UshrAssignExp; | |
13 import dmd.CatAssignExp; | |
14 import dmd.StaticIfCondition; | |
15 import dmd.TraitsExp; | |
13 | 16 import dmd.TemplateMixin; |
0 | 17 import dmd.BaseClass; |
18 import dmd.AssignExp; | |
19 import dmd.TemplateInstance; | |
20 import dmd.NewExp; | |
21 import dmd.ArrayExp; | |
22 import dmd.DotTemplateInstanceExp; | |
23 import dmd.ClassDeclaration; | |
24 import dmd.NewAnonClassExp; | |
25 import dmd.InterfaceDeclaration; | |
26 import dmd.StructDeclaration; | |
27 import dmd.UnionDeclaration; | |
28 import dmd.AnonDeclaration; | |
29 import dmd.StructInitializer; | |
30 import dmd.ArrayInitializer; | |
31 import dmd.ExpInitializer; | |
32 import dmd.TemplateAliasParameter; | |
33 import dmd.TemplateTupleParameter; | |
34 import dmd.TemplateThisParameter; | |
35 import dmd.TemplateValueParameter; | |
36 import dmd.VoidInitializer; | |
37 import dmd.VersionCondition; | |
38 import dmd.DotIdExp; | |
39 import dmd.DebugCondition; | |
40 import dmd.PostExp; | |
41 import dmd.CallExp; | |
42 import dmd.SliceExp; | |
43 import dmd.FuncExp; | |
44 import dmd.AssocArrayLiteralExp; | |
45 import dmd.ArrayLiteralExp; | |
46 import dmd.IsExp; | |
47 import dmd.FuncLiteralDeclaration; | |
48 import dmd.AssertExp; | |
49 import dmd.CompileExp; | |
50 import dmd.FileExp; | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
51 import dmd.TemplateMixin; |
0 | 52 import dmd.TemplateParameter; |
53 import dmd.TemplateTypeParameter; | |
54 import dmd.TypeidExp; | |
55 import dmd.StringExp; | |
56 import dmd.ScopeExp; | |
57 import dmd.IdentifierExp; | |
58 import dmd.DollarExp; | |
59 import dmd.ThisExp; | |
60 import dmd.SuperExp; | |
61 import dmd.NullExp; | |
62 import dmd.RealExp; | |
63 import dmd.TypeExp; | |
64 import dmd.AddrExp; | |
65 import dmd.MOD; | |
66 import dmd.IntegerExp; | |
67 import dmd.CastExp; | |
68 import dmd.PtrExp; | |
69 import dmd.NegExp; | |
70 import dmd.XorAssignExp; | |
71 import dmd.OrAssignExp; | |
72 import dmd.UAddExp; | |
73 import dmd.NotExp; | |
74 import dmd.ComExp; | |
75 import dmd.DeleteExp; | |
76 import dmd.MulAssignExp; | |
77 import dmd.ModAssignExp; | |
78 import dmd.MinAssignExp; | |
79 import dmd.DivAssignExp; | |
80 import dmd.AndAssignExp; | |
81 import dmd.AddAssignExp; | |
82 import dmd.ModuleDeclaration; | |
83 import dmd.CaseRangeStatement; | |
84 import dmd.CommaExp; | |
85 import dmd.XorExp; | |
86 import dmd.CondExp; | |
87 import dmd.CmpExp; | |
88 import dmd.InExp; | |
89 import dmd.OrOrExp; | |
90 import dmd.OrExp; | |
91 import dmd.AddExp; | |
92 import dmd.MinExp; | |
93 import dmd.CatExp; | |
94 import dmd.AndAndExp; | |
95 import dmd.EqualExp; | |
96 import dmd.ShlExp; | |
97 import dmd.ShrExp; | |
98 import dmd.DivExp; | |
99 import dmd.MulExp; | |
100 import dmd.ModExp; | |
101 import dmd.UshrExp; | |
102 import dmd.IdentityExp; | |
103 import dmd.AndExp; | |
104 import dmd.Id; | |
105 import dmd.LabelStatement; | |
106 import dmd.ExpStatement; | |
107 import dmd.StaticAssertStatement; | |
108 import dmd.DeclarationStatement; | |
109 import dmd.ScopeStatement; | |
110 import dmd.PragmaStatement; | |
111 import dmd.WhileStatement; | |
112 import dmd.DoStatement; | |
113 import dmd.ForStatement; | |
114 import dmd.OnScopeStatement; | |
115 import dmd.IfStatement; | |
116 import dmd.SwitchStatement; | |
117 import dmd.CaseStatement; | |
118 import dmd.DefaultStatement; | |
119 import dmd.GotoDefaultStatement; | |
120 import dmd.GotoCaseStatement; | |
121 import dmd.GotoStatement; | |
122 import dmd.SynchronizedStatement; | |
123 import dmd.WithStatement; | |
124 import dmd.Catch; | |
125 import dmd.TryCatchStatement; | |
126 import dmd.TryFinallyStatement; | |
127 import dmd.ThrowStatement; | |
128 import dmd.VolatileStatement; | |
129 import dmd.ReturnStatement; | |
130 import dmd.BreakStatement; | |
131 import dmd.ContinueStatement; | |
132 import dmd.AsmStatement; | |
133 import dmd.TypeReturn; | |
134 import dmd.TypeTypeof; | |
135 import dmd.ForeachRangeStatement; | |
136 import dmd.ForeachStatement; | |
137 import dmd.CompileStatement; | |
138 import dmd.CompoundStatement; | |
139 import dmd.ConditionalStatement; | |
140 import dmd.CompoundDeclarationStatement; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
141 import dmd.Parameter; |
0 | 142 import dmd.ParseStatementFlags; |
79 | 143 import dmd.TypeNewArray; |
0 | 144 import dmd.TypeNext; |
145 import dmd.TypeInstance; | |
146 import dmd.TypePointer; | |
147 import dmd.TypeDArray; | |
148 import dmd.TypeAArray; | |
149 import dmd.TypeSlice; | |
150 import dmd.TypeSArray; | |
151 import dmd.TemplateInstance; | |
152 import dmd.TypeIdentifier; | |
153 import dmd.VarDeclaration; | |
154 import dmd.TypeFunction; | |
155 import dmd.TypeDelegate; | |
156 import dmd.TY; | |
157 import dmd.LinkDeclaration; | |
158 import dmd.Declaration; | |
159 import dmd.AggregateDeclaration; | |
160 import dmd.TypedefDeclaration; | |
161 import dmd.AliasDeclaration; | |
162 import dmd.LINK; | |
163 import dmd.Loc; | |
164 import dmd.Module; | |
165 import dmd.Array; | |
166 import dmd.Expression; | |
167 import dmd.TemplateDeclaration; | |
168 import dmd.ArrayTypes; | |
169 import dmd.Dsymbol; | |
170 import dmd.StaticAssert; | |
171 import dmd.TypeQualified; | |
172 import dmd.Condition; | |
173 import dmd.PostBlitDeclaration; | |
174 import dmd.DtorDeclaration; | |
175 import dmd.ConditionalDeclaration; | |
176 import dmd.StaticCtorDeclaration; | |
177 import dmd.StaticDtorDeclaration; | |
178 import dmd.InvariantDeclaration; | |
179 import dmd.UnitTestDeclaration; | |
180 import dmd.NewDeclaration; | |
181 import dmd.DeleteDeclaration; | |
182 import dmd.EnumDeclaration; | |
183 import dmd.Import; | |
184 import dmd.Type; | |
185 import dmd.Identifier; | |
186 import dmd.FuncDeclaration; | |
187 import dmd.Statement; | |
188 import dmd.Initializer; | |
189 import dmd.Token; | |
190 import dmd.TOK; | |
191 import dmd.ParseStatementFlags; | |
192 import dmd.PROT; | |
193 import dmd.STC; | |
194 import dmd.Util; | |
195 import dmd.CompileDeclaration; | |
196 import dmd.StaticIfDeclaration; | |
197 import dmd.StorageClassDeclaration; | |
198 import dmd.LinkDeclaration; | |
199 import dmd.ProtDeclaration; | |
200 import dmd.AlignDeclaration; | |
201 import dmd.PragmaDeclaration; | |
202 import dmd.DebugSymbol; | |
203 import dmd.VersionSymbol; | |
204 import dmd.AliasThis; | |
205 import dmd.Global; | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
206 import dmd.TRUST; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
207 import dmd.PowExp; |
0 | 208 |
209 import core.stdc.string : memcpy; | |
210 | |
34 | 211 import std.exception; |
4 | 212 import core.memory; |
0 | 213 |
214 class Parser : Lexer | |
215 { | |
216 ModuleDeclaration md; | |
217 LINK linkage; | |
218 Loc endloc; // set to location of last right curly | |
219 int inBrackets; // inside [] of array index or slice | |
220 | |
221 this(Module module_, ubyte* base, uint length, int doDocComment) | |
222 { | |
223 super(module_, base, 0, length, doDocComment, 0); | |
224 //printf("Parser.Parser()\n"); | |
225 linkage = LINK.LINKd; | |
226 //nextToken(); // start up the scanner | |
227 } | |
228 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
229 Dsymbols parseModule() |
0 | 230 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
231 typeof(return) decldefs; |
0 | 232 |
233 // ModuleDeclation leads off | |
234 if (token.value == TOK.TOKmodule) | |
235 { | |
79 | 236 string comment = token.blockComment; |
0 | 237 bool safe = false; |
238 | |
239 nextToken(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
240 static if(false) { |
0 | 241 version (DMDV2) { |
242 if (token.value == TOK.TOKlparen) | |
243 { | |
244 nextToken(); | |
245 if (token.value != TOK.TOKidentifier) | |
246 { | |
247 error("module (system) identifier expected"); | |
248 goto Lerr; | |
249 } | |
250 Identifier id = token.ident; | |
251 | |
252 if (id is Id.system) | |
253 safe = true; | |
254 else | |
255 error("(safe) expected, not %s", id.toChars()); | |
256 nextToken(); | |
257 check(TOK.TOKrparen); | |
258 } | |
259 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
260 } |
0 | 261 |
262 if (token.value != TOK.TOKidentifier) | |
263 { | |
264 error("Identifier expected following module"); | |
265 goto Lerr; | |
266 } | |
267 else | |
268 { | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
269 Identifiers a = null; |
0 | 270 Identifier id = token.ident; |
271 while (nextToken() == TOK.TOKdot) | |
272 { | |
273 if (!a) | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
274 a = new Identifiers(); |
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
275 a.push(id); |
0 | 276 nextToken(); |
277 if (token.value != TOK.TOKidentifier) | |
278 { error("Identifier expected following package"); | |
279 goto Lerr; | |
280 } | |
281 id = token.ident; | |
282 } | |
283 | |
284 md = new ModuleDeclaration(a, id, safe); | |
285 | |
286 if (token.value != TOK.TOKsemicolon) | |
287 error("';' expected following module declaration instead of %s", token.toChars()); | |
288 | |
289 nextToken(); | |
290 addComment(mod, comment); | |
291 } | |
292 } | |
293 | |
294 decldefs = parseDeclDefs(0); | |
295 if (token.value != TOK.TOKeof) | |
296 { | |
297 error("unrecognized declaration"); | |
298 goto Lerr; | |
299 } | |
300 | |
301 return decldefs; | |
302 | |
303 Lerr: | |
304 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof) | |
305 nextToken(); | |
306 | |
307 nextToken(); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
308 return new Dsymbols(); |
0 | 309 } |
310 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
311 Dsymbols parseDeclDefs(int once) |
0 | 312 { |
313 Dsymbol s; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
314 Dsymbols decldefs; |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
315 Dsymbols a; |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
316 Dsymbols aelse; |
0 | 317 PROT prot; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
318 StorageClass stc; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
319 StorageClass storageClass; |
0 | 320 Condition condition; |
79 | 321 string comment; |
0 | 322 |
323 //printf("Parser.parseDeclDefs()\n"); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
324 decldefs = new Dsymbols(); |
0 | 325 do |
326 { | |
327 comment = token.blockComment; | |
328 storageClass = STC.STCundefined; | |
329 switch (token.value) | |
330 { | |
331 case TOK.TOKenum: | |
332 { /* Determine if this is a manifest constant declaration, | |
333 * or a conventional enum. | |
334 */ | |
335 Token *t = peek(&token); | |
336 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon) | |
337 s = parseEnum(); | |
338 else if (t.value != TOK.TOKidentifier) | |
339 goto Ldeclaration; | |
340 else | |
341 { | |
342 t = peek(t); | |
343 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon || | |
344 t.value == TOK.TOKsemicolon) | |
345 s = parseEnum(); | |
346 else | |
347 goto Ldeclaration; | |
348 } | |
349 break; | |
350 } | |
351 | |
352 case TOK.TOKstruct: | |
353 case TOK.TOKunion: | |
354 case TOK.TOKclass: | |
355 case TOK.TOKinterface: | |
356 s = parseAggregate(); | |
357 break; | |
358 | |
359 case TOK.TOKimport: | |
360 s = parseImport(decldefs, 0); | |
361 break; | |
362 | |
363 case TOK.TOKtemplate: | |
364 s = cast(Dsymbol)parseTemplateDeclaration(); | |
365 break; | |
366 | |
367 case TOK.TOKmixin: | |
368 { Loc loc = this.loc; | |
369 if (peek(&token).value == TOK.TOKlparen) | |
370 { // mixin(string) | |
371 nextToken(); | |
372 check(TOK.TOKlparen, "mixin"); | |
373 Expression e = parseAssignExp(); | |
374 check(TOK.TOKrparen); | |
375 check(TOK.TOKsemicolon); | |
376 s = new CompileDeclaration(loc, e); | |
377 break; | |
378 } | |
379 s = parseMixin(); | |
380 break; | |
381 } | |
382 | |
383 case TOK.TOKwchar: case TOK.TOKdchar: | |
384 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar: | |
385 case TOK.TOKint8: case TOK.TOKuns8: | |
386 case TOK.TOKint16: case TOK.TOKuns16: | |
387 case TOK.TOKint32: case TOK.TOKuns32: | |
388 case TOK.TOKint64: case TOK.TOKuns64: | |
389 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80: | |
390 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80: | |
391 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80: | |
392 case TOK.TOKvoid: | |
393 case TOK.TOKalias: | |
394 case TOK.TOKtypedef: | |
395 case TOK.TOKidentifier: | |
396 case TOK.TOKtypeof: | |
397 case TOK.TOKdot: | |
398 Ldeclaration: | |
399 a = parseDeclarations(STC.STCundefined); | |
400 decldefs.append(a); | |
401 continue; | |
402 | |
403 case TOK.TOKthis: | |
404 s = parseCtor(); | |
405 break; | |
406 | |
407 static if (false) { // dead end, use this(this){} instead | |
408 case TOK.TOKassign: | |
409 s = parsePostBlit(); | |
410 break; | |
411 } | |
412 case TOK.TOKtilde: | |
413 s = parseDtor(); | |
414 break; | |
415 | |
416 case TOK.TOKinvariant: | |
417 { Token *t; | |
418 t = peek(&token); | |
419 if (t.value == TOK.TOKlparen) | |
420 { | |
421 if (peek(t).value == TOK.TOKrparen) | |
422 // invariant() forms start of class invariant | |
423 s = parseInvariant(); | |
424 else | |
425 // invariant(type) | |
426 goto Ldeclaration; | |
427 } | |
428 else | |
429 { | |
430 stc = STC.STCimmutable; | |
431 goto Lstc; | |
432 } | |
433 break; | |
434 } | |
435 | |
436 case TOK.TOKunittest: | |
437 s = parseUnitTest(); | |
438 break; | |
439 | |
440 case TOK.TOKnew: | |
441 s = parseNew(); | |
442 break; | |
443 | |
444 case TOK.TOKdelete: | |
445 s = parseDelete(); | |
446 break; | |
447 | |
448 case TOK.TOKeof: | |
449 case TOK.TOKrcurly: | |
450 return decldefs; | |
451 | |
452 case TOK.TOKstatic: | |
453 nextToken(); | |
454 if (token.value == TOK.TOKthis) | |
455 s = parseStaticCtor(); | |
456 else if (token.value == TOK.TOKtilde) | |
457 s = parseStaticDtor(); | |
458 else if (token.value == TOK.TOKassert) | |
459 s = parseStaticAssert(); | |
460 else if (token.value == TOK.TOKif) | |
461 { condition = parseStaticIfCondition(); | |
462 a = parseBlock(); | |
463 aelse = null; | |
464 if (token.value == TOK.TOKelse) | |
465 { nextToken(); | |
466 aelse = parseBlock(); | |
467 } | |
468 s = new StaticIfDeclaration(condition, a, aelse); | |
469 break; | |
470 } | |
471 else if (token.value == TOK.TOKimport) | |
472 { | |
473 s = parseImport(decldefs, 1); | |
474 } | |
475 else | |
476 { stc = STC.STCstatic; | |
477 goto Lstc2; | |
478 } | |
479 break; | |
480 | |
481 case TOK.TOKconst: | |
482 if (peek(&token).value == TOK.TOKlparen) | |
483 goto Ldeclaration; | |
484 stc = STC.STCconst; | |
485 goto Lstc; | |
486 | |
487 case TOK.TOKimmutable: | |
488 if (peek(&token).value == TOK.TOKlparen) | |
489 goto Ldeclaration; | |
490 stc = STC.STCimmutable; | |
491 goto Lstc; | |
492 | |
493 case TOK.TOKshared: | |
494 if (peek(&token).value == TOK.TOKlparen) | |
495 goto Ldeclaration; | |
496 stc = STC.STCshared; | |
497 goto Lstc; | |
498 | |
499 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc; | |
500 case TOK.TOKauto: stc = STC.STCauto; goto Lstc; | |
501 case TOK.TOKscope: stc = STC.STCscope; goto Lstc; | |
502 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc; | |
503 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc; | |
504 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc; | |
505 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc; | |
506 version (DMDV2) { | |
507 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc; | |
508 case TOK.TOKpure: stc = STC.STCpure; goto Lstc; | |
509 case TOK.TOKref: stc = STC.STCref; goto Lstc; | |
510 case TOK.TOKtls: stc = STC.STCtls; goto Lstc; | |
511 case TOK.TOKgshared: | |
512 stc = STC.STCgshared; goto Lstc; | |
513 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
514 case TOK.TOKat: stc = parseAttribute(); goto Lstc; |
0 | 515 } |
516 | |
517 Lstc: | |
518 if (storageClass & stc) | |
519 error("redundant storage class %s", Token.toChars(token.value)); | |
520 composeStorageClass(storageClass | stc); | |
521 nextToken(); | |
522 Lstc2: | |
523 storageClass |= stc; | |
524 switch (token.value) | |
525 { | |
526 case TOK.TOKconst: | |
527 case TOK.TOKinvariant: | |
528 case TOK.TOKimmutable: | |
529 case TOK.TOKshared: | |
530 // If followed by a (, it is not a storage class | |
531 if (peek(&token).value == TOK.TOKlparen) | |
532 break; | |
533 if (token.value == TOK.TOKconst) | |
534 stc = STC.STCconst; | |
535 else if (token.value == TOK.TOKshared) | |
536 stc = STC.STCshared; | |
537 else | |
538 stc = STC.STCimmutable; | |
539 goto Lstc; | |
540 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc; | |
541 case TOK.TOKauto: stc = STC.STCauto; goto Lstc; | |
542 case TOK.TOKscope: stc = STC.STCscope; goto Lstc; | |
543 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc; | |
544 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc; | |
545 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc; | |
546 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc; | |
547 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc; | |
548 case TOK.TOKpure: stc = STC.STCpure; goto Lstc; | |
549 case TOK.TOKref: stc = STC.STCref; goto Lstc; | |
550 case TOK.TOKtls: stc = STC.STCtls; goto Lstc; | |
551 case TOK.TOKgshared: stc = STC.STCgshared; goto Lstc; | |
552 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
553 case TOK.TOKat: stc = parseAttribute(); goto Lstc; |
0 | 554 default: |
555 break; | |
556 } | |
557 | |
558 /* Look for auto initializers: | |
559 * storage_class identifier = initializer; | |
560 */ | |
561 if (token.value == TOK.TOKidentifier && | |
562 peek(&token).value == TOK.TOKassign) | |
563 { | |
564 a = parseAutoDeclarations(storageClass, comment); | |
565 decldefs.append(a); | |
566 continue; | |
567 } | |
568 | |
569 /* Look for return type inference for template functions. | |
570 */ | |
571 Token *tk; | |
572 if (token.value == TOK.TOKidentifier && | |
573 (tk = peek(&token)).value == TOK.TOKlparen && | |
574 skipParens(tk, &tk) && | |
575 (peek(tk).value == TOK.TOKlparen || | |
576 peek(tk).value == TOK.TOKlcurly) | |
577 ) | |
578 { | |
579 a = parseDeclarations(storageClass); | |
580 decldefs.append(a); | |
581 continue; | |
582 } | |
583 a = parseBlock(); | |
584 s = new StorageClassDeclaration(storageClass, a); | |
585 break; | |
586 | |
587 case TOK.TOKextern: | |
588 if (peek(&token).value != TOK.TOKlparen) | |
589 { | |
590 stc = STC.STCextern; | |
591 goto Lstc; | |
592 } | |
593 { | |
594 LINK linksave = linkage; | |
595 linkage = parseLinkage(); | |
596 a = parseBlock(); | |
597 s = new LinkDeclaration(linkage, a); | |
598 linkage = linksave; | |
599 break; | |
600 } | |
601 | |
602 case TOK.TOKprivate: prot = PROT.PROTprivate; goto Lprot; | |
603 case TOK.TOKpackage: prot = PROT.PROTpackage; goto Lprot; | |
604 case TOK.TOKprotected: prot = PROT.PROTprotected; goto Lprot; | |
605 case TOK.TOKpublic: prot = PROT.PROTpublic; goto Lprot; | |
606 case TOK.TOKexport: prot = PROT.PROTexport; goto Lprot; | |
607 Lprot: | |
608 nextToken(); | |
609 switch (token.value) | |
610 { | |
611 case TOK.TOKprivate: | |
612 case TOK.TOKpackage: | |
613 case TOK.TOKprotected: | |
614 case TOK.TOKpublic: | |
615 case TOK.TOKexport: | |
616 error("redundant protection attribute"); | |
617 break; | |
618 default: | |
619 break; | |
620 } | |
621 a = parseBlock(); | |
622 s = new ProtDeclaration(prot, a); | |
623 break; | |
624 | |
625 case TOK.TOKalign: | |
626 { uint n; | |
627 | |
628 s = null; | |
629 nextToken(); | |
630 if (token.value == TOK.TOKlparen) | |
631 { | |
632 nextToken(); | |
633 if (token.value == TOK.TOKint32v) | |
634 n = cast(uint)token.uns64value; | |
635 else | |
636 { error("integer expected, not %s", token.toChars()); | |
637 n = 1; | |
638 } | |
639 nextToken(); | |
640 check(TOK.TOKrparen); | |
641 } | |
642 else | |
643 n = global.structalign; // default | |
644 | |
645 a = parseBlock(); | |
646 s = new AlignDeclaration(n, a); | |
647 break; | |
648 } | |
649 | |
650 case TOK.TOKpragma: | |
651 { Identifier ident; | |
652 Expressions args = null; | |
653 | |
654 nextToken(); | |
655 check(TOK.TOKlparen); | |
656 if (token.value != TOK.TOKidentifier) | |
657 { error("pragma(identifier expected"); | |
658 goto Lerror; | |
659 } | |
660 ident = token.ident; | |
661 nextToken(); | |
662 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen) | |
663 args = parseArguments(); // pragma(identifier, args...) | |
664 else | |
665 check(TOK.TOKrparen); // pragma(identifier) | |
666 | |
667 if (token.value == TOK.TOKsemicolon) | |
668 a = null; | |
669 else | |
670 a = parseBlock(); | |
671 s = new PragmaDeclaration(loc, ident, args, a); | |
672 break; | |
673 } | |
674 | |
675 case TOK.TOKdebug: | |
676 nextToken(); | |
677 if (token.value == TOK.TOKassign) | |
678 { | |
679 nextToken(); | |
680 if (token.value == TOK.TOKidentifier) | |
681 s = new DebugSymbol(loc, token.ident); | |
682 else if (token.value == TOK.TOKint32v) | |
683 s = new DebugSymbol(loc, cast(uint)token.uns64value); | |
684 else | |
685 { error("identifier or integer expected, not %s", token.toChars()); | |
686 s = null; | |
687 } | |
688 nextToken(); | |
689 if (token.value != TOK.TOKsemicolon) | |
690 error("semicolon expected"); | |
691 nextToken(); | |
692 break; | |
693 } | |
694 | |
695 condition = parseDebugCondition(); | |
696 goto Lcondition; | |
697 | |
698 case TOK.TOKversion: | |
699 nextToken(); | |
700 if (token.value == TOK.TOKassign) | |
701 { | |
702 nextToken(); | |
703 if (token.value == TOK.TOKidentifier) | |
704 s = new VersionSymbol(loc, token.ident); | |
705 else if (token.value == TOK.TOKint32v) | |
706 s = new VersionSymbol(loc, cast(uint)token.uns64value); | |
707 else | |
708 { error("identifier or integer expected, not %s", token.toChars()); | |
709 s = null; | |
710 } | |
711 nextToken(); | |
712 if (token.value != TOK.TOKsemicolon) | |
713 error("semicolon expected"); | |
714 nextToken(); | |
715 break; | |
716 } | |
717 condition = parseVersionCondition(); | |
718 goto Lcondition; | |
719 | |
720 Lcondition: | |
721 a = parseBlock(); | |
722 aelse = null; | |
723 if (token.value == TOK.TOKelse) | |
724 { nextToken(); | |
725 aelse = parseBlock(); | |
726 } | |
727 s = new ConditionalDeclaration(condition, a, aelse); | |
728 break; | |
729 | |
730 case TOK.TOKsemicolon: // empty declaration | |
731 nextToken(); | |
732 continue; | |
733 | |
734 default: | |
735 error("Declaration expected, not '%s'",token.toChars()); | |
736 Lerror: | |
737 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof) | |
738 nextToken(); | |
739 nextToken(); | |
740 s = null; | |
741 continue; | |
742 } | |
743 if (s) | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
744 { decldefs.push(s); |
0 | 745 addComment(s, comment); |
746 } | |
747 } while (!once); | |
748 return decldefs; | |
749 } | |
750 | |
751 /***************************************** | |
752 * Parse auto declarations of the form: | |
753 * storageClass ident = init, ident = init, ... ; | |
754 * and return the array of them. | |
755 * Starts with token on the first ident. | |
756 * Ends with scanner past closing ';' | |
757 */ | |
79 | 758 version (DMDV2) |
759 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
760 Dsymbols parseAutoDeclarations(StorageClass storageClass, const(char)[] comment) |
0 | 761 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
762 auto a = new Dsymbols; |
0 | 763 |
764 while (true) | |
765 { | |
766 Identifier ident = token.ident; | |
767 nextToken(); // skip over ident | |
768 assert(token.value == TOKassign); | |
769 nextToken(); // skip over '=' | |
770 Initializer init = parseInitializer(); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
771 auto v = new VarDeclaration(loc, null, ident, init); |
0 | 772 v.storage_class = storageClass; |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
773 a.push(v); |
0 | 774 if (token.value == TOKsemicolon) |
775 { | |
776 nextToken(); | |
777 addComment(v, comment); | |
778 } | |
779 else if (token.value == TOKcomma) | |
780 { | |
781 nextToken(); | |
782 if (token.value == TOKidentifier && | |
783 peek(&token).value == TOKassign) | |
784 { | |
785 addComment(v, comment); | |
786 continue; | |
787 } | |
788 else | |
789 error("Identifier expected following comma"); | |
790 } | |
791 else | |
792 error("semicolon expected following auto declaration, not '%s'", token.toChars()); | |
793 break; | |
794 } | |
795 return a; | |
796 } | |
797 } | |
798 /******************************************** | |
799 * Parse declarations after an align, protection, or extern decl. | |
800 */ | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
801 Dsymbols parseBlock() |
0 | 802 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
803 Dsymbols a = null; |
0 | 804 Dsymbol ss; |
805 | |
806 //printf("parseBlock()\n"); | |
807 switch (token.value) | |
808 { | |
809 case TOK.TOKsemicolon: | |
810 error("declaration expected following attribute, not ';'"); | |
811 nextToken(); | |
812 break; | |
813 | |
814 case TOK.TOKeof: | |
815 error("declaration expected following attribute, not EOF"); | |
816 break; | |
817 | |
818 case TOK.TOKlcurly: | |
819 nextToken(); | |
820 a = parseDeclDefs(0); | |
821 if (token.value != TOK.TOKrcurly) | |
822 { /* { */ | |
823 error("matching '}' expected, not %s", token.toChars()); | |
824 } | |
825 else | |
826 nextToken(); | |
827 break; | |
828 | |
829 case TOK.TOKcolon: | |
830 nextToken(); | |
831 static if (false) { | |
832 a = null; | |
833 } else { | |
834 a = parseDeclDefs(0); // grab declarations up to closing curly bracket | |
835 } | |
836 break; | |
837 | |
838 default: | |
839 a = parseDeclDefs(1); | |
840 break; | |
841 } | |
842 return a; | |
843 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
844 version(DMDV2) { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
845 void composeStorageClass(StorageClass stc) |
0 | 846 { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
847 StorageClass u = stc; |
0 | 848 u &= STC.STCconst | STC.STCimmutable | STC.STCmanifest; |
849 if (u & (u - 1)) | |
850 error("conflicting storage class %s", Token.toChars(token.value)); | |
851 | |
852 u = stc; | |
853 u &= STC.STCgshared | STC.STCshared | STC.STCtls; | |
854 if (u & (u - 1)) | |
855 error("conflicting storage class %s", Token.toChars(token.value)); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
856 u = stc; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
857 u &= STCsafe | STCsystem | STCtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
858 if (u & (u - 1)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
859 error("conflicting attribute @%s", token.toChars()); |
0 | 860 } |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
861 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
862 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
863 /*********************************************** |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
864 * Parse storage class, lexer is on '@' |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
865 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
866 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
867 version(DMDV2) { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
868 StorageClass parseAttribute() |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
869 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
870 nextToken(); |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
871 StorageClass stc = STCundefined; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
872 if (token.value != TOKidentifier) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
873 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
874 error("identifier expected after @, not %s", token.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
875 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
876 else if (token.ident == Id.property) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
877 stc = STCproperty; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
878 else if (token.ident == Id.safe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
879 stc = STCsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
880 else if (token.ident == Id.trusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
881 stc = STCtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
882 else if (token.ident == Id.system) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
883 stc = STCsystem; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
884 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
885 error("valid attribute identifiers are @property, @safe, @trusted, @system, not @%s", token.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
886 return stc; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
887 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
888 } |
0 | 889 /************************************** |
890 * Parse constraint. | |
891 * Constraint is of the form: | |
892 * if ( ConstraintExpression ) | |
893 */ | |
894 version (DMDV2) { | |
895 Expression parseConstraint() | |
896 { | |
897 Expression e = null; | |
898 | |
899 if (token.value == TOKif) | |
900 { | |
901 nextToken(); // skip over 'if' | |
902 check(TOKlparen); | |
903 e = parseExpression(); | |
904 check(TOKrparen); | |
905 } | |
906 return e; | |
907 } | |
908 } | |
909 /************************************** | |
910 * Parse a TemplateDeclaration. | |
911 */ | |
912 TemplateDeclaration parseTemplateDeclaration() | |
913 { | |
914 TemplateDeclaration tempdecl; | |
915 Identifier id; | |
916 TemplateParameters tpl; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
917 Dsymbols decldefs; |
0 | 918 Expression constraint = null; |
919 Loc loc = this.loc; | |
920 | |
921 nextToken(); | |
922 if (token.value != TOKidentifier) | |
923 { | |
924 error("TemplateIdentifier expected following template"); | |
925 goto Lerr; | |
926 } | |
927 id = token.ident; | |
928 nextToken(); | |
929 tpl = parseTemplateParameterList(); | |
930 if (!tpl) | |
931 goto Lerr; | |
932 | |
933 constraint = parseConstraint(); | |
934 | |
935 if (token.value != TOKlcurly) | |
936 { | |
937 error("members of template declaration expected"); | |
938 goto Lerr; | |
939 } | |
940 else | |
941 { | |
942 nextToken(); | |
943 decldefs = parseDeclDefs(0); | |
944 if (token.value != TOKrcurly) | |
945 { | |
946 error("template member expected"); | |
947 goto Lerr; | |
948 } | |
949 nextToken(); | |
950 } | |
951 | |
952 tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs); | |
953 return tempdecl; | |
954 | |
955 Lerr: | |
956 return null; | |
957 } | |
958 | |
959 /****************************************** | |
960 * Parse template parameter list. | |
961 * Input: | |
962 * flag 0: parsing "( list )" | |
963 * 1: parsing non-empty "list )" | |
964 */ | |
965 TemplateParameters parseTemplateParameterList(int flag = 0) | |
966 { | |
967 TemplateParameters tpl = new TemplateParameters(); | |
968 | |
969 if (!flag && token.value != TOKlparen) | |
970 { | |
971 error("parenthesized TemplateParameterList expected following TemplateIdentifier"); | |
972 goto Lerr; | |
973 } | |
974 nextToken(); | |
975 | |
976 // Get array of TemplateParameters | |
977 if (flag || token.value != TOKrparen) | |
978 { | |
979 int isvariadic = 0; | |
980 | |
981 while (true) | |
982 { | |
983 TemplateParameter tp; | |
984 Identifier tp_ident = null; | |
985 Type tp_spectype = null; | |
986 Type tp_valtype = null; | |
987 Type tp_defaulttype = null; | |
988 Expression tp_specvalue = null; | |
989 Expression tp_defaultvalue = null; | |
990 Token* t; | |
991 | |
992 // Get TemplateParameter | |
993 | |
994 // First, look ahead to see if it is a TypeParameter or a ValueParameter | |
995 t = peek(&token); | |
996 if (token.value == TOKalias) | |
997 { | |
998 // AliasParameter | |
999 nextToken(); | |
1000 Type spectype = null; | |
1001 if (isDeclaration(&token, 2, TOKreserved, null)) | |
1002 { | |
1003 spectype = parseType(&tp_ident); | |
1004 } | |
1005 else | |
1006 { | |
1007 if (token.value != TOKidentifier) | |
1008 { | |
1009 error("identifier expected for template alias parameter"); | |
1010 goto Lerr; | |
1011 } | |
1012 tp_ident = token.ident; | |
1013 nextToken(); | |
1014 } | |
1015 Object spec = null; | |
1016 if (token.value == TOKcolon) // : Type | |
1017 { | |
1018 nextToken(); | |
1019 if (isDeclaration(&token, 0, TOKreserved, null)) | |
1020 spec = parseType(); | |
1021 else | |
1022 spec = parseCondExp(); | |
1023 } | |
1024 Object def = null; | |
1025 if (token.value == TOKassign) // = Type | |
1026 { | |
1027 nextToken(); | |
1028 if (isDeclaration(&token, 0, TOKreserved, null)) | |
1029 def = parseType(); | |
1030 else | |
1031 def = parseCondExp(); | |
1032 } | |
1033 tp = new TemplateAliasParameter(loc, tp_ident, spectype, spec, def); | |
1034 } | |
1035 else if (t.value == TOKcolon || t.value == TOKassign || | |
1036 t.value == TOKcomma || t.value == TOKrparen) | |
1037 { // TypeParameter | |
1038 if (token.value != TOKidentifier) | |
1039 { error("identifier expected for template type parameter"); | |
1040 goto Lerr; | |
1041 } | |
1042 tp_ident = token.ident; | |
1043 nextToken(); | |
1044 if (token.value == TOKcolon) // : Type | |
1045 { | |
1046 nextToken(); | |
1047 tp_spectype = parseType(); | |
1048 } | |
1049 if (token.value == TOKassign) // = Type | |
1050 { | |
1051 nextToken(); | |
1052 tp_defaulttype = parseType(); | |
1053 } | |
1054 tp = new TemplateTypeParameter(loc, tp_ident, tp_spectype, tp_defaulttype); | |
1055 } | |
1056 else if (token.value == TOKidentifier && t.value == TOKdotdotdot) | |
1057 { // ident... | |
1058 if (isvariadic) | |
1059 error("variadic template parameter must be last"); | |
1060 isvariadic = 1; | |
1061 tp_ident = token.ident; | |
1062 nextToken(); | |
1063 nextToken(); | |
1064 tp = new TemplateTupleParameter(loc, tp_ident); | |
1065 } | |
1066 /// version (DMDV2) { | |
1067 else if (token.value == TOKthis) | |
1068 { // ThisParameter | |
1069 nextToken(); | |
1070 if (token.value != TOKidentifier) | |
1071 { error("identifier expected for template this parameter"); | |
1072 goto Lerr; | |
1073 } | |
1074 tp_ident = token.ident; | |
1075 nextToken(); | |
1076 if (token.value == TOKcolon) // : Type | |
1077 { | |
1078 nextToken(); | |
1079 tp_spectype = parseType(); | |
1080 } | |
1081 if (token.value == TOKassign) // = Type | |
1082 { | |
1083 nextToken(); | |
1084 tp_defaulttype = parseType(); | |
1085 } | |
1086 tp = new TemplateThisParameter(loc, tp_ident, tp_spectype, tp_defaulttype); | |
1087 } | |
1088 /// } | |
1089 else | |
1090 { // ValueParameter | |
1091 tp_valtype = parseType(&tp_ident); | |
1092 if (!tp_ident) | |
1093 { | |
1094 error("identifier expected for template value parameter"); | |
1095 tp_ident = new Identifier("error", TOKidentifier); | |
1096 } | |
1097 if (token.value == TOKcolon) // : CondExpression | |
1098 { | |
1099 nextToken(); | |
1100 tp_specvalue = parseCondExp(); | |
1101 } | |
1102 if (token.value == TOKassign) // = CondExpression | |
1103 { | |
1104 nextToken(); | |
1105 tp_defaultvalue = parseDefaultInitExp(); | |
1106 } | |
1107 tp = new TemplateValueParameter(loc, tp_ident, tp_valtype, tp_specvalue, tp_defaultvalue); | |
1108 } | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1109 tpl.push(tp); |
0 | 1110 if (token.value != TOKcomma) |
1111 break; | |
1112 nextToken(); | |
1113 } | |
1114 } | |
1115 check(TOKrparen); | |
1116 | |
1117 Lerr: | |
1118 return tpl; | |
1119 } | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1120 |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1121 /****************************************** |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1122 * Parse template mixin. |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1123 * mixin Foo; |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1124 * mixin Foo!(args); |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1125 * mixin a.b.c!(args).Foo!(args); |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1126 * mixin Foo!(args) identifier; |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1127 * mixin typeof(expr).identifier!(args); |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1128 */ |
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1129 |
0 | 1130 Dsymbol parseMixin() |
1131 { | |
13 | 1132 TemplateMixin tm; |
1133 Identifier id; | |
1134 Type tqual; | |
1135 Objects tiargs; | |
1136 Array idents; | |
1137 | |
1138 //printf("parseMixin()\n"); | |
1139 nextToken(); | |
1140 tqual = null; | |
1141 if (token.value == TOKdot) | |
1142 { | |
1143 id = Id.empty; | |
1144 } | |
1145 else | |
1146 { | |
1147 if (token.value == TOKtypeof) | |
1148 { | |
1149 tqual = parseTypeof(); | |
1150 check(TOKdot); | |
1151 } | |
1152 if (token.value != TOKidentifier) | |
1153 { | |
1154 error("identifier expected, not %s", token.toChars()); | |
1155 id = Id.empty; | |
1156 } | |
1157 else | |
1158 id = token.ident; | |
1159 nextToken(); | |
1160 } | |
1161 | |
1162 idents = new Array(); | |
1163 while (1) | |
1164 { | |
1165 tiargs = null; | |
1166 if (token.value == TOKnot) | |
1167 { | |
1168 nextToken(); | |
1169 if (token.value == TOKlparen) | |
1170 tiargs = parseTemplateArgumentList(); | |
1171 else | |
1172 tiargs = parseTemplateArgument(); | |
1173 } | |
1174 if (token.value != TOKdot) | |
1175 break; | |
1176 if (tiargs) | |
1177 { | |
1178 TemplateInstance tempinst = new TemplateInstance(loc, id); | |
1179 tempinst.tiargs = tiargs; | |
1180 id = cast(Identifier)tempinst; | |
1181 tiargs = null; | |
1182 } | |
1183 idents.push(cast(void*)id); | |
1184 nextToken(); | |
1185 if (token.value != TOKidentifier) | |
1186 { | |
1187 error("identifier expected following '.' instead of '%s'", token.toChars()); | |
1188 break; | |
1189 } | |
1190 id = token.ident; | |
1191 nextToken(); | |
1192 } | |
1193 idents.push(cast(void*)id); | |
1194 if (token.value == TOKidentifier) | |
1195 { | |
1196 id = token.ident; | |
1197 nextToken(); | |
1198 } | |
1199 else | |
1200 id = null; | |
1201 | |
1202 tm = new TemplateMixin(loc, id, tqual, idents, tiargs); | |
1203 if (token.value != TOKsemicolon) | |
1204 error("';' expected after mixin"); | |
1205 nextToken(); | |
1206 return tm; | |
0 | 1207 } |
1208 | |
1209 /****************************************** | |
1210 * Parse template argument list. | |
1211 * Input: | |
1212 * current token is opening '(' | |
1213 * Output: | |
1214 * current token is one after closing ')' | |
1215 */ | |
1216 Objects parseTemplateArgumentList() | |
1217 { | |
1218 //printf("Parser.parseTemplateArgumentList()\n"); | |
1219 if (token.value != TOKlparen && token.value != TOKlcurly) | |
1220 { | |
1221 error("!(TemplateArgumentList) expected following TemplateIdentifier"); | |
1222 return new Objects(); | |
1223 } | |
1224 return parseTemplateArgumentList2(); | |
1225 } | |
1226 | |
1227 Objects parseTemplateArgumentList2() | |
1228 { | |
1229 //printf("Parser.parseTemplateArgumentList2()\n"); | |
1230 Objects tiargs = new Objects(); | |
1231 TOK endtok = TOKrparen; | |
1232 nextToken(); | |
1233 | |
1234 // Get TemplateArgumentList | |
1235 if (token.value != endtok) | |
1236 { | |
1237 while (1) | |
1238 { | |
1239 // See if it is an Expression or a Type | |
1240 if (isDeclaration(&token, 0, TOKreserved, null)) | |
1241 { // Template argument is a type | |
1242 Type ta = parseType(); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1243 tiargs.push(ta); |
0 | 1244 } |
1245 else | |
1246 { // Template argument is an expression | |
1247 Expression ea = parseAssignExp(); | |
1248 | |
1249 if (ea.op == TOKfunction) | |
1250 { | |
1251 FuncLiteralDeclaration fd = (cast(FuncExp)ea).fd; | |
1252 if (fd.type.ty == Tfunction) | |
1253 { | |
1254 TypeFunction tf = cast(TypeFunction)fd.type; | |
1255 /* If there are parameters that consist of only an identifier, | |
1256 * rather than assuming the identifier is a type, as we would | |
1257 * for regular function declarations, assume the identifier | |
1258 * is the parameter name, and we're building a template with | |
1259 * a deduced type. | |
1260 */ | |
1261 TemplateParameters tpl = null; | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
1262 foreach (param; tf.parameters) |
0 | 1263 { |
1264 if (param.ident is null && | |
1265 param.type && | |
1266 param.type.ty == Tident && | |
1267 (cast(TypeIdentifier)param.type).idents.dim == 0 | |
1268 ) | |
1269 { | |
1270 /* Switch parameter type to parameter identifier, | |
1271 * parameterize with template type parameter _T | |
1272 */ | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
1273 auto pt = cast(TypeIdentifier)param.type; |
0 | 1274 param.ident = pt.ident; |
1275 Identifier id = Lexer.uniqueId("__T"); | |
1276 param.type = new TypeIdentifier(pt.loc, id); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1277 auto tp = new TemplateTypeParameter(fd.loc, id, null, null); |
0 | 1278 if (!tpl) |
1279 tpl = new TemplateParameters(); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1280 tpl.push(tp); |
0 | 1281 } |
1282 } | |
1283 | |
1284 if (tpl) | |
1285 { | |
1286 // Wrap a template around function fd | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1287 auto decldefs = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1288 decldefs.push(fd); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1289 auto tempdecl = new TemplateDeclaration(fd.loc, fd.ident, tpl, null, decldefs); |
0 | 1290 tempdecl.literal = 1; // it's a template 'literal' |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1291 tiargs.push(tempdecl); |
0 | 1292 goto L1; |
1293 } | |
1294 } | |
1295 } | |
1296 | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1297 tiargs.push(ea); |
0 | 1298 } |
1299 L1: | |
1300 if (token.value != TOKcomma) | |
1301 break; | |
1302 nextToken(); | |
1303 } | |
1304 } | |
1305 check(endtok, "template argument list"); | |
1306 return tiargs; | |
1307 } | |
1308 | |
2 | 1309 /***************************** |
1310 * Parse single template argument, to support the syntax: | |
1311 * foo!arg | |
1312 * Input: | |
1313 * current token is the arg | |
1314 */ | |
0 | 1315 Objects parseTemplateArgument() |
1316 { | |
2 | 1317 //printf("parseTemplateArgument()\n"); |
1318 Objects tiargs = new Objects(); | |
1319 Type ta; | |
1320 switch (token.value) | |
1321 { | |
1322 case TOKidentifier: | |
1323 ta = new TypeIdentifier(loc, token.ident); | |
1324 goto LabelX; | |
1325 | |
1326 case TOKvoid: ta = Type.tvoid; goto LabelX; | |
1327 case TOKint8: ta = Type.tint8; goto LabelX; | |
1328 case TOKuns8: ta = Type.tuns8; goto LabelX; | |
1329 case TOKint16: ta = Type.tint16; goto LabelX; | |
1330 case TOKuns16: ta = Type.tuns16; goto LabelX; | |
1331 case TOKint32: ta = Type.tint32; goto LabelX; | |
1332 case TOKuns32: ta = Type.tuns32; goto LabelX; | |
1333 case TOKint64: ta = Type.tint64; goto LabelX; | |
1334 case TOKuns64: ta = Type.tuns64; goto LabelX; | |
1335 case TOKfloat32: ta = Type.tfloat32; goto LabelX; | |
1336 case TOKfloat64: ta = Type.tfloat64; goto LabelX; | |
1337 case TOKfloat80: ta = Type.tfloat80; goto LabelX; | |
1338 case TOKimaginary32: ta = Type.timaginary32; goto LabelX; | |
1339 case TOKimaginary64: ta = Type.timaginary64; goto LabelX; | |
1340 case TOKimaginary80: ta = Type.timaginary80; goto LabelX; | |
1341 case TOKcomplex32: ta = Type.tcomplex32; goto LabelX; | |
1342 case TOKcomplex64: ta = Type.tcomplex64; goto LabelX; | |
1343 case TOKcomplex80: ta = Type.tcomplex80; goto LabelX; | |
1344 case TOKbit: ta = Type.tbit; goto LabelX; | |
1345 case TOKbool: ta = Type.tbool; goto LabelX; | |
1346 case TOKchar: ta = Type.tchar; goto LabelX; | |
1347 case TOKwchar: ta = Type.twchar; goto LabelX; | |
1348 case TOKdchar: ta = Type.tdchar; goto LabelX; | |
1349 LabelX: | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1350 tiargs.push(ta); |
2 | 1351 nextToken(); |
1352 break; | |
1353 | |
1354 case TOKint32v: | |
1355 case TOKuns32v: | |
1356 case TOKint64v: | |
1357 case TOKuns64v: | |
1358 case TOKfloat32v: | |
1359 case TOKfloat64v: | |
1360 case TOKfloat80v: | |
1361 case TOKimaginary32v: | |
1362 case TOKimaginary64v: | |
1363 case TOKimaginary80v: | |
1364 case TOKnull: | |
1365 case TOKtrue: | |
1366 case TOKfalse: | |
1367 case TOKcharv: | |
1368 case TOKwcharv: | |
1369 case TOKdcharv: | |
1370 case TOKstring: | |
1371 case TOKfile: | |
1372 case TOKline: | |
1373 { | |
1374 // Template argument is an expression | |
1375 Expression ea = parsePrimaryExp(); | |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1376 tiargs.push(ea); |
2 | 1377 break; |
1378 } | |
1379 | |
1380 default: | |
1381 error("template argument expected following !"); | |
1382 break; | |
1383 } | |
1384 | |
1385 if (token.value == TOKnot) | |
1386 error("multiple ! arguments are not allowed"); | |
1387 return tiargs; | |
0 | 1388 } |
1389 | |
1390 /********************************** | |
1391 * Parse a static assertion. | |
1392 */ | |
1393 StaticAssert parseStaticAssert() | |
1394 { | |
1395 Loc loc = this.loc; | |
1396 Expression exp; | |
1397 Expression msg = null; | |
1398 | |
1399 //printf("parseStaticAssert()\n"); | |
1400 nextToken(); | |
1401 check(TOK.TOKlparen); | |
1402 exp = parseAssignExp(); | |
1403 if (token.value == TOK.TOKcomma) | |
1404 { | |
1405 nextToken(); | |
1406 msg = parseAssignExp(); | |
1407 } | |
1408 | |
1409 check(TOK.TOKrparen); | |
1410 check(TOK.TOKsemicolon); | |
1411 | |
1412 return new StaticAssert(loc, exp, msg); | |
1413 } | |
1414 | |
1415 TypeQualified parseTypeof() | |
1416 { | |
1417 TypeQualified t; | |
1418 Loc loc = this.loc; | |
1419 | |
1420 nextToken(); | |
1421 check(TOK.TOKlparen); | |
1422 if (token.value == TOK.TOKreturn) // typeof(return) | |
1423 { | |
1424 nextToken(); | |
1425 t = new TypeReturn(loc); | |
1426 } | |
1427 else | |
1428 { | |
1429 Expression exp = parseExpression(); // typeof(expression) | |
1430 t = new TypeTypeof(loc, exp); | |
1431 } | |
1432 check(TOK.TOKrparen); | |
1433 return t; | |
1434 } | |
1435 | |
1436 /*********************************** | |
1437 * Parse extern (linkage) | |
1438 * The parser is on the 'extern' token. | |
1439 */ | |
1440 LINK parseLinkage() | |
1441 { | |
1442 LINK link = LINK.LINKdefault; | |
1443 nextToken(); | |
1444 assert(token.value == TOK.TOKlparen); | |
1445 nextToken(); | |
1446 if (token.value == TOK.TOKidentifier) | |
1447 { | |
1448 Identifier id = token.ident; | |
1449 | |
1450 nextToken(); | |
1451 if (id == Id.Windows) | |
1452 link = LINK.LINKwindows; | |
1453 else if (id == Id.Pascal) | |
1454 link = LINK.LINKpascal; | |
1455 else if (id == Id.D) | |
1456 link = LINK.LINKd; | |
1457 else if (id == Id.C) | |
1458 { | |
1459 link = LINK.LINKc; | |
1460 if (token.value == TOK.TOKplusplus) | |
1461 { | |
1462 link = LINK.LINKcpp; | |
1463 nextToken(); | |
1464 } | |
1465 } | |
1466 else if (id == Id.System) | |
1467 { | |
114 | 1468 version (Windows) |
1469 { | |
0 | 1470 link = LINK.LINKwindows; |
114 | 1471 } |
1472 else | |
1473 { | |
0 | 1474 link = LINK.LINKc; |
1475 } | |
1476 } | |
1477 else | |
1478 { | |
1479 error("valid linkage identifiers are D, C, C++, Pascal, Windows, System"); | |
1480 link = LINK.LINKd; | |
1481 } | |
1482 } | |
1483 else | |
1484 { | |
1485 link = LINK.LINKd; // default | |
1486 } | |
1487 check(TOK.TOKrparen); | |
1488 | |
1489 return link; | |
1490 } | |
1491 | |
1492 | |
1493 /************************************** | |
1494 * Parse a debug conditional | |
1495 */ | |
1496 Condition parseDebugCondition() | |
1497 { | |
1498 Condition c; | |
1499 | |
1500 if (token.value == TOK.TOKlparen) | |
1501 { | |
1502 nextToken(); | |
1503 uint level = 1; | |
1504 Identifier id = null; | |
1505 | |
1506 if (token.value == TOK.TOKidentifier) | |
1507 id = token.ident; | |
1508 else if (token.value == TOK.TOKint32v) | |
1509 level = cast(uint)token.uns64value; | |
1510 else | |
1511 error("identifier or integer expected, not %s", token.toChars()); | |
1512 | |
1513 nextToken(); | |
1514 check(TOK.TOKrparen); | |
1515 | |
1516 c = new DebugCondition(mod, level, id); | |
1517 } | |
1518 else | |
1519 c = new DebugCondition(mod, 1, null); | |
1520 | |
1521 return c; | |
1522 } | |
1523 | |
1524 /************************************** | |
1525 * Parse a version conditional | |
1526 */ | |
1527 Condition parseVersionCondition() | |
1528 { | |
1529 Condition c; | |
1530 uint level = 1; | |
1531 Identifier id = null; | |
1532 | |
1533 if (token.value == TOK.TOKlparen) | |
1534 { | |
1535 nextToken(); | |
1536 if (token.value == TOK.TOKidentifier) | |
1537 id = token.ident; | |
1538 else if (token.value == TOK.TOKint32v) | |
1539 level = cast(uint)token.uns64value; | |
1540 else { | |
1541 version (DMDV2) { | |
1542 /* Allow: | |
1543 * version (unittest) | |
1544 * even though unittest is a keyword | |
1545 */ | |
1546 if (token.value == TOK.TOKunittest) | |
1547 id = Lexer.idPool(Token.toChars(TOK.TOKunittest)); | |
1548 else | |
1549 error("identifier or integer expected, not %s", token.toChars()); | |
1550 } else { | |
1551 error("identifier or integer expected, not %s", token.toChars()); | |
1552 } | |
1553 } | |
1554 nextToken(); | |
1555 check(TOK.TOKrparen); | |
1556 } | |
1557 else | |
1558 error("(condition) expected following version"); | |
1559 | |
1560 c = new VersionCondition(mod, level, id); | |
1561 | |
1562 return c; | |
1563 } | |
1564 | |
1565 /*********************************************** | |
1566 * static if (expression) | |
1567 * body | |
1568 * else | |
1569 * body | |
1570 */ | |
1571 Condition parseStaticIfCondition() | |
1572 { | |
1573 Expression exp; | |
1574 Condition condition; | |
1575 Array aif; | |
1576 Array aelse; | |
1577 Loc loc = this.loc; | |
1578 | |
1579 nextToken(); | |
1580 if (token.value == TOKlparen) | |
1581 { | |
1582 nextToken(); | |
1583 exp = parseAssignExp(); | |
1584 check(TOKrparen); | |
1585 } | |
1586 else | |
1587 { | |
1588 error("(expression) expected following static if"); | |
1589 exp = null; | |
1590 } | |
1591 condition = new StaticIfCondition(loc, exp); | |
1592 return condition; | |
1593 } | |
1594 | |
1595 /***************************************** | |
1596 * Parse a constructor definition: | |
1597 * this(parameters) { body } | |
1598 * or postblit: | |
1599 * this(this) { body } | |
1600 * or constructor template: | |
1601 * this(templateparameters)(parameters) { body } | |
1602 * Current token is 'this'. | |
1603 */ | |
1604 | |
1605 Dsymbol parseCtor() | |
1606 { | |
1607 Loc loc = this.loc; | |
1608 | |
1609 nextToken(); | |
1610 if (token.value == TOK.TOKlparen && peek(&token).value == TOK.TOKthis) | |
1611 { // this(this) { ... } | |
1612 nextToken(); | |
1613 nextToken(); | |
1614 check(TOK.TOKrparen); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1615 auto f = new PostBlitDeclaration(loc, Loc(0)); |
0 | 1616 parseContracts(f); |
1617 return f; | |
1618 } | |
1619 | |
1620 /* Look ahead to see if: | |
1621 * this(...)(...) | |
1622 * which is a constructor template | |
1623 */ | |
1624 TemplateParameters tpl = null; | |
1625 if (token.value == TOK.TOKlparen && peekPastParen(&token).value == TOK.TOKlparen) | |
1626 { tpl = parseTemplateParameterList(); | |
1627 | |
1628 int varargs; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1629 auto arguments = parseParameters(&varargs); |
0 | 1630 |
1631 Expression constraint = null; | |
1632 if (tpl) | |
1633 constraint = parseConstraint(); | |
1634 | |
1635 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs); | |
1636 parseContracts(f); | |
1637 | |
1638 // Wrap a template around it | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1639 auto decldefs = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1640 decldefs.push(f); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1641 auto tempdecl = new TemplateDeclaration(loc, f.ident, tpl, constraint, decldefs); |
0 | 1642 return tempdecl; |
1643 } | |
1644 | |
1645 /* Just a regular constructor | |
1646 */ | |
1647 int varargs; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1648 auto arguments = parseParameters(&varargs); |
0 | 1649 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs); |
1650 parseContracts(f); | |
1651 return f; | |
1652 } | |
1653 | |
1654 PostBlitDeclaration parsePostBlit() | |
1655 { | |
1656 assert(false); | |
1657 } | |
1658 | |
1659 /***************************************** | |
1660 * Parse a destructor definition: | |
1661 * ~this() { body } | |
1662 * Current token is '~'. | |
1663 */ | |
1664 DtorDeclaration parseDtor() | |
1665 { | |
1666 DtorDeclaration f; | |
1667 Loc loc = this.loc; | |
1668 | |
1669 nextToken(); | |
1670 check(TOKthis); | |
1671 check(TOKlparen); | |
1672 check(TOKrparen); | |
1673 | |
1674 f = new DtorDeclaration(loc, Loc(0)); | |
1675 parseContracts(f); | |
1676 return f; | |
1677 } | |
1678 | |
1679 /***************************************** | |
1680 * Parse a static constructor definition: | |
1681 * static this() { body } | |
1682 * Current token is 'this'. | |
1683 */ | |
1684 StaticCtorDeclaration parseStaticCtor() | |
1685 { | |
1686 StaticCtorDeclaration f; | |
1687 Loc loc = this.loc; | |
1688 | |
1689 nextToken(); | |
1690 check(TOKlparen); | |
1691 check(TOKrparen); | |
1692 | |
1693 f = new StaticCtorDeclaration(loc, Loc(0)); | |
1694 parseContracts(f); | |
1695 return f; | |
1696 } | |
1697 | |
1698 /***************************************** | |
1699 * Parse a static destructor definition: | |
1700 * static ~this() { body } | |
1701 * Current token is '~'. | |
1702 */ | |
1703 StaticDtorDeclaration parseStaticDtor() | |
1704 { | |
1705 StaticDtorDeclaration f; | |
1706 Loc loc = this.loc; | |
1707 | |
1708 nextToken(); | |
1709 check(TOKthis); | |
1710 check(TOKlparen); | |
1711 check(TOKrparen); | |
1712 | |
1713 f = new StaticDtorDeclaration(loc, Loc(0)); | |
1714 parseContracts(f); | |
1715 return f; | |
1716 } | |
1717 | |
1718 /***************************************** | |
1719 * Parse an invariant definition: | |
1720 * invariant() { body } | |
1721 * Current token is 'invariant'. | |
1722 */ | |
1723 InvariantDeclaration parseInvariant() | |
1724 { | |
1725 InvariantDeclaration f; | |
1726 Loc loc = this.loc; | |
1727 | |
1728 nextToken(); | |
1729 if (token.value == TOKlparen) // optional () | |
1730 { | |
1731 nextToken(); | |
1732 check(TOKrparen); | |
1733 } | |
1734 | |
1735 f = new InvariantDeclaration(loc, Loc(0)); | |
1736 f.fbody = parseStatement(ParseStatementFlags.PScurly); | |
1737 return f; | |
1738 } | |
1739 | |
1740 /***************************************** | |
1741 * Parse a unittest definition: | |
1742 * unittest { body } | |
1743 * Current token is 'unittest'. | |
1744 */ | |
1745 UnitTestDeclaration parseUnitTest() | |
1746 { | |
1747 Loc loc = this.loc; | |
1748 | |
1749 nextToken(); | |
1750 | |
1751 UnitTestDeclaration f = new UnitTestDeclaration(loc, this.loc); | |
1752 f.fbody = parseStatement(ParseStatementFlags.PScurly); | |
1753 | |
1754 return f; | |
1755 } | |
1756 | |
123 | 1757 /***************************************** |
1758 * Parse a new definition: | |
1759 * new(arguments) { body } | |
1760 * Current token is 'new'. | |
1761 */ | |
0 | 1762 NewDeclaration parseNew() |
1763 { | |
123 | 1764 NewDeclaration f; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1765 scope arguments = new Parameters(); |
123 | 1766 int varargs; |
1767 Loc loc = this.loc; | |
1768 | |
1769 nextToken(); | |
1770 arguments = parseParameters(&varargs); | |
1771 f = new NewDeclaration(loc, Loc(0), arguments, varargs); | |
1772 parseContracts(f); | |
1773 return f; | |
0 | 1774 } |
1775 | |
123 | 1776 /***************************************** |
1777 * Parse a delete definition: | |
1778 * delete(arguments) { body } | |
1779 * Current token is 'delete'. | |
1780 */ | |
0 | 1781 DeleteDeclaration parseDelete() |
1782 { | |
123 | 1783 DeleteDeclaration f; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1784 scope Parameters arguments; |
123 | 1785 int varargs; |
1786 Loc loc = this.loc; | |
1787 | |
1788 nextToken(); | |
1789 arguments = parseParameters(&varargs); | |
1790 if (varargs) | |
1791 error("... not allowed in delete function parameter list"); | |
1792 f = new DeleteDeclaration(loc, Loc(0), arguments); | |
1793 parseContracts(f); | |
1794 return f; | |
0 | 1795 } |
1796 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1797 Parameters parseParameters(int* pvarargs) |
0 | 1798 { |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1799 auto arguments = new Parameters(); |
0 | 1800 int varargs = 0; |
1801 int hasdefault = 0; | |
1802 | |
1803 check(TOK.TOKlparen); | |
1804 while (1) | |
1805 { Type *tb; | |
1806 Identifier ai = null; | |
1807 Type at; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1808 Parameter a; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
1809 StorageClass storageClass = STC.STCundefined; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
1810 StorageClass stc; |
0 | 1811 Expression ae; |
1812 | |
1813 for ( ;1; nextToken()) | |
1814 { | |
1815 switch (token.value) | |
1816 { | |
1817 case TOK.TOKrparen: | |
1818 break; | |
1819 | |
1820 case TOK.TOKdotdotdot: | |
1821 varargs = 1; | |
1822 nextToken(); | |
1823 break; | |
1824 | |
1825 case TOK.TOKconst: | |
1826 if (peek(&token).value == TOK.TOKlparen) | |
1827 goto Ldefault; | |
1828 stc = STC.STCconst; | |
1829 goto L2; | |
1830 | |
1831 case TOK.TOKinvariant: | |
1832 case TOK.TOKimmutable: | |
1833 if (peek(&token).value == TOK.TOKlparen) | |
1834 goto Ldefault; | |
1835 stc = STC.STCimmutable; | |
1836 goto L2; | |
1837 | |
1838 case TOK.TOKshared: | |
1839 if (peek(&token).value == TOK.TOKlparen) | |
1840 goto Ldefault; | |
1841 stc = STC.STCshared; | |
1842 goto L2; | |
1843 | |
1844 case TOK.TOKin: stc = STC.STCin; goto L2; | |
1845 case TOK.TOKout: stc = STC.STCout; goto L2; | |
1846 case TOK.TOKinout: | |
1847 case TOK.TOKref: stc = STC.STCref; goto L2; | |
1848 case TOK.TOKlazy: stc = STC.STClazy; goto L2; | |
1849 case TOK.TOKscope: stc = STC.STCscope; goto L2; | |
1850 case TOK.TOKfinal: stc = STC.STCfinal; goto L2; | |
1851 L2: | |
1852 if (storageClass & stc || | |
1853 (storageClass & STC.STCin && stc & (STC.STCconst | STC.STCscope)) || | |
1854 (stc & STC.STCin && storageClass & (STC.STCconst | STC.STCscope)) | |
1855 ) | |
1856 error("redundant storage class %s", Token.toChars(token.value)); | |
1857 storageClass |= stc; | |
1858 composeStorageClass(storageClass); | |
1859 continue; | |
1860 | |
1861 static if (false) { | |
1862 case TOK.TOKstatic: stc = STC.STCstatic; goto L2; | |
1863 case TOK.TOKauto: storageClass = STC.STCauto; goto L4; | |
1864 case TOK.TOKalias: storageClass = STC.STCalias; goto L4; | |
1865 L4: | |
1866 nextToken(); | |
1867 if (token.value == TOK.TOKidentifier) | |
1868 { ai = token.ident; | |
1869 nextToken(); | |
1870 } | |
1871 else | |
1872 ai = null; | |
1873 at = null; // no type | |
1874 ae = null; // no default argument | |
1875 if (token.value == TOK.TOKassign) // = defaultArg | |
1876 { nextToken(); | |
1877 ae = parseDefaultInitExp(); | |
1878 hasdefault = 1; | |
1879 } | |
1880 else | |
1881 { if (hasdefault) | |
1882 error("default argument expected for alias %s", | |
1883 ai ? ai.toChars() : ""); | |
1884 } | |
1885 goto L3; | |
1886 } | |
1887 | |
1888 default: | |
1889 Ldefault: | |
1890 stc = (storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STClazy)); | |
1891 if (stc & (stc - 1)) // if stc is not a power of 2 | |
1892 error("incompatible parameter storage classes"); | |
1893 if ((storageClass & (STC.STCconst | STC.STCout)) == (STC.STCconst | STC.STCout)) | |
1894 error("out cannot be const"); | |
1895 if ((storageClass & (STC.STCimmutable | STC.STCout)) == (STC.STCimmutable | STC.STCout)) | |
1896 error("out cannot be immutable"); | |
1897 if ((storageClass & STC.STCscope) && | |
1898 (storageClass & (STC.STCref | STC.STCout))) | |
1899 error("scope cannot be ref or out"); | |
1900 at = parseType(&ai); | |
1901 ae = null; | |
1902 if (token.value == TOK.TOKassign) // = defaultArg | |
1903 { nextToken(); | |
1904 ae = parseDefaultInitExp(); | |
1905 hasdefault = 1; | |
1906 } | |
1907 else | |
1908 { if (hasdefault) | |
1909 error("default argument expected for %s", | |
1910 ai ? ai.toChars() : at.toChars()); | |
1911 } | |
1912 if (token.value == TOK.TOKdotdotdot) | |
1913 { /* This is: | |
1914 * at ai ... | |
1915 */ | |
1916 | |
1917 if (storageClass & (STC.STCout | STC.STCref)) | |
1918 error("variadic argument cannot be out or ref"); | |
1919 varargs = 2; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1920 a = new Parameter(storageClass, at, ai, ae); |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
1921 arguments.push(a); |
0 | 1922 nextToken(); |
1923 break; | |
1924 } | |
1925 L3: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
1926 a = new Parameter(storageClass, at, ai, ae); |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
1927 arguments.push(a); |
0 | 1928 if (token.value == TOK.TOKcomma) |
1929 { nextToken(); | |
1930 goto L1; | |
1931 } | |
1932 break; | |
1933 } | |
1934 break; | |
1935 } | |
1936 break; | |
1937 | |
1938 L1: ; | |
1939 } | |
1940 check(TOK.TOKrparen); | |
1941 *pvarargs = varargs; | |
1942 return arguments; | |
1943 } | |
1944 | |
1945 EnumDeclaration parseEnum() | |
1946 { | |
1947 EnumDeclaration e; | |
1948 Identifier id; | |
1949 Type memtype; | |
1950 Loc loc = this.loc; | |
1951 | |
1952 //printf("Parser.parseEnum()\n"); | |
1953 nextToken(); | |
1954 if (token.value == TOK.TOKidentifier) | |
1955 { | |
1956 id = token.ident; | |
1957 nextToken(); | |
1958 } | |
1959 else | |
1960 id = null; | |
1961 | |
1962 if (token.value == TOK.TOKcolon) | |
1963 { | |
1964 nextToken(); | |
1965 memtype = parseBasicType(); | |
1966 memtype = parseDeclarator(memtype, null, null); | |
1967 } | |
1968 else | |
1969 memtype = null; | |
1970 | |
1971 e = new EnumDeclaration(loc, id, memtype); | |
1972 if (token.value == TOK.TOKsemicolon && id) | |
1973 nextToken(); | |
1974 else if (token.value == TOK.TOKlcurly) | |
1975 { | |
1976 //printf("enum definition\n"); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
1977 e.members = new Dsymbols(); |
0 | 1978 nextToken(); |
79 | 1979 string comment = token.blockComment; |
0 | 1980 while (token.value != TOK.TOKrcurly) |
1981 { | |
1982 /* Can take the following forms: | |
1983 * 1. ident | |
1984 * 2. ident = value | |
1985 * 3. type ident = value | |
1986 */ | |
1987 | |
1988 loc = this.loc; | |
1989 | |
1990 Type type = null; | |
1991 Identifier ident; | |
1992 Token* tp = peek(&token); | |
1993 if (token.value == TOK.TOKidentifier && | |
1994 (tp.value == TOK.TOKassign || tp.value == TOK.TOKcomma || tp.value == TOK.TOKrcurly)) | |
1995 { | |
1996 ident = token.ident; | |
1997 type = null; | |
1998 nextToken(); | |
1999 } | |
2000 else | |
2001 { | |
2002 type = parseType(&ident, null); | |
2003 if (id || memtype) | |
2004 error("type only allowed if anonymous enum and no enum type"); | |
2005 } | |
2006 | |
2007 Expression value; | |
2008 if (token.value == TOK.TOKassign) | |
2009 { | |
2010 nextToken(); | |
2011 value = parseAssignExp(); | |
2012 } | |
2013 else | |
2014 { | |
2015 value = null; | |
2016 if (type) | |
2017 error("if type, there must be an initializer"); | |
2018 } | |
2019 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2020 auto em = new EnumMember(loc, ident, value, type); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2021 e.members.push(em); |
0 | 2022 |
2023 if (token.value == TOK.TOKrcurly) { | |
2024 ; | |
2025 } else { | |
2026 addComment(em, comment); | |
2027 comment = null; | |
2028 check(TOK.TOKcomma); | |
2029 } | |
2030 addComment(em, comment); | |
2031 comment = token.blockComment; | |
2032 } | |
2033 nextToken(); | |
2034 } | |
2035 else | |
2036 error("enum declaration is invalid"); | |
2037 | |
2038 //printf("-parseEnum() %s\n", e.toChars()); | |
2039 return e; | |
2040 } | |
2041 | |
2042 Dsymbol parseAggregate() | |
2043 { | |
2044 AggregateDeclaration a = null; | |
2045 int anon = 0; | |
2046 TOK tok; | |
2047 Identifier id; | |
2048 TemplateParameters tpl = null; | |
2049 Expression constraint = null; | |
2050 | |
2051 //printf("Parser.parseAggregate()\n"); | |
2052 tok = token.value; | |
2053 nextToken(); | |
2054 if (token.value != TOK.TOKidentifier) | |
2055 { | |
2056 id = null; | |
2057 } | |
2058 else | |
2059 { | |
2060 id = token.ident; | |
2061 nextToken(); | |
2062 | |
2063 if (token.value == TOK.TOKlparen) | |
2064 { | |
2065 // Class template declaration. | |
2066 | |
2067 // Gather template parameter list | |
2068 tpl = parseTemplateParameterList(); | |
2069 constraint = parseConstraint(); | |
2070 } | |
2071 } | |
2072 | |
2073 Loc loc = this.loc; | |
2074 switch (tok) | |
2075 { case TOK.TOKclass: | |
2076 case TOK.TOKinterface: | |
2077 { | |
2078 if (!id) | |
2079 error("anonymous classes not allowed"); | |
2080 | |
2081 // Collect base class(es) | |
2082 BaseClasses baseclasses = null; | |
2083 if (token.value == TOK.TOKcolon) | |
2084 { | |
2085 nextToken(); | |
2086 baseclasses = parseBaseClasses(); | |
2087 | |
2088 if (token.value != TOK.TOKlcurly) | |
2089 error("members expected"); | |
2090 } | |
2091 | |
2092 if (tok == TOK.TOKclass) | |
2093 a = new ClassDeclaration(loc, id, baseclasses); | |
2094 else | |
2095 a = new InterfaceDeclaration(loc, id, baseclasses); | |
2096 break; | |
2097 } | |
2098 | |
2099 case TOK.TOKstruct: | |
2100 if (id) | |
2101 a = new StructDeclaration(loc, id); | |
2102 else | |
2103 anon = 1; | |
2104 break; | |
2105 | |
2106 case TOK.TOKunion: | |
2107 if (id) | |
2108 a = new UnionDeclaration(loc, id); | |
2109 else | |
2110 anon = 2; | |
2111 break; | |
2112 | |
2113 default: | |
2114 assert(0); | |
2115 break; | |
2116 } | |
2117 if (a && token.value == TOK.TOKsemicolon) | |
2118 { nextToken(); | |
2119 } | |
2120 else if (token.value == TOK.TOKlcurly) | |
2121 { | |
2122 //printf("aggregate definition\n"); | |
2123 nextToken(); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2124 auto decl = parseDeclDefs(0); |
0 | 2125 if (token.value != TOK.TOKrcurly) |
2126 error("} expected following member declarations in aggregate"); | |
2127 nextToken(); | |
2128 if (anon) | |
2129 { | |
2130 /* Anonymous structs/unions are more like attributes. | |
2131 */ | |
2132 return new AnonDeclaration(loc, anon - 1, decl); | |
2133 } | |
2134 else | |
2135 a.members = decl; | |
2136 } | |
2137 else | |
2138 { | |
2139 error("{ } expected following aggregate declaration"); | |
2140 a = new StructDeclaration(loc, null); | |
2141 } | |
2142 | |
2143 if (tpl) | |
2144 { // Wrap a template around the aggregate declaration | |
2145 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2146 auto decldefs = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2147 decldefs.push(a); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2148 auto tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs); |
0 | 2149 return tempdecl; |
2150 } | |
2151 | |
2152 return a; | |
2153 } | |
2154 | |
2155 BaseClasses parseBaseClasses() | |
2156 { | |
2157 BaseClasses baseclasses = new BaseClasses(); | |
2158 | |
2159 for (; 1; nextToken()) | |
2160 { | |
2161 PROT protection = PROT.PROTpublic; | |
2162 switch (token.value) | |
2163 { | |
2164 case TOK.TOKprivate: | |
2165 protection = PROT.PROTprivate; | |
2166 nextToken(); | |
2167 break; | |
2168 case TOK.TOKpackage: | |
2169 protection = PROT.PROTpackage; | |
2170 nextToken(); | |
2171 break; | |
2172 case TOK.TOKprotected: | |
2173 protection = PROT.PROTprotected; | |
2174 nextToken(); | |
2175 break; | |
2176 case TOK.TOKpublic: | |
2177 protection = PROT.PROTpublic; | |
2178 nextToken(); | |
2179 break; | |
2180 default: | |
2181 break; /// | |
2182 } | |
2183 if (token.value == TOK.TOKidentifier) | |
2184 { | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
2185 auto b = new BaseClass(parseBasicType(), protection); |
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
2186 baseclasses.push(b); |
0 | 2187 if (token.value != TOK.TOKcomma) |
2188 break; | |
2189 } | |
2190 else | |
2191 { | |
2192 error("base classes expected instead of %s", token.toChars()); | |
2193 return null; | |
2194 } | |
2195 } | |
2196 return baseclasses; | |
2197 } | |
2198 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2199 Import parseImport(Dsymbols decldefs, int isstatic) |
0 | 2200 { |
2201 Import s; | |
2202 Identifier id; | |
2203 Identifier aliasid = null; | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2204 Identifiers a; |
0 | 2205 Loc loc; |
2206 | |
2207 //printf("Parser.parseImport()\n"); | |
2208 do | |
2209 { | |
2210 L1: | |
2211 nextToken(); | |
2212 if (token.value != TOK.TOKidentifier) | |
2213 { | |
2214 error("Identifier expected following import"); | |
2215 break; | |
2216 } | |
2217 | |
2218 loc = this.loc; | |
2219 a = null; | |
2220 id = token.ident; | |
2221 nextToken(); | |
2222 if (!aliasid && token.value == TOK.TOKassign) | |
2223 { | |
2224 aliasid = id; | |
2225 goto L1; | |
2226 } | |
2227 while (token.value == TOK.TOKdot) | |
2228 { | |
2229 if (!a) | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2230 a = new Identifiers(); |
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2231 a.push(id); |
0 | 2232 nextToken(); |
2233 if (token.value != TOK.TOKidentifier) | |
2234 { | |
2235 error("identifier expected following package"); | |
2236 break; | |
2237 } | |
2238 id = token.ident; | |
2239 nextToken(); | |
2240 } | |
2241 | |
2242 s = new Import(loc, a, id, aliasid, isstatic); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2243 decldefs.push(s); |
0 | 2244 |
2245 /* Look for | |
2246 * : alias=name, alias=name; | |
2247 * syntax. | |
2248 */ | |
2249 if (token.value == TOK.TOKcolon) | |
2250 { | |
2251 do | |
2252 { | |
2253 Identifier name; | |
2254 | |
2255 nextToken(); | |
2256 if (token.value != TOK.TOKidentifier) | |
2257 { | |
2258 error("Identifier expected following :"); | |
2259 break; | |
2260 } | |
2261 Identifier alias_ = token.ident; | |
2262 nextToken(); | |
2263 if (token.value == TOK.TOKassign) | |
2264 { | |
2265 nextToken(); | |
2266 if (token.value != TOK.TOKidentifier) | |
2267 { | |
2268 error("Identifier expected following %s=", alias_.toChars()); | |
2269 break; | |
2270 } | |
2271 name = token.ident; | |
2272 nextToken(); | |
2273 } | |
2274 else | |
2275 { | |
2276 name = alias_; | |
2277 alias_ = null; | |
2278 } | |
2279 s.addAlias(name, alias_); | |
2280 } while (token.value == TOK.TOKcomma); | |
2281 | |
2282 break; // no comma-separated imports of this form | |
2283 } | |
2284 | |
2285 aliasid = null; | |
2286 | |
2287 } while (token.value == TOK.TOKcomma); | |
2288 | |
2289 if (token.value == TOK.TOKsemicolon) | |
2290 nextToken(); | |
2291 else | |
2292 { | |
2293 error("';' expected"); | |
2294 nextToken(); | |
2295 } | |
2296 | |
2297 return null; | |
2298 } | |
2299 | |
2300 Type parseType(Identifier* pident = null, TemplateParameters* tpl = null) | |
2301 { | |
2302 Type t; | |
2303 | |
2304 /* Take care of the storage class prefixes that | |
2305 * serve as type attributes: | |
2306 * const shared, shared const, const, invariant, shared | |
2307 */ | |
2308 if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() != TOK.TOKlparen || | |
2309 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() != TOK.TOKlparen) | |
2310 { | |
2311 nextToken(); | |
2312 nextToken(); | |
2313 /* shared const type | |
2314 */ | |
2315 t = parseType(pident, tpl); | |
2316 t = t.makeSharedConst(); | |
2317 return t; | |
2318 } | |
2319 else if (token.value == TOK.TOKconst && peekNext() != TOK.TOKlparen) | |
2320 { | |
2321 nextToken(); | |
2322 /* const type | |
2323 */ | |
2324 t = parseType(pident, tpl); | |
2325 t = t.makeConst(); | |
2326 return t; | |
2327 } | |
2328 else if ((token.value == TOK.TOKinvariant || token.value == TOK.TOKimmutable) && | |
2329 peekNext() != TOK.TOKlparen) | |
2330 { | |
2331 nextToken(); | |
2332 /* invariant type | |
2333 */ | |
2334 t = parseType(pident, tpl); | |
2335 t = t.makeInvariant(); | |
2336 return t; | |
2337 } | |
2338 else if (token.value == TOK.TOKshared && peekNext() != TOK.TOKlparen) | |
2339 { | |
2340 nextToken(); | |
2341 /* shared type | |
2342 */ | |
2343 t = parseType(pident, tpl); | |
2344 t = t.makeShared(); | |
2345 return t; | |
2346 } | |
2347 else | |
2348 t = parseBasicType(); | |
2349 t = parseDeclarator(t, pident, tpl); | |
2350 return t; | |
2351 } | |
2352 | |
2353 Type parseBasicType() | |
2354 { | |
2355 Type t; | |
2356 Identifier id; | |
2357 TypeQualified tid; | |
2358 | |
2359 //printf("parseBasicType()\n"); | |
2360 switch (token.value) | |
2361 { | |
2362 case TOK.TOKvoid: t = Type.tvoid; goto LabelX; | |
2363 case TOK.TOKint8: t = Type.tint8; goto LabelX; | |
2364 case TOK.TOKuns8: t = Type.tuns8; goto LabelX; | |
2365 case TOK.TOKint16: t = Type.tint16; goto LabelX; | |
2366 case TOK.TOKuns16: t = Type.tuns16; goto LabelX; | |
2367 case TOK.TOKint32: t = Type.tint32; goto LabelX; | |
2368 case TOK.TOKuns32: t = Type.tuns32; goto LabelX; | |
2369 case TOK.TOKint64: t = Type.tint64; goto LabelX; | |
2370 case TOK.TOKuns64: t = Type.tuns64; goto LabelX; | |
2371 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX; | |
2372 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX; | |
2373 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX; | |
2374 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX; | |
2375 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX; | |
2376 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX; | |
2377 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX; | |
2378 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX; | |
2379 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX; | |
2380 case TOK.TOKbit: t = Type.tbit; goto LabelX; | |
2381 case TOK.TOKbool: t = Type.tbool; goto LabelX; | |
2382 case TOK.TOKchar: t = Type.tchar; goto LabelX; | |
2383 case TOK.TOKwchar: t = Type.twchar; goto LabelX; | |
2384 case TOK.TOKdchar: t = Type.tdchar; goto LabelX; | |
2385 LabelX: | |
2386 nextToken(); | |
2387 break; | |
2388 | |
2389 case TOK.TOKidentifier: | |
2390 id = token.ident; | |
2391 nextToken(); | |
2392 if (token.value == TOK.TOKnot) | |
2393 { // ident!(template_arguments) | |
2394 TemplateInstance tempinst = new TemplateInstance(loc, id); | |
2395 nextToken(); | |
2396 if (token.value == TOK.TOKlparen) | |
2397 // ident!(template_arguments) | |
2398 tempinst.tiargs = parseTemplateArgumentList(); | |
2399 else | |
2400 // ident!template_argument | |
2401 tempinst.tiargs = parseTemplateArgument(); | |
2402 tid = new TypeInstance(loc, tempinst); | |
2403 goto Lident2; | |
2404 } | |
2405 Lident: | |
2406 tid = new TypeIdentifier(loc, id); | |
2407 Lident2: | |
2408 while (token.value == TOK.TOKdot) | |
2409 { nextToken(); | |
2410 if (token.value != TOK.TOKidentifier) | |
2411 { error("identifier expected following '.' instead of '%s'", token.toChars()); | |
2412 break; | |
2413 } | |
2414 id = token.ident; | |
2415 nextToken(); | |
2416 if (token.value == TOK.TOKnot) | |
2417 { | |
2418 TemplateInstance tempinst = new TemplateInstance(loc, id); | |
2419 nextToken(); | |
2420 if (token.value == TOK.TOKlparen) | |
2421 // ident!(template_arguments) | |
2422 tempinst.tiargs = parseTemplateArgumentList(); | |
2423 else | |
2424 // ident!template_argument | |
2425 tempinst.tiargs = parseTemplateArgument(); | |
56 | 2426 tid.addIdent(tempinst); |
0 | 2427 } |
2428 else | |
2429 tid.addIdent(id); | |
2430 } | |
2431 t = tid; | |
2432 break; | |
2433 | |
2434 case TOK.TOKdot: | |
2435 // Leading . as in .foo | |
2436 id = Id.empty; | |
2437 goto Lident; | |
2438 | |
2439 case TOK.TOKtypeof: | |
2440 // typeof(expression) | |
2441 tid = parseTypeof(); | |
2442 goto Lident2; | |
2443 | |
2444 case TOK.TOKconst: | |
2445 // const(type) | |
2446 nextToken(); | |
2447 check(TOK.TOKlparen); | |
2448 t = parseType(); | |
2449 check(TOK.TOKrparen); | |
2450 if (t.isShared()) | |
2451 t = t.makeSharedConst(); | |
2452 else | |
2453 t = t.makeConst(); | |
2454 break; | |
2455 | |
2456 case TOK.TOKinvariant: | |
2457 case TOK.TOKimmutable: | |
2458 // invariant(type) | |
2459 nextToken(); | |
2460 check(TOK.TOKlparen); | |
2461 t = parseType(); | |
2462 check(TOK.TOKrparen); | |
2463 t = t.makeInvariant(); | |
2464 break; | |
2465 | |
2466 case TOK.TOKshared: | |
2467 // shared(type) | |
2468 nextToken(); | |
2469 check(TOK.TOKlparen); | |
2470 t = parseType(); | |
2471 check(TOK.TOKrparen); | |
2472 if (t.isConst()) | |
2473 t = t.makeSharedConst(); | |
2474 else | |
2475 t = t.makeShared(); | |
2476 break; | |
2477 | |
2478 default: | |
2479 error("basic type expected, not %s", token.toChars()); | |
2480 t = Type.tint32; | |
2481 break; | |
2482 } | |
2483 return t; | |
2484 } | |
2485 | |
2486 Type parseBasicType2(Type t) | |
2487 { | |
79 | 2488 //writef("parseBasicType2()\n"); |
0 | 2489 while (1) |
2490 { | |
79 | 2491 switch (token.value) |
0 | 2492 { |
79 | 2493 case TOK.TOKmul: |
2494 t = new TypePointer(t); | |
2495 nextToken(); | |
2496 continue; | |
2497 | |
2498 case TOK.TOKlbracket: | |
2499 // Handle []. Make sure things like | |
2500 // int[3][1] a; | |
2501 // is (array[1] of array[3] of int) | |
0 | 2502 nextToken(); |
79 | 2503 if (token.value == TOK.TOKrbracket) |
2504 { | |
2505 t = new TypeDArray(t); // [] | |
2506 nextToken(); | |
2507 } | |
2508 else if (token.value == TOKnew && peekNext() == TOKrbracket) | |
0 | 2509 { |
79 | 2510 t = new TypeNewArray(t); // [new] |
2511 nextToken(); | |
2512 nextToken(); | |
2513 } | |
2514 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null)) | |
2515 { // It's an associative array declaration | |
2516 | |
2517 //printf("it's an associative array\n"); | |
2518 Type index = parseType(); // [ type ] | |
2519 t = new TypeAArray(t, index); | |
2520 check(TOK.TOKrbracket); | |
0 | 2521 } |
2522 else | |
79 | 2523 { |
2524 //printf("it's type[expression]\n"); | |
2525 inBrackets++; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2526 Expression e = parseAssignExp(); // [ expression ] |
79 | 2527 if (token.value == TOK.TOKslice) |
2528 { | |
2529 nextToken(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2530 Expression e2 = parseAssignExp(); // [ exp .. exp ] |
79 | 2531 t = new TypeSlice(t, e, e2); |
2532 } | |
2533 else | |
2534 t = new TypeSArray(t,e); | |
2535 inBrackets--; | |
2536 check(TOK.TOKrbracket); | |
2537 } | |
2538 continue; | |
2539 | |
2540 case TOK.TOKdelegate: | |
2541 case TOK.TOKfunction: | |
2542 { // Handle delegate declaration: | |
2543 // t delegate(parameter list) nothrow pure | |
2544 // t function(parameter list) nothrow pure | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2545 Parameters arguments; |
79 | 2546 int varargs; |
2547 bool ispure = false; | |
2548 bool isnothrow = false; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2549 bool isproperty = false; |
79 | 2550 TOK save = token.value; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2551 TRUST trust = TRUSTdefault; |
79 | 2552 |
2553 nextToken(); | |
2554 arguments = parseParameters(&varargs); | |
2555 while (1) | |
2556 { // Postfixes | |
2557 if (token.value == TOK.TOKpure) | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2558 ispure = true; |
79 | 2559 else if (token.value == TOK.TOKnothrow) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2560 isnothrow = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2561 else if (token.value == TOKat) |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2562 { StorageClass stc = parseAttribute(); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2563 switch (cast(uint)(stc >> 32)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2564 { case STCproperty >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2565 isproperty = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2566 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2567 case STCsafe >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2568 trust = TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2569 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2570 case STCsystem >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2571 trust = TRUSTsystem; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2572 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2573 case STCtrusted >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2574 trust = TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2575 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2576 case 0: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2577 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2578 default: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2579 assert(0); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2580 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2581 } |
79 | 2582 else |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2583 break; |
79 | 2584 nextToken(); |
2585 } | |
2586 TypeFunction tf = new TypeFunction(arguments, t, varargs, linkage); | |
2587 tf.ispure = ispure; | |
2588 tf.isnothrow = isnothrow; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2589 tf.isproperty = isproperty; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2590 tf.trust = trust; |
79 | 2591 if (save == TOK.TOKdelegate) |
2592 t = new TypeDelegate(tf); | |
0 | 2593 else |
79 | 2594 t = new TypePointer(tf); // pointer to function |
2595 continue; | |
2596 } | |
2597 | |
2598 default: | |
2599 return t; | |
2600 } | |
2601 assert(0); | |
0 | 2602 } |
2603 assert(0); | |
2604 return null; | |
2605 } | |
2606 | |
2607 Type parseDeclarator(Type t, Identifier* pident, TemplateParameters* tpl = null) | |
2608 { | |
2609 Type ts; | |
2610 | |
2611 //printf("parseDeclarator(tpl = %p)\n", tpl); | |
2612 t = parseBasicType2(t); | |
2613 | |
2614 switch (token.value) | |
2615 { | |
2616 | |
2617 case TOK.TOKidentifier: | |
2618 if (pident) | |
2619 *pident = token.ident; | |
2620 else | |
2621 error("unexpected identifer '%s' in declarator", token.ident.toChars()); | |
2622 ts = t; | |
2623 nextToken(); | |
2624 break; | |
2625 | |
2626 case TOK.TOKlparen: | |
2627 /* Parse things with parentheses around the identifier, like: | |
2628 * int (*ident[3])[] | |
2629 * although the D style would be: | |
2630 * int[]*[3] ident | |
2631 */ | |
2632 nextToken(); | |
2633 ts = parseDeclarator(t, pident); | |
2634 check(TOK.TOKrparen); | |
2635 break; | |
2636 | |
2637 default: | |
2638 ts = t; | |
2639 break; | |
2640 } | |
2641 | |
2642 // parse DeclaratorSuffixes | |
2643 while (1) | |
2644 { | |
2645 switch (token.value) | |
2646 { | |
2647 version (CARRAYDECL) { | |
2648 /* Support C style array syntax: | |
2649 * int ident[] | |
2650 * as opposed to D-style: | |
2651 * int[] ident | |
2652 */ | |
2653 case TOK.TOKlbracket: | |
2654 { // This is the old C-style post [] syntax. | |
2655 TypeNext ta; | |
2656 nextToken(); | |
2657 if (token.value == TOK.TOKrbracket) | |
2658 { // It's a dynamic array | |
2659 ta = new TypeDArray(t); // [] | |
2660 nextToken(); | |
2661 } | |
79 | 2662 else if (token.value == TOKnew && peekNext() == TOKrbracket) |
2663 { | |
2664 t = new TypeNewArray(t); // [new] | |
2665 nextToken(); | |
2666 nextToken(); | |
2667 } | |
0 | 2668 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null)) |
2669 { // It's an associative array | |
2670 | |
2671 //printf("it's an associative array\n"); | |
2672 Type index = parseType(); // [ type ] | |
2673 check(TOK.TOKrbracket); | |
2674 ta = new TypeAArray(t, index); | |
2675 } | |
2676 else | |
2677 { | |
2678 //printf("It's a static array\n"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2679 Expression e = parseAssignExp(); // [ expression ] |
0 | 2680 ta = new TypeSArray(t, e); |
2681 check(TOK.TOKrbracket); | |
2682 } | |
2683 | |
2684 /* Insert ta into | |
2685 * ts . ... . t | |
2686 * so that | |
2687 * ts . ... . ta . t | |
2688 */ | |
2689 Type* pt; | |
2690 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) { | |
2691 ; | |
2692 } | |
2693 *pt = ta; | |
2694 continue; | |
2695 } | |
2696 } | |
2697 case TOK.TOKlparen: | |
2698 { | |
2699 if (tpl) | |
2700 { | |
2701 /* Look ahead to see if this is (...)(...), | |
2702 * i.e. a function template declaration | |
2703 */ | |
2704 if (peekPastParen(&token).value == TOK.TOKlparen) | |
2705 { | |
2706 //printf("function template declaration\n"); | |
2707 | |
2708 // Gather template parameter list | |
2709 *tpl = parseTemplateParameterList(); | |
2710 } | |
2711 } | |
2712 | |
2713 int varargs; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2714 auto arguments = parseParameters(&varargs); |
0 | 2715 Type tf = new TypeFunction(arguments, t, varargs, linkage); |
2716 | |
2717 /* Parse const/invariant/nothrow/pure postfix | |
2718 */ | |
2719 while (1) | |
2720 { | |
2721 switch (token.value) | |
2722 { | |
2723 case TOK.TOKconst: | |
2724 if (tf.isShared()) | |
2725 tf = tf.makeSharedConst(); | |
2726 else | |
2727 tf = tf.makeConst(); | |
2728 nextToken(); | |
2729 continue; | |
2730 | |
2731 case TOK.TOKinvariant: | |
2732 case TOK.TOKimmutable: | |
2733 tf = tf.makeInvariant(); | |
2734 nextToken(); | |
2735 continue; | |
2736 | |
2737 case TOK.TOKshared: | |
2738 if (tf.isConst()) | |
2739 tf = tf.makeSharedConst(); | |
2740 else | |
2741 tf = tf.makeShared(); | |
2742 nextToken(); | |
2743 continue; | |
2744 | |
2745 case TOK.TOKnothrow: | |
2746 (cast(TypeFunction)tf).isnothrow = 1; | |
2747 nextToken(); | |
2748 continue; | |
2749 | |
2750 case TOK.TOKpure: | |
2751 (cast(TypeFunction)tf).ispure = 1; | |
2752 nextToken(); | |
2753 continue; | |
2754 | |
2755 case TOK.TOKat: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2756 { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2757 StorageClass stc = parseAttribute(); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2758 auto tfunc = cast(TypeFunction)tf; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2759 switch (cast(uint)(stc >> 32)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2760 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2761 case STCproperty >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2762 tfunc.isproperty = 1; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2763 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2764 case STCsafe >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2765 tfunc.trust = TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2766 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2767 case STCsystem >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2768 tfunc.trust = TRUSTsystem; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2769 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2770 case STCtrusted >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2771 tfunc.trust = TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2772 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2773 case 0: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2774 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2775 default: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2776 assert(0); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2777 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2778 nextToken(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2779 continue; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2780 } |
0 | 2781 default: |
2782 break; /// | |
2783 } | |
2784 break; | |
2785 } | |
2786 | |
2787 /* Insert tf into | |
2788 * ts . ... . t | |
2789 * so that | |
2790 * ts . ... . tf . t | |
2791 */ | |
2792 Type* pt; | |
2793 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) { | |
2794 ; | |
2795 } | |
2796 *pt = tf; | |
2797 break; | |
2798 } | |
2799 | |
2800 default: | |
2801 break; /// | |
2802 } | |
2803 break; | |
2804 } | |
2805 | |
2806 return ts; | |
2807 } | |
2808 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2809 Dsymbols parseDeclarations(StorageClass storage_class) |
0 | 2810 { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2811 StorageClass stc; |
0 | 2812 Type ts; |
2813 Type t; | |
2814 Type tfirst; | |
2815 Identifier ident; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2816 Dsymbols a; |
0 | 2817 TOK tok = TOK.TOKreserved; |
79 | 2818 string comment = token.blockComment; |
0 | 2819 LINK link = linkage; |
2820 | |
2821 //printf("parseDeclarations() %s\n", token.toChars()); | |
2822 if (storage_class) | |
2823 { ts = null; // infer type | |
2824 goto L2; | |
2825 } | |
2826 | |
2827 switch (token.value) | |
2828 { | |
2829 case TOK.TOKalias: | |
2830 /* Look for: | |
2831 * alias identifier this; | |
2832 */ | |
2833 tok = token.value; | |
2834 nextToken(); | |
2835 if (token.value == TOK.TOKidentifier && peek(&token).value == TOK.TOKthis) | |
2836 { | |
2837 AliasThis s = new AliasThis(this.loc, token.ident); | |
2838 nextToken(); | |
2839 check(TOK.TOKthis); | |
2840 check(TOK.TOKsemicolon); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2841 a = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2842 a.push(s); |
0 | 2843 addComment(s, comment); |
2844 return a; | |
2845 } | |
2846 break; | |
2847 case TOK.TOKtypedef: | |
2848 tok = token.value; | |
2849 nextToken(); | |
2850 break; | |
2851 default: | |
2852 break; | |
2853 } | |
2854 | |
2855 storage_class = STC.STCundefined; | |
2856 while (1) | |
2857 { | |
2858 switch (token.value) | |
2859 { | |
2860 case TOK.TOKconst: | |
2861 if (peek(&token).value == TOK.TOKlparen) | |
2862 break; // const as type constructor | |
2863 stc = STC.STCconst; // const as storage class | |
2864 goto L1; | |
2865 | |
2866 case TOK.TOKinvariant: | |
2867 case TOK.TOKimmutable: | |
2868 if (peek(&token).value == TOK.TOKlparen) | |
2869 break; | |
2870 stc = STC.STCimmutable; | |
2871 goto L1; | |
2872 | |
2873 case TOK.TOKshared: | |
2874 if (peek(&token).value == TOK.TOKlparen) | |
2875 break; | |
2876 stc = STC.STCshared; | |
2877 goto L1; | |
2878 | |
2879 case TOK.TOKstatic: stc = STC.STCstatic; goto L1; | |
2880 case TOK.TOKfinal: stc = STC.STCfinal; goto L1; | |
2881 case TOK.TOKauto: stc = STC.STCauto; goto L1; | |
2882 case TOK.TOKscope: stc = STC.STCscope; goto L1; | |
2883 case TOK.TOKoverride: stc = STC.STCoverride; goto L1; | |
2884 case TOK.TOKabstract: stc = STC.STCabstract; goto L1; | |
2885 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto L1; | |
2886 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto L1; | |
2887 version (DMDV2) { | |
2888 case TOK.TOKnothrow: stc = STC.STCnothrow; goto L1; | |
2889 case TOK.TOKpure: stc = STC.STCpure; goto L1; | |
2890 case TOK.TOKref: stc = STC.STCref; goto L1; | |
2891 case TOK.TOKtls: stc = STC.STCtls; goto L1; | |
2892 case TOK.TOKgshared: stc = STC.STCgshared; goto L1; | |
2893 case TOK.TOKenum: stc = STC.STCmanifest; goto L1; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
2894 case TOK.TOKat: stc = parseAttribute(); goto L1; |
0 | 2895 } |
2896 L1: | |
2897 if (storage_class & stc) | |
2898 error("redundant storage class '%s'", token.toChars()); | |
2899 storage_class = (storage_class | stc); | |
2900 composeStorageClass(storage_class); | |
2901 nextToken(); | |
2902 continue; | |
2903 | |
2904 case TOK.TOKextern: | |
2905 if (peek(&token).value != TOK.TOKlparen) | |
2906 { stc = STC.STCextern; | |
2907 goto L1; | |
2908 } | |
2909 | |
2910 link = parseLinkage(); | |
2911 continue; | |
2912 | |
2913 default: | |
2914 break; | |
2915 } | |
2916 break; | |
2917 } | |
2918 | |
2919 /* Look for auto initializers: | |
2920 * storage_class identifier = initializer; | |
2921 */ | |
2922 if (storage_class && | |
2923 token.value == TOK.TOKidentifier && | |
2924 peek(&token).value == TOK.TOKassign) | |
2925 { | |
2926 return parseAutoDeclarations(storage_class, comment); | |
2927 } | |
2928 | |
2929 if (token.value == TOK.TOKclass) | |
2930 { | |
2931 AggregateDeclaration s = cast(AggregateDeclaration)parseAggregate(); | |
2932 s.storage_class |= storage_class; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2933 a = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2934 a.push(s); |
0 | 2935 addComment(s, comment); |
2936 return a; | |
2937 } | |
2938 | |
2939 /* Look for return type inference for template functions. | |
2940 */ | |
2941 { | |
2942 Token *tk; | |
2943 if (storage_class && | |
2944 token.value == TOK.TOKidentifier && | |
2945 (tk = peek(&token)).value == TOK.TOKlparen && | |
2946 skipParens(tk, &tk) && | |
2947 peek(tk).value == TOK.TOKlparen) | |
2948 { | |
2949 ts = null; | |
2950 } | |
2951 else | |
2952 { | |
2953 ts = parseBasicType(); | |
2954 ts = parseBasicType2(ts); | |
2955 } | |
2956 } | |
2957 | |
2958 L2: | |
2959 tfirst = null; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2960 a = new Dsymbols(); |
0 | 2961 |
2962 while (1) | |
2963 { | |
2964 Loc loc = this.loc; | |
2965 TemplateParameters tpl = null; | |
2966 | |
2967 ident = null; | |
2968 t = parseDeclarator(ts, &ident, &tpl); | |
2969 assert(t); | |
2970 if (!tfirst) | |
2971 tfirst = t; | |
2972 else if (t != tfirst) | |
2973 error("multiple declarations must have the same type, not %s and %s", | |
2974 tfirst.toChars(), t.toChars()); | |
2975 if (!ident) | |
2976 error("no identifier for declarator %s", t.toChars()); | |
2977 | |
2978 if (tok == TOK.TOKtypedef || tok == TOK.TOKalias) | |
2979 { Declaration v; | |
2980 Initializer init = null; | |
2981 | |
2982 if (token.value == TOK.TOKassign) | |
2983 { | |
2984 nextToken(); | |
2985 init = parseInitializer(); | |
2986 } | |
2987 if (tok == TOK.TOKtypedef) | |
2988 v = new TypedefDeclaration(loc, ident, t, init); | |
2989 else | |
2990 { if (init) | |
2991 error("alias cannot have initializer"); | |
2992 v = new AliasDeclaration(loc, ident, t); | |
2993 } | |
2994 v.storage_class = storage_class; | |
2995 if (link == linkage) | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2996 a.push(v); |
0 | 2997 else |
2998 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
2999 auto ax = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3000 ax.push(v); |
0 | 3001 Dsymbol s = new LinkDeclaration(link, ax); |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3002 a.push(s); |
0 | 3003 } |
3004 switch (token.value) | |
3005 { case TOK.TOKsemicolon: | |
3006 nextToken(); | |
3007 addComment(v, comment); | |
3008 break; | |
3009 | |
3010 case TOK.TOKcomma: | |
3011 nextToken(); | |
3012 addComment(v, comment); | |
3013 continue; | |
3014 | |
3015 default: | |
3016 error("semicolon expected to close %s declaration", Token.toChars(tok)); | |
3017 break; | |
3018 } | |
3019 } | |
3020 else if (t.ty == TY.Tfunction) | |
3021 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3022 auto tf = cast(TypeFunction)t; |
0 | 3023 Expression constraint = null; |
3024 static if (false) { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3025 if (Parameter.isTPL(tf.parameters)) |
0 | 3026 { |
3027 if (!tpl) | |
3028 tpl = new TemplateParameters(); | |
3029 } | |
3030 } | |
3031 FuncDeclaration f = | |
3032 new FuncDeclaration(loc, Loc(0), ident, storage_class, t); | |
3033 addComment(f, comment); | |
3034 if (tpl) | |
3035 constraint = parseConstraint(); | |
3036 parseContracts(f); | |
3037 addComment(f, null); | |
3038 Dsymbol s; | |
3039 if (link == linkage) | |
3040 { | |
3041 s = f; | |
3042 } | |
3043 else | |
3044 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3045 auto ax = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3046 ax.push(f); |
0 | 3047 s = new LinkDeclaration(link, ax); |
3048 } | |
3049 /* A template parameter list means it's a function template | |
3050 */ | |
3051 if (tpl) | |
3052 { | |
3053 // Wrap a template around the function declaration | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3054 auto decldefs = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3055 decldefs.push(s); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3056 auto tempdecl = |
0 | 3057 new TemplateDeclaration(loc, s.ident, tpl, constraint, decldefs); |
3058 s = tempdecl; | |
3059 } | |
3060 addComment(s, comment); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3061 a.push(s); |
0 | 3062 } |
3063 else | |
3064 { | |
3065 Initializer init = null; | |
3066 if (token.value == TOK.TOKassign) | |
3067 { | |
3068 nextToken(); | |
3069 init = parseInitializer(); | |
3070 } | |
3071 | |
3072 VarDeclaration v = new VarDeclaration(loc, t, ident, init); | |
3073 v.storage_class = storage_class; | |
3074 if (link == linkage) | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3075 a.push(v); |
0 | 3076 else |
3077 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3078 auto ax = new Dsymbols(); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3079 ax.push(v); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3080 auto s = new LinkDeclaration(link, ax); |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3081 a.push(s); |
0 | 3082 } |
3083 switch (token.value) | |
3084 { case TOK.TOKsemicolon: | |
3085 nextToken(); | |
3086 addComment(v, comment); | |
3087 break; | |
3088 | |
3089 case TOK.TOKcomma: | |
3090 nextToken(); | |
3091 addComment(v, comment); | |
3092 continue; | |
3093 | |
3094 default: | |
3095 error("semicolon expected, not '%s'", token.toChars()); | |
3096 break; | |
3097 } | |
3098 } | |
3099 break; | |
3100 } | |
3101 return a; | |
3102 } | |
3103 | |
3104 void parseContracts(FuncDeclaration f) | |
3105 { | |
3106 LINK linksave = linkage; | |
3107 | |
3108 // The following is irrelevant, as it is overridden by sc.linkage in | |
3109 // TypeFunction.semantic | |
3110 linkage = LINK.LINKd; // nested functions have D linkage | |
3111 L1: | |
3112 switch (token.value) | |
3113 { | |
3114 case TOK.TOKlcurly: | |
3115 if (f.frequire || f.fensure) | |
3116 error("missing body { ... } after in or out"); | |
3117 f.fbody = parseStatement(ParseStatementFlags.PSsemi); | |
3118 f.endloc = endloc; | |
3119 break; | |
3120 | |
3121 case TOK.TOKbody: | |
3122 nextToken(); | |
3123 f.fbody = parseStatement(ParseStatementFlags.PScurly); | |
3124 f.endloc = endloc; | |
3125 break; | |
3126 | |
3127 case TOK.TOKsemicolon: | |
3128 if (f.frequire || f.fensure) | |
3129 error("missing body { ... } after in or out"); | |
3130 nextToken(); | |
3131 break; | |
3132 | |
3133 static if (false) { // Do we want this for function declarations, so we can do: | |
3134 // int x, y, foo(), z; | |
3135 case TOK.TOKcomma: | |
3136 nextToken(); | |
3137 continue; | |
3138 } | |
3139 | |
3140 static if (false) { // Dumped feature | |
3141 case TOK.TOKthrow: | |
3142 if (!f.fthrows) | |
3143 f.fthrows = new Array(); | |
3144 nextToken(); | |
3145 check(TOK.TOKlparen); | |
3146 while (1) | |
3147 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3148 Type tb = parseBasicType(); |
0 | 3149 f.fthrows.push(tb); |
3150 if (token.value == TOK.TOKcomma) | |
3151 { nextToken(); | |
3152 continue; | |
3153 } | |
3154 break; | |
3155 } | |
3156 check(TOK.TOKrparen); | |
3157 goto L1; | |
3158 } | |
3159 | |
3160 case TOK.TOKin: | |
3161 nextToken(); | |
3162 if (f.frequire) | |
3163 error("redundant 'in' statement"); | |
3164 f.frequire = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope); | |
3165 goto L1; | |
3166 | |
3167 case TOK.TOKout: | |
3168 // parse: out (identifier) { statement } | |
3169 nextToken(); | |
3170 if (token.value != TOK.TOKlcurly) | |
3171 { | |
3172 check(TOK.TOKlparen); | |
3173 if (token.value != TOK.TOKidentifier) | |
3174 error("(identifier) following 'out' expected, not %s", token.toChars()); | |
3175 f.outId = token.ident; | |
3176 nextToken(); | |
3177 check(TOK.TOKrparen); | |
3178 } | |
3179 if (f.fensure) | |
3180 error("redundant 'out' statement"); | |
3181 f.fensure = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope); | |
3182 goto L1; | |
3183 | |
3184 default: | |
3185 error("semicolon expected following function declaration"); | |
3186 break; | |
3187 } | |
3188 linkage = linksave; | |
3189 } | |
3190 | |
3191 Statement parseStatement(ParseStatementFlags flags) | |
3192 { | |
3193 Statement s; | |
3194 Token* t; | |
3195 Condition condition; | |
3196 Statement ifbody; | |
3197 Statement elsebody; | |
3198 bool isfinal; | |
3199 Loc loc = this.loc; | |
3200 | |
3201 //printf("parseStatement()\n"); | |
3202 | |
3203 if (flags & ParseStatementFlags.PScurly && token.value != TOK.TOKlcurly) | |
3204 error("statement expected to be { }, not %s", token.toChars()); | |
3205 | |
3206 switch (token.value) | |
3207 { | |
3208 case TOK.TOKidentifier: | |
3209 /* A leading identifier can be a declaration, label, or expression. | |
3210 * The easiest case to check first is label: | |
3211 */ | |
3212 t = peek(&token); | |
3213 if (t.value == TOK.TOKcolon) | |
3214 { // It's a label | |
3215 | |
3216 Identifier ident = token.ident; | |
3217 nextToken(); | |
3218 nextToken(); | |
3219 s = parseStatement(ParseStatementFlags.PSsemi); | |
3220 s = new LabelStatement(loc, ident, s); | |
3221 break; | |
3222 } | |
3223 // fallthrough to TOK.TOKdot | |
3224 case TOK.TOKdot: | |
3225 case TOK.TOKtypeof: | |
3226 if (isDeclaration(&token, 2, TOK.TOKreserved, null)) | |
3227 goto Ldeclaration; | |
3228 else | |
3229 goto Lexp; | |
3230 break; | |
3231 | |
3232 case TOK.TOKassert: | |
3233 case TOK.TOKthis: | |
3234 case TOK.TOKsuper: | |
3235 case TOK.TOKint32v: | |
3236 case TOK.TOKuns32v: | |
3237 case TOK.TOKint64v: | |
3238 case TOK.TOKuns64v: | |
3239 case TOK.TOKfloat32v: | |
3240 case TOK.TOKfloat64v: | |
3241 case TOK.TOKfloat80v: | |
3242 case TOK.TOKimaginary32v: | |
3243 case TOK.TOKimaginary64v: | |
3244 case TOK.TOKimaginary80v: | |
3245 case TOK.TOKcharv: | |
3246 case TOK.TOKwcharv: | |
3247 case TOK.TOKdcharv: | |
3248 case TOK.TOKnull: | |
3249 case TOK.TOKtrue: | |
3250 case TOK.TOKfalse: | |
3251 case TOK.TOKstring: | |
3252 case TOK.TOKlparen: | |
3253 case TOK.TOKcast: | |
3254 case TOK.TOKmul: | |
3255 case TOK.TOKmin: | |
3256 case TOK.TOKadd: | |
3257 case TOK.TOKplusplus: | |
3258 case TOK.TOKminusminus: | |
3259 case TOK.TOKnew: | |
3260 case TOK.TOKdelete: | |
3261 case TOK.TOKdelegate: | |
3262 case TOK.TOKfunction: | |
3263 case TOK.TOKtypeid: | |
3264 case TOK.TOKis: | |
3265 case TOK.TOKlbracket: | |
3266 version (DMDV2) { | |
3267 case TOK.TOKtraits: | |
3268 case TOK.TOKfile: | |
3269 case TOK.TOKline: | |
3270 } | |
3271 Lexp: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3272 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3273 auto exp = parseExpression(); |
0 | 3274 check(TOK.TOKsemicolon, "statement"); |
3275 s = new ExpStatement(loc, exp); | |
3276 break; | |
3277 } | |
3278 | |
3279 case TOK.TOKstatic: | |
3280 { // Look ahead to see if it's static assert() or static if() | |
3281 Token *tt; | |
3282 | |
3283 tt = peek(&token); | |
3284 if (tt.value == TOK.TOKassert) | |
3285 { | |
3286 nextToken(); | |
3287 s = new StaticAssertStatement(parseStaticAssert()); | |
3288 break; | |
3289 } | |
3290 if (tt.value == TOK.TOKif) | |
3291 { | |
3292 nextToken(); | |
3293 condition = parseStaticIfCondition(); | |
3294 goto Lcondition; | |
3295 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3296 if (t.value == TOK.TOKstruct || t.value == TOK.TOKunion || t.value == TOK.TOKclass) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3297 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3298 nextToken(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3299 auto a = parseBlock(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3300 Dsymbol d = new StorageClassDeclaration(STCstatic, a); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3301 s = new DeclarationStatement(loc, d); |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
3302 if (flags & ParseStatementFlags.PSscope) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3303 s = new ScopeStatement(loc, s); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3304 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3305 } |
0 | 3306 goto Ldeclaration; |
3307 } | |
3308 | |
3309 case TOK.TOKfinal: | |
3310 if (peekNext() == TOK.TOKswitch) | |
3311 { | |
3312 nextToken(); | |
3313 isfinal = true; | |
3314 goto Lswitch; | |
3315 } | |
3316 goto Ldeclaration; | |
3317 | |
3318 case TOK.TOKwchar: case TOK.TOKdchar: | |
3319 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar: | |
3320 case TOK.TOKint8: case TOK.TOKuns8: | |
3321 case TOK.TOKint16: case TOK.TOKuns16: | |
3322 case TOK.TOKint32: case TOK.TOKuns32: | |
3323 case TOK.TOKint64: case TOK.TOKuns64: | |
3324 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80: | |
3325 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80: | |
3326 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80: | |
3327 case TOK.TOKvoid: | |
3328 case TOK.TOKtypedef: | |
3329 case TOK.TOKalias: | |
3330 case TOK.TOKconst: | |
3331 case TOK.TOKauto: | |
3332 case TOK.TOKextern: | |
3333 case TOK.TOKinvariant: | |
3334 version (DMDV2) { | |
3335 case TOK.TOKimmutable: | |
3336 case TOK.TOKshared: | |
3337 case TOK.TOKnothrow: | |
3338 case TOK.TOKpure: | |
3339 case TOK.TOKtls: | |
3340 case TOK.TOKgshared: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3341 case TOK.TOKat: |
0 | 3342 } |
3343 // case TOK.TOKtypeof: | |
3344 Ldeclaration: | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
3345 { Dsymbols a; |
0 | 3346 |
3347 a = parseDeclarations(STC.STCundefined); | |
3348 if (a.dim > 1) | |
3349 { | |
3350 Statements as = new Statements(); | |
3351 as.reserve(a.dim); | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3352 foreach(Dsymbol d; a) |
0 | 3353 { |
3354 s = new DeclarationStatement(loc, d); | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
3355 as.push(s); |
0 | 3356 } |
3357 s = new CompoundDeclarationStatement(loc, as); | |
3358 } | |
3359 else if (a.dim == 1) | |
3360 { | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
3361 auto d = a[0]; |
0 | 3362 s = new DeclarationStatement(loc, d); |
3363 } | |
3364 else | |
3365 assert(0); | |
3366 if (flags & ParseStatementFlags.PSscope) | |
3367 s = new ScopeStatement(loc, s); | |
3368 break; | |
3369 } | |
3370 | |
3371 case TOK.TOKstruct: | |
3372 case TOK.TOKunion: | |
3373 case TOK.TOKclass: | |
3374 case TOK.TOKinterface: | |
3375 { Dsymbol d; | |
3376 | |
3377 d = parseAggregate(); | |
3378 s = new DeclarationStatement(loc, d); | |
3379 break; | |
3380 } | |
3381 | |
3382 case TOK.TOKenum: | |
3383 { /* Determine if this is a manifest constant declaration, | |
3384 * or a conventional enum. | |
3385 */ | |
3386 Dsymbol d; | |
3387 Token* tt = peek(&token); | |
3388 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon) | |
3389 d = parseEnum(); | |
3390 else if (tt.value != TOK.TOKidentifier) | |
3391 goto Ldeclaration; | |
3392 else | |
3393 { | |
3394 tt = peek(tt); | |
3395 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon || | |
3396 tt.value == TOK.TOKsemicolon) | |
3397 d = parseEnum(); | |
3398 else | |
3399 goto Ldeclaration; | |
3400 } | |
3401 s = new DeclarationStatement(loc, d); | |
3402 break; | |
3403 } | |
3404 | |
3405 case TOK.TOKmixin: | |
3406 { t = peek(&token); | |
3407 if (t.value == TOK.TOKlparen) | |
3408 { // mixin(string) | |
3409 nextToken(); | |
3410 check(TOK.TOKlparen, "mixin"); | |
3411 Expression e = parseAssignExp(); | |
3412 check(TOK.TOKrparen); | |
3413 check(TOK.TOKsemicolon); | |
3414 s = new CompileStatement(loc, e); | |
3415 break; | |
3416 } | |
3417 Dsymbol d = parseMixin(); | |
3418 s = new DeclarationStatement(loc, d); | |
3419 break; | |
3420 } | |
3421 | |
3422 case TOK.TOKlcurly: | |
79 | 3423 { |
3424 nextToken(); | |
3425 Statements statements = new Statements(); | |
3426 while (token.value != TOK.TOKrcurly && token.value != TOKeof) | |
0 | 3427 { |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
3428 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); |
0 | 3429 } |
3430 endloc = this.loc; | |
3431 s = new CompoundStatement(loc, statements); | |
3432 if (flags & (ParseStatementFlags.PSscope | ParseStatementFlags.PScurlyscope)) | |
3433 s = new ScopeStatement(loc, s); | |
3434 nextToken(); | |
3435 break; | |
3436 } | |
3437 | |
3438 case TOK.TOKwhile: | |
3439 { Expression condition2; | |
3440 Statement body_; | |
3441 | |
3442 nextToken(); | |
3443 check(TOK.TOKlparen); | |
3444 condition2 = parseExpression(); | |
3445 check(TOK.TOKrparen); | |
3446 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3447 s = new WhileStatement(loc, condition2, body_); | |
3448 break; | |
3449 } | |
3450 | |
3451 case TOK.TOKsemicolon: | |
3452 if (!(flags & ParseStatementFlags.PSsemi)) | |
3453 error("use '{ }' for an empty statement, not a ';'"); | |
3454 nextToken(); | |
3455 s = new ExpStatement(loc, null); | |
3456 break; | |
3457 | |
3458 case TOK.TOKdo: | |
3459 { Statement body_; | |
3460 Expression condition2; | |
3461 | |
3462 nextToken(); | |
3463 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3464 check(TOK.TOKwhile); | |
3465 check(TOK.TOKlparen); | |
3466 condition2 = parseExpression(); | |
3467 check(TOK.TOKrparen); | |
3468 s = new DoStatement(loc, body_, condition2); | |
3469 break; | |
3470 } | |
3471 | |
3472 case TOK.TOKfor: | |
3473 { | |
3474 Statement init; | |
3475 Expression condition2; | |
3476 Expression increment; | |
3477 Statement body_; | |
3478 | |
3479 nextToken(); | |
3480 check(TOK.TOKlparen); | |
3481 if (token.value == TOK.TOKsemicolon) | |
3482 { init = null; | |
3483 nextToken(); | |
3484 } | |
3485 else | |
3486 { init = parseStatement(cast(ParseStatementFlags)0); | |
3487 } | |
3488 if (token.value == TOK.TOKsemicolon) | |
3489 { | |
3490 condition2 = null; | |
3491 nextToken(); | |
3492 } | |
3493 else | |
3494 { | |
3495 condition2 = parseExpression(); | |
3496 check(TOK.TOKsemicolon, "for condition"); | |
3497 } | |
3498 if (token.value == TOK.TOKrparen) | |
3499 { increment = null; | |
3500 nextToken(); | |
3501 } | |
3502 else | |
3503 { increment = parseExpression(); | |
3504 check(TOK.TOKrparen); | |
3505 } | |
3506 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3507 s = new ForStatement(loc, init, condition2, increment, body_); | |
3508 if (init) | |
3509 s = new ScopeStatement(loc, s); | |
3510 break; | |
3511 } | |
3512 | |
3513 case TOK.TOKforeach: | |
3514 case TOK.TOKforeach_reverse: | |
3515 { | |
3516 TOK op = token.value; | |
3517 | |
3518 nextToken(); | |
3519 check(TOK.TOKlparen); | |
3520 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3521 auto arguments = new Parameters(); |
0 | 3522 |
3523 while (1) | |
3524 { | |
3525 Identifier ai = null; | |
3526 Type at; | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
3527 StorageClass storageClass = STC.STCundefined; |
0 | 3528 |
3529 if (token.value == TOK.TOKinout || token.value == TOK.TOKref) | |
3530 { storageClass = STC.STCref; | |
3531 nextToken(); | |
3532 } | |
3533 if (token.value == TOK.TOKidentifier) | |
3534 { | |
3535 Token *tt = peek(&token); | |
3536 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon) | |
3537 { ai = token.ident; | |
3538 at = null; // infer argument type | |
3539 nextToken(); | |
3540 goto Larg; | |
3541 } | |
3542 } | |
3543 at = parseType(&ai); | |
3544 if (!ai) | |
3545 error("no identifier for declarator %s", at.toChars()); | |
3546 Larg: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3547 auto a = new Parameter(storageClass, at, ai, null); |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
3548 arguments.push(a); |
0 | 3549 if (token.value == TOK.TOKcomma) |
3550 { nextToken(); | |
3551 continue; | |
3552 } | |
3553 break; | |
3554 } | |
3555 check(TOK.TOKsemicolon); | |
3556 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3557 Expression aggr = parseExpression(); |
0 | 3558 if (token.value == TOK.TOKslice && arguments.dim == 1) |
3559 { | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
3560 auto a = arguments[0]; |
0 | 3561 delete arguments; |
3562 nextToken(); | |
3563 Expression upr = parseExpression(); | |
3564 check(TOK.TOKrparen); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3565 auto body_ = parseStatement(cast(ParseStatementFlags)0); |
0 | 3566 s = new ForeachRangeStatement(loc, op, a, aggr, upr, body_); |
3567 } | |
3568 else | |
3569 { | |
3570 check(TOK.TOKrparen); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3571 auto body_ = parseStatement(cast(ParseStatementFlags)0); |
0 | 3572 s = new ForeachStatement(loc, op, arguments, aggr, body_); |
3573 } | |
3574 break; | |
3575 } | |
3576 | |
3577 case TOK.TOKif: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3578 { Parameter arg = null; |
0 | 3579 Expression condition2; |
3580 Statement ifbody2; | |
3581 Statement elsebody2; | |
3582 | |
3583 nextToken(); | |
3584 check(TOK.TOKlparen); | |
3585 | |
3586 if (token.value == TOK.TOKauto) | |
3587 { | |
3588 nextToken(); | |
3589 if (token.value == TOK.TOKidentifier) | |
3590 { | |
3591 Token *tt = peek(&token); | |
3592 if (tt.value == TOK.TOKassign) | |
3593 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3594 arg = new Parameter(STC.STCundefined, null, token.ident, null); |
0 | 3595 nextToken(); |
3596 nextToken(); | |
3597 } | |
3598 else | |
3599 { error("= expected following auto identifier"); | |
3600 goto Lerror; | |
3601 } | |
3602 } | |
3603 else | |
3604 { error("identifier expected following auto"); | |
3605 goto Lerror; | |
3606 } | |
3607 } | |
3608 else if (isDeclaration(&token, 2, TOK.TOKassign, null)) | |
3609 { | |
3610 Type at; | |
3611 Identifier ai; | |
3612 | |
3613 at = parseType(&ai); | |
3614 check(TOK.TOKassign); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3615 arg = new Parameter(STC.STCundefined, at, ai, null); |
0 | 3616 } |
3617 | |
3618 // Check for " ident;" | |
3619 else if (token.value == TOK.TOKidentifier) | |
3620 { | |
3621 Token *tt = peek(&token); | |
3622 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon) | |
3623 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
3624 arg = new Parameter(STC.STCundefined, null, token.ident, null); |
0 | 3625 nextToken(); |
3626 nextToken(); | |
3627 if (1 || !global.params.useDeprecated) | |
3628 error("if (v; e) is deprecated, use if (auto v = e)"); | |
3629 } | |
3630 } | |
3631 | |
3632 condition2 = parseExpression(); | |
3633 check(TOK.TOKrparen); | |
3634 ifbody2 = parseStatement(ParseStatementFlags.PSscope); | |
3635 if (token.value == TOK.TOKelse) | |
3636 { | |
3637 nextToken(); | |
3638 elsebody2 = parseStatement(ParseStatementFlags.PSscope); | |
3639 } | |
3640 else | |
3641 elsebody2 = null; | |
3642 s = new IfStatement(loc, arg, condition2, ifbody2, elsebody2); | |
3643 break; | |
3644 } | |
3645 | |
3646 case TOK.TOKscope: | |
3647 if (peek(&token).value != TOK.TOKlparen) | |
3648 goto Ldeclaration; // scope used as storage class | |
3649 nextToken(); | |
3650 check(TOK.TOKlparen); | |
3651 if (token.value != TOK.TOKidentifier) | |
3652 { error("scope identifier expected"); | |
3653 goto Lerror; | |
3654 } | |
3655 else | |
3656 { TOK tt = TOK.TOKon_scope_exit; | |
3657 Identifier id = token.ident; | |
3658 | |
3659 if (id == Id.exit) | |
3660 tt = TOK.TOKon_scope_exit; | |
3661 else if (id == Id.failure) | |
3662 tt = TOK.TOKon_scope_failure; | |
3663 else if (id == Id.success) | |
3664 tt = TOK.TOKon_scope_success; | |
3665 else | |
3666 error("valid scope identifiers are exit, failure, or success, not %s", id.toChars()); | |
3667 nextToken(); | |
3668 check(TOK.TOKrparen); | |
3669 Statement st = parseStatement(ParseStatementFlags.PScurlyscope); | |
3670 s = new OnScopeStatement(loc, tt, st); | |
3671 break; | |
3672 } | |
3673 | |
3674 case TOK.TOKdebug: | |
3675 nextToken(); | |
3676 condition = parseDebugCondition(); | |
3677 goto Lcondition; | |
3678 | |
3679 case TOK.TOKversion: | |
3680 nextToken(); | |
3681 condition = parseVersionCondition(); | |
3682 goto Lcondition; | |
3683 | |
3684 Lcondition: | |
3685 ifbody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/); | |
3686 elsebody = null; | |
3687 if (token.value == TOK.TOKelse) | |
3688 { | |
3689 nextToken(); | |
3690 elsebody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/); | |
3691 } | |
3692 s = new ConditionalStatement(loc, condition, ifbody, elsebody); | |
3693 break; | |
3694 | |
3695 case TOK.TOKpragma: | |
3696 { Identifier ident; | |
3697 Expressions args = null; | |
3698 Statement body_; | |
3699 | |
3700 nextToken(); | |
3701 check(TOK.TOKlparen); | |
3702 if (token.value != TOK.TOKidentifier) | |
3703 { error("pragma(identifier expected"); | |
3704 goto Lerror; | |
3705 } | |
3706 ident = token.ident; | |
3707 nextToken(); | |
3708 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen) | |
3709 args = parseArguments(); // pragma(identifier, args...); | |
3710 else | |
3711 check(TOK.TOKrparen); // pragma(identifier); | |
3712 if (token.value == TOK.TOKsemicolon) | |
3713 { nextToken(); | |
3714 body_ = null; | |
3715 } | |
3716 else | |
3717 body_ = parseStatement(ParseStatementFlags.PSsemi); | |
3718 s = new PragmaStatement(loc, ident, args, body_); | |
3719 break; | |
3720 } | |
3721 | |
3722 case TOK.TOKswitch: | |
3723 isfinal = false; | |
3724 goto Lswitch; | |
3725 | |
3726 Lswitch: | |
3727 { | |
3728 nextToken(); | |
3729 check(TOK.TOKlparen); | |
3730 Expression condition2 = parseExpression(); | |
3731 check(TOK.TOKrparen); | |
3732 Statement body_ = parseStatement(ParseStatementFlags.PSscope); | |
3733 s = new SwitchStatement(loc, condition2, body_, isfinal); | |
3734 break; | |
3735 } | |
3736 | |
3737 case TOK.TOKcase: | |
3738 { Expression exp; | |
3739 Statements statements; | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
3740 scope cases = new Expressions(); // array of Expression's |
0 | 3741 Expression last = null; |
3742 | |
3743 while (1) | |
3744 { | |
3745 nextToken(); | |
3746 exp = parseAssignExp(); | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
3747 cases.push(exp); |
0 | 3748 if (token.value != TOK.TOKcomma) |
3749 break; | |
3750 } | |
3751 check(TOK.TOKcolon); | |
3752 | |
3753 version (DMDV2) { | |
3754 /* case exp: .. case last: | |
3755 */ | |
3756 if (token.value == TOK.TOKslice) | |
3757 { | |
3758 if (cases.dim > 1) | |
3759 error("only one case allowed for start of case range"); | |
3760 nextToken(); | |
3761 check(TOK.TOKcase); | |
3762 last = parseAssignExp(); | |
3763 check(TOK.TOKcolon); | |
3764 } | |
3765 } | |
3766 | |
3767 statements = new Statements(); | |
3768 while (token.value != TOK.TOKcase && | |
3769 token.value != TOK.TOKdefault && | |
79 | 3770 token.value != TOKeof && |
0 | 3771 token.value != TOK.TOKrcurly) |
3772 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
3773 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); |
0 | 3774 } |
3775 s = new CompoundStatement(loc, statements); | |
3776 s = new ScopeStatement(loc, s); | |
3777 | |
3778 ///version (DMDV2) { | |
3779 if (last) | |
3780 { | |
3781 s = new CaseRangeStatement(loc, exp, last, s); | |
3782 } | |
3783 else | |
3784 ///} | |
3785 { | |
3786 // Keep cases in order by building the case statements backwards | |
3787 for (int i = cases.dim; i; i--) | |
3788 { | |
128
e6e542f37b94
Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
3789 exp = cases[i - 1]; |
0 | 3790 s = new CaseStatement(loc, exp, s); |
3791 } | |
3792 } | |
3793 break; | |
3794 } | |
3795 | |
3796 case TOK.TOKdefault: | |
3797 { | |
3798 Statements statements; | |
3799 | |
3800 nextToken(); | |
3801 check(TOK.TOKcolon); | |
3802 | |
3803 statements = new Statements(); | |
3804 while (token.value != TOK.TOKcase && | |
3805 token.value != TOK.TOKdefault && | |
79 | 3806 token.value != TOKeof && |
0 | 3807 token.value != TOK.TOKrcurly) |
3808 { | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
3809 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope)); |
0 | 3810 } |
3811 s = new CompoundStatement(loc, statements); | |
3812 s = new ScopeStatement(loc, s); | |
3813 s = new DefaultStatement(loc, s); | |
3814 break; | |
3815 } | |
3816 | |
3817 case TOK.TOKreturn: | |
3818 { Expression exp; | |
3819 | |
3820 nextToken(); | |
3821 if (token.value == TOK.TOKsemicolon) | |
3822 exp = null; | |
3823 else | |
3824 exp = parseExpression(); | |
3825 check(TOK.TOKsemicolon, "return statement"); | |
3826 s = new ReturnStatement(loc, exp); | |
3827 break; | |
3828 } | |
3829 | |
3830 case TOK.TOKbreak: | |
3831 { Identifier ident; | |
3832 | |
3833 nextToken(); | |
3834 if (token.value == TOK.TOKidentifier) | |
3835 { ident = token.ident; | |
3836 nextToken(); | |
3837 } | |
3838 else | |
3839 ident = null; | |
3840 check(TOK.TOKsemicolon, "break statement"); | |
3841 s = new BreakStatement(loc, ident); | |
3842 break; | |
3843 } | |
3844 | |
3845 case TOK.TOKcontinue: | |
3846 { Identifier ident; | |
3847 | |
3848 nextToken(); | |
3849 if (token.value == TOK.TOKidentifier) | |
3850 { ident = token.ident; | |
3851 nextToken(); | |
3852 } | |
3853 else | |
3854 ident = null; | |
3855 check(TOK.TOKsemicolon, "continue statement"); | |
3856 s = new ContinueStatement(loc, ident); | |
3857 break; | |
3858 } | |
3859 | |
3860 case TOK.TOKgoto: | |
3861 { Identifier ident; | |
3862 | |
3863 nextToken(); | |
3864 if (token.value == TOK.TOKdefault) | |
3865 { | |
3866 nextToken(); | |
3867 s = new GotoDefaultStatement(loc); | |
3868 } | |
3869 else if (token.value == TOK.TOKcase) | |
3870 { | |
3871 Expression exp = null; | |
3872 | |
3873 nextToken(); | |
3874 if (token.value != TOK.TOKsemicolon) | |
3875 exp = parseExpression(); | |
3876 s = new GotoCaseStatement(loc, exp); | |
3877 } | |
3878 else | |
3879 { | |
3880 if (token.value != TOK.TOKidentifier) | |
3881 { error("Identifier expected following goto"); | |
3882 ident = null; | |
3883 } | |
3884 else | |
3885 { ident = token.ident; | |
3886 nextToken(); | |
3887 } | |
3888 s = new GotoStatement(loc, ident); | |
3889 } | |
3890 check(TOK.TOKsemicolon, "goto statement"); | |
3891 break; | |
3892 } | |
3893 | |
3894 case TOK.TOKsynchronized: | |
3895 { Expression exp; | |
3896 Statement body_; | |
3897 | |
3898 nextToken(); | |
3899 if (token.value == TOK.TOKlparen) | |
3900 { | |
3901 nextToken(); | |
3902 exp = parseExpression(); | |
3903 check(TOK.TOKrparen); | |
3904 } | |
3905 else | |
3906 exp = null; | |
3907 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3908 s = new SynchronizedStatement(loc, exp, body_); | |
3909 break; | |
3910 } | |
3911 | |
3912 case TOK.TOKwith: | |
3913 { Expression exp; | |
3914 Statement body_; | |
3915 | |
3916 nextToken(); | |
3917 check(TOK.TOKlparen); | |
3918 exp = parseExpression(); | |
3919 check(TOK.TOKrparen); | |
3920 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3921 s = new WithStatement(loc, exp, body_); | |
3922 break; | |
3923 } | |
3924 | |
3925 case TOK.TOKtry: | |
3926 { Statement body_; | |
3927 Array catches = null; | |
3928 Statement finalbody = null; | |
3929 | |
3930 nextToken(); | |
3931 body_ = parseStatement(ParseStatementFlags.PSscope); | |
3932 while (token.value == TOK.TOKcatch) | |
3933 { | |
3934 Statement handler; | |
3935 Catch c; | |
3936 Type tt; | |
3937 Identifier id; | |
3938 Loc loc2 = this.loc; | |
3939 | |
3940 nextToken(); | |
3941 if (token.value == TOK.TOKlcurly) | |
3942 { | |
3943 tt = null; | |
3944 id = null; | |
3945 } | |
3946 else | |
3947 { | |
3948 check(TOK.TOKlparen); | |
3949 id = null; | |
3950 tt = parseType(&id); | |
3951 check(TOK.TOKrparen); | |
3952 } | |
3953 handler = parseStatement(cast(ParseStatementFlags)0); | |
3954 c = new Catch(loc2, tt, id, handler); | |
3955 if (!catches) | |
3956 catches = new Array(); | |
3957 catches.push(cast(void*)c); | |
3958 } | |
3959 | |
3960 if (token.value == TOK.TOKfinally) | |
3961 { nextToken(); | |
3962 finalbody = parseStatement(cast(ParseStatementFlags)0); | |
3963 } | |
3964 | |
3965 s = body_; | |
3966 if (!catches && !finalbody) | |
3967 error("catch or finally expected following try"); | |
3968 else | |
3969 { if (catches) | |
3970 s = new TryCatchStatement(loc, body_, catches); | |
3971 if (finalbody) | |
3972 s = new TryFinallyStatement(loc, s, finalbody); | |
3973 } | |
3974 break; | |
3975 } | |
3976 | |
3977 case TOK.TOKthrow: | |
3978 { Expression exp; | |
3979 | |
3980 nextToken(); | |
3981 exp = parseExpression(); | |
3982 check(TOK.TOKsemicolon, "throw statement"); | |
3983 s = new ThrowStatement(loc, exp); | |
3984 break; | |
3985 } | |
3986 | |
3987 case TOK.TOKvolatile: | |
3988 nextToken(); | |
3989 s = parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope); | |
3990 version (DMDV2) { | |
3991 if (!global.params.useDeprecated) | |
3992 error("volatile statements deprecated; used synchronized statements instead"); | |
3993 } | |
3994 s = new VolatileStatement(loc, s); | |
3995 break; | |
3996 | |
3997 case TOK.TOKasm: | |
3998 { Statements statements; | |
3999 Identifier label; | |
4000 Loc labelloc; | |
4001 Token* toklist; | |
4002 Token** ptoklist; | |
4003 | |
4004 // Parse the asm block into a sequence of AsmStatements, | |
4005 // each AsmStatement is one instruction. | |
4006 // Separate out labels. | |
4007 // Defer parsing of AsmStatements until semantic processing. | |
4008 | |
4009 nextToken(); | |
4010 check(TOK.TOKlcurly); | |
4011 toklist = null; | |
4012 ptoklist = &toklist; | |
4013 label = null; | |
4014 statements = new Statements(); | |
4015 while (1) | |
4016 { | |
4017 switch (token.value) | |
4018 { | |
4019 case TOK.TOKidentifier: | |
4020 if (!toklist) | |
4021 { | |
4022 // Look ahead to see if it is a label | |
4023 t = peek(&token); | |
4024 if (t.value == TOK.TOKcolon) | |
4025 { // It's a label | |
4026 label = token.ident; | |
4027 labelloc = this.loc; | |
4028 nextToken(); | |
4029 nextToken(); | |
4030 continue; | |
4031 } | |
4032 } | |
4033 goto Ldefault; | |
4034 | |
4035 case TOK.TOKrcurly: | |
4036 if (toklist || label) | |
4037 { | |
4038 error("asm statements must end in ';'"); | |
4039 } | |
4040 break; | |
4041 | |
4042 case TOK.TOKsemicolon: | |
4043 s = null; | |
4044 if (toklist || label) | |
4045 { // Create AsmStatement from list of tokens we've saved | |
4046 s = new AsmStatement(this.loc, toklist); | |
4047 toklist = null; | |
4048 ptoklist = &toklist; | |
4049 if (label) | |
4050 { | |
4051 s = new LabelStatement(labelloc, label, s); | |
4052 label = null; | |
4053 } | |
122
c77e9f4f1793
Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
4054 statements.push(s); |
0 | 4055 } |
4056 nextToken(); | |
4057 continue; | |
4058 | |
4059 case TOK.TOKeof: | |
4060 /* { */ | |
4061 error("matching '}' expected, not end of file"); | |
4062 break; | |
4063 | |
4064 default: | |
4065 Ldefault: | |
4066 *ptoklist = new Token(); | |
4067 memcpy(*ptoklist, &token, Token.sizeof); | |
4068 ptoklist = &(*ptoklist).next; | |
4069 *ptoklist = null; | |
4070 | |
4071 nextToken(); | |
4072 continue; | |
4073 } | |
4074 break; | |
4075 } | |
4076 s = new CompoundStatement(loc, statements); | |
4077 nextToken(); | |
4078 break; | |
4079 } | |
4080 | |
4081 default: | |
4082 error("found '%s' instead of statement", token.toChars()); | |
4083 goto Lerror; | |
4084 | |
4085 Lerror: | |
4086 while (token.value != TOK.TOKrcurly && | |
4087 token.value != TOK.TOKsemicolon && | |
4088 token.value != TOK.TOKeof) | |
4089 nextToken(); | |
4090 if (token.value == TOK.TOKsemicolon) | |
4091 nextToken(); | |
4092 s = null; | |
4093 break; | |
4094 } | |
4095 | |
4096 return s; | |
4097 } | |
4098 | |
4099 /***************************************** | |
4100 * Parse initializer for variable declaration. | |
4101 */ | |
4102 Initializer parseInitializer() | |
4103 { | |
4104 StructInitializer is_; | |
4105 ArrayInitializer ia; | |
4106 ExpInitializer ie; | |
4107 Expression e; | |
4108 Identifier id; | |
4109 Initializer value; | |
4110 int comma; | |
4111 Loc loc = this.loc; | |
4112 Token* t; | |
4113 int braces; | |
4114 int brackets; | |
4115 | |
4116 switch (token.value) | |
4117 { | |
4118 case TOK.TOKlcurly: | |
4119 /* Scan ahead to see if it is a struct initializer or | |
4120 * a function literal. | |
4121 * If it contains a ';', it is a function literal. | |
4122 * Treat { } as a struct initializer. | |
4123 */ | |
4124 braces = 1; | |
4125 for (t = peek(&token); 1; t = peek(t)) | |
4126 { | |
4127 switch (t.value) | |
4128 { | |
4129 case TOK.TOKsemicolon: | |
4130 case TOK.TOKreturn: | |
4131 goto Lexpression; | |
4132 | |
4133 case TOK.TOKlcurly: | |
4134 braces++; | |
4135 continue; | |
4136 | |
4137 case TOK.TOKrcurly: | |
4138 if (--braces == 0) | |
4139 break; | |
4140 continue; | |
4141 | |
4142 case TOK.TOKeof: | |
4143 break; | |
4144 | |
4145 default: | |
4146 continue; | |
4147 } | |
4148 break; | |
4149 } | |
4150 | |
4151 is_ = new StructInitializer(loc); | |
4152 nextToken(); | |
4153 comma = 0; | |
4154 while (1) | |
4155 { | |
4156 switch (token.value) | |
4157 { | |
4158 case TOK.TOKidentifier: | |
4159 if (comma == 1) | |
4160 error("comma expected separating field initializers"); | |
4161 t = peek(&token); | |
4162 if (t.value == TOK.TOKcolon) | |
4163 { | |
4164 id = token.ident; | |
4165 nextToken(); | |
4166 nextToken(); // skip over ':' | |
4167 } | |
4168 else | |
4169 { | |
4170 id = null; | |
4171 } | |
4172 value = parseInitializer(); | |
4173 is_.addInit(id, value); | |
4174 comma = 1; | |
4175 continue; | |
4176 | |
4177 case TOK.TOKcomma: | |
4178 nextToken(); | |
4179 comma = 2; | |
4180 continue; | |
4181 | |
4182 case TOK.TOKrcurly: // allow trailing comma's | |
4183 nextToken(); | |
4184 break; | |
4185 | |
4186 case TOK.TOKeof: | |
4187 error("found EOF instead of initializer"); | |
4188 break; | |
4189 | |
4190 default: | |
4191 value = parseInitializer(); | |
4192 is_.addInit(null, value); | |
4193 comma = 1; | |
4194 continue; | |
4195 //error("found '%s' instead of field initializer", token.toChars()); | |
4196 //break; | |
4197 } | |
4198 break; | |
4199 } | |
4200 return is_; | |
4201 | |
4202 case TOK.TOKlbracket: | |
4203 /* Scan ahead to see if it is an array initializer or | |
4204 * an expression. | |
4205 * If it ends with a ';' ',' or '}', it is an array initializer. | |
4206 */ | |
4207 brackets = 1; | |
4208 for (t = peek(&token); 1; t = peek(t)) | |
4209 { | |
4210 switch (t.value) | |
4211 { | |
4212 case TOK.TOKlbracket: | |
4213 brackets++; | |
4214 continue; | |
4215 | |
4216 case TOK.TOKrbracket: | |
4217 if (--brackets == 0) | |
4218 { | |
4219 t = peek(t); | |
4220 if (t.value != TOK.TOKsemicolon && | |
4221 t.value != TOK.TOKcomma && | |
4222 t.value != TOK.TOKrcurly) | |
4223 goto Lexpression; | |
4224 break; | |
4225 } | |
4226 continue; | |
4227 | |
4228 case TOK.TOKeof: | |
4229 break; | |
4230 | |
4231 default: | |
4232 continue; | |
4233 } | |
4234 break; | |
4235 } | |
4236 | |
4237 ia = new ArrayInitializer(loc); | |
4238 nextToken(); | |
4239 comma = 0; | |
4240 while (true) | |
4241 { | |
4242 switch (token.value) | |
4243 { | |
4244 default: | |
4245 if (comma == 1) | |
4246 { | |
4247 error("comma expected separating array initializers, not %s", token.toChars()); | |
4248 nextToken(); | |
4249 break; | |
4250 } | |
4251 e = parseAssignExp(); | |
4252 if (!e) | |
4253 break; | |
4254 if (token.value == TOK.TOKcolon) | |
4255 { | |
4256 nextToken(); | |
4257 value = parseInitializer(); | |
4258 } | |
4259 else | |
4260 { value = new ExpInitializer(e.loc, e); | |
4261 e = null; | |
4262 } | |
4263 ia.addInit(e, value); | |
4264 comma = 1; | |
4265 continue; | |
4266 | |
4267 case TOK.TOKlcurly: | |
4268 case TOK.TOKlbracket: | |
4269 if (comma == 1) | |
4270 error("comma expected separating array initializers, not %s", token.toChars()); | |
4271 value = parseInitializer(); | |
4272 ia.addInit(null, value); | |
4273 comma = 1; | |
4274 continue; | |
4275 | |
4276 case TOK.TOKcomma: | |
4277 nextToken(); | |
4278 comma = 2; | |
4279 continue; | |
4280 | |
4281 case TOK.TOKrbracket: // allow trailing comma's | |
4282 nextToken(); | |
4283 break; | |
4284 | |
4285 case TOK.TOKeof: | |
4286 error("found '%s' instead of array initializer", token.toChars()); | |
4287 break; | |
4288 } | |
4289 break; | |
4290 } | |
4291 return ia; | |
4292 | |
4293 case TOK.TOKvoid: | |
4294 t = peek(&token); | |
4295 if (t.value == TOK.TOKsemicolon || t.value == TOK.TOKcomma) | |
4296 { | |
4297 nextToken(); | |
4298 return new VoidInitializer(loc); | |
4299 } | |
4300 goto Lexpression; | |
4301 | |
4302 default: | |
4303 Lexpression: | |
4304 e = parseAssignExp(); | |
4305 ie = new ExpInitializer(loc, e); | |
4306 return ie; | |
4307 } | |
4308 } | |
4309 | |
4310 /***************************************** | |
4311 * Parses default argument initializer expression that is an assign expression, | |
4312 * with special handling for __FILE__ and __LINE__. | |
4313 */ | |
4314 version (DMDV2) { | |
4315 Expression parseDefaultInitExp() | |
4316 { | |
4317 if (token.value == TOK.TOKfile || | |
4318 token.value == TOK.TOKline) | |
4319 { | |
4320 Token* t = peek(&token); | |
4321 if (t.value == TOK.TOKcomma || t.value == TOK.TOKrparen) | |
4322 { | |
4323 Expression e; | |
4324 | |
4325 if (token.value == TOK.TOKfile) | |
4326 e = new FileInitExp(loc); | |
4327 else | |
4328 e = new LineInitExp(loc); | |
4329 nextToken(); | |
4330 return e; | |
4331 } | |
4332 } | |
4333 | |
4334 Expression e = parseAssignExp(); | |
4335 return e; | |
4336 } | |
4337 } | |
4338 void check(Loc loc, TOK value) | |
4339 { | |
4340 if (token.value != value) | |
4341 error(loc, "found '%s' when expecting '%s'", token.toChars(), Token.toChars(value)); | |
4342 nextToken(); | |
4343 } | |
4344 | |
4345 void check(TOK value) | |
4346 { | |
4347 check(loc, value); | |
4348 } | |
4349 | |
4350 void check(TOK value, string string_) | |
4351 { | |
4352 if (token.value != value) { | |
4353 error("found '%s' when expecting '%s' following '%s'", token.toChars(), Token.toChars(value), string_); | |
4354 } | |
4355 nextToken(); | |
4356 } | |
4357 | |
4358 /************************************ | |
4359 * Determine if the scanner is sitting on the start of a declaration. | |
4360 * Input: | |
4361 * needId 0 no identifier | |
4362 * 1 identifier optional | |
4363 * 2 must have identifier | |
4364 * Output: | |
4365 * if *pt is not null, it is set to the ending token, which would be endtok | |
4366 */ | |
4367 | |
4368 bool isDeclaration(Token* t, int needId, TOK endtok, Token** pt) | |
4369 { | |
4370 //printf("isDeclaration(needId = %d)\n", needId); | |
4371 int haveId = 0; | |
4372 | |
4373 version (DMDV2) { | |
4374 if ((t.value == TOK.TOKconst || | |
4375 t.value == TOK.TOKinvariant || | |
4376 t.value == TOK.TOKimmutable || | |
4377 t.value == TOK.TOKshared) && | |
4378 peek(t).value != TOK.TOKlparen) | |
4379 { | |
4380 /* const type | |
4381 * immutable type | |
4382 * shared type | |
4383 */ | |
4384 t = peek(t); | |
4385 } | |
4386 } | |
4387 | |
4388 if (!isBasicType(&t)) | |
4389 { | |
4390 goto Lisnot; | |
4391 } | |
4392 if (!isDeclarator(&t, &haveId, endtok)) | |
4393 goto Lisnot; | |
4394 if ( needId == 1 || | |
4395 (needId == 0 && !haveId) || | |
4396 (needId == 2 && haveId)) | |
4397 { | |
4398 if (pt) | |
4399 *pt = t; | |
4400 goto Lis; | |
4401 } | |
4402 else | |
4403 goto Lisnot; | |
4404 | |
4405 Lis: | |
4406 //printf("\tis declaration, t = %s\n", t.toChars()); | |
4407 return true; | |
4408 | |
4409 Lisnot: | |
4410 //printf("\tis not declaration\n"); | |
4411 return false; | |
4412 } | |
4413 | |
4414 bool isBasicType(Token** pt) | |
4415 { | |
4416 // This code parallels parseBasicType() | |
4417 Token* t = *pt; | |
4418 Token* t2; | |
4419 int parens; | |
4420 int haveId = 0; | |
4421 | |
4422 switch (t.value) | |
4423 { | |
4424 case TOKwchar: | |
4425 case TOKdchar: | |
4426 case TOKbit: | |
4427 case TOKbool: | |
4428 case TOKchar: | |
4429 case TOKint8: | |
4430 case TOKuns8: | |
4431 case TOKint16: | |
4432 case TOKuns16: | |
4433 case TOKint32: | |
4434 case TOKuns32: | |
4435 case TOKint64: | |
4436 case TOKuns64: | |
4437 case TOKfloat32: | |
4438 case TOKfloat64: | |
4439 case TOKfloat80: | |
4440 case TOKimaginary32: | |
4441 case TOKimaginary64: | |
4442 case TOKimaginary80: | |
4443 case TOKcomplex32: | |
4444 case TOKcomplex64: | |
4445 case TOKcomplex80: | |
4446 case TOKvoid: | |
4447 t = peek(t); | |
4448 break; | |
4449 | |
4450 case TOK.TOKidentifier: | |
4451 L5: | |
4452 t = peek(t); | |
4453 if (t.value == TOK.TOKnot) | |
4454 { | |
4455 goto L4; | |
4456 } | |
4457 goto L3; | |
4458 while (1) | |
4459 { | |
4460 L2: | |
4461 t = peek(t); | |
4462 L3: | |
4463 if (t.value == TOK.TOKdot) | |
4464 { | |
4465 Ldot: | |
4466 t = peek(t); | |
4467 if (t.value != TOK.TOKidentifier) | |
4468 goto Lfalse; | |
4469 t = peek(t); | |
4470 if (t.value != TOK.TOKnot) | |
4471 goto L3; | |
4472 L4: | |
4473 /* Seen a ! | |
4474 * Look for: | |
4475 * !( args ), !identifier, etc. | |
4476 */ | |
4477 t = peek(t); | |
4478 switch (t.value) | |
4479 { case TOK.TOKidentifier: | |
4480 goto L5; | |
4481 case TOK.TOKlparen: | |
4482 if (!skipParens(t, &t)) | |
4483 goto Lfalse; | |
4484 break; | |
4485 case TOK.TOKwchar: case TOK.TOKdchar: | |
4486 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar: | |
4487 case TOK.TOKint8: case TOK.TOKuns8: | |
4488 case TOK.TOKint16: case TOK.TOKuns16: | |
4489 case TOK.TOKint32: case TOK.TOKuns32: | |
4490 case TOK.TOKint64: case TOK.TOKuns64: | |
4491 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80: | |
4492 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80: | |
4493 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80: | |
4494 case TOK.TOKvoid: | |
4495 case TOK.TOKint32v: | |
4496 case TOK.TOKuns32v: | |
4497 case TOK.TOKint64v: | |
4498 case TOK.TOKuns64v: | |
4499 case TOK.TOKfloat32v: | |
4500 case TOK.TOKfloat64v: | |
4501 case TOK.TOKfloat80v: | |
4502 case TOK.TOKimaginary32v: | |
4503 case TOK.TOKimaginary64v: | |
4504 case TOK.TOKimaginary80v: | |
4505 case TOK.TOKnull: | |
4506 case TOK.TOKtrue: | |
4507 case TOK.TOKfalse: | |
4508 case TOK.TOKcharv: | |
4509 case TOK.TOKwcharv: | |
4510 case TOK.TOKdcharv: | |
4511 case TOK.TOKstring: | |
4512 case TOK.TOKfile: | |
4513 case TOK.TOKline: | |
4514 goto L2; | |
4515 default: | |
4516 goto Lfalse; | |
4517 } | |
4518 } | |
4519 else | |
4520 break; | |
4521 } | |
4522 break; | |
4523 | |
4524 case TOK.TOKdot: | |
4525 goto Ldot; | |
4526 | |
4527 case TOK.TOKtypeof: | |
4528 /* typeof(exp).identifier... | |
4529 */ | |
4530 t = peek(t); | |
4531 if (t.value != TOK.TOKlparen) | |
4532 goto Lfalse; | |
4533 if (!skipParens(t, &t)) | |
4534 goto Lfalse; | |
4535 goto L2; | |
4536 | |
4537 case TOK.TOKconst: | |
4538 case TOK.TOKinvariant: | |
4539 case TOK.TOKimmutable: | |
4540 case TOK.TOKshared: | |
4541 // const(type) or immutable(type) or shared(type) | |
4542 t = peek(t); | |
4543 if (t.value != TOK.TOKlparen) | |
4544 goto Lfalse; | |
4545 t = peek(t); | |
4546 if (!isDeclaration(t, 0, TOK.TOKrparen, &t)) | |
4547 { | |
4548 goto Lfalse; | |
4549 } | |
4550 t = peek(t); | |
4551 break; | |
4552 | |
4553 default: | |
4554 goto Lfalse; | |
4555 } | |
4556 *pt = t; | |
4557 //printf("is\n"); | |
4558 return true; | |
4559 | |
4560 Lfalse: | |
4561 //printf("is not\n"); | |
4562 return false; | |
4563 } | |
4564 | |
4565 bool isDeclarator(Token** pt, int* haveId, TOK endtok) | |
4566 { | |
4567 // This code parallels parseDeclarator() | |
4568 Token* t = *pt; | |
4569 bool parens; | |
4570 | |
4571 //printf("Parser.isDeclarator()\n"); | |
4572 //t.print(); | |
4573 if (t.value == TOK.TOKassign) | |
4574 return false; | |
4575 | |
4576 while (true) | |
4577 { | |
4578 parens = false; | |
4579 switch (t.value) | |
4580 { | |
4581 case TOK.TOKmul: | |
4582 //case TOKand: | |
4583 t = peek(t); | |
4584 continue; | |
4585 | |
4586 case TOK.TOKlbracket: | |
4587 t = peek(t); | |
4588 if (t.value == TOK.TOKrbracket) | |
4589 { | |
4590 t = peek(t); | |
4591 } | |
79 | 4592 else if (t.value == TOKnew && peek(t).value == TOKrbracket) |
4593 { | |
4594 t = peek(t); | |
4595 t = peek(t); | |
4596 } | |
0 | 4597 else if (isDeclaration(t, 0, TOK.TOKrbracket, &t)) |
4598 { | |
4599 // It's an associative array declaration | |
4600 t = peek(t); | |
4601 } | |
4602 else | |
4603 { | |
4604 // [ expression ] | |
4605 // [ expression .. expression ] | |
4606 if (!isExpression(&t)) | |
4607 return false; | |
4608 if (t.value == TOK.TOKslice) | |
4609 { | |
4610 t = peek(t); | |
4611 if (!isExpression(&t)) | |
4612 return false; | |
4613 } | |
4614 if (t.value != TOK.TOKrbracket) | |
4615 return false; | |
4616 t = peek(t); | |
4617 } | |
4618 continue; | |
4619 | |
4620 case TOK.TOKidentifier: | |
4621 if (*haveId) | |
4622 return false; | |
4623 *haveId = true; | |
4624 t = peek(t); | |
4625 break; | |
4626 | |
4627 case TOK.TOKlparen: | |
4628 t = peek(t); | |
4629 | |
4630 if (t.value == TOK.TOKrparen) | |
4631 return false; // () is not a declarator | |
4632 | |
4633 /* Regard ( identifier ) as not a declarator | |
4634 * BUG: what about ( *identifier ) in | |
4635 * f(*p)(x); | |
4636 * where f is a class instance with overloaded () ? | |
4637 * Should we just disallow C-style function pointer declarations? | |
4638 */ | |
4639 if (t.value == TOK.TOKidentifier) | |
4640 { | |
4641 Token *t2 = peek(t); | |
4642 if (t2.value == TOK.TOKrparen) | |
4643 return false; | |
4644 } | |
4645 | |
4646 if (!isDeclarator(&t, haveId, TOK.TOKrparen)) | |
4647 return false; | |
4648 t = peek(t); | |
4649 parens = true; | |
4650 break; | |
4651 | |
4652 case TOK.TOKdelegate: | |
4653 case TOK.TOKfunction: | |
4654 t = peek(t); | |
4655 if (!isParameters(&t)) | |
4656 return false; | |
4657 continue; | |
4658 default: | |
4659 break; /// | |
4660 } | |
4661 break; | |
4662 } | |
4663 | |
4664 while (1) | |
4665 { | |
4666 switch (t.value) | |
4667 { | |
4668 version (CARRAYDECL) { | |
4669 case TOK.TOKlbracket: | |
4670 parens = false; | |
4671 t = peek(t); | |
4672 if (t.value == TOK.TOKrbracket) | |
4673 { | |
4674 t = peek(t); | |
4675 } | |
4676 else if (isDeclaration(t, 0, TOKrbracket, &t)) | |
4677 { | |
4678 // It's an associative array declaration | |
4679 t = peek(t); | |
4680 } | |
4681 else | |
4682 { | |
4683 // [ expression ] | |
4684 if (!isExpression(&t)) | |
4685 return false; | |
4686 if (t.value != TOK.TOKrbracket) | |
4687 return false; | |
4688 t = peek(t); | |
4689 } | |
4690 continue; | |
4691 } | |
4692 | |
4693 case TOK.TOKlparen: | |
4694 parens = false; | |
4695 if (!isParameters(&t)) | |
4696 return false; | |
4697 version (DMDV2) { | |
4698 while (true) | |
4699 { | |
4700 switch (t.value) | |
4701 { | |
4702 case TOK.TOKconst: | |
4703 case TOK.TOKinvariant: | |
4704 case TOK.TOKimmutable: | |
4705 case TOK.TOKshared: | |
4706 case TOK.TOKpure: | |
4707 case TOK.TOKnothrow: | |
4708 t = peek(t); | |
4709 continue; | |
4710 case TOK.TOKat: | |
4711 t = peek(t); // skip '@' | |
4712 t = peek(t); // skip identifier | |
4713 continue; | |
4714 default: | |
4715 break; | |
4716 } | |
4717 break; | |
4718 } | |
4719 } | |
4720 continue; | |
4721 | |
4722 // Valid tokens that follow a declaration | |
4723 case TOK.TOKrparen: | |
4724 case TOK.TOKrbracket: | |
4725 case TOK.TOKassign: | |
4726 case TOK.TOKcomma: | |
4727 case TOK.TOKsemicolon: | |
4728 case TOK.TOKlcurly: | |
4729 case TOK.TOKin: | |
4730 // The !parens is to disallow unnecessary parentheses | |
4731 if (!parens && (endtok == TOK.TOKreserved || endtok == t.value)) | |
4732 { | |
4733 *pt = t; | |
4734 return true; | |
4735 } | |
4736 return false; | |
4737 | |
4738 default: | |
4739 return false; | |
4740 } | |
4741 } | |
4742 } | |
4743 | |
4744 bool isParameters(Token** pt) | |
4745 { | |
4746 // This code parallels parseParameters() | |
4747 Token* t = *pt; | |
4748 | |
4749 //printf("isParameters()\n"); | |
4750 if (t.value != TOKlparen) | |
4751 return false; | |
4752 | |
4753 t = peek(t); | |
4754 for (;1; t = peek(t)) | |
4755 { | |
4756 L1: | |
4757 switch (t.value) | |
4758 { | |
4759 case TOKrparen: | |
4760 break; | |
4761 | |
4762 case TOKdotdotdot: | |
4763 t = peek(t); | |
4764 break; | |
4765 | |
4766 case TOKin: | |
4767 case TOKout: | |
4768 case TOKinout: | |
4769 case TOKref: | |
4770 case TOKlazy: | |
4771 case TOKfinal: | |
4772 continue; | |
4773 | |
4774 case TOKconst: | |
4775 case TOKinvariant: | |
4776 case TOKimmutable: | |
4777 case TOKshared: | |
4778 t = peek(t); | |
4779 if (t.value == TOKlparen) | |
4780 { | |
4781 t = peek(t); | |
4782 if (!isDeclaration(t, 0, TOKrparen, &t)) | |
4783 return false; | |
4784 t = peek(t); // skip past closing ')' | |
4785 goto L2; | |
4786 } | |
4787 goto L1; | |
4788 | |
4789 static if (false) { | |
4790 case TOKstatic: | |
4791 continue; | |
4792 case TOKauto: | |
4793 case TOKalias: | |
4794 t = peek(t); | |
4795 if (t.value == TOKidentifier) | |
4796 t = peek(t); | |
4797 if (t.value == TOKassign) | |
4798 { t = peek(t); | |
4799 if (!isExpression(&t)) | |
4800 return false; | |
4801 } | |
4802 goto L3; | |
4803 } | |
4804 | |
4805 default: | |
4806 { | |
4807 if (!isBasicType(&t)) | |
4808 return false; | |
4809 L2: | |
4810 int tmp = false; | |
4811 if (t.value != TOKdotdotdot && | |
4812 !isDeclarator(&t, &tmp, TOKreserved)) | |
4813 return false; | |
4814 if (t.value == TOKassign) | |
4815 { | |
4816 t = peek(t); | |
4817 if (!isExpression(&t)) | |
4818 return false; | |
4819 } | |
4820 if (t.value == TOKdotdotdot) | |
4821 { | |
4822 t = peek(t); | |
4823 break; | |
4824 } | |
4825 } | |
4826 L3: | |
4827 if (t.value == TOKcomma) | |
4828 { | |
4829 continue; | |
4830 } | |
4831 break; | |
4832 } | |
4833 break; | |
4834 } | |
4835 | |
4836 if (t.value != TOKrparen) | |
4837 return false; | |
4838 | |
4839 t = peek(t); | |
4840 *pt = t; | |
4841 return true; | |
4842 } | |
4843 | |
4844 bool isExpression(Token** pt) | |
4845 { | |
4846 // This is supposed to determine if something is an expression. | |
4847 // What it actually does is scan until a closing right bracket | |
4848 // is found. | |
4849 | |
4850 Token* t = *pt; | |
4851 int brnest = 0; | |
4852 int panest = 0; | |
4853 int curlynest = 0; | |
4854 | |
4855 for (;; t = peek(t)) | |
4856 { | |
4857 switch (t.value) | |
4858 { | |
4859 case TOKlbracket: | |
4860 brnest++; | |
4861 continue; | |
4862 | |
4863 case TOKrbracket: | |
4864 if (--brnest >= 0) | |
4865 continue; | |
4866 break; | |
4867 | |
4868 case TOKlparen: | |
4869 panest++; | |
4870 continue; | |
4871 | |
4872 case TOKcomma: | |
4873 if (brnest || panest) | |
4874 continue; | |
4875 break; | |
4876 | |
4877 case TOKrparen: | |
4878 if (--panest >= 0) | |
4879 continue; | |
4880 break; | |
4881 | |
4882 case TOKlcurly: | |
4883 curlynest++; | |
4884 continue; | |
4885 | |
4886 case TOKrcurly: | |
4887 if (--curlynest >= 0) | |
4888 continue; | |
4889 return false; | |
4890 | |
4891 case TOKslice: | |
4892 if (brnest) | |
4893 continue; | |
4894 break; | |
4895 | |
4896 case TOKsemicolon: | |
4897 if (curlynest) | |
4898 continue; | |
4899 return false; | |
4900 | |
4901 case TOKeof: | |
4902 return false; | |
4903 | |
4904 default: | |
4905 continue; | |
4906 } | |
4907 break; | |
4908 } | |
4909 | |
4910 *pt = t; | |
4911 return true; | |
4912 } | |
4913 | |
4914 int isTemplateInstance(Token t, Token* pt) | |
4915 { | |
4916 assert(false); | |
4917 } | |
4918 | |
4919 /******************************************* | |
4920 * Skip parens, brackets. | |
4921 * Input: | |
4922 * t is on opening ( | |
4923 * Output: | |
4924 * *pt is set to closing token, which is ')' on success | |
4925 * Returns: | |
4926 * !=0 successful | |
4927 * 0 some parsing error | |
4928 */ | |
4929 bool skipParens(Token* t, Token** pt) | |
4930 { | |
4931 int parens = 0; | |
4932 | |
4933 while (1) | |
4934 { | |
4935 switch (t.value) | |
4936 { | |
4937 case TOKlparen: | |
4938 parens++; | |
4939 break; | |
4940 | |
4941 case TOKrparen: | |
4942 parens--; | |
4943 if (parens < 0) | |
4944 goto Lfalse; | |
4945 if (parens == 0) | |
4946 goto Ldone; | |
4947 break; | |
4948 | |
4949 case TOKeof: | |
4950 case TOKsemicolon: | |
4951 goto Lfalse; | |
4952 | |
4953 default: | |
4954 break; | |
4955 } | |
4956 t = peek(t); | |
4957 } | |
4958 | |
4959 Ldone: | |
4960 if (*pt) | |
4961 *pt = t; | |
4962 return true; | |
4963 | |
4964 Lfalse: | |
4965 return false; | |
4966 } | |
4967 | |
4968 Expression parseExpression() | |
4969 { | |
4970 Expression e; | |
4971 Expression e2; | |
4972 Loc loc = this.loc; | |
4973 | |
4974 //printf("Parser.parseExpression() loc = %d\n", loc.linnum); | |
4975 e = parseAssignExp(); | |
4976 while (token.value == TOK.TOKcomma) | |
4977 { | |
4978 nextToken(); | |
4979 e2 = parseAssignExp(); | |
4980 e = new CommaExp(loc, e, e2); | |
4981 loc = this.loc; | |
4982 } | |
4983 return e; | |
4984 } | |
4985 | |
4986 Expression parsePrimaryExp() | |
4987 { | |
4988 Expression e; | |
4989 Type t; | |
4990 Identifier id; | |
4991 TOK save; | |
4992 Loc loc = this.loc; | |
4993 | |
4994 //printf("parsePrimaryExp(): loc = %d\n", loc.linnum); | |
4995 switch (token.value) | |
4996 { | |
4997 case TOK.TOKidentifier: | |
4998 id = token.ident; | |
4999 nextToken(); | |
5000 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis) | |
5001 { // identifier!(template-argument-list) | |
5002 TemplateInstance tempinst; | |
5003 | |
5004 tempinst = new TemplateInstance(loc, id); | |
5005 nextToken(); | |
5006 if (token.value == TOK.TOKlparen) | |
5007 // ident!(template_arguments) | |
5008 tempinst.tiargs = parseTemplateArgumentList(); | |
5009 else | |
5010 // ident!template_argument | |
5011 tempinst.tiargs = parseTemplateArgument(); | |
5012 e = new ScopeExp(loc, tempinst); | |
5013 } | |
5014 else | |
5015 e = new IdentifierExp(loc, id); | |
5016 break; | |
5017 | |
5018 case TOK.TOKdollar: | |
5019 if (!inBrackets) | |
5020 error("'$' is valid only inside [] of index or slice"); | |
5021 e = new DollarExp(loc); | |
5022 nextToken(); | |
5023 break; | |
5024 | |
5025 case TOK.TOKdot: | |
5026 // Signal global scope '.' operator with "" identifier | |
5027 e = new IdentifierExp(loc, Id.empty); | |
5028 break; | |
5029 | |
5030 case TOK.TOKthis: | |
5031 e = new ThisExp(loc); | |
5032 nextToken(); | |
5033 break; | |
5034 | |
5035 case TOK.TOKsuper: | |
5036 e = new SuperExp(loc); | |
5037 nextToken(); | |
5038 break; | |
5039 | |
5040 case TOK.TOKint32v: | |
5041 e = new IntegerExp(loc, token.int32value, Type.tint32); | |
5042 nextToken(); | |
5043 break; | |
5044 | |
5045 case TOK.TOKuns32v: | |
5046 e = new IntegerExp(loc, token.uns32value, Type.tuns32); | |
5047 nextToken(); | |
5048 break; | |
5049 | |
5050 case TOK.TOKint64v: | |
5051 e = new IntegerExp(loc, token.int64value, Type.tint64); | |
5052 nextToken(); | |
5053 break; | |
5054 | |
5055 case TOK.TOKuns64v: | |
5056 e = new IntegerExp(loc, token.uns64value, Type.tuns64); | |
5057 nextToken(); | |
5058 break; | |
5059 | |
5060 case TOK.TOKfloat32v: | |
5061 e = new RealExp(loc, token.float80value, Type.tfloat32); | |
5062 nextToken(); | |
5063 break; | |
5064 | |
5065 case TOK.TOKfloat64v: | |
5066 e = new RealExp(loc, token.float80value, Type.tfloat64); | |
5067 nextToken(); | |
5068 break; | |
5069 | |
5070 case TOK.TOKfloat80v: | |
5071 e = new RealExp(loc, token.float80value, Type.tfloat80); | |
5072 nextToken(); | |
5073 break; | |
5074 | |
5075 case TOK.TOKimaginary32v: | |
5076 e = new RealExp(loc, token.float80value, Type.timaginary32); | |
5077 nextToken(); | |
5078 break; | |
5079 | |
5080 case TOK.TOKimaginary64v: | |
5081 e = new RealExp(loc, token.float80value, Type.timaginary64); | |
5082 nextToken(); | |
5083 break; | |
5084 | |
5085 case TOK.TOKimaginary80v: | |
5086 e = new RealExp(loc, token.float80value, Type.timaginary80); | |
5087 nextToken(); | |
5088 break; | |
5089 | |
5090 case TOK.TOKnull: | |
5091 e = new NullExp(loc); | |
5092 nextToken(); | |
5093 break; | |
5094 | |
5095 version (DMDV2) { | |
5096 case TOK.TOKfile: | |
5097 { | |
5098 string s = loc.filename ? loc.filename : mod.ident.toChars(); | |
5099 e = new StringExp(loc, s, 0); | |
5100 nextToken(); | |
5101 break; | |
5102 } | |
5103 | |
5104 case TOK.TOKline: | |
5105 e = new IntegerExp(loc, loc.linnum, Type.tint32); | |
5106 nextToken(); | |
5107 break; | |
5108 } | |
5109 | |
5110 case TOK.TOKtrue: | |
5111 e = new IntegerExp(loc, 1, Type.tbool); | |
5112 nextToken(); | |
5113 break; | |
5114 | |
5115 case TOK.TOKfalse: | |
5116 e = new IntegerExp(loc, 0, Type.tbool); | |
5117 nextToken(); | |
5118 break; | |
5119 | |
5120 case TOK.TOKcharv: | |
5121 e = new IntegerExp(loc, token.uns32value, Type.tchar); | |
5122 nextToken(); | |
5123 break; | |
5124 | |
5125 case TOK.TOKwcharv: | |
5126 e = new IntegerExp(loc, token.uns32value, Type.twchar); | |
5127 nextToken(); | |
5128 break; | |
5129 | |
5130 case TOK.TOKdcharv: | |
5131 e = new IntegerExp(loc, token.uns32value, Type.tdchar); | |
5132 nextToken(); | |
5133 break; | |
5134 | |
5135 case TOK.TOKstring: | |
5136 { | |
5137 const(char)* s; | |
5138 uint len; | |
5139 ubyte postfix; | |
5140 | |
5141 // cat adjacent strings | |
5142 s = token.ustring; | |
5143 len = token.len; | |
5144 postfix = token.postfix; | |
5145 while (1) | |
5146 { | |
5147 nextToken(); | |
5148 if (token.value == TOK.TOKstring) | |
5149 { uint len1; | |
5150 uint len2; | |
5151 char* s2; | |
5152 | |
5153 if (token.postfix) | |
5154 { if (token.postfix != postfix) | |
5155 error("mismatched string literal postfixes '%c' and '%c'", postfix, token.postfix); | |
5156 postfix = token.postfix; | |
5157 } | |
5158 | |
5159 len1 = len; | |
5160 len2 = token.len; | |
5161 len = len1 + len2; | |
2 | 5162 s2 = cast(char*)GC.malloc((len + 1) * ubyte.sizeof); |
0 | 5163 memcpy(s2, s, len1 * ubyte.sizeof); |
5164 memcpy(s2 + len1, token.ustring, (len2 + 1) * ubyte.sizeof); | |
5165 s = s2; | |
5166 } | |
5167 else | |
5168 break; | |
5169 } | |
5170 e = new StringExp(loc, assumeUnique(s[0..len]), postfix); | |
5171 break; | |
5172 } | |
5173 | |
5174 case TOK.TOKvoid: t = Type.tvoid; goto LabelX; | |
5175 case TOK.TOKint8: t = Type.tint8; goto LabelX; | |
5176 case TOK.TOKuns8: t = Type.tuns8; goto LabelX; | |
5177 case TOK.TOKint16: t = Type.tint16; goto LabelX; | |
5178 case TOK.TOKuns16: t = Type.tuns16; goto LabelX; | |
5179 case TOK.TOKint32: t = Type.tint32; goto LabelX; | |
5180 case TOK.TOKuns32: t = Type.tuns32; goto LabelX; | |
5181 case TOK.TOKint64: t = Type.tint64; goto LabelX; | |
5182 case TOK.TOKuns64: t = Type.tuns64; goto LabelX; | |
5183 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX; | |
5184 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX; | |
5185 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX; | |
5186 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX; | |
5187 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX; | |
5188 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX; | |
5189 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX; | |
5190 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX; | |
5191 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX; | |
5192 case TOK.TOKbit: t = Type.tbit; goto LabelX; | |
5193 case TOK.TOKbool: t = Type.tbool; goto LabelX; | |
5194 case TOK.TOKchar: t = Type.tchar; goto LabelX; | |
5195 case TOK.TOKwchar: t = Type.twchar; goto LabelX; | |
5196 case TOK.TOKdchar: t = Type.tdchar; goto LabelX; | |
5197 LabelX: | |
5198 nextToken(); | |
5199 L1: | |
5200 check(TOK.TOKdot, t.toChars()); | |
5201 if (token.value != TOK.TOKidentifier) | |
5202 { error("found '%s' when expecting identifier following '%s.'", token.toChars(), t.toChars()); | |
5203 goto Lerr; | |
5204 } | |
5205 e = typeDotIdExp(loc, t, token.ident); | |
5206 nextToken(); | |
5207 break; | |
5208 | |
5209 case TOK.TOKtypeof: | |
5210 { | |
5211 t = parseTypeof(); | |
5212 e = new TypeExp(loc, t); | |
5213 break; | |
5214 } | |
5215 | |
5216 case TOK.TOKtypeid: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5217 { |
0 | 5218 nextToken(); |
5219 check(TOK.TOKlparen, "typeid"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5220 Object o; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
5221 if (isDeclaration(&token, 0, TOKreserved, null)) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5222 { // argument is a type |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5223 o = parseType(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5224 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5225 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5226 { // argument is an expression |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5227 o = parseAssignExp(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5228 } |
0 | 5229 check(TOK.TOKrparen); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5230 e = new TypeidExp(loc, o); |
0 | 5231 break; |
5232 } | |
5233 | |
5234 version (DMDV2) { | |
5235 case TOK.TOKtraits: | |
5236 { /* __traits(identifier, args...) | |
5237 */ | |
5238 Identifier ident; | |
5239 Objects args = null; | |
5240 | |
5241 nextToken(); | |
5242 check(TOK.TOKlparen); | |
5243 if (token.value != TOK.TOKidentifier) | |
5244 { error("__traits(identifier, args...) expected"); | |
5245 goto Lerr; | |
5246 } | |
5247 ident = token.ident; | |
5248 nextToken(); | |
5249 if (token.value == TOK.TOKcomma) | |
5250 args = parseTemplateArgumentList2(); // __traits(identifier, args...) | |
5251 else | |
5252 check(TOK.TOKrparen); // __traits(identifier) | |
5253 | |
5254 e = new TraitsExp(loc, ident, args); | |
5255 break; | |
5256 } | |
5257 } | |
5258 | |
5259 case TOK.TOKis: | |
5260 { Type targ; | |
5261 Identifier ident = null; | |
5262 Type tspec = null; | |
5263 TOK tok = TOK.TOKreserved; | |
5264 TOK tok2 = TOK.TOKreserved; | |
5265 TemplateParameters tpl = null; | |
5266 Loc loc2 = this.loc; | |
5267 | |
5268 nextToken(); | |
5269 if (token.value == TOK.TOKlparen) | |
5270 { | |
5271 nextToken(); | |
5272 targ = parseType(&ident); | |
5273 if (token.value == TOK.TOKcolon || token.value == TOK.TOKequal) | |
5274 { | |
5275 tok = token.value; | |
5276 nextToken(); | |
5277 if (tok == TOK.TOKequal && | |
5278 (token.value == TOK.TOKtypedef || | |
5279 token.value == TOK.TOKstruct || | |
5280 token.value == TOK.TOKunion || | |
5281 token.value == TOK.TOKclass || | |
5282 token.value == TOK.TOKsuper || | |
5283 token.value == TOK.TOKenum || | |
5284 token.value == TOK.TOKinterface || | |
5285 ///version (DMDV2) { | |
5286 token.value == TOK.TOKconst && peek(&token).value == TOK.TOKrparen || | |
5287 token.value == TOK.TOKinvariant && peek(&token).value == TOK.TOKrparen || | |
5288 token.value == TOK.TOKimmutable && peek(&token).value == TOK.TOKrparen || | |
5289 token.value == TOK.TOKshared && peek(&token).value == TOK.TOKrparen || | |
5290 ///} | |
5291 token.value == TOK.TOKfunction || | |
5292 token.value == TOK.TOKdelegate || | |
5293 token.value == TOK.TOKreturn)) | |
5294 { | |
5295 tok2 = token.value; | |
5296 nextToken(); | |
5297 } | |
5298 else | |
5299 { | |
5300 tspec = parseType(); | |
5301 } | |
5302 } | |
5303 if (ident && tspec) | |
5304 { | |
5305 if (token.value == TOK.TOKcomma) | |
5306 tpl = parseTemplateParameterList(1); | |
5307 else | |
5308 { tpl = new TemplateParameters(); | |
5309 check(TOK.TOKrparen); | |
5310 } | |
5311 TemplateParameter tp = new TemplateTypeParameter(loc2, ident, null, null); | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
5312 tpl.insert(0, tp); |
0 | 5313 } |
5314 else | |
5315 check(TOK.TOKrparen); | |
5316 } | |
5317 else | |
5318 { error("(type identifier : specialization) expected following is"); | |
5319 goto Lerr; | |
5320 } | |
5321 e = new IsExp(loc2, targ, ident, tok, tspec, tok2, tpl); | |
5322 break; | |
5323 } | |
5324 | |
5325 case TOK.TOKassert: | |
5326 { | |
5327 Expression msg = null; | |
5328 | |
5329 nextToken(); | |
5330 check(TOK.TOKlparen, "assert"); | |
5331 e = parseAssignExp(); | |
5332 if (token.value == TOK.TOKcomma) | |
5333 { nextToken(); | |
5334 msg = parseAssignExp(); | |
5335 } | |
5336 check(TOK.TOKrparen); | |
5337 e = new AssertExp(loc, e, msg); | |
5338 break; | |
5339 } | |
5340 | |
5341 case TOK.TOKmixin: | |
5342 { | |
5343 nextToken(); | |
5344 check(TOK.TOKlparen, "mixin"); | |
5345 e = parseAssignExp(); | |
5346 check(TOK.TOKrparen); | |
5347 e = new CompileExp(loc, e); | |
5348 break; | |
5349 } | |
5350 | |
5351 case TOK.TOKimport: | |
5352 { | |
5353 nextToken(); | |
5354 check(TOK.TOKlparen, "import"); | |
5355 e = parseAssignExp(); | |
5356 check(TOK.TOKrparen); | |
5357 e = new FileExp(loc, e); | |
5358 break; | |
5359 } | |
5360 | |
5361 case TOK.TOKlparen: | |
5362 if (peekPastParen(&token).value == TOK.TOKlcurly) | |
5363 { // (arguments) { statements... } | |
5364 save = TOK.TOKdelegate; | |
5365 goto case_delegate; | |
5366 } | |
5367 // ( expression ) | |
5368 nextToken(); | |
5369 e = parseExpression(); | |
5370 check(loc, TOK.TOKrparen); | |
5371 break; | |
5372 | |
5373 case TOK.TOKlbracket: | |
5374 { /* Parse array literals and associative array literals: | |
5375 * [ value, value, value ... ] | |
5376 * [ key:value, key:value, key:value ... ] | |
5377 */ | |
5378 Expressions values = new Expressions(); | |
5379 Expressions keys = null; | |
5380 | |
5381 nextToken(); | |
5382 if (token.value != TOK.TOKrbracket) | |
5383 { | |
5384 while (token.value != TOK.TOKeof) | |
5385 { | |
5386 Expression e2 = parseAssignExp(); | |
5387 if (token.value == TOK.TOKcolon && (keys || values.dim == 0)) | |
5388 { | |
5389 nextToken(); | |
5390 if (!keys) | |
5391 keys = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
5392 keys.push(e2); |
0 | 5393 e2 = parseAssignExp(); |
5394 } | |
5395 else if (keys) | |
5396 { | |
5397 error("'key:value' expected for associative array literal"); | |
5398 delete keys; | |
5399 keys = null; | |
5400 } | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
5401 values.push(e2); |
0 | 5402 if (token.value == TOK.TOKrbracket) |
5403 break; | |
5404 check(TOK.TOKcomma); | |
5405 } | |
5406 } | |
5407 check(TOK.TOKrbracket); | |
5408 | |
5409 if (keys) | |
5410 e = new AssocArrayLiteralExp(loc, keys, values); | |
5411 else | |
5412 e = new ArrayLiteralExp(loc, values); | |
5413 break; | |
5414 } | |
5415 | |
5416 case TOK.TOKlcurly: | |
5417 // { statements... } | |
5418 save = TOK.TOKdelegate; | |
5419 goto case_delegate; | |
5420 | |
5421 case TOK.TOKfunction: | |
5422 case TOK.TOKdelegate: | |
5423 save = token.value; | |
5424 nextToken(); | |
5425 case_delegate: | |
5426 { | |
5427 /* function type(parameters) { body } pure nothrow | |
5428 * delegate type(parameters) { body } pure nothrow | |
5429 * (parameters) { body } | |
5430 * { body } | |
5431 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5432 Parameters arguments; |
0 | 5433 int varargs; |
5434 FuncLiteralDeclaration fd; | |
5435 Type tt; | |
5436 bool isnothrow = false; | |
5437 bool ispure = false; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5438 bool isproperty = false; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5439 TRUST trust = TRUSTdefault; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5440 |
0 | 5441 if (token.value == TOK.TOKlcurly) |
5442 { | |
5443 tt = null; | |
5444 varargs = 0; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5445 arguments = new Parameters(); |
0 | 5446 } |
5447 else | |
5448 { | |
5449 if (token.value == TOK.TOKlparen) | |
5450 tt = null; | |
5451 else | |
5452 { | |
5453 tt = parseBasicType(); | |
5454 tt = parseBasicType2(tt); // function return type | |
5455 } | |
5456 arguments = parseParameters(&varargs); | |
5457 while (1) | |
5458 { | |
5459 if (token.value == TOK.TOKpure) | |
5460 ispure = true; | |
5461 else if (token.value == TOK.TOKnothrow) | |
5462 isnothrow = true; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5463 else if (token.value == TOKat) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5464 { |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
5465 StorageClass stc = parseAttribute(); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5466 switch (cast(uint)(stc >> 32)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5467 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5468 case STCproperty >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5469 isproperty = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5470 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5471 case STCsafe >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5472 trust = TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5473 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5474 case STCsystem >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5475 trust = TRUSTsystem; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5476 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5477 case STCtrusted >> 32: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5478 trust = TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5479 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5480 case 0: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5481 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5482 default: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5483 assert(0); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5484 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5485 } |
0 | 5486 else |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5487 break; |
0 | 5488 nextToken(); |
5489 } | |
5490 } | |
5491 | |
5492 TypeFunction tf = new TypeFunction(arguments, tt, varargs, linkage); | |
5493 tf.ispure = ispure; | |
5494 tf.isnothrow = isnothrow; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5495 tf.isproperty = isproperty; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5496 tf.trust = trust; |
0 | 5497 fd = new FuncLiteralDeclaration(loc, Loc(0), tf, save, null); |
5498 parseContracts(fd); | |
5499 e = new FuncExp(loc, fd); | |
5500 break; | |
5501 } | |
5502 | |
5503 default: | |
5504 error("expression expected, not '%s'", token.toChars()); | |
5505 Lerr: | |
5506 // Anything for e, as long as it's not null | |
5507 e = new IntegerExp(loc, 0, Type.tint32); | |
5508 nextToken(); | |
5509 break; | |
5510 } | |
5511 return e; | |
5512 } | |
5513 | |
5514 Expression parseUnaryExp() | |
5515 { | |
5516 Expression e; | |
5517 Loc loc = this.loc; | |
5518 | |
5519 switch (token.value) | |
5520 { | |
5521 case TOK.TOKand: | |
5522 nextToken(); | |
5523 e = parseUnaryExp(); | |
5524 e = new AddrExp(loc, e); | |
5525 break; | |
5526 | |
5527 case TOK.TOKplusplus: | |
5528 nextToken(); | |
5529 e = parseUnaryExp(); | |
5530 e = new AddAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32)); | |
5531 break; | |
5532 | |
5533 case TOK.TOKminusminus: | |
5534 nextToken(); | |
5535 e = parseUnaryExp(); | |
5536 e = new MinAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32)); | |
5537 break; | |
5538 | |
5539 case TOK.TOKmul: | |
5540 nextToken(); | |
5541 e = parseUnaryExp(); | |
5542 e = new PtrExp(loc, e); | |
5543 break; | |
5544 | |
5545 case TOK.TOKmin: | |
5546 nextToken(); | |
5547 e = parseUnaryExp(); | |
5548 e = new NegExp(loc, e); | |
5549 break; | |
5550 | |
5551 case TOK.TOKadd: | |
5552 nextToken(); | |
5553 e = parseUnaryExp(); | |
5554 e = new UAddExp(loc, e); | |
5555 break; | |
5556 | |
5557 case TOK.TOKnot: | |
5558 nextToken(); | |
5559 e = parseUnaryExp(); | |
5560 e = new NotExp(loc, e); | |
5561 break; | |
5562 | |
5563 case TOK.TOKtilde: | |
5564 nextToken(); | |
5565 e = parseUnaryExp(); | |
5566 e = new ComExp(loc, e); | |
5567 break; | |
5568 | |
5569 case TOK.TOKdelete: | |
5570 nextToken(); | |
5571 e = parseUnaryExp(); | |
5572 e = new DeleteExp(loc, e); | |
5573 break; | |
5574 | |
5575 case TOK.TOKnew: | |
5576 e = parseNewExp(null); | |
5577 break; | |
5578 | |
5579 case TOK.TOKcast: // cast(type) expression | |
5580 { | |
5581 nextToken(); | |
5582 check(TOK.TOKlparen); | |
5583 /* Look for cast(), cast(const), cast(immutable), | |
5584 * cast(shared), cast(shared const) | |
5585 */ | |
5586 MOD m; | |
5587 if (token.value == TOK.TOKrparen) | |
5588 { | |
5589 m = MOD.MODundefined; | |
5590 goto Lmod1; | |
5591 } | |
5592 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKrparen) | |
5593 { | |
5594 m = MOD.MODconst; | |
5595 goto Lmod2; | |
5596 } | |
5597 else if ((token.value == TOK.TOKimmutable || token.value == TOK.TOKinvariant) && peekNext() == TOK.TOKrparen) | |
5598 { | |
5599 m = MOD.MODinvariant; | |
5600 goto Lmod2; | |
5601 } | |
5602 else if (token.value == TOK.TOKshared && peekNext() == TOK.TOKrparen) | |
5603 { | |
5604 m = MOD.MODshared; | |
5605 goto Lmod2; | |
5606 } | |
5607 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() == TOK.TOKrparen || | |
5608 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() == TOK.TOKrparen) | |
5609 { | |
5610 m = MOD.MODshared | MOD.MODconst; | |
5611 nextToken(); | |
5612 Lmod2: | |
5613 nextToken(); | |
5614 Lmod1: | |
5615 nextToken(); | |
5616 e = parseUnaryExp(); | |
5617 e = new CastExp(loc, e, m); | |
5618 } | |
5619 else | |
5620 { | |
5621 Type t = parseType(); // ( type ) | |
5622 check(TOK.TOKrparen); | |
5623 e = parseUnaryExp(); | |
5624 e = new CastExp(loc, e, t); | |
5625 } | |
5626 break; | |
5627 } | |
5628 | |
5629 case TOK.TOKlparen: | |
5630 { Token *tk; | |
5631 | |
5632 tk = peek(&token); | |
5633 version (CCASTSYNTAX) { | |
5634 // If cast | |
5635 if (isDeclaration(tk, 0, TOK.TOKrparen, &tk)) | |
5636 { | |
5637 tk = peek(tk); // skip over right parenthesis | |
5638 switch (tk.value) | |
5639 { | |
5640 case TOK.TOKnot: | |
5641 tk = peek(tk); | |
5642 if (tk.value == TOK.TOKis) // !is | |
5643 break; | |
5644 case TOK.TOKdot: | |
5645 case TOK.TOKplusplus: | |
5646 case TOK.TOKminusminus: | |
5647 case TOK.TOKdelete: | |
5648 case TOK.TOKnew: | |
5649 case TOK.TOKlparen: | |
5650 case TOK.TOKidentifier: | |
5651 case TOK.TOKthis: | |
5652 case TOK.TOKsuper: | |
5653 case TOK.TOKint32v: | |
5654 case TOK.TOKuns32v: | |
5655 case TOK.TOKint64v: | |
5656 case TOK.TOKuns64v: | |
5657 case TOK.TOKfloat32v: | |
5658 case TOK.TOKfloat64v: | |
5659 case TOK.TOKfloat80v: | |
5660 case TOK.TOKimaginary32v: | |
5661 case TOK.TOKimaginary64v: | |
5662 case TOK.TOKimaginary80v: | |
5663 case TOK.TOKnull: | |
5664 case TOK.TOKtrue: | |
5665 case TOK.TOKfalse: | |
5666 case TOK.TOKcharv: | |
5667 case TOK.TOKwcharv: | |
5668 case TOK.TOKdcharv: | |
5669 case TOK.TOKstring: | |
5670 static if (false) { | |
5671 case TOK.TOKtilde: | |
5672 case TOK.TOKand: | |
5673 case TOK.TOKmul: | |
5674 case TOK.TOKmin: | |
5675 case TOK.TOKadd: | |
5676 } | |
5677 case TOK.TOKfunction: | |
5678 case TOK.TOKdelegate: | |
5679 case TOK.TOKtypeof: | |
5680 version (DMDV2) { | |
5681 case TOK.TOKfile: | |
5682 case TOK.TOKline: | |
5683 } | |
5684 case TOK.TOKwchar: case TOK.TOKdchar: | |
5685 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar: | |
5686 case TOK.TOKint8: case TOK.TOKuns8: | |
5687 case TOK.TOKint16: case TOK.TOKuns16: | |
5688 case TOK.TOKint32: case TOK.TOKuns32: | |
5689 case TOK.TOKint64: case TOK.TOKuns64: | |
5690 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80: | |
5691 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80: | |
5692 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80: | |
5693 case TOK.TOKvoid: // (type)int.size | |
5694 { | |
5695 // (type) una_exp | |
5696 nextToken(); | |
5697 Type t = parseType(); | |
5698 check(TOK.TOKrparen); | |
5699 | |
5700 // if .identifier | |
5701 if (token.value == TOK.TOKdot) | |
5702 { | |
5703 nextToken(); | |
5704 if (token.value != TOK.TOKidentifier) | |
5705 { | |
5706 error("Identifier expected following (type)."); | |
5707 return null; | |
5708 } | |
5709 e = typeDotIdExp(loc, t, token.ident); | |
5710 nextToken(); | |
5711 e = parsePostExp(e); | |
5712 } | |
5713 else | |
5714 { | |
5715 e = parseUnaryExp(); | |
5716 e = new CastExp(loc, e, t); | |
5717 error("C style cast illegal, use %s", e.toChars()); | |
5718 } | |
5719 return e; | |
5720 } | |
5721 | |
5722 default: | |
5723 break; /// | |
5724 } | |
5725 } | |
5726 } | |
5727 e = parsePrimaryExp(); | |
5728 e = parsePostExp(e); | |
5729 break; | |
5730 } | |
5731 default: | |
5732 e = parsePrimaryExp(); | |
5733 e = parsePostExp(e); | |
5734 break; | |
5735 } | |
5736 assert(e); | |
5737 return e; | |
5738 } | |
5739 | |
5740 Expression parsePostExp(Expression e) | |
5741 { | |
5742 Loc loc; | |
5743 | |
5744 while (1) | |
5745 { | |
5746 loc = this.loc; | |
5747 switch (token.value) | |
5748 { | |
5749 case TOK.TOKdot: | |
5750 nextToken(); | |
5751 if (token.value == TOK.TOKidentifier) | |
5752 { Identifier id = token.ident; | |
5753 | |
5754 nextToken(); | |
5755 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis) | |
5756 { // identifier!(template-argument-list) | |
5757 TemplateInstance tempinst = new TemplateInstance(loc, id); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5758 Objects tiargs; |
0 | 5759 nextToken(); |
5760 if (token.value == TOK.TOKlparen) | |
5761 // ident!(template_arguments) | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5762 tiargs = parseTemplateArgumentList(); |
0 | 5763 else |
5764 // ident!template_argument | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5765 tiargs = parseTemplateArgument(); |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
5766 e = new DotTemplateInstanceExp(loc, e, id, tiargs); |
0 | 5767 } |
5768 else | |
5769 e = new DotIdExp(loc, e, id); | |
5770 continue; | |
5771 } | |
5772 else if (token.value == TOK.TOKnew) | |
5773 { | |
5774 e = parseNewExp(e); | |
5775 continue; | |
5776 } | |
5777 else | |
5778 error("identifier expected following '.', not '%s'", token.toChars()); | |
5779 break; | |
5780 | |
5781 case TOK.TOKplusplus: | |
5782 e = new PostExp(TOK.TOKplusplus, loc, e); | |
5783 break; | |
5784 | |
5785 case TOK.TOKminusminus: | |
5786 e = new PostExp(TOK.TOKminusminus, loc, e); | |
5787 break; | |
5788 | |
5789 case TOK.TOKlparen: | |
5790 e = new CallExp(loc, e, parseArguments()); | |
5791 continue; | |
5792 | |
5793 case TOK.TOKlbracket: | |
5794 { // array dereferences: | |
5795 // array[index] | |
5796 // array[] | |
5797 // array[lwr .. upr] | |
5798 Expression index; | |
5799 Expression upr; | |
5800 | |
5801 inBrackets++; | |
5802 nextToken(); | |
5803 if (token.value == TOK.TOKrbracket) | |
5804 { // array[] | |
5805 e = new SliceExp(loc, e, null, null); | |
5806 nextToken(); | |
5807 } | |
5808 else | |
5809 { | |
5810 index = parseAssignExp(); | |
5811 if (token.value == TOK.TOKslice) | |
5812 { // array[lwr .. upr] | |
5813 nextToken(); | |
5814 upr = parseAssignExp(); | |
5815 e = new SliceExp(loc, e, index, upr); | |
5816 } | |
5817 else | |
5818 { // array[index, i2, i3, i4, ...] | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
5819 auto arguments = new Expressions(); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
5820 arguments.push(index); |
0 | 5821 if (token.value == TOK.TOKcomma) |
5822 { | |
5823 nextToken(); | |
5824 while (1) | |
5825 { Expression arg; | |
5826 | |
5827 arg = parseAssignExp(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
5828 arguments.push(arg); |
0 | 5829 if (token.value == TOK.TOKrbracket) |
5830 break; | |
5831 check(TOK.TOKcomma); | |
5832 } | |
5833 } | |
5834 e = new ArrayExp(loc, e, arguments); | |
5835 } | |
5836 check(TOK.TOKrbracket); | |
5837 inBrackets--; | |
5838 } | |
5839 continue; | |
5840 } | |
5841 | |
5842 default: | |
5843 return e; | |
5844 } | |
5845 nextToken(); | |
5846 } | |
5847 | |
5848 assert(false); | |
5849 } | |
5850 | |
5851 Expression parseMulExp() | |
5852 { | |
5853 Expression e; | |
5854 Expression e2; | |
5855 Loc loc = this.loc; | |
5856 | |
5857 e = parseUnaryExp(); | |
5858 while (1) | |
5859 { | |
5860 switch (token.value) | |
5861 { | |
5862 case TOK.TOKmul: nextToken(); e2 = parseUnaryExp(); e = new MulExp(loc,e,e2); continue; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5863 case TOK.TOKdiv: nextToken(); e2 = parseUnaryExp(); e = new DivExp(loc,e,e2); continue; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5864 case TOK.TOKmod: nextToken(); e2 = parseUnaryExp(); e = new ModExp(loc,e,e2); continue; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
5865 case TOK.TOKpow: nextToken(); e2 = parseUnaryExp(); e = new PowExp(loc,e,e2); continue; |
0 | 5866 |
5867 default: | |
5868 break; | |
5869 } | |
5870 break; | |
5871 } | |
5872 return e; | |
5873 } | |
5874 | |
5875 Expression parseShiftExp() | |
5876 { | |
5877 Expression e; | |
5878 Expression e2; | |
5879 Loc loc = this.loc; | |
5880 | |
5881 e = parseAddExp(); | |
5882 while (1) | |
5883 { | |
5884 switch (token.value) | |
5885 { | |
5886 case TOK.TOKshl: nextToken(); e2 = parseAddExp(); e = new ShlExp(loc,e,e2); continue; | |
5887 case TOK.TOKshr: nextToken(); e2 = parseAddExp(); e = new ShrExp(loc,e,e2); continue; | |
5888 case TOK.TOKushr: nextToken(); e2 = parseAddExp(); e = new UshrExp(loc,e,e2); continue; | |
5889 | |
5890 default: | |
5891 break; | |
5892 } | |
5893 break; | |
5894 } | |
5895 return e; | |
5896 } | |
5897 | |
5898 Expression parseAddExp() | |
5899 { | |
5900 Expression e; | |
5901 Expression e2; | |
5902 Loc loc = this.loc; | |
5903 | |
5904 e = parseMulExp(); | |
5905 while (1) | |
5906 { | |
5907 switch (token.value) | |
5908 { | |
5909 case TOK.TOKadd: nextToken(); e2 = parseMulExp(); e = new AddExp(loc,e,e2); continue; | |
5910 case TOK.TOKmin: nextToken(); e2 = parseMulExp(); e = new MinExp(loc,e,e2); continue; | |
5911 case TOK.TOKtilde: nextToken(); e2 = parseMulExp(); e = new CatExp(loc,e,e2); continue; | |
5912 | |
5913 default: | |
5914 break; | |
5915 } | |
5916 break; | |
5917 } | |
5918 return e; | |
5919 } | |
5920 | |
5921 Expression parseRelExp() | |
5922 { | |
5923 assert(false); | |
5924 } | |
5925 | |
5926 Expression parseEqualExp() | |
5927 { | |
5928 assert(false); | |
5929 } | |
5930 | |
5931 Expression parseCmpExp() | |
5932 { | |
5933 Expression e; | |
5934 Expression e2; | |
5935 Token* t; | |
5936 Loc loc = this.loc; | |
5937 | |
5938 e = parseShiftExp(); | |
5939 TOK op = token.value; | |
5940 | |
5941 switch (op) | |
5942 { | |
5943 case TOK.TOKequal: | |
5944 case TOK.TOKnotequal: | |
5945 nextToken(); | |
5946 e2 = parseShiftExp(); | |
5947 e = new EqualExp(op, loc, e, e2); | |
5948 break; | |
5949 | |
5950 case TOK.TOKis: | |
5951 op = TOK.TOKidentity; | |
5952 goto L1; | |
5953 | |
5954 case TOK.TOKnot: | |
5955 // Attempt to identify '!is' | |
5956 t = peek(&token); | |
5957 if (t.value != TOK.TOKis) | |
5958 break; | |
5959 nextToken(); | |
5960 op = TOK.TOKnotidentity; | |
5961 goto L1; | |
5962 | |
5963 L1: | |
5964 nextToken(); | |
5965 e2 = parseShiftExp(); | |
5966 e = new IdentityExp(op, loc, e, e2); | |
5967 break; | |
5968 | |
5969 case TOK.TOKlt: | |
5970 case TOK.TOKle: | |
5971 case TOK.TOKgt: | |
5972 case TOK.TOKge: | |
5973 case TOK.TOKunord: | |
5974 case TOK.TOKlg: | |
5975 case TOK.TOKleg: | |
5976 case TOK.TOKule: | |
5977 case TOK.TOKul: | |
5978 case TOK.TOKuge: | |
5979 case TOK.TOKug: | |
5980 case TOK.TOKue: | |
5981 nextToken(); | |
5982 e2 = parseShiftExp(); | |
5983 e = new CmpExp(op, loc, e, e2); | |
5984 break; | |
5985 | |
5986 case TOK.TOKin: | |
5987 nextToken(); | |
5988 e2 = parseShiftExp(); | |
5989 e = new InExp(loc, e, e2); | |
5990 break; | |
5991 | |
5992 default: | |
5993 break; | |
5994 } | |
5995 return e; | |
5996 } | |
5997 | |
5998 Expression parseAndExp() | |
5999 { | |
6000 Expression e; | |
6001 Expression e2; | |
6002 Loc loc = this.loc; | |
6003 | |
6004 if (global.params.Dversion == 1) | |
6005 { | |
6006 e = parseEqualExp(); | |
6007 while (token.value == TOK.TOKand) | |
6008 { | |
6009 nextToken(); | |
6010 e2 = parseEqualExp(); | |
6011 e = new AndExp(loc,e,e2); | |
6012 loc = this.loc; | |
6013 } | |
6014 } | |
6015 else | |
6016 { | |
6017 e = parseCmpExp(); | |
6018 while (token.value == TOK.TOKand) | |
6019 { | |
6020 nextToken(); | |
6021 e2 = parseCmpExp(); | |
6022 e = new AndExp(loc,e,e2); | |
6023 loc = this.loc; | |
6024 } | |
6025 } | |
6026 return e; | |
6027 } | |
6028 | |
6029 Expression parseXorExp() | |
6030 { | |
6031 Expression e; | |
6032 Expression e2; | |
6033 Loc loc = this.loc; | |
6034 | |
6035 e = parseAndExp(); | |
6036 while (token.value == TOK.TOKxor) | |
6037 { | |
6038 nextToken(); | |
6039 e2 = parseAndExp(); | |
6040 e = new XorExp(loc, e, e2); | |
6041 } | |
6042 | |
6043 return e; | |
6044 } | |
6045 | |
6046 Expression parseOrExp() | |
6047 { | |
6048 Expression e; | |
6049 Expression e2; | |
6050 Loc loc = this.loc; | |
6051 | |
6052 e = parseXorExp(); | |
6053 while (token.value == TOK.TOKor) | |
6054 { | |
6055 nextToken(); | |
6056 e2 = parseXorExp(); | |
6057 e = new OrExp(loc, e, e2); | |
6058 } | |
6059 return e; | |
6060 } | |
6061 | |
6062 Expression parseAndAndExp() | |
6063 { | |
6064 Expression e; | |
6065 Expression e2; | |
6066 Loc loc = this.loc; | |
6067 | |
6068 e = parseOrExp(); | |
6069 while (token.value == TOK.TOKandand) | |
6070 { | |
6071 nextToken(); | |
6072 e2 = parseOrExp(); | |
6073 e = new AndAndExp(loc, e, e2); | |
6074 } | |
6075 return e; | |
6076 } | |
6077 | |
6078 Expression parseOrOrExp() | |
6079 { | |
6080 Expression e; | |
6081 Expression e2; | |
6082 Loc loc = this.loc; | |
6083 | |
6084 e = parseAndAndExp(); | |
6085 while (token.value == TOK.TOKoror) | |
6086 { | |
6087 nextToken(); | |
6088 e2 = parseAndAndExp(); | |
6089 e = new OrOrExp(loc, e, e2); | |
6090 } | |
6091 | |
6092 return e; | |
6093 } | |
6094 | |
6095 Expression parseCondExp() | |
6096 { | |
6097 Expression e; | |
6098 Expression e1; | |
6099 Expression e2; | |
6100 Loc loc = this.loc; | |
6101 | |
6102 e = parseOrOrExp(); | |
6103 if (token.value == TOK.TOKquestion) | |
6104 { | |
6105 nextToken(); | |
6106 e1 = parseExpression(); | |
6107 check(TOK.TOKcolon); | |
6108 e2 = parseCondExp(); | |
6109 e = new CondExp(loc, e, e1, e2); | |
6110 } | |
6111 return e; | |
6112 } | |
6113 | |
6114 Expression parseAssignExp() | |
6115 { | |
6116 Expression e; | |
6117 Expression e2; | |
6118 Loc loc; | |
6119 | |
6120 e = parseCondExp(); | |
6121 while (1) | |
6122 { | |
6123 loc = this.loc; | |
6124 switch (token.value) | |
6125 { | |
6126 case TOK.TOKassign: nextToken(); e2 = parseAssignExp(); e = new AssignExp(loc,e,e2); continue; | |
6127 case TOK.TOKaddass: nextToken(); e2 = parseAssignExp(); e = new AddAssignExp(loc,e,e2); continue; | |
6128 case TOK.TOKminass: nextToken(); e2 = parseAssignExp(); e = new MinAssignExp(loc,e,e2); continue; | |
6129 case TOK.TOKmulass: nextToken(); e2 = parseAssignExp(); e = new MulAssignExp(loc,e,e2); continue; | |
6130 case TOK.TOKdivass: nextToken(); e2 = parseAssignExp(); e = new DivAssignExp(loc,e,e2); continue; | |
6131 case TOK.TOKmodass: nextToken(); e2 = parseAssignExp(); e = new ModAssignExp(loc,e,e2); continue; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
128
diff
changeset
|
6132 // case TOK.TOKpowass: nextToken(); e2 = parseAssignExp(); e = new PowAssignExp(loc,e,e2); continue; |
0 | 6133 case TOK.TOKandass: nextToken(); e2 = parseAssignExp(); e = new AndAssignExp(loc,e,e2); continue; |
6134 case TOK.TOKorass: nextToken(); e2 = parseAssignExp(); e = new OrAssignExp(loc,e,e2); continue; | |
6135 case TOK.TOKxorass: nextToken(); e2 = parseAssignExp(); e = new XorAssignExp(loc,e,e2); continue; | |
6136 case TOK.TOKshlass: nextToken(); e2 = parseAssignExp(); e = new ShlAssignExp(loc,e,e2); continue; | |
6137 case TOK.TOKshrass: nextToken(); e2 = parseAssignExp(); e = new ShrAssignExp(loc,e,e2); continue; | |
6138 case TOK.TOKushrass: nextToken(); e2 = parseAssignExp(); e = new UshrAssignExp(loc,e,e2); continue; | |
6139 case TOK.TOKcatass: nextToken(); e2 = parseAssignExp(); e = new CatAssignExp(loc,e,e2); continue; | |
6140 | |
6141 default: | |
6142 break; | |
6143 } | |
6144 break; | |
6145 } | |
6146 | |
6147 return e; | |
6148 } | |
6149 | |
6150 /************************* | |
6151 * Collect argument list. | |
6152 * Assume current token is ',', '(' or '['. | |
6153 */ | |
6154 Expressions parseArguments() | |
6155 { | |
6156 // function call | |
6157 Expressions arguments = new Expressions(); | |
6158 Expression arg; | |
6159 TOK endtok; | |
6160 | |
6161 if (token.value == TOK.TOKlbracket) | |
6162 endtok = TOK.TOKrbracket; | |
6163 else | |
6164 endtok = TOK.TOKrparen; | |
6165 | |
6166 { | |
6167 nextToken(); | |
6168 if (token.value != endtok) | |
6169 { | |
6170 while (1) | |
6171 { | |
6172 arg = parseAssignExp(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
6173 arguments.push(arg); |
0 | 6174 if (token.value == endtok) |
6175 break; | |
6176 check(TOK.TOKcomma); | |
6177 } | |
6178 } | |
6179 check(endtok); | |
6180 } | |
6181 return arguments; | |
6182 } | |
6183 | |
6184 Expression parseNewExp(Expression thisexp) | |
6185 { | |
6186 Type t; | |
6187 Expressions newargs; | |
6188 Expressions arguments = null; | |
6189 Expression e; | |
6190 Loc loc = this.loc; | |
6191 | |
6192 nextToken(); | |
6193 newargs = null; | |
6194 if (token.value == TOKlparen) | |
6195 { | |
6196 newargs = parseArguments(); | |
6197 } | |
6198 | |
6199 // An anonymous nested class starts with "class" | |
6200 if (token.value == TOKclass) | |
6201 { | |
6202 nextToken(); | |
6203 if (token.value == TOKlparen) | |
6204 arguments = parseArguments(); | |
6205 | |
6206 BaseClasses baseclasses = null; | |
6207 if (token.value != TOKlcurly) | |
6208 baseclasses = parseBaseClasses(); | |
6209 | |
6210 Identifier id = null; | |
6211 ClassDeclaration cd = new ClassDeclaration(loc, id, baseclasses); | |
6212 | |
6213 if (token.value != TOKlcurly) | |
6214 { | |
6215 error("{ members } expected for anonymous class"); | |
6216 cd.members = null; | |
6217 } | |
6218 else | |
6219 { | |
6220 nextToken(); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
56
diff
changeset
|
6221 auto decl = parseDeclDefs(0); |
0 | 6222 if (token.value != TOKrcurly) |
6223 error("class member expected"); | |
6224 nextToken(); | |
6225 cd.members = decl; | |
6226 } | |
6227 | |
6228 e = new NewAnonClassExp(loc, thisexp, newargs, cd, arguments); | |
6229 | |
6230 return e; | |
6231 } | |
6232 | |
6233 t = parseBasicType(); | |
6234 t = parseBasicType2(t); | |
6235 if (t.ty == Taarray) | |
6236 { | |
6237 TypeAArray taa = cast(TypeAArray)t; | |
6238 Type index = taa.index; | |
6239 | |
6240 Expression e2 = index.toExpression(); | |
6241 if (e2) | |
6242 { | |
6243 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
6244 arguments.push(e2); |
0 | 6245 t = new TypeDArray(taa.next); |
6246 } | |
6247 else | |
6248 { | |
6249 error("need size of rightmost array, not type %s", index.toChars()); | |
6250 return new NullExp(loc); | |
6251 } | |
6252 } | |
6253 else if (t.ty == Tsarray) | |
6254 { | |
6255 TypeSArray tsa = cast(TypeSArray)t; | |
6256 Expression ee = tsa.dim; | |
6257 | |
6258 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
6259 arguments.push(ee); |
0 | 6260 t = new TypeDArray(tsa.next); |
6261 } | |
6262 else if (token.value == TOKlparen) | |
6263 { | |
6264 arguments = parseArguments(); | |
6265 } | |
6266 | |
6267 e = new NewExp(loc, thisexp, newargs, t, arguments); | |
6268 return e; | |
6269 } | |
6270 | |
79 | 6271 void addComment(Dsymbol s, const(char)[] blockComment) |
0 | 6272 { |
6273 s.addComment(combineComments(blockComment, token.lineComment)); | |
6274 token.lineComment = null; | |
6275 } | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
6276 } |