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