diff --git a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestCalls.java b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestCalls.java index b6606d64b..df0f16863 100644 --- a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestCalls.java +++ b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestCalls.java @@ -170,10 +170,10 @@ public Void performAnalysis(PropagationCallGraphBuilder builder) throws CancelEx public void testCalls8() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { CallGraph CG = process("calls8.py"); - System.err.println(CG); + LOGGER.info("Call graph for calls8.py: " + CG); CG.forEach( (n) -> { - System.err.println(n.getIR()); + LOGGER.fine("Node IR: " + n.getIR()); }); // verifyGraphAssertions(CG, assertionsCalls6); } diff --git a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestClasses.java b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestClasses.java index 228c5b560..1e5cf5398 100644 --- a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestClasses.java +++ b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestClasses.java @@ -6,10 +6,13 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.util.CancelException; import java.io.IOException; +import java.util.logging.Logger; import org.junit.Test; public class TestClasses extends TestJythonCallGraphShape { + private static final Logger LOGGER = Logger.getLogger(TestClasses.class.getName()); + protected static final Object[][] assertionsClasses1 = new Object[][] { new Object[] {ROOT, new String[] {"script classes1.py"}}, @@ -114,7 +117,7 @@ public void testClasses3() SSAPropagationCallGraphBuilder builder = (SSAPropagationCallGraphBuilder) engine.defaultCallGraphBuilder(); CallGraph CG = builder.makeCallGraph(builder.getOptions()); - System.err.println(CG); + LOGGER.info("Call graph for classes3.py: " + CG); verifyGraphAssertions(CG, assertionsClasses3); } } diff --git a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestSource.java b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestSource.java index 9a5f62ea5..dce524279 100644 --- a/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestSource.java +++ b/core/com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestSource.java @@ -4,17 +4,20 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.util.CancelException; import java.io.IOException; +import java.util.logging.Logger; import org.junit.Test; public class TestSource extends TestJythonCallGraphShape { + private static final Logger LOGGER = Logger.getLogger(TestSource.class.getName()); + @Test public void testSource1() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { CallGraph CG = process("src1.py"); CG.forEach( (n) -> { - System.err.println(n.getIR()); + LOGGER.fine("Node IR: " + n.getIR()); }); // verifyGraphAssertions(CG, assertionsCalls1); } diff --git a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtlePandasMergeAnalysis.java b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtlePandasMergeAnalysis.java index 0e8951c8d..1a1cb6139 100644 --- a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtlePandasMergeAnalysis.java +++ b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtlePandasMergeAnalysis.java @@ -54,10 +54,14 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.logging.Logger; import org.json.JSONObject; public class PythonTurtlePandasMergeAnalysis extends PythonTurtleAnalysisEngine { + private static final Logger LOGGER = + Logger.getLogger(PythonTurtlePandasMergeAnalysis.class.getName()); + class DataFrameState { private final String fileName; private final String sheetName; @@ -261,7 +265,7 @@ public IntSet getTargets(int d1) { ValueState vs = domain.getMappedObject(d1); if (AccessPath.isRootedAtLocal(ref, vs.fst)) { ValueState nvs = vs.assign(colName == null ? "*" : colName); - System.err.println("found " + nvs); + LOGGER.fine("Found value state: " + nvs); if (!domain.hasMappedIndex(nvs)) { domain.add(nvs); } @@ -278,7 +282,7 @@ public IntSet getTargets(int d1) { if (!domain.hasMappedIndex(nvs)) { domain.add(nvs); } - System.err.println("found " + nvs); + LOGGER.fine("Found value state: " + nvs); return IntSetUtil.make(new int[] {d1, domain.getMappedIndex(nvs)}); } else { return IntSetUtil.make(new int[] {d1}); @@ -316,7 +320,7 @@ public IntSet getTargets(int d1) { flow.snd); if (!domain.hasMappedIndex(adapt)) { int idx = domain.add(adapt); - System.err.println(adapt + " is " + idx); + LOGGER.fine("Added adapted value state: " + adapt + " with index " + idx); } result.add(domain.getMappedIndex(adapt)); } @@ -481,16 +485,17 @@ public int compare( for (BasicBlockInContext bbic : stmts) { if (bbic.getLastInstruction() != null) { if (bbic.getMethod() != currentMethod) { - System.err.println("method " + currentMethod); + LOGGER.info("Processing method: " + currentMethod); currentMethod = bbic.getMethod(); } - System.err.println( - bbic.getLastInstruction().toString(bbic.getNode().getIR().getSymbolTable())); + LOGGER.info( + "Instruction: " + + bbic.getLastInstruction().toString(bbic.getNode().getIR().getSymbolTable())); result .getResult(bbic) .foreach( (i) -> { - System.err.println(domain.getMappedObject(i)); + LOGGER.fine("Domain mapped object: " + domain.getMappedObject(i)); }); } } @@ -498,13 +503,13 @@ public int compare( for (BasicBlockInContext bbic : stmts) { SSAInstruction inst = bbic.getLastInstruction(); if (merges.containsKey(inst)) { - System.err.println(merges.get(inst)); + LOGGER.info("Merge instruction: " + merges.get(inst)); result .getResult(bbic) .foreach( (i) -> { ValueState val = domain.getMappedObject(i); - System.err.println(val); + LOGGER.fine("Value state: " + val); }); } } diff --git a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtleSKLearnClassifierAnalysis.java b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtleSKLearnClassifierAnalysis.java index 29b504be3..fc1390bb5 100644 --- a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtleSKLearnClassifierAnalysis.java +++ b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/client/PythonTurtleSKLearnClassifierAnalysis.java @@ -45,9 +45,13 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.logging.Logger; public class PythonTurtleSKLearnClassifierAnalysis extends PythonTurtleAnalysisEngine { + private static final Logger LOGGER = + Logger.getLogger(PythonTurtleSKLearnClassifierAnalysis.class.getName()); + private enum State { FRESH, FIT @@ -147,7 +151,7 @@ public LabeledGraph performAnalysis(PropagationCallGraphBu objs.forEach( (tp) -> { - System.out.println(" " + tp.position() + " " + tp.value()); + LOGGER.info("Tensor position and value: " + tp.position() + " " + tp.value()); }); ISupergraph, CGNode> supergraph = @@ -217,7 +221,7 @@ public IntSet getTargets(int d1) { ClassifierState adapt = new ClassifierState(dest.getNode(), i + 1, flow.state); if (!domain.hasMappedIndex(adapt)) { int idx = domain.add(adapt); - System.err.println(adapt + " is " + idx); + LOGGER.fine("Added classifier state: " + adapt + " with index " + idx); } result.add(domain.getMappedIndex(adapt)); } @@ -260,7 +264,8 @@ public IntSet getTargets(int d1) { new ClassifierState(dest.getNode(), pyCall.getDef(0), flow.state); if (!domain.hasMappedIndex(adapt)) { int i = domain.add(adapt); - System.err.println(adapt + " is " + i); + LOGGER.fine( + "Added return classifier state: " + adapt + " with index " + i); } result.add(domain.getMappedIndex(adapt)); } @@ -568,7 +573,7 @@ Iterable trace( (n) -> { ClassifierState s = domain.getMappedObject(n); if (s.vn == vn && s.node == bbic.getNode()) { - System.err.println( + LOGGER.info( ((AstMethod) bbic.getMethod()) .debugInfo() .getInstructionPosition(inst.iIndex()) @@ -587,7 +592,7 @@ Iterable trace( fp.fst.getLastInstructionIndex())); } }); - System.err.println(trace); + LOGGER.info("Trace positions: " + trace); } }); } diff --git a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java index caff98332..88a898ef4 100644 --- a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java +++ b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java @@ -667,8 +667,8 @@ private InstanceKey toTrampolineIfNeeded(InstanceKey ik, InstanceKey container) .isSubclassOf( ik.getConcreteType(), getClassHierarchy().lookupClass(PythonTypes.LambdaMethod))) { - System.err.println(ik.getConcreteType().getName().toString()); - System.err.println(container.getConcreteType().getName().toString()); + logger.fine("Instance key concrete type: " + ik.getConcreteType().getName().toString()); + logger.fine("Container concrete type: " + container.getConcreteType().getName().toString()); TypeReference trampolineClassRef = PythonInstanceMethodTrampoline.findOrCreate( ik.getConcreteType().getReference(), getClassHierarchy()); diff --git a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ir/PythonCAstToIRTranslator.java b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ir/PythonCAstToIRTranslator.java index 295346f0a..a7eca1ada 100644 --- a/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ir/PythonCAstToIRTranslator.java +++ b/core/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ir/PythonCAstToIRTranslator.java @@ -665,7 +665,7 @@ protected void leaveVar(CAstNode n, WalkContext c, CAstVisitor visi assert nm != null : "cannot find var for " + CAstPrinter.print(n, context.getSourceMap()); if ("0".equals(nm)) { - System.err.println("got here"); + LOGGER.fine("got here"); } if (isGlobalVar(nm)) { @@ -1202,7 +1202,7 @@ protected boolean doVisit(CAstNode n, WalkContext context, CAstVisitor " + x.asInt()); + LOGGER.fine( + "Expression evaluation: " + + lhs + + " " + + op.getValue() + + " " + + rhs + + " -> " + + x.asInt()); return x.asInt(); } } catch (Exception e) { diff --git a/jython/com.ibm.wala.cast.python.jython/source/com/ibm/wala/cast/python/parser/PythonParser.java b/jython/com.ibm.wala.cast.python.jython/source/com/ibm/wala/cast/python/parser/PythonParser.java index db1ed057f..177b5fecb 100644 --- a/jython/com.ibm.wala.cast.python.jython/source/com/ibm/wala/cast/python/parser/PythonParser.java +++ b/jython/com.ibm.wala.cast.python.jython/source/com/ibm/wala/cast/python/parser/PythonParser.java @@ -55,6 +55,7 @@ import java.util.LinkedList; import java.util.Map; import java.util.function.Supplier; +import java.util.logging.Logger; import org.python.antlr.PythonTree; import org.python.antlr.ast.Assert; import org.python.antlr.ast.Assign; @@ -125,6 +126,8 @@ public abstract class PythonParser extends AbstractParser implements TranslatorToCAst { + private static final Logger LOGGER = Logger.getLogger(PythonParser.class.getName()); + private static boolean COMPREHENSION_IR = true; private CAstType codeBody = @@ -508,8 +511,9 @@ public CAstNode visitClassDef(ClassDef arg0) throws Exception { public Collection getSupertypes() { Collection supertypes = HashSetFactory.make(); for (expr e : arg0.getInternalBases()) { - System.out.println( - arg0.getInternalName() + LOGGER.fine( + "Class inheritance: " + + arg0.getInternalName() + " " + arg0.getType() + " extends " @@ -1966,7 +1970,7 @@ public String getMsg() { } public void print(PyObject ast) { - System.err.println(ast.getClass()); + LOGGER.fine("AST class: " + ast.getClass()); } /** diff --git a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/client/PytestAnalysisEngine.java b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/client/PytestAnalysisEngine.java index 932aa60da..5e1b47f99 100644 --- a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/client/PytestAnalysisEngine.java +++ b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/client/PytestAnalysisEngine.java @@ -22,9 +22,12 @@ import com.ibm.wala.util.intset.OrdinalSet; import java.io.File; import java.util.List; +import java.util.logging.Logger; public class PytestAnalysisEngine extends PythonAnalysisEngine { + private static final Logger LOGGER = Logger.getLogger(PytestAnalysisEngine.class.getName()); + private class PytestTargetSelector implements MethodTargetSelector { private final MethodTargetSelector base; @@ -35,7 +38,7 @@ private PytestTargetSelector(MethodTargetSelector base) { @Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { if (site.getDeclaredTarget().getDeclaringClass().equals(PytestLoader.pytestType)) { - System.err.println("pytest call site " + site + " " + receiver); + LOGGER.fine("Pytest call site: " + site + " " + receiver); PointerKeyFactory pkf = builder.getPointerKeyFactory(); for (SSAAbstractInvokeInstruction inst : caller.getIR().getCalls(site)) { PointerKey test = pkf.getPointerKeyForLocal(caller, inst.getUse(0)); @@ -56,7 +59,7 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec PointerKey names = pkf.getPointerKeyForInstanceField(p, ns); OrdinalSet namesObjs = builder.getPointerAnalysis().getPointsToSet(names); - System.err.println("names: " + namesObjs); + LOGGER.fine("Parameter names: " + namesObjs); IField vs = p.getConcreteType() @@ -64,11 +67,11 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec PointerKey values = pkf.getPointerKeyForInstanceField(p, vs); OrdinalSet valsObjs = builder.getPointerAnalysis().getPointsToSet(values); - System.err.println("values: " + valsObjs); + LOGGER.fine("Parameter values: " + valsObjs); }); } }); - System.err.println(test + " " + testObjs); + LOGGER.fine("Test pointer key and objects: " + test + " " + testObjs); } } return base.getCalleeTarget(caller, site, receiver); diff --git a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/loader/PytestLoader.java b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/loader/PytestLoader.java index f2f6bc8f9..e0cbc9ff6 100644 --- a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/loader/PytestLoader.java +++ b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/loader/PytestLoader.java @@ -27,9 +27,12 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.logging.Logger; public class PytestLoader extends Python3Loader { + private static final Logger LOGGER = Logger.getLogger(PytestLoader.class.getName()); + public static final TypeReference pytestType = TypeReference.findOrCreate(PythonTypes.pythonLoader, "LPytest"); @@ -148,6 +151,6 @@ private void handlePytest(WalkContext context, CAstEntity fn, int function) { @Override protected void finishTranslation() { super.finishTranslation(); - System.err.println("xxsymbol " + testParams); + LOGGER.fine("Test parameters: " + testParams); } } diff --git a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonParser.java b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonParser.java index f6719d048..622196f64 100644 --- a/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonParser.java +++ b/jython/com.ibm.wala.cast.python.jython3/source/com/ibm/wala/cast/python/parser/PythonParser.java @@ -2058,7 +2058,7 @@ public CAstNode visitTryExcept(TryExcept arg0) throws Exception { CAstVisitor child = new CAstVisitor(catches, parser); CAstNode block = child.block(arg0.getInternalBody()); - System.err.println("catches: " + handlers); + LOGGER.fine("Exception handlers: " + handlers); return Ast.makeNode( CAstNode.TRY, @@ -2496,7 +2496,7 @@ public String getMsg() { } public void print(PyObject ast) { - System.err.println(ast.getClass()); + LOGGER.fine("AST class: " + ast.getClass()); } /** diff --git a/ml/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestPythonMLCallGraphShape.java b/ml/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestPythonMLCallGraphShape.java index c7a458f7d..0e7fea8d1 100644 --- a/ml/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestPythonMLCallGraphShape.java +++ b/ml/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestPythonMLCallGraphShape.java @@ -35,9 +35,12 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.logging.Logger; public abstract class TestPythonMLCallGraphShape extends TestJythonCallGraphShape { + private static final Logger LOGGER = Logger.getLogger(TestPythonMLCallGraphShape.class.getName()); + @FunctionalInterface protected interface CheckTensorOps { void check(PropagationCallGraphBuilder cgBuilder, CallGraph CG, TensorTypeAnalysis result); @@ -116,7 +119,7 @@ protected void checkTensorOps(String url, CheckTensorOps check) (PropagationCallGraphBuilder) e.defaultCallGraphBuilder(); CallGraph CG = cgBuilder.makeCallGraph(cgBuilder.getOptions()); TensorTypeAnalysis result = e.performAnalysis(cgBuilder); - System.err.println(result); + LOGGER.info("Tensor analysis result: " + result); check.check(cgBuilder, CG, result); } diff --git a/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/cloud/CloudFunction.java b/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/cloud/CloudFunction.java index 08d2c914f..6c8f49c5f 100644 --- a/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/cloud/CloudFunction.java +++ b/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/cloud/CloudFunction.java @@ -8,10 +8,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.logging.Logger; import org.eclipse.lsp4j.Diagnostic; public class CloudFunction { + private static final Logger LOGGER = Logger.getLogger(CloudFunction.class.getName()); + public static JsonObject main(JsonObject args) { String code = ""; if (args.has("code")) code = args.getAsJsonPrimitive("code").getAsString(); @@ -28,7 +31,7 @@ public static String analyze(String code) { uriTextPairs.put("fakecode.py", code); Map> diagnostics = PythonDriver.getDiagnostics(uriTextPairs); if (diagnostics == null) { - System.err.println("There was an error generating diagnostics"); + LOGGER.severe("There was an error generating diagnostics"); return "Error"; } // return diagnostics.toString(); diff --git a/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorType.java b/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorType.java index 71be5c35f..cc011e87d 100644 --- a/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorType.java +++ b/ml/com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/types/TensorType.java @@ -359,10 +359,10 @@ public static TensorType shapeArg(CGNode node, int literalVn) throws IOException ((AstMethod) node.getMethod()) .debugInfo() .getInstructionPosition(du.getDef(val).iIndex()); - System.err.println(p); + logger.fine("Position: " + p); SourceBuffer b = new SourceBuffer(p); String expr = b.toString(); - System.err.println(expr); + logger.fine("Expression: " + expr); Integer ival = PythonInterpreter.interpretAsInt(expr); if (ival != null) { r.add(new NumericDim(ival));