Skip to content
Snippets Groups Projects
Commit 24a4d16b authored by Johannes Mey's avatar Johannes Mey
Browse files

improved java scope tree generation. failed to reach my goal of aligning all...

improved java scope tree generation. failed to reach my goal of aligning all constructor methods. SAD!
parent 4fcbb2d0
No related branches found
No related tags found
No related merge requests found
......@@ -2,36 +2,34 @@ aspect ProgramToScopeTree {
coll ScopeTree Program.scopeTree() [asScopeTree()] with addElement root Program;
TypeDecl contributes scope() when !isClassDecl() to Program.scopeTree();
ClassDecl contributes publicScope() when !isInnerType() && !superclass().compilationUnit().fromSource() to Program.scopeTree();
ClassDecl contributes protectedScope() when !isInnerType() && !superclass().compilationUnit().fromSource() to Program.scopeTree();
/** a relational nta collection attribute to compute the scope tree */
coll Scope ASTNode.scope() [asScope()] with addElement root Program;
coll TypeDeclScope ClassDecl.packageScope() [asPackageScope()] with addElement root Program;
coll TypeDeclScope ClassDecl.protectedScope() [asProtectedScope()] with addElement root Program;
coll TypeDeclScope ClassDecl.publicScope() [asPublicScope()] with addElement root Program;
// collect all scopes
TypeDecl contributes scope() when !isClassDecl() to ASTNode.scope() for containingScope();
ClassDecl contributes publicScope() when isInnerClass() to ASTNode.scope() for containingScope();
ClassDecl contributes publicScope()
when superclass().compilationUnit().fromSource() && !isInnerClass() && accessibleFromPackage(containingScope().hostPackage())
to ClassDecl.packageScope()
ClassDecl contributes protectedScope()
when !(!isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource())
to ASTNode.scope()
for containingScope();
ClassDecl contributes publicScope()
when superclass().compilationUnit().fromSource() && !isInnerClass() && !accessibleFromPackage(containingScope().hostPackage())
ClassDecl contributes protectedScope()
when !isInnerClass() && superclass().isClassDecl() && superclass().compilationUnit().fromSource()
to ClassDecl.protectedScope()
for containingScope();
for superclass();
Block contributes scope() to ASTNode.scope() for containingScope();
ForStmt contributes scope() when !(getStmt() instanceof Block) to ASTNode.scope() for containingScope();
EnhancedForStmt contributes scope() when !(getStmt() instanceof Block) to ASTNode.scope() for containingScope();
// collect all elements
Declarator contributes asDeclaration() when !isField() || isPrivate() to ASTNode.scope() for containingScope();
Declarator contributes asDeclaration() when isField() && !(isPrivate() || isProtected() || isPublic()) to ClassDecl.packageScope() for containingScope();
Declarator contributes asDeclaration() when isField() && isProtected() to ClassDecl.protectedScope() for containingScope();
Declarator contributes asDeclaration() when isField() && isPublic() to ClassDecl.publicScope() for containingScope();
Declarator contributes asDeclaration() when isField() && !isPrivate() to ClassDecl.protectedScope() for containingScope();
ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for containingScope();
// if it was not for the single line in asProtectedScope(), the rest of this aspect could have been generated
// automatically, which would have been much nicer!
syn lazy ScopeTree Program.asScopeTree() {
ScopeTree tree = new ScopeTree();
tree.setProgram(this);
......@@ -49,26 +47,16 @@ aspect ProgramToScopeTree {
return scope;
}
syn lazy TypeDeclScope ClassDecl.asPublicScope() {
TypeDeclScope scope = new TypeDeclScope();
scope.setTypeDecl(this);
scope.addElement(protectedScope());
return scope;
}
syn lazy TypeDeclScope ClassDecl.asProtectedScope() {
TypeDeclScope scope = new TypeDeclScope();
scope.setTypeDecl(this);
scope.addElement(packageScope());
return scope;
}
syn lazy TypeDeclScope ClassDecl.asPackageScope() {
TypeDeclScope scope = new TypeDeclScope();
scope.setTypeDecl(this);
scope.addElement(scope());
scope.addElement(scope()); // this irregular statement is necessary because of either a bug or a limitation in JastAdd collections
return scope;
}
// the following commented statement unfortunately does not work, because during the contribution phase, the information
// which target should be contributed to is lost if there are multiple targets. Maybe I got it wrong, but I tried many things
// and JastAdd always wants to also add the contribution made in line 17ff to this target as well.
// ClassDecl contributes scope() to ClassDecl.protectedScope() for this;
syn lazy BlockScope Block.asScope() {
BlockScope scope = new BlockScope();
......@@ -124,14 +112,6 @@ aspect ScopeGenerationAttributes {
eq EnhancedForStmt.getVariableDecl().containingScope() = (getStmt() instanceof Block) ? getStmt() : this;
eq ForStmt.getInitStmt().containingScope() = (getStmt() instanceof Block) ? getStmt() : this;
eq ForStmt.getUpdateStmt().containingScope() = (getStmt() instanceof Block) ? getStmt() : this;
// belonging to visibility scope
eq CompilationUnit.getTypeDecl(int i).containingScope() {
if (getTypeDecl(i).isClassDecl()) {
TypeDecl superclass = ((ClassDecl)getTypeDecl(i)).superclass();
return superclass.compilationUnit().fromSource() ? superclass : this;
}
return this;
}
// allow host package to be called from all AST nodes
inh String ASTNode.hostPackage();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment