From 62207526da9c79dd116ca400ce6d77039cfd089f Mon Sep 17 00:00:00 2001
From: Johannes Mey <johannes.mey@tu-dresden.de>
Date: Mon, 23 Dec 2019 15:29:46 +0100
Subject: [PATCH] add extendj analysis

---
 .../src/main/jastadd/ProgramToScopeTree.jrag  | 31 +------------------
 .../main/java/org/extendj/ScopeAnalysis.java  |  8 +++++
 2 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
index 983afa4..a8c82ac 100644
--- a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+++ b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
@@ -16,9 +16,6 @@ aspect ProgramToScopeTree {
   // collect all scopes
   TypeDecl 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
   Declarator contributes asDeclaration() to ASTNode.scope() for containingScope();
@@ -29,34 +26,18 @@ aspect ProgramToScopeTree {
     throw new RuntimeException("unable to create a scope for type " + getClass().getSimpleName());
   }
 
-  // TypeDecl is a scope
   syn lazy TypeDeclScope TypeDecl.asScope() {
     TypeDeclScope scope = new TypeDeclScope();
     scope.setTypeDecl(this);
     return scope;
   }
 
-  // Block can be a scope
   syn lazy BlockScope Block.asScope() {
     BlockScope scope = new BlockScope();
     scope.setBlock(this);
     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() {
     JavaDeclaration decl = new JavaDeclaration(getID());
     decl.setDeclarator(this);
@@ -69,25 +50,15 @@ aspect ProgramToScopeTree {
     return decl;
   }
 
-
 }
 
 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 */
   inh lazy ASTNode ASTNode.containingScope();
   eq Program.getChild().containingScope() = this;
   eq TypeDecl.getChild().containingScope() = this;
-  eq Block.getChild().containingScope() = this; //isScope() ? this : containingScope();
-//  eq MethodDecl.getChild().containingScope() = this;
-//  eq ConstructorDecl.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();
diff --git a/scope4j/src/main/java/org/extendj/ScopeAnalysis.java b/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
index 408effb..53b570a 100644
--- a/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
+++ b/scope4j/src/main/java/org/extendj/ScopeAnalysis.java
@@ -49,6 +49,14 @@ public class ScopeAnalysis extends Frontend {
 
       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();
 
       Set<VariableShadowFinding> findings = scopeTree.variableShadowings();
-- 
GitLab