Package soot

Examples of soot.SootField


        for (Iterator freeVariables = freeVariableList.iterator(); freeVariables
                .hasNext();) {
            String freeVariable = (String) freeVariables.next();
            ptolemy.data.type.Type type = _scope.getType(freeVariable);
            Type sootType = PtolemyUtilities.getSootTypeForTokenType(type);
            SootField field = new SootField(freeVariable, sootType,
                    Modifier.PUBLIC);
            functionClass.addField(field);
            argumentSootTypes.add(sootType);
            nameToLocal.put(freeVariable, field);
            nameToType.put(freeVariable, type);
        }

        // Create the constructor.  The constructor takes one argument
        // for every free variable of the function closure that is not
        // bound to a formal argument.
        SootMethod functionConstructor = new SootMethod("<init>",
                argumentSootTypes, VoidType.v(), Modifier.PUBLIC);
        functionClass.addMethod(functionConstructor);

        {
            JimpleBody body = Jimple.v().newBody(functionConstructor);
            functionConstructor.setActiveBody(body);
            body.insertIdentityStmts();
            body.getUnits().add(
                    Jimple.v()
                            .newInvokeStmt(
                                    Jimple.v().newSpecialInvokeExpr(
                                            body.getThisLocal(),
                                            PtolemyUtilities.objectConstructor
                                                    .makeRef(),
                                            Collections.EMPTY_LIST)));

            // Read the parameters to the closure constructor.
            int i = 0;

            for (Iterator freeVariables = freeVariableList.iterator(); freeVariables
                    .hasNext();) {
                String freeVariable = (String) freeVariables.next();
                Local local = body.getParameterLocal(i);
                SootField field = (SootField) nameToLocal.get(freeVariable);
                body.getUnits().add(
                        Jimple.v().newAssignStmt(
                                Jimple.v().newInstanceFieldRef(
                                        body.getThisLocal(), field.makeRef()),
                                local));
                i++;
            }

            body.getUnits().add(Jimple.v().newReturnVoidStmt());
View Full Code Here


                        if (method.getName().equals("<init>")
                                && (method.getParameterCount() == 2)) {
                            // Change the constructor so that it takes an
                            // appropriate container type.
                            SootField containerField = theClass
                                    .getFieldByName(ModelTransformer
                                            .getContainerFieldName());
                            RefType containerType = (RefType) containerField
                                    .getType();
                            List typeList = new LinkedList();
                            typeList.add(containerType);
                            typeList.add(RefType.v("java.lang.String"));
                            method.setParameterTypes(typeList);
View Full Code Here

    }

    public SootField getBufferField(IOPort port, ptolemy.data.type.Type type) {
        Map typeNameToBufferField = (Map) _portToTypeNameToBufferField
                .get(port);
        SootField arrayField = (SootField) typeNameToBufferField.get(type
                .toString());

        if (arrayField == null) {
            throw new RuntimeException("arrayField for " + port + " and type "
                    + type + " is null!");
View Full Code Here

    public SootField getInsideBufferField(IOPort port,
            ptolemy.data.type.Type type) {
        Map typeNameToBufferField = (Map) _portToTypeNameToInsideBufferField
                .get(port);
        SootField arrayField = (SootField) typeNameToBufferField.get(type
                .toString());

        if (arrayField == null) {
            throw new RuntimeException("arrayField null!");
        }
View Full Code Here

            TypedIORelation relation = (TypedIORelation) relations.next();

            for (int i = 0; i < relation.getWidth(); i++, channel++) {
                Value channelValue = IntConstant.v(channel);

                SootField arrayField = _modelClass
                        .getFieldByName(InlinePortTransformer
                                .getBufferFieldName(relation, i, port.getType()));

                // load the buffer array.
                body.getUnits().insertBefore(
                        Jimple.v().newAssignStmt(
                                bufferLocal,
                                Jimple.v().newStaticFieldRef(
                                        arrayField.makeRef())), stmt);

                // If we are calling with just a token, then send the token.
                if (expr.getArgCount() == 1) {
                    // Write to the buffer.
                    body.getUnits().insertBefore(
View Full Code Here

        }

        RefType tokenType = PtolemyUtilities.getSootTypeForTokenType(type);

        // Create a field that refers to all the channels of that port.
        SootField bufferField = new SootField("_portbuffer_"
                + StringUtilities.sanitizeName(port.getName()) + "_"
                + StringUtilities.sanitizeName(type.toString()), ArrayType.v(
                tokenType, 1), Modifier.PUBLIC);
        entityClass.addField(bufferField);

        // Store references to the new field.
        typeNameToBufferField.put(type.toString(), bufferField);

        // Tag the field we created with the type of its data.
        bufferField.addTag(new TypeTag(type));

        // Create references to the buffer for each port channel
        for (Iterator methods = entityClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();
            JimpleBody body = (JimpleBody) method.retrieveActiveBody();
            Object insertPoint = body.getUnits().getLast();

            // Insert code into all the init methods.
            if (!method.getName().equals("<init>")) {
                continue;
            }

            Local channelLocal = Jimple.v().newLocal("channel",
                    ArrayType.v(tokenType, 1));
            body.getLocals().add(channelLocal);

            // Create the array of port channels.
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
                            channelLocal,
                            Jimple.v().newNewArrayExpr(tokenType,
                                    IntConstant.v(port.getWidth()))),
                    insertPoint);

            // Set the field to point to the new array.
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(body.getThisLocal(),
                                    bufferField.makeRef()), channelLocal),
                    insertPoint);
        }
    }
View Full Code Here

            Map typeNameToBufferField) {
        //  System.out.println("creating inside buffer reference for " + port + " type = " + type);
        RefType tokenType = PtolemyUtilities.getSootTypeForTokenType(type);

        // Create a field that refers to all the channels of that port.
        SootField bufferField = new SootField("_portinsidebuffer_"
                + StringUtilities.sanitizeName(port.getName()) + "_"
                + StringUtilities.sanitizeName(type.toString()), ArrayType.v(
                tokenType, 1), Modifier.PUBLIC);
        _modelClass.addField(bufferField);

        // Store references to the new field.
        typeNameToBufferField.put(type.toString(), bufferField);

        // Tag the field we created with the type of its data.
        bufferField.addTag(new TypeTag(type));

        // Create references to the buffer for each port channel
        for (Iterator methods = _modelClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();
            JimpleBody body = (JimpleBody) method.retrieveActiveBody();
            Object insertPoint = body.getUnits().getLast();

            // Insert code into all the init methods.
            if (!method.getName().equals("<init>")) {
                continue;
            }

            Local channelLocal = Jimple.v().newLocal("channel",
                    ArrayType.v(tokenType, 1));
            body.getLocals().add(channelLocal);

            // Create the array of port channels.
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
                            channelLocal,
                            Jimple.v().newNewArrayExpr(
                                    ArrayType.v(tokenType, 1),
                                    IntConstant.v(port.getWidth()))),
                    insertPoint);

            // Set the field to point to the new array.
            body.getUnits().insertBefore(
                    Jimple.v().newAssignStmt(
                            Jimple.v().newInstanceFieldRef(body.getThisLocal(),
                                    bufferField.makeRef()), channelLocal),
                    insertPoint);
        }
    }
