Search in sources :

Example 26 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class AllocationWcetModel method getObjectFields.

public List<Type> getObjectFields(String className) {
    List<Type> l = new LinkedList<Type>();
    ClassInfo cli = project.getAppInfo().getClassInfo(className);
    if (cli.getSuperClassName() != null) {
        l.addAll(getObjectFields(cli.getSuperClassName()));
    }
    for (FieldInfo f : cli.getFields()) {
        if (!f.isStatic()) {
            l.add(f.getType());
        }
    }
    return l;
}
Also used : Type(org.apache.bcel.generic.Type) ObjectType(org.apache.bcel.generic.ObjectType) LinkedList(java.util.LinkedList) FieldInfo(com.jopdesign.common.FieldInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 27 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class LinkerInfo method getOrCreateLinkInfo.

private LinkInfo getOrCreateLinkInfo(String classname) throws ClassNotFoundException {
    ClassInfo klass = project.getAppInfo().getClassInfo(classname);
    if (klass == null)
        throw new ClassNotFoundException(classname);
    LinkInfo linkInfo = classLinkInfo.get(classname);
    if (linkInfo == null) {
        linkInfo = new LinkInfo(klass, 0, 0);
        classLinkInfo.put(classname, linkInfo);
    }
    return linkInfo;
}
Also used : ClassInfo(com.jopdesign.common.ClassInfo)

Example 28 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class InvokeSite method isSuperMethod.

/**
     * Check if this invokespecial is a super invoke. Does NOT check if the instruction is indeed an
     * special invoke, check this first!
     * See #isInvokeSuper() for more details.
     *
     * @param invokee the method referenced by the instruction.
     * @return true if this references to a super method
     */
private boolean isSuperMethod(MethodRef invokee) {
    // This is the class where the invoker method is defined (not the class of the object instance!)
    ClassInfo cls = invoker.getClassInfo();
    if (!cls.hasSuperFlag())
        return false;
    if ("<init>".equals(invokee.getName()))
        return false;
    // just to handle some special cases of unknown superclasses gracefully, without requiring a classInfo
    if (cls.getClassName().equals(invokee.getClassName())) {
        // this is an invoke within the same class, no super here
        return false;
    }
    if (cls.isRootClass()) {
        // trying to call a super-method of Object? Not likely, dude ..
        return false;
    }
    // do not need to check interfaces, since invokespecial must not call interface methods
    Ternary rs = cls.hasSuperClass(invokee.getClassName(), false);
    if (rs == Ternary.UNKNOWN) {
        if (invokee.getClassRef().getClassInfo() != null) {
            // class exists, but method does not exists, either an error or superclasses are missing
            throw new JavaClassFormatError("Invokespecial tries to call " + invokee + " but this method has not been found");
        }
        // invokespecial to an unknown class, we cannot handle this safely
        throw new JavaClassFormatError("Could not determine if invokespecial is a super invoke for " + invokee);
    }
    return rs == Ternary.TRUE;
}
Also used : Ternary(com.jopdesign.common.misc.Ternary) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) ClassInfo(com.jopdesign.common.ClassInfo)

Example 29 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class BasicBlock method getStartLine.

/**
     * @return a human readable string representation of the location of the first instruction
     * in the basic block
     */
public String getStartLine() {
    ClassInfo cls = null;
    int line = -1;
    for (InstructionHandle ih : instructions) {
        cls = methodCode.getSourceClassInfo(ih);
        line = methodCode.getLineNumber(this.getFirstInstruction());
        if (line >= 0)
            break;
    }
    if (line >= 0) {
        return cls.getSourceFileName() + ":" + line;
    } else {
        return getMethodInfo().getClassInfo().getSourceFileName() + ":" + getMethodInfo().getFQMethodName();
    }
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle) ClassInfo(com.jopdesign.common.ClassInfo)

Example 30 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class BasicBlock method getSourceLines.

/**
     * @return all source code lines this basic block maps to
     */
public Map<ClassInfo, TreeSet<Integer>> getSourceLines() {
    Map<ClassInfo, TreeSet<Integer>> map = new HashMap<ClassInfo, TreeSet<Integer>>(2);
    for (InstructionHandle ih : instructions) {
        ClassInfo cls = methodCode.getSourceClassInfo(ih);
        TreeSet<Integer> lines = map.get(cls);
        if (lines == null) {
            lines = new TreeSet<Integer>();
            map.put(cls, lines);
        }
        int line = methodCode.getLineNumber(ih);
        if (line >= 0)
            lines.add(line);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

ClassInfo (com.jopdesign.common.ClassInfo)49 MethodInfo (com.jopdesign.common.MethodInfo)19 DefaultEdge (org.jgrapht.graph.DefaultEdge)8 AppInfo (com.jopdesign.common.AppInfo)7 HashMap (java.util.HashMap)7 InstructionHandle (org.apache.bcel.generic.InstructionHandle)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 IOException (java.io.IOException)5 LinkedList (java.util.LinkedList)5 FieldInfo (com.jopdesign.common.FieldInfo)4 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)4 MemberID (com.jopdesign.common.type.MemberID)4 BitSet (java.util.BitSet)3 AppSetup (com.jopdesign.common.AppSetup)2 MethodCode (com.jopdesign.common.MethodCode)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallString (com.jopdesign.common.code.CallString)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 ExecutionContext (com.jopdesign.common.code.ExecutionContext)2