示例#1
0
        // Array and pointer types might cause deep recursions; visit them iteratively
        // rather than recursively.
        public override void Visit(IPointerTypeReference pointerTypeReference)
        {
            // We don't visit the current pointer type; it has already been visited.
            // We go straight to the target type and visit it.
            ITypeReference current = pointerTypeReference.GetTargetType(Context);

            while (true)
            {
                bool mustVisitChildren = VisitTypeReference(current);
                if (!mustVisitChildren)
                {
                    return;
                }
                else if (current is IPointerTypeReference)
                {
                    // The target type is itself an pointer type, and we must visit *its* target type.
                    // Iterate rather than recursing.
                    current = ((IPointerTypeReference)current).GetTargetType(Context);
                    continue;
                }
                else
                {
                    // The target type is not an pointer type and we must visit its children.
                    // Dispatch the type in order to visit its children.
                    DispatchAsReference(current);
                    return;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Strip off *, &amp;, and [].
        /// </summary>
        private static ITypeReference UnwrapTypeReference(ITypeReference typeReference, EmitContext context)
        {
            while (true)
            {
                IArrayTypeReference arrType = typeReference as IArrayTypeReference;
                if (arrType != null)
                {
                    typeReference = arrType.GetElementType(context);
                    continue;
                }

                IPointerTypeReference pointer = typeReference as IPointerTypeReference;
                if (pointer != null)
                {
                    typeReference = pointer.GetTargetType(context);
                    continue;
                }

                IManagedPointerTypeReference reference = typeReference as IManagedPointerTypeReference;
                if (reference != null)
                {
                    typeReference = reference.GetTargetType(context);
                    continue;
                }

                return(typeReference);
            }
        }
 public override void Visit(IPointerTypeReference pointerTypeReference)
 {
     if (Process(pointerTypeReference))
     {
         visitor.Visit(pointerTypeReference);
     }
     base.Visit(pointerTypeReference);
 }
示例#4
0
        private static void VisitTypeReference(ITypeReference typeReference, EmitContext context)
        {
            Debug.Assert(typeReference != null);

            IArrayTypeReference arrayType = typeReference as IArrayTypeReference;

            if (arrayType != null)
            {
                VisitTypeReference(arrayType.GetElementType(context), context);
                return;
            }

            IPointerTypeReference pointerType = typeReference as IPointerTypeReference;

            if (pointerType != null)
            {
                VisitTypeReference(pointerType.GetTargetType(context), context);
                return;
            }

            //IManagedPointerTypeReference managedPointerType = typeReference as IManagedPointerTypeReference;
            //if (managedPointerType != null)
            //{
            //    VisitTypeReference(managedPointerType.GetTargetType(this.context));
            //    return;
            //}

            IModifiedTypeReference modifiedType = typeReference as IModifiedTypeReference;

            if (modifiedType != null)
            {
                foreach (var custModifier in modifiedType.CustomModifiers)
                {
                    VisitTypeReference(custModifier.GetModifier(context), context);
                }
                VisitTypeReference(modifiedType.UnmodifiedType, context);
                return;
            }

            // Visit containing type
            INestedTypeReference nestedType = typeReference.AsNestedTypeReference;

            if (nestedType != null)
            {
                VisitTypeReference(nestedType.GetContainingType(context), context);
            }

            // Visit generic arguments
            IGenericTypeInstanceReference genericInstance = typeReference.AsGenericTypeInstanceReference;

            if (genericInstance != null)
            {
                foreach (var arg in genericInstance.GetGenericArguments(context))
                {
                    VisitTypeReference(arg, context);
                }
            }
        }
示例#5
0
    public override void TraverseChildren(IPointerTypeReference pointerTypeReference)
    {
        var typ = pointerTypeReference.ResolvedType;

        if (typ == Dummy.Type)
        {
            this.EmitError(pointerTypeReference, ErrorCode.PointerTypeResolution);
        }
        base.TraverseChildren(pointerTypeReference);
    }
示例#6
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.GetGenericType(context), 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;
            }

            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;
                }
            }
        }
