Skip to content
Snippets Groups Projects
Commit fc2af107 authored by hansen's avatar hansen
Browse files

fixed constants setup in trace file

parent 159dcd05
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ dependencies { ...@@ -37,7 +37,7 @@ dependencies {
testCompile (group: 'junit', name: 'junit', version: '4.7') testCompile (group: 'junit', name: 'junit', version: '4.7')
testCompile (group: 'de.prob', name: 'tla2b', version: '1.0.4-SNAPSHOT') testCompile (group: 'de.prob', name: 'tla2b', version: '1.0.4-SNAPSHOT')
testCompile (group: 'de.prob', name: 'tla2bAST', version: '1.0.0-SNAPSHOT')
releaseJars (group: 'de.tla', name: 'tlatools', version: '1.0.0-SNAPSHOT') releaseJars (group: 'de.tla', name: 'tlatools', version: '1.0.0-SNAPSHOT')
releaseJars (group: 'de.prob', name: 'prologlib', version: parser_version) releaseJars (group: 'de.prob', name: 'prologlib', version: parser_version)
......
...@@ -7,6 +7,7 @@ import de.tlc4b.btypes.FunctionType; ...@@ -7,6 +7,7 @@ import de.tlc4b.btypes.FunctionType;
import de.tlc4b.btypes.PairType; import de.tlc4b.btypes.PairType;
import de.tlc4b.btypes.SetType; import de.tlc4b.btypes.SetType;
import de.tlc4b.btypes.StructType; import de.tlc4b.btypes.StructType;
import tla2sany.semantic.OpDeclNode;
import tlc2.tool.TLCState; import tlc2.tool.TLCState;
import tlc2.tool.TLCStateInfo; import tlc2.tool.TLCStateInfo;
import tlc2.value.FcnLambdaValue; import tlc2.value.FcnLambdaValue;
...@@ -38,6 +39,9 @@ public class TracePrinter { ...@@ -38,6 +39,9 @@ public class TracePrinter {
TLCState initialState; TLCState initialState;
TLCOutputInfo tlcOutputInfo; TLCOutputInfo tlcOutputInfo;
ArrayList<OpDeclNode> constants;
ArrayList<OpDeclNode> variables;
StringBuilder traceBuilder; StringBuilder traceBuilder;
public TracePrinter(ArrayList<TLCStateInfo> trace, public TracePrinter(ArrayList<TLCStateInfo> trace,
...@@ -45,9 +49,19 @@ public class TracePrinter { ...@@ -45,9 +49,19 @@ public class TracePrinter {
this.trace = trace; this.trace = trace;
this.tlcOutputInfo = tlcOutputInfo; this.tlcOutputInfo = tlcOutputInfo;
evalTrace(); constants = new ArrayList<OpDeclNode>();
variables = new ArrayList<OpDeclNode>();
for (int i = 0; i < TLCState.vars.length; i++) {
String id = TLCState.vars[i].getName().toString();
if (tlcOutputInfo.constants.contains(id)) {
constants.add(TLCState.vars[i]);
} else {
variables.add(TLCState.vars[i]);
}
} }
evalTrace();
}
public TracePrinter(TLCState initialState, TLCOutputInfo tlcOutputInfo) { public TracePrinter(TLCState initialState, TLCOutputInfo tlcOutputInfo) {
this.initialState = initialState; this.initialState = initialState;
...@@ -59,11 +73,11 @@ public class TracePrinter { ...@@ -59,11 +73,11 @@ public class TracePrinter {
return traceBuilder; return traceBuilder;
} }
private void evalTrace() { private void evalTrace() {
traceBuilder = new StringBuilder(); traceBuilder = new StringBuilder();
if (trace != null) { if (trace != null) {
traceBuilder.append(setupConstants(trace.get(0).state));
for (int i = 0; i < trace.size(); i++) { for (int i = 0; i < trace.size(); i++) {
if (i > 0) { if (i > 0) {
traceBuilder.append("\n"); traceBuilder.append("\n");
...@@ -71,20 +85,43 @@ public class TracePrinter { ...@@ -71,20 +85,43 @@ public class TracePrinter {
traceBuilder.append(evalExpression(trace.get(i).state)); traceBuilder.append(evalExpression(trace.get(i).state));
} }
} else { } else {
traceBuilder.append(setupConstants(initialState));
traceBuilder.append(evalExpression(initialState)); traceBuilder.append(evalExpression(initialState));
} }
// System.out.println(traceBuilder); // System.out.println(traceBuilder);
} }
private StringBuilder setupConstants(TLCState state) {
StringBuilder expression = new StringBuilder();
if (tlcOutputInfo.constantSetup) {
if(constants.size() == 0){
expression.append("1 = 1");
}else{
for (int i = 0; i < constants.size(); i++) {
if (i > 0) {
expression.append(" & ");
}
UniqueString var = constants.get(i).getName();
BType type = tlcOutputInfo.getBType(var.toString());
String value = parseValue(state.lookup(var), type)
.toString();
expression.append(var).append(" = ").append(value);
}
}
expression.append("\n");
}
return expression;
}
private StringBuilder evalExpression(TLCState state) { private StringBuilder evalExpression(TLCState state) {
StringBuilder expression = new StringBuilder(); StringBuilder expression = new StringBuilder();
for (int i = 0; i < TLCState.vars.length; i++) { for (int i = 0; i < variables.size(); i++) {
if (i > 0) { if (i > 0) {
expression.append(" & "); expression.append(" & ");
} }
UniqueString var = TLCState.vars[i].getName(); UniqueString var = variables.get(i).getName();
BType type = tlcOutputInfo.getBType(var.toString()); BType type = tlcOutputInfo.getBType(var.toString());
String value = parseValue(state.lookup(var), type).toString(); String value = parseValue(state.lookup(var), type).toString();
expression.append(var).append(" = ").append(value); expression.append(var).append(" = ").append(value);
...@@ -154,7 +191,6 @@ public class TracePrinter { ...@@ -154,7 +191,6 @@ public class TracePrinter {
return res; return res;
} }
case FCNRCDVALUE: case FCNRCDVALUE:
FcnRcdValue function = (FcnRcdValue) val; FcnRcdValue function = (FcnRcdValue) val;
FunctionType funcType = (FunctionType) type; FunctionType funcType = (FunctionType) type;
...@@ -214,7 +250,8 @@ public class TracePrinter { ...@@ -214,7 +250,8 @@ public class TracePrinter {
case SUBSETVALUE: { case SUBSETVALUE: {
SubsetValue s = (SubsetValue) val; SubsetValue s = (SubsetValue) val;
SetType t = (SetType) type; SetType t = (SetType) type;
res.append("POW(").append(parseValue(s.set, t.getSubtype())).append(")"); res.append("POW(").append(parseValue(s.set, t.getSubtype()))
.append(")");
return res; return res;
} }
case UNIONVALUE: { case UNIONVALUE: {
...@@ -279,7 +316,6 @@ public class TracePrinter { ...@@ -279,7 +316,6 @@ public class TracePrinter {
return res; return res;
} }
} }
System.err.println("Type: " + val.getKind()); System.err.println("Type: " + val.getKind());
throw new RuntimeException("not supported construct: " + val); throw new RuntimeException("not supported construct: " + val);
......
...@@ -29,8 +29,8 @@ public class Testing2 extends AbstractParseMachineTest{ ...@@ -29,8 +29,8 @@ public class Testing2 extends AbstractParseMachineTest{
@Test @Test
public void testRunTLC() throws Exception { public void testRunTLC() throws Exception {
String[] a = new String[] {machine.getPath()}; String[] a = new String[] {machine.getPath()};
//TLC4B.main(a); TLC4B.main(a);
TLC4B.test(a,false); //TLC4B.test(a,false);
} }
@Config @Config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment