comparison trunk/src/dil/Expressions.d @ 489:a7291d3ee9d7

Refactored classes that inherit from Node. Added methods addChild(), addOptChild(), addChildren(), addOptChildren() to class Node. Refactored subclasses to use the new methods instead of appending directly to the array Node.children. Moved enums StorageClass and Protection to new module dil.Enums. Added members stc, prot, isStatic() and isPulic() to Declaration.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Mon, 03 Dec 2007 22:44:27 +0100
parents cfb3805768b6
children 47be6bfe39cd
comparison
equal deleted inserted replaced
488:cfb3805768b6 489:a7291d3ee9d7
29 { 29 {
30 Expression left, right; 30 Expression left, right;
31 Token* tok; 31 Token* tok;
32 this(Expression left, Expression right, Token* tok) 32 this(Expression left, Expression right, Token* tok)
33 { 33 {
34 this.children = [left, right]; 34 addChildren([left, right]);
35 this.left = left; 35 this.left = left;
36 this.right = right; 36 this.right = right;
37 this.tok = tok; 37 this.tok = tok;
38 } 38 }
39 } 39 }
43 Expression condition; 43 Expression condition;
44 this(Expression condition, Expression left, Expression right, Token* tok) 44 this(Expression condition, Expression left, Expression right, Token* tok)
45 { 45 {
46 super(left, right, tok); 46 super(left, right, tok);
47 mixin(set_kind); 47 mixin(set_kind);
48 this.children ~= [condition]; 48 addChild(condition);
49 this.condition = condition; 49 this.condition = condition;
50 } 50 }
51 } 51 }
52 52
53 class CommaExpression : BinaryExpression 53 class CommaExpression : BinaryExpression
337 abstract class UnaryExpression : Expression 337 abstract class UnaryExpression : Expression
338 { 338 {
339 Expression e; 339 Expression e;
340 this(Expression e) 340 this(Expression e)
341 { 341 {
342 this.children ~= e; 342 addChild(e);
343 this.e = e; 343 this.e = e;
344 } 344 }
345 } 345 }
346 346
347 class AddressExpression : UnaryExpression 347 class AddressExpression : UnaryExpression
453 DotListExpression dotList; 453 DotListExpression dotList;
454 this(Expression e, DotListExpression dotList) 454 this(Expression e, DotListExpression dotList)
455 { 455 {
456 super(e); 456 super(e);
457 mixin(set_kind); 457 mixin(set_kind);
458 this.children ~= [dotList]; 458 addChild(dotList);
459 this.dotList = dotList; 459 this.dotList = dotList;
460 } 460 }
461 } 461 }
462 462
463 class CallExpression : UnaryExpression 463 class CallExpression : UnaryExpression
465 Expression[] args; 465 Expression[] args;
466 this(Expression e, Expression[] args) 466 this(Expression e, Expression[] args)
467 { 467 {
468 super(e); 468 super(e);
469 mixin(set_kind); 469 mixin(set_kind);
470 this.children ~= args; 470 addOptChildren(args);
471 this.args = args; 471 this.args = args;
472 } 472 }
473 } 473 }
474 474
475 class NewExpression : /*Unary*/Expression 475 class NewExpression : /*Unary*/Expression
479 Expression[] ctorArgs; 479 Expression[] ctorArgs;
480 this(/*Expression e, */Expression[] newArgs, Type type, Expression[] ctorArgs) 480 this(/*Expression e, */Expression[] newArgs, Type type, Expression[] ctorArgs)
481 { 481 {
482 /*super(e);*/ 482 /*super(e);*/
483 mixin(set_kind); 483 mixin(set_kind);
484 if (newArgs.length) 484 addOptChildren(newArgs);
485 this.children ~= newArgs; 485 addChild(type);
486 this.children ~= type; 486 addOptChildren(ctorArgs);
487 if (ctorArgs.length)
488 this.children ~= ctorArgs;
489 this.newArgs = newArgs; 487 this.newArgs = newArgs;
490 this.type = type; 488 this.type = type;
491 this.ctorArgs = ctorArgs; 489 this.ctorArgs = ctorArgs;
492 } 490 }
493 } 491 }
500 Declarations decls; 498 Declarations decls;
501 this(/*Expression e, */Expression[] newArgs, BaseClass[] bases, Expression[] ctorArgs, Declarations decls) 499 this(/*Expression e, */Expression[] newArgs, BaseClass[] bases, Expression[] ctorArgs, Declarations decls)
502 { 500 {
503 /*super(e);*/ 501 /*super(e);*/
504 mixin(set_kind); 502 mixin(set_kind);
505 if (newArgs.length) 503 addOptChildren(newArgs);
506 this.children ~= newArgs; 504 addOptChildren(bases);
507 if (bases.length) 505 addOptChildren(ctorArgs);
508 this.children ~= bases; 506 addChild(decls);
509 if (ctorArgs.length)
510 this.children ~= ctorArgs;
511 this.children ~= decls;
512 507
513 this.newArgs = newArgs; 508 this.newArgs = newArgs;
514 this.bases = bases; 509 this.bases = bases;
515 this.ctorArgs = ctorArgs; 510 this.ctorArgs = ctorArgs;
516 this.decls = decls; 511 this.decls = decls;
529 class CastExpression : UnaryExpression 524 class CastExpression : UnaryExpression
530 { 525 {
531 Type type; 526 Type type;
532 this(Expression e, Type type) 527 this(Expression e, Type type)
533 { 528 {
534 this.children = [type]; 529 addChild(type); // Add type before super().
535 super(e); 530 super(e);
536 mixin(set_kind); 531 mixin(set_kind);
537 this.type = type; 532 this.type = type;
538 } 533 }
539 } 534 }
543 Expression[] args; 538 Expression[] args;
544 this(Expression e, Expression[] args) 539 this(Expression e, Expression[] args)
545 { 540 {
546 super(e); 541 super(e);
547 mixin(set_kind); 542 mixin(set_kind);
548 this.children ~= args; 543 addChildren(args);
549 this.args = args; 544 this.args = args;
550 } 545 }
551 } 546 }
552 547
553 class SliceExpression : UnaryExpression 548 class SliceExpression : UnaryExpression
555 Expression left, right; 550 Expression left, right;
556 this(Expression e, Expression left, Expression right) 551 this(Expression e, Expression left, Expression right)
557 { 552 {
558 super(e); 553 super(e);
559 mixin(set_kind); 554 mixin(set_kind);
555 assert(left ? (right !is null) : right is null);
560 if (left) 556 if (left)
561 this.children ~= left; 557 addChildren([left, right]);
562 if (right)
563 this.children ~= right;
564 558
565 this.left = left; 559 this.left = left;
566 this.right = right; 560 this.right = right;
567 } 561 }
568 } 562 }
617 { 611 {
618 Expression[] items; 612 Expression[] items;
619 this(Expression[] items) 613 this(Expression[] items)
620 { 614 {
621 mixin(set_kind); 615 mixin(set_kind);
622 this.children = items; 616 addChildren(items);
623 this.items = items; 617 this.items = items;
624 } 618 }
625 } 619 }
626 620
627 class TemplateInstanceExpression : Expression 621 class TemplateInstanceExpression : Expression
629 Token* ident; 623 Token* ident;
630 TemplateArguments targs; 624 TemplateArguments targs;
631 this(Token* ident, TemplateArguments targs) 625 this(Token* ident, TemplateArguments targs)
632 { 626 {
633 mixin(set_kind); 627 mixin(set_kind);
634 if (targs) 628 addOptChild(targs);
635 this.children = [targs];
636 this.ident = ident; 629 this.ident = ident;
637 this.targs = targs; 630 this.targs = targs;
638 } 631 }
639 } 632 }
640 633
736 { 729 {
737 Expression[] values; 730 Expression[] values;
738 this(Expression[] values) 731 this(Expression[] values)
739 { 732 {
740 mixin(set_kind); 733 mixin(set_kind);
741 this.children = values; 734 addOptChildren(values);
742 this.values = values; 735 this.values = values;
743 } 736 }
744 } 737 }
745 738
746 class AArrayLiteralExpression : Expression 739 class AArrayLiteralExpression : Expression
749 this(Expression[] keys, Expression[] values) 742 this(Expression[] keys, Expression[] values)
750 { 743 {
751 assert(keys.length == values.length); 744 assert(keys.length == values.length);
752 mixin(set_kind); 745 mixin(set_kind);
753 foreach (i, key; keys) 746 foreach (i, key; keys)
754 this.children ~= [key, values[i]]; 747 addChildren([key, values[i]]);
755 this.keys = keys; 748 this.keys = keys;
756 this.values = values; 749 this.values = values;
757 } 750 }
758 } 751 }
759 752
761 { 754 {
762 Expression expr, msg; 755 Expression expr, msg;
763 this(Expression expr, Expression msg) 756 this(Expression expr, Expression msg)
764 { 757 {
765 mixin(set_kind); 758 mixin(set_kind);
766 this.children = [expr]; 759 addChild(expr);
767 if (msg) 760 addOptChild(msg);
768 this.children ~= msg;
769 this.expr = expr; 761 this.expr = expr;
770 this.msg = msg; 762 this.msg = msg;
771 } 763 }
772 } 764 }
773 765
775 { 767 {
776 Expression expr; 768 Expression expr;
777 this(Expression expr) 769 this(Expression expr)
778 { 770 {
779 mixin(set_kind); 771 mixin(set_kind);
780 this.children = [expr]; 772 addChild(expr);
781 this.expr = expr; 773 this.expr = expr;
782 } 774 }
783 } 775 }
784 776
785 class ImportExpression : Expression 777 class ImportExpression : Expression
786 { 778 {
787 Expression expr; 779 Expression expr;
788 this(Expression expr) 780 this(Expression expr)
789 { 781 {
790 mixin(set_kind); 782 mixin(set_kind);
791 this.children = [expr]; 783 addChild(expr);
792 this.expr = expr; 784 this.expr = expr;
793 } 785 }
794 } 786 }
795 787
796 class TypeofExpression : Expression 788 class TypeofExpression : Expression
797 { 789 {
798 Type type; 790 Type type;
799 this(Type type) 791 this(Type type)
800 { 792 {
801 mixin(set_kind); 793 mixin(set_kind);
802 this.children = [type]; 794 addChild(type);
803 this.type = type; 795 this.type = type;
804 } 796 }
805 } 797 }
806 798
807 class TypeDotIdExpression : Expression 799 class TypeDotIdExpression : Expression
809 Type type; 801 Type type;
810 Token* ident; 802 Token* ident;
811 this(Type type, Token* ident) 803 this(Type type, Token* ident)
812 { 804 {
813 mixin(set_kind); 805 mixin(set_kind);
814 this.children = [type]; 806 addChild(type);
815 this.type = type; 807 this.type = type;
816 this.ident = ident; 808 this.ident = ident;
817 } 809 }
818 } 810 }
819 811
821 { 813 {
822 Type type; 814 Type type;
823 this(Type type) 815 this(Type type)
824 { 816 {
825 mixin(set_kind); 817 mixin(set_kind);
826 this.children = [type]; 818 addChild(type);
827 this.type = type; 819 this.type = type;
828 } 820 }
829 } 821 }
830 822
831 class IsExpression : Expression 823 class IsExpression : Expression
836 Type specType; 828 Type specType;
837 TemplateParameters tparams; // D 2.0 829 TemplateParameters tparams; // D 2.0
838 this(Type type, Token* ident, Token* opTok, Token* specTok, Type specType, typeof(tparams) tparams) 830 this(Type type, Token* ident, Token* opTok, Token* specTok, Type specType, typeof(tparams) tparams)
839 { 831 {
840 mixin(set_kind); 832 mixin(set_kind);
841 this.children = [type]; 833 addChild(type);
842 if (specType) 834 addOptChild(specType);
843 this.children ~= specType; 835 version(D2)
844 if (tparams) 836 addOptChild(tparams);
845 this.children ~= tparams;
846 this.type = type; 837 this.type = type;
847 this.ident = ident; 838 this.ident = ident;
848 this.opTok = opTok; 839 this.opTok = opTok;
849 this.specTok = specTok; 840 this.specTok = specTok;
850 this.specType = specType; 841 this.specType = specType;
859 FunctionBody funcBody; 850 FunctionBody funcBody;
860 851
861 this() 852 this()
862 { 853 {
863 mixin(set_kind); 854 mixin(set_kind);
864 if (returnType) 855 addOptChild(returnType);
865 this.children ~= returnType; 856 addOptChild(parameters);
866 if (parameters) 857 addChild(funcBody);
867 this.children ~= parameters;
868 this.children ~= funcBody;
869 } 858 }
870 859
871 this(Type returnType, Parameters parameters, FunctionBody funcBody) 860 this(Type returnType, Parameters parameters, FunctionBody funcBody)
872 { 861 {
873 this.returnType = returnType; 862 this.returnType = returnType;
890 Token* ident; 879 Token* ident;
891 TemplateArguments targs; 880 TemplateArguments targs;
892 this(typeof(ident) ident, typeof(targs) targs) 881 this(typeof(ident) ident, typeof(targs) targs)
893 { 882 {
894 mixin(set_kind); 883 mixin(set_kind);
895 if (targs) 884 addOptChild(targs);
896 this.children = [targs];
897 this.ident = ident; 885 this.ident = ident;
898 this.targs = targs; 886 this.targs = targs;
899 } 887 }
900 } 888 }
901 } 889 }
916 { 904 {
917 assert(keys.length == values.length); 905 assert(keys.length == values.length);
918 mixin(set_kind); 906 mixin(set_kind);
919 foreach (i, key; keys) 907 foreach (i, key; keys)
920 { 908 {
921 if (key) 909 addOptChild(key); // The key is optional in ArrayInitializers.
922 this.children ~= key; 910 addChild(values[i]);
923 if (values[i])
924 this.children ~= values[i];
925 } 911 }
926 this.keys = keys; 912 this.keys = keys;
927 this.values = values; 913 this.values = values;
928 } 914 }
929 } 915 }
933 Token*[] idents; 919 Token*[] idents;
934 Expression[] values; 920 Expression[] values;
935 this(Token*[] idents, Expression[] values) 921 this(Token*[] idents, Expression[] values)
936 { 922 {
937 mixin(set_kind); 923 mixin(set_kind);
938 this.children = values; 924 addOptChildren(values);
939 this.idents = idents; 925 this.idents = idents;
940 this.values = values; 926 this.values = values;
941 } 927 }
942 } 928 }
943 929
981 { 967 {
982 Expression e; 968 Expression e;
983 this(Expression e) 969 this(Expression e)
984 { 970 {
985 mixin(set_kind); 971 mixin(set_kind);
986 this.children = [e]; 972 addChild(e);
987 this.e = e; 973 this.e = e;
988 } 974 }
989 } 975 }
990 976
991 class AsmLocalSizeExpression : Expression 977 class AsmLocalSizeExpression : Expression