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 {
// collect all scopes
TypeDecl 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
// TODO exclude declarators not in statements (for, enhancedfor, try)
Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
ResourceDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope();
ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for succeedingScope();
ParameterDeclaration contributes asDeclaration() to ASTNode.scope() for containingScope();
/** fallback attribute to ensure every AST element could pontentially be a scope */
syn Scope ASTNode.asScope() {
......@@ -56,20 +55,17 @@ aspect ProgramToScopeTree {
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();
// contained in scope:
eq Program.getChild().containingScope() = this;
eq TypeDecl.getChild().containingScope() = this;
eq Block.getChild().containingScope() = this;
/** determine the scope an AST element belongs to (but is not technically contained in) */
inh ASTNode ParameterDeclaration.succeedingScope();
eq LambdaExpr.getLambdaParameters().succeedingScope() = getLambdaBody().isBlockBody()? ((BlockLambdaBody)getLambdaBody()).getBlock() : null;
eq BasicCatch.getParameter().succeedingScope() = getBlock();
eq MethodDecl.getParameter().succeedingScope() = getBlock();
eq ConstructorDecl.getParameter().succeedingScope() = getBlock();
inh ASTNode ResourceDeclaration.succeedingScope();
eq TryWithResources.getResource().succeedingScope() = getBlock();
eq EnhancedForStmt.getVariableDecl().succeedingScope() = (getStmt() instanceof Block) ? getStmt() : null;
eq VarDeclStmt.getDeclarator().succeedingScope() = null;
// belonging to scope
eq LambdaExpr.getLambdaParameters().containingScope() = getLambdaBody().isBlockBody()? ((BlockLambdaBody)getLambdaBody()).getBlock() : null;
eq BasicCatch.getParameter().containingScope() = getBlock();
eq MethodDecl.getParameter().containingScope() = getBlock();
eq ConstructorDecl.getParameter().containingScope() = getBlock();
eq TryWithResources.getResource().containingScope() = getBlock();
eq EnhancedForStmt.getVariableDecl().containingScope() = (getStmt() instanceof Block) ? getStmt() : null;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment