Changeset 790
- Timestamp:
- 09/21/07 13:59:07 (1 year ago)
- Files:
-
- trunk/descent.core/src/descent/core/compiler/IProblem.java (modified) (1 diff)
- trunk/descent.core/src/descent/core/dom/ASTConverter.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/AggregateDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/DeleteExp.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Expression.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ForeachStatement.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/Module.java (modified) (6 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/Parser.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/ProblemMessages.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/ScopeDsymbol.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java (modified) (1 diff)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java (modified) (9 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java (modified) (3 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TypeInstance.java (modified) (2 diffs)
- trunk/descent.core/src/descent/internal/compiler/parser/TypeQualified.java (modified) (1 diff)
- trunk/descent.core/template/problem/problems.txt (modified) (1 diff)
- trunk/descent.tests/descent/tests/mars/Semantic1_Test.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/core/compiler/IProblem.java
r783 r790 368 368 int ScopeCannotBeRefOrOut = 158; 369 369 int IncompatibleTypeForOperator = 159; 370 int SymbolNotDefined = 160; 371 int SymbolNotATemplate = 161; 372 int CannotDeleteType = 162; 373 int NotAnLvalue = 163; 370 374 371 375 } trunk/descent.core/src/descent/core/dom/ASTConverter.java
r779 r790 92 92 unit.setModuleDeclaration(convert(module.md)); 93 93 } 94 convertDeclarations(unit.declarations(), module. members);94 convertDeclarations(unit.declarations(), module.sourceMembers); 95 95 unit.setSourceRange(module.start, module.length); 96 96 return unit; trunk/descent.core/src/descent/internal/compiler/parser/ASTDmdNode.java
r782 r790 1674 1674 1675 1675 /** 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 /** 1676 1684 * This is a debug string used by NaiveASTFlattener 1677 1685 * to add resolved information to the string output. trunk/descent.core/src/descent/internal/compiler/parser/AggregateDeclaration.java
r775 r790 10 10 public abstract class AggregateDeclaration extends ScopeDsymbol { 11 11 12 public Dsymbols sourceMembers;13 14 12 public Type type; 15 13 public PROT protection; trunk/descent.core/src/descent/internal/compiler/parser/DeleteExp.java
r762 r790 97 97 } 98 98 } 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) })); 100 100 break; 101 101 } trunk/descent.core/src/descent/internal/compiler/parser/Expression.java
r782 r790 440 440 loc = e.loc; 441 441 } 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) })); 443 443 return this; 444 444 } trunk/descent.core/src/descent/internal/compiler/parser/ForeachStatement.java
r783 r790 538 538 } 539 539 540 if ( cases.size() == 0) {540 if (size(cases) == 0) { 541 541 // Easy case, a clean exit from the loop 542 542 s[0] = new ExpStatement(loc, e); trunk/descent.core/src/descent/internal/compiler/parser/Module.java
r775 r790 25 25 public boolean needmoduleinfo; 26 26 public Module importedFrom; 27 28 public long debuglevel; // debug level29 public List<char[]> debugids; // debug identifiers30 public List<char[]> debugidsNot; // forward referenced debug identifiers31 27 28 public long debuglevel; // debug level 29 public List<char[]> debugids; // debug identifiers 30 public List<char[]> debugidsNot; // forward referenced debug identifiers 31 32 32 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 35 36 36 37 public Module(Loc loc) { 37 38 super(loc); 38 39 deferred = new Dsymbols(); 40 importedFrom = this; 39 41 } 40 42 … … 89 91 symtab = new DsymbolTable(); 90 92 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" 92 95 if (ident == null || ident.ident != Id.object) { 93 96 symtab.insert(context.object); … … 116 119 117 120 // 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); 119 124 s.semantic(sc, context); 120 125 } … … 150 155 // Pass 2 semantic routines: do initializers and function bodies 151 156 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); 153 160 s.semantic2(sc, context); 154 161 } … … 175 182 // Pass 3 semantic routines: do initializers and function bodies 176 183 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); 178 187 s.semantic3(sc, context); 179 188 } … … 237 246 s.semantic(null, context); 238 247 } 239 } while (deferred.size() < len || context.dprogress != 0); // while making progress 248 } while (deferred.size() < len || context.dprogress != 0); // while 249 // making 250 // progress 240 251 nested--; 241 252 } 242 253 243 254 @Override 244 255 public void appendBinding(StringBuilder sb) { trunk/descent.core/src/descent/internal/compiler/parser/Parser.java
r776 r790 161 161 module = new Module(loc); 162 162 module.members = parseModule(); 163 module.sourceMembers = new Dsymbols(module.members); 163 164 module.md = md; 164 165 module.comments = comments.toArray(new Comment[comments.size()]); trunk/descent.core/src/descent/internal/compiler/parser/Problem.java
r783 r790 414 414 case IncompatibleTypeForOperator: 415 415 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]); 416 424 default: 417 425 return ""; trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.java
r783 r790 170 170 public static String ScopeCannotBeRefOrOut; 171 171 public static String IncompatibleTypeForOperator; 172 public static String SymbolNotDefined; 173 public static String SymbolNotATemplate; 174 public static String CannotDeleteType; 175 public static String NotAnLvalue; 172 176 173 177 static { trunk/descent.core/src/descent/internal/compiler/parser/ProblemMessages.properties
r783 r790 158 158 ScopeCannotBeRefOrOut=<<TODO>> 159 159 IncompatibleTypeForOperator=Types %1$s and %2$s are incompatible for %3$s 160 SymbolNotDefined=%1$s is not defined 161 SymbolNotATemplate=%1$s is not a template 162 CannotDeleteType=Cannot delete type %1$s 163 NotAnLvalue=%1$s is not an lvalue trunk/descent.core/src/descent/internal/compiler/parser/ScopeDsymbol.java
r768 r790 12 12 public class ScopeDsymbol extends Dsymbol { 13 13 14 public Dsymbols members ;14 public Dsymbols members, sourceMembers; 15 15 public DsymbolTable symtab; 16 16 public List<ScopeDsymbol> imports; // imported ScopeDsymbol's … … 85 85 // sizeof(prots[0])); 86 86 // 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); 88 91 } 89 92 } trunk/descent.core/src/descent/internal/compiler/parser/TemplateDeclaration.java
r783 r790 254 254 255 255 // If more arguments than parameters, no match 256 if ( ti.tiargs.size() > parameters_dim && !variadic) {256 if (size(ti.tiargs) > parameters_dim && !variadic) { 257 257 return MATCHnomatch; 258 258 } 259 259 260 260 assert (dedtypes_dim == parameters_dim); 261 assert (dedtypes_dim >= ti.tiargs.size() || variadic);261 assert (dedtypes_dim >= size(ti.tiargs) || variadic); 262 262 263 263 // Set up scope for parameters trunk/descent.core/src/descent/internal/compiler/parser/TemplateInstance.java
r781 r790 108 108 // If more arguments than parameters, 109 109 // then this is no match. 110 if ( td.parameters.size() < tiargs.size()) {110 if (size(td.parameters) < size(tiargs)) { 111 111 if (null == td.isVariadic()) 112 112 continue; … … 133 133 td_best = td; 134 134 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 } 136 140 for (ASTDmdNode a : dedtypes) { 137 141 tdtypes.add(a); … … 149 153 td_best = td; 150 154 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 } 152 160 for (ASTDmdNode a : dedtypes) { 153 161 tdtypes.add(a); … … 285 293 // buf.printf("__T%zu%s", id.length(), id); 286 294 args = tiargs; 287 for (int i = 0; i < args.size(); i++) {295 for (int i = 0; i < size(args); i++) { 288 296 ASTDmdNode o = (ASTDmdNode) args.get(i); 289 297 Type ta = isType(o); … … 538 546 { 539 547 inst = this; 540 //printf("error return %p, %d\n", tempdecl, global.errors);541 548 return; // error recovery 542 549 } … … 843 850 nest = true; 844 851 Objects args = tiargs; 845 for(i = 0; i < args.size(); i++)852 for(i = 0; i < size(args); i++) 846 853 { 847 854 if(i > 0) … … 876 883 Dsymbol[] sa = { isDsymbol(o) }; 877 884 878 if (ta != null) {885 if (ta[0] != null) { 879 886 // It might really be an Expression or an Alias 880 887 ta[0].resolve(loc, sc, ea, ta, sa, context); 881 if (ea != null) {888 if (ea[0] != null) { 882 889 ea[0] = ea[0].semantic(sc, context); 883 890 ea[0] = ea[0].optimize(WANTvalue | WANTinterpret, context); … … 893 900 j--; 894 901 } 895 } else if (ta != null) {902 } else if (ta[0] != null) { 896 903 if (ta[0].ty == Ttuple) { // Expand tuple 897 904 TypeTuple tt = (TypeTuple) ta[0]; … … 902 909 for (int i = 0; i < dim; i++) { 903 910 Argument arg = (Argument) tt.arguments.get(i); 904 tiargs. add(j + i, arg.type);911 tiargs.set(j + i, arg.type); 905 912 } 906 913 } 907 914 j--; 908 } else 909 tiargs.add(j, ta[0]); 915 } else { 916 tiargs.set(j, ta[0]); 917 } 910 918 } else { 911 919 if (context.global.errors == 0) { trunk/descent.core/src/descent/internal/compiler/parser/TemplateMixin.java
r770 r790 2 2 3 3 import melnorme.miscutil.tree.TreeVisitor; 4 import descent.core.compiler.IProblem; 4 5 import descent.internal.compiler.parser.ast.IASTVisitor; 5 6 import static descent.internal.compiler.parser.PROT.PROTpublic; … … 126 127 } 127 128 if (null == s) { 128 error("is not defined");129 context.acceptProblem(Problem.newSemanticTypeError(IProblem.SymbolNotDefined, 0, typeStart, typeLength, new String[] { toChars(context) })); 129 130 inst = this; 130 131 return; … … 132 133 tempdecl = s.toAlias(context).isTemplateDeclaration(); 133 134 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) })); 135 136 inst = this; 136 137 return; trunk/descent.core/src/descent/internal/compiler/parser/TypeInstance.java
r741 r790 2 2 3 3 import melnorme.miscutil.tree.TreeVisitor; 4 import descent.core.compiler.IProblem; 4 5 import descent.internal.compiler.parser.ast.IASTVisitor; 5 6 … … 143 144 144 145 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) })); 146 147 t[0] = tvoid; 147 148 } trunk/descent.core/src/descent/internal/compiler/parser/TypeQualified.java
r770 r790 260 260 int i; 261 261 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 } 272 274 } 273 275 } trunk/descent.core/template/problem/problems.txt
r783 r790 476 476 formatString=Types %1$s and %2$s are incompatible for %3$s 477 477 numArgs=3 478 479 480 481 482 483 484 478 SymbolNotDefined 479 formatString=%1$s is not defined 480 numArgs=1 481 SymbolNotATemplate 482 formatString=%1$s is not a template 483 numArgs=1 484 CannotDeleteType 485 formatString=Cannot delete type %1$s 486 numArgs=1 487 NotAnLvalue 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 1053 1053 } 1054 1054 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 1055 1087 1056 1088 /* TODO test for SemanticContext.IN_GCC = true
