From 9eb2b5d0e543207507fabfb9116f74ecaf1f74f8 Mon Sep 17 00:00:00 2001 From: stschott Date: Tue, 19 Dec 2023 12:09:42 +0100 Subject: [PATCH] allow to specify explicitly which StmtPrinter to use --- .../core/util/printer/JimplePrinter.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java b/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java index 648df78ec11..306285f3d80 100644 --- a/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java +++ b/sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java @@ -115,8 +115,10 @@ private LabeledStmtPrinter determinePrinter() { } public void printTo(SootClass cl, PrintWriter out) { + printTo(cl, out, determinePrinter()); + } - LabeledStmtPrinter printer = determinePrinter(); + public void printTo(SootClass cl, PrintWriter out, LabeledStmtPrinter printer) { printer.enableImports(options.contains(Option.UseImports)); // add jimple line number tags @@ -207,7 +209,7 @@ public void printTo(SootClass cl, PrintWriter out) { } // Print methods - printMethods(cl, printer, out); + printMethods(cl, printer); printer.literal("}"); printer.newline(); @@ -228,7 +230,7 @@ public void printTo(SootClass cl, PrintWriter out) { out.println(printer.toString()); } - private void printMethods(SootClass cl, LabeledStmtPrinter printer, PrintWriter out) { + private void printMethods(SootClass cl, LabeledStmtPrinter printer) { Iterator methodIt = cl.getMethods().iterator(); if (methodIt.hasNext()) { printer.incIndent(); @@ -261,19 +263,25 @@ private void printMethods(SootClass cl, LabeledStmtPrinter printer, PrintWrit } } + public void printTo(Body body, PrintWriter out) { + printTo(body, out, determinePrinter()); + } + /** * Prints out the method corresponding to body Body, (declaration and body), in the textual format * corresponding to the IR used to encode body body. */ - public void printTo(Body body, PrintWriter out) { - LabeledStmtPrinter printer = determinePrinter(); + public void printTo(Body body, PrintWriter out, LabeledStmtPrinter printer) { printer.enableImports(options.contains(Option.UseImports)); printBody(body, printer); out.print(printer); } public void printTo(StmtGraph graph, PrintWriter out) { - LabeledStmtPrinter printer = determinePrinter(); + printTo(graph, out, determinePrinter()); + } + + public void printTo(StmtGraph graph, PrintWriter out, LabeledStmtPrinter printer) { printStmts(graph, printer); out.print(printer); }