예제 #1
0
 /// <summary>
 /// Copies specialized nested type references since their containing types may involve type parameters, but
 /// leaves other kinds of nested type references alone.
 /// </summary>
 /// <param name="nestedTypeReference">The nested type reference.</param>
 public override INestedTypeReference Visit(INestedTypeReference nestedTypeReference)
 {
     ISpecializedNestedTypeReference/*?*/ specializedNestedTypeReference = nestedTypeReference as ISpecializedNestedTypeReference;
       if (specializedNestedTypeReference != null)
     return this.Visit(specializedNestedTypeReference);
       return nestedTypeReference;
 }
예제 #2
0
 private void TraverseUnspecialized(INestedTypeReference nestedTypeReference)
 {
     Contract.Requires(nestedTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(nestedTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(nestedTypeReference);
       if (this.stopTraversal) return;
       this.TraverseChildren(nestedTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(nestedTypeReference);
 }
예제 #3
0
 /// <summary>
 /// Traverses the nested type reference.
 /// </summary>
 public void Traverse(INestedTypeReference nestedTypeReference)
 {
     Contract.Requires(nestedTypeReference != null);
       nestedTypeReference.DispatchAsReference(this.dispatchingVisitor);
 }
예제 #4
0
        public override void Visit(INestedTypeReference nestedTypeReference)
        {
            if (!this.typeReferenceNeedsToken && nestedTypeReference.AsSpecializedNestedTypeReference != null)
            {
                return;
            }

            RecordTypeReference(nestedTypeReference);
        }
예제 #5
0
 public void Visit(INestedTypeReference nestedTypeReference)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Rewrites the given namespace type reference.
 /// </summary>
 public virtual INestedTypeReference RewriteUnspecialized(INestedTypeReference nestedTypeReference)
 {
     return nestedTypeReference;
 }
예제 #7
0
    private void EmitTypeLoadingCallsFor(INestedTypeReference nestedType, string typeObjectName, SetOfUints alreadyLoadedTypes) {
      Contract.Requires(nestedType != null);
      Contract.Requires(typeObjectName != null);
      Contract.Requires(alreadyLoadedTypes != null);

      var containingTypeObjectName = this.GetMangledTypeName(nestedType.ContainingType)+"_typeObject";
      this.EmitTypeLoadingCallsFor(nestedType.ContainingType, containingTypeObjectName, alreadyLoadedTypes);
      this.EmitSetTypeAndSetBaseClass(nestedType.ResolvedType, typeObjectName, alreadyLoadedTypes);
      this.sourceEmitter.EmitString("SetDeclaringType(");
      this.sourceEmitter.EmitString(typeObjectName);
      this.sourceEmitter.EmitString(", ");
      this.sourceEmitter.EmitString(containingTypeObjectName);
      this.sourceEmitter.EmitString(");");
      this.sourceEmitter.EmitNewLine();
    }
예제 #8
0
        public override void Visit(INestedTypeReference type)
        {
            INestedTypeReference typeRef = (INestedTypeReference)Util.CanonicalizeTypeReference(type);

            // The type can resolve to an external assembly, so we need to check whether we can include the external assembly.
            if (m_implModel.CanInclude(typeRef))
            {
                Visit(Util.ResolveTypeThrowing(typeRef));
            }
        }
예제 #9
0
 public override INestedTypeReference Rewrite(INestedTypeReference nestedTypeReference)
 {
     return(base.Rewrite(TransformType(nestedTypeReference)));
 }
 public override void Visit(INestedTypeReference nestedTypeReference)
 {
     allElements.Add(new InvokInfo(Traverser, "INestedTypeReference", nestedTypeReference));
 }
예제 #11
0
 public override void Visit(INestedTypeReference type)
 {
     base.Visit(type);
     AddAssemblyReference(type.GetAssemblyReference());
 }
 public override void Visit(INestedTypeReference nestedTypeReference)
 {
     if(Process(nestedTypeReference)){visitor.Visit(nestedTypeReference);}
     base.Visit(nestedTypeReference);
 }
예제 #13
0
 public override void Visit(INestedTypeReference nestedTypeReference) {
   var containingType = this.mapper.GetType(nestedTypeReference.ContainingType);
   var name = nestedTypeReference.Name.Value;
   this.result = containingType.GetNestedType(name, BindingFlags.NonPublic|BindingFlags.DeclaredOnly);
   if (this.result == null && nestedTypeReference.GenericParameterCount > 0) {
     name = name + "'" + nestedTypeReference.GenericParameterCount;
     this.result = containingType.GetNestedType(name, BindingFlags.NonPublic|BindingFlags.DeclaredOnly);
   }
 }
예제 #14
0
 /// <summary>
 /// Performs some computation with the given nested type reference.
 /// </summary>
 public virtual void Visit(INestedTypeReference nestedTypeReference)
 {
 }
예제 #15
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given nested type reference.
 /// </summary>
 /// <param name="nestedTypeReference"></param>
 public virtual void Visit(INestedTypeReference nestedTypeReference)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(nestedTypeReference);
       this.Visit(nestedTypeReference.ContainingType);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
 public override void Visit(INestedTypeReference type)
 {
     base.Visit(type);
     AddAssemblyReference(type.GetAssemblyReference());
 }
예제 #17
0
 public override void Visit(INestedTypeReference type)
 {
     AddTypeReference(type);
     base.Visit(type);
 }
예제 #18
0
 /// <summary>
 /// Traverses the children of the nested type reference.
 /// </summary>
 public virtual void TraverseChildren(INestedTypeReference nestedTypeReference)
 {
     this.TraverseChildren((ITypeReference)nestedTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(nestedTypeReference.ContainingType);
       if (this.stopTraversal) return;
 }
예제 #19
0
        public override string GetTypeName(ITypeReference type, NameFormattingOptions formattingOptions)
        {
            Contract.Requires(type != null);
            Contract.Ensures(Contract.Result <string>() != null);

            if (type is Dummy)
            {
                return("Microsoft.Cci.DummyTypeReference");
            }
            if ((formattingOptions & NameFormattingOptions.UseTypeKeywords) != 0)
            {
                switch (type.TypeCode)
                {
                case PrimitiveTypeCode.Boolean: return("Boolean");

                case PrimitiveTypeCode.Char: return("Char");

                case PrimitiveTypeCode.Float32: return("Float");

                case PrimitiveTypeCode.Float64: return("Double");

                case PrimitiveTypeCode.Int16: return("Short");

                case PrimitiveTypeCode.Int32: return("Integer");

                case PrimitiveTypeCode.Int64: return("Long");

                case PrimitiveTypeCode.Int8: return("SByte");

                case PrimitiveTypeCode.String: return("String");

                case PrimitiveTypeCode.UInt16: return("UShort");

                case PrimitiveTypeCode.UInt32: return("UInteger");

                case PrimitiveTypeCode.UInt64: return("ULong");

                case PrimitiveTypeCode.UInt8: return("Byte");

                case PrimitiveTypeCode.Void: { Contract.Assert(false); throw new InvalidOperationException(); }

                case PrimitiveTypeCode.NotPrimitive:
                    if (TypeHelper.TypesAreEquivalent(type, type.PlatformType.SystemDecimal))
                    {
                        return("Decimal");
                    }
                    if (TypeHelper.TypesAreEquivalent(type, type.PlatformType.SystemObject))
                    {
                        return("Object");
                    }
                    break;
                }
            }
            IArrayTypeReference /*?*/ arrayType = type as IArrayTypeReference;

            if (arrayType != null)
            {
                return(this.GetArrayTypeName(arrayType, formattingOptions));
            }
            IFunctionPointerTypeReference /*?*/ functionPointerType = type as IFunctionPointerTypeReference;

            if (functionPointerType != null)
            {
                return(this.GetFunctionPointerTypeName(functionPointerType, formattingOptions));
            }
            IGenericTypeParameterReference /*?*/ genericTypeParam = type as IGenericTypeParameterReference;

            if (genericTypeParam != null)
            {
                return(this.GetGenericTypeParameterName(genericTypeParam, formattingOptions));
            }
            IGenericMethodParameterReference /*?*/ genericMethodParam = type as IGenericMethodParameterReference;

            if (genericMethodParam != null)
            {
                return(this.GetGenericMethodParameterName(genericMethodParam, formattingOptions));
            }
            IGenericTypeInstanceReference /*?*/ genericInstance = type as IGenericTypeInstanceReference;

            if (genericInstance != null)
            {
                return(this.GetGenericTypeInstanceName(genericInstance, formattingOptions));
            }
            INestedTypeReference /*?*/ ntTypeDef = type as INestedTypeReference;

            if (ntTypeDef != null)
            {
                return(this.GetNestedTypeName(ntTypeDef, formattingOptions));
            }
            INamespaceTypeReference /*?*/ nsTypeDef = type as INamespaceTypeReference;

            if (nsTypeDef != null)
            {
                return(this.GetNamespaceTypeName(nsTypeDef, formattingOptions));
            }
            IPointerTypeReference /*?*/ pointerType = type as IPointerTypeReference;

            if (pointerType != null)
            {
                return(this.GetPointerTypeName(pointerType, formattingOptions));
            }
            IManagedPointerTypeReference /*?*/ managedPointerType = type as IManagedPointerTypeReference;

            if (managedPointerType != null)
            {
                return(this.GetManagedPointerTypeName(managedPointerType, formattingOptions));
            }
            IModifiedTypeReference /*?*/ modifiedType = type as IModifiedTypeReference;

            if (modifiedType != null)
            {
                return(this.GetModifiedTypeName(modifiedType, formattingOptions));
            }
            if (type.ResolvedType != type && !(type.ResolvedType is Dummy))
            {
                return(this.GetTypeName(type.ResolvedType, formattingOptions));
            }
            return("unknown type: " + type.GetType().ToString());
        }
 /// <summary>
 /// Rewrites the given namespace type reference.
 /// </summary>
 public virtual INestedTypeReference Rewrite(INestedTypeReference nestedTypeReference)
 {
     return nestedTypeReference;
 }
예제 #21
0
        private static void AppendAssemblyQualifierIfNecessary(StringBuilder sb, ITypeReference typeReference, out bool isAssemQualified, EmitContext context)
        {
            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, nestedType.GetContainingType(context), out isAssemQualified, context);
                return;
            }

            IGenericTypeInstanceReference genInst = typeReference.AsGenericTypeInstanceReference;

            if (genInst != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, genInst.GenericType, out isAssemQualified, context);
                return;
            }

            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, arrType.GetElementType(context), out isAssemQualified, context);
                return;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context);
                return;
            }

            IManagedPointerTypeReference reference = typeReference as IManagedPointerTypeReference;

            if (reference != null)
            {
                AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context);
                return;
            }

            isAssemQualified = false;
            IAssemblyReference      referencedAssembly = null;
            INamespaceTypeReference namespaceType      = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                referencedAssembly = namespaceType.GetUnit(context) as IAssemblyReference;
            }

            if (referencedAssembly != null)
            {
                var containingAssembly = context.Module.GetContainingAssembly(context);

                if (containingAssembly == null || !ReferenceEquals(referencedAssembly, containingAssembly))
                {
                    sb.Append(", ");
                    sb.Append(MetadataWriter.StrongName(referencedAssembly));
                    isAssemQualified = true;
                }
            }
        }
