Package dk.brics.string.intermediate

Examples of dk.brics.string.intermediate.Method


    /**
     * Makes a method that simulates the <code>toString</code> method of a basic
     * wrapper classes.
     */
    void makeBasicToStringMethod(Type prim, String classname, Automaton a) {
        Method m = new Method(application, classname + ".toString",
                new Variable[0]);
        SootClass c = Scene.v().getSootClass(classname);
        Variable var = application.createVariable(VariableType.STRING);
        StringStatement ss = new StringInit(var, a);
        m.addStatement(ss);
        m.getEntry().addSucc(ss);
        Return ret = new Return(var);
        m.addStatement(ret);
        ss.addSucc(ret);

        methods.add(m);
        tostring_targets.put(c, m);
        tostring_methods.put(classname, m);
View Full Code Here


    /**
     * Makes wrapper method that calls all externally visible methods in
     * application classes, using arbitrary arguments.
     */
    void makeWrapperMethod() {
        Method wrapper = new Method(application, "<wrapper>", new Variable[0]);
        methods.add(wrapper);
       
        // build the wrapper's body
        ControlFlowBuilder cfg = new ControlFlowBuilder(wrapper);
        cfg.moveToStatement(wrapper.getEntry());
       
        // create a variable holding any string
        Variable anyVar = application.createVariable(VariableType.STRING);
        Statement assignAny = new StringInit(anyVar, Basic.makeAnyString());
        cfg.addStatement(assignAny);

        // create a variable holding the null string
        Variable nullVar = application.createVariable(VariableType.STRING);
        Statement assignNull = new StringInit(nullVar, Automatons.getNull());
        cfg.addStatement(assignNull);
       
        // initialize externally visible field variables to anything
        // and set string fields to "null"
        for (SootClass ac : getApplicationClasses()) {
            for (SootField field : ac.getFields()) {
                // String fields should be assigned to "null" because they are
                // exempt from the
                // null-pointer analysis we use for other objects
                if (field.getType().equals(RefType.v("java.lang.String"))) {
                    FieldAssignment assignment = new FieldAssignment(
                            variableManager.getField(field), nullVar);
                    cfg.addStatement(assignment);
                }

                // corrupt externally visible fields
                if (ext.isExternallyVisibleField(field)) {
                    VariableType type = fromSootType(field
                            .getType());

                    if (type == VariableType.NONE)
                        continue;

                    Variable fieldInit;

                    switch (type) {
                    case OBJECT:
                    case STRING:
                    case PRIMITIVE:
                        fieldInit = anyVar;
                        break;

                    case STRINGBUFFER: {
                        fieldInit = application.createVariable(VariableType.STRINGBUFFER);
                        Statement s = new StringBufferCorrupt(fieldInit);
                        cfg.addStatement(s);
                        break;
                    }

                    case ARRAY: {
                        fieldInit = application.createVariable(VariableType.ARRAY);
                        Statement s = new ArrayCorrupt(fieldInit);
                        cfg.addStatement(s);
                        break;
                    }
                    default:
                        throw new RuntimeException("Unknown field type " + type);
                    }// switch

                    FieldAssignment assignment = new FieldAssignment(variableManager.getField(field), fieldInit);
                    cfg.addStatement(assignment);
                }
            }
        }
       
        // split control here, and call a random externally visible method
        cfg.startBranch();
       
        // call externally visible methods
        for (SootClass ac : getApplicationClasses()) {
            for (SootMethod sm : ac.getMethods()) {
                if (ext.isExternallyVisibleMethod(sm)) {
                    Method m = sms_m.get(sm.getSignature());
                    Variable[] params = m.getEntry().params;
                    Variable[] args = new Variable[params.length];
                    for (int i = 0; i < params.length; i++) {
                        Variable arg = application.createVariable(params[i].getType());
                        args[i] = arg;
                        Statement s;
View Full Code Here

             
              factory.addStatement(new StringInit(result, Automatons.fromType(type.toString())));
             
            } else if (val.getType() instanceof RefType) {
                // Call the corresponding toString method
                Method tostring_method = factory.getToStringMethod(((RefType) val.getType()).getSootClass());
                if (tostring_method != null && !isInterface(val.getType())) {
                  factory.addStatement(new Call(result, tostring_method, new Variable[0]));
                } else {
                  factory.addStatement(new StringInit(result, Basic.makeAnyString()));
                }
View Full Code Here

TOP

Related Classes of dk.brics.string.intermediate.Method

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.