Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
JastAdd
relational-rags
Commits
5fbb5a86
Commit
5fbb5a86
authored
Oct 21, 2019
by
René Schöne
Browse files
Remove confusing attribute toTypeDecl.
- Changed error message for invalid redefinition
parent
6e142ca9
Pipeline
#4660
passed with stage
in 2 minutes and 21 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/jastadd/Analysis.jrag
View file @
5fbb5a86
...
...
@@ -30,12 +30,6 @@ aspect ComponentAnalysis {
//--- name ---
syn String Component.name() = getID();
//--- toTypeDecl ---
/** @return enclosing type */
syn TypeDecl Component.toTypeDecl() = enclosingTypeDecl();
/** @return type of nonterminal relation role is defined for */
eq RelationComponent.toTypeDecl() = getTypeUse().decl();
//--- enclosingTypeDecl ---
inh TypeDecl Component.enclosingTypeDecl();
eq TypeDecl.getChild().enclosingTypeDecl() = this;
...
...
@@ -48,7 +42,7 @@ aspect ComponentAnalysis {
eq Program.getChild().otherSide() = null;
//--- ofTypeDecl ---
syn TypeDecl RelationComponent.ofTypeDecl() = otherSide().t
o
Type
D
ecl();
syn TypeDecl RelationComponent.ofTypeDecl() = otherSide().
ge
tType
Use().d
ecl();
//--- isAlreadyDeclared ---
/**
...
...
@@ -56,8 +50,8 @@ aspect ComponentAnalysis {
*/
syn boolean RelationComponent.isAlreadyDeclared()
= !isTargetOfDirectedRelation() /* if unnamed in relation, there is no role name, so no error */
&& t
o
Type
D
ecl() != null /* nonterminal type of role is defined */
&& findComponent(t
o
Type
D
ecl(), name()) != this; /* there is another role defined previously with the same name */
&&
ge
tType
Use().d
ecl() != null /* nonterminal type of role is defined */
&& findComponent(
ge
tType
Use().d
ecl(), name()) != this; /* there is another role defined previously with the same name */
//--- findComponent ---
/** Search for either a component on the RHS of the given type with the given name,
...
...
@@ -82,12 +76,16 @@ aspect ComponentAnalysis {
return null;
}
/* Should this better return the component, where it is defined previously defined? */
//--- isInvalidRedefinition ---
/**
* Check, if a component with the same name is already declared in some supertype
*/
syn boolean Component.isInvalidRedefinition() {
TypeDecl td = toTypeDecl();
syn boolean Component.isInvalidRedefinition() = false;
eq TokenComponent.isInvalidRedefinition() = hasInvalidRedefinitionOn(enclosingTypeDecl());
eq RelationComponent.isInvalidRedefinition() = hasInvalidRedefinitionOn(getTypeUse().decl());
syn boolean Component.hasInvalidRedefinitionOn(TypeDecl td) {
if (td == null) return false;
while (td.hasSuper() && td.getSuper().decl() != null) {
...
...
@@ -121,16 +119,16 @@ aspect ComponentAnalysis {
* @return true, if the component has both type and role, its type matches the given typeDecl and its name matches the given name
*/
syn boolean RelationComponent.matches(TypeDecl td, String name)
= !isTargetOfDirectedRelation() && t
o
Type
D
ecl() == td && name().equals(name);
= !isTargetOfDirectedRelation() &&
ge
tType
Use().d
ecl() == td && name().equals(name);
//--- relationComponents ---
coll Set<RelationComponent> TypeDecl.relationComponents()
[new HashSet<RelationComponent>()]
root Program;
RelationComponent contributes this
when !isTargetOfDirectedRelation() && t
o
Type
D
ecl() != null
when !isTargetOfDirectedRelation() &&
ge
tType
Use().d
ecl() != null
to TypeDecl.relationComponents()
for t
o
Type
D
ecl();
for
ge
tType
Use().d
ecl();
//--- relationComponentsTransitive ---
syn Collection<RelationComponent> TypeDecl.relationComponentsTransitive() {
...
...
src/main/jastadd/Backend.jadd
View file @
5fbb5a86
...
...
@@ -240,7 +240,7 @@ aspect BackendDirectedAPI {
generateGetOne(sb);
// Set
sb.append(ind(1) + "public " + t
o
Type
D
ecl() + " " + t
o
Type
D
ecl());
sb.append(ind(1) + "public " +
ge
tType
Use().d
ecl() + " " +
ge
tType
Use().d
ecl());
sb.append(".set" + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
if (!optional) {
sb.append(ind(2) + "assertNotNull(o);\n");
...
...
@@ -252,7 +252,7 @@ aspect BackendDirectedAPI {
public void ManyRelationComponent.generateDirectedAPI(StringBuilder sb) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl() + ".");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
...
...
@@ -260,7 +260,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl());
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
...
...
@@ -287,7 +287,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Add
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -302,7 +302,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -317,7 +317,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".remove");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
...
...
@@ -331,7 +331,7 @@ aspect BackendDirectedAPI {
}
public void RelationComponent.generateGetOne(StringBuilder sb) {
sb.append(ind(1) + "public " + ofTypeDecl() + " " + t
o
Type
D
ecl() + ".");
sb.append(ind(1) + "public " + ofTypeDecl() + " " +
ge
tType
Use().d
ecl() + ".");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
...
...
@@ -353,7 +353,7 @@ aspect BackendDirectedAPI {
public void RelationComponent.generateExtraOptAPI(StringBuilder sb) {
// has
sb.append(ind(1) + "public boolean " + t
o
Type
D
ecl());
sb.append(ind(1) + "public boolean " +
ge
tType
Use().d
ecl());
sb.append(".has" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "return ");
if (useJastAddNames) {
...
...
@@ -365,7 +365,7 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// clear
sb.append(ind(1) + "public void " + t
o
Type
D
ecl());
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl());
sb.append(".clear" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "set" + nameCapitalized() + "(null);\n");
sb.append(ind(1) + "}\n");
...
...
@@ -418,7 +418,7 @@ aspect BackendBidirectionalAPI {
generateGetOne(sb);
// Set
sb.append(ind(1) + "public " + t
o
Type
D
ecl() + " " + t
o
Type
D
ecl());
sb.append(ind(1) + "public " +
ge
tType
Use().d
ecl() + " " +
ge
tType
Use().d
ecl());
sb.append(".set" + nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
if (!isOpt) {
sb.append(ind(2) + "assertNotNull(o);\n");
...
...
@@ -465,7 +465,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyMany(StringBuilder sb, RelationComponent opposite) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl() + ".");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
...
...
@@ -473,7 +473,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl());
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
...
...
@@ -489,7 +489,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(5) + "changed = true;\n");
sb.append(ind(5) + ofTypeDecl() + " resolvedElement = resolve" + nameCapitalized() + "ByToken(element.as$Unresolved().getUnresolved$Token(), i);\n");
sb.append(ind(5) + "if (resolvedElement != null && element.as$Unresolved().getUnresolved$ResolveOpposite()) {\n");
sb.append(ind(6) + ASTNode.listClass + "<" + t
o
Type
D
ecl() + "> otherList = resolvedElement." + opposite.getImplAttributeField() + ";\n");
sb.append(ind(6) + ASTNode.listClass + "<" +
ge
tType
Use().d
ecl() + "> otherList = resolvedElement." + opposite.getImplAttributeField() + ";\n");
sb.append(ind(6) + "if (otherList == null) {\n");
sb.append(ind(7) + "otherList = new " + listClass + "<>();\n");
sb.append(ind(6) + "}\n");
...
...
@@ -508,7 +508,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Add
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -529,7 +529,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -551,7 +551,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".remove");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
...
...
@@ -571,7 +571,7 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyOne(StringBuilder sb, RelationComponent opposite) {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl() + ".");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
...
...
@@ -579,7 +579,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + t
o
Type
D
ecl());
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " +
ge
tType
Use().d
ecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
...
...
@@ -595,7 +595,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(5) + "changed = true;\n");
sb.append(ind(5) + ofTypeDecl() + " resolvedElement = resolve" + nameCapitalized() + "ByToken(element.as$Unresolved().getUnresolved$Token(), i);\n");
sb.append(ind(5) + "if (element.as$Unresolved().getUnresolved$ResolveOpposite()) {\n");
sb.append(ind(6) + t
o
Type
D
ecl() + " oldTarget = resolvedElement." + opposite.getImplAttributeField() + ";\n");
sb.append(ind(6) +
ge
tType
Use().d
ecl() + " oldTarget = resolvedElement." + opposite.getImplAttributeField() + ";\n");
sb.append(ind(6) + "if (oldTarget != null && oldTarget != this) {\n");
sb.append(ind(7) + "oldTarget." + getImplAttributeField() + ".remove(resolvedElement);\n");
sb.append(ind(6) + "}\n");
...
...
@@ -620,7 +620,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Add
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -643,7 +643,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".add");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
...
...
@@ -664,7 +664,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Remove
sb.append(ind(1) + "public void " + t
o
Type
D
ecl() + ".remove");
sb.append(ind(1) + "public void " +
ge
tType
Use().d
ecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
...
...
@@ -685,13 +685,13 @@ aspect BackendBidirectionalAPI {
generateGetOne(sb);
// Set
sb.append(ind(1) + "public " + t
o
Type
D
ecl() + " " + t
o
Type
D
ecl() + ".set" + nameCapitalized()
sb.append(ind(1) + "public " +
ge
tType
Use().d
ecl() + " " +
ge
tType
Use().d
ecl() + ".set" + nameCapitalized()
+ "(" + ofTypeDecl() + " o) {\n");
if (!isOpt) {
sb.append(ind(2) + "assertNotNull(o);\n");
}
sb.append(ind(2) + "if (" + getImplAttributeField() + " != null) {\n");
sb.append(ind(3) + ASTNode.listClass + "<" + t
o
Type
D
ecl() + "> list2 = " + getImplAttributeField()
sb.append(ind(3) + ASTNode.listClass + "<" +
ge
tType
Use().d
ecl() + "> list2 = " + getImplAttributeField()
+ "." + otherSide().getImplAttributeField() + ";\n");
sb.append(ind(3) + "list2.remove(this);\n");
sb.append(ind(3) + getImplAttributeField() + "." + "set"
...
...
@@ -703,7 +703,7 @@ aspect BackendBidirectionalAPI {
if (isOpt) {
sb.append(ind(2) + "if (o != null) {\n");
}
sb.append(ind(ind) + ASTNode.listClass + "<" + t
o
Type
D
ecl() + "> list = o."
sb.append(ind(ind) + ASTNode.listClass + "<" +
ge
tType
Use().d
ecl() + "> list = o."
+ otherSide().getImplAttributeField() + ";\n");
sb.append(ind(ind) + "if (list == null) {\n");
sb.append(ind(ind+1) + "list = new " + ASTNode.listClass + "<>();\n");
...
...
@@ -933,13 +933,13 @@ aspect NameResolutionHelper {
public void ManyRelationComponent.generateContextDependentNameResolution(StringBuilder sb) {
if (serializer && !resolverHelper) {
sb.append(ind(1) + ofTypeDecl() + " " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(1) + ofTypeDecl() + " " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(2) + "return (" + ofTypeDecl() + ") globallyResolveASTNodeByUID(id);\n");
sb.append(ind(1) + "}\n");
} else {
sb.append(ind(1) + "// context-dependent name resolution\n");
sb.append(ind(1) + "uncache " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position);\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(1) + "uncache " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position);\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id, int position) {\n");
sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n");
sb.append(ind(1) + "}\n");
...
...
@@ -948,13 +948,13 @@ aspect NameResolutionHelper {
public void RelationComponent.generateDirectedContextDependentNameResolution(StringBuilder sb) {
if (serializer && !resolverHelper) {
sb.append(ind(1) + ofTypeDecl() + " " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
sb.append(ind(1) + ofTypeDecl() + " " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
sb.append(ind(2) + "return (" + ofTypeDecl() + ") globallyResolveASTNodeByUID(id);\n");
sb.append(ind(1) + "}\n");
} else {
sb.append(ind(1) + "// context-dependent name resolution\n");
sb.append(ind(1) + "uncache " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id);\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " + t
o
Type
D
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
sb.append(ind(1) + "uncache " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id);\n");
sb.append(ind(1) + "syn " + ofTypeDecl() + " " +
ge
tType
Use().d
ecl() + ".resolve" + nameCapitalized() + "ByToken(String id) {\n");
sb.append(ind(2) + "// default to context-independent name resolution\n");
sb.append(ind(2) + "return globallyResolve" + ofTypeDecl() + "ByToken(id);\n");
sb.append(ind(1) + "}\n");
...
...
src/main/jastadd/Errors.jrag
View file @
5fbb5a86
...
...
@@ -16,17 +16,22 @@ aspect Errors {
to Program.errors();
RelationComponent contributes error("Role '" + name()
+ "' is already declared for type '" + t
o
Type
D
ecl() + "'")
+ "' is already declared for type '" +
ge
tType
Use().d
ecl() + "'")
when isAlreadyDeclared()
to Program.errors();
Component contributes error("Component '" + name()
+ "' is an invalid redefinition for type '" + toTypeDecl() + "'")
RelationComponent contributes error("Role '" + name()
+ "' is an invalid redefinition for type '" + getTypeUse().decl() + "'")
when isInvalidRedefinition()
to Program.errors();
TokenComponent contributes error("Token '" + name()
+ "' is an invalid redefinition for type '" + enclosingTypeDecl() + "'")
when isInvalidRedefinition()
to Program.errors();
RelationComponent contributes
error("Role name missing for type '" + t
o
Type
D
ecl() + "'")
error("Role name missing for type '" +
ge
tType
Use().d
ecl() + "'")
when !isTargetOfDirectedRelation() && name().isEmpty()
to Program.errors();
...
...
src/test/jastadd/errors/Inheritance.expected
View file @
5fbb5a86
Errors:
$FILENAME Line 4, column 12:
Compon
en
t
'X' is an invalid redefinition for type 'B3'
$FILENAME Line 7, column 5:
Component
'X' is an invalid redefinition for type 'B2'
$FILENAME Line 4, column 12:
Tok
en 'X' is an invalid redefinition for type 'B3'
$FILENAME Line 7, column 5:
Role
'X' is an invalid redefinition for type 'B2'
src/test/jastadd/errors/Inheritance.relast
View file @
5fbb5a86
...
...
@@ -5,4 +5,3 @@ B3 : A ::= <X:String>;
X;
rel B2.X -> X;
rel X.X -> B2;
src/test/jastadd/errors/InheritanceLeft.expected
View file @
5fbb5a86
Errors:
$FILENAME Line 4, column 12:
Compon
en
t
'X' is an invalid redefinition for type 'B3'
$FILENAME Line 7, column 10:
Component
'X' is an invalid redefinition for type 'B2'
$FILENAME Line 4, column 12:
Tok
en 'X' is an invalid redefinition for type 'B3'
$FILENAME Line 7, column 10:
Role
'X' is an invalid redefinition for type 'B2'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment