Changeset 1161

Show
Ignore:
Timestamp:
05/10/08 14:17:41 (2 months ago)
Author:
asterite
Message:

Only one warning remains in phobos. :-)
Next... Tango!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1155 r1161  
    7070import descent.internal.compiler.parser.DotVarExp; 
    7171import descent.internal.compiler.parser.Dsymbol; 
     72import descent.internal.compiler.parser.DsymbolExp; 
    7273import descent.internal.compiler.parser.DsymbolTable; 
    7374import descent.internal.compiler.parser.Dsymbols; 
     
    15251526                this.endPosition = se.start + se.length; 
    15261527                completePackage((Package) se.sds, name, ident); 
    1527             } else if (se.sds instanceof TemplateMixin) { 
     1528            } else if (se.sds instanceof TemplateInstance) { 
    15281529                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; 
    15301541            } 
    15311542        } else if (e1 instanceof ThisExp) { 
  • trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java

    r1155 r1161  
    10401040                requestor.exitType(end); 
    10411041            } 
     1042        } else { 
     1043            requestor.exitType(end); 
    10421044        } 
    10431045        if (!node.wrapper) { 
  • trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java

    r1158 r1161  
    8484     * One ring to rule them all.  
    8585     */ 
    86     private final static boolean LAZY = true; 
     86    private final static boolean LAZY = false; 
    8787     
    8888    /* 
  • trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java

    r1160 r1161  
    621621            SemanticContext context) { 
    622622        if (e == null) { 
    623             if (context.acceptsProblems() &&  
    624                     (d.prot() == PROTprivate && d.getModule() != sc.module 
     623            if ((d.prot() == PROTprivate && d.getModule() != sc.module 
    625624                    || 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                } 
    629630            } 
    630631        } else if (e.type.ty == Tclass) { // Do access check 
     
    909910 
    910911                    // 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 &&  
    913913                            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                        } 
    916918                    } 
    917919                } 
     
    18431845     
    18441846    public void errorOnModifier(int problemId, TOK tok, SemanticContext context) { 
    1845         if (context.acceptsProblems()) { 
    1846             return; 
    1847         } 
    1848          
    18491847        boolean reported = false; 
    18501848         
     
    18521850            for (Modifier modifier : modifiers) { 
    18531851                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                    } 
    18561856                    reported = true; 
    18571857                } 
     
    18621862            for (Modifier modifier : extraModifiers) { 
    18631863                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                    } 
    18661868                    reported = true; 
    18671869                } 
     
    18701872         
    18711873        if (!reported) { 
    1872             context.acceptProblem(Problem.newSemanticTypeErrorLoc( 
    1873                     problemId, this)); 
     1874            if (context.acceptsProblems()) { 
     1875                context.acceptProblem(Problem.newSemanticTypeErrorLoc( 
     1876                        problemId, this)); 
     1877            } 
    18741878        } 
    18751879    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/AddrExp.java

    r1160 r1161  
    122122                    && !ve.var.isImportedSymbol()) { 
    123123                e = new SymOffExp(loc, ve.var, 0, context); 
     124                e.copySourceRange(ve); 
    124125                e.type = type; 
    125126                return e; 
     
    136137                    TypeSArray ts = (TypeSArray) ve.type; 
    137138                    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)) { 
    139140                        // 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                        } 
    147150                    } 
    148151                    e = new SymOffExp(loc, ve.var, index.multiply(ts.next 
  • trunk/descent.core/src/descent/internal/compiler/parser/AndAndExp.java

    r1160 r1161  
    122122        } else { 
    123123            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 
    126125                    && 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                } 
    130131            } 
    131132            if (e1.isConst()) { 
  • trunk/descent.core/src/descent/internal/compiler/parser/ArrayExp.java

    r1160 r1161  
    108108    @Override 
    109109    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            } 
    114115        } 
    115116        return this; 
  • trunk/descent.core/src/descent/internal/compiler/parser/ArrayInitializer.java

    r1160 r1161  
    135135            } 
    136136        } 
    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            } 
    140141        } 
    141142        return this; 
  • trunk/descent.core/src/descent/internal/compiler/parser/BinExp.java

    r1160 r1161  
    166166            e1.checkScalar(context); 
    167167            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                } 
    171173            } 
    172174            typeCombine(sc, context); 
  • trunk/descent.core/src/descent/internal/compiler/parser/CallExp.java

    r1160 r1161  
    565565                    te.td.consumeRest(); 
    566566                     
    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                    } 
    568575                    if (f == null) { 
    569576                        type = Type.terror; 
  • trunk/descent.core/src/descent/internal/compiler/parser/CmpExp.java

    r1160 r1161  
    7777        super.semanticp(sc, context); 
    7878         
    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 || 
    8180                e2.type.toBasetype(context).ty == Tclass && e1.op == TOKnull) 
    8281        { 
    83             context.acceptProblem(Problem.newSemanticTypeError(IProblem.DoNotUseNullWhenComparingClassTypes, this)); 
     82            if (context.acceptsProblems()) { 
     83                context.acceptProblem(Problem.newSemanticTypeError(IProblem.DoNotUseNullWhenComparingClassTypes, this)); 
     84            } 
    8485        } 
    8586         
  • trunk/descent.core/src/descent/internal/compiler/parser/CompileDeclaration.java

    r1160 r1161  
    8282 
    8383        // 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); 
    9290            } 
    9391        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/CompileExp.java

    r1160 r1161  
    4747         
    4848        // 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); 
    5755            } 
    5856        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/CompileStatement.java

    r1160 r1161  
    7474         
    7575        // 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); 
    8482            } 
    8583        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/DsymbolExp.java

    r1160 r1161  
    121121                } 
    122122                e = new VarExp(loc, v); 
    123                 e.start = start; 
    124                 e.length = length; 
     123                e.copySourceRange(this); 
    125124                e.type = type; 
    126125                e = e.semantic(sc, context); 
     
    134133            f = s.isFuncDeclaration(); 
    135134            if (f != null) { 
    136                 return new VarExp(loc, f); 
     135                VarExp ve = new VarExp(loc, f); 
     136                ve.copySourceRange(this); 
     137                return ve; 
    137138            } 
    138139            cd = s.isClassDeclaration(); 
  • trunk/descent.core/src/descent/internal/compiler/parser/EqualExp.java

    r1160 r1161  
    102102        } 
    103103         
    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 || 
    106105                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            } 
    108109        } 
    109110 
  • trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java

    r1160 r1161  
    304304                        } 
    305305                    } 
     306                     
     307                    if (sym instanceof TemplateDeclaration) { 
     308                        sym = ((TemplateDeclaration) sym).members.get(0); 
     309                    } 
     310                     
    306311                    FuncDeclaration func = (FuncDeclaration) sym; 
    307312                    func.semantic(scope.enclosing, context); 
  • trunk/descent.core/src/descent/internal/compiler/parser/IdentifierExp.java

    r1160 r1161  
    154154                } 
    155155                e = new DsymbolExp(loc, s); 
    156                 e.start = start; 
    157                 e.length = length; 
     156                e.copySourceRange(this); 
    158157            } 
    159158             
  • trunk/descent.core/src/descent/internal/compiler/parser/Problem.java

    r1158 r1161  
    9494    } 
    9595     
    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) { 
    9797        return newSemanticTypeProblem(id, line, start, length, arguments, false); 
    9898    } 
    9999     
    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) { 
    101101        return newSemanticTypeWarning(id, line, start, length, null); 
    102102    } 
    103103     
    104     public static IProblem newSemanticTypeWarning(int id, ASTDmdNode node) { 
     104    public static Problem newSemanticTypeWarning(int id, ASTDmdNode node) { 
    105105        return newSemanticTypeWarning(id, node.getLineNumber(), node.getStart(), node.getLength(), null); 
    106106    } 
    107107     
    108     public static IProblem newSemanticTypeWarningLoc(int id, ASTDmdNode node) { 
     108    public static Problem newSemanticTypeWarningLoc(int id, ASTDmdNode node) { 
    109109        return newSemanticTypeWarning(id, node.getLineNumber(), node.getErrorStart(), node.getErrorLength(), null); 
    110110    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/SemanticContext.java

    r1154 r1161  
    22 
    33import java.io.File; 
     4import java.util.ArrayList; 
    45import java.util.HashMap; 
     6import java.util.LinkedList; 
     7import java.util.List; 
    58import java.util.Map; 
     9import java.util.Stack; 
    610 
    711import org.eclipse.core.runtime.Assert; 
     
    8185     
    8286    public final ASTNodeEncoder encoder; 
     87    private final List<ASTDmdNode> templateEvaluationStack; 
    8388     
    8489    /* 
     
    104109        this.Type_tvoidptr = Type.tvoid.pointerTo(this); 
    105110        this.encoder = encoder; 
     111        this.templateEvaluationStack = new LinkedList<ASTDmdNode>(); 
    106112        this.apiLevel = Util.getApiLevel(project); 
    107113         
     
    181187    } 
    182188 
    183     public void acceptProblem(IProblem problem) { 
     189    public void acceptProblem(Problem problem) { 
    184190        // Don't report more problems if fatal was signaled 
    185191        if (fatalWasSignaled) { 
     
    189195        if (global.gag == 0 && muteProblems == 0 && problemRequestor != null) { 
    190196//          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             
    191204            problemRequestor.acceptProblem(problem); 
    192205        } 
     
    226239        } 
    227240        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); 
    228250    } 
    229251     
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java

    r1160 r1161  
    685685        // Copy the syntax trees from the TemplateDeclaration 
    686686        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(); 
    784792        } 
    785793    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java

    r1160 r1161  
    260260            } 
    261261        } 
    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); 
    270262         
    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