Mercurial > projects > ddmd
comparison dmd/Expression.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 1765f3ef917d |
children | af1bebfd96a4 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
1 module dmd.Expression; | 1 module dmd.Expression; |
2 | 2 |
3 import dmd.common; | 3 import dmd.common; |
4 import dmd.Loc; | 4 import dmd.Loc; |
5 import dmd.TOK; | 5 import dmd.TOK; |
6 import dmd.Argument; | 6 import dmd.Parameter; |
7 import dmd.IdentifierExp; | 7 import dmd.IdentifierExp; |
8 import dmd.Type; | 8 import dmd.Type; |
9 import dmd.WANT; | 9 import dmd.WANT; |
10 import dmd.Scope; | 10 import dmd.Scope; |
11 import dmd.Array; | 11 import dmd.Array; |
703 void checkPurity(Scope sc, FuncDeclaration f) | 703 void checkPurity(Scope sc, FuncDeclaration f) |
704 { | 704 { |
705 static if (true) { | 705 static if (true) { |
706 if (sc.func) | 706 if (sc.func) |
707 { | 707 { |
708 /* Given: | |
709 * void f() | |
710 * { pure void g() | |
711 * { | |
712 * void h() | |
713 * { | |
714 * void i() { } | |
715 * } | |
716 * } | |
717 * } | |
718 * g() can call h() but not f() | |
719 * i() can call h() and g() but not f() | |
720 */ | |
708 FuncDeclaration outerfunc = sc.func; | 721 FuncDeclaration outerfunc = sc.func; |
709 while (outerfunc.toParent2() && outerfunc.toParent2().isFuncDeclaration()) | 722 while (outerfunc.toParent2() && outerfunc.toParent2().isFuncDeclaration()) |
710 { | 723 { |
711 outerfunc = outerfunc.toParent2().isFuncDeclaration(); | 724 outerfunc = outerfunc.toParent2().isFuncDeclaration(); |
712 } | 725 } |
713 if (outerfunc.isPure() && !sc.intypeof && (!f.isNested() && !f.isPure())) | 726 if (outerfunc.isPure() && !sc.intypeof && (!f.isNested() && !f.isPure())) |
714 error("pure function '%s' cannot call impure function '%s'\n", | 727 error("pure function '%s' cannot call impure function '%s'\n", |
715 sc.func.toChars(), f.toChars()); | 728 sc.func.toChars(), f.toChars()); |
716 } | 729 } |
717 } else { | 730 } else { |
718 if (sc.func && sc.func.isPure() && !sc.intypeof && !f.isPure()) | 731 if (sc.func && sc.func.isPure() && !sc.intypeof && !f.isPure()) |
719 error("pure function '%s' cannot call impure function '%s'\n", | 732 error("pure function '%s' cannot call impure function '%s'\n", |
720 sc.func.toChars(), .toChars()); | 733 sc.func.toChars(), .toChars()); |
721 } | 734 } |
735 } | |
736 | |
737 void checkSafety(Scope sc, FuncDeclaration f) | |
738 { | |
739 if (sc.func && sc.func.isSafe() && !sc.intypeof && | |
740 !f.isSafe() && !f.isTrusted()) | |
741 error("safe function '%s' cannot call system function '%s'\n", | |
742 sc.func.toChars(), f.toChars()); | |
722 } | 743 } |
723 | 744 |
724 /***************************** | 745 /***************************** |
725 * Check that expression can be tested for true or false. | 746 * Check that expression can be tested for true or false. |
726 */ | 747 */ |
930 } else { | 951 } else { |
931 return true; | 952 return true; |
932 } | 953 } |
933 } | 954 } |
934 | 955 |
956 /**************************************** | |
957 * Resolve __LINE__ and __FILE__ to loc. | |
958 */ | |
959 | |
960 Expression resolveLoc(Loc loc, Scope sc) | |
961 { | |
962 return this; | |
963 } | |
964 | |
935 int inlineCost(InlineCostState* ics) | 965 int inlineCost(InlineCostState* ics) |
936 { | 966 { |
937 return 1; | 967 return 1; |
938 } | 968 } |
939 | 969 |
985 { | 1015 { |
986 buf.writestring("Exp"); | 1016 buf.writestring("Exp"); |
987 arguments.shift(this); | 1017 arguments.shift(this); |
988 } | 1018 } |
989 | 1019 |
990 Expression buildArrayLoop(Arguments fparams) | 1020 Expression buildArrayLoop(Parameters fparams) |
991 { | 1021 { |
992 Identifier id = Identifier.generateId("c", fparams.dim); | 1022 Identifier id = Identifier.generateId("c", fparams.dim); |
993 auto param = new Argument(STC.STCundefined, type, id, null); | 1023 auto param = new Parameter(STC.STCundefined, type, id, null); |
994 fparams.shift(param); | 1024 fparams.shift(param); |
995 Expression e = new IdentifierExp(Loc(0), id); | 1025 Expression e = new IdentifierExp(Loc(0), id); |
996 return e; | 1026 return e; |
997 } | 1027 } |
998 | 1028 |