Пример #1
0
		public OptionalModifierType (TypeReference modifierType, TypeReference type)
			: base (type)
		{
			Mixin.CheckModifier (modifierType, type);
			this.modifier_type = modifierType;
			this.etype = MD.ElementType.CModOpt;
		}
Пример #2
0
		public static TypeDefinition Resolve (IAssemblyResolver resolver, TypeReference type)
		{
			type = type.GetElementType ();

			var scope = type.Scope;
			switch (scope.MetadataScopeType) {
			case MetadataScopeType.AssemblyNameReference:
				var assembly = resolver.Resolve ((AssemblyNameReference) scope);
				if (assembly == null)
					return null;

				return GetType (resolver, assembly.MainModule, type);
			case MetadataScopeType.ModuleDefinition:
				return GetType (resolver, (ModuleDefinition) scope, type);
			case MetadataScopeType.ModuleReference:
				var modules = type.Module.Assembly.Modules;
				var module_ref = (ModuleReference) scope;
				for (int i = 0; i < modules.Count; i++) {
					var netmodule = modules [i];
					if (netmodule.Name == module_ref.Name)
						return GetType (resolver, netmodule, type);
				}
				break;
			}

			throw new NotSupportedException ();
		}
Пример #3
0
		protected EventReference (string name, TypeReference eventType)
			: base (name)
		{
			if (eventType == null)
				throw new ArgumentNullException ("eventType");

			event_type = eventType;
		}
Пример #4
0
		internal ParameterReference (string name, TypeReference parameterType)
		{
			if (parameterType == null)
				throw new ArgumentNullException ("parameterType");

			this.name = name ?? string.Empty;
			this.parameter_type = parameterType;
		}
Пример #5
0
		internal PropertyReference (string name, TypeReference propertyType)
			: base (name)
		{
			if (propertyType == null)
				throw new ArgumentNullException ("propertyType");

			property_type = propertyType;
		}
Пример #6
0
		public FieldReference (string name, TypeReference fieldType, TypeReference declaringType)
			: this (name, fieldType)
		{
			if (declaringType == null)
				throw new ArgumentNullException("declaringType");

			this.DeclaringType = declaringType;
		}
Пример #7
0
		public FieldReference (string name, TypeReference fieldType)
			: base (name)
		{
			if (fieldType == null)
				throw new ArgumentNullException ("fieldType");

			this.field_type = fieldType;
			this.token = new MetadataToken (TokenType.MemberRef);
		}
Пример #8
0
		public RequiredModifierType (TypeReference modifierType, TypeReference type)
			: base (type)
		{
			Mixin.CheckModifier (modifierType, type);
			this.modifier_type = modifierType;
			this.etype = MD.ElementType.CModReqD;
		}
Пример #9
0
		public PropertyDefinition (string name, PropertyAttributes attributes, TypeReference propertyType)
			: base (name, propertyType)
		{
			this.attributes = (ushort) attributes;
			this.token = new MetadataToken (TokenType.Property);
		}
Пример #10
0
		static TypeDefinition GetType (IAssemblyResolver resolver, ModuleDefinition module, TypeReference reference)
		{
			var type = GetType (module, reference);
			if (type != null)
				return type;

			if (!module.HasExportedTypes)
				return null;

			var exported_types = module.ExportedTypes;

			for (int i = 0; i < exported_types.Count; i++) {
				var exported_type = exported_types [i];
				if (exported_type.Name != reference.Name)
					continue;

				if (exported_type.Namespace != reference.Namespace)
					continue;

				return exported_type.Resolve ();
			}

			return null;
		}
Пример #11
0
		public TypeDefinition (string @namespace, string name, TypeAttributes attributes, TypeReference baseType) :
			this (@namespace, name, attributes)
		{
			this.BaseType = baseType;
		}
Пример #12
0
		public TypeReference ImportType (TypeReference type, IGenericContext context)
		{
			if (type.IsTypeSpecification ())
				return ImportTypeSpecification (type, context);

			var reference = new TypeReference (
				type.Namespace,
				type.Name,
				module,
				ImportScope (type.Scope),
				type.IsValueType);

			MetadataSystem.TryProcessPrimitiveType (reference);

			if (type.IsNested)
				reference.DeclaringType = ImportType (type.DeclaringType, context);

			if (type.HasGenericParameters)
				ImportGenericParameters (reference, type);

			return reference;
		}
