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

simplify (and correct) scope analysis

parent 8c334682
No related branches found
No related tags found
No related merge requests found
...@@ -16,12 +16,11 @@ aspect ProgramToScopeTree { ...@@ -16,12 +16,11 @@ aspect ProgramToScopeTree {
// collect all scopes // collect all scopes
TypeDecl contributes scope() to ASTNode.scope() for containingScope(); TypeDecl contributes scope() to ASTNode.scope() for containingScope();
Block contributes scope() to ASTNode.scope() for containingScope(); Block contributes scope() to ASTNode.scope() for containingScope();
// for and enhanced-for create a scope even if they do not contain a block
// collect all elements // collect all elements
// TODO exclude declarators not in statements (for, enhancedfor, try)
Declarator contributes asDeclaration() to ASTNode.scope() for containingScope(); Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
ResourceDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope(); ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for containingScope();
ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope();
/** fallback attribute to ensure every AST element could pontentially be a scope */ /** fallback attribute to ensure every AST element could pontentially be a scope */
syn Scope ASTNode.asScope() { syn Scope ASTNode.asScope() {
...@@ -56,20 +55,17 @@ aspect ProgramToScopeTree { ...@@ -56,20 +55,17 @@ aspect ProgramToScopeTree {
aspect ScopeGenerationAttributes { aspect ScopeGenerationAttributes {
/** determine the scope an AST element is contained in */ /** determine the scope an AST element is contained in or belongs to */
inh lazy ASTNode ASTNode.containingScope(); inh lazy ASTNode ASTNode.containingScope();
// contained in scope:
eq Program.getChild().containingScope() = this; eq Program.getChild().containingScope() = this;
eq TypeDecl.getChild().containingScope() = this; eq TypeDecl.getChild().containingScope() = this;
eq Block.getChild().containingScope() = this; eq Block.getChild().containingScope() = this;
// belonging to scope
/** determine the scope an AST element belongs to (but is not technically contained in) */ eq LambdaExpr.getLambdaParameters().containingScope() = getLambdaBody().isBlockBody()? ((BlockLambdaBody)getLambdaBody()).getBlock() : null;
inh ASTNode ParameterDeclaration.succeedingScope(); eq BasicCatch.getParameter().containingScope() = getBlock();
eq LambdaExpr.getLambdaParameters().succeedingScope() = getLambdaBody().isBlockBody()? ((BlockLambdaBody)getLambdaBody()).getBlock() : null; eq MethodDecl.getParameter().containingScope() = getBlock();
eq BasicCatch.getParameter().succeedingScope() = getBlock(); eq ConstructorDecl.getParameter().containingScope() = getBlock();
eq MethodDecl.getParameter().succeedingScope() = getBlock(); eq TryWithResources.getResource().containingScope() = getBlock();
eq ConstructorDecl.getParameter().succeedingScope() = getBlock(); eq EnhancedForStmt.getVariableDecl().containingScope() = (getStmt() instanceof Block) ? getStmt() : null;
inh ASTNode ResourceDeclaration.succeedingScope();
eq TryWithResources.getResource().succeedingScope() = getBlock();
eq EnhancedForStmt.getVariableDecl().succeedingScope() = (getStmt() instanceof Block) ? getStmt() : null;
eq VarDeclStmt.getDeclarator().succeedingScope() = null;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment