comparison dmd/VarExp.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 e28b18c23469
children af1bebfd96a4
comparison
equal deleted inserted replaced
129:010eb8f0e18d 130:60bb0fe4563e
81 } 81 }
82 } 82 }
83 v.checkNestedReference(sc, loc); 83 v.checkNestedReference(sc, loc);
84 version (DMDV2) { 84 version (DMDV2) {
85 static if (true) { 85 static if (true) {
86 if (sc.func) 86 if (sc.func && !sc.intypeof)
87 { 87 {
88 /* Given:
89 * void f()
90 * { int fx;
91 * pure void g()
92 * { int gx;
93 * void h()
94 * { int hx;
95 * void i() { }
96 * }
97 * }
98 * }
99 * i() can modify hx and gx but not fx
100 */
101
88 /* Determine if sc.func is pure or if any function that 102 /* Determine if sc.func is pure or if any function that
89 * encloses it is also pure. 103 * encloses it is also pure.
90 */ 104 */
91 bool hasPureParent = false; 105 bool hasPureParent = false;
92 for (FuncDeclaration outerfunc = sc.func; outerfunc;) 106 for (FuncDeclaration outerfunc = sc.func; outerfunc;)
105 /* If ANY of its enclosing functions are pure, 119 /* If ANY of its enclosing functions are pure,
106 * it cannot do anything impure. 120 * it cannot do anything impure.
107 * If it is pure, it cannot access any mutable variables other 121 * If it is pure, it cannot access any mutable variables other
108 * than those inside itself 122 * than those inside itself
109 */ 123 */
110 if (hasPureParent && !sc.intypeof && v.isDataseg() && !v.isInvariant()) 124 if (hasPureParent && v.isDataseg() && !v.isInvariant())
111 { 125 {
112 error("pure function '%s' cannot access mutable static data '%s'", 126 error("pure function '%s' cannot access mutable static data '%s'",
113 sc.func.toChars(), v.toChars()); 127 sc.func.toChars(), v.toChars());
114 } 128 }
115 else if (sc.func.isPure() && sc.parent != v.parent && !sc.intypeof && !v.isInvariant() && !(v.storage_class & STC.STCmanifest)) 129 else if (sc.func.isPure() && sc.parent != v.parent && !v.isInvariant() && !(v.storage_class & STC.STCmanifest))
116 { 130 {
117 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());
118 if (v.isEnumDeclaration()) 132 if (v.isEnumDeclaration())
119 error("enum"); 133 error("enum");
120 } 134 }
135
136 /* Do not allow safe functions to access __gshared data
137 */
138 if (sc.func.isSafe() && v.storage_class & STCgshared)
139 error("safe function '%s' cannot access __gshared data '%s'",
140 sc.func.toChars(), v.toChars());
121 } 141 }
122 } else { 142 } else {
123 if (sc.func && sc.func.isPure() && !sc.intypeof) 143 if (sc.func && sc.func.isPure() && !sc.intypeof)
124 { 144 {
125 if (v.isDataseg() && !v.isInvariant()) 145 if (v.isDataseg() && !v.isInvariant())