2020 */
2121public class AnalysisSummaryArcsBuilder extends SummaryArcsBuilder {
2222
23- private static class SummaryArcPair {
23+ private static class FormalNodesPair {
2424 FormalIONode in ;
25- GraphNode <?> out ; // out node is either FormalIONode or METHOD_OUTPUT
25+ GraphNode <?> out ; // out node is either FormalIONode or METHOD_OUTPUT type
2626
27- SummaryArcPair (FormalIONode in , GraphNode <?> out ) {
27+ FormalNodesPair (FormalIONode in , GraphNode <?> out ) {
2828 this .in = in ; this .out = out ;
2929 }
30+
31+ public String toString () {
32+ return String .format ("FormalNodesPair{in: %d, out: %d}" , in .getId (), out .getId ());
33+ }
34+
35+ public boolean equals (Object o ) {
36+ if (o == this ) return true ;
37+ if (!(o instanceof FormalNodesPair )) return false ;
38+ FormalNodesPair pair = (FormalNodesPair ) o ;
39+ return Objects .equals (in , pair .in ) && Objects .equals (out , pair .out );
40+ }
41+
42+ public int hashCode () {
43+ return Objects .hash (in , out );
44+ }
3045 }
3146
3247 private final SDG sdg ;
3348 private final CallGraph callGraph ;
3449
35- protected Map <CallableDeclaration <?>, Set <SummaryArcPair >> vertexDataMap = new HashMap <>();
50+ protected Map <CallableDeclaration <?>, Set <FormalNodesPair >> vertexDataMap = new HashMap <>();
3651 protected boolean built = false ;
3752
3853 public AnalysisSummaryArcsBuilder (SDG sdg ) {
@@ -52,7 +67,7 @@ public AnalysisSummaryArcsBuilder(SDG sdg, CallGraph callGraph) {
5267 this .callGraph = callGraph ;
5368 }
5469
55- public Set <SummaryArcPair > getResult (MethodDeclaration vertex ) {
70+ public Set <FormalNodesPair > getResult (MethodDeclaration vertex ) {
5671 return vertexDataMap .get (vertex );
5772 }
5873
@@ -65,7 +80,7 @@ public void visit() {
6580 List <CallableDeclaration <?>> newWorkList = new LinkedList <>();
6681 for (CallableDeclaration <?> vertex : workList ) {
6782 updateVertex (vertex );
68- Set <SummaryArcPair > newValue = computeSummaryArcs (vertex ); // now with new arcs!!!
83+ Set <FormalNodesPair > newValue = computeSummaryArcs (vertex ); // now with new arcs!!!
6984 if (!Objects .equals (vertexDataMap .get (vertex ), newValue )) {
7085 vertexDataMap .put (vertex , newValue );
7186 newWorkList .addAll (callGraph .incomingEdgesOf (vertex ).stream ()
@@ -100,7 +115,7 @@ protected void updateVertex(CallableDeclaration<?> declaration) {
100115 for (CallArc callArc : methodCallExprNodes ) {
101116 GraphNode <?> methodCallNode = sdg .getEdgeSource (callArc );
102117
103- for (SummaryArcPair summaryArcPair : vertexDataMap .getOrDefault (declaration , Utils .emptySet ())) {
118+ for (FormalNodesPair summaryArcPair : vertexDataMap .getOrDefault (declaration , Utils .emptySet ())) {
104119 FormalIONode inFormalNode = summaryArcPair .in ;
105120 GraphNode <?> outFormalNode = summaryArcPair .out ;
106121
@@ -118,12 +133,9 @@ protected void updateVertex(CallableDeclaration<?> declaration) {
118133 return outFormalNode instanceof FormalIONode
119134 && ((ActualIONode ) actualNode ).matchesFormalIO ((FormalIONode ) outFormalNode );
120135 }
121- // otherwise, actualNode must be METHOD_CALL_RETURN
122- if (actualNode .getNodeType () != NodeType .METHOD_CALL_RETURN ) {
123- return false ;
124- }
125-
126- return outFormalNode .getNodeType () == NodeType .METHOD_OUTPUT ;
136+ // otherwise, actualNode must be METHOD_CALL_RETURN and outFormalNode METHOD_OUTPUT
137+ return actualNode .getNodeType ().is (NodeType .METHOD_CALL_RETURN )
138+ && outFormalNode .getNodeType ().is (NodeType .METHOD_OUTPUT );
127139 })
128140 .findFirst ();
129141
@@ -136,7 +148,7 @@ protected void updateVertex(CallableDeclaration<?> declaration) {
136148 }
137149 }
138150
139- protected Set <SummaryArcPair > computeSummaryArcs (CallableDeclaration <?> declaration ) {
151+ protected Set <FormalNodesPair > computeSummaryArcs (CallableDeclaration <?> declaration ) {
140152 Optional <GraphNode <MethodDeclaration >> optionalMethodDeclarationNode = sdg .findNodeByASTNode (declaration .asMethodDeclaration ());
141153
142154 if (optionalMethodDeclarationNode .isEmpty ()) {
@@ -152,11 +164,11 @@ protected Set<SummaryArcPair> computeSummaryArcs(CallableDeclaration<?> declarat
152164 .filter (node -> node .getNodeType ().is (NodeType .FORMAL_OUT ))
153165 .collect (Collectors .toSet ());
154166
155- Set <SummaryArcPair > res = new HashSet <>();
167+ Set <FormalNodesPair > res = new HashSet <>();
156168
157169 for (GraphNode <?> formalOutNode : formalOutNodes ) {
158170 for (FormalIONode formalInNode : findReachableFormalInNodes (formalOutNode )) {
159- res .add (new SummaryArcPair (formalInNode , formalOutNode ));
171+ res .add (new FormalNodesPair (formalInNode , formalOutNode ));
160172 }
161173 }
162174
0 commit comments