Changeset 1185
- Timestamp:
- 06/02/08 20:43:54 (7 months ago)
- Files:
-
- trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/AddrExp.java (modified) (5 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/ArrayScopeSymbol.java (modified) (9 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Dsymbol.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/PostBlitDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/PtrExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ScopeDsymbol.java (modified) (5 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/SymOffExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/VarDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/VarExp.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/port.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java
r1176 r1185 23 23 import static descent.internal.compiler.parser.PROT.PROTprotected; 24 24 25 import static descent.internal.compiler.parser.STC. STClazy;25 import static descent.internal.compiler.parser.STC.*; 26 26 import static descent.internal.compiler.parser.STC.STCout; 27 27 import static descent.internal.compiler.parser.STC.STCref; 28 28 29 import static descent.internal.compiler.parser.TOK. TOKarray;29 import static descent.internal.compiler.parser.TOK.*; 30 30 import static descent.internal.compiler.parser.TOK.TOKassocarrayliteral; 31 31 import static descent.internal.compiler.parser.TOK.TOKdelegate; … … 1087 1087 return getNodeType(); 1088 1088 } 1089 1090 /************************************* 1091 * If variable has a const initializer, 1092 * return that initializer. 1093 */ 1094 1095 public static Expression expandVar(int result, VarDeclaration v, 1096 SemanticContext context) { 1097 Expression e = null; 1098 if (v != null 1099 && (v.isConst() || v.isInvariant() || (v.storage_class & STCmanifest) != 0)) { 1100 Type tb = v.type.toBasetype(context); 1101 if ((result & WANTinterpret) != 0 1102 || (v.storage_class & STCmanifest) != 0 1103 || (tb.ty != Tsarray && tb.ty != Tstruct)) { 1104 if (v.init != null) { 1105 if (v.inuse != 0) { 1106 // goto L1; 1107 return e; 1108 } 1109 Expression ei = v.init.toExpression(context); 1110 if (null == ei) { 1111 // goto L1; 1112 return e; 1113 } 1114 if (ei.op == TOKconstruct || ei.op == TOKblit) { 1115 AssignExp ae = (AssignExp) ei; 1116 ei = ae.e2; 1117 if (ei.isConst() != true && ei.op != TOKstring) { 1118 // goto L1; 1119 return e; 1120 } 1121 if (ei.type != v.type) { 1122 // goto L1; 1123 return e; 1124 } 1125 } 1126 if (v.scope != null) { 1127 v.inuse++; 1128 e = ei.syntaxCopy(context); 1129 e = e.semantic(v.scope, context); 1130 e = e.implicitCastTo(v.scope, v.type, context); 1131 v.scope = null; 1132 v.inuse--; 1133 } else if (null == ei.type) { 1134 // goto L1; 1135 return e; 1136 } else { 1137 // Should remove the copy() operation by 1138 // making all mods to expressions copy-on-write 1139 e = ei.copy(); 1140 } 1141 } else { 1142 // goto L1; 1143 return e; 1144 } 1145 if (e.type != v.type) { 1146 e = e.castTo(null, v.type, context); 1147 } 1148 e = e.optimize(result, context); 1149 } 1150 } 1151 //L1: 1152 return e; 1153 } 1154 1089 1155 1090 1156 /************************************* … … 1092 1158 * return that initializer. 1093 1159 */ 1094 1095 public Expression fromConstInitializer(Expression e1,1160 1161 public static Expression fromConstInitializer(Expression e1, 1096 1162 SemanticContext context) { 1097 if (e1.op == TOKvar) { 1098 VarExp ve = (VarExp) e1; 1099 VarDeclaration v = ve.var.isVarDeclaration(); 1100 if (v != null && v.isConst() && v.init() != null) { 1101 Expression ei = v.init().toExpression(context); 1102 if (ei != null && ei.type != null) { 1103 e1 = ei; 1163 return fromConstInitializer(0, e1, context); 1164 } 1165 1166 public static Expression fromConstInitializer(int result, Expression e1, 1167 SemanticContext context) { 1168 if (context.isD2()) { 1169 Expression e = e1; 1170 if (e1.op == TOKvar) { 1171 VarExp ve = (VarExp) e1; 1172 VarDeclaration v = ve.var.isVarDeclaration(); 1173 e = expandVar(result, v, context); 1174 if (e != null) { 1175 if (e.type != e1.type) { // Type 'paint' operation 1176 e = e.copy(); 1177 e.type = e1.type; 1178 } 1179 } else 1180 e = e1; 1181 } 1182 return e; 1183 } else { 1184 if (e1.op == TOKvar) { 1185 VarExp ve = (VarExp) e1; 1186 VarDeclaration v = ve.var.isVarDeclaration(); 1187 if (v != null && v.isConst() && v.init() != null) { 1188 Expression ei = v.init().toExpression(context); 1189 if (ei != null && ei.type != null) { 1190 e1 = ei; 1191 } 1104 1192 } 1105 1193 } trunk/descent.core/src/descent/internal/compiler/parser/AddrExp.java
r1161 r1185 8 8 import static descent.internal.compiler.parser.TOK.TOKint64; 9 9 import static descent.internal.compiler.parser.TOK.TOKstar; 10 import static descent.internal.compiler.parser.TOK.TOKvar; 10 import static descent.internal.compiler.parser.TOK.*; 11 import static descent.internal.compiler.parser.STC.*; 11 12 import static descent.internal.compiler.parser.TY.Tbit; 12 13 import static descent.internal.compiler.parser.TY.Tfunction; … … 103 104 Expression e; 104 105 105 e1 = e1.optimize(result, context); 106 if (context.isD2()) { 107 /* Rewrite &(a,b) as (a,&b) 108 */ 109 if (e1.op == TOKcomma) { 110 CommaExp ce = (CommaExp) e1; 111 AddrExp ae = new AddrExp(loc, ce.e2); 112 ae.type = type; 113 e = new CommaExp(ce.loc, ce.e1, ae); 114 e.type = type; 115 return e.optimize(result, context); 116 } 117 118 if (e1.op == TOKvar) { 119 VarExp ve = (VarExp) e1; 120 if ((ve.var.storage_class & STCmanifest) != 0) { 121 e1 = e1.optimize(result, context); 122 } 123 } else { 124 e1 = e1.optimize(result, context); 125 } 126 } else { 127 e1 = e1.optimize(result, context); 128 } 129 106 130 // Convert &ex to ex 107 131 if (e1.op == TOKstar) { … … 121 145 if (!ve.var.isOut() && !ve.var.isRef() 122 146 && !ve.var.isImportedSymbol()) { 123 e = new SymOffExp(loc, ve.var, 0, context); 124 e.copySourceRange(ve); 125 e.type = type; 126 return e; 147 if (context.isD2()) { 148 SymOffExp se = new SymOffExp(loc, ve.var, 0, ve.hasOverloads, context); 149 se.type = type; 150 return se; 151 } else { 152 e = new SymOffExp(loc, ve.var, 0, context); 153 e.copySourceRange(ve); 154 e.type = type; 155 return e; 156 } 127 157 } 128 158 } … … 133 163 integer_t index = ae.e2.toInteger(context); 134 164 VarExp ve = (VarExp) ae.e1; 135 if (ve.type.ty == Tsarray && ve.type.next.ty != Tbit 136 && !ve.var.isImportedSymbol()) { 165 166 boolean condition; 167 if (context.isD2()) { 168 condition = ve.type.ty == Tsarray && !ve.var.isImportedSymbol(); 169 } else { 170 condition = ve.type.ty == Tsarray && ve.type.next.ty != Tbit 171 && !ve.var.isImportedSymbol(); 172 } 173 174 if (condition) { 137 175 TypeSArray ts = (TypeSArray) ve.type; 138 176 integer_t dim = ts.dim.toInteger(context); … … 149 187 } 150 188 } 151 e = new SymOffExp(loc, ve.var, index.multiply(ts.next 152 .size(context)), context); 189 if (context.isD2()) { 190 e = new SymOffExp(loc, ve.var, index.multiply(ts.nextOf() 191 .size(context)), context); 192 } else { 193 e = new SymOffExp(loc, ve.var, index.multiply(ts.next 194 .size(context)), context); 195 } 153 196 e.type = type; 154 197 return e; trunk/descent.core/src/descent/internal/compiler/parser/ArrayScopeSymbol.java
r1160 r1185 6 6 7 7 import static descent.internal.compiler.parser.STC.STCconst; 8 import static descent.internal.compiler.parser.STC.STCstatic; 8 9 9 10 import static descent.internal.compiler.parser.TOK.TOKarrayliteral; … … 13 14 import static descent.internal.compiler.parser.TOK.TOKtuple; 14 15 import static descent.internal.compiler.parser.TOK.TOKtype; 16 import static descent.internal.compiler.parser.TOK.TOKvar; 15 17 16 18 import static descent.internal.compiler.parser.TY.Ttuple; … … 21 23 public TypeTuple type; // for tuple[length] 22 24 public TupleDeclaration td; // for tuples of objects 25 public Scope sc; 23 26 24 27 public ArrayScopeSymbol(Expression e) { 28 this(null, e); 29 } 30 31 public ArrayScopeSymbol(Scope sc, Expression e) { 25 32 Assert.isTrue(e.op == TOK.TOKindex || e.op == TOK.TOKslice); 26 exp = e; 33 this.exp = e; 34 this.sc = sc; 27 35 } 28 36 29 37 public ArrayScopeSymbol(TupleDeclaration s) { 38 this(null, s); 39 } 40 41 public ArrayScopeSymbol(Scope sc, TupleDeclaration s) { 30 42 this.exp = null; 31 43 this.type = null; 32 44 this.td = s; 45 this.sc = sc; 33 46 } 34 47 35 48 public ArrayScopeSymbol(TypeTuple t) { 49 this(null, t); 50 } 51 52 public ArrayScopeSymbol(Scope sc, TypeTuple t) { 36 53 this.exp = null; 37 54 this.type = t; 38 55 this.td = null; 56 this.sc = sc; 39 57 } 40 58 … … 75 93 Type.tsize_t); 76 94 v.init = new ExpInitializer(Loc.ZERO, e); 77 v.storage_class |= STCconst; 95 if (context.isD2()) { 96 v.storage_class |= STCstatic | STCconst; 97 v.semantic(sc, context); 98 } else { 99 v.storage_class |= STCconst; 100 } 78 101 return v; 79 102 } … … 85 108 .size(), Type.tsize_t); 86 109 v.init = new ExpInitializer(Loc.ZERO, e); 87 v.storage_class |= STCconst; 110 if (context.isD2()) { 111 v.storage_class |= STCstatic | STCconst; 112 v.semantic(sc, context); 113 } else { 114 v.storage_class |= STCconst; 115 } 88 116 return v; 89 117 } … … 126 154 VarDeclaration v = new VarDeclaration(loc, Type.tsize_t, 127 155 Id.dollar, null); 156 157 if (context.isD2()) { 158 if (ce.op == TOKvar) { // if ce is const, get its initializer 159 ce = fromConstInitializer( 160 WANTvalue | WANTinterpret, ce, context); 161 } 162 } 128 163 129 164 if (ce.op == TOKstring) { … … 131 166 ((StringExp) ce).len, Type.tsize_t); 132 167 v.init = new ExpInitializer(Loc.ZERO, e); 133 v.storage_class |= STCconst; 168 if (context.isD2()) { 169 v.storage_class |= STCstatic | STCconst; 170 } else { 171 v.storage_class |= STCconst; 172 } 134 173 } else if (ce.op == TOKarrayliteral) { 135 174 /* It is for an array literal, so the … … 140 179 Type.tsize_t); 141 180 v.init = new ExpInitializer(Loc.ZERO, e); 142 v.storage_class |= STCconst; 181 if (context.isD2()) { 182 v.storage_class |= STCstatic | STCconst; 183 } else { 184 v.storage_class |= STCconst; 185 } 143 186 } else if (ce.op == TOKtuple) { 144 187 Expression e = new IntegerExp(loc, ((TupleExp) ce).exps 145 188 .size(), Type.tsize_t); 146 189 v.init = new ExpInitializer(loc, e); 147 v.storage_class |= STCconst; 190 if (context.isD2()) { 191 v.storage_class |= STCstatic | STCconst; 192 } else { 193 v.storage_class |= STCconst; 194 } 148 195 } 149 196 … … 156 203 } 157 204 } 205 206 if (context.isD2()) { 207 pvar.semantic(sc, context); 208 } 209 158 210 // TODO semantic I think this logic is ok 159 211 // return *pvar; trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java
r1176 r1185 165 165 166 166 e1 = e1.optimize(result, context); 167 if (e1.op == TOKvar && (result & WANTinterpret) != 0) { 167 168 boolean condition; 169 if (context.isD2()) { 170 condition = e1.op == TOKvar; 171 } else { 172 condition = e1.op == TOKvar && (result & WANTinterpret) != 0; 173 } 174 175 if (condition) { 168 176 FuncDeclaration fd = ((VarExp) e1).var.isFuncDeclaration(); 169 177 if (fd != null) { 170 Expression eresult = fd.interpret(null, arguments, context); 171 if (eresult != null && eresult != EXP_VOID_INTERPRET) { 172 e = eresult; 173 } else if ((result & WANTinterpret) != 0) { 174 if (context.acceptsProblems()) { 175 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ExpressionIsNotEvaluatableAtCompileTime, this, new String[] { toChars(context) })); 176 } 177 } 178 BUILTIN b = fd.isBuiltin(); 179 if (context.isD2() && b != BUILTIN.BUILTINunknown) { 180 e = eval_builtin(b, arguments, context); 181 if (null == e) { // failed 182 e = this; // evaluate at runtime 183 } 184 } else { 185 Expression eresult = fd.interpret(null, arguments, context); 186 if (eresult != null && eresult != EXP_VOID_INTERPRET) { 187 e = eresult; 188 } else if ((result & WANTinterpret) != 0) { 189 if (context.acceptsProblems()) { 190 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ExpressionIsNotEvaluatableAtCompileTime, this, new String[] { toChars(context) })); 191 } 192 } 193 } 178 194 } 179 195 } trunk/descent.core/src/descent/internal/compiler/parser/Dsymbol.java
r1176 r1185 321 321 } 322 322 323 public boolean isOverloadable() { 324 return false; 325 } 326 323 327 public OverloadSet isOverloadSet() { 324 328 return null; … … 326 330 327 331 public Package isPackage() { 332 return null; 333 } 334 335 public PostBlitDeclaration isPostBlitDeclaration() { 328 336 return null; 329 337 } trunk/descent.core/src/descent/internal/compiler/parser/PostBlitDeclaration.java
r1171 r1185 66 66 67 67 @Override 68 public PostBlitDeclaration isPostBlitDeclaration() { 69 return this; 70 } 71 72 @Override 68 73 public boolean isVirtual(SemanticContext context) { 69 74 return false; trunk/descent.core/src/descent/internal/compiler/parser/PtrExp.java
r1160 r1185 115 115 } 116 116 117 if (context.isD2()) { 118 if (e1.op == TOKsymoff) { 119 SymOffExp se = (SymOffExp) e1; 120 VarDeclaration v = se.var.isVarDeclaration(); 121 Expression e = expandVar(result, v, context); 122 if (e != null && e.op == TOKstructliteral) { 123 StructLiteralExp sle = (StructLiteralExp) e; 124 e = sle.getField(type, se.offset.intValue(), context); 125 if (e != EXP_CANT_INTERPRET) 126 return e; 127 } 128 } 129 } 130 117 131 return this; 118 132 } trunk/descent.core/src/descent/internal/compiler/parser/ScopeDsymbol.java
r1168 r1185 156 156 @Override 157 157 public Dsymbol search(Loc loc, char[] ident, int flags, SemanticContext context) { 158 Dsymbol s;159 int i;160 161 158 // Look in symbols declared in this module 162 s = symtab != null ? symtab.lookup(ident) : null;159 Dsymbol s = symtab != null ? symtab.lookup(ident) : null; 163 160 if (s != null) { 164 161 } else if (imports != null && !imports.isEmpty()) { 162 OverloadSet a = null; 163 165 164 // Look in imported modules 166 i = -1;167 for ( ScopeDsymbol ss : imports) {168 i++;165 loop: 166 for (int i = 0; i < imports.size(); i++) { 167 ScopeDsymbol ss = imports.get(i); 169 168 Dsymbol s2; 170 169 … … 192 191 .isImport() == null 193 192 && i2.parent.isImport() == null && ASTDmdNode.equals(i1.ident, i2.ident))))) { 194 ScopeDsymbol.multiplyDefined(loc, s, s2, context); 193 if (context.isD2()) { 194 /* If both s2 and s are overloadable (though we only 195 * need to check s once) 196 */ 197 if (s2.isOverloadable() 198 && (a != null || s.isOverloadable())) { 199 if (null == a) 200 a = new OverloadSet(); 201 /* Don't add to a[] if s2 is alias of previous sym 202 */ 203 for (int j = 0; j < size(a.a); j++) { 204 Dsymbol s3 = (Dsymbol) a.a.get(j); 205 if (s2.toAlias(context) == s3 206 .toAlias(context)) { 207 if (s3.isDeprecated()) { 208 a.a.set(j, s2); 209 } 210 // goto Lcontinue; 211 continue loop; 212 } 213 } 214 a.push(s2); 215 // Lcontinue: continue; 216 } 217 if ((flags & 4) != 0) { // if return NULL on ambiguity 218 return null; 219 } 220 if (0 == (flags & 2)) { 221 ScopeDsymbol.multiplyDefined(loc, s, s2, 222 context); 223 } 224 } else { 225 ScopeDsymbol.multiplyDefined(loc, s, s2, 226 context); 227 } 195 228 break; 196 229 } … … 198 231 } 199 232 } 233 234 if (context.isD2()) { 235 /* Build special symbol if we had multiple finds 236 */ 237 if (a != null) { 238 a.push(s); 239 s = a; 240 } 241 } 242 200 243 if (s != null) { 201 244 Declaration d = s.isDeclaration(); 202 if (d != null && d.protection == PROT.PROTprivate 203 && d.parent.isTemplateMixin() == null) { 245 246 boolean condition = d != null && d.protection == PROT.PROTprivate 247 && d.parent.isTemplateMixin() == null; 248 if (context.isD2()) { 249 condition &= 0 == (flags & 2); 250 } 251 if (condition) { 204 252 if (context.acceptsProblems()) { 205 253 context.acceptProblem(Problem.newSemanticTypeError( … … 232 280 * Returns NULL if not found 233 281 */ 234 FuncDeclaration findGetMembers(SemanticContext context) {282 public FuncDeclaration findGetMembers(SemanticContext context) { 235 283 Dsymbol s = search_function(this, Id.getmembers, context); 236 284 FuncDeclaration fdx = s != null ? s.isFuncDeclaration() : null; … … 241 289 return fdx; 242 290 } 291 292 /*************************************** 293 * Determine number of Dsymbols, folding in AttribDeclaration members. 294 */ 295 public static int dim(Array members) { 296 int n = 0; 297 if (members != null) { 298 for (int i = 0; i < size(members); i++) { 299 Dsymbol s = (Dsymbol) members.get(i); 300 AttribDeclaration a = s.isAttribDeclaration(); 301 302 if (a != null) { 303 n += dim(a.decl); 304 } else { 305 n++; 306 } 307 } 308 } 309 return n; 310 } 311 312 /*************************************** 313 * Get nth Dsymbol, folding in AttribDeclaration members. 314 * Returns: 315 * Dsymbol* nth Dsymbol 316 * NULL not found, *pn gets incremented by the number 317 * of Dsymbols 318 */ 319 public static Dsymbol getNth(Array members, int nth, int[] pn) { 320 if (null == members) 321 return null; 322 323 int[] n = { 0 }; 324 for (int i = 0; i < size(members); i++) { 325 Dsymbol s = (Dsymbol) members.get(i); 326 AttribDeclaration a = s.isAttribDeclaration(); 327 328 if (a != null) { 329 s = getNth(a.decl, nth - n[0], n); 330 if (s != null) 331 return s; 332 } else if (n[0] == nth) 333 return s; 334 else 335 n[0]++; 336 } 337 338 if (pn != null) { 339 pn[0] += n[0]; 340 } 341 return null; 342 } 243 343 244 344 } trunk/descent.core/src/descent/internal/compiler/parser/SymOffExp.java
r1160 r1185 34 34 } 35 35 36 public SymOffExp(Loc loc, Declaration var, int offset, boolean hasOverloads, SemanticContext context) { 37 // TODO SEMANTIC 38 this(loc, var, new integer_t(offset), context); 39 } 40 36 41 @Override 37 42 public void accept0(IASTVisitor visitor) { trunk/descent.core/src/descent/internal/compiler/parser/VarDeclaration.java
r1168 r1185 56 56 public Object csym; 57 57 public Object isym; 58 public Scope scope; 58 59 59 60 private IField javaElement; trunk/descent.core/src/descent/internal/compiler/parser/VarExp.java
r1160 r1185 18 18 19 19 public Declaration var; 20 public boolean hasOverloads; 20 21 21 22 public VarExp(Loc loc, Declaration var) { … … 149 150 public Expression optimize(int result, SemanticContext context) 150 151 { 151 if((result & WANTinterpret) > 0) 152 { 153 return fromConstInitializer(this, context); 154 } 155 return this; 152 if (context.isD2()) { 153 return fromConstInitializer(result, this, context); 154 } else { 155 if((result & WANTinterpret) > 0) 156 { 157 return fromConstInitializer(this, context); 158 } 159 return this; 160 } 156 161 } 157 162 trunk/descent.core/src/descent/internal/compiler/parser/port.txt
r1176 r1185 23 23 declaration.c 24 24 declaration.h 25 dsymbol.c26 dsymbol.h27 25 enum.c 28 26 enum.h … … 40 38 mtype.h 41 39 opopver.c 42 optimize.c 40 optimize.c --> CastExp::optimize 43 41 statement.c 44 42 statement.h
