Changeset 1161
- Timestamp:
- 05/10/08 14:17:41 (2 months ago)
- Files:
-
- trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java (modified) (6 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/AddrExp.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/AndAndExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ArrayExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ArrayInitializer.java (modified) (1 diff)
- 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/CmpExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/CompileDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/CompileExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/CompileStatement.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/DsymbolExp.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/EqualExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/IdentifierExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Problem.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/SemanticContext.java (modified) (6 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Type.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TypeFunction.java (modified) (6 diffs)
- trunk/descent.core/src/descent/internal/core/CompilerConfiguration.java (modified) (4 diffs)
- trunk/descent.core/src/descent/internal/core/InternalSignature.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java
r1155 r1161 70 70 import descent.internal.compiler.parser.DotVarExp; 71 71 import descent.internal.compiler.parser.Dsymbol; 72 import descent.internal.compiler.parser.DsymbolExp; 72 73 import descent.internal.compiler.parser.DsymbolTable; 73 74 import descent.internal.compiler.parser.Dsymbols; … … 1525 1526 this.endPosition = se.start + se.length; 1526 1527 completePackage((Package) se.sds, name, ident); 1527 } else if (se.sds instanceof Template Mixin) {1528 } else if (se.sds instanceof TemplateInstance) { 1528 1529 currentName = computePrefixAndSourceRange(ident); 1529 suggestMembers(((TemplateMixin) se.sds).members, false, 0, new HashtableOfCharArrayAndObject(), INCLUDE_ALL); 1530 options.checkVisibility = false; 1531 suggestMembers(((TemplateInstance) se.sds).members, false, 0, new HashtableOfCharArrayAndObject(), INCLUDE_ALL); 1532 options.checkVisibility = true; 1533 } 1534 } else if (e1 instanceof DsymbolExp) { 1535 DsymbolExp de = (DsymbolExp) e1; 1536 if (de.s instanceof TemplateInstance) { 1537 currentName = computePrefixAndSourceRange(ident); 1538 options.checkVisibility = false; 1539 suggestMembers(((TemplateInstance) de.s).members, false, 0, new HashtableOfCharArrayAndObject(), INCLUDE_ALL); 1540 options.checkVisibility = true; 1530 1541 } 1531 1542 } else if (e1 instanceof ThisExp) { trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java
r1155 r1161 1040 1040 requestor.exitType(end); 1041 1041 } 1042 } else { 1043 requestor.exitType(end); 1042 1044 } 1043 1045 if (!node.wrapper) { trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java
r1158 r1161 84 84 * One ring to rule them all. 85 85 */ 86 private final static boolean LAZY = true;86 private final static boolean LAZY = false; 87 87 88 88 /* trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java
r1160 r1161 621 621 SemanticContext context) { 622 622 if (e == null) { 623 if (context.acceptsProblems() && 624 (d.prot() == PROTprivate && d.getModule() != sc.module 623 if ((d.prot() == PROTprivate && d.getModule() != sc.module 625 624 || d.prot() == PROTpackage && !hasPackageAccess(sc, d))) { 626 context.acceptProblem(Problem.newSemanticTypeError(IProblem.SymbolIsNotAccessible, this, new String[] { d.kind(), d 627 .getModule().toChars(context), d.toChars(context), 628 sc.module.toChars(context) })); 625 if (context.acceptsProblems()) { 626 context.acceptProblem(Problem.newSemanticTypeError(IProblem.SymbolIsNotAccessible, this, new String[] { d.kind(), d 627 .getModule().toChars(context), d.toChars(context), 628 sc.module.toChars(context) })); 629 } 629 630 } 630 631 } else if (e.type.ty == Tclass) { // Do access check … … 909 910 910 911 // Don't have a way yet to do a pointer to a bit in array 911 if (context.acceptsProblems() && 912 arg.op == TOKarray && 912 if (arg.op == TOKarray && 913 913 arg.type.toBasetype(context).ty == Tbit) { 914 context.acceptProblem(Problem.newSemanticTypeError( 915 IProblem.CannotHaveOutOrInoutArgumentOfBitInArray, this)); 914 if (context.acceptsProblems()) { 915 context.acceptProblem(Problem.newSemanticTypeError( 916 IProblem.CannotHaveOutOrInoutArgumentOfBitInArray, this)); 917 } 916 918 } 917 919 } … … 1843 1845 1844 1846 public void errorOnModifier(int problemId, TOK tok, SemanticContext context) { 1845 if (context.acceptsProblems()) {1846 return;1847 }1848 1849 1847 boolean reported = false; 1850 1848 … … 1852 1850 for (Modifier modifier : modifiers) { 1853 1851 if (modifier.tok == tok) { 1854 context.acceptProblem(Problem.newSemanticTypeError( 1855 problemId, modifier)); 1852 if (context.acceptsProblems()) { 1853 context.acceptProblem(Problem.newSemanticTypeError( 1854 problemId, modifier)); 1855 } 1856 1856 reported = true; 1857 1857 } … … 1862 1862 for (Modifier modifier : extraModifiers) { 1863 1863 if (modifier.tok == tok) { 1864 context.acceptProblem(Problem.newSemanticTypeError( 1865 problemId, modifier)); 1864 if (context.acceptsProblems()) { 1865 context.acceptProblem(Problem.newSemanticTypeError( 1866 problemId, modifier)); 1867 } 1866 1868 reported = true; 1867 1869 } … … 1870 1872 1871 1873 if (!reported) { 1872 context.acceptProblem(Problem.newSemanticTypeErrorLoc( 1873 problemId, this)); 1874 if (context.acceptsProblems()) { 1875 context.acceptProblem(Problem.newSemanticTypeErrorLoc( 1876 problemId, this)); 1877 } 1874 1878 } 1875 1879 } trunk/descent.core/src/descent/internal/compiler/parser/AddrExp.java
r1160 r1161 122 122 && !ve.var.isImportedSymbol()) { 123 123 e = new SymOffExp(loc, ve.var, 0, context); 124 e.copySourceRange(ve); 124 125 e.type = type; 125 126 return e; … … 136 137 TypeSArray ts = (TypeSArray) ve.type; 137 138 integer_t dim = ts.dim.toInteger(context); 138 if ( context.acceptsProblems() &&(index.compareTo(0) < 0 || index.compareTo(dim) >= 0)) {139 if ((index.compareTo(0) < 0 || index.compareTo(dim) >= 0)) { 139 140 // PERHAPS test this error 140 context.acceptProblem(Problem.newSemanticTypeError( 141 IProblem.ArrayIndexOutOfBounds, 142 this, 143 new String[] { 144 String.valueOf(index), 145 String.valueOf(dim), 146 })); 141 if (context.acceptsProblems()) { 142 context.acceptProblem(Problem.newSemanticTypeError( 143 IProblem.ArrayIndexOutOfBounds, 144 this, 145 new String[] { 146 String.valueOf(index), 147 String.valueOf(dim), 148 })); 149 } 147 150 } 148 151 e = new SymOffExp(loc, ve.var, index.multiply(ts.next trunk/descent.core/src/descent/internal/compiler/parser/AndAndExp.java
r1160 r1161 122 122 } else { 123 123 e2 = e2.optimize(WANTflags | (result & WANTinterpret), context); 124 if (context.acceptsProblems() && 125 result > 0 && e2.type.toBasetype(context).ty == Tvoid 124 if (result > 0 && e2.type.toBasetype(context).ty == Tvoid 126 125 && context.global.errors <= 0) { 127 context.acceptProblem(Problem.newSemanticTypeError( 128 IProblem.SymbolHasNoValue, this, 129 new String[] { "void" })); 126 if (context.acceptsProblems()) { 127 context.acceptProblem(Problem.newSemanticTypeError( 128 IProblem.SymbolHasNoValue, this, 129 new String[] { "void" })); 130 } 130 131 } 131 132 if (e1.isConst()) { trunk/descent.core/src/descent/internal/compiler/parser/ArrayExp.java
r1160 r1161 108 108 @Override 109 109 public Expression toLvalue(Scope sc, Expression e, SemanticContext context) { 110 if (context.acceptsProblems() && 111 (type != null) && (type.toBasetype(context).ty == TY.Tvoid)) { 112 context.acceptProblem(Problem.newSemanticTypeError( 113 IProblem.VoidsHaveNoValue, this)); 110 if ((type != null) && (type.toBasetype(context).ty == TY.Tvoid)) { 111 if (context.acceptsProblems()) { 112 context.acceptProblem(Problem.newSemanticTypeError( 113 IProblem.VoidsHaveNoValue, this)); 114 } 114 115 } 115 116 return this; trunk/descent.core/src/descent/internal/compiler/parser/ArrayInitializer.java
r1160 r1161 135 135 } 136 136 } 137 if (context.acceptsProblems() && 138 new integer_t(dim).multiply(t.next.size(context)).compareTo(amax) >= 0) { 139 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ArrayDimensionExceedsMax, this, new String[] { String.valueOf(dim), amax.divide(t.next.size(context)).toString() })); 137 if (new integer_t(dim).multiply(t.next.size(context)).compareTo(amax) >= 0) { 138 if (context.acceptsProblems()) { 139 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ArrayDimensionExceedsMax, this, new String[] { String.valueOf(dim), amax.divide(t.next.size(context)).toString() })); 140 } 140 141 } 141 142 return this; trunk/descent.core/src/descent/internal/compiler/parser/BinExp.java
r1160 r1161 166 166 e1.checkScalar(context); 167 167 type = e1.type; 168 if (context.acceptsProblems() && type.toBasetype(context).ty == Tbool) { 169 context.acceptProblem(Problem.newSemanticTypeError( 170 IProblem.OperatorNotAllowedOnBoolExpression, this, new String[] { toChars(context) })); 168 if (type.toBasetype(context).ty == Tbool) { 169 if (context.acceptsProblems()) { 170 context.acceptProblem(Problem.newSemanticTypeError( 171 IProblem.OperatorNotAllowedOnBoolExpression, this, new String[] { toChars(context) })); 172 } 171 173 } 172 174 typeCombine(sc, context); trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java
r1160 r1161 565 565 te.td.consumeRest(); 566 566 567 f = te.td.deduceFunctionTemplate(sc, loc, null, arguments, context); 567 // Descent: temporary adjust error position so errors doesn't 568 // appear inside templates, but always on the invocation site 569 context.startTemplateEvaluation(this); 570 try { 571 f = te.td.deduceFunctionTemplate(sc, loc, null, arguments, context); 572 } finally { 573 context.endTemplateEvaluation(); 574 } 568 575 if (f == null) { 569 576 type = Type.terror; trunk/descent.core/src/descent/internal/compiler/parser/CmpExp.java
r1160 r1161 77 77 super.semanticp(sc, context); 78 78 79 if (context.acceptsProblems() && 80 e1.type.toBasetype(context).ty == Tclass && e2.op == TOKnull || 79 if (e1.type.toBasetype(context).ty == Tclass && e2.op == TOKnull || 81 80 e2.type.toBasetype(context).ty == Tclass && e1.op == TOKnull) 82 81 { 83 context.acceptProblem(Problem.newSemanticTypeError(IProblem.DoNotUseNullWhenComparingClassTypes, this)); 82 if (context.acceptsProblems()) { 83 context.acceptProblem(Problem.newSemanticTypeError(IProblem.DoNotUseNullWhenComparingClassTypes, this)); 84 } 84 85 } 85 86 trunk/descent.core/src/descent/internal/compiler/parser/CompileDeclaration.java
r1160 r1161 82 82 83 83 // TODO semantic do this better 84 if (context.acceptsProblems()) { 85 if (p.problems != null) { 86 for (int i = 0; i < p.problems.size(); i++) { 87 Problem problem = (Problem) p.problems.get(i); 88 problem.setSourceStart(start); 89 problem.setSourceEnd(start + length - 1); 90 context.acceptProblem(problem); 91 } 84 if (p.problems != null) { 85 for (int i = 0; i < p.problems.size(); i++) { 86 Problem problem = (Problem) p.problems.get(i); 87 problem.setSourceStart(start); 88 problem.setSourceEnd(start + length - 1); 89 context.acceptProblem(problem); 92 90 } 93 91 } trunk/descent.core/src/descent/internal/compiler/parser/CompileExp.java
r1160 r1161 47 47 48 48 // TODO semantic do this better 49 if (context.acceptsProblems()) { 50 if (p.problems != null) { 51 for (int i = 0; i < p.problems.size(); i++) { 52 Problem problem = (Problem) p.problems.get(i); 53 problem.setSourceStart(start); 54 problem.setSourceEnd(start + length - 1); 55 context.acceptProblem(problem); 56 } 49 if (p.problems != null) { 50 for (int i = 0; i < p.problems.size(); i++) { 51 Problem problem = (Problem) p.problems.get(i); 52 problem.setSourceStart(start); 53 problem.setSourceEnd(start + length - 1); 54 context.acceptProblem(problem); 57 55 } 58 56 } trunk/descent.core/src/descent/internal/compiler/parser/CompileStatement.java
r1160 r1161 74 74 75 75 // TODO semantic do this better 76 if (context.acceptsProblems()) { 77 if (p.problems != null) { 78 for (int i = 0; i < p.problems.size(); i++) { 79 Problem problem = (Problem) p.problems.get(i); 80 problem.setSourceStart(start); 81 problem.setSourceEnd(start + length - 1); 82 context.acceptProblem(problem); 83 } 76 if (p.problems != null) { 77 for (int i = 0; i < p.problems.size(); i++) { 78 Problem problem = (Problem) p.problems.get(i); 79 problem.setSourceStart(start); 80 problem.setSourceEnd(start + length - 1); 81 context.acceptProblem(problem); 84 82 } 85 83 } trunk/descent.core/src/descent/internal/compiler/parser/DsymbolExp.java
r1160 r1161 121 121 } 122 122 e = new VarExp(loc, v); 123 e.start = start; 124 e.length = length; 123 e.copySourceRange(this); 125 124 e.type = type; 126 125 e = e.semantic(sc, context); … … 134 133 f = s.isFuncDeclaration(); 135 134 if (f != null) { 136 return new VarExp(loc, f); 135 VarExp ve = new VarExp(loc, f); 136 ve.copySourceRange(this); 137 return ve; 137 138 } 138 139 cd = s.isClassDeclaration(); trunk/descent.core/src/descent/internal/compiler/parser/EqualExp.java
r1160 r1161 102 102 } 103 103 104 if (context.acceptsProblems() && 105 (e1.type.toBasetype(context).ty == Tclass && e2.op == TOKnull || 104 if ((e1.type.toBasetype(context).ty == Tclass && e2.op == TOKnull || 106 105 e2.type.toBasetype(context).ty == Tclass && e1.op == TOKnull)) { 107 context.acceptProblem(Problem.newSemanticTypeError(IProblem.UseTokenInsteadOfTokenWhenComparingWithNull, this, new String[] { op == TOKequal ? "is" : "!is", op.toString() })); 106 if (context.acceptsProblems()) { 107 context.acceptProblem(Problem.newSemanticTypeError(IProblem.UseTokenInsteadOfTokenWhenComparingWithNull, this, new String[] { op == TOKequal ? "is" : "!is", op.toString() })); 108 } 108 109 } 109 110 trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java
r1160 r1161 304 304 } 305 305 } 306 307 if (sym instanceof TemplateDeclaration) { 308 sym = ((TemplateDeclaration) sym).members.get(0); 309 } 310 306 311 FuncDeclaration func = (FuncDeclaration) sym; 307 312 func.semantic(scope.enclosing, context); trunk/descent.core/src/descent/internal/compiler/parser/IdentifierExp.java
r1160 r1161 154 154 } 155 155 e = new DsymbolExp(loc, s); 156 e.start = start; 157 e.length = length; 156 e.copySourceRange(this); 158 157 } 159 158 trunk/descent.core/src/descent/internal/compiler/parser/Problem.java
r1158 r1161 94 94 } 95 95 96 public static IProblem newSemanticTypeWarning(int id, int line, int start, int length, String[] arguments) {96 public static Problem newSemanticTypeWarning(int id, int line, int start, int length, String[] arguments) { 97 97 return newSemanticTypeProblem(id, line, start, length, arguments, false); 98 98 } 99 99 100 public static IProblem newSemanticTypeWarning(int id, int line, int start, int length) {100 public static Problem newSemanticTypeWarning(int id, int line, int start, int length) { 101 101 return newSemanticTypeWarning(id, line, start, length, null); 102 102 } 103 103 104 public static IProblem newSemanticTypeWarning(int id, ASTDmdNode node) {104 public static Problem newSemanticTypeWarning(int id, ASTDmdNode node) { 105 105 return newSemanticTypeWarning(id, node.getLineNumber(), node.getStart(), node.getLength(), null); 106 106 } 107 107 108 public static IProblem newSemanticTypeWarningLoc(int id, ASTDmdNode node) {108 public static Problem newSemanticTypeWarningLoc(int id, ASTDmdNode node) { 109 109 return newSemanticTypeWarning(id, node.getLineNumber(), node.getErrorStart(), node.getErrorLength(), null); 110 110 } trunk/descent.core/src/descent/internal/compiler/parser/SemanticContext.java
r1154 r1161 2 2 3 3 import java.io.File; 4 import java.util.ArrayList; 4 5 import java.util.HashMap; 6 import java.util.LinkedList; 7 import java.util.List; 5 8 import java.util.Map; 9 import java.util.Stack; 6 10 7 11 import org.eclipse.core.runtime.Assert; … … 81 85 82 86 public final ASTNodeEncoder encoder; 87 private final List<ASTDmdNode> templateEvaluationStack; 83 88 84 89 /* … … 104 109 this.Type_tvoidptr = Type.tvoid.pointerTo(this); 105 110 this.encoder = encoder; 111 this.templateEvaluationStack = new LinkedList<ASTDmdNode>(); 106 112 this.apiLevel = Util.getApiLevel(project); 107 113 … … 181 187 } 182 188 183 public void acceptProblem( IProblem problem) {189 public void acceptProblem(Problem problem) { 184 190 // Don't report more problems if fatal was signaled 185 191 if (fatalWasSignaled) { … … 189 195 if (global.gag == 0 && muteProblems == 0 && problemRequestor != null) { 190 196 // System.out.println("~~~" + problem); 197 198 if (!templateEvaluationStack.isEmpty()) { 199 ASTDmdNode target = templateEvaluationStack.get(0); 200 problem.setSourceStart(target.start); 201 problem.setSourceEnd(target.start + target.length - 1); 202 } 203 191 204 problemRequestor.acceptProblem(problem); 192 205 } … … 226 239 } 227 240 return fd; 241 } 242 243 244 public void startTemplateEvaluation(ASTDmdNode node) { 245 this.templateEvaluationStack.add(node); 246 } 247 248 public void endTemplateEvaluation() { 249 this.templateEvaluationStack.remove(this.templateEvaluationStack.size() - 1); 228 250 } 229 251 trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java
r1160 r1161 685 685 // Copy the syntax trees from the TemplateDeclaration 686 686 members = Dsymbol.arraySyntaxCopy(tempdecl.members, context); 687 688 // Create our own scope for the template parameters 689 Scope scope = tempdecl.scope; 690 if (null == scope) { 691 if (context.acceptsProblems()) { 692 context.acceptProblem(Problem.newSemanticTypeError( 693 IProblem.ForwardReferenceToTemplateDeclaration, this, new String[] { tempdecl.toChars(context) })); 694 } 695 return; 696 } 697 argsym = new ScopeDsymbol(); 698 argsym.parent = scope.parent; 699 scope = scope.push(argsym); 700 701 // Declare each template parameter as an alias for the argument type 702 declareParameters(scope, context); 703 704 // Add members of template instance to template instance symbol table 705 // parent = scope.scopesym; 706 symtab = new DsymbolTable(); 707 int memnum = 0; 708 for (int i = 0; i < members.size(); i++) { 709 Dsymbol s = members.get(i); 710 memnum |= s.addMember(scope, this, memnum, context); 711 } 712 713 /* See if there is only one member of template instance, and that 714 * member has the same name as the template instance. 715 * If so, this template instance becomes an alias for that member. 716 */ 717 if (members.size() > 0) { 718 Dsymbol[] s = new Dsymbol[] { null }; 719 if (Dsymbol.oneMembers(members, s, context) && null != s[0]) { 720 if (null != s[0].ident && equals(s[0].ident, tempdecl.ident)) { 721 aliasdecl = new AliasDeclaration(loc, s[0].ident, s[0]); 722 723 // Descent 724 aliasdecl.isTemplateParameter = true; 725 } 726 } 727 } 728 729 // Do semantic() analysis on template instance members 730 Scope sc2; 731 sc2 = scope.push(this); 732 sc2.parent = /*isnested ? sc.parent :*/this; 733 734 for (int i = 0; i < members.size(); i++) { 735 Dsymbol s = members.get(i); 736 s.semantic(sc2, context); 737 sc2.module.runDeferredSemantic(context); 738 } 739 740 /* If any of the instantiation members didn't get semantic() run 741 * on them due to forward references, we cannot run semantic2() 742 * or semantic3() yet. 743 */ 744 boolean gotoLaftersemantic = false; 745 for (int j = 0; j < size(context.Module_deferred); j++) { 746 Dsymbol sd = (Dsymbol) context.Module_deferred.get(j); 747 748 if (sd.parent == this) { 749 gotoLaftersemantic = true; 750 } 751 } 752 753 /* The problem is when to parse the initializer for a variable. 754 * Perhaps VarDeclaration.semantic() should do it like it does 755 * for initializers inside a function. 756 */ 757 // if (sc.parent.isFuncDeclaration()) 758 /* BUG 782: this has problems if the classes this depends on 759 * are forward referenced. Find a way to defer semantic() 760 * on this template. 761 */ 762 if (!gotoLaftersemantic) { 763 semantic2(sc2, context); 764 765 if (null != sc.func || dosemantic3 > 0) { 766 semantic3(sc2, context); 767 } 768 } 769 770 //Laftersemantic: 771 sc2.pop(); 772 773 scope.pop(); 774 775 // Give additional context info if error occurred during instantiation 776 if (context.global.errors != errorsave) { 777 if (context.acceptsProblems()) { 778 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ErrorInstantiating, this)); 779 } 780 errors = 1; 781 if (context.global.gag > 0) { 782 tempdecl.instances.remove(tempdecl_instance_idx); 783 } 687 688 // Descent: temporary adjust error position so errors doesn't 689 // appear inside templates, but always on the invocation site 690 context.startTemplateEvaluation(this); 691 692 try { 693 // Create our own scope for the template parameters 694 Scope scope = tempdecl.scope; 695 if (null == scope) { 696 if (context.acceptsProblems()) { 697 context.acceptProblem(Problem.newSemanticTypeError( 698 IProblem.ForwardReferenceToTemplateDeclaration, this, new String[] { tempdecl.toChars(context) })); 699 } 700 return; 701 } 702 argsym = new ScopeDsymbol(); 703 argsym.parent = scope.parent; 704 scope = scope.push(argsym); 705 706 // Declare each template parameter as an alias for the argument type 707 declareParameters(scope, context); 708 709 // Add members of template instance to template instance symbol table 710 // parent = scope.scopesym; 711 symtab = new DsymbolTable(); 712 int memnum = 0; 713 for (int i = 0; i < members.size(); i++) { 714 Dsymbol s = members.get(i); 715 memnum |= s.addMember(scope, this, memnum, context); 716 } 717 718 /* See if there is only one member of template instance, and that 719 * member has the same name as the template instance. 720 * If so, this template instance becomes an alias for that member. 721 */ 722 if (members.size() > 0) { 723 Dsymbol[] s = new Dsymbol[] { null }; 724 if (Dsymbol.oneMembers(members, s, context) && null != s[0]) { 725 if (null != s[0].ident && equals(s[0].ident, tempdecl.ident)) { 726 aliasdecl = new AliasDeclaration(loc, s[0].ident, s[0]); 727 728 // Descent 729 aliasdecl.isTemplateParameter = true; 730 } 731 } 732 } 733 734 // Do semantic() analysis on template instance members 735 Scope sc2; 736 sc2 = scope.push(this); 737 sc2.parent = /*isnested ? sc.parent :*/this; 738 739 for (int i = 0; i < members.size(); i++) { 740 Dsymbol s = members.get(i); 741 s.semantic(sc2, context); 742 sc2.module.runDeferredSemantic(context); 743 } 744 745 /* If any of the instantiation members didn't get semantic() run 746 * on them due to forward references, we cannot run semantic2() 747 * or semantic3() yet. 748 */ 749 boolean gotoLaftersemantic = false; 750 for (int j = 0; j < size(context.Module_deferred); j++) { 751 Dsymbol sd = (Dsymbol) context.Module_deferred.get(j); 752 753 if (sd.parent == this) { 754 gotoLaftersemantic = true; 755 } 756 } 757 758 /* The problem is when to parse the initializer for a variable. 759 * Perhaps VarDeclaration.semantic() should do it like it does 760 * for initializers inside a function. 761 */ 762 // if (sc.parent.isFuncDeclaration()) 763 /* BUG 782: this has problems if the classes this depends on 764 * are forward referenced. Find a way to defer semantic() 765 * on this template. 766 */ 767 if (!gotoLaftersemantic) { 768 semantic2(sc2, context); 769 770 if (null != sc.func || dosemantic3 > 0) { 771 semantic3(sc2, context); 772 } 773 } 774 775 //Laftersemantic: 776 sc2.pop(); 777 778 scope.pop(); 779 780 // Give additional context info if error occurred during instantiation 781 if (context.global.errors != errorsave) { 782 if (context.acceptsProblems()) { 783 context.acceptProblem(Problem.newSemanticTypeError(IProblem.ErrorInstantiating, this)); 784 } 785 errors = 1; 786 if (context.global.gag > 0) { 787 tempdecl.instances.remove(tempdecl_instance_idx); 788 } 789 } 790 } finally { 791 context.endTemplateEvaluation(); 784 792 } 785 793 } trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java
r1160 r1161 260 260 } 261 261 } 262 263 Scope scy = sc;264 scy = sc.push(this);265 scy.parent = this;266 267 argsym = new ScopeDsymbol();268 argsym.parent = scy.parent;269 Scope scope = scy.push(argsym);270 262 271 int errorsave = context.global.errors; 272 273 // Declare each template parameter as an alias for the argument type 274 declareParameters(scope, context); 275 276 // Add members to enclosing scope, as well as this scope 277 for (int i = 0; i < members.size(); i++) { 278 Dsymbol s; 279 280 s = members.get(i); 281 s.addMember(scope, this, i, context); 282 //sc.insert(s); 283 //printf("sc.parent = %p, sc.scopesym = %p\n", sc.parent, sc.scopesym); 284 //printf("s.parent = %s\n", s.parent.toChars()); 285 } 286 287 // Do semantic() analysis on template instance members 288 Scope sc2; 289 sc2 = scope.push(this); 290 sc2.offset = sc.offset; 291 for (int i = 0; i < members.size(); i++) { 292 Dsymbol s = members.get(i); 293 s.semantic(sc2, context);&n
