public static bool IsEnum(TypeDefinition type) { TypeReference baseType = type.BaseType; if (baseType == null) { return false; } return (String.CompareOrdinal(type.BaseType.FullName, "System.Enum") == 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); }
public static bool ShouldImportScriptCoreType(TypeDefinition type) { return GetAttribute(type, "System.Runtime.CompilerServices.NonScriptableAttribute") == null; }
public static bool ShouldIgnoreNamespace(TypeDefinition type) { return GetAttribute(type, "System.Runtime.CompilerServices.IgnoreNamespaceAttribute") != null; }
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; }
public void RemoveEventsRange (TypeDefinition type) { Events.Remove (type.token.RID); }
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; }
public static bool IsCompilerGeneratedType(TypeDefinition type) { return GetAttribute(type, "System.Runtime.CompilerServices.CompilerGeneratedAttribute") != null; }
public void RemoveInterfaceMapping (TypeDefinition type) { Interfaces.Remove (type.token.RID); }
public bool TryGetInterfaceMapping (TypeDefinition type, out MetadataToken [] mapping) { return Interfaces.TryGetValue (type.token.RID, out mapping); }
public void RemoveReverseNestedTypeMapping (TypeDefinition type) { ReverseNestedTypes.Remove (type.token.RID); }
public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring) { return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring); }
public bool TryGetNestedTypeMapping (TypeDefinition type, out uint [] mapping) { return NestedTypes.TryGetValue (type.token.RID, out mapping); }
public void AddTypeDefinition (TypeDefinition type) { Types [type.token.RID - 1] = type; }
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); } }
public static bool ShouldTreatAsRecordType(TypeDefinition type) { if ((type.BaseType != null) && (String.CompareOrdinal(type.BaseType.FullName, "System.Record") == 0)) { return true; } return false; }
public static bool ShouldUseEnumValues(TypeDefinition type) { return GetAttribute(type, "System.Runtime.CompilerServices.NumericValuesAttribute") != null; }
public bool TryGetPropertiesRange (TypeDefinition type, out Range range) { return Properties.TryGetValue (type.token.RID, out range); }
public void RemovePropertiesRange (TypeDefinition type) { Properties.Remove (type.token.RID); }
public bool TryGetEventsRange (TypeDefinition type, out Range range) { return Events.TryGetValue (type.token.RID, out range); }
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; }
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; }