Skip to content

Commit 7ef6698

Browse files
authored
[fix] Use local variables for assume statements (#870)
1 parent 8bd9b88 commit 7ef6698

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Src/PCompiler/CompilerCore/Backend/PVerifier/Uclid5CodeGenerator.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ private void EmitLine(string str)
569569
private static string StateAdtReceivedSelector => $"{StateAdt}_Received";
570570
private static string StateAdtMachinesSelector => $"{StateAdt}_Machines";
571571

572+
private static bool useLocalPrefix = false;
573+
572574
private static string StateAdtConstruct(string sent, string received, string machines)
573575
{
574576
return
@@ -598,7 +600,7 @@ private static string StateAdtDeclaration()
598600

599601
private static string InFlight(string state, string action)
600602
{
601-
return $"({StateAdtSelectSent(state)}[{action}] && !{StateAdtSelectReceived(state)}[{action}])";
603+
return useLocalPrefix ? $"({LocalPrefix}sent[{action}] && !{StateAdtSelectReceived(state)}[{action}])" : $"({StateAdtSelectSent(state)}[{action}] && !{StateAdtSelectReceived(state)}[{action}])";
602604
}
603605

604606
private static string StateVar => $"{BuiltinPrefix}State";
@@ -1024,7 +1026,9 @@ private void GenerateSpecProcedures(List<Machine> specs, List<Invariant> goals,
10241026
foreach (var v in spec.Fields)
10251027
EmitLine($"{GetLocalName(v)} = {SpecPrefix}{spec.Name}_{v.Name};");
10261028

1029+
useLocalPrefix = true;
10271030
GenerateStmt(f.Body, spec, goals, generateSanityChecks);
1031+
useLocalPrefix = false;
10281032

10291033
// update the global variables
10301034
EmitLine($"{SpecPrefix}{spec.Name}_State = {LocalPrefix}state;");
@@ -1406,7 +1410,9 @@ private void GenerateMachineProcedures(Machine m, List<Invariant> goals, bool ge
14061410
EmitLine($"{GetLocalName(v)} = {MachineStateAdtSelectField(currState, m, v)};");
14071411
// foreach (var v in f.LocalVariables) EmitLine($"{GetLocalName(v)} = {DefaultValue(v.Type)};");
14081412

1413+
useLocalPrefix = true;
14091414
GenerateStmt(f.Body, null, goals, generateSanityChecks);
1415+
useLocalPrefix = false;
14101416

14111417
var fields = m.Fields.Select(GetLocalName).Prepend($"{LocalPrefix}state").ToList();
14121418

@@ -2042,7 +2048,7 @@ ContainsExpr cexp when cexp.Collection.Type.Canonicalize() is SetType =>
20422048
s), // must deref for ADT!
20432049
PureCallExpr pexpr => $"{pexpr.Pure.Name}({string.Join(", ", pexpr.Arguments.Select(ExprToString))})",
20442050
FlyingExpr fexpr => $"{InFlight(StateVar, ExprToString(fexpr.Instance))}",
2045-
SentExpr sexpr => $"{StateAdtSelectSent(StateVar)}[{ExprToString(sexpr.Instance)}]",
2051+
SentExpr sexpr => useLocalPrefix ? $"{LocalPrefix}sent[{ExprToString(sexpr.Instance)}]" : $"{StateAdtSelectSent(StateVar)}[{ExprToString(sexpr.Instance)}]",
20462052
TargetsExpr texpr =>
20472053
$"({LabelAdtSelectTarget(ExprToString(texpr.Instance))} == {ExprToString(texpr.Target)})",
20482054
_ => throw new NotSupportedException($"Not supported expr ({expr}) at {GetLocation(expr)}")

0 commit comments

Comments
 (0)