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));
}
}
}
}
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;
}
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);
}
Aggregations