Mercurial > projects > dil
comparison trunk/src/dil/ast/Declarations.d @ 791:5fe89bb8cbdd
Implemented syntax tree copying.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Tue, 26 Feb 2008 20:13:41 +0100 |
parents | 9f61e8af55d5 |
children |
comparison
equal
deleted
inserted
replaced
790:a83a07f6233d | 791:5fe89bb8cbdd |
---|---|
4 +/ | 4 +/ |
5 module dil.ast.Declarations; | 5 module dil.ast.Declarations; |
6 | 6 |
7 public import dil.ast.Declaration; | 7 public import dil.ast.Declaration; |
8 import dil.ast.Node; | 8 import dil.ast.Node; |
9 import dil.ast.Expressions; | 9 import dil.ast.Expression; |
10 import dil.ast.Types; | 10 import dil.ast.Types; |
11 import dil.ast.Statements; | 11 import dil.ast.Statements; |
12 import dil.ast.Parameters; | 12 import dil.ast.Parameters; |
13 import dil.ast.NodeCopier; | |
13 import dil.lexer.IdTable; | 14 import dil.lexer.IdTable; |
14 import dil.semantic.Symbols; | 15 import dil.semantic.Symbols; |
15 import dil.Enums; | 16 import dil.Enums; |
16 import common; | 17 import common; |
17 | 18 |
35 | 36 |
36 Declaration[] decls() | 37 Declaration[] decls() |
37 { | 38 { |
38 return cast(Declaration[])this.children; | 39 return cast(Declaration[])this.children; |
39 } | 40 } |
41 | |
42 void decls(Declaration[] decls) | |
43 { | |
44 this.children = decls; | |
45 } | |
46 | |
47 mixin(copyMethod); | |
40 } | 48 } |
41 | 49 |
42 /// Single semicolon. | 50 /// Single semicolon. |
43 class EmptyDeclaration : Declaration | 51 class EmptyDeclaration : Declaration |
44 { | 52 { |
45 this() | 53 this() |
46 { | 54 { |
47 mixin(set_kind); | 55 mixin(set_kind); |
48 } | 56 } |
49 } | 57 mixin(copyMethod); |
50 | 58 } |
51 /++ | 59 |
52 Illegal declarations encompass all tokens that don't | 60 /// Illegal declarations encompass all tokens that don't |
53 start a DeclarationDefinition. | 61 /// start a DeclarationDefinition. |
54 See_Also: dil.lexer.Token.isDeclDefStartToken() | 62 /// See_Also: dil.lexer.Token.isDeclDefStartToken() |
55 +/ | |
56 class IllegalDeclaration : Declaration | 63 class IllegalDeclaration : Declaration |
57 { | 64 { |
58 this() | 65 this() |
59 { | 66 { |
60 mixin(set_kind); | 67 mixin(set_kind); |
61 } | 68 } |
69 mixin(copyMethod); | |
62 } | 70 } |
63 | 71 |
64 /// FQN = fully qualified name | 72 /// FQN = fully qualified name |
65 alias Identifier*[] ModuleFQN; // Identifier(.Identifier)* | 73 alias Identifier*[] ModuleFQN; // Identifier(.Identifier)* |
66 | 74 |
100 pname ~= pckg.str ~ separator; | 108 pname ~= pckg.str ~ separator; |
101 if (pname.length) | 109 if (pname.length) |
102 pname = pname[0..$-1]; // Remove last separator | 110 pname = pname[0..$-1]; // Remove last separator |
103 return pname; | 111 return pname; |
104 } | 112 } |
113 | |
114 mixin(copyMethod); | |
105 } | 115 } |
106 | 116 |
107 class ImportDeclaration : Declaration | 117 class ImportDeclaration : Declaration |
108 { | 118 { |
109 private alias Identifier*[] Ids; | 119 private alias Identifier*[] Ids; |
134 FQN ~= ident.str ~ separator; | 144 FQN ~= ident.str ~ separator; |
135 FQNs ~= FQN[0..$-1]; // Remove last separator | 145 FQNs ~= FQN[0..$-1]; // Remove last separator |
136 } | 146 } |
137 return FQNs; | 147 return FQNs; |
138 } | 148 } |
149 | |
150 mixin(copyMethod); | |
139 } | 151 } |
140 | 152 |
141 class AliasDeclaration : Declaration | 153 class AliasDeclaration : Declaration |
142 { | 154 { |
143 Declaration decl; | 155 Declaration decl; |
145 { | 157 { |
146 mixin(set_kind); | 158 mixin(set_kind); |
147 addChild(decl); | 159 addChild(decl); |
148 this.decl = decl; | 160 this.decl = decl; |
149 } | 161 } |
162 mixin(copyMethod); | |
150 } | 163 } |
151 | 164 |
152 class TypedefDeclaration : Declaration | 165 class TypedefDeclaration : Declaration |
153 { | 166 { |
154 Declaration decl; | 167 Declaration decl; |
156 { | 169 { |
157 mixin(set_kind); | 170 mixin(set_kind); |
158 addChild(decl); | 171 addChild(decl); |
159 this.decl = decl; | 172 this.decl = decl; |
160 } | 173 } |
174 mixin(copyMethod); | |
161 } | 175 } |
162 | 176 |
163 class EnumDeclaration : Declaration | 177 class EnumDeclaration : Declaration |
164 { | 178 { |
165 Identifier* name; | 179 Identifier* name; |
176 this.baseType = baseType; | 190 this.baseType = baseType; |
177 this.members = members; | 191 this.members = members; |
178 } | 192 } |
179 | 193 |
180 Enum symbol; | 194 Enum symbol; |
195 | |
196 mixin(copyMethod); | |
181 } | 197 } |
182 | 198 |
183 class EnumMemberDeclaration : Declaration | 199 class EnumMemberDeclaration : Declaration |
184 { | 200 { |
185 Identifier* name; | 201 Identifier* name; |
192 this.name = name; | 208 this.name = name; |
193 this.value = value; | 209 this.value = value; |
194 } | 210 } |
195 | 211 |
196 EnumMember symbol; | 212 EnumMember symbol; |
213 | |
214 mixin(copyMethod); | |
197 } | 215 } |
198 | 216 |
199 class TemplateDeclaration : Declaration | 217 class TemplateDeclaration : Declaration |
200 { | 218 { |
201 Identifier* name; | 219 Identifier* name; |
212 this.tparams = tparams; | 230 this.tparams = tparams; |
213 this.decls = decls; | 231 this.decls = decls; |
214 } | 232 } |
215 | 233 |
216 Template symbol; /// The template symbol for this declaration. | 234 Template symbol; /// The template symbol for this declaration. |
235 | |
236 mixin(copyMethod); | |
217 } | 237 } |
218 | 238 |
219 abstract class AggregateDeclaration : Declaration | 239 abstract class AggregateDeclaration : Declaration |
220 { | 240 { |
221 Identifier* name; | 241 Identifier* name; |
226 super.hasBody = decls !is null; | 246 super.hasBody = decls !is null; |
227 this.name = name; | 247 this.name = name; |
228 // this.tparams = tparams; | 248 // this.tparams = tparams; |
229 this.decls = decls; | 249 this.decls = decls; |
230 } | 250 } |
251 mixin(copyMethod); | |
231 } | 252 } |
232 | 253 |
233 class ClassDeclaration : AggregateDeclaration | 254 class ClassDeclaration : AggregateDeclaration |
234 { | 255 { |
235 BaseClassType[] bases; | 256 BaseClassType[] bases; |
243 | 264 |
244 this.bases = bases; | 265 this.bases = bases; |
245 } | 266 } |
246 | 267 |
247 Class symbol; /// The class symbol for this declaration. | 268 Class symbol; /// The class symbol for this declaration. |
269 | |
270 mixin(copyMethod); | |
248 } | 271 } |
249 | 272 |
250 class InterfaceDeclaration : AggregateDeclaration | 273 class InterfaceDeclaration : AggregateDeclaration |
251 { | 274 { |
252 BaseClassType[] bases; | 275 BaseClassType[] bases; |
262 } | 285 } |
263 | 286 |
264 alias dil.semantic.Symbols.Interface Interface; | 287 alias dil.semantic.Symbols.Interface Interface; |
265 | 288 |
266 Interface symbol; /// The interface symbol for this declaration. | 289 Interface symbol; /// The interface symbol for this declaration. |
290 | |
291 mixin(copyMethod); | |
267 } | 292 } |
268 | 293 |
269 class StructDeclaration : AggregateDeclaration | 294 class StructDeclaration : AggregateDeclaration |
270 { | 295 { |
271 uint alignSize; | 296 uint alignSize; |
281 { | 306 { |
282 this.alignSize = alignSize; | 307 this.alignSize = alignSize; |
283 } | 308 } |
284 | 309 |
285 Struct symbol; /// The struct symbol for this declaration. | 310 Struct symbol; /// The struct symbol for this declaration. |
311 | |
312 mixin(copyMethod); | |
286 } | 313 } |
287 | 314 |
288 class UnionDeclaration : AggregateDeclaration | 315 class UnionDeclaration : AggregateDeclaration |
289 { | 316 { |
290 this(Identifier* name, /+TemplateParameters tparams, +/CompoundDeclaration decls) | 317 this(Identifier* name, /+TemplateParameters tparams, +/CompoundDeclaration decls) |
294 // addChild(tparams); | 321 // addChild(tparams); |
295 addOptChild(decls); | 322 addOptChild(decls); |
296 } | 323 } |
297 | 324 |
298 Union symbol; /// The union symbol for this declaration. | 325 Union symbol; /// The union symbol for this declaration. |
326 | |
327 mixin(copyMethod); | |
299 } | 328 } |
300 | 329 |
301 class ConstructorDeclaration : Declaration | 330 class ConstructorDeclaration : Declaration |
302 { | 331 { |
303 Parameters params; | 332 Parameters params; |
310 addChild(funcBody); | 339 addChild(funcBody); |
311 | 340 |
312 this.params = params; | 341 this.params = params; |
313 this.funcBody = funcBody; | 342 this.funcBody = funcBody; |
314 } | 343 } |
344 mixin(copyMethod); | |
315 } | 345 } |
316 | 346 |
317 class StaticConstructorDeclaration : Declaration | 347 class StaticConstructorDeclaration : Declaration |
318 { | 348 { |
319 FuncBodyStatement funcBody; | 349 FuncBodyStatement funcBody; |
323 mixin(set_kind); | 353 mixin(set_kind); |
324 addChild(funcBody); | 354 addChild(funcBody); |
325 | 355 |
326 this.funcBody = funcBody; | 356 this.funcBody = funcBody; |
327 } | 357 } |
358 mixin(copyMethod); | |
328 } | 359 } |
329 | 360 |
330 class DestructorDeclaration : Declaration | 361 class DestructorDeclaration : Declaration |
331 { | 362 { |
332 FuncBodyStatement funcBody; | 363 FuncBodyStatement funcBody; |
336 mixin(set_kind); | 367 mixin(set_kind); |
337 addChild(funcBody); | 368 addChild(funcBody); |
338 | 369 |
339 this.funcBody = funcBody; | 370 this.funcBody = funcBody; |
340 } | 371 } |
372 mixin(copyMethod); | |
341 } | 373 } |
342 | 374 |
343 class StaticDestructorDeclaration : Declaration | 375 class StaticDestructorDeclaration : Declaration |
344 { | 376 { |
345 FuncBodyStatement funcBody; | 377 FuncBodyStatement funcBody; |
349 mixin(set_kind); | 381 mixin(set_kind); |
350 addChild(funcBody); | 382 addChild(funcBody); |
351 | 383 |
352 this.funcBody = funcBody; | 384 this.funcBody = funcBody; |
353 } | 385 } |
386 mixin(copyMethod); | |
354 } | 387 } |
355 | 388 |
356 class FunctionDeclaration : Declaration | 389 class FunctionDeclaration : Declaration |
357 { | 390 { |
358 TypeNode returnType; | 391 TypeNode returnType; |
386 bool isTemplatized() | 419 bool isTemplatized() |
387 { // E.g.: void func(T)(T t) | 420 { // E.g.: void func(T)(T t) |
388 // ^ params.begin.prevNWS | 421 // ^ params.begin.prevNWS |
389 return params.begin.prevNWS.kind == TOK.RParen; | 422 return params.begin.prevNWS.kind == TOK.RParen; |
390 } | 423 } |
424 | |
425 mixin(copyMethod); | |
391 } | 426 } |
392 | 427 |
393 /// VariablesDeclaration := Type? Identifier ("=" Init)? ("," Identifier ("=" Init)?)* ";" | 428 /// VariablesDeclaration := Type? Identifier ("=" Init)? ("," Identifier ("=" Init)?)* ";" |
394 class VariablesDeclaration : Declaration | 429 class VariablesDeclaration : Declaration |
395 { | 430 { |
418 { | 453 { |
419 this.linkageType = linkageType; | 454 this.linkageType = linkageType; |
420 } | 455 } |
421 | 456 |
422 Variable[] variables; | 457 Variable[] variables; |
458 | |
459 mixin(copyMethod); | |
423 } | 460 } |
424 | 461 |
425 class InvariantDeclaration : Declaration | 462 class InvariantDeclaration : Declaration |
426 { | 463 { |
427 FuncBodyStatement funcBody; | 464 FuncBodyStatement funcBody; |
431 mixin(set_kind); | 468 mixin(set_kind); |
432 addChild(funcBody); | 469 addChild(funcBody); |
433 | 470 |
434 this.funcBody = funcBody; | 471 this.funcBody = funcBody; |
435 } | 472 } |
473 mixin(copyMethod); | |
436 } | 474 } |
437 | 475 |
438 class UnittestDeclaration : Declaration | 476 class UnittestDeclaration : Declaration |
439 { | 477 { |
440 FuncBodyStatement funcBody; | 478 FuncBodyStatement funcBody; |
444 mixin(set_kind); | 482 mixin(set_kind); |
445 addChild(funcBody); | 483 addChild(funcBody); |
446 | 484 |
447 this.funcBody = funcBody; | 485 this.funcBody = funcBody; |
448 } | 486 } |
487 mixin(copyMethod); | |
449 } | 488 } |
450 | 489 |
451 abstract class ConditionalCompilationDeclaration : Declaration | 490 abstract class ConditionalCompilationDeclaration : Declaration |
452 { | 491 { |
453 Token* spec; | 492 Token* spec; |
485 this(Token* spec, Token* cond, Declaration decls, Declaration elseDecls) | 524 this(Token* spec, Token* cond, Declaration decls, Declaration elseDecls) |
486 { | 525 { |
487 super(spec, cond, decls, elseDecls); | 526 super(spec, cond, decls, elseDecls); |
488 mixin(set_kind); | 527 mixin(set_kind); |
489 } | 528 } |
529 mixin(copyMethod); | |
490 } | 530 } |
491 | 531 |
492 class VersionDeclaration : ConditionalCompilationDeclaration | 532 class VersionDeclaration : ConditionalCompilationDeclaration |
493 { | 533 { |
494 this(Token* spec, Token* cond, Declaration decls, Declaration elseDecls) | 534 this(Token* spec, Token* cond, Declaration decls, Declaration elseDecls) |
495 { | 535 { |
496 super(spec, cond, decls, elseDecls); | 536 super(spec, cond, decls, elseDecls); |
497 mixin(set_kind); | 537 mixin(set_kind); |
498 } | 538 } |
539 mixin(copyMethod); | |
499 } | 540 } |
500 | 541 |
501 class StaticIfDeclaration : Declaration | 542 class StaticIfDeclaration : Declaration |
502 { | 543 { |
503 Expression condition; | 544 Expression condition; |
512 | 553 |
513 this.condition = condition; | 554 this.condition = condition; |
514 this.ifDecls = ifDecls; | 555 this.ifDecls = ifDecls; |
515 this.elseDecls = elseDecls; | 556 this.elseDecls = elseDecls; |
516 } | 557 } |
558 mixin(copyMethod); | |
517 } | 559 } |
518 | 560 |
519 class StaticAssertDeclaration : Declaration | 561 class StaticAssertDeclaration : Declaration |
520 { | 562 { |
521 Expression condition, message; | 563 Expression condition, message; |
527 addOptChild(message); | 569 addOptChild(message); |
528 | 570 |
529 this.condition = condition; | 571 this.condition = condition; |
530 this.message = message; | 572 this.message = message; |
531 } | 573 } |
574 mixin(copyMethod); | |
532 } | 575 } |
533 | 576 |
534 class NewDeclaration : Declaration | 577 class NewDeclaration : Declaration |
535 { | 578 { |
536 Parameters params; | 579 Parameters params; |
543 addChild(funcBody); | 586 addChild(funcBody); |
544 | 587 |
545 this.params = params; | 588 this.params = params; |
546 this.funcBody = funcBody; | 589 this.funcBody = funcBody; |
547 } | 590 } |
591 mixin(copyMethod); | |
548 } | 592 } |
549 | 593 |
550 class DeleteDeclaration : Declaration | 594 class DeleteDeclaration : Declaration |
551 { | 595 { |
552 Parameters params; | 596 Parameters params; |
559 addChild(funcBody); | 603 addChild(funcBody); |
560 | 604 |
561 this.params = params; | 605 this.params = params; |
562 this.funcBody = funcBody; | 606 this.funcBody = funcBody; |
563 } | 607 } |
608 mixin(copyMethod); | |
564 } | 609 } |
565 | 610 |
566 abstract class AttributeDeclaration : Declaration | 611 abstract class AttributeDeclaration : Declaration |
567 { | 612 { |
568 Declaration decls; | 613 Declaration decls; |
581 { | 626 { |
582 super(decls); | 627 super(decls); |
583 mixin(set_kind); | 628 mixin(set_kind); |
584 this.prot = prot; | 629 this.prot = prot; |
585 } | 630 } |
631 mixin(copyMethod); | |
586 } | 632 } |
587 | 633 |
588 class StorageClassDeclaration : AttributeDeclaration | 634 class StorageClassDeclaration : AttributeDeclaration |
589 { | 635 { |
590 StorageClass storageClass; | 636 StorageClass storageClass; |
593 super(decl); | 639 super(decl); |
594 mixin(set_kind); | 640 mixin(set_kind); |
595 | 641 |
596 this.storageClass = storageClass; | 642 this.storageClass = storageClass; |
597 } | 643 } |
644 mixin(copyMethod); | |
598 } | 645 } |
599 | 646 |
600 class LinkageDeclaration : AttributeDeclaration | 647 class LinkageDeclaration : AttributeDeclaration |
601 { | 648 { |
602 LinkageType linkageType; | 649 LinkageType linkageType; |
605 super(decls); | 652 super(decls); |
606 mixin(set_kind); | 653 mixin(set_kind); |
607 | 654 |
608 this.linkageType = linkageType; | 655 this.linkageType = linkageType; |
609 } | 656 } |
657 mixin(copyMethod); | |
610 } | 658 } |
611 | 659 |
612 class AlignDeclaration : AttributeDeclaration | 660 class AlignDeclaration : AttributeDeclaration |
613 { | 661 { |
614 int size; | 662 int size; |
616 { | 664 { |
617 super(decls); | 665 super(decls); |
618 mixin(set_kind); | 666 mixin(set_kind); |
619 this.size = size; | 667 this.size = size; |
620 } | 668 } |
669 mixin(copyMethod); | |
621 } | 670 } |
622 | 671 |
623 class PragmaDeclaration : AttributeDeclaration | 672 class PragmaDeclaration : AttributeDeclaration |
624 { | 673 { |
625 Identifier* ident; | 674 Identifier* ident; |
631 mixin(set_kind); | 680 mixin(set_kind); |
632 | 681 |
633 this.ident = ident; | 682 this.ident = ident; |
634 this.args = args; | 683 this.args = args; |
635 } | 684 } |
685 mixin(copyMethod); | |
636 } | 686 } |
637 | 687 |
638 class MixinDeclaration : Declaration | 688 class MixinDeclaration : Declaration |
639 { | 689 { |
640 /// IdExpression := IdentifierExpression | TemplateInstanceExpression | 690 /// IdExpression := IdentifierExpression | TemplateInstanceExpression |
663 | 713 |
664 bool isMixinExpression() | 714 bool isMixinExpression() |
665 { | 715 { |
666 return argument !is null; | 716 return argument !is null; |
667 } | 717 } |
668 } | 718 |
719 mixin(copyMethod); | |
720 } |