Package soot

Examples of soot.RefType


    /** Return true if the given type references a
     *  ptolemy token type.  In other words It is either a direct
     *  reference to a Token, or an array of Tokens.
     */
    public static boolean isTokenType(Type type) {
        RefType refType;

        if (type instanceof RefType) {
            refType = (RefType) type;
        } else if (type instanceof ArrayType) {
            ArrayType arrayType = (ArrayType) type;

            if (arrayType.baseType instanceof RefType) {
                refType = (RefType) arrayType.baseType;
            } else {
                return false;
            }
        } else {
            return false;
        }

        return SootUtilities.derivesFrom(refType.getSootClass(),
                PtolemyUtilities.tokenClass);
    }
View Full Code Here


    /** Return true if the given type references a
     *  ptolemy token type type.  In other words It is either a direct
     *  reference to a Type, or an array of Types.
     */
    public static boolean isTypeType(Type type) {
        RefType refType;

        if (type instanceof RefType) {
            refType = (RefType) type;
        } else if (type instanceof ArrayType) {
            ArrayType arrayType = (ArrayType) type;

            if (arrayType.baseType instanceof RefType) {
                refType = (RefType) arrayType.baseType;
            } else {
                return false;
            }
        } else {
            return false;
        }

        return SootUtilities.derivesFrom(refType.getSootClass(),
                PtolemyUtilities.typeClass);
    }
