comparison trunk/src/dil/Expressions.d @ 537:db7913148b29

Added constructors and semantic() methods.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 18 Dec 2007 21:23:52 +0100
parents 0781ac288537
children 3418027c3914
comparison
equal deleted inserted replaced
536:0781ac288537 537:db7913148b29
604 } 604 }
605 } 605 }
606 606
607 class SpecialTokenExpression : Expression 607 class SpecialTokenExpression : Expression
608 { 608 {
609 Token* special; 609 Token* specialToken;
610 this(Token* special) 610 this(Token* specialToken)
611 { 611 {
612 mixin(set_kind); 612 mixin(set_kind);
613 this.special = special; 613 this.specialToken = specialToken;
614 }
615
616 Expression e; /// The expression created in the semantic phase.
617
618 Expression semantic(Scope)
619 {
620 if (type)
621 return e;
622 switch (specialToken.type)
623 {
624 case TOK.LINE, TOK.VERSION:
625 e = new IntExpression(specialToken.uint_, Types.Uint);
626 break;
627 case TOK.FILE, TOK.DATE, TOK.TIME, TOK.TIMESTAMP, TOK.VENDOR:
628 e = new StringExpression(specialToken.str);
629 break;
630 default:
631 assert(0);
632 }
633 type = e.type;
634 return e;
614 } 635 }
615 } 636 }
616 637
617 /* 638 /*
618 class IdentifierListExpression : Expression 639 class IdentifierListExpression : Expression
697 } 718 }
698 } 719 }
699 720
700 class IntExpression : Expression 721 class IntExpression : Expression
701 { 722 {
702 TOK type;
703 ulong number; 723 ulong number;
704 this(TOK type, ulong number) 724
725 this(ulong number, Type type)
705 { 726 {
706 mixin(set_kind); 727 mixin(set_kind);
707 this.number = number; 728 this.number = number;
708 this.type = type; 729 this.type = type;
730 }
731
732 this(Token* token)
733 {
734 auto type = Types.Int; // Should be most common case.
735 switch (token.type)
736 {
737 // case TOK.Int32:
738 // type = Types.Int; break;
739 case TOK.Uint32:
740 type = Types.Uint; break;
741 case TOK.Int64:
742 type = Types.Long; break;
743 case TOK.Uint64:
744 type = Types.Ulong; break;
745 default:
746 assert(token.type == TOK.Int32);
747 }
748 this(token.ulong_, type);
749 }
750
751 Expression semantic(Scope scop)
752 {
753 if (type)
754 return this;
755 return this;
709 } 756 }
710 } 757 }
711 758
712 class RealExpression : Expression 759 class RealExpression : Expression
713 { 760 {
744 } 791 }
745 } 792 }
746 793
747 class StringExpression : Expression 794 class StringExpression : Expression
748 { 795 {
749 Token*[] strings; 796 Token*[] stringTokens;
750 this(Token*[] strings) 797 this()
751 { 798 { mixin(set_kind); }
752 mixin(set_kind); 799
753 this.strings = strings; 800 /// Constructor used in parsing phase.
801 this(Token*[] stringTokens)
802 {
803 this.stringTokens = stringTokens;
804 }
805
806 ubyte[] str; /// The string data.
807 Type charType; /// The character type of the string.
808 // Constructors used in semantic phase.
809 this(ubyte[] str, Type charType)
810 {
811 this();
812 this.str = str;
813 this.charType = charType;
814 type = new TypeSArray(charType, str.length);
815 }
816
817 this(char[] str)
818 {
819 this(cast(ubyte[])str, Types.Char);
820 }
821 this(wchar[] str)
822 {
823 this(cast(ubyte[])str, Types.Wchar);
824 }
825 this(dchar[] str)
826 {
827 this(cast(ubyte[])str, Types.Dchar);
828 }
829
830 Expression semantic()
831 {
832 if (type)
833 return this;
754 } 834 }
755 835
756 char[] getString() 836 char[] getString()
757 { 837 {
758 char[] buffer; 838 char[] buffer;
759 foreach (strTok; strings) 839 foreach (token; stringTokens)
760 { 840 buffer ~= token.str[0..$-1];
761 buffer ~= strTok.str[0..$-1];
762 }
763 return buffer; 841 return buffer;
764 } 842 }
765 } 843 }
766 844
767 class ArrayLiteralExpression : Expression 845 class ArrayLiteralExpression : Expression