Search in sources :

Example 1 with CallStringSerialization

use of com.jopdesign.common.code.CallString.CallStringSerialization in project jop by jop-devel.

the class AnalysisResultSerialization method dump.

/** Dump the results in human readable form to the given stream */
public void dump(PrintStream os, ResultFormatter<R> formatter) {
    for (Entry<String, Map<CallStringSerialization, Map<Integer, R>>> miEntry : serializedResults.entrySet()) {
        os.println(miEntry.getKey());
        for (Entry<CallStringSerialization, Map<Integer, R>> csEntry : miEntry.getValue().entrySet()) {
            os.println("  " + csEntry.getKey().toString());
            for (Entry<Integer, R> posEntry : csEntry.getValue().entrySet()) {
                String rStr;
                if (formatter != null) {
                    rStr = formatter.format(miEntry.getKey(), csEntry.getKey(), posEntry.getKey(), posEntry.getValue());
                } else {
                    rStr = "" + posEntry.getValue();
                }
                os.println(String.format("  %-6d: %s", posEntry.getKey(), rStr));
            }
        }
    }
}
Also used : CallStringSerialization(com.jopdesign.common.code.CallString.CallStringSerialization) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with CallStringSerialization

use of com.jopdesign.common.code.CallString.CallStringSerialization in project jop by jop-devel.

the class AnalysisResultSerialization method toContextMapResult.

public <T> Map<InstructionHandle, ContextMap<CallString, T>> toContextMapResult(AppInfo appInfo, Serializer<T, R> serializer) throws MethodNotFoundException, IOException, ClassNotFoundException {
    /* `context' is a really bad hack in the DFA. In the deserialization,
		 * we guarantee that context.getMethodInfo() and context.callstring are correct,
		 * but the rest of context is undefined.
		 */
    Context currentContext;
    Map<InstructionHandle, ContextMap<CallString, T>> resultMap = new LinkedHashMap<InstructionHandle, ContextMap<CallString, T>>();
    for (Entry<String, Map<CallStringSerialization, Map<Integer, R>>> miEntry : serializedResults.entrySet()) {
        MethodInfo mi = appInfo.getMethodInfo(MemberID.parse(miEntry.getKey()));
        for (Entry<CallStringSerialization, Map<Integer, R>> csEntry : miEntry.getValue().entrySet()) {
            CallString cs = csEntry.getKey().getCallString(appInfo);
            currentContext = new Context();
            currentContext.setMethodInfo(mi);
            currentContext.callString = cs;
            for (Entry<Integer, R> posEntry : csEntry.getValue().entrySet()) {
                int pos = posEntry.getKey();
                R value = posEntry.getValue();
                InstructionHandle instr = mi.getCode().getInstructionList(false, false).findHandle(pos);
                ContextMap<CallString, T> ctxMap = resultMap.get(instr);
                if (ctxMap == null) {
                    ctxMap = new ContextMap<CallString, T>(currentContext, new LinkedHashMap<CallString, T>());
                    resultMap.put(instr, ctxMap);
                }
                if (serializer == null) {
                    ctxMap.put(cs, (T) value);
                } else {
                    T origValue = serializer.fromSerializedRepresentation(value, appInfo);
                    ctxMap.put(cs, origValue);
                }
            }
        }
    }
    return resultMap;
}
Also used : CallStringSerialization(com.jopdesign.common.code.CallString.CallStringSerialization) CallString(com.jopdesign.common.code.CallString) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedHashMap(java.util.LinkedHashMap) CallString(com.jopdesign.common.code.CallString) MethodInfo(com.jopdesign.common.MethodInfo) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with CallStringSerialization

use of com.jopdesign.common.code.CallString.CallStringSerialization in project jop by jop-devel.

the class AnalysisResultSerialization method addResult.

public void addResult(MethodInfo method, Integer pos, CallString cs, R result) {
    Map<CallStringSerialization, Map<Integer, R>> csMap = getOrCreateMapEntry(serializedResults, method.getFQMethodName(), LinkedHashMap.class);
    Map<Integer, R> posMap = getOrCreateMapEntry(csMap, new CallStringSerialization(cs), TreeMap.class);
    if (posMap.containsKey(pos)) {
        throw new AssertionError("Duplicate Key in DFA result set");
    }
    posMap.put(pos, result);
}
Also used : CallStringSerialization(com.jopdesign.common.code.CallString.CallStringSerialization) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

CallStringSerialization (com.jopdesign.common.code.CallString.CallStringSerialization)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 CallString (com.jopdesign.common.code.CallString)2 MethodInfo (com.jopdesign.common.MethodInfo)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1