Ejemplo n.º 1
0
        protected override void ScanCore(MemberImportingOptions options, List<MemberImporter> importList)
        {
            //Type
            var type = (TypeSpecification)Member;

            //Checks if the type is a generic instance type
            MemberImporter importer;
            if (type is GenericInstanceType)
            {
                importer = new GenericInstanceTypeImporter(type, Session.Destination, Session).Scan(options);
                importList.Add(importer);
                importer.ImportFinished += t => retType = (TypeSpecification)t;
                return;
            }

            //Creates the importer for the element type
            importer = Helpers.CreateTypeImporter(type.ElementType, Session, importList, options);

            //Switches on the metadata type of the specification
            switch (type.MetadataType)
            {
                case MetadataType.Pointer:
                    importer.ImportFinished += t => retType = new PointerType((TypeReference)t);
                    break;
                case MetadataType.ByReference:
                    importer.ImportFinished += t => retType = new ByReferenceType((TypeReference)t);
                    break;
                default:
                    throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        private static bool AreSame(TypeSpecification a, TypeSpecification b)
        {
            if (!TypeMatch(a.ElementType, b.ElementType))
                return false;

            if (a.IsGenericInstance)
            {
                if (!b.IsGenericInstance)
                    return false;

                return AreSame((GenericInstanceType)a, (GenericInstanceType)b);
            }

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return AreSame((IModifierType)a, (IModifierType)b);

            if (a.IsArray)
            {
                if (!b.IsArray)
                    return false;

                return AreSame((ArrayType)a, (ArrayType)b);
            }

            return true;
        }
Ejemplo n.º 3
0
        static bool TypeMatch(TypeSpecification a, TypeSpecification b)
        {
            if (a.IsGenericInstance)
                return TypeMatch((GenericInstanceType)a, (GenericInstanceType)b);

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return TypeMatch((IModifierType)a, (IModifierType)b);

            return TypeMatch(a.ElementType, b.ElementType);
        }
Ejemplo n.º 4
0
        static bool TypeMatch(TypeSpecification a, TypeSpecification b, ref Dictionary<string, string> gp)
        {
            var gita = a as GenericInstanceType;
            if (gita != null)
                return TypeMatch(gita, (GenericInstanceType)b, ref gp);

            var mta = a as IModifierType;
            if (mta != null)
                return TypeMatch(mta, (IModifierType)b, ref gp);

            return TypeMatch(a.ElementType, b.ElementType, ref gp);
        }
		private void UpdateSpecification(bool allow, TypeSpecification specification)
		{
			foreach (var tslevel in new[] {TypeSpecificationL1, TypeSpecificationL2, TypeSpecificationL3})
			{
				if (allow && !tslevel.Items.Contains(specification))
				{
					tslevel.Items.Add(specification);
				}
				else if (!allow && tslevel.Items.Contains(specification))
				{
					tslevel.Items.Remove(specification);
				}
			}
		}
Ejemplo n.º 6
0
 public static bool IsEqualTo(this TypeSpecification a, TypeSpecification b)
 {
     if (!IsEqualTo(a.ElementType, b.ElementType)) {
         return false;
     }
     if (a.IsGenericInstance) {
         return IsEqualTo((GenericInstanceType)a, (GenericInstanceType)b);
     }
     if (a.IsRequiredModifier || a.IsOptionalModifier) {
         return IsEqualTo((IModifierType)a, (IModifierType)b);
     }
     if (a.IsArray) {
         return IsEqualTo((ArrayType)a, (ArrayType)b);
     }
     return true;
 }
Ejemplo n.º 7
0
        internal bool AreSame(TypeSpecification a, TypeSpecification b)
        {
            if (!AreSame(a.ElementType, b.ElementType))
                return false;

            if (a.IsGenericInstance)
                return AreSame((GenericInstanceType)a, (GenericInstanceType)b);

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return AreSame((IModifierType)a, (IModifierType)b);

            if (a.IsArray)
                return AreSame((ArrayType)a, (ArrayType)b);

            return true;
        }
		TypeSpecification GetTypeSpec (TypeSpecification original, ImportContext context)
		{
			TypeSpecification typeSpec;

			TypeReference elementType = ImportTypeReference (original.ElementType, context);
			if (original is PointerType) {
				typeSpec = new PointerType (elementType);
			} else if (original is ArrayType) { // deal with complex arrays
				typeSpec = new ArrayType (elementType);
			} else if (original is ReferenceType) {
				typeSpec = new ReferenceType (elementType);
			} else if (original is GenericInstanceType) {
				GenericInstanceType git = original as GenericInstanceType;
				GenericInstanceType genElemType = new GenericInstanceType (elementType);

				context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);
				foreach (TypeReference arg in git.GenericArguments)
					genElemType.GenericArguments.Add (ImportTypeReference (arg, context));

				typeSpec = genElemType;
			} else if (original is ModifierOptional) {
				TypeReference mt = (original as ModifierOptional).ModifierType;
				typeSpec = new ModifierOptional (elementType, ImportTypeReference (mt, context));
			} else if (original is ModifierRequired) {
				TypeReference mt = (original as ModifierRequired).ModifierType;
				typeSpec = new ModifierRequired (elementType, ImportTypeReference (mt, context));
			} else if (original is SentinelType) {
				typeSpec = new SentinelType (elementType);
			} else if (original is FunctionPointerType) {
				FunctionPointerType ori = original as FunctionPointerType;

				FunctionPointerType fnptr = new FunctionPointerType (
					ori.HasThis,
					ori.ExplicitThis,
					ori.CallingConvention,
					new MethodReturnType (ImportTypeReference (ori.ReturnType.ReturnType, context)));

				foreach (ParameterDefinition parameter in ori.Parameters)
					fnptr.Parameters.Add (new ParameterDefinition (ImportTypeReference (parameter.ParameterType, context)));

				typeSpec = fnptr;
			} else
				throw new ReflectionException ("Unknown element type: {0}", original.GetType ().Name);

			return typeSpec;
		}
Ejemplo n.º 9
0
        static bool AreSame(TypeSpecification a, TypeSpecification b)
        {
            if (!AreSame(a.ElementType, b.ElementType))
            {
                return(false);
            }

            if (a.IsGenericInstance)
            {
                return(AreSame((GenericInstanceType)a, (GenericInstanceType)b));
            }

            if (a.IsRequiredModifier || a.IsOptionalModifier)
            {
                return(AreSame((IModifierType)a, (IModifierType)b));
            }

            if (a.IsArray)
            {
                return(AreSame((ArrayType)a, (ArrayType)b));
            }

            return(true);
        }
        internal Type ResolveTypeSpecification(TypeSpecification typeSpecification)
        {
            Type elementType = ResolveType(typeSpecification.ElementType);

            ArrayType arrayType = typeSpecification as ArrayType;
            if (arrayType != null)
            {
                if (arrayType.IsSizedArray)
                    return elementType.MakeArrayType();

                return elementType.MakeArrayType(arrayType.Rank);
            }

            GenericInstanceType genericInstanceType = typeSpecification as GenericInstanceType;
            if (genericInstanceType != null)
            {
                Type[] args = ResolveTypes(genericInstanceType.GenericArguments);
                return elementType.MakeGenericType(args);
            }

            ReferenceType referenceType = typeSpecification as ReferenceType;
            if (referenceType != null)
            {
                return elementType.MakeByRefType();
            }

            PointerType pointerType = typeSpecification as PointerType;
            if (pointerType != null)
            {
                return elementType.MakePointerType();
            }

            FunctionPointerType functionPointerType = typeSpecification as FunctionPointerType;
            PinnedType pinnedType = typeSpecification as PinnedType;
            ModifierOptional modifierOptional = typeSpecification as ModifierOptional;
            ModifierRequired modifierRequired = typeSpecification as ModifierRequired;
            SentinelType sentinelType = typeSpecification as SentinelType;
            throw new NotImplementedException();
        }
Ejemplo n.º 11
0
        TypeSpecification GetTypeSpec(TypeSpecification original, ImportContext context)
        {
            TypeSpecification typeSpec;

            TypeReference elementType = ImportTypeReference(original.ElementType, context);

            if (original is PointerType)
            {
                typeSpec = new PointerType(elementType);
            }
            else if (original is ArrayType)                 // deal with complex arrays
            {
                typeSpec = new ArrayType(elementType);
            }
            else if (original is ReferenceType)
            {
                typeSpec = new ReferenceType(elementType);
            }
            else if (original is GenericInstanceType)
            {
                GenericInstanceType git         = original as GenericInstanceType;
                GenericInstanceType genElemType = new GenericInstanceType(elementType);

                context.GenericContext.CheckProvider(genElemType.GetOriginalType(), git.GenericArguments.Count);
                foreach (TypeReference arg in git.GenericArguments)
                {
                    genElemType.GenericArguments.Add(ImportTypeReference(arg, context));
                }

                typeSpec = genElemType;
            }
            else if (original is ModifierOptional)
            {
                TypeReference mt = (original as ModifierOptional).ModifierType;
                typeSpec = new ModifierOptional(elementType, ImportTypeReference(mt, context));
            }
            else if (original is ModifierRequired)
            {
                TypeReference mt = (original as ModifierRequired).ModifierType;
                typeSpec = new ModifierRequired(elementType, ImportTypeReference(mt, context));
            }
            else if (original is SentinelType)
            {
                typeSpec = new SentinelType(elementType);
            }
            else if (original is FunctionPointerType)
            {
                FunctionPointerType ori = original as FunctionPointerType;

                FunctionPointerType fnptr = new FunctionPointerType(
                    ori.HasThis,
                    ori.ExplicitThis,
                    ori.CallingConvention,
                    new MethodReturnType(ImportTypeReference(ori.ReturnType.ReturnType, context)));

                foreach (ParameterDefinition parameter in ori.Parameters)
                {
                    fnptr.Parameters.Add(new ParameterDefinition(ImportTypeReference(parameter.ParameterType, context)));
                }

                typeSpec = fnptr;
            }
            else
            {
                throw new ReflectionException("Unknown element type: {0}", original.GetType().Name);
            }

            return(typeSpec);
        }
Ejemplo n.º 12
0
        private static void AppendTypeSpecification(TypeSpecification type, StringBuilder name)
        {
            ArrayType     arrayType;
            int           i;
            StringBuilder stringBuilder;
            StringBuilder stringBuilder1;
            StringBuilder stringBuilder2;
            StringBuilder stringBuilder3;

            if (type.ElementType.IsTypeSpecification())
            {
                TypeParser.AppendTypeSpecification((TypeSpecification)type.ElementType, name);
            }
            ElementType elementType = type.etype;

            switch (elementType)
            {
            case ElementType.Ptr:
            {
                name.Append('*');
                return;
            }

            case ElementType.ByRef:
            {
                name.Append('&');
                return;
            }

            case ElementType.ValueType:
            case ElementType.Class:
            case ElementType.Var:
            {
                return;
            }

            case ElementType.Array:
            {
                arrayType = (ArrayType)type;
                if (arrayType.IsVector)
                {
                    stringBuilder = name.Append("[]");
                    return;
                }
                stringBuilder1 = name.Append('[');
                for (i = 1; i < arrayType.Rank; i++)
                {
                    stringBuilder2 = name.Append(',');
                }
                stringBuilder3 = name.Append(']');
                return;
            }

            case ElementType.GenericInst:
            {
                Collection <TypeReference> genericArguments = ((GenericInstanceType)type).GenericArguments;
                name.Append('[');
                for (int j = 0; j < genericArguments.Count; j++)
                {
                    if (j > 0)
                    {
                        name.Append(',');
                    }
                    TypeReference item  = genericArguments[j];
                    bool          scope = item.Scope != item.Module;
                    if (scope)
                    {
                        name.Append('[');
                    }
                    TypeParser.AppendType(item, name, true, false);
                    if (scope)
                    {
                        name.Append(']');
                    }
                }
                name.Append(']');
                return;
            }

            default:
            {
                if (elementType == ElementType.SzArray)
                {
                    arrayType = (ArrayType)type;
                    if (arrayType.IsVector)
                    {
                        stringBuilder = name.Append("[]");
                        return;
                    }
                    stringBuilder1 = name.Append('[');
                    for (i = 1; i < arrayType.Rank; i++)
                    {
                        stringBuilder2 = name.Append(',');
                    }
                    stringBuilder3 = name.Append(']');
                    return;
                }
                return;
            }
            }
        }
		private void UpdateSpecification(bool allow, TypeSpecification specification)
		{
			if (allow && !TypeSpecification.Items.Contains(specification))
			{
				TypeSpecification.Items.Add(specification);
			}
			else if (!allow && TypeSpecification.Items.Contains(specification))
			{
				TypeSpecification.Items.Remove(specification);
			}
		}
Ejemplo n.º 14
0
        private TypeSpecification Fix(TypeSpecification type, IGenericParameterProvider context)
        {
            var fet = Fix(type.ElementType, context);
            if (type is ArrayType)
            {
                var array = (ArrayType)type;
                var imported_array = new ArrayType(fet);
                if (array.IsVector)
                    return imported_array;

                var dimensions = array.Dimensions;
                var imported_dimensions = imported_array.Dimensions;

                imported_dimensions.Clear();

                for (int i = 0; i < dimensions.Count; i++)
                {
                    var dimension = dimensions[i];

                    imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound));
                }

                return imported_array;
            }
            if (type is PointerType)
                return new PointerType(fet);
            if (type is ByReferenceType)
                return new ByReferenceType(fet);
            if (type is PinnedType)
                return new PinnedType(fet);
            if (type is SentinelType)
                return new SentinelType(fet);
            if (type is OptionalModifierType)
            {
                TypeReference fmt = Fix(((OptionalModifierType)type).ModifierType, context);
                return new OptionalModifierType(fmt, fet);
            }
            if (type is RequiredModifierType)
            {
                TypeReference fmt = Fix(((RequiredModifierType)type).ModifierType);
                return new RequiredModifierType(fmt, fet);
            }
            if (type is GenericInstanceType)
            {
                var instance = (GenericInstanceType)type;
                var imported_instance = new GenericInstanceType(fet);

                var arguments = instance.GenericArguments;
                var imported_arguments = imported_instance.GenericArguments;

                for (int i = 0; i < arguments.Count; i++)
                    imported_arguments.Add(Fix(arguments[i], context));

                return imported_instance;
            }
            // TODO: what about FunctionPointerType?
            throw new InvalidOperationException();
        }
        protected override void WriteTypeSpecification(TypeSpecification typeSpecification, int startingArgument = 0)
        {
            if (isDynamicEnumerator != null && !typeSpecification.IsGenericInstance)
            {
                if (typeSpecification.IsArray)
                {
                    TypeReference currentTypeRef = typeSpecification;
                    while (currentTypeRef.IsArray)
                    {
                        if (!isDynamicEnumerator.MoveNext() || (bool)isDynamicEnumerator.Current)
                        {
                            throw new Exception("Invalid argument type for DynamicAttribute");
                        }
                        currentTypeRef = (currentTypeRef as ArrayType).ElementType;
                    }
                }
                else if (!isDynamicEnumerator.MoveNext() || (bool)isDynamicEnumerator.Current)
                {
                    throw new Exception("Invalid argument type for DynamicAttribute");
                }
            }

            if (typeSpecification.IsRequiredModifier || typeSpecification.IsOptionalModifier)
            {
                WriteModifier(typeSpecification);
                return;
            }

            base.WriteTypeSpecification(typeSpecification, startingArgument);
        }
