void WhileStmt(out Statement stmt) { Contract.Ensures(Contract.ValueAtReturn(out stmt) != null); IToken x; Expression guard = null; IToken guardEllipsis = null; List<MaybeFreeExpression> invariants = new List<MaybeFreeExpression>(); List<Expression> decreases = new List<Expression>(); Attributes decAttrs = null; Attributes modAttrs = null; List<FrameExpression> mod = null; BlockStmt body = null; IToken bodyEllipsis = null; IToken bodyStart = null, bodyEnd = null, endTok = Token.NoToken; List<GuardedAlternative> alternatives; stmt = dummyStmt; // to please the compiler bool isDirtyLoop = true; Expect(99); x = t; if (IsLoopSpec() || IsAlternative()) { while (StartOf(22)) { LoopSpec(invariants, decreases, ref mod, ref decAttrs, ref modAttrs); } AlternativeBlock(false, out alternatives, out endTok); stmt = new AlternativeLoopStmt(x, endTok, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(mod, modAttrs), alternatives); } else if (StartOf(20)) { if (StartOf(21)) { Guard(out guard); Contract.Assume(guard == null || cce.Owner.None(guard)); } else { Get(); guardEllipsis = t; } while (StartOf(22)) { LoopSpec(invariants, decreases, ref mod, ref decAttrs, ref modAttrs); } if (la.kind == _lbrace) { BlockStmt(out body, out bodyStart, out bodyEnd); endTok = body.EndTok; isDirtyLoop = false; } else if (la.kind == _ellipsis) { Expect(59); bodyEllipsis = t; endTok = t; isDirtyLoop = false; } else if (StartOf(23)) { } else SynErr(187); if (guardEllipsis != null || bodyEllipsis != null) { if (mod != null) { SemErr(mod[0].E.tok, "'modifies' clauses are not allowed on refining loops"); } if (body == null && !isDirtyLoop) { body = new BlockStmt(x, endTok, new List<Statement>()); } stmt = new WhileStmt(x, endTok, guard, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(null, null), body); stmt = new SkeletonStatement(stmt, guardEllipsis, bodyEllipsis); } else { // The following statement protects against crashes in case of parsing errors if (body == null && !isDirtyLoop) { body = new BlockStmt(x, endTok, new List<Statement>()); } stmt = new WhileStmt(x, endTok, guard, invariants, new Specification<Expression>(decreases, decAttrs), new Specification<FrameExpression>(mod, modAttrs), body); } } else SynErr(188); }
void AssumeStmt(out Statement/*!*/ s) { Contract.Ensures(Contract.ValueAtReturn(out s) != null); IToken/*!*/ x; Expression e = dummyExpr; Attributes attrs = null; IToken dotdotdot = null; Expect(31); x = t; while (IsAttribute()) { Attribute(ref attrs); } if (StartOf(7)) { Expression(out e, false, true); } else if (la.kind == 59) { Get(); dotdotdot = t; } else SynErr(181); Expect(28); if (dotdotdot != null) { s = new SkeletonStatement(new AssumeStmt(x, t, new LiteralExpr(x, true), attrs), dotdotdot, null); } else { s = new AssumeStmt(x, t, e, attrs); } }
void SkeletonStmt(out Statement s) { List<IToken> names = null; List<Expression> exprs = null; IToken tok, dotdotdot, whereTok; Expression e; Expect(59); dotdotdot = t; if (la.kind == 94) { Get(); names = new List<IToken>(); exprs = new List<Expression>(); whereTok = t; Ident(out tok); names.Add(tok); while (la.kind == 22) { Get(); Ident(out tok); names.Add(tok); } Expect(95); Expression(out e, false, true); exprs.Add(e); while (la.kind == 22) { Get(); Expression(out e, false, true); exprs.Add(e); } if (exprs.Count != names.Count) { SemErr(whereTok, exprs.Count < names.Count ? "not enough expressions" : "too many expressions"); names = null; exprs = null; } } Expect(28); s = new SkeletonStatement(dotdotdot, t, names, exprs); }
void ModifyStmt(out Statement s) { IToken tok; IToken endTok = Token.NoToken; Attributes attrs = null; FrameExpression fe; var mod = new List<FrameExpression>(); BlockStmt body = null; IToken bodyStart; IToken ellipsisToken = null; Expect(105); tok = t; while (IsAttribute()) { Attribute(ref attrs); } if (StartOf(18)) { FrameExpression(out fe, false, true); mod.Add(fe); while (la.kind == 22) { Get(); FrameExpression(out fe, false, true); mod.Add(fe); } } else if (la.kind == 59) { Get(); ellipsisToken = t; } else SynErr(193); if (la.kind == 46) { BlockStmt(out body, out bodyStart, out endTok); } else if (la.kind == 28) { while (!(la.kind == 0 || la.kind == 28)) {SynErr(194); Get();} Get(); endTok = t; } else SynErr(195); s = new ModifyStmt(tok, endTok, mod, attrs, body); if (ellipsisToken != null) { s = new SkeletonStatement(s, ellipsisToken, null); } }
void IfStmt(out Statement/*!*/ ifStmt) { Contract.Ensures(Contract.ValueAtReturn(out ifStmt) != null); IToken/*!*/ x; Expression guard = null; IToken guardEllipsis = null; bool isExistentialGuard = false; BlockStmt/*!*/ thn; BlockStmt/*!*/ bs; Statement/*!*/ s; Statement els = null; IToken bodyStart, bodyEnd, endTok; List<GuardedAlternative> alternatives; ifStmt = dummyStmt; // to please the compiler Expect(98); x = t; if (IsAlternative()) { AlternativeBlock(true, out alternatives, out endTok); ifStmt = new AlternativeStmt(x, endTok, alternatives); } else if (StartOf(20)) { if (IsExistentialGuard()) { ExistentialGuard(out guard, true); isExistentialGuard = true; } else if (StartOf(21)) { Guard(out guard); } else { Get(); guardEllipsis = t; } BlockStmt(out thn, out bodyStart, out bodyEnd); endTok = thn.EndTok; if (la.kind == 35) { Get(); if (la.kind == 98) { IfStmt(out s); els = s; endTok = s.EndTok; } else if (la.kind == 46) { BlockStmt(out bs, out bodyStart, out bodyEnd); els = bs; endTok = bs.EndTok; } else SynErr(185); } if (guardEllipsis != null) { ifStmt = new SkeletonStatement(new IfStmt(x, endTok, isExistentialGuard, guard, thn, els), guardEllipsis, null); } else { ifStmt = new IfStmt(x, endTok, isExistentialGuard, guard, thn, els); } } else SynErr(186); }
void TacnyCasesBlockStmt(out Statement/*!*/ tacnyCasesStmt, IToken x) { Contract.Ensures(Contract.ValueAtReturn(out tacnyCasesStmt) != null); Expression guard = null; IToken guardEllipsis = null; BlockStmt/*!*/ thn; Attributes attrs = null; IToken bodyStart, bodyEnd, endTok; List<GuardedAlternative> alternatives; tacnyCasesStmt = dummyStmt; // to please the compiler if(IsAlternative()) { AlternativeBlock(true, out alternatives, out endTok); tacnyCasesStmt = new AlternativeStmt(x, endTok, alternatives); } else if(StartOf(22)) { if(StartOf(23)) { Guard(out guard); } else { Get(); guardEllipsis = t; } while(IsAttribute()) { Attribute(ref attrs); } BlockStmt(out thn, out bodyStart, out bodyEnd); endTok = thn.EndTok; if(guardEllipsis != null) { tacnyCasesStmt = new SkeletonStatement(new TacnyCasesBlockStmt(x, endTok, guard, attrs, thn), guardEllipsis, null); } else { tacnyCasesStmt = new TacnyCasesBlockStmt(x, endTok, guard, attrs, thn); } } else SynErr(217); }
void AssertStmt(out Statement/*!*/ s) { Contract.Ensures(Contract.ValueAtReturn(out s) != null); IToken/*!*/ x; Expression e = dummyExpr; Attributes attrs = null; IToken dotdotdot = null; BlockStmt proof = null; IToken proofStart, proofEnd; Expect(105); x = t; while (IsAttribute()) { Attribute(ref attrs); } if (StartOf(10)) { Expression(out e, false, true); if (la.kind == 106) { Get(); BlockStmt(out proof, out proofStart, out proofEnd); } else if (la.kind == 30) { Get(); } else SynErr(198); } else if (la.kind == 63) { Get(); dotdotdot = t; Expect(30); } else SynErr(199); if (dotdotdot != null) { s = new SkeletonStatement(new AssertStmt(x, t, new LiteralExpr(x, true), null, attrs), dotdotdot, null); } else { s = new AssertStmt(x, t, e, proof, attrs); } }