Esempio n. 1
0
        public static bool IsEnum(TypeDefinition type) {
            TypeReference baseType = type.BaseType;
            if (baseType == null) {
                return false;
            }

            return (String.CompareOrdinal(type.BaseType.FullName, "System.Enum") == 0);
        }
Esempio n. 2
0
        public static bool IsDelegate(TypeDefinition type) {
            TypeReference baseType = type.BaseType;
            if (baseType == null) {
                return false;
            }

            string baseTypeName = type.BaseType.FullName;

            return (String.CompareOrdinal(baseTypeName, "System.MulticastDelegate") == 0) ||
                   (String.CompareOrdinal(baseTypeName, "System.Delegate") == 0);
        }
Esempio n. 3
0
 public static bool ShouldImportScriptCoreType(TypeDefinition type) {
     return GetAttribute(type, "System.Runtime.CompilerServices.NonScriptableAttribute") == null;
 }
Esempio n. 4
0
 public static bool ShouldIgnoreNamespace(TypeDefinition type) {
     return GetAttribute(type, "System.Runtime.CompilerServices.IgnoreNamespaceAttribute") != null;
 }
Esempio n. 5
0
		static TypeDefinition BinaryRangeSearch (TypeDefinition [] types, uint rid, bool field)
		{
			int min = 0;
			int max = types.Length - 1;
			while (min <= max) {
				int mid = min + ((max - min) / 2);
				var type = types [mid];
				var range = field ? type.fields_range : type.methods_range;

				if (rid < range.Start)
					max = mid - 1;
				else if (rid >= range.Start + range.Length)
					min = mid + 1;
				else
					return type;
			}

			return null;
		}
Esempio n. 6
0
		public void RemoveEventsRange (TypeDefinition type)
		{
			Events.Remove (type.token.RID);
		}
Esempio n. 7
0
		static MethodDefinition GetMethod (IAssemblyResolver resolver, TypeDefinition type, MethodReference reference)
		{
			while (type != null) {
				var method = GetMethod (type.Methods, reference);
				if (method != null)
					return method;

				if (type.BaseType == null)
					return null;

				type = Resolve (resolver, type.BaseType);
			}

			return null;
		}
Esempio n. 8
0
 public static bool IsCompilerGeneratedType(TypeDefinition type) {
     return GetAttribute(type, "System.Runtime.CompilerServices.CompilerGeneratedAttribute") != null;
 }
Esempio n. 9
0
		public void RemoveInterfaceMapping (TypeDefinition type)
		{
			Interfaces.Remove (type.token.RID);
		}
Esempio n. 10
0
		public bool TryGetInterfaceMapping (TypeDefinition type, out MetadataToken [] mapping)
		{
			return Interfaces.TryGetValue (type.token.RID, out mapping);
		}
Esempio n. 11
0
		public void RemoveReverseNestedTypeMapping (TypeDefinition type)
		{
			ReverseNestedTypes.Remove (type.token.RID);
		}
Esempio n. 12
0
		public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring)
		{
			return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring);
		}
Esempio n. 13
0
		public bool TryGetNestedTypeMapping (TypeDefinition type, out uint [] mapping)
		{
			return NestedTypes.TryGetValue (type.token.RID, out mapping);
		}
Esempio n. 14
0
		public void AddTypeDefinition (TypeDefinition type)
		{
			Types [type.token.RID - 1] = type;
		}