Ejemplo n.º 16
0
		static bool TypeMatch (TypeSpecification a, TypeSpecification b)
		{
			var gita = a as GenericInstanceType;
			if (gita != null)
				return TypeMatch (gita, (GenericInstanceType) b);

			var mta = a as IModifierType;
			if (mta != null)
				return TypeMatch (mta, (IModifierType) b);

			return TypeMatch (a.ElementType, b.ElementType);
		}
Ejemplo n.º 17
0
 public TypeSpecificationImporter(TypeSpecification type, MemberImportingSession session)
     : base(type, session)
 {
 }
Ejemplo n.º 18
0
 private static MemberReference ElementTypeFor(TypeSpecification genericInstanceType)
 {
     return genericInstanceType.ElementType;
 }
Ejemplo n.º 19
0
        static bool IsMatch(TypeSpecification a, TypeSpecification b)
        {
            if (a is GenericInstanceType) {
            return IsMatch((GenericInstanceType)a, (GenericInstanceType)b);
              }

              return IsMatch(a.ElementType, b.ElementType);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Is type a the same as type b?
        /// </summary>
        public static bool AreSame(this TypeSpecification a, TypeSpecification b, Func<GenericParameter, TypeReference> genericParamResolver)
        {
            if (!AreSame(a.ElementType, b.ElementType, genericParamResolver))
                return false;

            if (a.IsGenericInstance)
                return AreSame((GenericInstanceType)a, (GenericInstanceType)b, genericParamResolver);

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return AreSame((IModifierType)a, (IModifierType)b, genericParamResolver);

            if (a.IsArray)
                return AreSame((ArrayType)a, (ArrayType)b);

            return true;
        }
Ejemplo n.º 21
0
 static bool compareTypeSpecifications(TypeSpecification a, TypeSpecification b)
 {
     // It overrides everything of importance in TypeReference. The only thing to check
     // is the ElementType.
     return compareTypes(a.ElementType, b.ElementType);
 }
Ejemplo n.º 22
0
 static int typeSpecificationHashCode(TypeSpecification a)
 {
     if (a == null)
         return 0;
     return typeHashCode(a.ElementType);
 }
Ejemplo n.º 23
0
        public static bool TypeMatch(TypeSpecification a, TypeSpecification b)
        {
            if (a is GenericInstanceType)
                return TypeMatch ((GenericInstanceType) a, (GenericInstanceType) b);

            if (a is IModifierType)
                return TypeMatch ((IModifierType) a, (IModifierType) b);

            return TypeMatch (a.ElementType, b.ElementType);
        }
Ejemplo n.º 24
0
        public static bool IsSameType(TypeSpecification a, TypeSpecification b, bool genericMatch)
        {
            if (!IsSameType(a.ElementType, b.ElementType, genericMatch))
                return false;

            if (a.IsGenericInstance)
                return IsSameType((GenericInstanceType)a, (GenericInstanceType)b, genericMatch);

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return IsSameType((IModifierType)a, (IModifierType)b, genericMatch);

            if (a.IsArray)
                return IsSameType((ArrayType)a, (ArrayType)b, genericMatch);

            return true;
        }
Ejemplo n.º 25
0
        public static bool AreSame(TypeSpecification a, TypeSpecification b)
        {
            if (a is GenericInstanceType)
                return AreSame ((GenericInstanceType) a, (GenericInstanceType) b);

            if (a is ModType)
                return AreSame ((ModType) a, (ModType) b);

            return AreSame (a.ElementType, b.ElementType);
        }
Ejemplo n.º 26
0
        private static void AppendTypeSpecification(TypeSpecification type, StringBuilder name)
        {
            if (type.ElementType.IsTypeSpecification())
            {
                AppendTypeSpecification((TypeSpecification)type.ElementType, name);
            }
            switch (type.etype)
            {
            case ElementType.Ptr:
                name.Append('*');
                break;

            case ElementType.ByRef:
                name.Append('&');
                break;

            case ElementType.Array:
            case ElementType.SzArray:
            {
                ArrayType arrayType = (ArrayType)type;
                if (arrayType.IsVector)
                {
                    name.Append("[]");
                }
                else
                {
                    name.Append('[');
                    for (int j = 1; j < arrayType.Rank; j++)
                    {
                        name.Append(',');
                    }
                    name.Append(']');
                }
                break;
            }

            case ElementType.GenericInst:
            {
                Collection <TypeReference> genericArguments = ((GenericInstanceType)type).GenericArguments;
                name.Append('[');
                for (int i = 0; i < genericArguments.Count; i++)
                {
                    if (i > 0)
                    {
                        name.Append(',');
                    }
                    TypeReference typeReference = genericArguments[i];
                    bool          num           = typeReference.Scope != typeReference.Module;
                    if (num)
                    {
                        name.Append('[');
                    }
                    AppendType(typeReference, name, true, false);
                    if (num)
                    {
                        name.Append(']');
                    }
                }
                name.Append(']');
                break;
            }
            }
        }
Ejemplo n.º 27
0
        static void AppendTypeSpecification(TypeSpecification type, StringBuilder name)
        {
            if (type.ElementType.IsTypeSpecification())
            {
                AppendTypeSpecification((TypeSpecification)type.ElementType, name);
            }

            switch (type.etype)
            {
            case ElementType.Ptr:
                name.Append('*');
                break;

            case ElementType.ByRef:
                name.Append('&');
                break;

            case ElementType.SzArray:
            case ElementType.Array:
                var array = (ArrayType)type;
                if (array.IsVector)
                {
                    name.Append("[]");
                }
                else
                {
                    name.Append('[');
                    for (int i = 1; i < array.Rank; i++)
                    {
                        name.Append(',');
                    }
                    name.Append(']');
                }
                break;

            case ElementType.GenericInst:
                var instance  = (GenericInstanceType)type;
                var arguments = instance.GenericArguments;

                name.Append('[');

                for (int i = 0; i < arguments.Count; i++)
                {
                    if (i > 0)
                    {
                        name.Append(',');
                    }

                    var argument        = arguments [i];
                    var requires_fqname = argument.Scope != argument.Module;

                    if (requires_fqname)
                    {
                        name.Append('[');
                    }

                    AppendType(argument, name, true, false);

                    if (requires_fqname)
                    {
                        name.Append(']');
                    }
                }

                name.Append(']');
                break;

            default:
                return;
            }
        }
        private void WriteModifier(TypeSpecification typeSpecification)
        {
            StringBuilder sb = new StringBuilder();
            TypeReference elementType = typeSpecification;
            IModifierType currentType = typeSpecification as IModifierType;
            bool wroteModifier = false;
            while (currentType != null)
            {
                if (currentType.ModifierType.FullName == "System.Runtime.CompilerServices.IsVolatile")
                {
                    elementType = currentType.ElementType;
                    currentType = elementType as IModifierType;
                    continue;
                }

                if (wroteModifier)
                {
                    sb.Append(", ");
                }

                sb.Append(currentType is RequiredModifierType ? "modreq" : "modopt");
                sb.Append("(");
                sb.Append(currentType.ModifierType.FullName);
                sb.Append(")");
                wroteModifier = true;

                elementType = currentType.ElementType;
                currentType = elementType as IModifierType;
            }

            if (wroteModifier)
            {
                WriteCommentBlock(sb.ToString());
                WriteSpace();
            }

            WriteReferenceAndNamespaceIfInCollision(elementType);
        }
Ejemplo n.º 29
0
 private static bool AreSame(TypeSpecification a, TypeSpecification b) =>
 (AreSame(a.ElementType, b.ElementType) ? (!a.IsGenericInstance ? ((a.IsRequiredModifier || a.IsOptionalModifier) ? AreSame((IModifierType)a, (IModifierType)b) : (!a.IsArray || AreSame((ArrayType)a, (ArrayType)b))) : AreSame((GenericInstanceType)a, (GenericInstanceType)b)) : false);
		static string ToString (TypeSpecification specification)
		{
			var pointer = specification as PointerType;
			if (pointer != null)
				return ToString (specification.ElementType) + "*";

			var reference = specification as ByReferenceType;
			if (reference != null)
				return ToString (specification.ElementType) + "&";

			var array = specification as ArrayType;
			if (array != null)
				return ToString (specification.ElementType) + "[]";

			var generic = specification as GenericInstanceType;
			if (generic != null)
				return ToString (generic);

			throw new NotSupportedException ();
		}
Ejemplo n.º 31
0
        private static void AppendTypeSpecification(TypeSpecification type, StringBuilder name)
        {
            ArrayType type2;

            if (type.ElementType.IsTypeSpecification())
            {
                AppendTypeSpecification((TypeSpecification)type.ElementType, name);
            }
            ElementType etype = type.etype;

            switch (etype)
            {
            case ElementType.Ptr:
                name.Append('*');
                return;

            case ElementType.ByRef:
                name.Append('&');
                return;

            case ElementType.ValueType:
            case ElementType.Class:
            case ElementType.Var:
                break;

            case ElementType.Array:
                goto TR_0007;

            case ElementType.GenericInst:
            {
                Collection <TypeReference> genericArguments = ((GenericInstanceType)type).GenericArguments;
                name.Append('[');
                int num2 = 0;
                while (true)
                {
                    if (num2 >= genericArguments.Count)
                    {
                        name.Append(']');
                        break;
                    }
                    if (num2 > 0)
                    {
                        name.Append(',');
                    }
                    TypeReference reference = genericArguments[num2];
                    bool          flag      = !ReferenceEquals(reference.Scope, reference.Module);
                    if (flag)
                    {
                        name.Append('[');
                    }
                    AppendType(reference, name, true, false);
                    if (flag)
                    {
                        name.Append(']');
                    }
                    num2++;
                }
                break;
            }

            default:
                if (etype != ElementType.SzArray)
                {
                    return;
                }
                goto TR_0007;
            }
            return;

TR_0007:
            type2 = (ArrayType)type;
            if (type2.IsVector)
            {
                name.Append("[]");
            }
            else
            {
                name.Append('[');
                for (int i = 1; i < type2.Rank; i++)
                {
                    name.Append(',');
                }
                name.Append(']');
            }
        }
Ejemplo n.º 32
0
        private TypeSpecification Fix(TypeSpecification type)
        {
            var fet = Fix(type.ElementType);
            if (type is ArrayType)
            {
                var array = (ArrayType)type;
                var imported_array = new ArrayType(fet);
                if (array.IsVector)
                    return imported_array;

                var dimensions = array.Dimensions;
                var imported_dimensions = imported_array.Dimensions;

                imported_dimensions.Clear();

                for (int i = 0; i < dimensions.Count; i++)
                {
                    var dimension = dimensions[i];

                    imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound));
                }

                return imported_array;
            }
            if (type is PointerType)
                return new PointerType(fet);
            if (type is ByReferenceType)
                return new ByReferenceType(fet);
            if (type is PinnedType)
                return new PinnedType(fet);
            if (type is SentinelType)
                return new SentinelType(fet);
            if (type is OptionalModifierType)
            {
                TypeReference fmt = Fix(((OptionalModifierType)type).ModifierType);
                return new OptionalModifierType(fmt, fet);
            }
            if (type is RequiredModifierType)
            {
                TypeReference fmt = Fix(((RequiredModifierType)type).ModifierType);
                return new RequiredModifierType(fmt, fet);
            }
            if (type is GenericInstanceType)
            {
                var instance = (GenericInstanceType)type;
                var imported_instance = new GenericInstanceType(fet);

                var arguments = instance.GenericArguments;
                var imported_arguments = imported_instance.GenericArguments;

                for (int i = 0; i < arguments.Count; i++)
                    imported_arguments.Add(Fix(arguments[i]));

                return imported_instance;
            }
            if (type is FunctionPointerType)
            {
                var funcPtr = (FunctionPointerType)type;
                var imported_instance = new FunctionPointerType()
                {
                    HasThis = funcPtr.HasThis,
                    ExplicitThis = funcPtr.ExplicitThis,
                    CallingConvention = funcPtr.CallingConvention,
                    ReturnType = Fix(funcPtr.ReturnType)
                };
                if (funcPtr.HasParameters)
                {
                    foreach (var pd in funcPtr.Parameters)
                    {
                        imported_instance.Parameters.Add(pd);
                    }
                    FixReferences(imported_instance.Parameters);
                }
                return imported_instance;
            }
            throw new InvalidOperationException();
        }
