Search in sources :

Example 1 with soot

use of soot in project soot by Sable.

the class TryStmt method jimplify2.

/**
 * @ast method
 * @aspect Statements
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Statements.jrag:358
 */
public void jimplify2(Body b) {
    ArrayList ranges = exceptionRanges();
    b.addLabel(label_begin());
    ranges.add(label_begin());
    getBlock().jimplify2(b);
    soot.jimple.Stmt label_block_end = null;
    soot.jimple.Stmt label_end = null;
    if (getBlock().canCompleteNormally()) {
        if (hasFinally() && getNumCatchClause() != 0) {
            label_block_end = label_block_end();
            b.addLabel(label_block_end);
        }
        emitFinallyCode(b);
        b.setLine(this);
        if ((!hasFinally() || getFinally().canCompleteNormally()) && (getNumCatchClause() != 0 || hasFinally()))
            b.add(b.newGotoStmt(label_end = label_end(), this));
    }
    if (getNumCatchClause() != 0) {
        if (label_block_end == null)
            label_block_end = ((BasicCatch) getCatchClause(0)).label();
        ranges.add(label_block_end);
        ranges.add(label_block_end);
        for (int i = 0; i < getNumCatchClause(); i++) {
            // beginExceptionRange(b, ranges);
            getCatchClause(i).jimplify2(b);
            if (getCatchClause(i).getBlock().canCompleteNormally()) {
                b.setLine(getCatchClause(i));
                endExceptionRange(b, ranges);
                emitFinallyCode(b);
                if (!hasFinally() || getFinally().canCompleteNormally())
                    b.add(b.newGotoStmt(label_end = label_end(), this));
                beginExceptionRange(b, ranges);
            }
            b.setLine(getCatchClause(i));
        // endExceptionRange(b, ranges);
        }
    }
    if (hasFinally()) /*&& needsFinallyTrap()*/
    {
        b.addLabel(label_exception_handler());
        emitExceptionHandler(b);
        b.setLine(getFinally());
    // if(getFinally().canCompleteNormally())
    // b.add(b.newGotoStmt(label_end(), this));
    }
    if (label_end != null)
        b.addLabel(label_end);
    // createExceptionTable
    for (int i = 0; i < getNumCatchClause(); i++) {
        for (Iterator iter = ranges.iterator(); iter.hasNext(); ) {
            soot.jimple.Stmt stmtBegin = (soot.jimple.Stmt) iter.next();
            soot.jimple.Stmt stmtEnd = (soot.jimple.Stmt) iter.next();
            if (stmtBegin != stmtEnd) {
                soot.jimple.Stmt lbl = ((BasicCatch) getCatchClause(i)).label();
                b.addTrap(((BasicCatch) getCatchClause(i)).getParameter().type(), stmtBegin, stmtEnd, lbl);
                addFallThroughLabelTag(b, lbl, label_end);
            }
            if (stmtEnd == label_block_end)
                break;
        }
    }
    if (hasFinally()) /*&& needsFinallyTrap()*/
    {
        for (Iterator iter = ranges.iterator(); iter.hasNext(); ) {
            soot.jimple.Stmt stmtBegin = (soot.jimple.Stmt) iter.next();
            soot.jimple.Stmt stmtEnd;
            if (iter.hasNext())
                stmtEnd = (soot.jimple.Stmt) iter.next();
            else
                stmtEnd = label_exception_handler();
            if (stmtBegin != stmtEnd) {
                soot.jimple.Stmt lbl = label_exception_handler();
                b.addTrap(typeThrowable(), stmtBegin, stmtEnd, lbl);
                addFallThroughLabelTag(b, lbl, label_end);
            }
        }
    /*
      b.addTrap(
        typeThrowable(),
        label_begin(),
        label_exception_handler(),
        label_exception_handler()
      );
      */
    }
}
Also used : soot(soot) soot.jimple(soot.jimple) ArrayList(java.util.ArrayList)

Example 2 with soot

use of soot in project soot by Sable.

the class MethodAccess method eval.

/**
 * @ast method
 * @aspect GenericsCodegen
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/GenericsCodegen.jrag:141
 */
