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
62207526
Commit
62207526
authored
Dec 23, 2019
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
add extendj analysis
parent
5e085bce
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+1
-30
1 addition, 30 deletions
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
scope4j/src/main/java/org/extendj/ScopeAnalysis.java
+8
-0
8 additions, 0 deletions
scope4j/src/main/java/org/extendj/ScopeAnalysis.java
with
9 additions
and
30 deletions
scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+
1
−
30
View file @
62207526
...
@@ -16,9 +16,6 @@ aspect ProgramToScopeTree {
...
@@ -16,9 +16,6 @@ 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();
// Block contributes scope() when isScope() to ASTNode.scope() for containingScope();
// MethodDecl contributes scope() to ASTNode.scope() for containingScope();
// ConstructorDecl contributes scope() to ASTNode.scope() for containingScope();
// collect all elements
// collect all elements
Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
...
@@ -29,34 +26,18 @@ aspect ProgramToScopeTree {
...
@@ -29,34 +26,18 @@ aspect ProgramToScopeTree {
throw new RuntimeException("unable to create a scope for type " + getClass().getSimpleName());
throw new RuntimeException("unable to create a scope for type " + getClass().getSimpleName());
}
}
// TypeDecl is a scope
syn lazy TypeDeclScope TypeDecl.asScope() {
syn lazy TypeDeclScope TypeDecl.asScope() {
TypeDeclScope scope = new TypeDeclScope();
TypeDeclScope scope = new TypeDeclScope();
scope.setTypeDecl(this);
scope.setTypeDecl(this);
return scope;
return scope;
}
}
// Block can be a scope
syn lazy BlockScope Block.asScope() {
syn lazy BlockScope Block.asScope() {
BlockScope scope = new BlockScope();
BlockScope scope = new BlockScope();
scope.setBlock(this);
scope.setBlock(this);
return scope;
return scope;
}
}
// // MethodDecl is a scope
// syn lazy MethodDeclScope MethodDecl.asScope() {
// MethodDeclScope scope = new MethodDeclScope();
// scope.setMethodDecl(this);
// return scope;
// }
// // ConstructorDecl is a scope
// syn lazy ConstructorDeclScope ConstructorDecl.asScope() {
// ConstructorDeclScope scope = new ConstructorDeclScope();
// scope.setConstructorDecl(this);
// return scope;
// }
syn lazy JavaDeclaration Declarator.asDeclaration() {
syn lazy JavaDeclaration Declarator.asDeclaration() {
JavaDeclaration decl = new JavaDeclaration(getID());
JavaDeclaration decl = new JavaDeclaration(getID());
decl.setDeclarator(this);
decl.setDeclarator(this);
...
@@ -69,25 +50,15 @@ aspect ProgramToScopeTree {
...
@@ -69,25 +50,15 @@ aspect ProgramToScopeTree {
return decl;
return decl;
}
}
}
}
aspect ScopeGenerationAttributes {
aspect ScopeGenerationAttributes {
// /** determine if a block is a scope (which is not the case if it is directly contained in a scope) */
// syn boolean Block.isScope() {
// ASTNode parent = getParent();
// if (parent instanceof List || parent instanceof Opt) parent = parent.getParent();
// return !(parent instanceof MethodDecl || parent instanceof ConstructorDecl);
// }
/** determine the scope an AST element is contained in */
/** determine the scope an AST element is contained in */
inh lazy ASTNode ASTNode.containingScope();
inh lazy ASTNode ASTNode.containingScope();
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; //isScope() ? this : containingScope();
eq Block.getChild().containingScope() = this;
// eq MethodDecl.getChild().containingScope() = this;
// eq ConstructorDecl.getChild().containingScope() = this;
/** determine the scope an AST element belongs to (but is not technically contained in) */
/** determine the scope an AST element belongs to (but is not technically contained in) */
inh ASTNode ParameterDeclaration.succeedingScope();
inh ASTNode ParameterDeclaration.succeedingScope();
...
...
This diff is collapsed.
Click to expand it.
scope4j/src/main/java/org/extendj/ScopeAnalysis.java
+
8
−
0
View file @
62207526
...
@@ -49,6 +49,14 @@ public class ScopeAnalysis extends Frontend {
...
@@ -49,6 +49,14 @@ public class ScopeAnalysis extends Frontend {
scopeTree
.
printAST
();
scopeTree
.
printAST
();
System
.
out
.
println
(
"\nExtendJ found the following problems:"
);
for
(
CompilationUnit
unit
:
program
.
getCompilationUnitList
())
{
for
(
Problem
problem:
unit
.
problems
())
{
System
.
out
.
println
(
problem
);
}
}
System
.
out
.
println
(
"\n"
);
long
startAnalysisTime
=
System
.
nanoTime
();
long
startAnalysisTime
=
System
.
nanoTime
();
Set
<
VariableShadowFinding
>
findings
=
scopeTree
.
variableShadowings
();
Set
<
VariableShadowFinding
>
findings
=
scopeTree
.
variableShadowings
();
...
...
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