예제 #1
0
 /// <summary>
 /// Returns this.Address unless it is a fixed size array. In that case, returns the address of the array value, after conversion to a pointer
 /// to the element type of the array.
 /// </summary>
 private Expression GetConvertedAddress()
 {
     if (this.Address.Type is IPointerType || this.Type == Dummy.Type) return this.Address;
       VccAddressOf addressOf = new VccAddressOf(new AddressableExpression(this.Address), this.Address.SourceLocation);
       addressOf.SetContainingExpression(this);
       return addressOf;
 }
예제 #2
0
        /// <summary>
        /// Returns an expression corresponding to *(ptr + index) where ptr is this.IndexedObject and index is the first element of this.ConvertedArguments.
        /// </summary>
        protected override IExpression ProjectAsDereferencedPointerAddition()
        {
            //transform to *(ptr + index)

              IEnumerator<Expression> indexEnumerator = this.ConvertedArguments.GetEnumerator();
              if (!indexEnumerator.MoveNext()) return CodeDummy.Expression;
              Expression ptr = this.IndexedObject;
              if (this.FixedArrayElementType != null) {
            ptr = new VccAddressOf(new VccAddressableExpression(this.IndexedObject, true), this.IndexedObject.SourceLocation);
            ptr.SetContainingExpression(this);
              }
              Expression index = indexEnumerator.Current;
              if (index.Type.IsEnum) index = this.Helper.ExplicitConversion(index, index.Type.UnderlyingType.ResolvedType);
              VccAddition addition = new VccAddition(ptr, index, this.SourceLocation);
              AddressDereference aderef = new AddressDereference(addition, this.SourceLocation);
              aderef.SetContainingExpression(this);
              return aderef.ProjectAsIExpression();
        }
예제 #3
0
 protected override IExpression ProjectAsNonConstantIExpression()
 {
     if (this.cachedProjection == null) {
     object member = this.ResolveAsValueContainer(true);
     INestedTypeDefinition groupType = member as INestedTypeDefinition;
     if (groupType != null) {
       // expression refers to a group
       Cast cast = new Cast(new Parenthesis(this.Instance, this.SourceLocation), TypeExpression.For(this.Type), this.SourceLocation);
       cast.SetContainingExpression(this);
       // TODO the projection of cast looses its source location, it only retains the source location of the casted expression,
       // so we stick the proper location on the casted expression itself
       return this.cachedProjection = cast.ProjectAsIExpression();
     }
     IFieldDefinition fieldDef = member as IFieldDefinition;
     if (fieldDef != null) {
       var addrOf = new VccAddressOf(new AddressableExpression(new ProjectionHelper(this.Qualifier, this.SimpleName, fieldDef, this.SourceLocation)), this.SourceLocation);
       addrOf.SetContainingExpression(this);
       return this.cachedProjection = addrOf.ProjectAsIExpression();
     }
     this.cachedProjection = new DummyExpression(this.SourceLocation);
       }
       return this.cachedProjection;
 }
예제 #4
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();
 }