예제 #22
0
        public override void TraverseChildren(INestedTypeReference nestedTypeReference)
{ MethodEnter(nestedTypeReference);
            base.TraverseChildren(nestedTypeReference);
     MethodExit();   }
예제 #23
0
 /// <summary>
 /// Performs some computation with the given nested type reference.
 /// </summary>
 public virtual void Visit(INestedTypeReference nestedTypeReference) {
   this.Visit((INamedTypeReference)nestedTypeReference);
   this.Visit((ITypeMemberReference)nestedTypeReference);
 }
예제 #24
0
 public virtual void Visit(INestedTypeReference nestedTypeReference)
 {
     this.Visit(nestedTypeReference.GetContainingType(Context));
 }
예제 #25
0
        internal static string GetSerializedTypeName(this ITypeReference typeReference, EmitContext context, ref bool isAssemblyQualified)
        {
            var                 pooled  = PooledStringBuilder.GetInstance();
            StringBuilder       sb      = pooled.Builder;
            IArrayTypeReference arrType = typeReference as IArrayTypeReference;

            if (arrType != null)
            {
                typeReference = arrType.GetElementType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                if (arrType.IsSZArray)
                {
                    sb.Append("[]");
                }
                else
                {
                    sb.Append('[');
                    if (arrType.Rank == 1)
                    {
                        sb.Append('*');
                    }

                    sb.Append(',', (int)arrType.Rank - 1);

                    sb.Append(']');
                }

                goto done;
            }

            IPointerTypeReference pointer = typeReference as IPointerTypeReference;

            if (pointer != null)
            {
                typeReference = pointer.GetTargetType(context);
                bool isAssemQual = false;
                AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context);
                sb.Append('*');
                goto done;
            }

            INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference;

            if (namespaceType != null)
            {
                var name = namespaceType.NamespaceName;
                if (name.Length != 0)
                {
                    sb.Append(name);
                    sb.Append('.');
                }

                sb.Append(GetMangledAndEscapedName(namespaceType));
                goto done;
            }


            if (typeReference.IsTypeSpecification())
            {
                ITypeReference uninstantiatedTypeReference = typeReference.GetUninstantiatedGenericType(context);

                ArrayBuilder <ITypeReference> consolidatedTypeArguments = ArrayBuilder <ITypeReference> .GetInstance();

                typeReference.GetConsolidatedTypeArguments(consolidatedTypeArguments, context);

                bool uninstantiatedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(uninstantiatedTypeReference, context, ref uninstantiatedTypeIsAssemblyQualified));
                sb.Append('[');
                bool first = true;
                foreach (ITypeReference argument in consolidatedTypeArguments)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }

                    bool isAssemQual = true;
                    AppendSerializedTypeName(sb, argument, ref isAssemQual, context);
                }
                consolidatedTypeArguments.Free();

                sb.Append(']');
                goto done;
            }

            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                bool nestedTypeIsAssemblyQualified = false;
                sb.Append(GetSerializedTypeName(nestedType.GetContainingType(context), context, ref nestedTypeIsAssemblyQualified));
                sb.Append('+');
                sb.Append(GetMangledAndEscapedName(nestedType));
                goto done;
            }

