Ejemplo n.º 1
0
            public override void Visit(ITypeReference type)
            {
                var namedTypeReference = type as INamedTypeReference;

                if (namedTypeReference != null)
                {
                    _formattedValue = namedTypeReference.Name.Value;
                }
                else
                {
                    _formattedValue = "{" + type.GetType().Name + "}";
                }
            }
Ejemplo n.º 2
0
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference,
                            string.Format("Unexpected type reference that we may need to unwrap {0}", (reference != null ? reference.GetType().FullName : "null")));

            return(reference);
        }
Ejemplo n.º 3
0
 public override void Visit(ITypeReference typeReference)
 {
     if (typeReference is INamedTypeReference)
     {
         output.Append((typeReference as INamedTypeReference).Name.Value);
     }
     else if (typeReference is VectorTypeReference)
     {
         output.Append((((typeReference as VectorTypeReference).ElementType) as INamedTypeReference).Name.Value);
         output.Append("[]");
     }
     else
     {
         output.AppendFormat("?{0}?", typeReference.GetType().Name);
     }
     AppendSpace();
     base.Visit(typeReference);
 }
        public static ITypeReference UnWrap(this ITypeReference reference)
        {
            IPointerTypeReference pointer = reference as IPointerTypeReference;

            if (pointer != null)
            {
                return(pointer.TargetType.UnWrap());
            }

            IArrayTypeReference array = reference as IArrayTypeReference;

            if (array != null)
            {
                return(array.ElementType.UnWrap());
            }

            IModifiedTypeReference modified = reference as IModifiedTypeReference;

            if (modified != null)
            {
                return(modified.UnmodifiedType.UnWrap());
            }

            ISpecializedNestedTypeReference specialized = reference as ISpecializedNestedTypeReference;

            if (specialized != null)
            {
                return(specialized.UnspecializedVersion.UnWrap());
            }

            IGenericTypeInstanceReference instantiation = reference as IGenericTypeInstanceReference;

            if (instantiation != null)
            {
                return(instantiation.GenericType.UnWrap());
            }

            Contract.Assert(reference is INamedTypeReference ||
                            reference is INestedTypeReference ||
                            reference is INamespaceTypeReference ||
                            reference is IGenericTypeParameterReference ||
                            reference is IGenericMethodParameterReference ||
                            reference is IFunctionPointerTypeReference,
                            string.Format(CultureInfo.CurrentCulture, LocalizedStrings.UnexpectedTypeReference, (reference?.GetType()?.FullName ?? "null")));

            return(reference);
        }
Ejemplo n.º 5
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());
        }