View Full Code Here

            Entity entityContainer = FieldsForEntitiesTransformer
                    .getEntityContainerOfObject(attribute);

            //             NamedObj creatorObject =
            //                 ModelTransformer.getCreatorObject(attribute);
            SootField attributeField = (SootField) _attributeToFieldMap
                    .get(attribute);
            Local local;

            if (entityContainer.equals(baseObject)) {
                local = baseLocal;
            } else {
                local = FieldsForEntitiesTransformer
                        .getLocalReferenceForEntity(entityContainer, theClass,
                                body.getThisLocal(), body, unit, _options);
            }

            if (attributeField != null) {
                System.out.println(unit.getClass().toString());
                System.out.println(box.getClass().toString());
                box.setValue(Jimple.v().newInstanceFieldRef(local,
                        attributeField.makeRef()));
            } else {
                throw new RuntimeException(
                        "Failed to find field for attribute "
                                + attribute.getFullName());
            }
        } else {
            // Otherwise, we have an attribute inside a port or
            // another attribute...  In such cases, we need to work
            // backwards to get to an entity, so we can find the
            // correct port.  Walk back and get the definition of the
            // field.
            DefinitionStmt definition = _getFieldDef(baseLocal, unit, localDefs);
            InstanceFieldRef fieldRef = (InstanceFieldRef) definition
                    .getRightOp();
            SootField baseField = fieldRef.getField();
            _replaceGetAttributeMethod(theClass, body, box, (Local) fieldRef
                    .getBase(), baseField.getName() + "." + name, definition,
                    localDefs);

            //baseField.getDeclaringClass().getFieldByName(
            //    baseField.getName() + "_" + name);
        }
View Full Code Here

                //                         + attribute.getFullName());
                continue;
            }

            // retrieve the existing field.
            SootField field = theClass.getFieldByName(fieldName);

            Type type = field.getType();

            if (!(type instanceof RefType)) {
                System.out.println("Class " + theClass
                        + " declares field for attribute "
                        + attribute.getFullName() + " but it has type " + type);
                continue;
            } else {
                SootClass fieldClass = ((RefType) type).getSootClass();

                if (!SootUtilities.derivesFrom(fieldClass,
                        PtolemyUtilities.attributeClass)) {
                    System.out.println("Class " + theClass
                            + " declares field for attribute "
                            + attribute.getFullName() + " but it has type "
                            + fieldClass.getName());
                    continue;
                }
            }

            // Make the field final and private.
            field.setModifiers((field.getModifiers() & Modifier.STATIC)
                    | Modifier.FINAL | Modifier.PUBLIC); // FIXME | Modifier.PRIVATE);

            field.addTag(new ValueTag(attribute));
            _attributeToFieldMap.put(attribute, field);

            // call recursively
            _getAttributeFields(theClass, container, attribute);
        }
View Full Code Here

    private static void _getBuffer(SootClass modelClass, JimpleBody body,
            Unit unit, TypedIOPort port, ptolemy.data.type.Type type,
            Local bufferLocal, Map portToTypeNameToBufferField) {
        // If we don't know the channel, then use the port indexes.
        Map typeNameToBufferField = (Map) portToTypeNameToBufferField.get(port);
        SootField arrayField = (SootField) typeNameToBufferField.get(type
                .toString());

        if (arrayField == null) {
            throw new RuntimeException("arrayField null!");
        }

        // Load the array of port channels.
        body.getUnits().insertBefore(
                Jimple.v().newAssignStmt(
                        bufferLocal,
                        Jimple.v().newInstanceFieldRef(body.getThisLocal(),
                                arrayField.makeRef())), unit);
    }
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.