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

add extendj analysis

parent 5e085bce
No related branches found
No related tags found
No related merge requests found
...@@ -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();
......
...@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment