Verified Commit c176b3f1 authored by Amin Bandali's avatar Amin Bandali
Browse files

Add Gson and pick up json serialization work

parent 433c57b0
......@@ -55,6 +55,11 @@
<artifactId>picocli</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
</project>
......@@ -24,4 +24,5 @@ Main-Class: org.aminb.alloy.catalyst.MainCLI
@${repo;org.alloytools.kodkod.nativesat.x86-windows}, \
@${repo;org.sat4j.core}, \
@${repo;info.picocli:picocli}, \
@${repo;com.google.gson}, \
LICENSES
......@@ -11,7 +11,8 @@ Main-Class: org.aminb.alloy.catalyst.MainCLI
com.github.dpaukov:combinatoricslib3,\
org.kohsuke:github-api,\
org.apache.commons.codec;version=1.11,\
info.picocli:picocli
info.picocli:picocli,\
com.google.gson
Private-Package: \
org.aminb.alloy.catalyst,\
......
......@@ -28,6 +28,9 @@ import edu.mit.csail.sdg.translator.A4Options;
import edu.mit.csail.sdg.translator.A4Options.SatSolver;
import edu.mit.csail.sdg.translator.TranslateAlloyToKodkod;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
enum Solver {
minisat(SatSolver.MiniSatJNI),
......@@ -55,6 +58,7 @@ enum SolverResult {
public final class MainCLI {
private Options o;
private Result r;
private Gson gson;
private static AtomicInteger errorCount;
......@@ -67,6 +71,7 @@ public final class MainCLI {
r = new Result();
r.options = o;
r.results = new ArrayList<CorpusResult>();
gson = new GsonBuilder().setPrettyPrinting().create();
errorCount = new AtomicInteger();
......@@ -102,6 +107,9 @@ public final class MainCLI {
pr.ln(String.format("total number of analyzed files: %d", r.total_file_count));
pr.ln(String.format("total error count: %d", r.total_error_count));
pr.ln(String.format("total elapsed time: %dms", r.total_elapsed_time));
pr.ln(gson.toJson(r));
pr.close();
}
private CorpusResult analyzeCorpus(Printer mainPr, String corpus) {
......@@ -137,14 +145,16 @@ public final class MainCLI {
corpus, cr.elapsed_time));
if (o.ssr) {
long ssrc = 0, ssrt = 0;
for (FileResult fr : cr.file_results)
for (SSRResult r : fr.ssr_results) {
ssrc += r.ssr_candidate_count;
ssrt += r.total_sig_count;
}
long ssrs = 0, ssrc = 0;
for (FileResult fr : cr.file_results) {
ssrs += fr.ssr_result.sig_count;
ssrc += fr.ssr_result.ssr_candidate_count;
}
mainPr.ln(String.format("SSR candidates: %d/%d (%.2f%%)",
ssrc, ssrt, 100. * ssrc / ssrt));
ssrc, ssrs, 100. * ssrc / ssrs));
cr.ssr_result = new SSRResult();
cr.ssr_result.sig_count = ssrs;
cr.ssr_result.ssr_candidate_count = ssrc;
}
mainPr.ln();
......@@ -155,7 +165,6 @@ public final class MainCLI {
private FileResult analyzeFile(Printer mainPr, Path p, String corpus, int index, int total) {
FileResult fr = new FileResult();
fr.file_name = p.toString();
fr.ssr_results = new ArrayList<SSRResult>();
fr.mutation_results = new ArrayList<MutationResult>();
fr.error = new ArrayList<ParseOrTypeError>();
......@@ -211,8 +220,7 @@ public final class MainCLI {
}
if (o.ssr) { // if we're in SSR mode
SSRResult r = detectRemovableSigs(world);
fr.ssr_results.add(r);
fr.ssr_result = detectRemovableSigs(world);
mainPr.ln(progress + "done: " + fr.file_name);
pr.close();
return fr;
......@@ -285,7 +293,7 @@ public final class MainCLI {
SSRVisitor v = new SSRVisitor();
world.visitExpressions(v);
SSRResult r = new SSRResult();
r.total_sig_count = v.candidates.size();
r.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();
......
......@@ -18,7 +18,7 @@ import picocli.CommandLine.Option;
mixinStandardHelpOptions = true,
showDefaultValues = true)
public class Options implements Runnable {
private MainCLI app;
private transient MainCLI app;
@Option(names = "--models-dir",
required = true,
......
......@@ -17,6 +17,7 @@ class CorpusResult {
public int file_count;
public List<FileResult> file_results;
public long elapsed_time;
public SSRResult ssr_result;
public String error;
}
......@@ -24,6 +25,7 @@ class ParseOrTypeError {
private String msg;
private boolean fatal;
public ParseOrTypeError() {}
public ParseOrTypeError(String msg, boolean fatal) {
this.msg = msg;
this.fatal = fatal;
......@@ -32,13 +34,13 @@ class ParseOrTypeError {
class FileResult {
public String file_name;
public List<SSRResult> ssr_results;
public SSRResult ssr_result;
public List<MutationResult> mutation_results;
public List<ParseOrTypeError> error;
}
class SSRResult {
public long total_sig_count;
public long sig_count;
public long ssr_candidate_count;
}
......
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