Changeset 1167
- Timestamp:
- 05/17/08 10:22:56 (2 months ago)
- Files:
-
- trunk/descent.core/src/descent/core/compiler/IProblem.java (modified) (1 diff)
- trunk/descent.core/src/descent/core/dom/ASTConverter.java (modified) (4 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/BinExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/DelegateExp.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/DotIdExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/DotVarExp.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/Problem.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/StructInitializer.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateParameter.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateThisParameter.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateValueParameter.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TypeAArray.java (modified) (1 diff)
- trunk/descent.core/template/problem/problems.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/core/compiler/IProblem.java
r1165 r1167 671 671 int TypeofReturnMustBeInsideFunction = 460; 672 672 int PostBlitsAreOnlyForStructUnionDefinitions = 461; 673 int CannotHaveEDotTuple = 462; 673 674 674 675 } trunk/descent.core/src/descent/core/dom/ASTConverter.java
r1166 r1167 544 544 545 545 public void convert(StorageClassDeclaration a, List<Declaration> toAdd) { 546 descent.core.dom.Modifier modifier = convert(a.modifier); 546 descent.core.dom.Modifier modifier = null; 547 548 if (a.modifier != null) { 549 convert(a.modifier); 550 } 547 551 548 552 if (a.single && a.decl != null && a.decl.size() >= 1) { … … 585 589 } 586 590 587 descent.core.dom.ModifierDeclaration b = new descent.core.dom.ModifierDeclaration(ast); 588 b.setModifier(modifier); 591 descent.core.dom.ModifierDeclaration b = new descent.core.dom.ModifierDeclaration(ast); 592 if (modifier != null) { 593 b.setModifier(modifier); 594 } 589 595 convertDeclarations(b.declarations(), a.decl); 590 596 b.setSourceRange(a.start, a.length); … … 615 621 616 622 public void convert(ProtDeclaration a, List<Declaration> toAdd) { 617 descent.core.dom.Modifier modifier = convert(a.modifier); 623 descent.core.dom.Modifier modifier = null; 624 if (a.modifier != null) { 625 modifier = convert(a.modifier); 626 } 618 627 619 628 if (a.single && a.decl != null && a.decl.size() > 0) { … … 646 655 } 647 656 648 descent.core.dom.ModifierDeclaration b = new descent.core.dom.ModifierDeclaration(ast); 649 b.setModifier(modifier); 657 descent.core.dom.ModifierDeclaration b = new descent.core.dom.ModifierDeclaration(ast); 658 if (modifier != null) { 659 b.setModifier(modifier); 660 } 650 661 convertDeclarations(b.declarations(), a.decl); 651 662 b.setSourceRange(a.start, a.length); trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java
r1165 r1167 44 44 import static descent.internal.compiler.parser.TY.Tfunction; 45 45 import static descent.internal.compiler.parser.TY.Tident; 46 import static descent.internal.compiler.parser.TY.Tpointer; 46 47 import static descent.internal.compiler.parser.TY.Tsarray; 47 48 import static descent.internal.compiler.parser.TY.Tstruct; … … 1894 1895 } 1895 1896 1897 /************************************************************* 1898 * Now that we have the right function f, we need to get the 1899 * right 'this' pointer if f is in an outer class, but our 1900 * existing 'this' pointer is in an inner class. 1901 * This code is analogous to that used for variables 1902 * in DotVarExp::semantic(). 1903 */ 1904 public static Expression getRightThis(Loc loc, Scope sc, 1905 AggregateDeclaration ad, Expression e1, Declaration var, 1906 SemanticContext context) { 1907 boolean gotoL1 = true; 1908 L1: 1909 while(gotoL1) { 1910 gotoL1 = false; 1911 1912 Type t = e1.type.toBasetype(context); 1913 1914 if (ad != null 1915 && !(t.ty == Tpointer && t.next.ty == Tstruct && ((TypeStruct) t.next).sym == ad) 1916 && !(t.ty == Tstruct && ((TypeStruct) t).sym == ad)) { 1917 ClassDeclaration cd = ad.isClassDeclaration(); 1918 ClassDeclaration tcd = t.isClassHandle(); 1919 1920 if (null == cd || null == tcd 1921 || !(tcd == cd || cd.isBaseOf(tcd, null, context))) { 1922 if (tcd != null && tcd.isNested()) { // Try again with outer scope 1923 1924 e1 = new DotVarExp(loc, e1, tcd.vthis); 1925 e1 = e1.semantic(sc, context); 1926 1927 // Skip over nested functions, and get the enclosing 1928 // class type. 1929 Dsymbol s = tcd.toParent(); 1930 while (s != null && s.isFuncDeclaration() != null) { 1931 FuncDeclaration f = s.isFuncDeclaration(); 1932 if (f.vthis != null) { 1933 e1 = new VarExp(loc, f.vthis); 1934 } 1935 s = s.toParent(); 1936 } 1937 if (s != null && s.isClassDeclaration() != null) { 1938 e1.type = s.isClassDeclaration().type; 1939 } 1940 e1 = e1.semantic(sc, context); 1941 // goto L1; 1942 gotoL1 = true; 1943 continue L1; 1944 } 1945 if (context.acceptsProblems()) { 1946 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ThisForSymbolNeedsToBeType, var, new String[] { var 1947 .toChars(context), ad.toChars(context), t 1948 .toChars(context) })); 1949 } 1950 } 1951 } 1952 } 1953 return e1; 1954 } 1955 1896 1956 public void errorOnModifier(int problemId, TOK tok, SemanticContext context) { 1897 1957 boolean reported = false; trunk/descent.core/src/descent/internal/compiler/parser/BinExp.java
r1161 r1167 474 474 return this; 475 475 } else if (t1.ty == Tclass || t2.ty == Tclass) { 476 MATCH i1; 477 MATCH i2; 478 479 i1 = e2.implicitConvTo(t1, context); 480 i2 = e1.implicitConvTo(t2, context); 481 482 if (i1 != MATCHnomatch && i2 != MATCHnomatch) { 483 // We have the case of class vs. void*, so pick class 484 if (t1.ty == Tpointer) { 485 i1 = MATCHnomatch; 486 } else if (t2.ty == Tpointer) { 487 i2 = MATCHnomatch; 488 } 489 } 490 491 if (i2 != MATCHnomatch) { 492 // goto Lt2; 493 e1 = e1.castTo(sc, t2, context); 494 t = t2; 495 if (type == null) { 496 type = t; 497 } 498 return this; 499 } else if (i1 != MATCHnomatch) { 500 // goto Lt1; 501 e2 = e2.castTo(sc, t1, context); 502 t = t1; 503 if (type == null) { 504 type = t; 505 } 506 return this; 507 } else { 508 return typeCombine_Lincompatible_End(t, context); 476 477 while(true) { 478 MATCH i1 = e2.implicitConvTo(t1, context); 479 MATCH i2 = e1.implicitConvTo(t2, context); 480 481 if (i1 != MATCHnomatch && i2 != MATCHnomatch) { 482 // We have the case of class vs. void*, so pick class 483 if (t1.ty == Tpointer) { 484 i1 = MATCHnomatch; 485 } else if (t2.ty == Tpointer) { 486 i2 = MATCHnomatch; 487 } 488 } 489 490 if (i2 != MATCHnomatch) { 491 // goto Lt2; 492 e1 = e1.castTo(sc, t2, context); 493 t = t2; 494 if (type == null) { 495 type = t; 496 } 497 return this; 498 } else if (i1 != MATCHnomatch) { 499 // goto Lt1; 500 e2 = e2.castTo(sc, t1, context); 501 t = t1; 502 if (type == null) { 503 type = t; 504 } 505 return this; 506 } else if (t1.ty == Tclass && t2.ty == Tclass) { 507 TypeClass tc1 = (TypeClass) t1; 508 TypeClass tc2 = (TypeClass) t2; 509 510 /* Pick 'tightest' type 511 */ 512 ClassDeclaration cd1 = tc1.sym.baseClass; 513 ClassDeclaration cd2 = tc2.sym.baseClass; 514 515 if (cd1 != null && cd2 != null) { 516 t1 = cd1.type; 517 t2 = cd2.type; 518 } else if (cd1 != null) 519 t1 = cd1.type; 520 else if (cd2 != null) 521 t2 = cd2.type; 522 else { 523 // goto Lincompatible; 524 return typeCombine_Lincompatible_End(t, context); 525 } 526 } else { 527 return typeCombine_Lincompatible_End(t, context); 528 } 509 529 } 510 530 } else if ((e1.op == TOKstring || e1.op == TOKnull) trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java
r1165 r1167 391 391 ad = td.toParent().isAggregateDeclaration(); 392 392 } 393 /* Now that we have the right function f, we need to get the 394 * right 'this' pointer if f is in an outer class, but our 395 * existing 'this' pointer is in an inner class. 396 * This code is analogous to that used for variables 397 * in DotVarExp.semantic(). 398 */ 399 boolean loopL10 = true; 400 L10: while (loopL10) { 401 loopL10 = false; 402 Type t = ue.e1.type.toBasetype(context); 403 if (f.needThis() 404 && ad != null 405 && !(t.ty == Tpointer && t.next.ty == Tstruct && ((TypeStruct) t.next).sym == ad) 406 && !(t.ty == Tstruct && ((TypeStruct) t).sym == ad)) { 407 ClassDeclaration cd = ad.isClassDeclaration(); 408 ClassDeclaration tcd = t.isClassHandle(); 409 410 if (cd == null 411 || tcd == null 412 || !(tcd == cd || cd.isBaseOf(tcd, null, 413 context))) { 414 if (tcd != null && tcd.isNested()) { // Try again with outer scope 415 416 ue.e1 = new DotVarExp(loc, ue.e1, tcd.vthis); 417 ue.e1 = ue.e1.semantic(sc, context); 418 // goto L10; 419 loopL10 = true; 420 continue L10; 421 } 422 if (context.acceptsProblems()) { 423 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ThisForSymbolNeedsToBeType, this, new String[] { f.toChars(context), ad.toChars(context), t 424 .toChars(context) })); 425 } 426 } 427 } 393 394 if (f.needThis()) { 395 ue.e1 = getRightThis(loc, sc, ad, ue.e1, f, context); 428 396 } 429 397 trunk/descent.core/src/descent/internal/compiler/parser/DelegateExp.java
r1160 r1167 6 6 import static descent.internal.compiler.parser.TY.Tdelegate; 7 7 import static descent.internal.compiler.parser.TY.Tfunction; 8 import static descent.internal.compiler.parser.TY.Tpointer;9 import static descent.internal.compiler.parser.TY.Tstruct;10 8 11 9 … … 113 111 type = new TypeDelegate(func.type); 114 112 type = type.semantic(loc, sc, context); 115 // -----------------116 /* For func, we need to get the117 * right 'this' pointer if func is in an outer class, but our118 * existing 'this' pointer is in an inner class.119 * This code is analogous to that used for variables120 * in DotVarExp::semantic().121 */122 113 AggregateDeclaration ad = func.toParent().isAggregateDeclaration(); 123 124 boolean loop = true; 125 L10: while (loop) { 126 loop = false; 127 Type t = e1.type; 128 if (func.needThis() 129 && ad != null 130 && !(t.ty == Tpointer && t.next.ty == Tstruct && ((TypeStruct) t.next).sym == ad) 131 && !(t.ty == Tstruct && ((TypeStruct) t).sym == ad)) { 132 ClassDeclaration cd = ad.isClassDeclaration(); 133 ClassDeclaration tcd = t.isClassHandle(); 134 135 if (cd == null || tcd == null 136 || !(tcd == cd || cd.isBaseOf(tcd, null, context))) { 137 if (tcd != null && tcd.isNested()) { // Try again with outer scope 138 139 e1 = new DotVarExp(loc, e1, tcd.vthis); 140 e1 = e1.semantic(sc, context); 141 // goto L10; 142 loop = true; 143 continue L10; 144 } 145 if (context.acceptsProblems()) { 146 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ThisForSymbolNeedsToBeType, this, new String[] { func.toChars(context), ad.toChars(context), t 147 .toChars(context) })); 148 } 149 } 150 } 114 if (func.needThis()) { 115 e1 = getRightThis(loc, sc, ad, e1, func, context); 151 116 } 152 // -----------------153 117 } 154 118 return this; trunk/descent.core/src/descent/internal/compiler/parser/DotIdExp.java
r1160 r1167 199 199 return new TypeExp(loc, t); 200 200 } 201 202 TupleDeclaration tup = s.isTupleDeclaration(); 203 if (tup != null) 204 { 205 if (eleft != null) { 206 if (context.acceptsProblems()) { 207 context.acceptProblem(Problem.newSemanticTypeError(IProblem.CannotHaveEDotTuple, this)); 208 } 209 } 210 e = new TupleExp(loc, tup, context); 211 e = e.semantic(sc, context); 212 return e; 213 } 201 214 202 215 ScopeDsymbol sds = s.isScopeDsymbol(); trunk/descent.core/src/descent/internal/compiler/parser/DotVarExp.java
r1160 r1167 10 10 import static descent.internal.compiler.parser.TOK.TOKdsymbol; 11 11 import static descent.internal.compiler.parser.TOK.TOKthis; 12 13 import static descent.internal.compiler.parser.TY.Tpointer;14 import static descent.internal.compiler.parser.TY.Tstruct;15 12 16 13 … … 125 122 AggregateDeclaration ad = var.toParent() 126 123 .isAggregateDeclaration(); 127 128 boolean loop = true; 129 L1: while (loop) { 130 loop = false; 131 132 Type t = e1.type.toBasetype(context); 133 134 if (ad != null 135 && !(t.ty == Tpointer && t.next.ty == Tstruct && ((TypeStruct) t.next).sym == ad) 136 && !(t.ty == Tstruct && ((TypeStruct) t).sym == ad)) { 137 ClassDeclaration cd = ad.isClassDeclaration(); 138 ClassDeclaration tcd = t.isClassHandle(); 139 140 if (cd == null 141 || tcd == null 142 || !(tcd == cd || cd.isBaseOf(tcd, null, 143 context))) { 144 if (tcd != null && tcd.isNested()) { // Try again with outer scope 145 146 e1 = new DotVarExp(loc, e1, tcd.vthis); 147 e1 = e1.semantic(sc, context); 148 149 // Skip over nested functions, and get the enclosing 150 // class type. 151 Dsymbol s = tcd.toParent(); 152 while (s != null 153 && s.isFuncDeclaration() != null) { 154 FuncDeclaration f = s.isFuncDeclaration(); 155 if (f.vthis() != null) { 156 e1 = new VarExp(loc, f.vthis()); 157 } 158 s = s.toParent(); 159 } 160 if (s != null && s.isClassDeclaration() != null) { 161 e1.type = s.isClassDeclaration().type; 162 } 163 164 // goto L1; 165 loop = true; 166 continue L1; 167 } 168 if (context.acceptsProblems()) { 169 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ThisForSymbolNeedsToBeType, this, new String[] { var.toChars(context), ad.toChars(context), 170 t.toChars(context) })); 171 } 172 } 173 } 174 } 124 e1 = getRightThis(loc, sc, ad, e1, var, context); 175 125 accessCheck(sc, e1, var, context); 176 126 } trunk/descent.core/src/descent/internal/compiler/parser/Problem.java
r1165 r1167 1050 1050 case PostBlitsAreOnlyForStructUnionDefinitions: 1051 1051 return String.format(ProblemMessages.PostBlitsAreOnlyForStructUnionDefinitions); 1052 case CannotHaveEDotTuple: 1053 return String.format(ProblemMessages.CannotHaveEDotTuple); 1052 1054 default: 1053 1055 return ""; trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.java
r1165 r1167 472 472 public static String TypeofReturnMustBeInsideFunction; 473 473 public static String PostBlitsAreOnlyForStructUnionDefinitions; 474 public static String CannotHaveEDotTuple; 474 475 475 476 static { trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties
r1165 r1167 460 460 TypeofReturnMustBeInsideFunction=typeof(return) must be inside function 461 461 PostBlitsAreOnlyForStructUnionDefinitions=Post blits are only for struct/union definitions 462 CannotHaveEDotTuple=Cannot have e.tuple trunk/descent.core/src/descent/internal/compiler/parser/StructInitializer.java
r1160 r1167 83 83 context.acceptProblem(Problem.newSemanticTypeError(IProblem.TooManyInitializers, this, new String[] { ad.toChars(context) })); 84 84 } 85 field.remove(i); 86 i--; 85 87 continue; 86 88 } else { trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java
r1160 r1167 6 6 import melnorme.miscutil.tree.TreeVisitor; 7 7 import descent.core.IJavaElement; 8 import descent.core.compiler.CharOperation;9 8 import descent.core.compiler.IProblem; 10 9 import descent.internal.compiler.lookup.SemanticRest; … … 102 101 } 103 102 104 VarDeclaration v = new VarDeclaration( Loc.ZERO, tvp.valType,103 VarDeclaration v = new VarDeclaration(loc, tvp.valType, 105 104 tp.ident, init); 106 105 v.storage_class = STCconst; … … 655 654 Declaration[] sparam = { null }; 656 655 657 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, 658 sparam, context); 656 if (context.apiLevel == Parser.D2) { 657 // TODO Semantic fix this 658 // m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, sparam, (flag & 2) != 0 ? 1 : 0, context); 659 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, sparam, context); 660 } else { 661 m2 = tp.matchArg(paramscope, ti.tiargs, i, parameters, dedtypes, sparam, context); 662 } 659 663 660 664 if (m2 == MATCHnomatch) { trunk/descent.core/src/descent/internal/compiler/parser/TemplateParameter.java
r1160 r1167 39 39 return null; 40 40 } 41 42 public TemplateThisParameter isTemplateThisParameter() { 43 return null; 44 } 41 45 42 46 /** trunk/descent.core/src/descent/internal/compiler/parser/TemplateThisParameter.java
r1165 r1167 1 1 package descent.internal.compiler.parser; 2 3 2 4 3 public class TemplateThisParameter extends TemplateTypeParameter { 5 4 6 public TemplateThisParameter(Loc loc, IdentifierExp ident, Type specType, Type defaultType) { 5 public TemplateThisParameter(Loc loc, IdentifierExp ident, Type specType, 6 Type defaultType) { 7 7 super(loc, ident, specType, defaultType); 8 8 } 9 9 10 @Override 11 public TemplateThisParameter isTemplateThisParameter() { 12 return this; 13 } 14 15 @Override 16 public TemplateParameter syntaxCopy(SemanticContext context) { 17 TemplateThisParameter tp = new TemplateThisParameter(loc, ident, 18 specType, defaultType); 19 if (tp.specType != null) 20 tp.specType = specType.syntaxCopy(context); 21 if (defaultType != null) 22 tp.defaultType = defaultType.syntaxCopy(context); 23 tp.copySourceRange(this); 24 return tp; 25 } 26 27 @Override 28 public void toCBuffer(OutBuffer buf, HdrGenState hgs, SemanticContext context) { 29 buf.writestring("this "); 30 super.toCBuffer(buf, hgs, context); 31 } 32 10 33 } trunk/descent.core/src/descent/internal/compiler/parser/TemplateValueParameter.java
r1160 r1167 69 69 e = e.syntaxCopy(context); 70 70 e = e.semantic(sc, context); 71 if (context.apiLevel == Parser.D2) { 72 // TODO Semantic D2 73 // if (e.op == TOKdefault) 74 // { DefaultInitExp de = (DefaultInitExp) e; 75 // e = de.resolve(loc, sc, context); 76 // } 77 } 71 78 } 72 79 return e; trunk/descent.core/src/descent/internal/compiler/parser/TypeAArray.java
r1165 r1167 241 241 242 242 @Override 243 public void resolve(Loc loc, Scope sc, Expression[] pe, Type[] pt, Dsymbol[] ps, SemanticContext context) { 244 // Deal with the case where we thought the index was a type, but 245 // in reality it was an expression. 246 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray) { 247 Expression[] e = { null }; 248 Type[] t = { null }; 249 Dsymbol[] s = { null }; 250 251 index.resolve(loc, sc, e, t, s, context); 252 if (e[0] != null) { // It was an expression - 253 // Rewrite as a static array 254 255 TypeSArray tsa = new TypeSArray(next, e[0], context.encoder); 256 tsa.resolve(loc, sc, pe, pt, ps, context); 257 return; 258 } else if (t != null) { 259 index = t[0]; 260 } else { 261 if (context.acceptsProblems()) { 262 context.acceptProblem(Problem.newSemanticTypeError(IProblem.IndexIsNotATypeOrExpression, index)); 263 } 264 } 265 } 266 super.resolve(loc, sc, pe, pt, ps, context); 267 } 268 269 @Override 243 270 protected void appendSignature0(StringBuilder sb) { 244 271 sb.append('H'); trunk/descent.core/template/problem/problems.txt
r1165 r1167 1381 1381 PostBlitsAreOnlyForStructUnionDefinitions 1382 1382 formatString=Post blits are only for struct/union definitions 1383 numArgs=0 1384 CannotHaveEDotTuple 1385 formatString=Cannot have e.tuple 1383 1386 numArgs=0 1384 1387 … … 1391 1394 1392 1395 1393 1394