示例#7
0
        public override void TraverseChildren(IAddressDereference addressDereference)
        {
            base.TraverseChildren(addressDereference);
            IPointerTypeReference /*?*/ pointerTypeReference = addressDereference.Address.Type as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                if (!(pointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = pointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, pointerTypeReference.TargetType))
                    {
                        var targetPointerType = Immutable.PointerType.GetPointerType(addressDereference.Type, this.host.InternFactory);
                        ((AddressDereference)addressDereference).Address = new Conversion()
                        {
                            ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                        };
                    }
                    return;
                }
            }
            IManagedPointerTypeReference /*?*/ managedPointerTypeReference = addressDereference.Address.Type as IManagedPointerTypeReference;

            if (managedPointerTypeReference != null)
            {
                if (!(managedPointerTypeReference.TargetType is Dummy))
                {
                    if (addressDereference.Type is Dummy)
                    {
                        ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                    }
                    else if (!TypeHelper.TypesAreEquivalent(addressDereference.Type, managedPointerTypeReference.TargetType))
                    {
                        if (managedPointerTypeReference.TargetType.TypeCode == PrimitiveTypeCode.Boolean && addressDereference.Type.TypeCode == PrimitiveTypeCode.Int8)
                        {
                            ((AddressDereference)addressDereference).Type = managedPointerTypeReference.TargetType;
                        }
                        else
                        {
                            var targetPointerType = Immutable.ManagedPointerType.GetManagedPointerType(addressDereference.Type, this.host.InternFactory);
                            ((AddressDereference)addressDereference).Address = new Conversion()
                            {
                                ValueToConvert = addressDereference.Address, TypeAfterConversion = targetPointerType, Type = targetPointerType
                            };
                        }
                    }
                    return;
                }
            }
        }
示例#8
0
        public static INamedTypeReference CanonicalizeTypeReference(ITypeReference type)
        {
            while (type != null)
            {
                IModifiedTypeReference          modifiedType = type as IModifiedTypeReference;
                IPointerTypeReference           ptrType      = type as IPointerTypeReference;
                IManagedPointerType             refType      = type as IManagedPointerType;
                IArrayTypeReference             arrType      = type as IArrayTypeReference;
                IGenericTypeInstanceReference   genType      = type as IGenericTypeInstanceReference;
                ISpecializedNestedTypeReference nestedType   = type as ISpecializedNestedTypeReference;
                // TODO: Why doesn't ISpecializedNestedTypeDefinition derive from ISpecializedNestedTypeReference?
                ISpecializedNestedTypeDefinition nestedTypeDef = type as ISpecializedNestedTypeDefinition;

                if (modifiedType != null)
                {
                    type = modifiedType.UnmodifiedType;
                }
                else if (ptrType != null)
                {
                    type = ptrType.TargetType;
                }
                else if (refType != null)
                {
                    type = refType.TargetType;
                }
                else if (arrType != null)
                {
                    type = arrType.ElementType;
                }
                else if (genType != null)
                {
                    type = genType.GenericType;
                }
                else if (nestedType != null)
                {
                    type = nestedType.UnspecializedVersion;
                }
                else if (nestedTypeDef != null)
                {
                    type = nestedTypeDef.UnspecializedVersion;
                }
                else /* ITypeDefinition */
                {
                    break;
                }
            }

            return(type as INamedTypeReference);
        }
示例#9
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 ||
                            reference is IManagedPointerType,
                            string.Format("Unexpected type reference that we may need to unwrap {0}", (reference != null ? reference.GetType().FullName : "null")));

            return(reference);
        }
        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);
        }
 public override void Visit(IPointerTypeReference pointerTypeReference)
 {
     if(Process(pointerTypeReference)){visitor.Visit(pointerTypeReference);}
     base.Visit(pointerTypeReference);
 }
示例#12
0
 public override void Visit(IPointerTypeReference pointerTypeReference) {
   this.result = this.mapper.GetType(pointerTypeReference.TargetType).MakePointerType();
 }
示例#13
0
 public override void Visit(IPointerTypeReference pointerTypeReference) {
   pointerTypeReference.TargetType.ResolvedType.Dispatch(this);
   int h = this.hash;
   h = (h << 5 + h) ^ 3;
   this.hash = h;
 }
示例#14
0
 public virtual void Visit(IPointerTypeReference pointerTypeReference)
 {
     this.Visit(pointerTypeReference.GetTargetType(Context));
 }
 /// <summary>
 /// Rewrites the given pointer type reference.
 /// </summary>
 public virtual IPointerTypeReference Rewrite(IPointerTypeReference pointerTypeReference)
 {
     return pointerTypeReference;
 }
