예제 #1
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();
        }