diff --git a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag index cb3828343ebf6e843d2b85365e73129e4dffe28b..d36f2cb13090843d59689191f2a324b0bd0d1ed2 100644 --- a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag +++ b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag @@ -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; }