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