Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Reusable Analysis
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
Reusable Analysis
Commits
6e540cea
Commit
6e540cea
authored
5 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
simplify (and correct) scope analysis
parent
8c334682
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+11
-15
11 additions, 15 deletions
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
with
11 additions
and
15 deletions
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+
11
−
15
View file @
6e540cea
...
@@ -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;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment