示例#1
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();
 }
示例#2
0
 //^ ensures this.containingTypeDeclaration == containingTypeDeclaration;
 /// <summary>
 /// A copy constructor that allocates an instance that is the same as the given template, except for its containing type.
 /// </summary>
 /// <param name="containingTypeDeclaration">The containing type of the copied member. This should be different from the containing type of the template member.</param>
 /// <param name="template">The type member to copy.</param>
 private GlobalVariableDeclaration(TypeDeclaration containingTypeDeclaration, GlobalVariableDeclaration template)
     : base(containingTypeDeclaration, template)
 {
 }