protected override void ParseFunctionOrBlockContract(FunctionOrBlockContract contract, TokenSet followers) { this.ParseFunctionOrBlockContract(contract, followers, false, false); }
private void ParseContractMacro(FunctionOrBlockContract contract, TokenSet followers) { var keyword = this.scanner.GetIdentifierString(); var fnName = this.functionContractExtensions[keyword]; var loc = this.GetSourceLocationBuilderForLastScannedToken(); Expression name = this.GetSimpleNameFor(fnName); this.GetNextToken(); var slb = new SourceLocationBuilder(name.SourceLocation); List<Expression> parameters = new List<Expression>(); if (this.currentToken != Token.RightParenthesis) { this.ParseExpressionList(parameters, Token.Comma, false, followers | Token.RightParenthesis); } slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); if (fnName.StartsWith("\\result_macro_")) { var res = new VccReturnValue(loc); parameters.Insert(0, res); var tp = new VccTypeExpressionOf(res); name = new GenericInstanceExpression(name, new TypeExpression[] { tp }, loc); } var call = this.CheckedExpressionIfRequested(new VccMethodCall(name, parameters.AsReadOnly(), slb)); contract.AddPostcondition(new Postcondition(call, call.SourceLocation)); }
private void ParseFunctionOrBlockContract(FunctionOrBlockContract contract, TokenSet followers, bool alreadyInContract, bool savedInSpecCode) { while (this.currentToken == Token.Specification || alreadyInContract) { if (alreadyInContract) { alreadyInContract = false; } else{ savedInSpecCode = SkipIntoSpecBlock(); } while (STS.FunctionOrBlockContract[this.currentToken] || (this.currentToken == Token.Identifier && this.functionContractExtensions.ContainsKey(this.scanner.GetIdentifierString()))) { switch (this.currentToken) { case Token.SpecRequires: this.GetNextToken(); var precond = this.ParseExpression(followers | Token.RightParenthesis); precond = this.CheckedExpressionIfRequested(precond); contract.AddPrecondition(new Precondition(precond, null, precond.SourceLocation)); break; case Token.SpecEnsures: this.GetNextToken(); this.resultIsAKeyword = true; var postcond = this.ParseExpression(followers | Token.RightParenthesis); this.resultIsAKeyword = false; postcond = this.CheckedExpressionIfRequested(postcond); contract.AddPostcondition(new Postcondition(postcond, postcond.SourceLocation)); break; case Token.SpecWrites: this.GetNextToken(); var writes = this.ParseExpressionList(Token.Comma, followers | Token.RightParenthesis); contract.AddWrites(writes); break; case Token.SpecDecreases: this.GetNextToken(); var variants = this.ParseExpressionList(Token.Comma, followers | Token.RightParenthesis); contract.AddMethodVariants(variants); break; case Token.SpecReads: this.GetNextToken(); var reads = this.ParseExpressionList(Token.Comma, followers | Token.RightParenthesis); contract.AddReads(reads); break; case Token.Identifier: this.ParseContractMacro(contract, followers); break; } this.SkipSemicolonsInSpecBlock(STS.FunctionOrBlockContract | Token.RightParenthesis); } this.SkipOutOfSpecBlock(savedInSpecCode, followers | Token.Specification); } }
private Statement ParseBlockWithPureModifier(TokenSet followers, bool savedInSpecCode) { SourceLocationBuilder slb = this.GetSourceLocationBuilderForLastScannedToken(); this.GetNextToken(); this.SkipOutOfSpecBlock(savedInSpecCode, TS.StatementStart | followers); var contract = new FunctionOrBlockContract { IsPure = true }; this.ParseFunctionOrBlockContract(contract, followers, false, savedInSpecCode); Statement stmt = this.ParseStatement(followers); slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken); var blockWithContracts = new VccBlockWithContracts(new List<Statement>(1) { stmt }, slb); this.compilation.ContractProvider.AssociateMethodWithContract(blockWithContracts, contract.ToMethodContract()); return blockWithContracts; }