Esempio n. 15
0
        private void ImportType(MetadataSource mdSource, TypeDefinition type, bool inScriptCoreAssembly, string assemblyScriptNamespace, string assemblyScriptName)
        {
            if (type.IsPublic == false) {
                return;
            }
            if (inScriptCoreAssembly && (MetadataHelpers.ShouldImportScriptCoreType(type) == false)) {
                return;
            }

            string name = type.Name;
            string namespaceName = type.Namespace;
            string scriptNamespace = MetadataHelpers.GetScriptNamespace(type);
            string scriptName = MetadataHelpers.GetScriptName(type);

            if (String.IsNullOrEmpty(scriptNamespace) && (String.IsNullOrEmpty(assemblyScriptNamespace) == false)) {
                scriptNamespace = assemblyScriptNamespace;
            }

            NamespaceSymbol namespaceSymbol = _symbols.GetNamespace(namespaceName);
            TypeSymbol typeSymbol = null;

            if (type.IsInterface) {
                typeSymbol = new InterfaceSymbol(name, namespaceSymbol);
            }
            else if (MetadataHelpers.IsEnum(type)) {
                // NOTE: We don't care about the flags bit on imported enums
                //       because this is only consumed by the generation logic.
                typeSymbol = new EnumerationSymbol(name, namespaceSymbol, /* flags */ false);
                if (MetadataHelpers.ShouldUseEnumNames(type)) {
                    ((EnumerationSymbol)typeSymbol).SetNamedValues();
                }
                else if (MetadataHelpers.ShouldUseEnumValues(type)) {
                    ((EnumerationSymbol)typeSymbol).SetNumericValues();
                }
            }
            else if (MetadataHelpers.IsDelegate(type)) {
                typeSymbol = new DelegateSymbol(name, namespaceSymbol);
                typeSymbol.SetTransformedName("Function");
            }
            else {
                if (MetadataHelpers.ShouldTreatAsRecordType(type)) {
                    typeSymbol = new RecordSymbol(name, namespaceSymbol);
                }
                else {
                    typeSymbol = new ClassSymbol(name, namespaceSymbol);

                    string mixinRoot;
                    if (MetadataHelpers.ShouldGlobalizeMembers(type, out mixinRoot)) {
                        ((ClassSymbol)typeSymbol).SetGlobalMethods(mixinRoot);
                    }
                }
            }

            if (typeSymbol != null) {
                if (type.HasGenericParameters) {
                    List<GenericParameterSymbol> genericArguments = new List<GenericParameterSymbol>();
                    foreach (GenericParameter genericParameter in type.GenericParameters) {
                        GenericParameterSymbol arg =
                            new GenericParameterSymbol(genericParameter.Position, genericParameter.Name,
                                                      /* typeArgument */ true,
                                                      _symbols.GlobalNamespace);
                        genericArguments.Add(arg);
                    }

                    typeSymbol.AddGenericParameters(genericArguments);
                }

                typeSymbol.SetImported(assemblyScriptName);
                typeSymbol.SetMetadataToken(type, inScriptCoreAssembly);

                bool ignoreNamespace = MetadataHelpers.ShouldIgnoreNamespace(type);
                if (ignoreNamespace) {
                    typeSymbol.SetIgnoreNamespace();
                }
                typeSymbol.SetPublic();

                if (String.IsNullOrEmpty(scriptNamespace) == false) {
                    typeSymbol.ScriptNamespace = scriptNamespace;
                }

                if (String.IsNullOrEmpty(scriptName) == false) {
                    typeSymbol.SetTransformedName(scriptName);
                }

                namespaceSymbol.AddType(typeSymbol);
                _importedTypes.Add(typeSymbol);
            }
        }
Esempio n. 16
0
        public static bool ShouldTreatAsRecordType(TypeDefinition type) {
            if ((type.BaseType != null) &&
                (String.CompareOrdinal(type.BaseType.FullName, "System.Record") == 0)) {
                return true;
            }

            return false;
        }
Esempio n. 17
0
 public static bool ShouldUseEnumValues(TypeDefinition type) {
     return GetAttribute(type, "System.Runtime.CompilerServices.NumericValuesAttribute") != null;
 }
Esempio n. 18
0
		public bool TryGetPropertiesRange (TypeDefinition type, out Range range)
		{
			return Properties.TryGetValue (type.token.RID, out range);
		}
Esempio n. 19
0
		public void RemovePropertiesRange (TypeDefinition type)
		{
			Properties.Remove (type.token.RID);
		}
Esempio n. 20
0
		public bool TryGetEventsRange (TypeDefinition type, out Range range)
		{
			return Events.TryGetValue (type.token.RID, out range);
		}
Esempio n. 21
0
        public static bool ShouldGlobalizeMembers(TypeDefinition type, out string mixinRoot) {
            mixinRoot = null;

            CustomAttribute globalMethodsAttribute = GetAttribute(type, "System.Runtime.CompilerServices.GlobalMethodsAttribute");
            if (globalMethodsAttribute != null) {
                return true;
            }

            CustomAttribute mixinAttribute = GetAttribute(type, "System.Runtime.CompilerServices.MixinAttribute");
            if (mixinAttribute != null) {
                mixinRoot = GetAttributeArgument(mixinAttribute);
            }

            return false;
        }
Esempio n. 22
0
		static FieldDefinition GetField (IAssemblyResolver resolver, TypeDefinition type, FieldReference reference)
		{
			while (type != null) {
				var field = GetField (type.Fields, reference);
				if (field != null)
					return field;

				if (type.BaseType == null)
					return null;

				type = Resolve (resolver, type.BaseType);
			}

			return null;
		}