Package soot

Examples of soot.SootField


        }
        Map map = new HashMap();
        // Loop through all the fields and update the types.
        for (Iterator fields = theClass.getFields().iterator(); fields
                .hasNext();) {
            SootField field = (SootField) fields.next();

            if (debug) {
                System.out.println("updating types for " + field);
            }

            Type baseType = field.getType();
            RefType refType = PtolemyUtilities.getBaseTokenType(baseType);

            if ((refType != null)
                    && SootUtilities.derivesFrom(refType.getSootClass(),
                            PtolemyUtilities.tokenClass)) {
                Type type = typeAnalysis.getSpecializedSootType(field);

                if (debug) {
                    System.out.println("replacing with " + type);
                }

                field.setType(type);

                // Update the type tag.
                // FIXME: Correct?
                ptolemy.data.type.Type specializedType = typeAnalysis
                        .getSpecializedType(field);

                if ((specializedType != BaseType.UNKNOWN)
                        && (specializedType != BaseType.GENERAL)
                        && specializedType.isInstantiable()) {
                    if (debug) {
                        System.out.println("updating type tag of " + field
                                + " to "
                                + typeAnalysis.getSpecializedType(field));
                    }

                    field.removeTag("_CGType");
                    field.addTag(new TypeTag(typeAnalysis
                            .getSpecializedType(field)));
                }

                map.put(field, typeAnalysis.getSpecializedType(field));
            }
View Full Code Here


        // Rename fields in the given class
        // whose name is the same between
        // the given class and its superclass.
        for (Iterator fields = theClass.getFields().snapshotIterator(); fields
                .hasNext();) {
            SootField field = (SootField) fields.next();

            if (superClass.declaresFieldByName(field.getName())) {
                // SootField superField = superClass.getFieldByName(field.getName());
                String newName = StringUtilities.sanitizeName(superClass
                        .getName())
                        + field.getName();
                System.out.println("Renaming field " + field + " to " + newName
                        + " to avoid collision with superClass field "
                        + superClass.getFieldByName(field.getName()));

                field.setName(newName);

                // We have to do this seemingly useless
                // thing, since the scene caches a pointer
                // to the field based on it's name.
                theClass.removeField(field);
View Full Code Here

                        .get(blockStmtList.size() - 1));

                // Loop through and unroll the loop body once for
                // every element of the field list.
                for (Iterator fields = fieldList.iterator(); fields.hasNext();) {
                    SootField insertField = (SootField) fields.next();

                    for (Iterator blockStmts = blockStmtList.iterator(); blockStmts
                            .hasNext();) {
                        // clone each statement
                        Stmt original = (Stmt) blockStmts.next();
                        Stmt clone = (Stmt) original.clone();

                        // If the statement is a call to the next() method,
                        // then inline it with the next value of the iterator.
                        for (Iterator boxes = clone.getUseBoxes().iterator(); boxes
                                .hasNext();) {
                            ValueBox box = (ValueBox) boxes.next();
                            Value value = box.getValue();

                            if (value instanceof InvokeExpr) {
                                InvokeExpr r = (InvokeExpr) value;

                                if (r.getMethod() == iteratorNextMethod) {
                                    box.setValue(Jimple.v()
                                            .newInstanceFieldRef(thisLocal,
                                                    insertField.makeRef()));
                                }
                            }
                        }

                        units.insertBefore(clone, insertPoint);
View Full Code Here

    private static List _copyFields(SootClass newClass, SootClass oldClass) {
        List list = new LinkedList();
        Iterator fields = oldClass.getFields().iterator();

        while (fields.hasNext()) {
            SootField oldField = (SootField) fields.next();

            if (newClass.declaresFieldByName(oldField.getName())) {
                // FIXME
                throw new RuntimeException("Field " + oldField
                        + " cannot be folded into " + newClass
                        + " because its name is the same as "
                        + newClass.getFieldByName(oldField.getName()));
            }

            SootField newField = new SootField(oldField.getName(), oldField
                    .getType(), oldField.getModifiers());
            newClass.addField(newField);
        }

        return list;
View Full Code Here

                        localUses);
            } else if (value instanceof CastExpr) {
                return getNamedObjValue(method, (Local) ((CastExpr) value)
                        .getOp(), stmt, localDefs, localUses);
            } else if (value instanceof FieldRef) {
                SootField field = ((FieldRef) value).getField();
                ValueTag tag = (ValueTag) field.getTag("_CGValue");

                if (tag == null) {
                    // return null;
                    throw new RuntimeException(
                            "Could not determine the static value of " + local
                                    + " in " + method);
                } else {
                    return (NamedObj) tag.getObject();
                }
            } else if (value instanceof NewExpr) {
                // If we get to an object creation, then try
                // to figure out where the variable is stored into a field.
                Iterator pairs = localUses.getUsesOf(stmt).iterator();

                while (pairs.hasNext()) {
                    UnitValueBoxPair pair = (UnitValueBoxPair) pairs.next();

                    if (pair.getUnit() instanceof DefinitionStmt) {
                        DefinitionStmt useStmt = (DefinitionStmt) pair
                                .getUnit();

                        if (useStmt.getLeftOp() instanceof FieldRef) {
                            SootField field = ((FieldRef) useStmt.getLeftOp())
                                    .getField();
                            ValueTag tag = (ValueTag) field.getTag("_CGValue");

                            if (tag == null) {
                                System.out.println("Failed usage: " + useStmt);
                            } else {
                                return (NamedObj) tag.getObject();
View Full Code Here

    private void _collectVariables(SootClass entityClass, boolean debug) {
        // Loop through all the fields.
        for (Iterator fields = entityClass.getFields().iterator(); fields
                .hasNext();) {
            SootField field = (SootField) fields.next();

            // Ignore things that aren't reference types.
            Type type = field.getType();
            _createInequalityTerm(debug, field, type, _objectToInequalityTerm);

            // If the field has been tagged with a more specific type, then
            // constrain the type more.
            TypeTag tag = (TypeTag) field.getTag("_CGType");

            if (tag != null) {
                if (debug) {
                    System.out.println("tagged with type = " + tag.getType());
                }
View Full Code Here

            return null;
        } else if (value instanceof FieldRef) {
            FieldRef r = (FieldRef) value;

            // Field references have the type of the field.
            SootField field = r.getField();

            // FIXME: UGH: This is the same as elementType...
            if (field.getSignature().equals(
                    "<ptolemy.data.ArrayToken: ptolemy.data.Token[] _value>")
                    || field
                            .getSignature()
                            .equals(
                                    "<ptolemy.data.ArrayToken: ptolemy.data.type.Type _elementType>")) {
                InequalityTerm baseTerm = (InequalityTerm) objectToInequalityTerm
                        .get(((InstanceFieldRef) r).getBase());
                ptolemy.data.type.ArrayType arrayType = new ptolemy.data.type.ArrayType(
                        ptolemy.data.type.BaseType.UNKNOWN);
                InequalityTerm variableTerm = new VariableTerm(arrayType, r);
                _addInequality(debug, solver, baseTerm, variableTerm);
                _addInequality(debug, solver, variableTerm, baseTerm);

                InequalityTerm returnTypeTerm = arrayType.getElementTypeTerm();
                return returnTypeTerm;
            } else if (field.equals(PtolemyUtilities.unknownTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.UNKNOWN, r);
            } else if (field.equals(PtolemyUtilities.booleanTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.BOOLEAN, r);
            } else if (field.equals(PtolemyUtilities.booleanMatrixTypeField)) {
                return new ConstantTerm(
                        ptolemy.data.type.BaseType.BOOLEAN_MATRIX, r);
            } else if (field.equals(PtolemyUtilities.byteTypeField)) {
                return new ConstantTerm(
                        ptolemy.data.type.BaseType.UNSIGNED_BYTE, r);
            } else if (field.equals(PtolemyUtilities.complexTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.COMPLEX, r);
            } else if (field.equals(PtolemyUtilities.complexMatrixTypeField)) {
                return new ConstantTerm(
                        ptolemy.data.type.BaseType.COMPLEX_MATRIX, r);
            } else if (field.equals(PtolemyUtilities.doubleTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.DOUBLE, r);
            } else if (field.equals(PtolemyUtilities.doubleMatrixTypeField)) {
                return new ConstantTerm(
                        ptolemy.data.type.BaseType.DOUBLE_MATRIX, r);
            } else if (field.equals(PtolemyUtilities.fixTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.FIX, r);
            } else if (field.equals(PtolemyUtilities.fixMatrixTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.FIX_MATRIX,
                        r);
            } else if (field.equals(PtolemyUtilities.floatTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.FLOAT, r);
            } else if (field.equals(PtolemyUtilities.intTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.INT, r);
            } else if (field.equals(PtolemyUtilities.intMatrixTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.INT_MATRIX,
                        r);
            } else if (field.equals(PtolemyUtilities.longTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.LONG, r);
            } else if (field.equals(PtolemyUtilities.longMatrixTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.LONG_MATRIX,
                        r);
            } else if (field.equals(PtolemyUtilities.objectTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.OBJECT, r);
            } else if (field.equals(PtolemyUtilities.shortTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.SHORT, r);
            } else if (field.equals(PtolemyUtilities.stringTypeField)) {
                return new ConstantTerm(ptolemy.data.type.BaseType.STRING, r);
            }

            return (InequalityTerm) objectToInequalityTerm.get(field);
        } else if (value instanceof Local) {
View Full Code Here

                        localUses);
            } else if (value instanceof CastExpr) {
                return getPortValue(method, (Local) ((CastExpr) value).getOp(),
                        stmt, localDefs, localUses);
            } else if (value instanceof FieldRef) {
                SootField field = ((FieldRef) value).getField();
                return _getFieldValueTag(field);
            } else if (value instanceof NewExpr) {
                // If we get to an object creation, then try
                // to figure out where the variable is stored into a field.
                Iterator pairs = localUses.getUsesOf(stmt).iterator();

                while (pairs.hasNext()) {
                    UnitValueBoxPair pair = (UnitValueBoxPair) pairs.next();

                    if (pair.getUnit() instanceof DefinitionStmt) {
                        DefinitionStmt useStmt = (DefinitionStmt) pair
                                .getUnit();

                        if (useStmt.getLeftOp() instanceof FieldRef) {
                            SootField field = ((FieldRef) useStmt.getLeftOp())
                                    .getField();
                            return _getFieldValueTag(field);
                        }
                    }
                }
View Full Code Here

                Type type = PtolemyUtilities.tokenType;
                nameToType.put(name, port.getType());

                // PtolemyUtilities.getSootTypeForTokenType(
                //  port.getType());
                SootField field = new SootField(StringUtilities
                        .sanitizeName(name)
                        + "Token", type);
                entityInstanceClass.addField(field);
                nameToField.put(name, field);

                field = new SootField(StringUtilities.sanitizeName(name)
                        + "IsPresent", type);
                entityInstanceClass.addField(field);
                nameToField.put(name + "_isPresent", field);
            }
        }

        {
            SootMethod preinitializeMethod = new SootMethod("preinitialize",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(preinitializeMethod);

            JimpleBody body = Jimple.v().newBody(preinitializeMethod);
            preinitializeMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Stmt insertPoint = Jimple.v().newReturnVoidStmt();
            body.getUnits().add(insertPoint);
            ModelTransformer.initializeAttributesBefore(body, insertPoint,
                    entity, body.getThisLocal(), entity, body.getThisLocal(),
                    entityInstanceClass);
        }

        // Add a field to keep track of the current state.
        SootField currentStateField = new SootField("_currentState", IntType
                .v());
        entityInstanceClass.addField(currentStateField);

        SootField nextTransitionField = new SootField("_nextTransition",
                IntType.v());
        entityInstanceClass.addField(nextTransitionField);
        // populate the initialize method.
        {
            System.out.println("create initialize()");

            SootMethod initializeMethod = new SootMethod("initialize",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(initializeMethod);

            JimpleBody body = Jimple.v().newBody(initializeMethod);
            initializeMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            // Set the initial state.
            String initialStateName = ((StringAttribute) entity
                    .getAttribute("initialStateName")).getExpression();
            int initialStateIndex = entity.entityList().indexOf(
                    entity.getEntity(initialStateName));
            units.add(Jimple.v().newAssignStmt(
                    Jimple.v().newInstanceFieldRef(thisLocal,
                            currentStateField.makeRef()),
                    IntConstant.v(initialStateIndex)));

            // return void
            units.add(Jimple.v().newReturnVoidStmt());

            LocalNameStandardizer.v().transform(body, "at.lns");
            LocalSplitter.v().transform(body, "at.ls");
        }
        // populate the fire method.
        {
            System.out.println("create fire()");

            SootMethod fireMethod = new SootMethod("fire",
                    Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
            entityInstanceClass.addMethod(fireMethod);

            JimpleBody body = Jimple.v().newBody(fireMethod);
            fireMethod.setActiveBody(body);
            body.insertIdentityStmts();

            Chain units = body.getUnits();
            Local thisLocal = body.getThisLocal();

            Local hasTokenLocal = Jimple.v().newLocal("hasTokenLocal",
                    BooleanType.v());
            body.getLocals().add(hasTokenLocal);

            Local tokenLocal = Jimple.v().newLocal("tokenLocal",
                    PtolemyUtilities.tokenType);
            body.getLocals().add(tokenLocal);

            Iterator inputPorts = entity.inputPortList().iterator();

            while (inputPorts.hasNext()) {
                TypedIOPort port = (TypedIOPort) (inputPorts.next());

                // FIXME: Handle multiports
                if (port.getWidth() > 0) {
                    String name = port.getName(entity);

                    // Create an if statement.
                    //
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityInstanceClass
                            .getFieldByName(StringUtilities.sanitizeName(name));
                    units.add(Jimple.v().newAssignStmt(
                            portLocal,
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    portField.makeRef())));
                    units.add(Jimple.v().newAssignStmt(
                            hasTokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.hasTokenMethod.makeRef(),
                                    IntConstant.v(0))));

                    Local hasTokenToken = PtolemyUtilities.addTokenLocal(body,
                            "token", PtolemyUtilities.booleanTokenClass,
                            PtolemyUtilities.booleanTokenConstructor,
                            hasTokenLocal);

                    // store the isPresent
                    SootField tokenIsPresentField = (SootField) nameToField
                            .get(name + "_isPresent");
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenIsPresentField.makeRef()),
                            hasTokenToken));

                    Stmt target = Jimple.v().newNopStmt();
                    units.add(Jimple.v().newIfStmt(
                            Jimple.v().newEqExpr(hasTokenLocal,
                                    IntConstant.v(0)), target));
                    units.add(Jimple.v().newAssignStmt(
                            tokenLocal,
                            Jimple.v().newVirtualInvokeExpr(portLocal,
                                    PtolemyUtilities.getMethod.makeRef(),
                                    IntConstant.v(0))));

                    SootField tokenField = (SootField) nameToField.get(name);
                    units.add(Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(thisLocal,
                                    tokenField.makeRef()), tokenLocal));
                    units.add(target);
                }
            }

            Map stateToStartStmt = new HashMap();
View Full Code Here

                    // send the computed token
                    Local portLocal = Jimple.v().newLocal("port",
                            PtolemyUtilities.componentPortType);
                    body.getLocals().add(portLocal);

                    SootField portField = entityClass.getFieldByName(name);

                    body.getUnits().add(
                            Jimple.v().newAssignStmt(
                                    portLocal,
                                    Jimple.v().newInstanceFieldRef(
                                            body.getThisLocal(),
                                            portField.makeRef())));
                    body.getUnits().add(
                            Jimple.v()
                                    .newInvokeStmt(
                                            Jimple.v().newVirtualInvokeExpr(
                                                    portLocal,
View Full Code Here

TOP

Related Classes of soot.SootField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.