Skip to content
Snippets Groups Projects
Commit b55e635a authored by Niklas Fors's avatar Niklas Fors
Browse files

Add more error report

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