comparison dmd/DeclarationExp.d @ 63:cab4c37afb89

A bunch of implementations
author korDen
date Mon, 23 Aug 2010 16:52:24 +0400
parents 10317f0c89a5
children 2e2a5c3f943a
comparison
equal deleted inserted replaced
62:6557375aff35 63:cab4c37afb89
17 import dmd.AttribDeclaration; 17 import dmd.AttribDeclaration;
18 import dmd.VarDeclaration; 18 import dmd.VarDeclaration;
19 import dmd.Global; 19 import dmd.Global;
20 import dmd.TOK; 20 import dmd.TOK;
21 import dmd.VoidInitializer; 21 import dmd.VoidInitializer;
22 import dmd.GlobalExpressions;
22 import dmd.Type; 23 import dmd.Type;
23 import dmd.codegen.Util; 24 import dmd.codegen.Util;
24 25
25 // Declaration of a symbol 26 // Declaration of a symbol
26 27
117 118
118 type = Type.tvoid; 119 type = Type.tvoid;
119 return this; 120 return this;
120 } 121 }
121 122
122 Expression interpret(InterState* istate) 123 Expression interpret(InterState istate)
123 { 124 {
124 assert(false); 125 version (LOG) {
126 printf("DeclarationExp.interpret() %s\n", toChars());
127 }
128 Expression e;
129 VarDeclaration v = declaration.isVarDeclaration();
130 if (v)
131 {
132 Dsymbol s = v.toAlias();
133 if (s == v && !v.isStatic() && v.init)
134 {
135 ExpInitializer ie = v.init.isExpInitializer();
136 if (ie)
137 e = ie.exp.interpret(istate);
138 else if (v.init.isVoidInitializer())
139 e = null;
140 }
141 ///version (DMDV2) {
142 else if (s == v && (v.isConst() || v.isInvariant()) && v.init)
143 ///} else {
144 /// else if (s == v && v.isConst() && v.init)
145 ///}
146 {
147 e = v.init.toExpression();
148 if (!e)
149 e = EXP_CANT_INTERPRET;
150 else if (!e.type)
151 e.type = v.type;
152 }
153 }
154 else if (declaration.isAttribDeclaration() ||
155 declaration.isTemplateMixin() ||
156 declaration.isTupleDeclaration())
157 {
158 // These can be made to work, too lazy now
159 error("Declaration %s is not yet implemented in CTFE", toChars());
160
161 e = EXP_CANT_INTERPRET;
162 }
163 else
164 { // Others should not contain executable code, so are trivial to evaluate
165 e = null;
166 }
167 version (LOG) {
168 printf("-DeclarationExp.interpret(%.*s): %p\n", toChars(), e);
169 }
170 return e;
125 } 171 }
126 172
127 bool checkSideEffect(int flag) 173 bool checkSideEffect(int flag)
128 { 174 {
129 return true; 175 return true;