From be0656bd8803a35959565fa11ab7be61dade9987 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Sat, 4 Jan 2020 13:25:08 +0100
Subject: [PATCH] Fixed inherited scopes.

- also added hashCodes to printed ASTs
---
 scope/src/main/jastadd/Shadowing.jrag            | 4 ++--
 scope4j/build.gradle                             | 5 +----
 scope4j/src/main/jastadd/ASTPrinting.jadd        | 5 +++--
 scope4j/src/main/jastadd/ProgramToScopeTree.jrag | 9 +++++++--
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/scope/src/main/jastadd/Shadowing.jrag b/scope/src/main/jastadd/Shadowing.jrag
index 8bd777b..5c37ee8 100644
--- a/scope/src/main/jastadd/Shadowing.jrag
+++ b/scope/src/main/jastadd/Shadowing.jrag
@@ -4,7 +4,7 @@ aspect Shadowing {
   Declaration contributes new VariableShadowFinding(shadowed(), this) when isShadowing() to ScopeTree.variableShadowings();
   Declaration contributes new MultipleDeclarationFinding(this) when isShadowingInSameScope() to ScopeTree.variableShadowings();
 
-  syn Declaration Declaration.shadowed()= shadowed(asDeclaration());
+  syn Declaration Declaration.shadowed() = shadowed(asDeclaration());
 
   inh Declaration Element.shadowed(Declaration shadower);
   eq Scope.getElement().shadowed(Declaration shadower) = shadowedLocally(shadower);
@@ -16,7 +16,7 @@ aspect Shadowing {
         return declaration;
       }
     }
-    // the look in the inherited scopes
+    // then look in the inherited scopes
     for (Scope inherited : getInheritedScopeList()) {
       Declaration shadowed = inherited.shadowedLocally(shadower);
       if (shadowed != null) {
diff --git a/scope4j/build.gradle b/scope4j/build.gradle
index cf6e3a0..27898cf 100644
--- a/scope4j/build.gradle
+++ b/scope4j/build.gradle
@@ -133,10 +133,7 @@ jastadd {
 }
 
 run {
-    mainClassName = 'org.extendj.SccChecker'
-    if (project.hasProperty("appArgs")) {
-        args Eval.me(appArgs)
-    }
+    mainClassName = 'org.extendj.ScopeAnalysis'
 }
 
 task preprocess(type: JavaExec) {
diff --git a/scope4j/src/main/jastadd/ASTPrinting.jadd b/scope4j/src/main/jastadd/ASTPrinting.jadd
index 0864144..b12a7fd 100644
--- a/scope4j/src/main/jastadd/ASTPrinting.jadd
+++ b/scope4j/src/main/jastadd/ASTPrinting.jadd
@@ -2,7 +2,7 @@ aspect Debugging {
 
   public String ASTNode.getASTString() {
 
-    String result = this.getClass().getSimpleName() + "\n";
+    String result = this.getClass().getSimpleName() + " (@" + this.hashCode() + ")\n";
 
     for (java.lang.reflect.Method method : this.getClass().getMethods()) {
       ASTNodeAnnotation.Token annotation = method.getAnnotation(ASTNodeAnnotation.Token.class);
@@ -14,7 +14,8 @@ aspect Debugging {
           } else {
             name += ":= ";
           }
-          result += "|--" + name + method.invoke(this);
+          Object methodResult = method.invoke(this);
+          result += "|--" + name + methodResult + (methodResult == null ? "" : " (@" + methodResult.hashCode() + ")");
         } catch (IllegalAccessException e) {
           e.printStackTrace();
         } catch (java.lang.reflect.InvocationTargetException e) {
diff --git a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
index 05b0ea1..1cb2b14 100644
--- a/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
+++ b/scope4j/src/main/jastadd/ProgramToScopeTree.jrag
@@ -27,8 +27,13 @@ aspect ProgramToScopeTree {
   public void ProtectedClassDeclScope.updateInheritance() {
     if (getTypeDecl().isClassDecl()) {
       ClassDecl classDecl = (ClassDecl)getTypeDecl();
-      if(classDecl.superclass().isClassDecl() && classDecl.superclass().compilationUnit().fromSource()) {
-        addInheritedScope(((ClassDecl)classDecl.superclass()).asPackageScope());
+      if (classDecl.superclass().isClassDecl() && classDecl.superclass().compilationUnit().fromSource()) {
+        ClassDecl superDecl = (ClassDecl)classDecl.superclass();
+        if (classDecl.hostPackage().equals(superDecl.hostPackage())) {
+          addInheritedScope(superDecl.asPackageScope());
+        } else {
+          addInheritedScope(superDecl.asProtectedScope());
+        }
       }
     }
     super.updateInheritance();
-- 
GitLab