예제 #1
0
 internal override void AddInitializingElementAssignmentsTo(ICollection<Statement> statements, Expression target, VccArrayTypeExpression arrTypeExp)
 {
     throw new InvalidOperationException("Cannot use designator list to initialize an array");
 }
예제 #2
0
 internal abstract void AddInitializingElementAssignmentsTo(ICollection<Statement> statements, Expression target, VccArrayTypeExpression/*?*/ arrTypeExp);
예제 #3
0
 protected VccInitializerBase(BlockStatement containingBlock, VccInitializerBase template)
     : base(containingBlock, template)
 {
     this.structureTypeExpression = template.structureTypeExpression;
       this.arrayTypeExpression = template.arrayTypeExpression;
       this.typeDefaultsToObjset = template.typeDefaultsToObjset;
 }
예제 #4
0
 internal override void AddInitializingElementAssignmentsTo(ICollection<Statement> statements, Expression array, VccArrayTypeExpression/*?*/ arrTypeExp)
 {
     TypeExpression elemTypeExp = null;
       if (arrTypeExp != null) {
     elemTypeExp = arrTypeExp.ElementType;
       }
       // If we have a multiple dimensional array, and the element is not a VccInitializer,
       // then we will compute the number of constants needed for array[i], say, x, and bundle
       // x constant together for array[i], which may be further an array, in which case, the above
       // process repeat.
       int i = 0, n = this.expressions.Count;
       int lengthForFirstDimensionIfNotProvided = 0;
       bool elementIsVccInitializer = (n == 0) ? true : expressions[0] is VccInitializer;
       int rownum = 0;
       // For multidimensional array,
       // i may be increased by the total number of embedded array elements per loop, rownum always by 1.
       while (i < n){
     Expression arrayLine = array;
     List<Expression> indices = new List<Expression>(1) {new CompileTimeConstant(rownum++, true, SourceDummy.SourceLocation)};
     VccIndexer element = new VccIndexer(arrayLine, indices.AsReadOnly(), SourceDummy.SourceLocation);
     // Construct the initial value for one element of the array.
     Expression/*?*/ initialValueForOneElement = null;
     int sizeOfEmbeddedArrays = arrTypeExp.SizeOfEmbeddedArrays;
     VccArrayTypeExpression embeddedArrayType = elemTypeExp as VccArrayTypeExpression;
     //^ assert sizeOfEmbeddedArrays >=0;
     // TODO: C doesnt allow sizeOfEmbeddedArrays to be zero, in which case we should report an error
     if (sizeOfEmbeddedArrays ==0 || elementIsVccInitializer || embeddedArrayType == null) {
       initialValueForOneElement = this.expressions[i++];
     } else {
       List<Expression> exprs = new List<Expression>(sizeOfEmbeddedArrays);
       for (int j = 0; j < sizeOfEmbeddedArrays; j++) {
     exprs.Add(i < n ? expressions[i++] : new CompileTimeConstant(0, this.SourceLocation));
       }
       initialValueForOneElement = new VccInitializer(exprs, false, this.SourceLocation);
     }
     //^ assert initialValueForOneElement != null;
     AddInitializationTo(statements, initialValueForOneElement, element, elemTypeExp, this.ContainingBlock);
     lengthForFirstDimensionIfNotProvided++;
       }
       // In C, it is possible to initialize an array when its first dimension's length is not
       // specified, in which case, the initializer provides information of the length.
       if (arrTypeExp.Size != null) {
     arrTypeExp.ResetSizeWhenProvidedByInitializer(new CompileTimeConstant(lengthForFirstDimensionIfNotProvided, arrTypeExp.SourceLocation));
       }
 }
예제 #5
0
 private IExpression GetProjectedExpression()
 {
     VccCompilationHelper helper = (VccCompilationHelper)this.Helper;
       string/*?*/ str = this.Value as string;
       if (str == null) return CodeDummy.Expression;
       GlobalVariableDeclaration/*?*/ globalVar;
       if (!helper.StringTable.TryGetValue(str, out globalVar)) {
     NameDeclaration dummyName = new NameDeclaration(this.NameTable.GetNameFor("?mappedLiteral"+this.GetHashCode()), this.SourceLocation);
     VccArrayTypeExpression arrayType = new VccArrayTypeExpression(TypeExpression.For(this.PlatformType.SystemUInt8.ResolvedType), new CompileTimeConstant(str.Length+1, SourceDummy.SourceLocation), SourceDummy.SourceLocation);
     globalVar = new GlobalVariableDeclaration(FieldDeclaration.Flags.ReadOnly, TypeMemberVisibility.Assembly, arrayType, dummyName, this, this.SourceLocation);
     if (this.ContainingBlock.ContainingTypeDeclaration != null) {
       this.ContainingBlock.ContainingTypeDeclaration.AddHelperMember(globalVar);
       globalVar.SetContainingTypeDeclaration(this.ContainingBlock.ContainingTypeDeclaration, true);
       helper.StringTable.Add(str, globalVar);
     } else {
       return CodeDummy.Expression;
       //TODO: error
     }
       }
       //^ assume globalVar != null;
       AddressableExpression fieldRef = new AddressableExpression(new BoundExpression(this, globalVar.FieldDefinition));
       VccAddressOf addressOf = new VccAddressOf(fieldRef, this.SourceLocation);
       addressOf.SetContainingExpression(this);
       Conversion conversion = new Conversion(addressOf, this.Type, this.SourceLocation);
       return conversion.ProjectAsIExpression();
 }
예제 #6
0
 //^ requires template.ContainingBlock != containingBlock;
 //^ ensures this.containingBlock == containingBlock;
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing block.
 /// </summary>
 /// <param name="containingBlock">A new value for containing block. This replaces template.ContainingBlock in the resulting copy of template.</param>
 /// <param name="template">The template to copy.</param>
 private VccArrayTypeExpression(BlockStatement containingBlock, VccArrayTypeExpression template)
     : base(containingBlock, template)
 {
     this.Size = template.Size == null ? null : template.Size.MakeCopyFor(containingBlock);
 }