Ejemplo n.º 33
0
        public static bool AreSame(TypeSpecification a, TypeSpecification b)
        {
            if (a.IsGenericInstance)
                return AreSame((GenericInstanceType)a, (GenericInstanceType)b);

            if (a.IsRequiredModifier || a.IsOptionalModifier)
                return AreSame((IModifierType)a, (IModifierType)b);

            if (a.IsArray)
                return AreSame((ArrayType)a, (ArrayType)b);

            return AreSame(a.ElementType, b.ElementType);
        }
Ejemplo n.º 34
0
 void addTypeSpecification(TypeSpecification ts)
 {
     if (ts == null)
         return;
     addTypeReference(ts);
     pushMember(ts.ElementType);
 }
        protected override void WriteTypeSpecification(TypeSpecification typeSpecification, int startingArgument = 0)
        {
            if ((typeSpecification.IsOptionalModifier || typeSpecification.IsRequiredModifier) && !isWritingComment)
            {
                WriteReferenceAndNamespaceIfInCollision(typeSpecification.ElementType);
                return;
            }

            base.WriteTypeSpecification(typeSpecification, startingArgument);
        }
		protected virtual void WriteTypeSpecification(TypeSpecification typeSpecification, int startingArgument = 0)
		{
			PointerType pointer = typeSpecification as PointerType;
			if (pointer != null)
			{
				WriteReference(typeSpecification.ElementType);
				WriteToken("*");
				return;
			}

			PinnedType pinnedType = typeSpecification as PinnedType;
			if (pinnedType != null)
			{
				if (typeSpecification.ElementType is ByReferenceType)
				{
					WriteReference(((typeSpecification.ElementType) as ByReferenceType).ElementType);
					WriteToken("*");
				}
				else
				{
					WriteReference(typeSpecification.ElementType);
				}
				return;
			}

			ByReferenceType reference = typeSpecification as ByReferenceType;
			if (reference != null)
			{
				WriteReference(typeSpecification.ElementType);
				WriteToken("&");
				return;
			}

			ArrayType array = typeSpecification as ArrayType;
			if (array != null)
			{
				List<int> dimentions = new List<int>();
				TypeReference elementType = typeSpecification.ElementType;
				while (elementType is ArrayType)
				{
					ArrayType ar = (elementType as ArrayType);
					dimentions.Add(ar.Dimensions.Count);
					elementType = ar.ElementType;
				}

				WriteReference(elementType);

				WriteToken(IndexLeftBracket);
				if (array.Dimensions != null)
				{
					for (int i = 1; i < array.Dimensions.Count; i++)
					{
						WriteToken(",");
					}
				}
				WriteToken(IndexRightBracket);
				foreach (int dimentionsSize in dimentions)
				{
					WriteToken(IndexLeftBracket);
					for (int i = 1; i < dimentionsSize; i++)
					{
						WriteToken(",");
					}
					WriteToken(IndexRightBracket);
				}
				return;
			}

			GenericInstanceType generic = typeSpecification as GenericInstanceType;
			if (generic != null)
			{
				if (SupportsSpecialNullable && (generic.GetFriendlyFullName(Language).IndexOf("System.Nullable<") == 0) &&
					generic.GenericArguments[0].IsValueType)
				{
					TypeReference toWrite = generic.GenericArguments[0];
					if (generic.PostionToArgument.ContainsKey(0))
					{
						toWrite = generic.PostionToArgument[0];
					}
					WriteReference(toWrite);
					WriteToken("?");
					return;
				}
				else
				{
					WriteGenericInstance(generic, startingArgument);
					return;
				}
			}

			if (typeSpecification.MetadataType == MetadataType.OptionalModifier)
			{
				Write(typeSpecification.Name);
				return;
			}

			if (typeSpecification.IsRequiredModifier)
			{
				if (isWritingComment && (typeSpecification as RequiredModifierType).ModifierType.FullName == "System.Runtime.CompilerServices.IsVolatile")
				{
					//Corner case when writing field declarations in visual basic
					WriteVolatileType(typeSpecification.ElementType);
				}
				else
				{
					WriteReference(typeSpecification.ElementType);
				}
				return;
			}

			throw new NotSupportedException();
		}
