Changeset 790

Show
Ignore:
Timestamp:
09/21/07 13:59:07 (1 year ago)
Author:
asterite
Message:

Some more problem reporting...

Files:

Legend:

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

    r783 r790  
    368368    int ScopeCannotBeRefOrOut = 158; 
    369369    int IncompatibleTypeForOperator = 159; 
     370    int SymbolNotDefined = 160; 
     371    int SymbolNotATemplate = 161; 
     372    int CannotDeleteType = 162; 
     373    int NotAnLvalue = 163; 
    370374 
    371375} 
  • trunk/descent.core/src/descent/core/dom/ASTConverter.java

    r779 r790  
    9292            unit.setModuleDeclaration(convert(module.md)); 
    9393        } 
    94         convertDeclarations(unit.declarations(), module.members); 
     94        convertDeclarations(unit.declarations(), module.sourceMembers); 
    9595        unit.setSourceRange(module.start, module.length);        
    9696        return unit; 
  • trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java

    r782 r790  
    16741674     
    16751675    /** 
     1676     * Returns the size of a list which may ne <code>null</code>. 
     1677     * In such case, 0 is returned. 
     1678     */ 
     1679    protected int size(List list) { 
     1680        return list == null ? 0 : list.size();  
     1681    } 
     1682     
     1683    /** 
    16761684     * This is a debug string used by NaiveASTFlattener 
    16771685     * to add resolved information to the string output. 
  • trunk/descent.core/src/descent/internal/compiler/parser/AggregateDeclaration.java

    r775 r790  
    1010public abstract class AggregateDeclaration extends ScopeDsymbol { 
    1111     
    12     public Dsymbols sourceMembers; 
    13  
    1412    public Type type; 
    1513    public PROT protection; 
  • trunk/descent.core/src/descent/internal/compiler/parser/DeleteExp.java

    r762 r790  
    9797                } 
    9898            } 
    99             error("cannot delete type %s", e1.type.toChars(context)); 
     99            context.acceptProblem(Problem.newSemanticTypeError(IProblem.CannotDeleteType, 0, start, length, new String[] { e1.type.toChars(context) })); 
    100100            break; 
    101101        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/Expression.java

    r782 r790  
    440440            loc = e.loc; 
    441441        } 
    442         error("%s is not an lvalue", e.toChars(context)); 
     442        context.acceptProblem(Problem.newSemanticTypeError(IProblem.NotAnLvalue, 0, start, length, new String[] { e.toChars(context) })); 
    443443        return this; 
    444444    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/ForeachStatement.java

    r783 r790  
    538538        } 
    539539 
    540         if (cases.size() == 0) { 
     540        if (size(cases) == 0) { 
    541541            // Easy case, a clean exit from the loop 
    542542            s[0] = new ExpStatement(loc, e); 
  • trunk/descent.core/src/descent/internal/compiler/parser/Module.java

    r775 r790  
    2525    public boolean needmoduleinfo; 
    2626    public Module importedFrom; 
    27      
    28     public long debuglevel;    // debug level 
    29     public List<char[]> debugids;      // debug identifiers 
    30     public List<char[]> debugidsNot;       // forward referenced debug identifiers 
    31      
     27 
     28    public long debuglevel; // debug level 
     29    public List<char[]> debugids; // debug identifiers 
     30    public List<char[]> debugidsNot; // forward referenced debug identifiers 
     31 
    3232    public long versionlevel; 
    33     public List<char[]> versionids;     // version identifiers 
    34     public List<char[]> versionidsNot;  // forward referenced version identifiers 
     33    public List<char[]> versionids; // version identifiers 
     34    public List<char[]> versionidsNot; // forward referenced version 
     35                                        // identifiers 
    3536 
    3637    public Module(Loc loc) { 
    3738        super(loc); 
    3839        deferred = new Dsymbols(); 
     40        importedFrom = this; 
    3941    } 
    4042 
     
    8991        symtab = new DsymbolTable(); 
    9092 
    91         // TODO This is the current replacement of Add import of "object" if this module isn't "object" 
     93        // TODO This is the current replacement of Add import of "object" if 
     94        // this module isn't "object" 
    9295        if (ident == null || ident.ident != Id.object) { 
    9396            symtab.insert(context.object); 
     
    116119 
    117120            // Pass 1 semantic routines: do public side of the definition 
    118             for (Dsymbol s : members) { 
     121            for (int i = 0; i < members.size(); i++) { 
     122                Dsymbol s; 
     123                s = members.get(i); 
    119124                s.semantic(sc, context); 
    120125            } 
     
    150155        // Pass 2 semantic routines: do initializers and function bodies 
    151156        if (members != null) { 
    152             for (Dsymbol s : members) { 
     157            for (int i = 0; i < members.size(); i++) { 
     158                Dsymbol s; 
     159                s = members.get(i); 
    153160                s.semantic2(sc, context); 
    154161            } 
     
    175182        // Pass 3 semantic routines: do initializers and function bodies 
    176183        if (members != null) { 
    177             for (Dsymbol s : members) { 
     184            for (int i = 0; i < members.size(); i++) { 
     185                Dsymbol s; 
     186                s = members.get(i); 
    178187                s.semantic3(sc, context); 
    179188            } 
     
    237246                s.semantic(null, context); 
    238247            } 
    239         } while (deferred.size() < len || context.dprogress != 0); // while making progress 
     248        } while (deferred.size() < len || context.dprogress != 0); // while 
     249                                                                    // making 
     250                                                                    // progress 
    240251        nested--; 
    241252    } 
    242      
     253 
    243254    @Override 
    244255    public void appendBinding(StringBuilder sb) { 
  • trunk/descent.core/src/descent/internal/compiler/parser/Parser.java

    r776 r790  
    161161        module = new Module(loc); 
    162162        module.members = parseModule(); 
     163        module.sourceMembers = new Dsymbols(module.members); 
    163164        module.md = md; 
    164165        module.comments = comments.toArray(new Comment[comments.size()]); 
  • trunk/descent.core/src/descent/internal/compiler/parser/Problem.java

    r783 r790  
    414414        case IncompatibleTypeForOperator: 
    415415            return String.format(ProblemMessages.IncompatibleTypeForOperator, arguments[0], arguments[1], arguments[2]); 
     416        case SymbolNotDefined: 
     417            return String.format(ProblemMessages.SymbolNotDefined, arguments[0]); 
     418        case SymbolNotATemplate: 
     419            return String.format(ProblemMessages.SymbolNotATemplate, arguments[0]); 
     420        case CannotDeleteType: 
     421            return String.format(ProblemMessages.CannotDeleteType, arguments[0]); 
     422        case NotAnLvalue: 
     423            return String.format(ProblemMessages.NotAnLvalue, arguments[0]); 
    416424        default: 
    417425            return ""; 
  • trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.java

    r783 r790  
    170170    public static String ScopeCannotBeRefOrOut; 
    171171    public static String IncompatibleTypeForOperator; 
     172    public static String SymbolNotDefined; 
     173    public static String SymbolNotATemplate; 
     174    public static String CannotDeleteType; 
     175    public static String NotAnLvalue; 
    172176     
    173177    static { 
  • trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties

    r783 r790  
    158158ScopeCannotBeRefOrOut=<<TODO>> 
    159159IncompatibleTypeForOperator=Types %1$s and %2$s are incompatible for %3$s 
     160SymbolNotDefined=%1$s is not defined 
     161SymbolNotATemplate=%1$s is not a template 
     162CannotDeleteType=Cannot delete type %1$s 
     163NotAnLvalue=%1$s is not an lvalue 
  • trunk/descent.core/src/descent/internal/compiler/parser/ScopeDsymbol.java

    r768 r790  
    1212public class ScopeDsymbol extends Dsymbol { 
    1313 
    14     public Dsymbols members
     14    public Dsymbols members, sourceMembers
    1515    public DsymbolTable symtab; 
    1616    public List<ScopeDsymbol> imports; // imported ScopeDsymbol's 
     
    8585            // sizeof(prots[0])); 
    8686            // prots[imports.dim - 1] = protection; 
    87             prots.set(imports.size() - 1, protection); 
     87            if (prots == null) { 
     88                prots = new Array<PROT>(); 
     89            } 
     90            prots.set(size(imports) - 1, protection); 
    8891        } 
    8992    } 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java

    r783 r790  
    254254 
    255255        // If more arguments than parameters, no match 
    256         if (ti.tiargs.size() > parameters_dim && !variadic) { 
     256        if (size(ti.tiargs) > parameters_dim && !variadic) { 
    257257            return MATCHnomatch; 
    258258        } 
    259259 
    260260        assert (dedtypes_dim == parameters_dim); 
    261         assert (dedtypes_dim >= ti.tiargs.size() || variadic); 
     261        assert (dedtypes_dim >= size(ti.tiargs) || variadic); 
    262262 
    263263        // Set up scope for parameters 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java

    r781 r790  
    108108            // If more arguments than parameters, 
    109109            // then this is no match. 
    110             if (td.parameters.size() < tiargs.size()) { 
     110            if (size(td.parameters) < size(tiargs)) { 
    111111                if (null == td.isVariadic()) 
    112112                    continue; 
     
    133133                td_best = td; 
    134134                m_best = m; 
    135                 tdtypes.ensureCapacity(dedtypes.size()); 
     135                if (tdtypes == null) { 
     136                    tdtypes = new Objects(dedtypes.size()); 
     137                } else { 
     138                    tdtypes.ensureCapacity(dedtypes.size()); 
     139                } 
    136140                for (ASTDmdNode a : dedtypes) { 
    137141                    tdtypes.add(a); 
     
    149153                    td_best = td; 
    150154                    m_best = m; 
    151                     tdtypes.ensureCapacity(dedtypes.size()); 
     155                    if (tdtypes == null) { 
     156                        tdtypes = new Objects(dedtypes.size()); 
     157                    } else { 
     158                        tdtypes.ensureCapacity(dedtypes.size()); 
     159                    } 
    152160                    for (ASTDmdNode a : dedtypes) { 
    153161                        tdtypes.add(a); 
     
    285293        // buf.printf("__T%zu%s", id.length(), id); 
    286294        args = tiargs; 
    287         for (int i = 0; i < args.size(); i++) { 
     295        for (int i = 0; i < size(args); i++) { 
    288296            ASTDmdNode o = (ASTDmdNode) args.get(i); 
    289297            Type ta = isType(o); 
     
    538546            { 
    539547                inst = this; 
    540                 //printf("error return %p, %d\n", tempdecl, global.errors); 
    541548                return; // error recovery 
    542549            } 
     
    843850            nest = true; 
    844851            Objects args = tiargs; 
    845             for(i = 0; i < args.size(); i++) 
     852            for(i = 0; i < size(args); i++) 
    846853            { 
    847854                if(i > 0) 
     
    876883            Dsymbol[] sa = { isDsymbol(o) }; 
    877884 
    878             if (ta != null) { 
     885            if (ta[0] != null) { 
    879886                // It might really be an Expression or an Alias 
    880887                ta[0].resolve(loc, sc, ea, ta, sa, context); 
    881                 if (ea != null) { 
     888                if (ea[0] != null) { 
    882889                    ea[0] = ea[0].semantic(sc, context); 
    883890                    ea[0] = ea[0].optimize(WANTvalue | WANTinterpret, context); 
     
    893900                        j--; 
    894901                    } 
    895                 } else if (ta != null) { 
     902                } else if (ta[0] != null) { 
    896903                    if (ta[0].ty == Ttuple) { // Expand tuple 
    897904                        TypeTuple tt = (TypeTuple) ta[0]; 
     
    902909                            for (int i = 0; i < dim; i++) { 
    903910                                Argument arg = (Argument) tt.arguments.get(i); 
    904                                 tiargs.add(j + i, arg.type); 
     911                                tiargs.set(j + i, arg.type); 
    905912                            } 
    906913                        } 
    907914                        j--; 
    908                     } else 
    909                         tiargs.add(j, ta[0]); 
     915                    } else { 
     916                        tiargs.set(j, ta[0]); 
     917                    } 
    910918                } else { 
    911919                    if (context.global.errors == 0) { 
  • trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java

    r770 r790  
    22 
    33import melnorme.miscutil.tree.TreeVisitor; 
     4import descent.core.compiler.IProblem; 
    45import descent.internal.compiler.parser.ast.IASTVisitor; 
    56import static descent.internal.compiler.parser.PROT.PROTpublic; 
     
    126127            } 
    127128            if (null == s) { 
    128                 error("is not defined"); 
     129                context.acceptProblem(Problem.newSemanticTypeError(IProblem.SymbolNotDefined, 0, typeStart, typeLength, new String[] { toChars(context) })); 
    129130                inst = this; 
    130131                return; 
     
    132133            tempdecl = s.toAlias(context).isTemplateDeclaration(); 
    133134            if (null == tempdecl) { 
    134                 error("%s isn't a template", s.toChars(context)); 
     135                context.acceptProblem(Problem.newSemanticTypeError(IProblem.SymbolNotATemplate, 0, typeStart, typeLength, new String[] { s.toChars(context) })); 
    135136                inst = this; 
    136137                return; 
  • trunk/descent.core/src/descent/internal/compiler/parser/TypeInstance.java

    r741 r790  
    22 
    33import melnorme.miscutil.tree.TreeVisitor; 
     4import descent.core.compiler.IProblem; 
    45import descent.internal.compiler.parser.ast.IASTVisitor; 
    56 
     
    143144 
    144145        if (null == t[0]) { 
    145             error(loc, "%s is used as a type", toChars(context)); 
     146            context.acceptProblem(Problem.newSemanticTypeError(IProblem.UsedAsAType, 0, start, length, new String[] { toChars(context) })); 
    146147            t[0] = tvoid; 
    147148        } 
  • trunk/descent.core/src/descent/internal/compiler/parser/TypeQualified.java

    r770 r790  
    260260        int i; 
    261261 
    262         for (i = 0; i < idents.size(); i++) { 
    263             IdentifierExp id = idents.get(i); 
    264  
    265             buf.writeByte('.'); 
    266  
    267             if (id.dyncast() == DYNCAST_DSYMBOL) { 
    268                 TemplateInstance ti = ((TemplateInstanceWrapper) id).tempinst; 
    269                 ti.toCBuffer(buf, hgs, context); 
    270             } else { 
    271                 buf.writestring(id.toChars()); 
     262        if (idents != null) { 
     263            for (i = 0; i < idents.size(); i++) { 
     264                IdentifierExp id = idents.get(i); 
     265     
     266                buf.writeByte('.'); 
     267     
     268                if (id.dyncast() == DYNCAST_DSYMBOL) { 
     269                    TemplateInstance ti = ((TemplateInstanceWrapper) id).tempinst; 
     270                    ti.toCBuffer(buf, hgs, context); 
     271                } else { 
     272                    buf.writestring(id.toChars()); 
     273                } 
    272274            } 
    273275        } 
  • trunk/descent.core/template/problem/problems.txt

    r783 r790  
    476476    formatString=Types %1$s and %2$s are incompatible for %3$s 
    477477    numArgs=3 
    478  
    479      
    480      
    481      
    482      
    483      
    484      
     478SymbolNotDefined 
     479    formatString=%1$s is not defined 
     480    numArgs=1 
     481SymbolNotATemplate 
     482    formatString=%1$s is not a template 
     483    numArgs=1 
     484CannotDeleteType 
     485    formatString=Cannot delete type %1$s 
     486    numArgs=1 
     487NotAnLvalue 
     488    formatString=%1$s is not an lvalue 
     489    numArgs=1 
     490     
     491     
     492     
     493     
     494     
     495     
  • trunk/descent.tests/descent/tests/mars/Semantic1_Test.java

    r760 r790  
    10531053    } 
    10541054     
     1055    public void testSymbolNotDefined() { 
     1056        String s = "mixin T!();"; 
     1057        IProblem[] p = getModuleProblems(s); 
     1058        assertEquals(1, p.length); 
     1059         
     1060        assertError(p[0], IProblem.SymbolNotDefined, 6, 4); 
     1061    } 
     1062     
     1063    public void testSymbolNotATemplate() { 
     1064        String s = "class T { } mixin T!();"; 
     1065        IProblem[] p = getModuleProblems(s); 
     1066        assertEquals(1, p.length); 
     1067         
     1068        assertError(p[0], IProblem.SymbolNotATemplate, 18, 4); 
     1069    } 
     1070     
     1071    public void testCannotDeleteType() { 
     1072        String s = "void foo() { delete 1; }"; 
     1073        IProblem[] p = getModuleProblems(s); 
     1074        assertEquals(2, p.length); 
     1075         
     1076        assertError(p[1], IProblem.CannotDeleteType, 13, 8); 
     1077    } 
     1078     
     1079    public void testNotAnLvalue() { 
     1080        String s = "void foo() { delete new int; }"; 
     1081        IProblem[] p = getModuleProblems(s); 
     1082        assertEquals(1, p.length); 
     1083         
     1084        assertError(p[0], IProblem.NotAnLvalue, 20, 7); 
     1085    } 
     1086     
    10551087     
    10561088    /* TODO test for SemanticContext.IN_GCC = true