// TODO: error
done:
            if (isAssemblyQualified)
            {
                AppendAssemblyQualifierIfNecessary(sb, UnwrapTypeReference(typeReference, context), out isAssemblyQualified, context);
            }

            return(pooled.ToStringAndFree());
        }
예제 #26
0
 /// <summary>
 /// Performs some computation with the given nested type reference.
 /// </summary>
 public virtual void Visit(INestedTypeReference nestedTypeReference)
 {
 }
예제 #27
0
 public virtual void Visit(INestedTypeReference nestedTypeReference)
 {
     this.Visit(nestedTypeReference.GetContainingType(Context));
 }
예제 #28
0
 /// <summary>
 /// Traverses the children of the nested type reference.
 /// </summary>
 public virtual void TraverseChildren(INestedTypeReference nestedTypeReference)
 {
     Contract.Requires(nestedTypeReference != null);
       this.TraverseChildren((ITypeReference)nestedTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(nestedTypeReference.ContainingType);
       if (this.stopTraversal) return;
 }
예제 #29
0
        /// <summary>
        /// Use this routine, rather than ITypeReference.Dispatch, to call the appropriate derived overload of an ITypeReference.
        /// The former routine will call Visit(INamespaceTypeDefinition) rather than Visit(INamespaceTypeReference), etc.,
        /// in the case where a definition is used as a reference to itself.
        /// </summary>
        /// <param name="typeReference">A reference to a type definition. Note that a type definition can serve as a reference to itself.</param>
        protected void DispatchAsReference(ITypeReference typeReference)
        {
            INamespaceTypeReference namespaceTypeReference = typeReference.AsNamespaceTypeReference;

            if (namespaceTypeReference != null)
            {
                this.Visit(namespaceTypeReference);
                return;
            }

            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                this.Visit(genericTypeInstanceReference);
                return;
            }

            INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;

            if (nestedTypeReference != null)
            {
                this.Visit(nestedTypeReference);
                return;
            }

            IArrayTypeReference arrayTypeReference = typeReference as IArrayTypeReference;

            if (arrayTypeReference != null)
            {
                this.Visit(arrayTypeReference);
                return;
            }

            IGenericTypeParameterReference genericTypeParameterReference = typeReference.AsGenericTypeParameterReference;

            if (genericTypeParameterReference != null)
            {
                this.Visit(genericTypeParameterReference);
                return;
            }

            IGenericMethodParameterReference genericMethodParameterReference = typeReference.AsGenericMethodParameterReference;

            if (genericMethodParameterReference != null)
            {
                this.Visit(genericMethodParameterReference);
                return;
            }

            IPointerTypeReference pointerTypeReference = typeReference as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                this.Visit(pointerTypeReference);
                return;
            }

            IModifiedTypeReference modifiedTypeReference = typeReference as IModifiedTypeReference;

            if (modifiedTypeReference != null)
            {
                this.Visit(modifiedTypeReference);
                return;
            }
        }
