Verified Commit 0772a738 authored by Amin Bandali's avatar Amin Bandali
Browse files

Make ModuleResult abstract, add SSRResult and MutResult subclasses

And display total count and percentage of SSR candidates in a corpus,
with respect to total number of signatures in that corpus.
parent 86d924ca
......@@ -42,7 +42,7 @@ enum Solver {
}
}
enum ModuleKind {
enum MutKind {
ORIGINAL,
MUT_RANDOM
}
......@@ -136,6 +136,19 @@ public final class MainCLI {
mainPr.ln(String.format("time taken to analyze %s models: %dms",
corpus, cr.elapsed_time));
if (o.ssr) {
long ssrc = 0, ssrt = 0;
for (FileResult fr : cr.file_results)
for (ModuleResult mr : fr.module_results)
if (mr instanceof SSRResult) {
SSRResult r = (SSRResult)mr;
ssrc += r.ssr_candidate_count;
ssrt += r.total_sig_count;
}
mainPr.ln(String.format("SSR candidates: %d/%d (%.2f%%)",
ssrc, ssrt, 100. * ssrc / ssrt));
}
mainPr.ln();
return cr;
......@@ -198,8 +211,13 @@ public final class MainCLI {
return fr;
}
if (o.ssr) // if we're in SSR mode
return detectRemovableSigs(world);
if (o.ssr) { // if we're in SSR mode
SSRResult r = detectRemovableSigs(world);
fr.module_results.add(r);
mainPr.ln(progress + "done: " + fr.file_name);
pr.close();
return fr;
}
if (moduleHasCommands(world)) {
......@@ -211,7 +229,7 @@ public final class MainCLI {
pr.lnd(" running...");
try {
fr.module_results.add(analyzeModule(pr, world, ModuleKind.ORIGINAL));
fr.module_results.add(mutModule(pr, world, MutKind.ORIGINAL));
} catch (Err e) {
String msg = "Error while analyzing original module. Stack trace from the exception:",
err = e.dump();
......@@ -235,7 +253,7 @@ public final class MainCLI {
pr.lnd(" running...");
try {
fr.module_results.add(analyzeModule(pr, world, ModuleKind.MUT_RANDOM));
fr.module_results.add(mutModule(pr, world, MutKind.MUT_RANDOM));
} catch (Err e) {
String msg = "Error while analyzing mutation. Stack trace from the exception:",
err = e.dump();
......@@ -264,12 +282,15 @@ public final class MainCLI {
return fr;
}
private FileResult detectRemovableSigs(CompModule world) {
private SSRResult detectRemovableSigs(CompModule world) {
SSRVisitor v = new SSRVisitor();
world.visitExpressions(v);
System.out.println("SSR candidates: " + v.candidates);
System.out.println();
return null; // TODO: return non-null FileResult ?
SSRResult r = new SSRResult();
r.total_sig_count = v.candidates.size();
r.ssr_candidate_count = Collections.frequency(v.candidates.values(), true);
// System.out.println("SSR candidates: " + v.candidates);
// System.out.println();
return r;
}
private static boolean moduleHasCommands(CompModule module) {
......@@ -296,8 +317,8 @@ public final class MainCLI {
}
}
private ModuleResult analyzeModule(Printer pr, CompModule module, ModuleKind kind) throws Err {
ModuleResult mr = new ModuleResult();
private MutResult mutModule(Printer pr, CompModule module, MutKind kind) throws Err {
MutResult mr = new MutResult();
mr.kind = kind;
mr.runs = Collections.synchronizedList(new ArrayList<Run>());
......
......@@ -36,8 +36,15 @@ class FileResult {
public List<ParseOrTypeError> error;
}
class ModuleResult {
ModuleKind kind;
abstract class ModuleResult {}
class SSRResult extends ModuleResult {
public long total_sig_count;
public long ssr_candidate_count;
}
class MutResult extends ModuleResult {
MutKind kind;
List<Run> runs;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment