Mercurial > projects > ddmd
comparison dmd/CallExp.d @ 63:cab4c37afb89
A bunch of implementations
author | korDen |
---|---|
date | Mon, 23 Aug 2010 16:52:24 +0400 |
parents | 10317f0c89a5 |
children | 4290d870944a |
comparison
equal
deleted
inserted
replaced
62:6557375aff35 | 63:cab4c37afb89 |
---|---|
1 module dmd.CallExp; | 1 module dmd.CallExp; |
2 | 2 |
3 import dmd.Expression; | 3 import dmd.Expression; |
4 import dmd.Cast; | |
4 import dmd.WANT; | 5 import dmd.WANT; |
5 import dmd.BUILTIN; | 6 import dmd.BUILTIN; |
6 import dmd.TypeFunction; | 7 import dmd.TypeFunction; |
7 import dmd.ScopeDsymbol; | 8 import dmd.ScopeDsymbol; |
8 import dmd.CastExp; | 9 import dmd.CastExp; |
68 import dmd.backend.TYPE; | 69 import dmd.backend.TYPE; |
69 import dmd.backend.Util; | 70 import dmd.backend.Util; |
70 import dmd.backend.TYM; | 71 import dmd.backend.TYM; |
71 import dmd.codegen.Util; | 72 import dmd.codegen.Util; |
72 | 73 |
74 import std.stdio; | |
75 | |
73 class CallExp : UnaExp | 76 class CallExp : UnaExp |
74 { | 77 { |
75 Expressions arguments; | 78 Expressions arguments; |
76 | 79 |
77 this(Loc loc, Expression e, Expressions exps) | 80 this(Loc loc, Expression e, Expressions exps) |
805 } | 808 } |
806 | 809 |
807 return e; | 810 return e; |
808 } | 811 } |
809 | 812 |
810 Expression interpret(InterState* istate) | 813 Expression interpret(InterState istate) |
811 { | 814 { |
812 assert(false); | 815 Expression e = EXP_CANT_INTERPRET; |
816 | |
817 version (LOG) { | |
818 printf("CallExp.interpret() %.*s\n", toChars()); | |
819 } | |
820 if (e1.op == TOKdotvar) | |
821 { | |
822 Expression pthis = (cast(DotVarExp)e1).e1; | |
823 FuncDeclaration fd = (cast(DotVarExp)e1).var.isFuncDeclaration(); | |
824 TypeFunction tf = fd ? cast(TypeFunction)fd.type : null; | |
825 if (tf) | |
826 { | |
827 // Member function call | |
828 if(pthis.op == TOKthis) | |
829 pthis = istate.localThis; | |
830 Expression eresult = fd.interpret(istate, arguments, pthis); | |
831 if (eresult) | |
832 e = eresult; | |
833 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors) | |
834 e = EXP_VOID_INTERPRET; | |
835 else | |
836 error("cannot evaluate %s at compile time", toChars()); | |
837 return e; | |
838 } | |
839 error("cannot evaluate %s at compile time", toChars()); | |
840 return EXP_CANT_INTERPRET; | |
841 } | |
842 if (e1.op == TOKvar) | |
843 { | |
844 FuncDeclaration fd = (cast(VarExp)e1).var.isFuncDeclaration(); | |
845 if (fd) | |
846 { | |
847 ///version (DMDV2) { | |
848 BUILTIN b = fd.isBuiltin(); | |
849 if (b) | |
850 { | |
851 scope Expressions args = new Expressions(); | |
852 args.setDim(arguments.dim); | |
853 for (size_t i = 0; i < args.dim; i++) | |
854 { | |
855 Expression earg = cast(Expression)arguments.data[i]; | |
856 earg = earg.interpret(istate); | |
857 if (earg == EXP_CANT_INTERPRET) | |
858 return earg; | |
859 args.data[i] = cast(void*)earg; | |
860 } | |
861 e = eval_builtin(b, args); | |
862 if (!e) | |
863 e = EXP_CANT_INTERPRET; | |
864 } | |
865 else | |
866 ///} | |
867 // Inline .dup | |
868 if (fd.ident == Id.adDup && arguments && arguments.dim == 2) | |
869 { | |
870 e = cast(Expression)arguments.data[1]; | |
871 e = e.interpret(istate); | |
872 if (e !is EXP_CANT_INTERPRET) | |
873 { | |
874 e = expType(type, e); | |
875 } | |
876 } | |
877 else | |
878 { | |
879 Expression eresult = fd.interpret(istate, arguments); | |
880 if (eresult) | |
881 e = eresult; | |
882 else if (fd.type.toBasetype().nextOf().ty == Tvoid && !global.errors) | |
883 e = EXP_VOID_INTERPRET; | |
884 else | |
885 error("cannot evaluate %s at compile time", toChars()); | |
886 } | |
887 } | |
888 } | |
889 return e; | |
813 } | 890 } |
814 | 891 |
815 bool checkSideEffect(int flag) | 892 bool checkSideEffect(int flag) |
816 { | 893 { |
817 version (DMDV2) { | 894 version (DMDV2) { |