comparison dmd/VarExp.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents 60bb0fe4563e
children fe2e1b93e88f
comparison
equal deleted inserted replaced
134:4251f96733f4 135:af1bebfd96a4
68 68
69 VarDeclaration v = var.isVarDeclaration(); 69 VarDeclaration v = var.isVarDeclaration();
70 if (v) 70 if (v)
71 { 71 {
72 static if (false) { 72 static if (false) {
73 if ((v.isConst() || v.isInvariant()) && type.toBasetype().ty != TY.Tsarray && v.init) 73 if ((v.isConst() || v.isImmutable()) && type.toBasetype().ty != TY.Tsarray && v.init)
74 { 74 {
75 ExpInitializer ei = v.init.isExpInitializer(); 75 ExpInitializer ei = v.init.isExpInitializer();
76 if (ei) 76 if (ei)
77 { 77 {
78 //ei.exp.implicitCastTo(sc, type).print(); 78 //ei.exp.implicitCastTo(sc, type).print();
119 /* If ANY of its enclosing functions are pure, 119 /* If ANY of its enclosing functions are pure,
120 * it cannot do anything impure. 120 * it cannot do anything impure.
121 * If it is pure, it cannot access any mutable variables other 121 * If it is pure, it cannot access any mutable variables other
122 * than those inside itself 122 * than those inside itself
123 */ 123 */
124 if (hasPureParent && v.isDataseg() && !v.isInvariant()) 124 if (hasPureParent && v.isDataseg() && !v.isImmutable())
125 { 125 {
126 error("pure function '%s' cannot access mutable static data '%s'", 126 error("pure function '%s' cannot access mutable static data '%s'",
127 sc.func.toChars(), v.toChars()); 127 sc.func.toChars(), v.toChars());
128 } 128 }
129 else if (sc.func.isPure() && sc.parent != v.parent && !v.isInvariant() && !(v.storage_class & STC.STCmanifest)) 129 else if (sc.func.isPure() && sc.parent != v.parent && !v.isImmutable() && !(v.storage_class & STC.STCmanifest))
130 { 130 {
131 error("pure nested function '%s' cannot access mutable data '%s'", sc.func.toChars(), v.toChars()); 131 error("pure nested function '%s' cannot access mutable data '%s'", sc.func.toChars(), v.toChars());
132 if (v.isEnumDeclaration()) 132 if (v.isEnumDeclaration())
133 error("enum"); 133 error("enum");
134 } 134 }
140 sc.func.toChars(), v.toChars()); 140 sc.func.toChars(), v.toChars());
141 } 141 }
142 } else { 142 } else {
143 if (sc.func && sc.func.isPure() && !sc.intypeof) 143 if (sc.func && sc.func.isPure() && !sc.intypeof)
144 { 144 {
145 if (v.isDataseg() && !v.isInvariant()) 145 if (v.isDataseg() && !v.isImmutable())
146 error("pure function '%s' cannot access mutable static data '%s'", sc.func.toChars(), v.toChars()); 146 error("pure function '%s' cannot access mutable static data '%s'", sc.func.toChars(), v.toChars());
147 } 147 }
148 } 148 }
149 } 149 }
150 } 150 }
205 else if (v.storage_class & STC.STCvariadic) 205 else if (v.storage_class & STC.STCvariadic)
206 error("escaping reference to variadic parameter %s", v.toChars()); 206 error("escaping reference to variadic parameter %s", v.toChars());
207 } 207 }
208 } 208 }
209 } 209 }
210
211 override void checkEscapeRef()
212 {
213 VarDeclaration v = var.isVarDeclaration();
214 if (v)
215 {
216 if (!v.isDataseg() && !(v.storage_class & (STCref | STCout)))
217 error("escaping reference to local variable %s", v.toChars());
218 }
219 }
210 220
211 version (DMDV2) 221 version (DMDV2)
212 { 222 {
213 override int isLvalue() 223 override int isLvalue()
214 { 224 {