View Full Code Here

                    if (value instanceof FieldRef) {
                        // Fix references to fields
                        FieldRef r = (FieldRef) value;
                        SootFieldRef fieldRef = r.getFieldRef();
                        if (fieldRef.type() instanceof RefType) {
                            RefType fieldType = (RefType) fieldRef.type();
                            SootClass fieldClass = fieldType.getSootClass();
                            if (fieldClass == oldClass) {
                                r.setFieldRef(Scene.v().makeFieldRef(
                                        fieldRef.declaringClass(),
                                        fieldRef.name(), RefType.v(newClass),
                                        fieldRef.isStatic()));
View Full Code Here

     */
    public static Local createRuntimeException(Body body, Unit unit,
            String string) {
        SootClass exceptionClass = Scene.v().getSootClass(
                "java.lang.RuntimeException");
        RefType exceptionType = RefType.v(exceptionClass);
        SootMethod initMethod = exceptionClass
                .getMethod("void <init>(java.lang.String)");

        Local local = Jimple.v().newLocal("exceptionLocal", exceptionType);
        body.getLocals().add(local);
View Full Code Here

            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);
View Full Code Here

                    NamedObj rightObject = null;

                    if (left.getType() instanceof NullType) {
                        leftObject = null;
                    } else if (left.getType() instanceof RefType) {
                        RefType leftType = (RefType) left.getType();
                        SootClass leftClass = leftType.getSootClass();

                        if (SootUtilities.derivesFrom(leftClass,
                                PtolemyUtilities.namedObjClass)) {
                            try {
                                leftObject = getNamedObjValue(method,
                                        (Local) left, stmt, localDefs,
                                        localUses);
                            } catch (Exception ex) {
                                // Ignore... We cannot determine the
                                // value of the object.
                                continue;
                            }
                        } else {
                            continue;
                        }
                    } else {
                        continue;
                    }

                    if (right.getType() instanceof NullType) {
                        rightObject = null;
                    } else if (right.getType() instanceof RefType) {
                        RefType rightType = (RefType) right.getType();
                        SootClass rightClass = rightType.getSootClass();

                        if (SootUtilities.derivesFrom(rightClass,
                                PtolemyUtilities.namedObjClass)) {
                            try {
                                rightObject = getNamedObjValue(method,
View Full Code Here

    // the given type, look into the given map and retrieve the
    // inequality term for the object.  retrieve the resolved type,
    // and return it.
    private Type _getUpdateType(Object object, Type type)
            throws IllegalActionException {
        RefType tokenType = PtolemyUtilities.getBaseTokenType(type);

        if (tokenType != null) {
            if (_debug) {
                System.out.println("type of value " + object + " = " + type);
            }

            InequalityTerm term = (InequalityTerm) _objectToInequalityTerm
                    .get(object);

            if (term == null) {
                return null;
            }

            ptolemy.data.type.Type newTokenType = (ptolemy.data.type.Type) term
                    .getValue();
            RefType newType = PtolemyUtilities
                    .getSootTypeForTokenType(newTokenType);

            if (_debug) {
                System.out.println("newType = " + newType);
            }

            if (!SootUtilities.derivesFrom(newType.getSootClass(), tokenType
                    .getSootClass())) {
                // If the new Type is less specific, in Java terms,
                // than what we had before, then the resulting code is
                // likely not correct.  FIXME: hack to get around the
                // bogus type lattice.  This should be an exception.
View Full Code Here

            InequalityTerm baseTerm = (InequalityTerm) objectToInequalityTerm
                    .get(castExpr.getOp());
            return baseTerm;
        } else if (value instanceof NewExpr) {
            NewExpr newExpr = (NewExpr) value;
            RefType type = newExpr.getBaseType();
            SootClass castClass = type.getSootClass();

            // If we are creating a Token type...
            if (SootUtilities.derivesFrom(castClass,
                    PtolemyUtilities.tokenClass)) {
                InequalityTerm typeTerm = new ConstantTerm(PtolemyUtilities
                        .getTokenTypeForSootType(type), newExpr);

                // Then the value of the expression is the type of the
                // constructor.
                return typeTerm;
            } else {
                // Otherwise there is nothing to be done.
                return null;
            }
        } else if (value instanceof NewArrayExpr) {
            // Since arrays are aliasable, we must update their types.
            NewArrayExpr newExpr = (NewArrayExpr) value;
            Type type = newExpr.getBaseType();
            RefType tokenType = PtolemyUtilities.getBaseTokenType(type);

            if ((tokenType != null)
                    && (objectToInequalityTerm.get(newExpr) == null)) {
                InequalityTerm typeTerm = new VariableTerm(PtolemyUtilities
                        .getTokenTypeForSootType(tokenType), newExpr);

                // This is something we update, so put an entry
                // in the map used for updating
                objectToInequalityTerm.put(newExpr, typeTerm);

                // Then the value of the expression is the type of the
                // constructor.
                return typeTerm;
            }

            // Otherwise there is nothing to be done.
            return null;
        } else if (value instanceof NewMultiArrayExpr) {
            // Since arrays are aliasable, we must update their types.
            NewMultiArrayExpr newExpr = (NewMultiArrayExpr) value;
            Type type = newExpr.getBaseType();
            RefType tokenType = PtolemyUtilities.getBaseTokenType(type);

            if ((tokenType != null)
                    && (objectToInequalityTerm.get(newExpr) == null)) {
                InequalityTerm typeTerm = new VariableTerm(PtolemyUtilities
                        .getTokenTypeForSootType(tokenType), newExpr);
View Full Code Here

        }
    }

    private static void _createInequalityTerm(boolean debug, Object object,
            Type type, Map objectToInequalityTerm) {
        RefType tokenType = PtolemyUtilities.getBaseTokenType(type);
        if (debug) {
            System.out.println("_createInequalityTerm(): " + object + " type: "
                    + type + " tokenType: " + tokenType);
        }
        if (objectToInequalityTerm.get(object) != null) {
            return;
        }
        if (tokenType != null) {
            if (debug) {
                System.out.println("creating inequality term for " + object);
            }

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

            InequalityTerm term = new VariableTerm(PtolemyUtilities
                    .getTokenTypeForSootType(tokenType), object);
            objectToInequalityTerm.put(object, term);
            return;
        }

        RefType typeType = PtolemyUtilities.getBaseTokenTypeType(type);

        if (typeType != null) {
            if (debug) {
                System.out.println("creating inequality term for " + object);
            }
View Full Code Here

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

                if (r.getBase().getType() instanceof RefType) {
                    RefType type = (RefType) r.getBase().getType();

                    // Inline calls to connections changed.
                    if (r.getMethod().equals(
                            PtolemyUtilities.connectionsChangedMethod)) {
                        // If we are calling connections changed on one of the classes
                        // we are generating code for, then inline it.
                        if (type.getSootClass().isApplicationClass()) {
                            SootMethod inlinee = null;

                            if (r instanceof VirtualInvokeExpr) {
                                // Now inline the resulting call.
                                List methodList = Scene
                                        .v()
                                        .getActiveHierarchy()
                                        .resolveAbstractDispatch(
                                                type.getSootClass(),
                                                PtolemyUtilities.connectionsChangedMethod);

                                if (methodList.size() == 1) {
                                    // Inline the method.
                                    inlinee = (SootMethod) methodList.get(0);
                                } else {
                                    String string = "Can't inline " + stmt
                                            + " in method " + method + "\n";

                                    for (int i = 0; i < methodList.size(); i++) {
                                        string += ("target = "
                                                + methodList.get(i) + "\n");
                                    }

                                    System.out.println(string);
                                }
                            } else if (r instanceof SpecialInvokeExpr) {
                                inlinee = Scene.v().getActiveHierarchy()
                                        .resolveSpecialDispatch(
                                                (SpecialInvokeExpr) r, method);
                            }

                            if (inlinee != null
                                    && !inlinee.getDeclaringClass()
                                            .isApplicationClass()) {
                                inlinee.getDeclaringClass().setLibraryClass();
                            }

                            inlinee.retrieveActiveBody();

                            if (debug) {
                                System.out
                                        .println("Inlining method call: " + r);
                            }

                            SiteInliner.inlineSite(inlinee, stmt, method);

                            doneSomething = true;
                        } else {
                            // FIXME: this is a bit of a hack, but
                            // for right now it seems to work.
                            // How many things that aren't
                            // the actors we are generating
                            // code for do we really care about here?
                            // Can we do this without having to create
                            // a class for the port too????
                            body.getUnits().remove(stmt);
                            doneSomething = true;
                        }
                    }

                    // Statically evaluate constant arguments.
                    Value[] argValues = new Value[r.getArgCount()];
                    int constantArgCount = 0;

                    for (Iterator args = r.getArgs().iterator(); args.hasNext();) {
                        Value arg = (Value) args.next();

                        //System.out.println("arg = " + arg);
                        if (Evaluator.isValueConstantValued(arg)) {
                            argValues[constantArgCount++] = Evaluator
                                    .getConstantValueOf(arg);

                            // System.out.println("argument = " + argValues[argCount-1]);
                        } else {
                            break;
                        }
                    }

                    //boolean allArgsAreConstant = (r.getArgCount() == constantArgCount);

                    if (SootUtilities.derivesFrom(type.getSootClass(),
                            PtolemyUtilities.componentPortClass)) {
                        // If we are invoking a method on a port
                        // class, then attempt to get the constant
                        // value of the port.
                        TypedIOPort port = (TypedIOPort) analysis
View Full Code Here

TOP

Related Classes of soot.RefType

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.