Пример #13
0
		public TypeReference ImportType (Type type, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsTypeSpecification (type) || ImportOpenGenericType (type, import_kind))
				return ImportTypeSpecification (type, context);

			var reference = new TypeReference (
				string.Empty,
				type.Name,
				module,
				ImportScope (type.Assembly),
				type.IsValueType);

			reference.etype = ImportElementType (type);

			if (IsNestedType (type))
				reference.DeclaringType = ImportType (type.DeclaringType, context, import_kind);
			else
				reference.Namespace = type.Namespace;

			if (type.IsGenericType)
				ImportGenericParameters (reference, type.GetGenericArguments ());

			return reference;
		}
Пример #14
0
        private TypeSymbol ResolveType(TypeReference type)
        {
            int arrayDimensions = 0;
            while (type is ArrayType) {
                arrayDimensions++;
                type = ((ArrayType)type).ElementType;
            }

            GenericInstanceType genericType = type as GenericInstanceType;
            if (genericType != null) {
                type = genericType.ElementType;
            }

            string name = type.FullName;
            if (String.CompareOrdinal(name, "System.ValueType") == 0) {
                // Ignore this type - it is the base class for enums, and other primitive types
                // but we don't import it since it is not useful in script
                return null;
            }

            TypeSymbol typeSymbol;

            GenericParameter genericParameter = type as GenericParameter;
            if (genericParameter != null) {
                typeSymbol = new GenericParameterSymbol(genericParameter.Position, genericParameter.Name,
                                                       (genericParameter.Owner.GenericParameterType == GenericParameterType.Type),
                                                       _symbols.GlobalNamespace);
            }
            else {
                typeSymbol = (TypeSymbol)((ISymbolTable)_symbols).FindSymbol(name, null, SymbolFilter.Types);
                if (typeSymbol == null) {
                    _errorHandler.ReportError("Unable to resolve referenced type '" + name +
                                              "'. Make sure all needed assemblies have been explicitly referenced.",
                                              String.Empty);
                    _resolveError = true;
                }
            }

            if (genericType != null) {
                List<TypeSymbol> typeArgs = new List<TypeSymbol>();

                foreach (TypeReference argTypeRef in genericType.GenericArguments) {
                    TypeSymbol argType = ResolveType(argTypeRef);
                    typeArgs.Add(argType);
                }

                typeSymbol = _symbols.CreateGenericTypeSymbol(typeSymbol, typeArgs);
                Debug.Assert(typeSymbol != null);
            }

            if (arrayDimensions != 0) {
                for (int i = 0; i < arrayDimensions; i++) {
                    typeSymbol = _symbols.CreateArrayTypeSymbol(typeSymbol);
                }
            }

            return typeSymbol;
        }
Пример #15
0
		public ParameterDefinition (TypeReference parameterType)
			: this (string.Empty, ParameterAttributes.None, parameterType)
		{
		}
Пример #16
0
		public FieldDefinition (string name, FieldAttributes attributes, TypeReference fieldType)
			: base (name, fieldType)
		{
			this.attributes = (ushort) attributes;
		}
Пример #17
0
		public CustomAttributeArgument (TypeReference type, object value)
		{
			Mixin.CheckType (type);
			this.type = type;
			this.value = value;
		}
Пример #18
0
		public MethodReference (string name, TypeReference returnType, TypeReference declaringType)
			: this (name, returnType)
		{
			if (declaringType == null)
				throw new ArgumentNullException ("declaringType");

			this.DeclaringType = declaringType;
		}
Пример #19
0
		public MethodReference (string name, TypeReference returnType)
			: base (name)
		{
			if (returnType == null)
				throw new ArgumentNullException ("returnType");

			this.return_type = new MethodReturnType (this);
			this.return_type.ReturnType = returnType;
			this.token = new MetadataToken (TokenType.MemberRef);
		}
Пример #20
0
		public ByReferenceType (TypeReference type)
			: base (type)
		{
			Mixin.CheckType (type);
			this.etype = MD.ElementType.ByRef;
		}
Пример #21
0
		public static void CheckModifier (TypeReference modifierType, TypeReference type)
		{
			if (modifierType == null)
				throw new ArgumentNullException ("modifierType");
			if (type == null)
				throw new ArgumentNullException ("type");
		}
Пример #22
0
		public ParameterDefinition (string name, ParameterAttributes attributes, TypeReference parameterType)
			: base (name, parameterType)
		{
			this.attributes = (ushort) attributes;
			this.token = new MetadataToken (TokenType.Param);
		}
Пример #23
0
		static TypeDefinition GetType (ModuleDefinition module, TypeReference type)
		{
			if (!type.IsNested)
				return module.GetType (type.Namespace, type.Name);

			var declaring_type = type.DeclaringType.Resolve ();
			if (declaring_type == null)
				return null;

			return declaring_type.GetNestedType (type.Name);
		}