public soot.Value eval(Body b) {
    MethodDecl decl = decl().erasedMethod();
    if (!decl().isStatic() && isQualified() && prevExpr().isSuperAccess()) {
        Local left = asLocal(b, createLoadQualifier(b));
        ArrayList list = buildArgList(b);
        soot.Value result;
        if (!hostType().instanceOf(prevExpr().type())) {
            MethodDecl m = decl.createSuperAccessor(superAccessorTarget());
            if (methodQualifierType().isInterfaceDecl())
                result = b.newInterfaceInvokeExpr(left, m.sootRef(), list, this);
            else
                result = b.newVirtualInvokeExpr(left, m.sootRef(), list, this);
        } else
            result = b.newSpecialInvokeExpr(left, sootRef(), list, this);
        if (decl.type() != decl().type())
            result = decl.type().emitCastTo(b, result, decl().type(), this);
        return type().isVoid() ? result : asLocal(b, result);
    } else {
        soot.Value result;
        if (!decl().isStatic()) {
            Local left = asLocal(b, createLoadQualifier(b));
            ArrayList list = buildArgList(b);
            if (methodQualifierType().isInterfaceDecl())
                result = b.newInterfaceInvokeExpr(left, sootRef(), list, this);
            else
                result = b.newVirtualInvokeExpr(left, sootRef(), list, this);
        } else {
            if (isQualified() && !qualifier().isTypeAccess())
                b.newTemp(qualifier().eval(b));
            ArrayList list = buildArgList(b);
            result = b.newStaticInvokeExpr(sootRef(), list, this);
        }
        if (decl.type() != decl().type())
            result = decl.type().emitCastTo(b, result, decl().type(), this);
        return type().isVoid() ? result : asLocal(b, result);
    }
}
Also used : soot(soot) ArrayList(java.util.ArrayList)

Example 3 with soot

use of soot in project soot by Sable.

the class Modifiers method addRuntimeInvisibleAnnotationsAttribute.

/**
 * @ast method
 * @aspect AnnotationsCodegen
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:125
 */
public void addRuntimeInvisibleAnnotationsAttribute(Collection c) {
    Collection annotations = runtimeInvisibleAnnotations();
    if (!annotations.isEmpty()) {
        soot.tagkit.VisibilityAnnotationTag tag = new soot.tagkit.VisibilityAnnotationTag(soot.tagkit.AnnotationConstants.RUNTIME_INVISIBLE);
        for (Iterator iter = annotations.iterator(); iter.hasNext(); ) {
            Annotation annotation = (Annotation) iter.next();
            ArrayList elements = new ArrayList(1);
            annotation.appendAsAttributeTo(elements);
            tag.addAnnotation((soot.tagkit.AnnotationTag) elements.get(0));
        }
        c.add(tag);
    }
}
Also used : soot(soot) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 4 with soot

use of soot in project soot by Sable.

the class SwitchStmt method jimplify2.

/**
 * @ast method
 * @aspect Statements
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Statements.jrag:50
 */
public void jimplify2(Body b) {
    soot.jimple.Stmt cond_label = newLabel();
    soot.jimple.Stmt switch_label = newLabel();
    b.setLine(this);
    b.add(b.newGotoStmt(cond_label, this));
    getBlock().jimplify2(b);
    if (canCompleteNormally()) {
        b.setLine(this);
        b.add(b.newGotoStmt(end_label(), this));
    }
    b.addLabel(cond_label);
    soot.Value expr = asImmediate(b, getExpr().eval(b));
    TreeMap map = new TreeMap();
    for (int i = 0; i < getBlock().getNumStmt(); i++) {
        if (getBlock().getStmt(i) instanceof ConstCase) {
            ConstCase ca = (ConstCase) getBlock().getStmt(i);
            map.put(new Integer(ca.getValue().constant().intValue()), ca);
        }
    }
    long low = map.isEmpty() ? 0 : ((Integer) map.firstKey()).intValue();
    long high = map.isEmpty() ? 0 : ((Integer) map.lastKey()).intValue();
    long tableSwitchSize = 8L + (high - low + 1L) * 4L;
    long lookupSwitchSize = 4L + map.size() * 8L;
    b.addLabel(switch_label);
    soot.jimple.Stmt defaultStmt = defaultCase() != null ? defaultCase().label() : end_label();
    if (tableSwitchSize < lookupSwitchSize) {
        ArrayList targets = new ArrayList();
        for (long i = low; i <= high; i++) {
            ConstCase ca = (ConstCase) map.get(new Integer((int) i));
            if (ca != null)
                targets.add(ca.label());
            else
                targets.add(defaultStmt);
        }
        b.setLine(this);
        b.add(b.newTableSwitchStmt(expr, (int) low, (int) high, targets, defaultStmt, this));
    } else {
        ArrayList targets = new ArrayList();
        ArrayList values = new ArrayList();
        for (Iterator iter = map.values().iterator(); iter.hasNext(); ) {
            ConstCase ca = (ConstCase) iter.next();
            targets.add(ca.label());
            values.add(IntType.emitConstant(ca.getValue().constant().intValue()));
        }
        b.setLine(this);
        b.add(b.newLookupSwitchStmt(expr, values, targets, defaultStmt, this));
    }
    b.addLabel(end_label());
}
Also used : soot(soot) soot.jimple(soot.jimple) ArrayList(java.util.ArrayList)

