comparison dmd/CallExp.d @ 96:acd69f84627e

further work
author Trass3r
date Tue, 31 Aug 2010 02:12:15 +0200
parents 39648eb578f6
children ceda59b4d255
comparison
equal deleted inserted replaced
95:ae5b11064a9a 96:acd69f84627e
92 this(Loc loc, Expression e, Expression earg1) 92 this(Loc loc, Expression e, Expression earg1)
93 { 93 {
94 super(loc, TOK.TOKcall, CallExp.sizeof, e); 94 super(loc, TOK.TOKcall, CallExp.sizeof, e);
95 95
96 auto arguments = new Expressions(); 96 auto arguments = new Expressions();
97 if (earg1) 97 if (earg1)
98 { 98 {
99 arguments.setDim(1); 99 arguments.setDim(1);
100 arguments[0] = earg1; 100 arguments[0] = earg1;
101 } 101 }
102 this.arguments = arguments; 102 this.arguments = arguments;
776 return this; 776 return this;
777 } 777 }
778 778
779 override Expression optimize(int result) 779 override Expression optimize(int result)
780 { 780 {
781 //printf("CallExp::optimize(result = %d) %s\n", result, toChars()); 781 // writef("CallExp::optimize(result = %d) %s\n", result, toChars());
782 Expression e = this; 782 Expression e = this;
783 783
784 // Optimize parameters 784 // Optimize parameters
785 if (arguments) 785 if (arguments)
786 { 786 {
809 if (eresult && eresult !is EXP_VOID_INTERPRET) 809 if (eresult && eresult !is EXP_VOID_INTERPRET)
810 e = eresult; 810 e = eresult;
811 else 811 else
812 error("cannot evaluate %s at compile time", toChars()); 812 error("cannot evaluate %s at compile time", toChars());
813 } 813 }
814 }
815 }
816 else if (e1.op == TOKdotvar && result & WANTinterpret)
817 {
818 DotVarExp dve = cast(DotVarExp) e1;
819 FuncDeclaration fd = dve.var.isFuncDeclaration();
820 if (fd)
821 {
822 Expression eresult = fd.interpret(null, arguments, dve.e1);
823 if (eresult && eresult != EXP_VOID_INTERPRET)
824 e = eresult;
825 else
826 error("cannot evaluate %s at compile time", toChars());
814 } 827 }
815 } 828 }
816 829
817 return e; 830 return e;
818 } 831 }
831 TypeFunction tf = fd ? cast(TypeFunction)fd.type : null; 844 TypeFunction tf = fd ? cast(TypeFunction)fd.type : null;
832 if (tf) 845 if (tf)
833 { 846 {
834 // Member function call 847 // Member function call
835 if(pthis.op == TOKthis) 848 if(pthis.op == TOKthis)
836 pthis = istate.localThis; 849 pthis = istate.localThis;
837 Expression eresult = fd.interpret(istate, arguments, pthis); 850 Expression eresult = fd.interpret(istate, arguments, pthis);
838 if (eresult) 851 if (eresult)
839 e = eresult; 852 e = eresult;
840 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors) 853 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors)
841 e = EXP_VOID_INTERPRET; 854 e = EXP_VOID_INTERPRET;
1032 } 1045 }
1033 1046
1034 version (DMDV2) { 1047 version (DMDV2) {
1035 override int isLvalue() 1048 override int isLvalue()
1036 { 1049 {
1037 // if (type.toBasetype().ty == Tstruct) 1050 // if (type.toBasetype().ty == Tstruct)
1038 // return 1; 1051 // return 1;
1039 Type tb = e1.type.toBasetype(); 1052 Type tb = e1.type.toBasetype();
1040 if (tb.ty == Tfunction && (cast(TypeFunction)tb).isref) 1053 if (tb.ty == Tfunction && (cast(TypeFunction)tb).isref)
1041 return 1; // function returns a reference 1054 return 1; // function returns a reference
1042 return 0; 1055 return 0;