Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tla2bAST
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
tla2bAST
Commits
26fe2558
Commit
26fe2558
authored
8 months ago
by
Jan Gruteser
Browse files
Options
Downloads
Patches
Plain Diff
simplify file creation in Translator
parent
2e7d2fca
No related branches found
No related tags found
No related merge requests found
Pipeline
#144922
passed
8 months ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/tla2bAst/Translator.java
+18
-53
18 additions, 53 deletions
src/main/java/de/tla2bAst/Translator.java
with
18 additions
and
53 deletions
src/main/java/de/tla2bAst/Translator.java
+
18
−
53
View file @
26fe2558
...
@@ -39,6 +39,8 @@ import java.util.List;
...
@@ -39,6 +39,8 @@ import java.util.List;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
public
class
Translator
implements
TranslationGlobals
{
public
class
Translator
implements
TranslationGlobals
{
private
static
final
String
GENERATED_BY_TLA2B_HEADER
=
"/*@ generated by TLA2B "
;
private
String
parentPath
;
private
String
parentPath
;
private
File
moduleFile
;
private
File
moduleFile
;
private
File
configFile
;
private
File
configFile
;
...
@@ -106,14 +108,11 @@ public class Translator implements TranslationGlobals {
...
@@ -106,14 +108,11 @@ public class Translator implements TranslationGlobals {
dir
.
mkdirs
();
dir
.
mkdirs
();
dir
.
deleteOnExit
();
dir
.
deleteOnExit
();
try
{
moduleFile
=
new
File
(
"temp/"
+
moduleName
+
".tla"
);
moduleFile
=
new
File
(
"temp/"
+
moduleName
+
".tla"
);
moduleFile
.
createNewFile
();
try
(
BufferedWriter
out
=
Files
.
newBufferedWriter
(
moduleFile
.
toPath
(),
StandardCharsets
.
UTF_8
))
{
try
(
BufferedWriter
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
Files
.
newOutputStream
(
moduleFile
.
toPath
()),
StandardCharsets
.
UTF_8
)))
{
out
.
write
(
moduleString
);
out
.
write
(
moduleString
);
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrac
e
();
System
.
err
.
println
(
"Error while writing file '"
+
moduleFile
.
getAbsolutePath
()
+
"':\n"
+
e
.
getMessag
e
()
)
;
}
}
}
}
...
@@ -121,14 +120,10 @@ public class Translator implements TranslationGlobals {
...
@@ -121,14 +120,10 @@ public class Translator implements TranslationGlobals {
modelConfig
=
null
;
modelConfig
=
null
;
if
(
configString
!=
null
)
{
if
(
configString
!=
null
)
{
configFile
=
new
File
(
"temp/"
+
moduleName
+
".cfg"
);
configFile
=
new
File
(
"temp/"
+
moduleName
+
".cfg"
);
try
{
try
(
BufferedWriter
out
=
Files
.
newBufferedWriter
(
configFile
.
toPath
(),
StandardCharsets
.
UTF_8
))
{
configFile
.
createNewFile
();
try
(
BufferedWriter
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
Files
.
newOutputStream
(
configFile
.
toPath
()),
StandardCharsets
.
UTF_8
)))
{
out
.
write
(
configString
);
out
.
write
(
configString
);
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrac
e
();
System
.
err
.
println
(
"Error while writing file '"
+
configFile
.
getAbsolutePath
()
+
"':\n"
+
e
.
getMessag
e
()
)
;
}
}
}
}
}
}
...
@@ -210,44 +205,26 @@ public class Translator implements TranslationGlobals {
...
@@ -210,44 +205,26 @@ public class Translator implements TranslationGlobals {
}
}
public
void
createProbFile
()
{
public
void
createProbFile
()
{
String
fileName
=
FileUtils
.
removeExtension
(
moduleFile
.
getAbsolutePath
());
File
probFile
=
new
File
(
FileUtils
.
removeExtension
(
moduleFile
.
getAbsolutePath
())
+
".prob"
);
fileName
=
fileName
+
".prob"
;
File
probFile
;
probFile
=
new
File
(
fileName
);
try
{
probFile
.
createNewFile
();
}
catch
(
IOException
e
)
{
System
.
err
.
printf
(
"Could not create File %s.%n"
,
probFile
.
getName
());
System
.
exit
(-
1
);
}
BParser
bParser
=
new
BParser
();
BParser
bParser
=
new
BParser
();
try
(
BufferedWriter
outWriter
=
Files
.
newBufferedWriter
(
probFile
.
toPath
(),
StandardCharsets
.
UTF_8
))
{
try
{
bParser
.
getDefinitions
().
addDefinitions
(
getBDefinitions
());
bParser
.
getDefinitions
().
addDefinitions
(
getBDefinitions
());
final
RecursiveMachineLoader
rml
=
parseAllMachines
(
getBAST
(),
getModuleFile
(),
bParser
);
final
RecursiveMachineLoader
rml
=
parseAllMachines
(
getBAST
(),
getModuleFile
(),
bParser
);
PrintWriter
outWriter
=
new
PrintWriter
(
probFile
,
"UTF-8"
);
rml
.
printAsProlog
(
new
PrologTermOutput
(
outWriter
,
false
));
rml
.
printAsProlog
(
new
PrologTermOutput
(
outWriter
,
false
));
outWriter
.
close
();
System
.
out
.
println
(
probFile
.
getAbsolutePath
()
+
" created."
);
System
.
out
.
println
(
probFile
.
getAbsolutePath
()
+
" created."
);
}
catch
(
BCompoundException
|
IOException
|
PreParseException
e
)
{
}
catch
(
BCompoundException
|
FileNotFoundException
|
PreParseException
|
UnsupportedEncodingException
e
)
{
System
.
err
.
println
(
e
.
getMessage
());
System
.
err
.
println
(
e
.
getMessage
());
System
.
exit
(-
1
);
System
.
exit
(-
1
);
}
}
}
}
public
void
createMachineFile
()
{
public
void
createMachineFile
()
{
String
bFile
=
FileUtils
.
removeExtension
(
moduleFile
.
getAbsolutePath
())
+
"_tla.txt"
;
File
machineFile
=
new
File
(
FileUtils
.
removeExtension
(
moduleFile
.
getAbsolutePath
())
+
"_tla.txt"
);
File
machineFile
=
new
File
(
bFile
);
if
(
machineFile
.
exists
())
{
if
(
machineFile
.
exists
())
{
try
{
try
(
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
machineFile
)))
{
BufferedReader
in
=
new
BufferedReader
(
new
FileReader
(
machineFile
));
String
firstLine
=
in
.
readLine
();
String
firstLine
=
in
.
readLine
();
in
.
close
();
if
(
firstLine
!=
null
&&
!
firstLine
.
startsWith
(
GENERATED_BY_TLA2B_HEADER
))
{
if
(
firstLine
!=
null
&&
!
firstLine
.
startsWith
(
"/*@ generated by TLA2B "
))
{
System
.
err
.
println
(
"Error: File "
+
machineFile
.
getName
()
+
" already exists"
System
.
err
.
println
(
"Error: File "
+
machineFile
.
getName
()
+
" already exists"
+
" and was not generated by TLA2B.\n"
+
"Delete or move this file."
);
+
" and was not generated by TLA2B.\n"
+
"Delete or move this file."
);
System
.
exit
(-
1
);
System
.
exit
(-
1
);
...
@@ -258,28 +235,16 @@ public class Translator implements TranslationGlobals {
...
@@ -258,28 +235,16 @@ public class Translator implements TranslationGlobals {
}
}
}
}
try
{
machineFile
.
createNewFile
();
}
catch
(
IOException
e
)
{
System
.
err
.
printf
(
"Could not create File %s.%n"
,
machineFile
.
getName
());
System
.
exit
(-
1
);
}
PrettyPrinter
pp
=
new
PrettyPrinter
();
PrettyPrinter
pp
=
new
PrettyPrinter
();
pp
.
setRenaming
(
new
SuffixIdentifierRenaming
());
pp
.
setRenaming
(
new
SuffixIdentifierRenaming
());
getBAST
().
apply
(
pp
);
getBAST
().
apply
(
pp
);
String
result
=
"/*@ generated by TLA2B "
+
VERSION_NUMBER
+
" */\n"
+
pp
.
getPrettyPrint
();
try
(
BufferedWriter
out
=
Files
.
newBufferedWriter
(
machineFile
.
toPath
(),
StandardCharsets
.
UTF_8
))
{
out
.
write
(
GENERATED_BY_TLA2B_HEADER
+
VERSION_NUMBER
+
" */\n"
+
pp
.
getPrettyPrint
());
try
{
try
(
BufferedWriter
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
Files
.
newOutputStream
(
machineFile
.
toPath
()),
StandardCharsets
.
UTF_8
)))
{
out
.
write
(
result
);
}
System
.
out
.
println
(
"B-Machine "
+
machineFile
.
getAbsolutePath
()
+
" created."
);
System
.
out
.
println
(
"B-Machine "
+
machineFile
.
getAbsolutePath
()
+
" created."
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Error while creating file '"
+
machineFile
.
getAbsolutePath
()
+
"'
."
);
System
.
err
.
println
(
"Error while creating file '"
+
machineFile
.
getAbsolutePath
()
+
"'
:\n"
+
e
.
getMessage
()
);
System
.
exit
(-
1
);
System
.
exit
(-
1
);
}
}
}
}
public
RecursiveMachineLoader
parseAllMachines
(
final
Start
ast
,
final
File
f
,
final
BParser
bparser
)
throws
BCompoundException
{
public
RecursiveMachineLoader
parseAllMachines
(
final
Start
ast
,
final
File
f
,
final
BParser
bparser
)
throws
BCompoundException
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment