Skip to content
Snippets Groups Projects
Commit d7192852 authored by René Schöne's avatar René Schöne
Browse files

Merge branch 'component-reordering' into 'master'

reordering of components is allowed

See merge request johannes.mey/relast!3
parents 2568fb4c d6c9f0ce
No related branches found
No related tags found
1 merge request!3reordering of components is allowed
Pipeline #4559 passed
......@@ -62,12 +62,6 @@ aspect ComponentAnalysis {
eq Program.getChild().lookupComponent(TypeDecl td, String name)
= lookupComponentSyn(td, name);
syn Component Program.lookupComponentSyn(TypeDecl td, String name) {
// Check super type first to find duplicates (shadowing is not allowed)
if (td.hasSuper() && td.getSuper().decl() != null) {
Component c = lookupComponentSyn(td.getSuper().decl(), name);
if (c != null) return c;
}
for (Component c: td.getComponents()) {
if (c.name().equals(name)) {
return c;
......@@ -84,6 +78,36 @@ aspect ComponentAnalysis {
return null;
}
syn boolean Component.isInvalidRedefinition() {
if (toTypeDecl() == null) return false;
TypeDecl td = toTypeDecl();
while (td.hasSuper() && td.getSuper().decl() != null) {
td = td.getSuper().decl();
Component c = lookupComponent(td, getID());
if (c != null && isTargetOfDirectedRelation()) return true;
if (c != null && !this.isEqual(c)) return true;
}
return false;
}
syn boolean Component.isEqual(Component c) = this.getClass() == c.getClass() && getTypeUse().isEqual(c.getTypeUse());
syn boolean TypeUse.isEqual(TypeUse u);
eq SimpleTypeUse.isEqual(TypeUse u) = u instanceof SimpleTypeUse && getID().equals(u.getID());
eq ParameterizedTypeUse.isEqual(TypeUse u) {
if (!getID().equals(u.getID())) return false;
if (!(u instanceof ParameterizedTypeUse)) return false;
ParameterizedTypeUse pu = (ParameterizedTypeUse) u;
if (getNumTypeUse() != pu.getNumTypeUse()) return false;
for (int i = 0; i < getNumTypeUse(); i++) {
if (!getTypeUse(i).isEqual(pu.getTypeUse(i))) return false;
}
return true;
}
syn RelationComponent RelationComponent.lookup(TypeDecl td, String name)
= !isTargetOfDirectedRelation() && toTypeDecl() == td && name().equals(name)
? this
......
......@@ -20,6 +20,11 @@ aspect Errors {
when isAlreadyDeclared()
to Program.errors();
Component contributes error("Component '" + name()
+ "' is an invalid redefition for type '" + toTypeDecl() + "'")
when isInvalidRedefinition()
to Program.errors();
RelationComponent contributes
error("Role name missing for type '" + toTypeDecl() + "'")
when !isTargetOfDirectedRelation() && name().isEmpty()
......
Errors:
$FILENAME Line 2, column 12: Component 'X' is already declared for type 'B1'
$FILENAME Line 6, column 5: Component 'X' is already declared for type 'B2'
$FILENAME Line 4, column 12: Component 'X' is an invalid redefition for type 'B3'
$FILENAME Line 7, column 5: Component 'X' is an invalid redefition for type 'B2'
A ::= X;
B1 : A ::= X;
B2 : A;
B3 : A ::= <X:String>;
X;
rel B2.X -> X;
Errors:
$FILENAME Line 2, column 12: Component 'X' is already declared for type 'B1'
$FILENAME Line 6, column 10: Component 'X' is already declared for type 'B2'
$FILENAME Line 4, column 12: Component 'X' is an invalid redefition for type 'B3'
$FILENAME Line 7, column 10: Component 'X' is an invalid redefition for type 'B2'
A ::= X;
B1 : A ::= X;
B2 : A;
B3 : A ::= <X:String>;
X;
rel X <- B2.X;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment