Skip to content

Commit

Permalink
Fix contract and usages of LabelOrCmd in parser (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkragl authored Sep 7, 2020
1 parent b083fb1 commit bae82d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
16 changes: 7 additions & 9 deletions Source/Core/BoogiePL.atg
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,14 @@ StmtList<out StmtList/*!*/ stmtList>

{
( LabelOrCmd<out c, out label>
(. if (c != null) {
(. Contract.Assert(c == null || label == null);
if (c != null) {
// LabelOrCmd read a Cmd
Contract.Assert(label == null);
if (startToken == null) { startToken = c.tok; cs = new List<Cmd>(); }
Contract.Assert(cs != null);
cs.Add(c);
} else {
} else if (label != null) {
// LabelOrCmd read a label
Contract.Assert(label != null);
if (startToken != null) {
Contract.Assert(cs != null);
// dump the built-up state into a BigBlock
Expand Down Expand Up @@ -854,7 +853,7 @@ BreakCmd<out BreakCmd/*!*/ bcmd>
/*------------------------------------------------------------------------*/

LabelOrCmd<out Cmd c, out IToken label>
/* ensures (c == null) != (label != null) */
/* ensures (c == null) || (label == null) */
= (. IToken/*!*/ x; Expr/*!*/ e;
List<IToken>/*!*/ xs;
List<IdentifierExpr> ids;
Expand Down Expand Up @@ -1362,11 +1361,10 @@ SpecBlock<out Block/*!*/ b>
.)
Ident<out x> ":"
{ LabelOrCmd<out c, out label>
(. if (c != null) {
Contract.Assert(label == null);
(. Contract.Assert(c == null || label == null);
if (c != null) {
cs.Add(c);
} else {
Contract.Assert(label != null);
} else if (label != null) {
SemErr("SpecBlock's can only have one label");
}
.)
Expand Down
10 changes: 4 additions & 6 deletions Source/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,15 +952,14 @@ void StmtList(out StmtList/*!*/ stmtList) {
while (StartOf(7)) {
if (StartOf(8)) {
LabelOrCmd(out c, out label);
Contract.Assert(c == null || label == null);
if (c != null) {
// LabelOrCmd read a Cmd
Contract.Assert(label == null);
if (startToken == null) { startToken = c.tok; cs = new List<Cmd>(); }
Contract.Assert(cs != null);
cs.Add(c);
} else {
} else if (label != null) {
// LabelOrCmd read a label
Contract.Assert(label != null);
if (startToken != null) {
Contract.Assert(cs != null);
// dump the built-up state into a BigBlock
Expand Down Expand Up @@ -2082,11 +2081,10 @@ void SpecBlock(out Block/*!*/ b) {
Expect(12);
while (StartOf(8)) {
LabelOrCmd(out c, out label);
Contract.Assert(c == null || label == null);
if (c != null) {
Contract.Assert(label == null);
cs.Add(c);
} else {
Contract.Assert(label != null);
} else if (label != null) {
SemErr("SpecBlock's can only have one label");
}

Expand Down

0 comments on commit bae82d3

Please sign in to comment.