From 8e4730fb0765f55f660879bdee58c6555160e696 Mon Sep 17 00:00:00 2001 From: jacosro Date: Thu, 11 Jun 2020 00:53:12 +0200 Subject: [PATCH] OUT nodes not generated for primitive types or literals --- src/main/java/tfm/arcs/Arc.java | 12 ------- src/main/java/tfm/graphs/cfg/CFGBuilder.java | 8 ++++- .../graphs/sdg/MethodCallReplacerVisitor.java | 36 ++----------------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/src/main/java/tfm/arcs/Arc.java b/src/main/java/tfm/arcs/Arc.java index 950ae8f..ef0ffd5 100644 --- a/src/main/java/tfm/arcs/Arc.java +++ b/src/main/java/tfm/arcs/Arc.java @@ -7,7 +7,6 @@ import tfm.arcs.pdg.ControlDependencyArc; import tfm.arcs.pdg.DataDependencyArc; import tfm.arcs.sdg.CallArc; import tfm.arcs.sdg.ParameterInOutArc; -import tfm.arcs.sdg.ReturnArc; import tfm.arcs.sdg.SummaryArc; import tfm.nodes.GraphNode; @@ -87,17 +86,6 @@ public abstract class Arc extends DefaultEdge { throw new UnsupportedOperationException("Not a ParameterInOutArc"); } - /** @see ReturnArc */ - public final boolean isReturnArc() { - return this instanceof ReturnArc; - } - - public final ReturnArc asReturnArc() { - if (isReturnArc()) - return (ReturnArc) this; - throw new UnsupportedOperationException("Not a ReturnArc"); - } - /** @see SummaryArc */ public final boolean isSummaryArc() { return this instanceof SummaryArc; diff --git a/src/main/java/tfm/graphs/cfg/CFGBuilder.java b/src/main/java/tfm/graphs/cfg/CFGBuilder.java index 0038c50..6fbfa9f 100644 --- a/src/main/java/tfm/graphs/cfg/CFGBuilder.java +++ b/src/main/java/tfm/graphs/cfg/CFGBuilder.java @@ -309,8 +309,14 @@ public class CFGBuilder extends VoidVisitorAdapter { returnList.stream().filter(node -> !hangingNodes.contains(node)).forEach(hangingNodes::add); // Create and connect formal-out nodes sequentially - for (Parameter param : methodDeclaration.getParameters()) + for (Parameter param : methodDeclaration.getParameters()) { + // Do not generate out for primitives + if (param.getType().isPrimitiveType()) { + continue; + } + connectTo(addFormalOutGraphNode(param)); + } // Create and connect the exit node connectTo(graph.addNode("Exit", new EmptyStmt(), TypeNodeFactory.fromType(NodeType.METHOD_EXIT))); } diff --git a/src/main/java/tfm/graphs/sdg/MethodCallReplacerVisitor.java b/src/main/java/tfm/graphs/sdg/MethodCallReplacerVisitor.java index ab9d7cb..e6f334a 100644 --- a/src/main/java/tfm/graphs/sdg/MethodCallReplacerVisitor.java +++ b/src/main/java/tfm/graphs/sdg/MethodCallReplacerVisitor.java @@ -110,10 +110,6 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter { GraphNode methodDeclarationNode = optionalNethodDeclarationNode.get(); MethodDeclaration methodDeclaration = methodDeclarationNode.getAstNode(); - Optional optionalCFG = sdg.getMethodCFG(methodDeclaration); - assert optionalCFG.isPresent(); - CFG methodCFG = optionalCFG.get(); - GraphNode methodCallNode = sdg.addNode("CALL " + methodCallExpr.toString(), methodCallExpr, TypeNodeFactory.fromType(NodeType.METHOD_CALL)); sdg.addControlDependencyArc(originalMethodCallNode, methodCallNode); @@ -182,32 +178,8 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter { // Out expression - OutNodeVariableVisitor shouldHaveOutNodeVisitor = new OutNodeVariableVisitor(); - Set variablesForOutNode = new HashSet<>(); - argument.accept(shouldHaveOutNodeVisitor, variablesForOutNode); - - // Here, variablesForOutNode may have 1 variable or more depending on the expression - - Logger.log("MethodCallReplacerVisitor", String.format("Variables for out node: %s", variablesForOutNode)); - if (variablesForOutNode.isEmpty()) { - /* - If the argument is not a variable or it is not declared in the scope, - then there is no OUT node - */ - Logger.log("MethodCallReplacerVisitor", String.format("Expression '%s' should not have out node", argument.toString())); - continue; - } else if (variablesForOutNode.size() == 1) { - String variable = variablesForOutNode.iterator().next(); - - List> declarations = sdg.findDeclarationsOfVariable(variable, originalMethodCallNode); - - Logger.log("MethodCallReplacerVisitor", String.format("Declarations of variable: '%s': %s", variable, declarations)); - - if (declarations.isEmpty()) { - Logger.log("MethodCallReplacerVisitor", String.format("Expression '%s' should not have out node", argument.toString())); - continue; - } - } else { + // If argument is primitive or not a variable, do not generate out nodes + if (parameter.getType().isPrimitiveType() || !argument.isNameExpr()) { continue; } @@ -284,10 +256,6 @@ class MethodCallReplacerVisitor extends VoidVisitorAdapter { Logger.log("MethodCallReplacerVisitor", String.format("%s | Method '%s' called", methodCallExpr, methodDeclaration.getNameAsString())); } - private void argumentAsNameExpr(GraphNode methodCallNode) { - - } - @Override public void visit(MethodDeclaration n, Context arg) { arg.setCurrentMethod(n); -- GitLab