Esempio n. 1
0
 private Expression ParseStackalloc(TokenSet followers)
   //^ requires this.currentToken == Token.Stackalloc;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   this.GetNextToken();
   TypeExpression elementType = this.ParseBaseTypeExpression(false, followers|Token.LeftBracket);
   Token openingDelimiter = this.currentToken;
   if (this.currentToken != Token.LeftBracket) {
     this.HandleError(Error.BadStackAllocExpr);
     if (this.currentToken == Token.LeftParenthesis) this.GetNextToken();
   } else
     this.GetNextToken();
   Expression size = this.ParseExpression(followers|Token.RightBracket|Token.RightParenthesis);
   slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
   if (this.currentToken == Token.RightParenthesis && openingDelimiter == Token.LeftParenthesis)
     this.GetNextToken();
   else
     this.Skip(Token.RightBracket);
   Expression result = new CreateStackArray(elementType, size, slb);
   this.SkipTo(followers);
   return result;
 }
Esempio n. 2
0
        /// <summary>
        /// Returns an object that implements IExpression and that represents this expression after language specific rules have been
        /// applied to it in order to determine its semantics. The resulting expression is a standard representation of the semantics
        /// of this expression, suitable for use by language agnostic clients and complete enough for translation of the expression
        /// into IL.
        /// </summary>
        protected override IExpression ProjectAsNonConstantIExpression()
        {
            if (cachedProjection != null) return cachedProjection;
              if (this.Type == Dummy.Type) return (cachedProjection = CodeDummy.Expression);
              if (TypeHelper.GetTypeName(this.Type) == VccCompilationHelper.SystemDiagnosticsContractsCodeContractObjsetString) {
            this.cachedProjection = this.ProjectAsFiniteSet();
            return this.cachedProjection;
              }

              // create the value in a local and initialize its fields field-by-field
              List<Statement> statements = new List<Statement>();
              LocalDefinition localTemp;
              Expression result;
              if (this.arrayTypeExpression != null) {
            CreateStackArray createStackArray = new CreateStackArray(this.arrayTypeExpression.ElementType, new CompileTimeConstant(this.ExpressionCount, this.SourceLocation), this.SourceLocation);
            createStackArray.SetContainingExpression(this);
            localTemp = Expression.CreateInitializedLocalDeclarationAndAddDeclarationsStatementToList(createStackArray, statements);
            result = new BoundExpression(this, localTemp);
            this.AddInitializingElementAssignmentsTo(statements, result, this.arrayTypeExpression);
              } else {
            localTemp = this.CreateLocalTempForProjection(statements);
            result = new BoundExpression(this, localTemp);
            VccStructuredTypeDeclaration typeDecl = this.GetStructuredTypeDecl();
            if (typeDecl != null)
              this.AddInitializingFieldAssignmentsTo(statements, result, typeDecl);
              }
              BlockStatement block = new BlockStatement(statements, this.SourceLocation);
              BlockExpression bexpr = new BlockExpression(block, result, this.SourceLocation);
              bexpr.SetContainingExpression(this);
              return this.cachedProjection = bexpr.ProjectAsIExpression();
        }