Skip to content
Snippets Groups Projects
Commit 2e7d2fca authored by Jan Gruteser's avatar Jan Gruteser
Browse files

simplify Translator

parent b000185c
No related branches found
No related tags found
No related merge requests found
Pipeline #144890 passed
......@@ -39,15 +39,10 @@ import java.util.List;
import java.util.stream.Collectors;
public class Translator implements TranslationGlobals {
private String moduleFileName;
private String parentPath;
private File moduleFile;
private File configFile;
private List<File> moduleFiles = new ArrayList<>();
private Start BAst;
private Map<Node, TLAType> types;
private Definitions bDefinitions;
private BAstCreator bAstCreator;
......@@ -59,8 +54,6 @@ public class Translator implements TranslationGlobals {
private TypeChecker typechecker;
public Translator(String moduleFileName) throws TLA2BFrontEndException {
this.moduleFileName = moduleFileName;
this.moduleFile = new File(moduleFileName);
if (!moduleFile.exists()) {
throw new RuntimeException("Can not find module file: '" + moduleFileName + "'");
......@@ -119,7 +112,6 @@ public class Translator implements TranslationGlobals {
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(moduleFile.toPath()), StandardCharsets.UTF_8))) {
out.write(moduleString);
}
moduleFileName = moduleFile.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
......@@ -212,11 +204,9 @@ public class Translator implements TranslationGlobals {
new BMacroHandler(specAnalyser, conEval),
new RecursiveFunctionHandler(specAnalyser));
this.types = bAstCreator.getTypes();
this.bDefinitions = bAstCreator.getBDefinitions();
this.moduleFiles = bAstCreator.getFilesOrderedById().stream()
.map(file -> new File(parentPath, file + ".tla")).collect(Collectors.toList());
return this.BAst = bAstCreator.getStartNode();
return getBAST();
}
public void createProbFile() {
......@@ -249,15 +239,12 @@ public class Translator implements TranslationGlobals {
}
public void createMachineFile() {
String bFile = FileUtils.removeExtension(moduleFile.getAbsolutePath());
bFile = bFile + "_tla.txt";
String bFile = FileUtils.removeExtension(moduleFile.getAbsolutePath()) + "_tla.txt";
File machineFile;
machineFile = new File(bFile);
File machineFile = new File(bFile);
if (machineFile.exists()) {
try {
BufferedReader in;
in = new BufferedReader(new FileReader(machineFile));
BufferedReader in = new BufferedReader(new FileReader(machineFile));
String firstLine = in.readLine();
in.close();
if (firstLine != null && !firstLine.startsWith("/*@ generated by TLA2B ")) {
......@@ -280,7 +267,7 @@ public class Translator implements TranslationGlobals {
PrettyPrinter pp = new PrettyPrinter();
pp.setRenaming(new SuffixIdentifierRenaming());
BAst.apply(pp);
getBAST().apply(pp);
String result = "/*@ generated by TLA2B " + VERSION_NUMBER + " */\n" + pp.getPrettyPrint();
try {
......@@ -336,7 +323,7 @@ public class Translator implements TranslationGlobals {
}
public Definitions getBDefinitions() {
return bDefinitions;
return bAstCreator.getBDefinitions();
}
public ModuleNode getModuleNode() {
......@@ -352,7 +339,7 @@ public class Translator implements TranslationGlobals {
}
public Start getBAST() {
return BAst;
return bAstCreator.getStartNode();
}
public File getModuleFile() {
......@@ -364,7 +351,7 @@ public class Translator implements TranslationGlobals {
}
public Map<Node, TLAType> getTypes() {
return this.types;
return bAstCreator.getTypes();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment