Mercurial > projects > dil
comparison trunk/src/dil/ast/Expressions.d @ 645:89ee7802c978
Moved semantic() methods of expressions to class SemanticPass1.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 14 Jan 2008 16:01:21 +0100 |
parents | b2fc028d8b55 |
children | 68953760d569 |
comparison
equal
deleted
inserted
replaced
644:a0643a4d4501 | 645:89ee7802c978 |
---|---|
34 addChildren([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 | |
40 override Expression semantic(Scope scop) | |
41 { | |
42 left = left.semantic(scop); | |
43 right = right.semantic(scop); | |
44 return this; | |
45 } | |
46 } | 39 } |
47 | 40 |
48 class CondExpression : BinaryExpression | 41 class CondExpression : BinaryExpression |
49 { | 42 { |
50 Expression condition; | 43 Expression condition; |
581 { | 574 { |
582 mixin(set_kind); | 575 mixin(set_kind); |
583 this.specialToken = specialToken; | 576 this.specialToken = specialToken; |
584 } | 577 } |
585 | 578 |
586 Expression e; /// The expression created in the semantic phase. | 579 Expression value; /// The expression created in the semantic phase. |
587 | |
588 override Expression semantic(Scope) | |
589 { | |
590 if (type) | |
591 return e; | |
592 switch (specialToken.type) | |
593 { | |
594 case TOK.LINE, TOK.VERSION: | |
595 e = new IntExpression(specialToken.uint_, Types.Uint); | |
596 break; | |
597 case TOK.FILE, TOK.DATE, TOK.TIME, TOK.TIMESTAMP, TOK.VENDOR: | |
598 e = new StringExpression(specialToken.str); | |
599 break; | |
600 default: | |
601 assert(0); | |
602 } | |
603 type = e.type; | |
604 return e; | |
605 } | |
606 } | 580 } |
607 | 581 |
608 class TemplateInstanceExpression : Expression | 582 class TemplateInstanceExpression : Expression |
609 { | 583 { |
610 Identifier* ident; | 584 Identifier* ident; |
644 this(Type type) | 618 this(Type type) |
645 { | 619 { |
646 this(); | 620 this(); |
647 this.type = type; | 621 this.type = type; |
648 } | 622 } |
649 | |
650 override Expression semantic(Scope) | |
651 { | |
652 if (!type) | |
653 type = Types.Void_ptr; | |
654 return this; | |
655 } | |
656 } | 623 } |
657 | 624 |
658 class DollarExpression : Expression | 625 class DollarExpression : Expression |
659 { | 626 { |
660 this() | 627 this() |
661 { | 628 { |
662 mixin(set_kind); | 629 mixin(set_kind); |
663 } | 630 } |
664 | |
665 override Expression semantic(Scope scop) | |
666 { | |
667 if (type) | |
668 return this; | |
669 type = Types.Size_t; | |
670 // if (!scop.inArraySubscript) | |
671 // error(scop, "$ can only be in an array subscript."); | |
672 return this; | |
673 } | |
674 } | 631 } |
675 | 632 |
676 class BoolExpression : Expression | 633 class BoolExpression : Expression |
677 { | 634 { |
678 this() | 635 this() |
679 { | 636 { |
680 mixin(set_kind); | 637 mixin(set_kind); |
681 } | 638 } |
682 | 639 |
683 Expression e; | 640 Expression value; /// IntExpression of type int. |
684 override Expression semantic(Scope scop) | |
685 { | |
686 if (type) | |
687 return this; | |
688 assert(this.begin !is null); | |
689 auto b = (this.begin.type == TOK.True) ? true : false; | |
690 e = new IntExpression(b, Types.Bool); | |
691 type = Types.Bool; | |
692 return this; | |
693 } | |
694 } | 641 } |
695 | 642 |
696 class IntExpression : Expression | 643 class IntExpression : Expression |
697 { | 644 { |
698 ulong number; | 645 ulong number; |
719 type = Types.Ulong; break; | 666 type = Types.Ulong; break; |
720 default: | 667 default: |
721 assert(token.type == TOK.Int32); | 668 assert(token.type == TOK.Int32); |
722 } | 669 } |
723 this(token.ulong_, type); | 670 this(token.ulong_, type); |
724 } | |
725 | |
726 override Expression semantic(Scope) | |
727 { | |
728 if (type) | |
729 return this; | |
730 | |
731 if (number & 0x8000_0000_0000_0000) | |
732 type = Types.Ulong; // 0xFFFF_FFFF_FFFF_FFFF | |
733 else if (number & 0xFFFF_FFFF_0000_0000) | |
734 type = Types.Long; // 0x7FFF_FFFF_FFFF_FFFF | |
735 else if (number & 0x8000_0000) | |
736 type = Types.Uint; // 0xFFFF_FFFF | |
737 else | |
738 type = Types.Int; // 0x7FFF_FFFF | |
739 return this; | |
740 } | 671 } |
741 } | 672 } |
742 | 673 |
743 class RealExpression : Expression | 674 class RealExpression : Expression |
744 { | 675 { |
771 default: | 702 default: |
772 assert(token.type == TOK.Float64); | 703 assert(token.type == TOK.Float64); |
773 } | 704 } |
774 this(token.real_, type); | 705 this(token.real_, type); |
775 } | 706 } |
776 | |
777 override Expression semantic(Scope) | |
778 { | |
779 if (type) | |
780 return this; | |
781 type = Types.Double; | |
782 return this; | |
783 } | |
784 } | 707 } |
785 | 708 |
786 /++ | 709 /++ |
787 This expression holds a complex number. | 710 This expression holds a complex number. |
788 It is only created in the semantic phase. | 711 It is only created in the semantic phase. |
795 { | 718 { |
796 mixin(set_kind); | 719 mixin(set_kind); |
797 this.number = number; | 720 this.number = number; |
798 this.type = type; | 721 this.type = type; |
799 } | 722 } |
800 | |
801 override Expression semantic(Scope) | |
802 { | |
803 if (type) | |
804 return this; | |
805 type = Types.Cdouble; | |
806 return this; | |
807 } | |
808 } | 723 } |
809 | 724 |
810 class CharExpression : Expression | 725 class CharExpression : Expression |
811 { | 726 { |
812 dchar character; | 727 dchar character; |
813 this(dchar character) | 728 this(dchar character) |
814 { | 729 { |
815 mixin(set_kind); | 730 mixin(set_kind); |
816 this.character = character; | 731 this.character = character; |
817 } | |
818 | |
819 override Expression semantic(Scope scop) | |
820 { | |
821 if (type) | |
822 return this; | |
823 if (character <= 0xFF) | |
824 type = Types.Char; | |
825 else if (character <= 0xFFFF) | |
826 type = Types.Wchar; | |
827 else | |
828 type = Types.Dchar; | |
829 return this; | |
830 } | 732 } |
831 } | 733 } |
832 | 734 |
833 class StringExpression : Expression | 735 class StringExpression : Expression |
834 { | 736 { |
865 this(dchar[] str) | 767 this(dchar[] str) |
866 { | 768 { |
867 this(cast(ubyte[])str, Types.Dchar); | 769 this(cast(ubyte[])str, Types.Dchar); |
868 } | 770 } |
869 | 771 |
870 override Expression semantic(Scope scop) | |
871 { | |
872 if (type) | |
873 return this; | |
874 return this; | |
875 } | |
876 | |
877 char[] getString() | 772 char[] getString() |
878 { | 773 { |
879 char[] buffer; | 774 char[] buffer; |
880 foreach (token; stringTokens) | 775 foreach (token; stringTokens) |
881 buffer ~= token.str[0..$-1]; | 776 buffer ~= token.str[0..$-1]; |
927 this(Expression expr) | 822 this(Expression expr) |
928 { | 823 { |
929 mixin(set_kind); | 824 mixin(set_kind); |
930 addChild(expr); | 825 addChild(expr); |
931 this.expr = expr; | 826 this.expr = expr; |
932 } | |
933 | |
934 override Expression semantic(Scope scop) | |
935 { | |
936 if (type) | |
937 return this.expr; | |
938 // TODO: | |
939 auto expr = this.expr.semantic(scop); | |
940 expr = expr.evaluate(); | |
941 if (expr is null) | |
942 return this; | |
943 auto strExpr = TryCast!(StringExpression)(expr); | |
944 if (strExpr is null) | |
945 error(scop, MSG.MixinArgumentMustBeString); | |
946 else | |
947 { | |
948 auto loc = this.begin.getLocation(); | |
949 auto filePath = loc.filePath; | |
950 auto parser = new_ExpressionParser(strExpr.getString(), filePath, scop.infoMan); | |
951 expr = parser.parse(); | |
952 expr = expr.semantic(scop); | |
953 } | |
954 this.expr = expr; | |
955 this.type = expr.type; | |
956 return expr; | |
957 } | 827 } |
958 } | 828 } |
959 | 829 |
960 class ImportExpression : Expression | 830 class ImportExpression : Expression |
961 { | 831 { |