Commit b55e635a authored by Niklas Fors's avatar Niklas Fors
Browse files

Add more error report

parent 649c8133
......@@ -18,29 +18,14 @@ aspect TypeAnalysis {
}
aspect ComponentAnalysis {
syn boolean Component.isDeclaringName() = true;
eq RelationComponent.isDeclaringName() = !isTargetOfRightDirection();
syn boolean Component.isTargetOfDirectedRelation() = false;
eq RelationComponent.isTargetOfDirectedRelation() = isTargetOfRightDirection();
inh boolean RelationComponent.isTargetOfRightDirection();
eq Relation.getRight().isTargetOfRightDirection()
= getDirection() instanceof RightDirection;
eq Program.getChild().isTargetOfRightDirection() = false;
syn String Component.name() {
if (!isDeclaringName()) {
return "";
}
if (!getID().isEmpty()) {
return getID();
}
return otherRelationSideName();
}
inh String Component.otherRelationSideName();
eq Relation.getLeft().otherRelationSideName()
= getRight().getTypeUse().getID();
eq Relation.getRight().otherRelationSideName()
= getLeft().getTypeUse().getID();
eq Program.getChild().otherRelationSideName()
= "";
syn String Component.name() = getID();
syn TypeDecl Component.toTypeDecl() = enclosingTypeDecl();
eq RelationComponent.toTypeDecl() = getTypeUse().decl();
......@@ -53,7 +38,8 @@ aspect ComponentAnalysis {
eq Program.getChild().ofTypeDecl() = null;
syn boolean Component.isAlreadyDeclared()
= isDeclaringName() && lookupComponent(toTypeDecl(), name()) != this;
= !isTargetOfDirectedRelation()
&& lookupComponent(toTypeDecl(), name()) != this;
inh Component Component.lookupComponent(TypeDecl td, String name);
eq Program.getChild().lookupComponent(TypeDecl td, String name) {
if (td != null) {
......@@ -73,7 +59,7 @@ aspect ComponentAnalysis {
}
syn RelationComponent RelationComponent.lookup(TypeDecl td, String name)
= isDeclaringName() && toTypeDecl() == td && name().equals(name)
= !isTargetOfDirectedRelation() && toTypeDecl() == td && name().equals(name)
? this
: null;
......@@ -82,7 +68,7 @@ aspect ComponentAnalysis {
[new HashSet<RelationComponent>()]
root Program;
RelationComponent contributes this
when isDeclaringName() && toTypeDecl() != null
when !isTargetOfDirectedRelation() && toTypeDecl() != null
to TypeDecl.relationComponents()
for toTypeDecl();
}
......
......@@ -128,7 +128,7 @@ aspect PrettyPrint {
}
}
public String OptionalRelationComponent.prettyPrint() {
return "[" + super.prettyPrint() + "]";
return super.prettyPrint() + "?";
}
public String ManyRelationComponent.prettyPrint() {
return super.prettyPrint() + "*";
......
......@@ -21,7 +21,12 @@ aspect DumpTree {
public void ASTNode.dumpTree(PrintStream out, String indent) {
out.print(indent + getClass().getSimpleName());
out.println(getTokens());
out.print(getTokens());
String extra = extraDumpInfo();
if (!extra.isEmpty()) {
out.print(" " + extra);
}
out.println();
String childIndent = indent + DUMP_TREE_INDENT;
for (ASTNode child : astChildren()) {
if (child == null) {
......@@ -32,6 +37,8 @@ aspect DumpTree {
}
}
public String ASTNode.extraDumpInfo() { return ""; }
public String ASTNode.getTokens() {
java.util.TreeSet<java.lang.reflect.Method> methods = new java.util.TreeSet<>(
new java.util.Comparator<java.lang.reflect.Method>() {
......
......@@ -19,6 +19,21 @@ aspect Errors {
+ "' is already declared for type '" + toTypeDecl() + "'")
when isAlreadyDeclared()
to Program.errors();
RelationComponent contributes
error("Role name missing for type '" + toTypeDecl() + "'")
when !isTargetOfDirectedRelation() && name().isEmpty()
to Program.errors();
RelationComponent contributes
error("The target of a directed relation cannot have a role name")
when isTargetOfDirectedRelation() && !getID().isEmpty()
to Program.errors();
RelationComponent contributes
error("The target of a directed relation may only have multiplicity 1")
when isTargetOfDirectedRelation() && !hasMultiplicityOne()
to Program.errors();
}
aspect HelpAttributes {
......@@ -28,6 +43,9 @@ aspect HelpAttributes {
inh boolean TypeUse.isToken();
eq Program.getChild().isToken() = false;
eq TokenComponent.getTypeUse().isToken() = true;
syn boolean RelationComponent.hasMultiplicityOne() = false;
eq OneRelationComponent.hasMultiplicityOne() = true;
}
aspect ErrorMessage {
......
......@@ -34,6 +34,7 @@ public class Compiler {
Program p = parseProgram(commandLine.getArguments().get(0));
if (!p.errors().isEmpty()) {
System.out.println(p.dumpTree());
System.err.println("Errors:");
for (ErrorMessage e: p.errors()) {
System.err.println(e);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment