annotate dmd/VarExp.d @ 73:ef02e2e203c2

Updating to dmd2.033
author korDen
date Sat, 28 Aug 2010 19:42:41 +0400
parents 2e2a5c3f943a
children 6da99741178e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
1 module dmd.VarExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
4 import dmd.Declaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
6 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
7 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
8 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
9 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
10 import dmd.FuncLiteralDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
11 import dmd.VarDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
12 import dmd.Dsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
13 import dmd.FuncDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
14 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
15 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
16 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
17 import dmd.TY;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
18 import dmd.STC;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
19 import dmd.SymbolExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
20 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
21 import dmd.interpret.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
22 import dmd.backend.dt_t;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
23 import dmd.expression.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
24
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
25 // Variable
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
26
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class VarExp : SymbolExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
29 this(Loc loc, Declaration var, bool hasOverloads = false)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
31 super(loc, TOK.TOKvar, VarExp.sizeof, var, hasOverloads);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
32
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
33 //printf("VarExp(this = %p, '%s', loc = %s)\n", this, var.toChars(), loc.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
34 //if (strcmp(var.ident.toChars(), "func") == 0) halt();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.type = var.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
38 override bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
43 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
45 FuncLiteralDeclaration fd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
46
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
47 version (LOGSEMANTIC) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
48 printf("VarExp.semantic(%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
49 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
50 if (!type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
51 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
52 type = var.type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
53 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
54 if (var.storage_class & STC.STClazy)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
55 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
56 TypeFunction tf = new TypeFunction(null, type, 0, LINK.LINKd);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
57 type = new TypeDelegate(tf);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
58 type = type.semantic(loc, sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
59 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
60 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
61 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
62
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
63 /* Fix for 1161 doesn't work because it causes protection
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
64 * problems when instantiating imported templates passing private
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
65 * variables as alias template parameters.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
66 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
67 //accessCheck(loc, sc, null, var);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
68
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
69 VarDeclaration v = var.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
70 if (v)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
71 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
72 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
73 if ((v.isConst() || v.isInvariant()) && type.toBasetype().ty != TY.Tsarray && v.init)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
74 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
75 ExpInitializer ei = v.init.isExpInitializer();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
76 if (ei)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
77 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
78 //ei.exp.implicitCastTo(sc, type).print();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
79 return ei.exp.implicitCastTo(sc, type);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
80 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
81 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
82 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
83 v.checkNestedReference(sc, loc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
84 version (DMDV2) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
85 static if (true) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
86 if (sc.func)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
87 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
88 /* Determine if sc.func is pure or if any function that
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
89 * encloses it is also pure.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
90 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
91 bool hasPureParent = false;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
92 for (FuncDeclaration outerfunc = sc.func; outerfunc;)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
93 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
94 if (outerfunc.isPure())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
95 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
96 hasPureParent = true;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
97 break;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
98 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
99 Dsymbol parent = outerfunc.toParent2();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
100 if (!parent)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
101 break;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
102 outerfunc = parent.isFuncDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
103 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
104
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
105 /* If ANY of its enclosing functions are pure,
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
106 * it cannot do anything impure.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
107 * If it is pure, it cannot access any mutable variables other
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
108 * than those inside itself
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
109 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
110 if (hasPureParent && !sc.intypeof && v.isDataseg() && !v.isInvariant())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
111 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
112 error("pure function '%s' cannot access mutable static data '%s'",
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
113 sc.func.toChars(), v.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
114 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
115 else if (sc.func.isPure() && sc.parent != v.parent && !sc.intypeof && !v.isInvariant() && !(v.storage_class & STC.STCmanifest))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
116 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
117 error("pure nested function '%s' cannot access mutable data '%s'", sc.func.toChars(), v.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
118 if (v.isEnumDeclaration())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
119 error("enum");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
120 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
121 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
122 } else {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
123 if (sc.func && sc.func.isPure() && !sc.intypeof)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
124 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
125 if (v.isDataseg() && !v.isInvariant())
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
126 error("pure function '%s' cannot access mutable static data '%s'", sc.func.toChars(), v.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
127 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
128 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
129 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
130 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
131 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
132 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
133 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
134 if ((fd = var.isFuncLiteralDeclaration()) !is null)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
135 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
136 Expression e = new FuncExp(loc, fd);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
137 e.type = type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
138 return e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
139 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
140 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
141 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
142
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
146 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 return fromConstInitializer(result, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
151 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
153 version (LOG) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
154 printf("VarExp.interpret() %.*s\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
155 }
63
cab4c37afb89 A bunch of implementations
korDen
parents: 45
diff changeset
156 return getVarExp(loc, istate, var);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
159 override void dump(int indent)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
164 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 return var.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
169 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 buf.writestring(var.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
174 override void checkEscape()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
176 VarDeclaration v = var.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
177 if (v)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
178 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
179 Type tb = v.type.toBasetype();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
180 // if reference type
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
181 if (tb.ty == TY.Tarray || tb.ty == TY.Tsarray || tb.ty == TY.Tclass)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
182 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
183 if ((v.isAuto() || v.isScope()) && !v.noauto)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
184 error("escaping reference to scope local %s", v.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
185 else if (v.storage_class & STC.STCvariadic)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
186 error("escaping reference to variadic parameter %s", v.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
187 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
190
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
192 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
194 if (var.storage_class & STClazy)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
195 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
199 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
201 static if (false) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
202 tym = tybasic(e1.ET.Tty);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
203 if (!(tyscalar(tym) ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
204 tym == TYM.TYstruct ||
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
205 tym == TYM.TYarray && e.Eoper == TOK.TOKaddr))
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
206 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
207 synerr(EM_lvalue); // lvalue expected
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
208 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
209 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
210 if (var.storage_class & STC.STClazy)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
211 error("lazy variables cannot be lvalues");
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
212
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
216 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
218 //printf("VarExp::modifiableLvalue('%s')\n", var.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
219 if (type && type.toBasetype().ty == TY.Tsarray)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
220 error("cannot change reference to static array '%s'", var.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
221
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
222 var.checkModify(loc, sc, type);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
223
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
224 // See if this expression is a modifiable lvalue (i.e. not const)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 return toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
228 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
233 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
235 //printf("VarExp.scanForNestedRef(%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
236 VarDeclaration v = var.isVarDeclaration();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
237 if (v)
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
238 v.checkNestedReference(sc, Loc(0));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
241 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
243 //printf("VarExp.inlineCost() %s\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
247 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
249 int i;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
250
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
251 //printf("VarExp.doInline(%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
252 for (i = 0; i < ids.from.dim; i++)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
253 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
254 if (var == cast(Declaration)ids.from.data[i])
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
255 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
256 VarExp ve = cast(VarExp)copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
257
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
258 ve.var = cast(Declaration)ids.to.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
259 return ve;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
260 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
261 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265