Пример #24
0
 public FieldDefinition(string name, FieldAttributes attributes, TypeReference fieldType)
     : base(name, fieldType)
 {
     this.attributes = (ushort)attributes;
 }
Пример #25
0
		TypeReference ImportTypeSpecification (TypeReference type, IGenericContext context)
		{
			switch (type.etype) {
			case ElementType.SzArray:
				var vector = (ArrayType) type;
				return new ArrayType (ImportType (vector.ElementType, context));
			case ElementType.Ptr:
				var pointer = (PointerType) type;
				return new PointerType (ImportType (pointer.ElementType, context));
			case ElementType.ByRef:
				var byref = (ByReferenceType) type;
				return new ByReferenceType (ImportType (byref.ElementType, context));
			case ElementType.Pinned:
				var pinned = (PinnedType) type;
				return new PinnedType (ImportType (pinned.ElementType, context));
			case ElementType.Sentinel:
				var sentinel = (SentinelType) type;
				return new SentinelType (ImportType (sentinel.ElementType, context));
			case ElementType.CModOpt:
				var modopt = (OptionalModifierType) type;
				return new OptionalModifierType (
					ImportType (modopt.ModifierType, context),
					ImportType (modopt.ElementType, context));
			case ElementType.CModReqD:
				var modreq = (RequiredModifierType) type;
				return new RequiredModifierType (
					ImportType (modreq.ModifierType, context),
					ImportType (modreq.ElementType, context));
			case ElementType.Array:
				var array = (ArrayType) type;
				var imported_array = new ArrayType (ImportType (array.ElementType, context));
				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;
			case ElementType.GenericInst:
				var instance = (GenericInstanceType) type;
				var element_type = ImportType (instance.ElementType, context);
				var imported_instance = new GenericInstanceType (element_type);

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

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

				return imported_instance;
			case ElementType.Var:
				if (context == null || context.Type == null)
					throw new InvalidOperationException ();

				return ((TypeReference) context.Type).GetElementType ().GenericParameters [((GenericParameter) type).Position];
			case ElementType.MVar:
				if (context == null || context.Method == null)
					throw new InvalidOperationException ();

				return context.Method.GenericParameters [((GenericParameter) type).Position];
			}

			throw new NotSupportedException (type.etype.ToString ());
		}
Пример #26
0
		public PointerType (TypeReference type)
			: base (type)
		{
			Mixin.CheckType (type);
			this.etype = MD.ElementType.Ptr;
		}
Пример #27
0
		public MethodDefinition (string name, MethodAttributes attributes, TypeReference returnType)
			: base (name, returnType)
		{
			this.attributes = (ushort) attributes;
			this.HasThis = !this.IsStatic;
			this.token = new MetadataToken (TokenType.Method);
		}
Пример #28
0
		public static void TryProcessPrimitiveType (TypeReference type)
		{
			var scope = type.scope;
			if (scope == null)
				return;

			if (scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference)
				return;

			if (scope.Name != "mscorlib")
				return;

			if (type.Namespace != "System")
				return;

			if (primitive_value_types == null)
				InitializePrimitives ();

			Row<ElementType, bool> primitive_data;
			if (!primitive_value_types.TryGetValue (type.Name, out primitive_data))
				return;

			type.etype = primitive_data.Col1;
			type.IsValueType = primitive_data.Col2;
		}
Пример #29
0
		public CallSite (TypeReference returnType)
			: this ()
		{
			if (returnType == null)
				throw new ArgumentNullException ("returnType");

			this.signature.ReturnType = returnType;
		}
Пример #30
0
		public void AddTypeReference (TypeReference type)
		{
			TypeReferences [type.token.RID - 1] = type;
		}
 public TypeDefinition(string @namespace, string name, TypeAttributes attributes, TypeReference baseType) :
     this(@namespace, name, attributes)
 {
     this.BaseType = baseType;
 }
Пример #32
0
		static bool AreSame (TypeReference a, TypeReference b)
		{
			if (ReferenceEquals (a, b))
				return true;

			if (a == null || b == null)
				return false;

			if (a.etype != b.etype)
				return false;

			if (a.IsGenericParameter)
				return AreSame ((GenericParameter) a, (GenericParameter) b);

			if (a.IsTypeSpecification ())
				return AreSame ((TypeSpecification) a, (TypeSpecification) b);

			if (a.Name != b.Name || a.Namespace != b.Namespace)
				return false;

			//TODO: check scope

			return AreSame (a.DeclaringType, b.DeclaringType);
		}