示例#16
0
 public override void Visit(IPointerTypeReference pointerTypeReference)
 {
     this.result = this.mapper.GetType(pointerTypeReference.TargetType).MakePointerType();
 }
 public override void TraverseChildren(IPointerTypeReference pointerTypeReference) {
   base.TraverseChildren(pointerTypeReference);
 }
示例#18
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given pointer type reference.
 /// </summary>
 /// <param name="pointerTypeReference"></param>
 public virtual void Visit(IPointerTypeReference pointerTypeReference)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(pointerTypeReference);
       this.Visit(pointerTypeReference.TargetType);
       //^ 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();
 }
示例#19
0
 public void Visit(IPointerTypeReference pointerTypeReference)
 {
     this.traverser.Traverse(pointerTypeReference);
 }
示例#20
0
 public virtual void Visit(IPointerTypeReference pointerTypeReference)
 {
     this.Visit(pointerTypeReference.GetTargetType(Context));
 }
示例#21
0
 /// <summary>
 /// Traverses the pointer type reference.
 /// </summary>
 public void Traverse(IPointerTypeReference pointerTypeReference)
 {
     Contract.Requires(pointerTypeReference != null);
       if (!this.objectsThatHaveAlreadyBeenTraversed.Add(pointerTypeReference)) return;
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(pointerTypeReference);
       if (this.stopTraversal) return;
       this.TraverseChildren(pointerTypeReference);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(pointerTypeReference);
 }
示例#22
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());
        }
示例#23
0
 private void EmitTypeLoadingCallsFor(IPointerTypeReference pointerType, string mangledName, SetOfUints alreadyLoadedTypes) {
   Contract.Requires(pointerType != null);
   Contract.Requires(mangledName != null);
   Contract.Requires(alreadyLoadedTypes != null);
   //TODO: implement this
   this.EmitSetTypeAndSetBaseClass((ITypeReference)pointerType, mangledName, alreadyLoadedTypes);
 }
示例#24
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());
        }
示例#25
0
 public override void TraverseChildren(IPointerTypeReference pointerTypeReference)
 {
     MethodEnter(pointerTypeReference);
     base.TraverseChildren(pointerTypeReference);
     MethodExit();
 }
示例#26
0
 // Array and pointer types might cause deep recursions; visit them iteratively
 // rather than recursively.
 public override void Visit(IPointerTypeReference pointerTypeReference)
 {
     // We don't visit the current pointer type; it has already been visited.
     // We go straight to the target type and visit it.
     ITypeReference current = pointerTypeReference.GetTargetType(Context);
     while (true)
     {
         bool mustVisitChildren = VisitTypeReference(current);
         if (!mustVisitChildren)
         {
             return;
         }
         else if (current is IPointerTypeReference)
         {
             // The target type is itself an pointer type, and we must visit *its* target type.
             // Iterate rather than recursing.
             current = ((IPointerTypeReference)current).GetTargetType(Context);
             continue;
         }
         else
         {
             // The target type is not an pointer type and we must visit its children.
             // Dispatch the type in order to visit its children.
             DispatchAsReference(current);
             return;
         }
     }
 }
示例#27
0
 public override void Visit(IPointerTypeReference pointerTypeReference)
 {
     allElements.Add(new InvokInfo(Traverser, "IPointerTypeReference", pointerTypeReference));
 }
示例#28
0
 /// <summary>
 /// Performs some computation with the given pointer type reference.
 /// </summary>
 public virtual void Visit(IPointerTypeReference pointerTypeReference)
 {
 }