Example 5 with soot

use of soot in project soot by Sable.

the class EnhancedForStmt method jimplify2.

/**
 * @ast method
 * @aspect EnhancedForToBytecode
 * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/EnhancedForCodegen.jrag:24
 */
public void jimplify2(Body b) {
    if (getExpr().type().isArrayDecl()) {
        soot.Local array = asLocal(b, getExpr().eval(b));
        soot.Local index = asLocal(b, soot.jimple.IntConstant.v(0));
        soot.Local parameter = b.newLocal(getVariableDeclaration().name(), getVariableDeclaration().type().getSootType());
        getVariableDeclaration().local = parameter;
        b.setLine(this);
        b.addLabel(cond_label());
        b.add(b.newIfStmt(b.newGeExpr(asImmediate(b, index), asImmediate(b, b.newLengthExpr(asImmediate(b, array), this)), this), end_label(), this));
        b.add(b.newAssignStmt(parameter, asRValue(b, getExpr().type().elementType().emitCastTo(b, asLocal(b, b.newArrayRef(array, index, this)), getVariableDeclaration().type(), this)), this));
        getStmt().jimplify2(b);
        b.addLabel(update_label());
        b.add(b.newAssignStmt(index, b.newAddExpr(index, soot.jimple.IntConstant.v(1), this), this));
        b.add(b.newGotoStmt(cond_label(), this));
        b.addLabel(end_label());
    } else {
        soot.Local iterator = asLocal(b, b.newInterfaceInvokeExpr(asLocal(b, getExpr().eval(b)), iteratorMethod().sootRef(), new ArrayList(), this));
        soot.Local parameter = b.newLocal(getVariableDeclaration().name(), getVariableDeclaration().type().getSootType());
        getVariableDeclaration().local = parameter;
        b.addLabel(cond_label());
        b.add(b.newIfStmt(b.newEqExpr(asImmediate(b, b.newInterfaceInvokeExpr(iterator, hasNextMethod().sootRef(), new ArrayList(), this)), BooleanType.emitConstant(false), this), end_label(), this));
        b.add(b.newAssignStmt(parameter, nextMethod().type().emitCastTo(b, b.newInterfaceInvokeExpr(iterator, nextMethod().sootRef(), new ArrayList(), this), getVariableDeclaration().type(), this), this));
        getStmt().jimplify2(b);
        b.addLabel(update_label());
        b.add(b.newGotoStmt(cond_label(), this));
        b.addLabel(end_label());
    /*
      getExpr().createBCode(gen);
      iteratorMethod().emitInvokeMethod(gen, lookupType("java.lang", "Iterable"));
      gen.emitStoreReference(extraLocalIndex());
      gen.addLabel(cond_label());
      gen.emitLoadReference(extraLocalIndex());
      hasNextMethod().emitInvokeMethod(gen, lookupType("java.util", "Iterator"));
      gen.emitCompare(Bytecode.IFEQ, end_label());
      gen.emitLoadReference(extraLocalIndex());
      nextMethod().emitInvokeMethod(gen, lookupType("java.util", "Iterator"));
      gen.emitCheckCast(getVariableDeclaration().type());
      gen.emitStoreReference(getVariableDeclaration().localNum());
      getStmt().createBCode(gen);
      gen.addLabel(update_label());	
      gen.emitGoto(cond_label());
      gen.addLabel(end_label());
      */
    }
}
Also used : soot(soot) ArrayList(java.util.ArrayList)

Aggregations

soot (soot)19 ArrayList (java.util.ArrayList)17 SourceFileTag (soot.tagkit.SourceFileTag)3 Collection (java.util.Collection)2 soot.jimple (soot.jimple)2