Changeset 1155

Show
Ignore:
Timestamp:
05/04/08 22:32:49 (8 months ago)
Author:
asterite
Message:

template.c ported to DMD 1.028.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/core/compiler/IProblem.java

    r1120 r1155  
    640640    int CannotDeclareTemplateAtFunctionScope = 429; 
    641641    int TemplateHasNoValue = 430; 
    642     int InconsistentNestingLevels = 431; 
    643     int CannotUseLocalAsTemplateParameter = 432; 
    644     int NoSizeForType = 433; 
    645     int SymbolDotSymbolIsNotADeclaration = 434; 
    646     int ThisIsRequiredButIsNotABaseClassOf = 435; 
    647     int ForwardReferenceToSymbol = 436; 
    648     int IdentifierOfSymbolIsNotDefined = 437; 
    649     int StructIsForwardReferenced = 438; 
    650     int CannotUseTemplateToAddFieldToAggregate = 439; 
    651     int CannotModifyFinalVariable = 440; 
    652     int InvalidUtf8Sequence2 = 441; 
    653     int Utf16HighValuePastEndOfString = 442; 
    654     int Utf16LowValueOutOfRange = 443; 
    655     int UnpairedUtf16Value = 444; 
    656     int IllegalUtf16Value = 445; 
    657     int StaticConstructorCanOnlyBePartOfStructClassModule = 446; 
    658     int ShiftAssignIsOutsideTheRange = 447; 
     642    int CannotUseLocalAsTemplateParameter = 431; 
     643    int NoSizeForType = 432; 
     644    int SymbolDotSymbolIsNotADeclaration = 433; 
     645    int ThisIsRequiredButIsNotABaseClassOf = 434; 
     646    int ForwardReferenceToSymbol = 435; 
     647    int IdentifierOfSymbolIsNotDefined = 436; 
     648    int StructIsForwardReferenced = 437; 
     649    int CannotUseTemplateToAddFieldToAggregate = 438; 
     650    int CannotModifyFinalVariable = 439; 
     651    int InvalidUtf8Sequence2 = 440; 
     652    int Utf16HighValuePastEndOfString = 441; 
     653    int Utf16LowValueOutOfRange = 442; 
     654    int UnpairedUtf16Value = 443; 
     655    int IllegalUtf16Value = 444; 
     656    int StaticConstructorCanOnlyBePartOfStructClassModule = 445; 
     657    int ShiftAssignIsOutsideTheRange = 446; 
     658    int TemplateTupleParameterMustBeLastOne = 447; 
     659    int SymbolIsNestedInBoth = 448; 
    659660 
    660661} 
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1154 r1155  
    334334        } 
    335335         
    336 //        long time = System.currentTimeMillis(); 
     336      long time = System.currentTimeMillis(); 
    337337         
    338338        this.requestor.beginReporting(); 
     
    429429            this.requestor.endReporting(); 
    430430             
    431 //            time = System.currentTimeMillis() - time; 
     431          time = System.currentTimeMillis() - time; 
    432432//          System.out.println("Completion took " + time + " milliseconds to complete."); 
    433433        } 
  • trunk/descent.core/src/descent/internal/compiler/SourceElementParser.java

    r1141 r1155  
    417417    @Override 
    418418    public boolean visit(TemplateDeclaration node) { 
    419         // TODO Java -> D 
    420419        if (node.wrapper) { 
    421420            Dsymbol wrappedSymbol = node.members.get(0); // SEMANTIC 
     
    10271026    @Override 
    10281027    public void endVisit(TemplateDeclaration node) { 
     1028        int end; 
    10291029        if (node.postComment != null) { 
    1030             requestor.exitType(endOfDeclaration(node.postComment)); 
     1030            end = endOfDeclaration(node.postComment); 
    10311031        } else { 
    1032             requestor.exitType(endOfDeclaration(node)); 
     1032            end = endOfDeclaration(node); 
     1033        } 
     1034         
     1035        if (node.wrapper) { 
     1036            Dsymbol wrappedSymbol = node.members.get(0); // SEMANTIC 
     1037            if (wrappedSymbol.getNodeType() == ASTDmdNode.FUNC_DECLARATION) { 
     1038                requestor.exitMethod(end, -1, -1); 
     1039            } else { 
     1040                requestor.exitType(end); 
     1041            } 
    10331042        } 
    10341043        if (!node.wrapper) { 
  • trunk/descent.core/src/descent/internal/compiler/lookup/ModuleBuilder.java

    r1154 r1155  
    8989     * Wether to make surface Module semantic. 
    9090     */ 
    91     public boolean LAZY_MODULES = LAZY & true; 
     91    public boolean LAZY_MODULES = LAZY & false; 
    9292     
    9393    /* 
     
    180180        this.encoder = encoder; 
    181181         
    182       switch(config.semanticAnalysisLevel) { 
    183       case 0: // None 
    184           LAZY_MODULES = LAZY & true; 
    185           LAZY_VARS = LAZY & true; 
    186           break; 
    187       case 1: // Some 
    188       case 2: // All 
    189           LAZY_MODULES = false; 
    190           LAZY_VARS = false; 
    191           break; 
    192       } 
     182//        switch(config.semanticAnalysisLevel) { 
     183//        case 0: // None 
     184//            LAZY_MODULES = LAZY & true; 
     185//            LAZY_VARS = LAZY & true; 
     186//            break; 
     187//        case 1: // Some 
     188//        case 2: // All 
     189//            LAZY_MODULES = false; 
     190//            LAZY_VARS = false; 
     191//            break; 
     192//        } 
    193193    } 
    194194     
     
    208208                public void run() { 
    209209                    try { 
     210                        long time = System.currentTimeMillis(); 
     211                         
    210212                        IPackageDeclaration[] packageDeclarations = unit.getPackageDeclarations(); 
    211213                        if (packageDeclarations.length == 1) { 
     
    222224                         
    223225                        state.surface = false; 
     226                         
     227                        time = System.currentTimeMillis() - time; 
     228                        System.out.println(module.moduleName + ": " + time); 
    224229                    } catch (JavaModelException e) { 
    225230                        Util.log(e); 
  • trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java

    r1154 r1155  
    4242import static descent.internal.compiler.parser.TY.Tdelegate; 
    4343import static descent.internal.compiler.parser.TY.Tfunction; 
     44import static descent.internal.compiler.parser.TY.Tident; 
    4445import static descent.internal.compiler.parser.TY.Tsarray; 
    4546import static descent.internal.compiler.parser.TY.Tstruct; 
     
    16511652 
    16521653            if (null == t2 || !t1.equals(t2)) { 
    1653                 // goto L1
     1654                // goto Lnomatch
    16541655                return false; 
    16551656            } 
    16561657        } else if (e1 != null) { 
    1657             if (null == e2 || !e1.equals(e2)) { 
    1658                 // goto L1; 
     1658            if (null == e2) { 
     1659                // goto Lnomatch; 
     1660                return false; 
     1661            } 
     1662            if (!e1.equals(e2)) { 
     1663                // goto Lnomatch; 
    16591664                return false; 
    16601665            } 
    16611666        } else if (s1 != null) { 
    16621667            if (null == s2 || !s1.equals(s2) || s1.parent != s2.parent) { 
    1663                 // goto L1
     1668                // goto Lnomatch
    16641669                return false; 
    16651670            } 
    16661671        } else if (v1 != null) { 
    16671672            if (null == v2) { 
    1668                 // goto L1
     1673                // goto Lnomatch
    16691674                return false; 
    16701675            } 
    16711676            if (size(v1.objects) != size(v2.objects)) { 
    1672                 // goto L1
     1677                // goto Lnomatch
    16731678                return false; 
    16741679            } 
     
    16761681                if (!match((ASTDmdNode) v1.objects.get(i), 
    16771682                        (ASTDmdNode) v2.objects.get(i), tempdecl, sc, context)) { 
    1678                     // goto L1
     1683                    // goto Lnomatch
    16791684                    return false; 
    16801685                } 
     
    16821687        } 
    16831688        return true; // match 
    1684         //  L1
     1689        //  Lnomatch
    16851690        //      return 0;   // nomatch; 
    16861691    } 
     
    18431848    } 
    18441849     
     1850    public static int templateIdentifierLookup(IdentifierExp id, TemplateParameters parameters) { 
     1851        for (int i = 0; i < size(parameters); i++) { 
     1852            TemplateParameter tp = (TemplateParameter) parameters.get(i); 
     1853 
     1854            if (equals(tp.ident, id)) 
     1855                return i; 
     1856        } 
     1857 
     1858        return -1; 
     1859    } 
     1860     
     1861    public static int templateParameterLookup(Type tparam, 
     1862            TemplateParameters parameters) { 
     1863        if (tparam.ty != Tident) { 
     1864            throw new IllegalStateException("assert(tparam.ty == Tident);"); 
     1865        } 
     1866        TypeIdentifier tident = (TypeIdentifier) tparam; 
     1867        if (size(tident.idents) == 0) { 
     1868            return templateIdentifierLookup(tident.ident, parameters); 
     1869        } 
     1870        return -1; 
     1871    } 
     1872     
    18451873    public void errorOnModifier(int problemId, TOK tok, SemanticContext context) { 
    18461874        boolean reported = false; 
  • trunk/descent.core/src/descent/internal/compiler/parser/FuncDeclaration.java

    r1154 r1155  
    992992                // Verify this doesn't override previous final function 
    993993                if (cd.baseClass != null) { 
     994                    if (ident.toString().equals("callWindowProc")) { 
     995                        System.out.println(1); 
     996                    } 
     997                     
    994998                    Dsymbol s = cd.baseClass.search(loc, ident, 0, context); 
    995999                    if (s != null) { 
    9961000                        FuncDeclaration f2 = s.isFuncDeclaration(); 
     1001                        if (f2 == null) { 
     1002                            cd.baseClass.search(loc, ident, 0, context); 
     1003                        } 
    9971004                        f2 = f2.overloadExactMatch(type, context); 
    9981005                        if (f2 != null && f2.isFinal() 
  • trunk/descent.core/src/descent/internal/compiler/parser/Module.java

    r1154 r1155  
    66import melnorme.miscutil.tree.TreeVisitor; 
    77import descent.core.ICompilationUnit; 
     8import descent.core.JavaModelException; 
    89import descent.core.compiler.CharOperation; 
    910import descent.core.compiler.IProblem; 
    1011import descent.internal.compiler.lookup.SemanticRest; 
    1112import descent.internal.compiler.parser.ast.IASTVisitor; 
     13import descent.internal.core.CompilationUnit; 
     14import descent.internal.core.CompilationUnitElementInfo; 
     15import descent.internal.core.util.Util; 
    1216 
    1317// DMD 1.020 
    1418public class Module extends Package { 
     19     
     20    private final static boolean FAST_SEARCH = false; 
    1521 
    1622    public int apiLevel; 
     
    177183        semanticdone = semanticstarted; 
    178184         
    179       nest--; 
     185//        nest--; 
    180186    } 
    181187 
     
    346352            s = this.searchCacheSymbol; 
    347353        } else { 
     354            this.insearch = true; 
     355             
    348356            // Descent: lazy initailization 
    349             consumeRestStructure(); 
    350             consumeRest(); 
     357            if (FAST_SEARCH && javaElement != null && rest != null && !rest.isConsumed()) { 
     358                try { 
     359                    CompilationUnit unit = (CompilationUnit) javaElement; 
     360                    CompilationUnitElementInfo info = (CompilationUnitElementInfo) unit.getElementInfo(); 
     361                    if (info.containsTopLevelIdentifier(ident)) { 
     362                        consumeRestStructure(); 
     363                        consumeRest(); 
     364                        s = super.search(loc, ident, flags, context); 
     365                    } else { 
     366                        s = null; 
     367                    } 
     368                } catch (JavaModelException e) { 
     369                    Util.log(e); 
     370                    s = null; 
     371                } 
     372            } else { 
     373                consumeRestStructure(); 
     374                consumeRest(); 
     375                s = super.search(loc, ident, flags, context); 
     376            } 
    351377             
    352             this.insearch = true; 
    353             s = super.search(loc, ident, flags, context); 
    354378            this.insearch = false; 
    355379 
    356             this.searchCacheIdent = ident; 
    357              
    358             if ("SOCKET_ERROR".equals(new String(ident)) && s == null) { 
    359                 this.insearch = true; 
    360                 s = super.search(loc, ident, flags, context); 
    361                 this.insearch = false; 
    362                 this.searchCacheIdent = ident; 
    363             } 
    364              
     380            this.searchCacheIdent = ident;           
    365381            this.searchCacheSymbol = s; 
    366382            this.searchCacheFlags = flags; 
  • trunk/descent.core/src/descent/internal/compiler/parser/Problem.java

    r1120 r1155  
    988988        case TemplateHasNoValue: 
    989989            return String.format(ProblemMessages.TemplateHasNoValue, arguments[0]); 
    990         case InconsistentNestingLevels: 
    991             return String.format(ProblemMessages.InconsistentNestingLevels, arguments[0], arguments[1]); 
    992990        case CannotUseLocalAsTemplateParameter: 
    993991            return String.format(ProblemMessages.CannotUseLocalAsTemplateParameter, arguments[0]); 
     
    10221020        case ShiftAssignIsOutsideTheRange: 
    10231021            return String.format(ProblemMessages.ShiftAssignIsOutsideTheRange, arguments[0], arguments[1]); 
     1022        case TemplateTupleParameterMustBeLastOne: 
     1023            return String.format(ProblemMessages.TemplateTupleParameterMustBeLastOne); 
     1024        case SymbolIsNestedInBoth: 
     1025            return String.format(ProblemMessages.SymbolIsNestedInBoth, arguments[0], arguments[1], arguments[2]); 
    10241026        default: 
    10251027            return ""; 
  • trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.java

    r1120 r1155  
    441441    public static String CannotDeclareTemplateAtFunctionScope; 
    442442    public static String TemplateHasNoValue; 
    443     public static String InconsistentNestingLevels; 
    444443    public static String CannotUseLocalAsTemplateParameter; 
    445444    public static String NoSizeForType; 
     
    458457    public static String StaticConstructorCanOnlyBePartOfStructClassModule; 
    459458    public static String ShiftAssignIsOutsideTheRange; 
     459    public static String TemplateTupleParameterMustBeLastOne; 
     460    public static String SymbolIsNestedInBoth; 
    460461     
    461462    static { 
  • trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties

    r1120 r1155  
    429429CannotDeclareTemplateAtFunctionScope=Cannot declare template at function scope %1$s 
    430430TemplateHasNoValue=Template %1$s has no value 
    431 InconsistentNestingLevels=Inconsistent nesting levels %1$s and %2$s 
    432431CannotUseLocalAsTemplateParameter=Cannot use local '%1$s' as template parameter 
    433432NoSizeForType=No size for type %1$s 
     
    446445StaticConstructorCanOnlyBePartOfStructClassModule=Static constructor can only be part of struct/class/module 
    447446ShiftAssignIsOutsideTheRange=Shift assign by %1$s is outside the range 0..%2$s 
     447TemplateTupleParameterMustBeLastOne=Template tuple parameter must be last one 
     448SymbolIsNestedInBoth=%1$s is nested in both %2$s and %2$s 
  • trunk/descent.core/src/descent/internal/compiler/parser/STC.java

    r718 r1155  
    2727    public final static int STCinvariant    = 0x100000; 
    2828    public final static int STCref      = 0x200000; 
     29    public final static int STCinit     = 0x400000;     // has explicit initializer 
     30    public final static int STCmanifest     = 0x800000;     // manifest constant 
     31    public final static int STCnodtor       = 0x1000000;    // don't run destructor 
     32    public final static int STCnothrow      = 0x2000000;    // never throws exceptions 
    2933     
    3034    public static int fromTOK(TOK tok) { 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java

    r1154 r1155  
    66import melnorme.miscutil.tree.TreeVisitor; 
    77import descent.core.IJavaElement; 
     8import descent.core.compiler.CharOperation; 
    89import descent.core.compiler.IProblem; 
    910import descent.internal.compiler.lookup.SemanticRest; 
     
    177178            td_best.leastAsSpecialized(td, context); 
    178179 
    179             if (0 != c1 && 0 == c2) { 
     180            if (c1 > c2) { 
    180181                // Ltd: 
    181182                td_ambig = null; 
    182183                continue; 
    183             } else if (0 == c1 && 0 != c2) { 
     184            } else if (c1 < c2) { 
    184185                // Ltd_best: 
    185186                td_ambig = null; 
     
    239240        int i; 
    240241        int nfparams; 
    241         int nfparams2; 
    242242        int nfargs; 
    243243        int nargsi; 
     244        int fptupindex = -1; 
     245        int tuple_dim = 0; 
    244246        MATCH match = MATCHexact; 
    245247        FuncDeclaration fd = onemember.toAlias(context).isFuncDeclaration(); 
     
    261263        paramsym.parent = scope.parent; 
    262264        Scope paramscope = scope.push(paramsym); 
     265         
     266        tp = isVariadic(); 
    263267 
    264268        nargsi = 0; 
     
    266270 
    267271            nargsi = targsi.size(); 
    268             if (nargsi > parameters.size()) 
    269                 return Lnomatch(paramscope); // goto Lnomatch; 
     272            if (nargsi > parameters.size()) { 
     273                if (null == tp) { 
     274                    return Lnomatch(paramscope); // goto Lnomatch; 
     275                } 
     276                dedargs.setDim(nargsi); 
     277                dedargs.zero(); 
     278            } 
    270279 
    271280            //memcpy(dedargs.data, targsi.data, nargsi * sizeof(dedargs.data)); 
     
    302311        // function 
    303312        // parameters 
    304         nfparams2 = nfparams; 
    305313        nfargs = fargs.size(); // number of function arguments 
    306314 
     
    324332                    throw GOTO_L1; 
    325333                } else { 
    326                     /* 
    327                      * See if 'A' of the template parameter matches 'A' of the 
    328                      * type of the last function parameter. 
    329                      */ 
    330                     Argument fparam = (Argument) fdtype.parameters 
    331                             .get(nfparams - 1); 
    332                     if (fparam.type.ty != Tident) { 
    333                         throw GOTO_L1; 
     334                    /*  
     335                     * Figure out which of the function parameters matches 
     336                     * the tuple template parameter. Do this by matching 
     337                     * type identifiers. 
     338                     * Set the index of this function parameter to fptupindex. 
     339                     */ 
     340                    for (fptupindex = 0; fptupindex < nfparams; fptupindex++) { 
     341                        Argument fparam = (Argument) fdtype.parameters 
     342                                .get(fptupindex); 
     343                        if (fparam.type.ty != Tident) { 
     344                            continue; 
     345                        } 
     346                        TypeIdentifier tid = (TypeIdentifier) fparam.type; 
     347     
     348                        if (!equals(tp.ident, tid.ident) 
     349                                || (tid.idents != null && tid.idents.size() > 0)) { 
     350                            continue; 
     351                        } 
     352                        if (fdtype.varargs > 0) // variadic function doesn't 
     353                            return Lnomatch(paramscope); // goto Lnomatch; // go 
     354                        // with 
     355                        // variadic template 
     356     
     357                        /*  
     358                         * The types of the function arguments 
     359                         * now form the tuple argument. 
     360                         */ 
     361                        Tuple t = new Tuple(); 
     362                        dedargs.set(parameters.size() - 1, t); 
     363     
     364                        tuple_dim = nfargs - (nfparams - 1); 
     365                        t.objects.setDim(tuple_dim); 
     366                        for (i = 0; i < tuple_dim; i++) { 
     367                            Expression farg = (Expression) fargs.get(fptupindex + 1); 
     368                            t.objects.set(i, farg.type); 
     369                        } 
     370                        throw GOTO_L2; 
    334371                    } 
    335                     TypeIdentifier tid = (TypeIdentifier) fparam.type; 
    336  
    337                     if (!equals(tp.ident, tid.ident) 
    338                             || (tid.idents != null && tid.idents.size() > 0)) { 
    339                         throw GOTO_L1; 
    340                     } 
    341                     if (fdtype.varargs > 0) // variadic function doesn't 
    342                         return Lnomatch(paramscope); // goto Lnomatch; // go 
    343                     // with 
    344                     // variadic template 
    345  
    346                     /* 
    347                      * The types of the function arguments [nfparams - 1 .. 
    348                      * nfargs] now form the tuple argument. 
    349                      */ 
    350                     Tuple t = new Tuple(); 
    351                     dedargs.set(parameters.size() - 1, t); 
    352  
    353                     int tuple_dim = nfargs - (nfparams - 1); 
    354                     t.objects.setDim(tuple_dim); 
    355                     for (i = 0; i < tuple_dim; i++) { 
    356                         Expression farg = (Expression) fargs.get(nfparams - 1 
    357                                 + i); 
    358                         t.objects.set(i, farg.type); 
    359                     } 
    360                     nfparams2--; // don't consider the last parameter for 
    361                     // type 
    362                     // deduction 
    363                     throw GOTO_L2; 
     372                    fptupindex--; 
    364373                } 
    365374            } 
     
    383392        // L2: 
    384393        // Loop through the function parameters 
    385         for (i = 0; i < nfparams2; i++) { 
     394        for (i = 0; i < nfparams; i++) { 
     395             
     396            /* Skip over function parameters which wound up 
     397             * as part of a template tuple parameter. 
     398             */ 
     399            if (i == fptupindex) { 
     400                if (fptupindex == nfparams - 1) 
     401                    break; 
     402                i += tuple_dim - 1; 
     403                continue; 
     404            } 
     405             
    386406            Argument fparam = Argument.getNth(fdtype.parameters, i, context); 
    387407            Expression farg; 
     
    756776        } 
    757777 
    758         for (TemplateParameter tp : parameters) { 
     778        for (int i = 0; i < parameters.size(); i++) { 
     779            TemplateParameter tp = parameters.get(i); 
    759780            tp.semantic(paramscope, context); 
     781             
     782            if (i + 1 != parameters.size() && tp.isTemplateTupleParameter() != null) { 
     783                if (context.acceptsProblems()) { 
     784                    context.acceptProblem(Problem.newSemanticTypeError(IProblem.TemplateTupleParameterMustBeLastOne, tp)); 
     785                } 
     786            } 
    760787        } 
    761788 
     
    771798                } 
    772799            } 
    773              
    774             // Descent: do semantic of my members without reporting 
    775             // problems, in order to get code selection, code completion, 
    776             // code evaluation and bindings. 
    777 //          context.muteProblems++; 
    778 //          for(Dsymbol member : members) { 
    779 //              member.semantic(scope, context); 
    780 //          } 
    781 //          context.muteProblems--; 
    782         } 
    783     } 
    784      
    785 //  @Override 
    786 //  public void semantic2(Scope sc, SemanticContext context) { 
    787 //      // Descent: do semantic of my members without reporting 
    788 //      // problems, in order to get code selection, code completion, 
    789 //      // code evaluation and bindings. 
    790 //      context.muteProblems++; 
    791 //      for(Dsymbol member : members) { 
    792 //          member.semantic2(scope, context); 
    793 //      } 
    794 //      context.muteProblems--; 
    795 //  } 
    796 //   
    797 //  @Override 
    798 //  public void semantic3(Scope sc, SemanticContext context) { 
    799 //      // Descent: do semantic of my members without reporting 
    800 //      // problems, in order to get code selection, code completion, 
    801 //      // code evaluation and bindings. 
    802 //      context.muteProblems++; 
    803 //      for(Dsymbol member : members) { 
    804 //          member.semantic3(scope, context); 
    805 //      } 
    806 //      context.muteProblems--; 
    807 //  } 
     800        } 
     801    } 
    808802 
    809803    @Override 
     
    894888    } 
    895889     
     890    /** 
     891     * We can overload templates. 
     892     */ 
     893    public boolean isOverloadable() { 
     894        return true; 
     895    } 
     896     
    896897    public void setJavaElement(IJavaElement javaElement) { 
    897898        this.javaElement = javaElement; 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java

    r1154 r1155  
    88import descent.internal.compiler.parser.ast.IASTVisitor; 
    99 
     10import static descent.internal.compiler.parser.STC.*; 
    1011import static descent.internal.compiler.parser.MATCH.MATCHnomatch; 
    1112 
    12 import static descent.internal.compiler.parser.TOK.TOKfunction
     13import static descent.internal.compiler.parser.TOK.*
    1314import static descent.internal.compiler.parser.TOK.TOKtuple; 
    1415import static descent.internal.compiler.parser.TOK.TOKvar; 
     
    121122 
    122123            dedtypes.setDim(size(td.parameters)); 
     124            dedtypes.zero(); 
     125             
    123126            if (null == td.scope) { 
    124127                if (context.acceptsProblems()) { 
     
    152155                int c2 = td_best.leastAsSpecialized(td, context); 
    153156 
    154                 if (c1 != 0 && 0 == c2) { 
     157                if (c1 > c2) { 
    155158                    // goto Ltd; 
    156159                    td_ambig = null; 
     
    163166                    tdtypes.memcpy(dedtypes); 
    164167                    continue; 
    165                 } else if (0 == c1 && c2 != 0) { 
     168                } else if (c1 < c2) { 
    166169                    // goto Ltd_best; 
    167170                    td_ambig = null; 
     
    404407    } 
    405408 
    406     public boolean isNested(Objects args, SemanticContext context) { 
    407         boolean nested = false
     409    public int isNested(Objects args, SemanticContext context) { 
     410        int nested = 0
    408411 
    409412        /* A nested instance happens when an argument references a local 
     
    435438                if (gotoLsa) { 
    436439                    Declaration d = sa.isDeclaration(); 
    437                     if (null != d 
     440                     
     441                    boolean condition = null != d 
    438442                            && !d.isDataseg(context) 
    439443                            && (null == d.isFuncDeclaration() || d 
    440444                                    .isFuncDeclaration().isNested()) 
    441                             && null == isTemplateMixin()) { 
     445                            && null == isTemplateMixin(); 
     446                    if (context.apiLevel == Parser.D2) { 
     447                        condition = condition && null != d && 0 == (d.storage_class & STCmanifest); 
     448                    } 
     449                     
     450                    if (condition) { 
    442451                        // if module level template 
    443452                        if (null != tempdecl.toParent().isModule()) { 
    444                             if (null != isnested && isnested != d.toParent()) { 
     453                            Dsymbol dparent = d.toParent(); 
     454                            if (null == isnested) 
     455                                isnested = dparent; 
     456                            else if (isnested != dparent) { 
     457                                boolean gotoL1 = false; 
     458                                 
     459                                /* Select the more deeply nested of the two. 
     460                                 * Error if one is not nested inside the other. 
     461                                 */ 
     462                                for (Dsymbol p = isnested; p != null; p = p.parent) { 
     463                                    if (p == dparent) { 
     464                                        // goto L1; // isnested is most nested 
     465                                        gotoL1 = true; 
     466                                        break; 
     467                                    } 
     468                                } 
     469                                 
     470                                if (!gotoL1) { 
     471                                    for (Dsymbol p = dparent; true; p = p.parent) { 
     472                                        if (p == isnested) { 
     473                                            isnested = dparent; 
     474                                            // goto L1; // dparent is most nested 
     475                                            break; 
     476                                        } 
     477                                    } 
     478                                } 
    445479                                if (context.acceptsProblems()) { 
    446                                     context.acceptProblem(Problem.newSemanticTypeError( 
    447                                             IProblem.InconsistentNestingLevels, this, new String[] { isnested.toChars(context), d.toParent().toChars(context) })); 
     480                                    context.acceptProblem(Problem.newSemanticTypeErrorLoc( 
     481                                            IProblem.SymbolIsNestedInBoth,  
     482                                            this,  
     483                                            new String[] {  
     484                                            this.toChars(context),  
     485                                            isnested.toChars(context),  
     486                                            dparent.toChars(context) })); 
    448487                                } 
    449488                            } 
    450                             isnested = d.toParent(); 
    451                             nested = true
     489                            // L1: 
     490                            nested |= 1
    452491                        } else { 
    453492                            if (context.acceptsProblems()) { 
    454                                 context.acceptProblem(Problem.newSemanticTypeError( 
    455                                         IProblem.CannotUseLocalAsTemplateParameter, this, new String[] { d.toChars(context) })); 
     493                                context 
     494                                        .acceptProblem(Problem 
     495                                                .newSemanticTypeError( 
     496                                                        IProblem.CannotUseLocalAsTemplateParameter, 
     497                                                        this, 
     498                                                        new String[] { d 
     499                                                                .toChars(context) })); 
    456500                            } 
    457501                        } 
     
    929973                ea[0] = ea[0].optimize(WANTvalue | WANTinterpret, context); 
    930974                tiargs.set(j, ea[0]); 
     975                if (ea[0].op == TOKtype) { 
     976                    tiargs.set(j, ea[0].type); 
     977                } 
    931978            } else if (sa[0] != null) { 
    932979            } else { 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java

    r1154 r1155  
    268268        argsym.parent = scy.parent; 
    269269        Scope scope = scy.push(argsym); 
     270         
     271        int errorsave = context.global.errors; 
    270272 
    271273        // Declare each template parameter as an alias for the argument type 
     
    303305