Skip to content
Snippets Groups Projects
Commit a8b04ad0 authored by dohan's avatar dohan
Browse files

translate certain TLA definitions although they are not used in the specification (e.g. GOAL)

parent b8a08a1b
No related branches found
No related tags found
No related merge requests found
...@@ -33,15 +33,14 @@ import tla2sany.semantic.SymbolNode; ...@@ -33,15 +33,14 @@ import tla2sany.semantic.SymbolNode;
import tlc2.tool.BuiltInOPs; import tlc2.tool.BuiltInOPs;
import tlc2.tool.ToolGlobals; import tlc2.tool.ToolGlobals;
public class SpecAnalyser extends BuiltInOPs implements ASTConstants, public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ToolGlobals, TranslationGlobals {
ToolGlobals, TranslationGlobals {
private OpDefNode spec; private OpDefNode spec;
private OpDefNode init; private OpDefNode init;
private OpDefNode next; private OpDefNode next;
private ArrayList<OpDefNode> invariants = new ArrayList<OpDefNode>(); private ArrayList<OpDefNode> invariants = new ArrayList<>();
private OpDefNode expressionOpdefNode; private OpDefNode expressionOpdefNode;
private Hashtable<String, SymbolNode> namingHashTable = new Hashtable<String, SymbolNode>(); private Hashtable<String, SymbolNode> namingHashTable = new Hashtable<>();
private final ModuleNode moduleNode; private final ModuleNode moduleNode;
private ExprNode nextExpr; private ExprNode nextExpr;
...@@ -57,14 +56,14 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -57,14 +56,14 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
// set of OpDefNodes which will appear in the resulting B Machine // set of OpDefNodes which will appear in the resulting B Machine
private Set<OpDefNode> usedDefinitions = new HashSet<OpDefNode>(); private Set<OpDefNode> usedDefinitions = new HashSet<OpDefNode>();
// definitions which are used for the type inference algorithm // definitions which are used for the type inference algorithm
private Hashtable<OpDefNode, FormalParamNode[]> letParams = new Hashtable<OpDefNode, FormalParamNode[]>(); private Hashtable<OpDefNode, FormalParamNode[]> letParams = new Hashtable<>();
// additional parameters of an let Operator, these parameters are from the // additional parameters of an let Operator, these parameters are from the
// surrounding operator // surrounding operator
private ArrayList<String> definitionMacros = new ArrayList<String>(); private ArrayList<String> definitionMacros = new ArrayList<>();
private ArrayList<OpDefNode> recursiveFunctions = new ArrayList<OpDefNode>(); private ArrayList<OpDefNode> recursiveFunctions = new ArrayList<>();
private ArrayList<RecursiveDefinition> recursiveDefinitions = new ArrayList<RecursiveDefinition>(); private ArrayList<RecursiveDefinition> recursiveDefinitions = new ArrayList<>();
private ConfigfileEvaluator configFileEvaluator; private ConfigfileEvaluator configFileEvaluator;
...@@ -73,8 +72,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -73,8 +72,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
this.bConstants = new ArrayList<OpDeclNode>(); this.bConstants = new ArrayList<OpDeclNode>();
} }
public static SpecAnalyser createSpecAnalyser(ModuleNode m, public static SpecAnalyser createSpecAnalyser(ModuleNode m, ConfigfileEvaluator conEval) {
ConfigfileEvaluator conEval) {
SpecAnalyser specAnalyser = new SpecAnalyser(m); SpecAnalyser specAnalyser = new SpecAnalyser(m);
specAnalyser.spec = conEval.getSpecNode(); specAnalyser.spec = conEval.getSpecNode();
specAnalyser.init = conEval.getInitNode(); specAnalyser.init = conEval.getInitNode();
...@@ -99,8 +97,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -99,8 +97,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
SpecAnalyser specAnalyser = new SpecAnalyser(m); SpecAnalyser specAnalyser = new SpecAnalyser(m);
Hashtable<String, OpDefNode> definitions = new Hashtable<String, OpDefNode>(); Hashtable<String, OpDefNode> definitions = new Hashtable<String, OpDefNode>();
for (int i = 0; i < m.getOpDefs().length; i++) { for (int i = 0; i < m.getOpDefs().length; i++) {
definitions.put(m.getOpDefs()[i].getName().toString(), definitions.put(m.getOpDefs()[i].getName().toString(), m.getOpDefs()[i]);
m.getOpDefs()[i]);
} }
specAnalyser.spec = definitions.get("Spec"); specAnalyser.spec = definitions.get("Spec");
specAnalyser.init = definitions.get("Init"); specAnalyser.init = definitions.get("Init");
...@@ -115,8 +112,8 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -115,8 +112,8 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
return specAnalyser; return specAnalyser;
} }
public void start() throws SemanticErrorException, FrontEndException, public void start()
ConfigFileErrorException, NotImplementedException { throws SemanticErrorException, FrontEndException, ConfigFileErrorException, NotImplementedException {
if (spec != null) { if (spec != null) {
evalSpec(); evalSpec();
...@@ -131,8 +128,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -131,8 +128,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
OpDefNode opDefNode = (OpDefNode) opApplNode.getOperator(); OpDefNode opDefNode = (OpDefNode) opApplNode.getOperator();
if (opDefNode.getKind() == UserDefinedOpKind if (opDefNode.getKind() == UserDefinedOpKind && !BBuiltInOPs.contains(opDefNode.getName())) {
&& !BBuiltInOPs.contains(opDefNode.getName())) {
int i = invariants.indexOf(inv); int i = invariants.indexOf(inv);
invariants.set(i, opDefNode); invariants.set(i, opDefNode);
} }
...@@ -160,9 +156,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -160,9 +156,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
OpDeclNode con = bConstants.get(i); OpDeclNode con = bConstants.get(i);
if (con.getArity() > 0) { if (con.getArity() > 0) {
throw new ConfigFileErrorException( throw new ConfigFileErrorException(
String.format( String.format("Constant '%s' must be overriden in the configuration file.", con.getName()));
"Constant '%s' must be overriden in the configuration file.",
con.getName()));
} }
} }
findRecursiveConstructs(); findRecursiveConstructs();
...@@ -198,8 +192,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -198,8 +192,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
} }
private void processConfigSpec(ExprNode exprNode) private void processConfigSpec(ExprNode exprNode) throws SemanticErrorException, FrontEndException {
throws SemanticErrorException, FrontEndException {
if (exprNode instanceof OpApplNode) { if (exprNode instanceof OpApplNode) {
OpApplNode opApp = (OpApplNode) exprNode; OpApplNode opApp = (OpApplNode) exprNode;
...@@ -217,8 +210,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -217,8 +210,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
} }
return; return;
} }
throw new SemanticErrorException( throw new SemanticErrorException("Can not handle specification conjunction.");
"Can not handle specification conjunction.");
} }
int opcode = BuiltInOPs.getOpCode(opApp.getOperator().getName()); int opcode = BuiltInOPs.getOpCode(opApp.getOperator().getName());
...@@ -232,8 +224,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -232,8 +224,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
if (opcode == OPCODE_box) { if (opcode == OPCODE_box) {
SemanticNode boxArg = args[0]; SemanticNode boxArg = args[0];
if ((boxArg instanceof OpApplNode) if ((boxArg instanceof OpApplNode)
&& BuiltInOPs.getOpCode(((OpApplNode) boxArg) && BuiltInOPs.getOpCode(((OpApplNode) boxArg).getOperator().getName()) == OPCODE_sa) {
.getOperator().getName()) == OPCODE_sa) {
ExprNode next = (ExprNode) ((OpApplNode) boxArg).getArgs()[0]; ExprNode next = (ExprNode) ((OpApplNode) boxArg).getArgs()[0];
this.nextExpr = next; this.nextExpr = next;
return; return;
...@@ -247,8 +238,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -247,8 +238,7 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
// temporal // temporal
} else { } else {
throw new SemanticErrorException( throw new SemanticErrorException("Can not handle specification conjunction.");
"Can not handle specification conjunction.");
} }
} }
...@@ -257,8 +247,8 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants, ...@@ -257,8 +247,8 @@ public class SpecAnalyser extends BuiltInOPs implements ASTConstants,
Set<OpDefNode> set = new HashSet<OpDefNode>(usedDefinitions); Set<OpDefNode> set = new HashSet<OpDefNode>(usedDefinitions);
for (OpDefNode def : set) { for (OpDefNode def : set) {
if (def.getInRecursive()) { if (def.getInRecursive()) {
throw new NotImplementedException( throw new NotImplementedException("Recursive definitions are currently not supported: " + def.getName()
"Recursive definitions are currently not supported: " + def.getName() + "\n" + def.getLocation() ); + "\n" + def.getLocation());
// bDefinitionsSet.remove(def); // bDefinitionsSet.remove(def);
// RecursiveDefinition rd = new RecursiveDefinition(def); // RecursiveDefinition rd = new RecursiveDefinition(def);
// recursiveDefinitions.add(rd); // recursiveDefinitions.add(rd);
......
...@@ -13,22 +13,18 @@ import de.tla2b.analysis.SpecAnalyser; ...@@ -13,22 +13,18 @@ import de.tla2b.analysis.SpecAnalyser;
import de.tla2b.global.BBuiltInOPs; import de.tla2b.global.BBuiltInOPs;
import de.tla2b.global.TranslationGlobals; import de.tla2b.global.TranslationGlobals;
public class UsedDefinitionsFinder extends AbstractASTVisitor implements public class UsedDefinitionsFinder extends AbstractASTVisitor implements ASTConstants, ToolGlobals, TranslationGlobals {
ASTConstants, ToolGlobals, TranslationGlobals {
private final HashSet<OpDefNode> usedDefinitions = new HashSet<OpDefNode>();
private final HashSet<OpDefNode> usedDefinitions = new HashSet<>();
public UsedDefinitionsFinder(SpecAnalyser specAnalyser) { public UsedDefinitionsFinder(SpecAnalyser specAnalyser) {
if (specAnalyser.getConfigFileEvaluator() != null) { if (specAnalyser.getConfigFileEvaluator() != null) {
Collection<OpDefNode> cons = specAnalyser.getConfigFileEvaluator() Collection<OpDefNode> cons = specAnalyser.getConfigFileEvaluator().getConstantOverrideTable().values();
.getConstantOverrideTable().values();
for (OpDefNode def : cons) { for (OpDefNode def : cons) {
visitExprNode(def.getBody()); visitExprNode(def.getBody());
} }
Collection<OpDefNode> ops = specAnalyser.getConfigFileEvaluator() Collection<OpDefNode> ops = specAnalyser.getConfigFileEvaluator().getOperatorOverrideTable().values();
.getOperatorOverrideTable().values();
for (OpDefNode def : cons) { for (OpDefNode def : cons) {
visitExprNode(def.getBody()); visitExprNode(def.getBody());
} }
...@@ -59,6 +55,15 @@ public class UsedDefinitionsFinder extends AbstractASTVisitor implements ...@@ -59,6 +55,15 @@ public class UsedDefinitionsFinder extends AbstractASTVisitor implements
visitExprNode(def.getBody()); visitExprNode(def.getBody());
} }
} }
for (OpDefNode opDef : specAnalyser.getModuleNode().getOpDefs()) {
String defName = opDef.getName().toString();
// GOAL, ANIMATION_FUNCTION, ANIMATION_IMGxx, SET_PREF_xxx,
if (defName.equals("GOAL") || defName.startsWith("ANIMATION_FUNCTION")
|| defName.startsWith("ANIMATION_IMG") || defName.startsWith("SET_PREF_")) {
usedDefinitions.add(opDef);
}
}
} }
public HashSet<OpDefNode> getUsedDefinitions() { public HashSet<OpDefNode> getUsedDefinitions() {
...@@ -70,15 +75,12 @@ public class UsedDefinitionsFinder extends AbstractASTVisitor implements ...@@ -70,15 +75,12 @@ public class UsedDefinitionsFinder extends AbstractASTVisitor implements
super.visitUserDefinedNode(n); super.visitUserDefinedNode(n);
OpDefNode def = (OpDefNode) n.getOperator(); OpDefNode def = (OpDefNode) n.getOperator();
ModuleNode moduleNode = def.getSource() ModuleNode moduleNode = def.getSource().getOriginallyDefinedInModuleNode();
.getOriginallyDefinedInModuleNode();
if (moduleNode.getName().toString().equals("TLA2B")) { if (moduleNode.getName().toString().equals("TLA2B")) {
return; return;
} }
if (BBuiltInOPs.contains(def.getName()) if (BBuiltInOPs.contains(def.getName())
&& STANDARD_MODULES.contains(def.getSource() && STANDARD_MODULES.contains(def.getSource().getOriginallyDefinedInModuleNode().getName().toString())) {
.getOriginallyDefinedInModuleNode().getName()
.toString())) {
return; return;
} }
if (usedDefinitions.add(def)) { if (usedDefinitions.add(def)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment