Ejemplo n.º 1
0
 private Expression ParseGenericInstance(Expression expression, TokenSet followers)
   //^ requires this.currentToken == Token.LessThan;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   int position = this.scanner.CurrentDocumentPosition();
   SourceLocationBuilder slb = new SourceLocationBuilder(expression.SourceLocation);
   List<IErrorMessage> savedErrors = this.scannerAndParserErrors;
   this.scannerAndParserErrors = new List<IErrorMessage>(0);
   List<TypeExpression> argumentTypes = this.ParseTypeArguments(slb, false, followers);
   if (this.scannerAndParserErrors.Count > 0 && (argumentTypes.Count <= 1 || Parser.TypeArgumentListNonFollower[this.currentToken])) {
     //Encountered an error while trying to parse <...type args...> and there is some reason to be believe that this might not be a type argument list at all.
     //Back up the scanner and let the caller carry on as if it knew that < is the less than operator
     this.scannerAndParserErrors = savedErrors;
     this.scanner.RestoreDocumentPosition(position);
     this.currentToken = Token.None;
     this.GetNextToken();
     //^ assume this.currentToken == Token.LessThan;
     return expression;
   }
   savedErrors.AddRange(this.scannerAndParserErrors);
   this.scannerAndParserErrors = savedErrors;
   Expression result = new GenericInstanceExpression(expression, argumentTypes, slb);
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
Ejemplo n.º 2
0
 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));
 }