Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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});
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -481,30 +485,31 @@ public int compare(
for (BasicBlockInContext<IExplodedBasicBlock> 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));
});
}
}

for (BasicBlockInContext<IExplodedBasicBlock> 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);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -147,7 +151,7 @@ public LabeledGraph<TurtlePath, EdgeType> performAnalysis(PropagationCallGraphBu

objs.forEach(
(tp) -> {
System.out.println(" " + tp.position() + " " + tp.value());
LOGGER.info("Tensor position and value: " + tp.position() + " " + tp.value());
});

ISupergraph<BasicBlockInContext<IExplodedBasicBlock>, CGNode> supergraph =
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -568,7 +573,7 @@ Iterable<FactPair> 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())
Expand All @@ -587,7 +592,7 @@ Iterable<FactPair> trace(
fp.fst.getLastInstructionIndex()));
}
});
System.err.println(trace);
LOGGER.info("Trace positions: " + trace);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected void leaveVar(CAstNode n, WalkContext c, CAstVisitor<WalkContext> 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)) {
Expand Down Expand Up @@ -1202,7 +1202,7 @@ protected boolean doVisit(CAstNode n, WalkContext context, CAstVisitor<WalkConte
int numOfChildren = n.getChildCount();
for (int i = 0; i < numOfChildren; i++) {
String val = (String) n.getChild(i).getChild(0).getValue();
System.out.println("Hey " + val);
LOGGER.fine("Processing global declaration: " + val);
addGlobal(context.currentScope(), val);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ public static void main(String... args) throws IOException, ClassHierarchyExcept
code.add((SourceModule) f);
});
IClassHierarchy cha = CPythonAstToCAstTranslator.load(code);
System.err.println(cha);
LOGGER.info("Class hierarchy: " + cha);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.python.core.PyObject;

public class Python2Loader extends PythonLoader {

private static final Logger LOGGER = Logger.getLogger(Python2Loader.class.getName());

public Python2Loader(IClassHierarchy cha, IClassLoader parent) {
super(cha, parent, Collections.emptyList());
}
Expand Down Expand Up @@ -97,7 +101,15 @@ protected Object eval(CAstOperator op, Object lhs, Object rhs) {
PyObject x =
Python2Interpreter.getInterp().eval(lhs + " " + op.getValue() + " " + rhs);
if (x.isNumberType()) {
System.err.println(lhs + " " + op.getValue() + " " + rhs + " -> " + x.asInt());
LOGGER.fine(
"Expression evaluation: "
+ lhs
+ " "
+ op.getValue()
+ " "
+ rhs
+ " -> "
+ x.asInt());
return x.asInt();
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,6 +126,8 @@

public abstract class PythonParser<T> extends AbstractParser implements TranslatorToCAst {

private static final Logger LOGGER = Logger.getLogger(PythonParser.class.getName());

private static boolean COMPREHENSION_IR = true;

private CAstType codeBody =
Expand Down Expand Up @@ -508,8 +511,9 @@ public CAstNode visitClassDef(ClassDef arg0) throws Exception {
public Collection<CAstType> getSupertypes() {
Collection<CAstType> supertypes = HashSetFactory.make();
for (expr e : arg0.getInternalBases()) {
System.out.println(
arg0.getInternalName()
LOGGER.fine(
"Class inheritance: "
+ arg0.getInternalName()
+ " "
+ arg0.getType()
+ " extends "
Expand Down Expand Up @@ -1966,7 +1970,7 @@ public String getMsg() {
}

public void print(PyObject ast) {
System.err.println(ast.getClass());
LOGGER.fine("AST class: " + ast.getClass());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends PythonAnalysisEngine<T> {

private static final Logger LOGGER = Logger.getLogger(PytestAnalysisEngine.class.getName());

private class PytestTargetSelector implements MethodTargetSelector {
private final MethodTargetSelector base;

Expand All @@ -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));
Expand All @@ -56,19 +59,19 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec
PointerKey names = pkf.getPointerKeyForInstanceField(p, ns);
OrdinalSet<InstanceKey> namesObjs =
builder.getPointerAnalysis().getPointsToSet(names);
System.err.println("names: " + namesObjs);
LOGGER.fine("Parameter names: " + namesObjs);

IField vs =
p.getConcreteType()
.getField(Atom.findOrCreateUnicodeAtom("values"));
PointerKey values = pkf.getPointerKeyForInstanceField(p, vs);
OrdinalSet<InstanceKey> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2496,7 +2496,7 @@ public String getMsg() {
}

public void print(PyObject ast) {
System.err.println(ast.getClass());
LOGGER.fine("AST class: " + ast.getClass());
}

/**
Expand Down
Loading