示例#29
0
        internal static string TypeDefinition(IUnit currentUnit, ITypeDefinition typeDefinition)
        {
            if (typeDefinition == Dummy.Type)
            {
                return("###DummyType###");
            }
            PrimitiveTypeCode ptc = typeDefinition.TypeCode;

            switch (ptc)
            {
            case PrimitiveTypeCode.Boolean:
                return("bool");

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

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

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

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

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

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

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

            case PrimitiveTypeCode.IntPtr:
                return("native int");

            case PrimitiveTypeCode.UInt8:
                return("unsigned int8");

            case PrimitiveTypeCode.UInt16:
                return("unsigned int16");

            case PrimitiveTypeCode.UInt32:
                return("unsigned int32");

            case PrimitiveTypeCode.UInt64:
                return("unsigned int64");

            case PrimitiveTypeCode.UIntPtr:
                return("native unsigned int");

            case PrimitiveTypeCode.Void:
                return("void");
            }
            INamespaceTypeDefinition namespaceType = typeDefinition as INamespaceTypeDefinition;

            if (namespaceType != null)
            {
                bool          wasRoot;
                StringBuilder sb = new StringBuilder(Helper.ModuleQualifiedUnitNamespace(currentUnit, (IUnitNamespace)namespaceType.ContainingNamespace, out wasRoot));
                if (!wasRoot)
                {
                    sb.Append(".");
                }
                sb.Append(namespaceType.Name.Value);
                if (namespaceType.GenericParameterCount != 0)
                {
                    sb.Append("`");
                    sb.Append(namespaceType.GenericParameterCount);
                }
                return(sb.ToString());
            }
            INestedTypeDefinition nestedTypeDefinition = typeDefinition as INestedTypeDefinition;

            if (nestedTypeDefinition != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, nestedTypeDefinition.ContainingTypeDefinition));
                sb.Append("/");
                sb.Append(nestedTypeDefinition.Name.Value);
                if (nestedTypeDefinition.GenericParameterCount != 0)
                {
                    sb.Append("`");
                    sb.Append(nestedTypeDefinition.GenericParameterCount);
                }
                return(sb.ToString());
            }
            IGenericTypeInstanceReference genericTypeInstance = typeDefinition as IGenericTypeInstanceReference;

            if (genericTypeInstance != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, genericTypeInstance.GenericType.ResolvedType));
                sb.Append("<");
                bool isNotFirst = false;
                foreach (ITypeReference typeReference in genericTypeInstance.GenericArguments)
                {
                    if (isNotFirst)
                    {
                        sb.Append(",");
                    }
                    isNotFirst = true;
                    sb.Append(Helper.TypeDefinition(currentUnit, typeReference.ResolvedType));
                }
                sb.Append(">");
                return(sb.ToString());
            }
            IPointerTypeReference pointerType = typeDefinition as IPointerTypeReference;

            if (pointerType != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, pointerType.TargetType.ResolvedType));
                sb.Append("*");
                return(sb.ToString());
            }
            IArrayTypeReference arrayType = typeDefinition as IArrayTypeReference;

            if (arrayType != null)
            {
                StringBuilder sb = new StringBuilder(Helper.TypeDefinition(currentUnit, arrayType.ElementType.ResolvedType));
                sb.Append("[");
                if (!arrayType.IsVector)
                {
                    if (arrayType.Rank == 1)
                    {
                        sb.Append("*");
                    }
                    else
                    {
                        for (int i = 1; i < arrayType.Rank; ++i)
                        {
                            sb.Append(",");
                        }
                    }
                }
                sb.Append("]");
                return(sb.ToString());
            }
            IGenericTypeParameter genericTypeParameter = typeDefinition as IGenericTypeParameter;

            if (genericTypeParameter != null)
            {
                return("!" + genericTypeParameter.Index);
            }
            IGenericMethodParameter genericMethodParameter = typeDefinition as IGenericMethodParameter;

            if (genericMethodParameter != null)
            {
                return("!!" + genericMethodParameter.Index);
            }
            return("!?!ErrorType!?!");
        }
示例#30
0
 /// <summary>
 /// Traverses the children of the pointer type reference.
 /// </summary>
 public virtual void TraverseChildren(IPointerTypeReference pointerTypeReference)
 {
     Contract.Requires(pointerTypeReference != null);
       this.TraverseChildren((ITypeReference)pointerTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(pointerTypeReference.TargetType);
 }
 /// <summary>
 /// Performs some computation with the given pointer type reference.
 /// </summary>
 public virtual void Visit(IPointerTypeReference pointerTypeReference)
 {
 }
示例#32
0
 /// <summary>
 /// Performs some computation with the given pointer type reference.
 /// </summary>
 public void Visit(IPointerTypeReference pointerTypeReference)
 {
     this.Visit((ITypeReference)pointerTypeReference);
 }
示例#33
0
 public virtual void onMetadataElement(IPointerTypeReference pointerTypeReference)
 {
 }
示例#34
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;
            }
        }
        public override void TraverseChildren(IPointerTypeReference pointerTypeReference)
{ MethodEnter(pointerTypeReference);
            base.TraverseChildren(pointerTypeReference);
     MethodExit();   }
 public virtual void onMetadataElement(IPointerTypeReference pointerTypeReference) { }
示例#37
0
 public void Visit(IPointerTypeReference pointerTypeReference)
 {
     throw new NotImplementedException();
 }
