From 8bf7beb4a22b2ab75d07f2a0eda2a4efc0aa1ccf Mon Sep 17 00:00:00 2001 From: Julian Schuette Date: Wed, 5 Aug 2020 22:52:30 +0200 Subject: [PATCH 1/4] Fixes #192 --- src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java index 4a5ff14fd0..627f90324d 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java @@ -116,7 +116,7 @@ public class Node extends IVisitable { /** List of annotations associated with that node. */ @SubGraph("AST") - protected List annotations; + public List annotations = new ArrayList<>(); public Long getId() { return id; From d941874f46467ebbd20faa2e5b41a8df914b1b95 Mon Sep 17 00:00:00 2001 From: Julian Schuette Date: Wed, 5 Aug 2020 22:57:33 +0200 Subject: [PATCH 2/4] Add remaining @NonNull annotations --- .../de/fraunhofer/aisec/cpg/graph/Node.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java index 627f90324d..710239aa39 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java @@ -74,6 +74,7 @@ public class Node extends IVisitable { protected String file; /** Incoming control flow edges. */ + @NonNull @Relationship(value = "EOG", direction = "INCOMING") protected List prevEOG = new ArrayList<>(); @@ -87,12 +88,15 @@ public class Node extends IVisitable { @Relationship(value = "CFG", direction = "OUTGOING") protected List nextCFG = new ArrayList<>(); + @NonNull @Relationship(value = "DFG", direction = "INCOMING") protected Set prevDFG = new HashSet<>(); + @NonNull @Relationship(value = "DFG") protected Set nextDFG = new HashSet<>(); + @NonNull protected Set typedefs = new HashSet<>(); /** @@ -156,11 +160,12 @@ public void setLocation(@Nullable PhysicalLocation location) { this.location = location; } + @NonNull public List getPrevEOG() { return this.prevEOG; } - public void setPrevEOG(List prevEOG) { + public void setPrevEOG(@NonNull List prevEOG) { this.prevEOG = prevEOG; } @@ -178,11 +183,12 @@ public List getNextCFG() { return this.nextCFG; } + @NonNull public Set getNextDFG() { return nextDFG; } - public void setNextDFG(Set nextDFG) { + public void setNextDFG(@NonNull Set nextDFG) { this.nextDFG = nextDFG; } @@ -198,11 +204,12 @@ public void removeNextDFG(Node next) { } } + @NonNull public Set getPrevDFG() { return prevDFG; } - public void setPrevDFG(Set prevDFG) { + public void setPrevDFG(@NonNull Set prevDFG) { this.prevDFG = prevDFG; } @@ -222,11 +229,12 @@ public void addTypedef(TypedefDeclaration typedef) { this.typedefs.add(typedef); } + @NonNull public Set getTypedefs() { return typedefs; } - public void setTypedefs(Set typedefs) { + public void setTypedefs(@NonNull Set typedefs) { this.typedefs = typedefs; } @@ -259,6 +267,15 @@ public boolean isImplicit() { return this.implicit; } + @NonNull + public List getAnnotations() { + return annotations; + } + + public void setAnnotations(@NonNull List annotations) { + this.annotations = annotations; + } + /** * If a node should be removed from the graph, just removing it from the AST is not enough (see * issue #60). It will most probably be referenced somewhere via DFG or EOG edges. Thus, if it @@ -326,12 +343,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(name, this.getClass()); } - - public void setAnnotations(List annotations) { - this.annotations = annotations; - } - - public List getAnnotations() { - return annotations; - } } From 42cb33326d88d70e5fabc039061d7ed1e4889425 Mon Sep 17 00:00:00 2001 From: Julian Schuette Date: Thu, 13 Aug 2020 16:31:00 +0200 Subject: [PATCH 3/4] Make member protected --- src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java index 710239aa39..21cf2a0875 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java @@ -120,7 +120,7 @@ public class Node extends IVisitable { /** List of annotations associated with that node. */ @SubGraph("AST") - public List annotations = new ArrayList<>(); + protected List annotations = new ArrayList<>(); public Long getId() { return id; From 14ea7925b60771c2103f3837af39be0266c2adc7 Mon Sep 17 00:00:00 2001 From: Julian Schuette Date: Thu, 13 Aug 2020 16:39:18 +0200 Subject: [PATCH 4/4] Handle annotations equivalent to nextEog/nextDfg --- .../cpg/frontends/cpp/CXXLanguageFrontend.java | 2 +- .../aisec/cpg/graph/ConstructorDeclaration.java | 2 +- .../aisec/cpg/graph/MethodDeclaration.java | 3 ++- .../java/de/fraunhofer/aisec/cpg/graph/Node.java | 13 ++++--------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java index 4f1e2bd0e4..5cfe36af01 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/frontends/cpp/CXXLanguageFrontend.java @@ -372,7 +372,7 @@ public PhysicalLocation getLocationFromRawNode(T astNode) { public void processAttributes(@NonNull Node node, @NonNull IASTAttributeOwner owner) { if (this.config.processAnnotations) { // set attributes - node.setAnnotations(handleAttributes(owner)); + node.addAnnotations(handleAttributes(owner)); } } diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java index 816a2a126e..7a6efb08bd 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/ConstructorDeclaration.java @@ -55,7 +55,7 @@ public static ConstructorDeclaration from(MethodDeclaration methodDeclaration) { c.setBody(methodDeclaration.getBody()); c.setLocation(methodDeclaration.getLocation()); c.setParameters(methodDeclaration.getParameters()); - c.setAnnotations(methodDeclaration.getAnnotations()); + c.addAnnotations(methodDeclaration.getAnnotations()); c.setIsDefinition(methodDeclaration.isDefinition()); if (!c.isDefinition()) { diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java index 20361ebbd1..f1f8456d08 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/MethodDeclaration.java @@ -59,7 +59,7 @@ public static MethodDeclaration from( md.setParameters(functionDeclaration.getParameters()); md.setBody(functionDeclaration.getBody()); md.setType(functionDeclaration.getType()); - md.setAnnotations(functionDeclaration.getAnnotations()); + md.addAnnotations(functionDeclaration.getAnnotations()); md.setRecordDeclaration(recordDeclaration); md.setIsDefinition(functionDeclaration.isDefinition()); @@ -80,6 +80,7 @@ public void setStatic(boolean isStatic) { this.isStatic = isStatic; } + @Nullable public RecordDeclaration getRecordDeclaration() { return recordDeclaration; } diff --git a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java index 21cf2a0875..e468976451 100644 --- a/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java +++ b/src/main/java/de/fraunhofer/aisec/cpg/graph/Node.java @@ -29,11 +29,7 @@ import de.fraunhofer.aisec.cpg.helpers.LocationConverter; import de.fraunhofer.aisec.cpg.processing.IVisitable; import de.fraunhofer.aisec.cpg.sarif.PhysicalLocation; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.checkerframework.checker.nullness.qual.NonNull; @@ -96,8 +92,7 @@ public class Node extends IVisitable { @Relationship(value = "DFG") protected Set nextDFG = new HashSet<>(); - @NonNull - protected Set typedefs = new HashSet<>(); + @NonNull protected Set typedefs = new HashSet<>(); /** * If a node is marked as being a dummy, it means that it was created artificially and does not @@ -272,8 +267,8 @@ public List getAnnotations() { return annotations; } - public void setAnnotations(@NonNull List annotations) { - this.annotations = annotations; + public void addAnnotations(@NonNull Collection annotations) { + this.annotations.addAll(annotations); } /**