From 54f1cab237522cdfd2d9746d4e943f15dca4a0d9 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Sun, 12 Jan 2025 17:41:41 +0800 Subject: [PATCH] no more views passing around --- .../callgraph/AbstractCallGraphAlgorithm.java | 28 ++++++------------- .../ClassHierarchyAnalysisAlgorithm.java | 6 ++-- .../callgraph/RapidTypeAnalysisAlgorithm.java | 8 ++---- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java index 99f6efe019a..02fe418bf1c 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java @@ -67,13 +67,12 @@ protected AbstractCallGraphAlgorithm(@Nonnull View view) { * This method starts the construction of the call graph algorithm. It initializes the needed * objects for the call graph generation and calls processWorkList method. * - * @param view the view contains all needed class files. * @param entryPoints a list of method signatures that will be added to the work list in the call * graph generation. * @return the complete constructed call graph starting from the entry methods. */ @Nonnull - final CallGraph constructCompleteCallGraph(View view, List entryPoints) { + final CallGraph constructCompleteCallGraph(List entryPoints) { Deque workList = new ArrayDeque<>(entryPoints); Set processed = new HashSet<>(); @@ -83,7 +82,7 @@ final CallGraph constructCompleteCallGraph(View view, List entr workList.addAll(clinits); MutableCallGraph cg = initializeCallGraph(entryPoints, clinits); - processWorkList(view, workList, processed, cg); + processWorkList(workList, processed, cg); return cg; } @@ -124,21 +123,17 @@ private Optional getSignatureOfImplementedStaticInitializer( /** * Processes all entries in the workList, skipping those present in processed - * , adding call edges to the graph. Newly discovered methods are added to the - * workList and processed as well. cg is updated accordingly. The method + * , adding call edges to the graph. Newly discovered methods are added to the + * workList and processed as well. cg is updated accordingly. The method * postProcessingMethod is called after a method is processed in the workList. * - * @param view it contains the classes. * @param workList it contains all method that have to be processed in the call graph generation. * This list is filled in the execution with found call targets in the call graph algorithm. * @param processed the list of processed method to only process the method once. * @param cg the call graph object that is filled with the found methods and call edges. */ final void processWorkList( - View view, - Deque workList, - Set processed, - MutableCallGraph cg) { + Deque workList, Set processed, MutableCallGraph cg) { while (!workList.isEmpty()) { MethodSignature currentMethodSignature = workList.pop(); // skip if already processed @@ -154,7 +149,7 @@ final void processWorkList( } // perform pre-processing if needed - preProcessingMethod(view, currentMethodSignature, workList, cg); + preProcessingMethod(currentMethodSignature, workList, cg); // process the method if (!cg.containsMethod(currentMethodSignature)) { @@ -175,7 +170,7 @@ final void processWorkList( processed.add(currentMethodSignature); // perform post-processing if needed - postProcessingMethod(view, currentMethodSignature, workList, cg); + postProcessingMethod(currentMethodSignature, workList, cg); } } @@ -351,13 +346,11 @@ private void addStaticInitializerCalls( /** * This method enables optional pre-processing of a method in the call graph algorithm * - * @param view view * @param sourceMethod the processed method * @param workList the current work list that might be extended * @param cg the current cg that might be extended */ protected abstract void preProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg); @@ -365,13 +358,11 @@ protected abstract void preProcessingMethod( /** * This method enables optional post-processing of a method in the call graph algorithm * - * @param view it contains classes and the type hierarchy. * @param sourceMethod the processed method * @param workList the current work list that might be extended * @param cg the current cg that might be extended */ protected abstract void postProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg); @@ -397,7 +388,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl // Step 1: Add edges from the new methods to other methods Deque workList = new ArrayDeque<>(newMethodSignatures); Set processed = new HashSet<>(oldCallGraph.getMethodSignatures()); - processWorkList(view, workList, processed, updated); + processWorkList(workList, processed, updated); // Step 2: Add edges from old methods to methods overridden in the new class Stream superClasses = view.getTypeHierarchy().superClassesOf(classType); @@ -445,10 +436,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl *

The method throws an exception if there is no main method in any of the classes or if there * are more than one main method. * - * @param view to get the view specific main method. * @return - MethodSignature of main method. */ - public MethodSignature findMainMethod(View view) { + public MethodSignature findMainMethod() { Collection mainMethods = view.getClasses() .filter(aClass -> !aClass.isLibraryClass()) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java index 262291e6c48..1aa07b97245 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/ClassHierarchyAnalysisAlgorithm.java @@ -57,13 +57,13 @@ public ClassHierarchyAnalysisAlgorithm(@Nonnull View view) { @Nonnull @Override public CallGraph initialize() { - return constructCompleteCallGraph(view, Collections.singletonList(findMainMethod(view))); + return constructCompleteCallGraph(Collections.singletonList(findMainMethod())); } @Nonnull @Override public CallGraph initialize(@Nonnull List entryPoints) { - return constructCompleteCallGraph(view, entryPoints); + return constructCompleteCallGraph(entryPoints); } /** @@ -162,7 +162,6 @@ private List resolveAllCallTargets( @Override protected void postProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg) { @@ -171,7 +170,6 @@ protected void postProcessingMethod( @Override protected void preProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg) { diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java index 4cc0d604b83..185d68de3f4 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java @@ -63,7 +63,7 @@ public RapidTypeAnalysisAlgorithm(@Nonnull View view) { @Nonnull @Override public CallGraph initialize() { - List entryPoints = Collections.singletonList(findMainMethod(view)); + List entryPoints = Collections.singletonList(findMainMethod()); return initialize(entryPoints); } @@ -74,7 +74,7 @@ public CallGraph initialize(@Nonnull List entryPoints) { instantiatedClasses = new HashSet<>(); ignoredCalls = new HashMap<>(); - CallGraph cg = constructCompleteCallGraph(view, entryPoints); + CallGraph cg = constructCompleteCallGraph(entryPoints); // delete the data structures instantiatedClasses = Collections.emptySet(); @@ -214,14 +214,12 @@ private void saveIgnoredCall( * sourceMethod. If a new instantiated class has previously ignored calls to this class, they are * added to call graph * - * @param view view * @param sourceMethod the processed method * @param workList the current work list * @param cg the current cg */ @Override protected void preProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg) { @@ -272,14 +270,12 @@ protected void includeIgnoredCallsToClass( /** * Postprocessing is not needed in RTA * - * @param view view * @param sourceMethod the processed method * @param workList the current worklist that is extended by methods that have to be analyzed. * @param cg the current cg is extended by new call targets and calls */ @Override protected void postProcessingMethod( - View view, MethodSignature sourceMethod, @Nonnull Deque workList, @Nonnull MutableCallGraph cg) {