示例#38
0
        private static void WriteType(ITypeReference type, TextWriter writer, bool omitOutermostTypeFormals)
        {
            Contract.Requires(type != null);
            Contract.Requires(writer != null);

            IArrayType array = type as IArrayType;

            if (array != null)
            {
                Contract.Assume(array.ElementType != null, "lack of CCI2 contracts");

                WriteType(array.ElementType, writer);
                writer.Write("[");
                if (array.Rank > 1)
                {
                    for (int i = 0; i < array.Rank; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(",");
                        }
                        writer.Write("0:");
                    }
                }
                writer.Write("]");
                return;
            }

            IManagedPointerTypeReference reference = type as IManagedPointerTypeReference;;

            if (reference != null)
            {
                Contract.Assume(reference.TargetType != null, "lack of CCI2 contracts");

                var referencedType = reference.TargetType;
                WriteType(referencedType, writer);
                writer.Write("@");
                return;
            }

            IPointerTypeReference pointer = type as IPointerTypeReference;

            if (pointer != null)
            {
                Contract.Assume(pointer.TargetType != null, "lack of CCI2 contracts");

                WriteType(pointer.TargetType, writer);
                writer.Write("*");
                return;
            }

            IModifiedTypeReference modref = type as IModifiedTypeReference;

            if (modref != null)
            {
                Contract.Assume(modref.UnmodifiedType != null, "lack of CCI2 contracts");
                Contract.Assume(modref.CustomModifiers != null, "lack of CCI2 contracts");

                WriteType(modref.UnmodifiedType, writer);
                foreach (var modifier in modref.CustomModifiers)
                {
                    Contract.Assume(modifier != null, "lack of collection contracts and CCI2 contracts");
                    Contract.Assume(modifier.Modifier != null, "lack of CCI2 contracts");

                    if (modifier.IsOptional)
                    {
                        writer.Write("!");
                    }
                    else
                    {
                        writer.Write("|");
                    }
                    WriteType(modifier.Modifier, writer);
                }
                return;
            }

            IGenericTypeParameterReference gtp = type as IGenericTypeParameterReference;

            if (gtp != null)
            {
                writer.Write("`");
                writer.Write(gtp.Index);
                return;
            }
            IGenericMethodParameterReference gmp = type as IGenericMethodParameterReference;

            if (gmp != null)
            {
                writer.Write("``");
                writer.Write(gmp.Index);
                return;
            }

            IGenericTypeInstanceReference instance = type as IGenericTypeInstanceReference;

            if (instance != null)
            {
                Contract.Assume(instance.GenericType != null, "lack of CCI2 contracts");
                Contract.Assume(instance.GenericArguments != null, "lack of CCI2 contracts");

                WriteType(instance.GenericType, writer, true);
                writer.Write("{");
                var first = true;
                foreach (var arg in instance.GenericArguments)
                {
                    Contract.Assume(arg != null, "lack of collection and CCI2 contracts");

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        writer.Write(",");
                    }
                    WriteType(arg, writer);
                }
                writer.Write("}");
                return;
            }

            // namespace or nested
            INamedTypeReference  named  = (INamedTypeReference)type;
            INestedTypeReference nested = type as INestedTypeReference;

            if (nested != null)
            {
                Contract.Assume(nested.ContainingType != null, "lack of CCI2 contracts");

                // names of nested types begin with outer type name
                WriteType(nested.ContainingType, writer);
                writer.Write(".");
                // continue to write type sig
            }

            INamespaceTypeReference nt = type as INamespaceTypeReference;

            if (nt != null)
            {
                Contract.Assume(nt.ContainingUnitNamespace != null, "lack of CCI2 contracts");

                WriteNamespaceAndSeparator(nt.ContainingUnitNamespace, writer);
                // continue to write type sig
            }
            // name
            writer.Write(named.Name.Value);
            // generic parameters
            if (omitOutermostTypeFormals)
            {
                return;
            }

            if (named.GenericParameterCount > 0)
            {
                writer.Write("`{0}", named.GenericParameterCount);
            }
        }
示例#39
0
 /// <summary>
 /// Traverses the children of the pointer type reference.
 /// </summary>
 public virtual void TraverseChildren(IPointerTypeReference pointerTypeReference)
 {
     this.TraverseChildren((ITypeReference)pointerTypeReference);
       if (this.stopTraversal) return;
       this.Traverse(pointerTypeReference.TargetType);
 }