Collect the errors for a node recursively.
Collect the errors for a node recursively.
public void ASTNode.collectErrors(Collection c) { for(int i = 0; i < getNumChild(); i++) getChild(i).collectErrors(c); }
public void AssignStmt.collectErrors(Collection c) { super.collectErrors(c); if(!getValue().type().isSubtypeOf(getVariable().type())) error(c, "Can not assign a variable of type " + getVariable().type().getName() + " to a value of type " + getValue().type().getName()); }
public void ClassDecl.collectErrors(Collection c) { super.collectErrors(c); if(hasCycleOnSuperclassChain()) error(c, "Cyclic inheritance chain for class " + getName()); }
public void WhileStmt.collectErrors(Collection c) { super.collectErrors(c); if(!getCondition().type().isSubtypeOf(booleanType())) error(c, "Condition must be a boolean expression"); if(!getCondition().isValue()) error(c, "Condition must be a value"); }
public void IdnUse.collectErrors(Collection c) { super.collectErrors(c); if(decl().isUnknown() && (!isQualified() || !qualifier().type().isUnknown())) error(c, "Unknown identifier " + getName()); }
All of the error messages for a program.
All of the error messages for a program.
public Collection Program.errors() { Collection c = new ArrayList(); collectErrors(c); return c; }
Is this entity qualified?
Is this entity qualified?
eq Program.getBlock().isQualified() = false; eq Program.getPredefinedType(int i).isQualified() = false; eq Dot.getIdnUse().isQualified() = true; inh boolean IdnUse.isQualified(); inh boolean TypeDecl.isQualified();
What is the qualifier?
What is the qualifier?
eq Program.getBlock().qualifier() { throw new Error("Can not compute qualifier for non qualified names"); } eq Program.getPredefinedType(int i).qualifier() { throw new Error("Can not compute qualifier for non qualified names"); } eq Dot.getIdnUse().qualifier() = getObjectReference(); inh Access IdnUse.qualifier(); inh Access TypeDecl.qualifier();
Record a new error in the collection.
Record a new error in the collection.
protected void ASTNode.error(Collection c, String s) { //c.add(getLine(getStart()) + ": " + s); c.add(s); }