import java.util.Collection;

aspect ErrorCheck {

    syn int ASTNode.lineNumber() = getLine(getStart());

    protected String ASTNode.errors = null;

    protected void ASTNode.error(String s) {
        s = "Error at " + lineNumber() + ": " + s;
        if(errors == null) {
          errors = s;
        } else {
          errors = errors + "\n" + s;
        }
    }

    protected boolean ASTNode.hasErrors() {
        return errors != null;
    }
    public void ASTNode.errorCheck(Collection collection) {
        nameCheck();
        typeCheck();
        if(hasErrors())
        collection.add(errors);
        for(int i = 0; i < getNumChild(); i++) {
        getChild(i).errorCheck(collection);
        }
    }
}