Verified Commit 67ff9605 authored by Amin Bandali's avatar Amin Bandali
Browse files

Mark vars as transient to avoid sending Gson into infinite loop

Because they reference resultsDir
parent 24d8b6f3
package org.aminb.alloy.catalyst; package org.aminb.alloy.catalyst;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
...@@ -78,7 +77,7 @@ public abstract class CatalystCommand { ...@@ -78,7 +77,7 @@ public abstract class CatalystCommand {
wjson = setupWriter(outputJsonFile, true); wjson = setupWriter(outputJsonFile, true);
ptxt = new PrintWriter(wtxt); ptxt = new PrintWriter(wtxt);
} }
abstract protected CorpusResult analyzeCorpus(String corpus); abstract protected CorpusResult analyzeCorpus(String corpus);
abstract protected FileResult analyzeFile(String corpus, Path p, int index, int total); abstract protected FileResult analyzeFile(String corpus, Path p, int index, int total);
...@@ -101,7 +100,7 @@ public abstract class CatalystCommand { ...@@ -101,7 +100,7 @@ public abstract class CatalystCommand {
} }
protected void p(String s) { protected void p(String s) {
System.out.println(s); System.out.print(s);
ptxt.print(s); ptxt.print(s);
} }
......
package org.aminb.alloy.catalyst; package org.aminb.alloy.catalyst;
import java.io.FileNotFoundException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -16,6 +15,8 @@ import java.util.stream.Collectors; ...@@ -16,6 +15,8 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.gson.GsonBuilder;
import edu.mit.csail.sdg.alloy4.A4Reporter; import edu.mit.csail.sdg.alloy4.A4Reporter;
import edu.mit.csail.sdg.alloy4.ConstList; import edu.mit.csail.sdg.alloy4.ConstList;
import edu.mit.csail.sdg.alloy4.Err; import edu.mit.csail.sdg.alloy4.Err;
...@@ -27,9 +28,6 @@ import edu.mit.csail.sdg.parser.CompUtil; ...@@ -27,9 +28,6 @@ import edu.mit.csail.sdg.parser.CompUtil;
import edu.mit.csail.sdg.translator.A4Options; import edu.mit.csail.sdg.translator.A4Options;
import edu.mit.csail.sdg.translator.A4Options.SatSolver; import edu.mit.csail.sdg.translator.A4Options.SatSolver;
import edu.mit.csail.sdg.translator.TranslateAlloyToKodkod; import edu.mit.csail.sdg.translator.TranslateAlloyToKodkod;
import com.google.gson.GsonBuilder;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
import picocli.CommandLine.Option; import picocli.CommandLine.Option;
...@@ -63,8 +61,8 @@ public final class Mut extends CatalystCommand implements Runnable { ...@@ -63,8 +61,8 @@ public final class Mut extends CatalystCommand implements Runnable {
description = "Number of mutations to generate per Alloy file") description = "Number of mutations to generate per Alloy file")
protected int mutationCount = 3; protected int mutationCount = 3;
final private Path OUT_TEXT = Paths.get(resultsDir, "catalyst_mut.txt"); final transient private Path OUT_TEXT = Paths.get(resultsDir, "catalyst_mut.txt");
final private Path OUT_JSON = Paths.get(resultsDir, "catalyst_mut.json"); final transient private Path OUT_JSON = Paths.get(resultsDir, "catalyst_mut.json");
public Mut() {} public Mut() {}
......
package org.aminb.alloy.catalyst; package org.aminb.alloy.catalyst;
import java.io.FileNotFoundException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -14,23 +13,22 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -14,23 +13,22 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.google.gson.GsonBuilder;
import edu.mit.csail.sdg.alloy4.A4Reporter; import edu.mit.csail.sdg.alloy4.A4Reporter;
import edu.mit.csail.sdg.alloy4.Err; import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.ErrorWarning; import edu.mit.csail.sdg.alloy4.ErrorWarning;
import edu.mit.csail.sdg.alloy4.MailBug; import edu.mit.csail.sdg.alloy4.MailBug;
import edu.mit.csail.sdg.parser.CompModule; import edu.mit.csail.sdg.parser.CompModule;
import edu.mit.csail.sdg.parser.CompUtil; import edu.mit.csail.sdg.parser.CompUtil;
import com.google.gson.GsonBuilder;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
@Command(name = "ssr", description = "Structure Signature Removal mode") @Command(name = "ssr", description = "Structure Signature Removal mode")
public final class SSR extends CatalystCommand implements Runnable { public final class SSR extends CatalystCommand implements Runnable {
public SSR() {} public SSR() {}
final private Path OUT_TEXT = Paths.get(resultsDir, "catalyst_ssr.txt"); final transient private Path OUT_TEXT = Paths.get(resultsDir, "catalyst_ssr.txt");
final private Path OUT_JSON = Paths.get(resultsDir, "catalyst_ssr.json"); final transient private Path OUT_JSON = Paths.get(resultsDir, "catalyst_ssr.json");
public void run() { public void run() {
initialize(OUT_TEXT, OUT_JSON); initialize(OUT_TEXT, OUT_JSON);
......
package org.aminb.alloy.catalyst; package org.aminb.alloy.catalyst;
import java.util.Map; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.Arrays; import java.util.Map;
import java.util.Set;
import edu.mit.csail.sdg.alloy4.Pos; import edu.mit.csail.sdg.alloy4.Pos;
import edu.mit.csail.sdg.ast.Decl; import edu.mit.csail.sdg.ast.Decl;
...@@ -21,8 +21,8 @@ import edu.mit.csail.sdg.ast.ExprQt; ...@@ -21,8 +21,8 @@ import edu.mit.csail.sdg.ast.ExprQt;
import edu.mit.csail.sdg.ast.ExprUnary; import edu.mit.csail.sdg.ast.ExprUnary;
import edu.mit.csail.sdg.ast.ExprVar; import edu.mit.csail.sdg.ast.ExprVar;
import edu.mit.csail.sdg.ast.Sig; import edu.mit.csail.sdg.ast.Sig;
import edu.mit.csail.sdg.ast.Sig.PrimSig;
import edu.mit.csail.sdg.ast.Sig.Field; import edu.mit.csail.sdg.ast.Sig.Field;
import edu.mit.csail.sdg.ast.Sig.PrimSig;
import edu.mit.csail.sdg.ast.Type.ProductType; import edu.mit.csail.sdg.ast.Type.ProductType;
import edu.mit.csail.sdg.ast.VisitReturn; import edu.mit.csail.sdg.ast.VisitReturn;
...@@ -31,7 +31,7 @@ import edu.mit.csail.sdg.ast.VisitReturn; ...@@ -31,7 +31,7 @@ import edu.mit.csail.sdg.ast.VisitReturn;
* Structure Signature Removal (SSR) Visitor * Structure Signature Removal (SSR) Visitor
*/ */
public class SSRVisitor extends VisitReturn { public class SSRVisitor extends VisitReturn<Object> {
Set<PrimSig> builtins = Set<PrimSig> builtins =
new HashSet<>(Arrays.asList(Sig.UNIV, Sig.SIGINT, Sig.SEQIDX, new HashSet<>(Arrays.asList(Sig.UNIV, Sig.SIGINT, Sig.SEQIDX,
...@@ -146,13 +146,13 @@ public class SSRVisitor extends VisitReturn { ...@@ -146,13 +146,13 @@ public class SSRVisitor extends VisitReturn {
Expr subsub = getUnarySub(getUnarySub(s)); Expr subsub = getUnarySub(getUnarySub(s));
if (subsub instanceof PrimSig) if (subsub instanceof PrimSig)
if (((PrimSig)subsub).getFieldDecls().size() > 1) if (((PrimSig)subsub).getFieldDecls().size() > 1)
if (!builtins.contains((PrimSig)subsub)) if (!builtins.contains(subsub))
candidates.put((PrimSig)subsub, false); candidates.put((PrimSig)subsub, false);
} }
} }
else if (s instanceof PrimSig) { else if (s instanceof PrimSig) {
if (((PrimSig)s).getFieldDecls().size() > 1) if (((PrimSig)s).getFieldDecls().size() > 1)
if (!builtins.contains((PrimSig)s)) if (!builtins.contains(s))
candidates.put((PrimSig)s, false); candidates.put((PrimSig)s, false);
} }
/** /**
......
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