public void printAssign(String v, Type t) { String oldName = varName; varName = v; t.apply(this); varName = oldName; }
/** Transform boolean, byte, short and char into int. **/ Type toInt(Type type) { type.apply(this); return result; }
/** Create a new TypeNode instance for the type parameter. **/ TypeNode typeNode(int id, Type type, ClassHierarchy hierarchy) { if (type == null || hierarchy == null) { throw new InternalTypingException(); } this.id = id; this.hierarchy = hierarchy; type.apply(this); return result; }
public void caseArrayType(ArrayType t) { sb.append('['); t.getElementType().apply(this); }
final private void addAllocNode(final AllocNode alloc) { alloc.getType().apply(new TypeSwitch() { final public void caseRefType(RefType t) { SootClass cl = t.getSootClass(); List<AllocNode> list; if ((list = class2allocs.get(cl)) == null) { list = new LinkedList<AllocNode>(); class2allocs.put(cl, list); } list.add(alloc); } final public void caseAnySubType(AnySubType t) { anySubtypeAllocs.add(alloc); } }); }
public void caseThisRef(ThisRef v) { String oldName = varName; Type paramType = v.getType(); suggestVariableName("type"); String typeName = this.varName; ttp.setVariableName(typeName); paramType.apply(ttp); p.println("Value " + oldName + " = Jimple.v().newThisRef(" + typeName + ");"); varName = oldName; }
public void caseNewExpr(NewExpr v) { String oldName = varName; suggestVariableName("type"); String typeName = varName; ttp.setVariableName(varName); v.getType().apply(ttp); p.println("Value " + oldName + " = Jimple.v().newNewExpr(" + typeName + ");"); varName = oldName; }
/** * Finds or creates the GlobalVarNode for the variable value, of type type. */ public GlobalVarNode makeGlobalVarNode(Object value, Type type) { if (opts.rta()) { value = null; type = RefType.v("java.lang.Object"); } GlobalVarNode ret = valToGlobalVarNode.get(value); if (ret == null) { valToGlobalVarNode.put(value, ret = new GlobalVarNode(this, value, type)); // if library mode is activated, add allocation of every possible // type to accessible fields if (cgOpts.library() != CGOptions.library_disabled) { if (value instanceof SootField) { SootField sf = (SootField) value; if (accessibilityOracle.isAccessible(sf)) { type.apply(new SparkLibraryHelper(this, ret, null)); } } } addNodeTag(ret, null); } else if (!(ret.getType().equals(type))) { throw new RuntimeException("Value " + value + " of type " + type + " previously had type " + ret.getType()); } return ret; }
public void caseCastExpr(CastExpr v) { String oldName = varName; suggestVariableName("type"); String lhsName = varName; ttp.setVariableName(varName); v.getType().apply(ttp); String rhsName = printValueAssignment(v.getOp(), "op"); p.println("Value " + oldName + " = Jimple.v().newCastExpr(" + lhsName + "," + rhsName + ");"); varName = oldName; }
public void caseInstanceOfExpr(InstanceOfExpr v) { String oldName = varName; suggestVariableName("type"); String lhsName = varName; ttp.setVariableName(varName); v.getType().apply(ttp); String rhsName = printValueAssignment(v.getOp(), "op"); p.println("Value " + oldName + " = Jimple.v().newInstanceOfExpr(" + lhsName + "," + rhsName + ");"); varName = oldName; }
public void caseNewArrayExpr(NewArrayExpr v) { String oldName = varName; Value size = v.getSize(); suggestVariableName("size"); String sizeName = varName; size.apply(this); suggestVariableName("type"); String lhsName = varName; ttp.setVariableName(varName); v.getType().apply(ttp); p.println("Value " + oldName + " = Jimple.v().newNewArrayExpr(" + lhsName + ", " + sizeName + ");"); varName = oldName; }
public void caseParameterRef(ParameterRef v) { String oldName = varName; Type paramType = v.getType(); suggestVariableName("paramType"); String paramTypeName = this.varName; ttp.setVariableName(paramTypeName); paramType.apply(ttp); int number = v.getIndex(); suggestVariableName("number"); p.println("int " + varName + "=" + number + ";"); p.println("Value " + oldName + " = Jimple.v().newParameterRef(" + paramTypeName + ", " + varName + ");"); varName = oldName; }
/** * Finds or creates the FieldRefNode for base variable baseValue and field field, of type type. */ public FieldRefNode makeLocalFieldRefNode(Object baseValue, Type baseType, SparkField field, SootMethod method) { VarNode base = makeLocalVarNode(baseValue, baseType, method); FieldRefNode ret = makeFieldRefNode(base, field); // if library mode is activated, add allocation of every possible type // to accessible fields if (cgOpts.library() != CGOptions.library_disabled) { if (field instanceof SootField) { SootField sf = (SootField) field; Type type = sf.getType(); if (accessibilityOracle.isAccessible(sf)) { type.apply(new SparkLibraryHelper(this, ret, method)); } } } return ret; }
public void caseAndExpr(AndExpr v) { emitValue(v.getOp1()); emitValue(v.getOp2()); v.getType().apply(new TypeSwitch() { private void handleIntCase() { emit("iand", -1); } public void caseIntType(IntType t) { handleIntCase(); } public void caseBooleanType(BooleanType t) { handleIntCase(); } public void caseShortType(ShortType t) { handleIntCase(); } public void caseCharType(CharType t) { handleIntCase(); } public void caseByteType(ByteType t) { handleIntCase(); } public void caseLongType(LongType t) { emit("land", -2); } public void defaultCase(Type t) { throw new RuntimeException("Invalid argument type for and"); } }); }
public void caseUshrExpr(UshrExpr v) { emitValue(v.getOp1()); emitValue(v.getOp2()); v.getType().apply(new TypeSwitch() { private void handleIntCase() { emit("iushr", -1); } public void caseIntType(IntType t) { handleIntCase(); } public void caseBooleanType(BooleanType t) { handleIntCase(); } public void caseShortType(ShortType t) { handleIntCase(); } public void caseCharType(CharType t) { handleIntCase(); } public void caseByteType(ByteType t) { handleIntCase(); } public void caseLongType(LongType t) { emit("lushr", -1); } public void defaultCase(Type t) { throw new RuntimeException("Invalid argument type for ushr"); } }); }
private void printFieldRef(FieldRef v) { String refTypeName = v.getClass().getSimpleName(); p.openBlock(); String oldName = varName; SootField f = v.getField(); ttp.setVariableName("type"); f.getType().apply(ttp); p.print("SootFieldRef fieldRef = "); p.printNoIndent("Scene.v().makeFieldRef("); String className = f.getDeclaringClass().getName(); p.printNoIndent("Scene.v().getSootClass(\"" + className + "\"),"); p.printNoIndent("\"" + f.getName() + "\","); p.printNoIndent("type,"); p.printNoIndent(f.isStatic() + ");"); p.println("Value " + oldName + " = Jimple.v().new" + refTypeName + "(fieldRef);"); varName = oldName; p.closeBlock(); }
public void caseNewMultiArrayExpr(NewMultiArrayExpr v) { p.openBlock(); String oldName = varName; ttp.setVariableName("arrayType"); v.getType().apply(ttp); p.println("List<IntConstant> sizes = new LinkedList<IntConstant>();"); int i = 0; for (Value s : v.getSizes()) { this.suggestVariableName("size" + i); s.apply(this); i++; p.println("sizes.add(sizes" + i + ");"); } p.println("Value " + oldName + " = Jimple.v().newNewMultiArrayExpr(arrayType, sizes);"); varName = oldName; p.closeBlock(); }
protected void buildNative() { ValNode thisNode = null; ValNode retNode = null; if (!method.isStatic()) { thisNode = (ValNode) nodeFactory.caseThis(); } if (method.getReturnType() instanceof RefLikeType) { retNode = (ValNode) nodeFactory.caseRet(); // on library analysis we assume that the return type of an native method can // be anything matching to the declared type. if (pag.getCGOpts().library() != CGOptions.library_disabled) { Type retType = method.getReturnType(); retType.apply(new SparkLibraryHelper(pag, retNode, method)); } } ValNode[] args = new ValNode[method.getParameterCount()]; for (int i = 0; i < method.getParameterCount(); i++) { if (!(method.getParameterType(i) instanceof RefLikeType)) { continue; } args[i] = (ValNode) nodeFactory.caseParm(i); } pag.nativeMethodDriver.process(method, thisNode, retNode, args); }
@Override final public void caseIdentityStmt(IdentityStmt is) { if (!(is.getLeftOp().getType() instanceof RefLikeType)) { return; } Value leftOp = is.getLeftOp(); Value rightOp = is.getRightOp(); leftOp.apply(MethodNodeFactory.this); Node dest = getNode(); rightOp.apply(MethodNodeFactory.this); Node src = getNode(); mpag.addInternalEdge(src, dest); // in case library mode is activated add allocations to any // possible type of this local and // parameters of accessible methods int libOption = pag.getCGOpts().library(); if (libOption != CGOptions.library_disabled && (accessibilityOracle.isAccessible(method))) { if (rightOp instanceof IdentityRef) { Type rt = rightOp.getType(); rt.apply(new SparkLibraryHelper(pag, src, method)); } } }