예제 #30
0
 public void Visit(INestedTypeReference nestedTypeReference)
 {
     this.traverser.TraverseUnspecialized(nestedTypeReference);
 }
예제 #31
0
 /// <summary>
 /// Use this constructor when the anonymous delegate did capture a local or parameter
 /// and so was implemented as an instance, non-generic closure method within a generic
 /// class.
 /// </summary>
 public GenericMethodParameterMapper(IMetadataHost host, IMethodDefinition targetMethod, INestedTypeReference sourceType)
     : this(host, targetMethod)
 {
     this.sourceType = sourceType;
 }
예제 #32
0
 /// <summary>
 /// Performs some computation with the given nested type reference.
 /// </summary>
 public void Visit(INestedTypeReference nestedTypeReference)
 {
     this.Visit((INamedTypeReference)nestedTypeReference);
 }
예제 #33
0
 public override void TraverseChildren(INestedTypeReference nestedTypeReference) {
   this.Traverse(nestedTypeReference.ContainingType);
   this.TraverseChildren(nestedTypeReference.ResolvedType);
 }
 public override void TraverseChildren(INestedTypeReference nestedTypeReference) {
   base.TraverseChildren(nestedTypeReference);
 }
예제 #35
0
 /// <summary>
 /// Use this constructor when the anonymous delegate did capture a local or parameter
 /// and so was implemented as an instance, non-generic closure method within a generic
 /// class.
 /// </summary>
 public GenericMethodParameterMapper(IMetadataHost host, IMethodDefinition targetMethod, INestedTypeReference sourceType)
     : this(host, targetMethod)
 {
     this.sourceType = sourceType;
 }
예제 #36
0
 public virtual void onMetadataElement(INestedTypeReference nestedTypeReference) { }
예제 #37
0
 /// <summary>
 /// Traverses the nested type reference.
 /// </summary>
 public void Traverse(INestedTypeReference nestedTypeReference)
 {
     nestedTypeReference.DispatchAsReference(this.dispatchingVisitor);
 }