Ejemplo n.º 37
0
        public void WriteTypeSignature(TypeReference type)
        {
            if (type == null)
            {
                throw new ArgumentNullException();
            }
            ElementType etype = type.etype;

            switch (etype)
            {
            case ElementType.Var:
            case ElementType.MVar:
            {
                GenericParameter obj = (GenericParameter)type;
                WriteElementType(etype);
                int position = obj.Position;
                if (position == -1)
                {
                    throw new NotSupportedException();
                }
                base.WriteCompressedUInt32((uint)position);
                break;
            }

            case ElementType.GenericInst:
            {
                GenericInstanceType genericInstanceType = (GenericInstanceType)type;
                WriteElementType(ElementType.GenericInst);
                WriteElementType(genericInstanceType.IsValueType ? ElementType.ValueType : ElementType.Class);
                base.WriteCompressedUInt32(MakeTypeDefOrRefCodedRID(genericInstanceType.ElementType));
                WriteGenericInstanceSignature(genericInstanceType);
                break;
            }

            case ElementType.Ptr:
            case ElementType.ByRef:
            case ElementType.Sentinel:
            case ElementType.Pinned:
            {
                TypeSpecification typeSpecification = (TypeSpecification)type;
                WriteElementType(etype);
                WriteTypeSignature(typeSpecification.ElementType);
                break;
            }

            case ElementType.FnPtr:
            {
                FunctionPointerType method = (FunctionPointerType)type;
                WriteElementType(ElementType.FnPtr);
                WriteMethodSignature(method);
                break;
            }

            case ElementType.CModReqD:
            case ElementType.CModOpt:
            {
                IModifierType type2 = (IModifierType)type;
                WriteModifierSignature(etype, type2);
                break;
            }

            case ElementType.Array:
            {
                ArrayType arrayType = (ArrayType)type;
                if (!arrayType.IsVector)
                {
                    WriteArrayTypeSignature(arrayType);
                }
                else
                {
                    WriteElementType(ElementType.SzArray);
                    WriteTypeSignature(arrayType.ElementType);
                }
                break;
            }

            case ElementType.None:
                WriteElementType(type.IsValueType ? ElementType.ValueType : ElementType.Class);
                base.WriteCompressedUInt32(MakeTypeDefOrRefCodedRID(type));
                break;

            default:
                if (TryWriteElementType(type))
                {
                    break;
                }
                throw new NotSupportedException();
            }
        }