// Returns null if no matching method is found private static MethodDesc GetMatchingMethod(ModuleDesc module, MethodDesc method) { var matchingType = GetMatchingType(module, method.OwningType); if (matchingType == null) return null; return matchingType.GetMethod(method.Name, method.Signature); }
private void InitializeScopeReference(Cts.ModuleDesc module, ScopeReference scopeReference) { var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeReference.Name = HandleString(assemblyName.Name); scopeReference.Culture = HandleString(assemblyName.CultureName); scopeReference.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeReference.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeReference.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeReference.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); // References use a public key token instead of full public key. scopeReference.Flags = (AssemblyFlags)(assemblyName.Flags & ~AssemblyNameFlags.PublicKey); if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeReference.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } scopeReference.PublicKeyOrToken = assemblyName.GetPublicKeyToken(); } else { throw new NotSupportedException("Multi-module assemblies"); } }
public SyntheticVirtualOverrideTests() { _context = new SyntheticVirtualOverrideTypeSystemContext(); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; }
public HashcodeTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; }
public GenericMethodTests() { _context = new TestTypeSystemContext(TargetArchitecture.Unknown); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; }
public ILDisassemblerTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = _context.GetModuleForSimpleName("ILTestAssembly"); }
public Cts.ModuleDesc GetModuleOfType(Cts.MetadataType typeDef) { Cts.ModuleDesc overrideModule = OverrideModuleOfTypeViaExplicitScope(typeDef); if (overrideModule != null) { return(overrideModule); } return(typeDef.Module); }
// Returns null if no matching method is found private static MethodDesc GetMatchingMethod(ModuleDesc module, MethodDesc method) { // TODO:Enable this once mcg generated code match GetMatchingType // type lookup. // var matchingType = GetMatchingType(module, method.OwningType); var matchingType = TryGetMcgGeneratedType(module); if (matchingType == null) return null; return matchingType.GetMethod(method.Name, method.Signature); }
private NamespaceDefinition HandleNamespaceDefinition(Cts.ModuleDesc parentScope, string namespaceString) { Debug.Assert(namespaceString != null); NamespaceDefinition result; NamespaceKey key = new NamespaceKey(parentScope, namespaceString); if (_namespaceDefs.TryGetValue(key, out result)) { return(result); } if (namespaceString.Length == 0) { var rootNamespace = new NamespaceDefinition { Name = null, }; _namespaceDefs.Add(key, rootNamespace); ScopeDefinition rootScope = HandleScopeDefinition(parentScope); rootScope.RootNamespaceDefinition = rootNamespace; rootNamespace.ParentScopeOrNamespace = rootScope; return(rootNamespace); } string currentNamespaceName = String.Empty; NamespaceDefinition currentNamespace = HandleNamespaceDefinition(parentScope, currentNamespaceName); foreach (var segment in namespaceString.Split('.')) { string nextNamespaceName = currentNamespaceName; if (nextNamespaceName.Length > 0) { nextNamespaceName = nextNamespaceName + '.'; } nextNamespaceName += segment; NamespaceDefinition nextNamespace; key = new NamespaceKey(parentScope, nextNamespaceName); if (!_namespaceDefs.TryGetValue(key, out nextNamespace)) { nextNamespace = new NamespaceDefinition { Name = HandleString(segment.Length == 0 ? null : segment), ParentScopeOrNamespace = currentNamespace }; _namespaceDefs.Add(key, nextNamespace); currentNamespace.NamespaceDefinitions.Add(nextNamespace); } currentNamespace = nextNamespace; currentNamespaceName = nextNamespaceName; } return(currentNamespace); }
public VirtualMethodEnumerationAlgorithmTests() { _context = new TestTypeSystemContext(TargetArchitecture.Unknown); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; _testType = _testModule.GetType("VirtualFunctionOverride", "SimpleGeneric`1") .MakeInstantiatedType(_context.GetWellKnownType(WellKnownType.Object)); }
public VirtualFunctionOverrideTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; _stringType = _context.GetWellKnownType(WellKnownType.String); _voidType = _context.GetWellKnownType(WellKnownType.Void); }
public ValueTypeShapeCharacteristicsTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; _singleType = _context.GetWellKnownType(WellKnownType.Single); _doubleType = _context.GetWellKnownType(WellKnownType.Double); }
private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition) { var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeDefinition.Name = HandleString(assemblyName.Name); #if NETFX_45 // With NET 4.5 contract System.Reflection 4.0.0.0 EcmaModule has no way // to set Culture in its AssemblyName. scopeDefinition.Culture = HandleString(assemblyName.CultureName ?? ""); #else scopeDefinition.Culture = HandleString(assemblyName.CultureName); #endif scopeDefinition.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeDefinition.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeDefinition.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags; if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } if ((scopeDefinition.Flags & AssemblyFlags.PublicKey) != 0) { scopeDefinition.PublicKey = assemblyName.GetPublicKey(); } else { scopeDefinition.PublicKey = assemblyName.GetPublicKeyToken(); } Cts.Ecma.EcmaAssembly ecmaAssembly = module as Cts.Ecma.EcmaAssembly; if (ecmaAssembly != null) { Ecma.CustomAttributeHandleCollection customAttributes = ecmaAssembly.AssemblyDefinition.GetCustomAttributes(); if (customAttributes.Count > 0) { scopeDefinition.CustomAttributes = HandleCustomAttributes(ecmaAssembly, customAttributes); } } } else { throw new NotSupportedException("Multi-module assemblies"); } }
private NamespaceReference HandleNamespaceReference(Cts.ModuleDesc parentScope, string namespaceString) { NamespaceReference result; NamespaceKey key = new NamespaceKey(parentScope, namespaceString); if (_namespaceRefs.TryGetValue(key, out result)) { return(result); } ScopeReference scope = HandleScopeReference(parentScope); NamespaceReference rootNamespace; key = new NamespaceKey(parentScope, null); if (!_namespaceRefs.TryGetValue(key, out rootNamespace)) { rootNamespace = new NamespaceReference { Name = null, ParentScopeOrNamespace = scope, }; _namespaceRefs.Add(key, rootNamespace); } NamespaceReference currentNamespace = rootNamespace; string currentNamespaceName = String.Empty; foreach (var segment in namespaceString.Split('.')) { string nextNamespaceName = currentNamespaceName; if (nextNamespaceName.Length > 0) { nextNamespaceName = nextNamespaceName + '.'; } nextNamespaceName += segment; NamespaceReference nextNamespace; key = new NamespaceKey(parentScope, nextNamespaceName); if (!_namespaceRefs.TryGetValue(key, out nextNamespace)) { nextNamespace = new NamespaceReference { Name = HandleString(segment.Length == 0 ? null : segment), ParentScopeOrNamespace = currentNamespace }; _namespaceRefs.Add(key, nextNamespace); } currentNamespace = nextNamespace; currentNamespaceName = nextNamespaceName; } return(currentNamespace); }
private ScopeReference HandleScopeReference(Cts.ModuleDesc module) { var assembly = module as Cts.IAssemblyDesc; if (assembly != null) { return(HandleScopeReference(assembly.GetName())); } else { throw new NotSupportedException("Multi-module assemblies"); } }
private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition) { // Make sure we're expected to create a scope definition here. If the assert fires, the metadata // policy should have directed us to create a scope reference (or the list of inputs was incomplete). Debug.Assert(_modulesToTransform.Contains(module), "Incomplete list of input modules with respect to metadata policy"); var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeDefinition.Name = HandleString(assemblyName.Name); #if NETFX_45 // With NET 4.5 contract System.Reflection 4.0.0.0 EcmaModule has no way // to set Culture in its AssemblyName. scopeDefinition.Culture = HandleString(assemblyName.CultureName ?? ""); #else scopeDefinition.Culture = HandleString(assemblyName.CultureName); #endif scopeDefinition.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeDefinition.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeDefinition.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags; if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } scopeDefinition.PublicKey = assemblyName.GetPublicKey(); Cts.Ecma.EcmaModule ecmaModule = module as Cts.Ecma.EcmaModule; if (ecmaModule != null) { Ecma.CustomAttributeHandleCollection customAttributes = ecmaModule.AssemblyDefinition.GetCustomAttributes(); if (customAttributes.Count > 0) { scopeDefinition.CustomAttributes = HandleCustomAttributes(ecmaModule, customAttributes); } } } else { throw new NotSupportedException("Multi-module assemblies"); } }
public void SetSystemModule(ModuleDesc systemModule) { _systemModule = systemModule; // Sanity check the name table Debug.Assert(s_wellKnownTypeNames[(int)WellKnownType.MulticastDelegate - 1] == "MulticastDelegate"); // Initialize all well known types - it will save us from checking the name for each loaded type for (int typeIndex = 0; typeIndex < _wellKnownTypes.Length; typeIndex++) { MetadataType type = _systemModule.GetType("System", s_wellKnownTypeNames[typeIndex]); type.SetWellKnownType((WellKnownType)(typeIndex + 1)); _wellKnownTypes[typeIndex] = type; } }
public CanonicalizationTests() { _context = new TestTypeSystemContext(TargetArchitecture.Unknown); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; _referenceType = _testModule.GetType("Canonicalization", "ReferenceType"); _otherReferenceType = _testModule.GetType("Canonicalization", "OtherReferenceType"); _structType = _testModule.GetType("Canonicalization", "StructType"); _otherStructType = _testModule.GetType("Canonicalization", "OtherStructType"); _genericReferenceType = _testModule.GetType("Canonicalization", "GenericReferenceType`1"); _genericStructType = _testModule.GetType("Canonicalization", "GenericStructType`1"); }
// Returns null if no matching type is found private static TypeDesc GetMatchingType(ModuleDesc module, TypeDesc type) { var metadataType = (MetadataType)type; var containingType = metadataType.ContainingType; if (containingType != null) { var matchingContainingType = (MetadataType)GetMatchingType(module, containingType); if (matchingContainingType == null) return null; return matchingContainingType.GetNestedType(metadataType.Name); } else { return module.GetType(metadataType.Namespace, metadataType.Name, false); } }
private NamespaceDefinition HandleNamespaceDefinition(Cts.ModuleDesc parentScope, string namespaceString) { NamespaceDefinition rootNamespace = HandleScopeDefinition(parentScope).RootNamespaceDefinition; if (String.IsNullOrEmpty(namespaceString)) { return(rootNamespace); } NamespaceDefinition result; NamespaceKey key = new NamespaceKey(parentScope, namespaceString); if (_namespaceDefs.TryGetValue(key, out result)) { return(result); } NamespaceDefinition currentNamespace = rootNamespace; string currentNamespaceName = String.Empty; foreach (var segment in namespaceString.Split('.')) { string nextNamespaceName = currentNamespaceName; if (nextNamespaceName.Length > 0) { nextNamespaceName = nextNamespaceName + '.'; } nextNamespaceName += segment; NamespaceDefinition nextNamespace; key = new NamespaceKey(parentScope, nextNamespaceName); if (!_namespaceDefs.TryGetValue(key, out nextNamespace)) { nextNamespace = new NamespaceDefinition { Name = HandleString(segment.Length == 0 ? null : segment), ParentScopeOrNamespace = currentNamespace }; _namespaceDefs.Add(key, nextNamespace); currentNamespace.NamespaceDefinitions.Add(nextNamespace); } currentNamespace = nextNamespace; currentNamespaceName = nextNamespaceName; } return(currentNamespace); }
private static MetadataType GetType(this ModuleDesc module, string fullName, bool throwIfNotFound = true) { string namespaceName; string typeName; int split = fullName.LastIndexOf('.'); if (split < 0) { namespaceName = ""; typeName = fullName; } else { namespaceName = fullName.Substring(0, split); typeName = fullName.Substring(split + 1); } return(module.GetType(namespaceName, typeName, throwIfNotFound)); }
private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition) { // Make sure we're expected to create a scope definition here. If the assert fires, the metadata // policy should have directed us to create a scope reference (or the list of inputs was incomplete). Debug.Assert(_modulesToTransform.Contains(module), "Incomplete list of input modules with respect to metadata policy"); var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeDefinition.Name = HandleString(assemblyName.Name); scopeDefinition.Culture = HandleString(assemblyName.CultureName); scopeDefinition.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeDefinition.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeDefinition.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags; if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } scopeDefinition.PublicKey = assemblyName.GetPublicKey(); // TODO: CustomAttributes } else { throw new NotSupportedException("Multi-module assemblies"); } scopeDefinition.RootNamespaceDefinition = new NamespaceDefinition { Name = null, ParentScopeOrNamespace = scopeDefinition, }; }
public static string Module(ModuleDesc module) { if (module == null) { return("?"); } IAssemblyDesc assembly = module as IAssemblyDesc; if (assembly != null) { return(assembly.GetName().FullName); } else { Debug.Assert(false, "Multi-module assemblies"); return(module.ToString()); } }
public ArchitectureSpecificFieldLayoutTests() { _contextX64 = new TestTypeSystemContext(TargetArchitecture.X64); var systemModuleX64 = _contextX64.CreateModuleForSimpleName("CoreTestAssembly"); _contextX64.SetSystemModule(systemModuleX64); _testModuleX64 = systemModuleX64; _contextARM = new TestTypeSystemContext(TargetArchitecture.ARM); var systemModuleARM = _contextARM.CreateModuleForSimpleName("CoreTestAssembly"); _contextARM.SetSystemModule(systemModuleARM); _testModuleARM = systemModuleARM; _contextX86 = new TestTypeSystemContext(TargetArchitecture.X86); var systemModuleX86 = _contextX86.CreateModuleForSimpleName("CoreTestAssembly"); _contextX86.SetSystemModule(systemModuleX86); _testModuleX86 = systemModuleX86; }
private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition) { var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeDefinition.Name = HandleString(assemblyName.Name); scopeDefinition.Culture = HandleString(assemblyName.CultureName); scopeDefinition.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeDefinition.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeDefinition.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags; if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } scopeDefinition.PublicKey = assemblyName.GetPublicKey(); // TODO: CustomAttributes } else { throw new NotSupportedException("Multi-module assemblies"); } scopeDefinition.RootNamespaceDefinition = new NamespaceDefinition { Name = null, ParentScopeOrNamespace = scopeDefinition, }; }
public TypeNameParsingTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); // TODO-NICE: split test types into a separate, non-core, module _testModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(_testModule); _simpleType = _testModule.GetType("TypeNameParsing", "Simple"); _nestedType = _simpleType.GetNestedType("Nested"); _nestedTwiceType = _nestedType.GetNestedType("NestedTwice"); _genericType = _testModule.GetType("TypeNameParsing", "Generic`1"); _nestedGenericType = _genericType.GetNestedType("NestedGeneric`1"); _nestedNongenericType = _genericType.GetNestedType("NestedNongeneric"); _veryGenericType = _testModule.GetType("TypeNameParsing", "VeryGeneric`3"); _structType = _testModule.GetType("TypeNameParsing", "Struct"); _coreAssemblyQualifier = ((IAssemblyDesc)_testModule).GetName().FullName; }
public virtual void SetSystemModule(ModuleDesc systemModule) { InitializeSystemModule(systemModule); // Sanity check the name table Debug.Assert(s_wellKnownTypeNames[(int)WellKnownType.MulticastDelegate - 1] == "MulticastDelegate"); _wellKnownTypes = new MetadataType[s_wellKnownTypeNames.Length]; // Initialize all well known types - it will save us from checking the name for each loaded type for (int typeIndex = 0; typeIndex < _wellKnownTypes.Length; typeIndex++) { // Require System.Object to be present as a minimal sanity check. // The set of required well-known types is not strictly defined since different .NET profiles implement different subsets. MetadataType type = systemModule.GetType("System", s_wellKnownTypeNames[typeIndex], typeIndex == (int)WellKnownType.Object); if (type != null) { type.SetWellKnownType((WellKnownType)(typeIndex + 1)); _wellKnownTypes[typeIndex] = type; } } }
public CompilerGeneratedType(ModuleDesc module, string name) { Module = module; Name = name; }
private NamespaceReference HandleNamespaceReference(Cts.ModuleDesc parentScope, string namespaceString) { throw new NotImplementedException(); }
public MethodDesc GetPInvokeCalliStub(MethodSignature signature, ModuleDesc moduleContext) { return(_pInvokeCalliHashtable.GetOrCreateValue(new CalliMarshallingMethodThunkKey(signature, MarshalHelpers.IsRuntimeMarshallingEnabled(moduleContext)))); }
public TypeLoadException(string @namespace, string name, ModuleDesc module) : this(ExceptionStringID.ClassLoadGeneral, Format.Type(@namespace, name), Format.Module(module)) { }
public PInvokeDelegateWrapperHashtable(InteropStateManager interopStateManager, ModuleDesc owningModule) { _interopStateManager = interopStateManager; _owningModule = owningModule; }
// TODO: This's to work-around the limitation of mcg code generation.Mcg currently // do not preserve user pinvoke defining type hierarchy,but dump all pinvoke stub methods // to a type named McgPInvokeMarshaller private static TypeDesc TryGetMcgGeneratedType(ModuleDesc module) { // this should not fail since we are looking for a well known type. return module.GetType(PInvokeContainerTypeNS, PInvokeMethodContainerType, true); }
public static void ThrowTypeLoadException(string nestedTypeName, ModuleDesc module) { ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, nestedTypeName, Format.Module(module)); }
private static MetadataType ResolveCustomAttributeTypeNameToTypeDesc(string name, ModuleDesc module) { MetadataType containingType = null; StringBuilder typeName = new StringBuilder(name.Length); bool escaped = false; for (var c = name.Begin(); c < name.End(); c++) { if (c.Current == '\\' && !escaped) { escaped = true; continue; } if (escaped) { escaped = false; typeName.Append(c.Current); continue; } if (c.Current == ',') { break; } if (c.Current == '[' || c.Current == '*' || c.Current == '&') { break; } if (c.Current == '+') { if (containingType != null) { containingType = containingType.GetNestedType(typeName.ToString()); } else { containingType = module.GetType(typeName.ToString()); } typeName.Length = 0; continue; } typeName.Append(c.Current); } if (containingType != null) { return containingType.GetNestedType(typeName.ToString()); } return module.GetType(typeName.ToString()); }
public TypeLoadException(string nestedTypeName, ModuleDesc module) : this(ExceptionStringID.ClassLoadGeneral, nestedTypeName, Format.Module(module)) { }
public static MetadataType ResolveCustomAttributeTypeDefinitionName(string name, ModuleDesc module, bool throwIfNotFound) { MetadataType containingType = null; StringBuilder typeName = new StringBuilder(name.Length); bool escaped = false; for (var c = name.Begin(); c < name.End(); c++) { if (c.Current == '\\' && !escaped) { escaped = true; continue; } if (escaped) { escaped = false; typeName.Append(c.Current); continue; } if (c.Current == ',') { break; } if (c.Current == '[' || c.Current == '*' || c.Current == '&') { break; } if (c.Current == '+') { if (containingType != null) { MetadataType outerType = containingType; containingType = outerType.GetNestedType(typeName.ToString()); if (containingType == null) { if (throwIfNotFound) { ThrowHelper.ThrowTypeLoadException(typeName.ToString(), outerType.Module); } return(null); } } else { containingType = module.GetType(typeName.ToString(), throwIfNotFound); if (containingType == null) { return(null); } } typeName.Length = 0; continue; } typeName.Append(c.Current); } if (containingType != null) { MetadataType type = containingType.GetNestedType(typeName.ToString()); if ((type == null) && throwIfNotFound) { ThrowHelper.ThrowTypeLoadException(typeName.ToString(), containingType.Module); } return(type); } return(module.GetType(typeName.ToString(), throwIfNotFound)); }
public NamespaceKey(Cts.ModuleDesc module, string namespaceName) { Module = module; Namespace = namespaceName; }
/// <summary> /// Parses the string '<paramref name="name"/>' and returns the type corresponding to the parsed type name. /// The type name string should be in the 'SerString' format as defined by the ECMA-335 standard. /// This is the inverse of what <see cref="CustomAttributeTypeNameFormatter"/> does. /// </summary> public static TypeDesc GetTypeByCustomAttributeTypeName(this ModuleDesc module, string name, bool throwIfNotFound = true, Func <string, ModuleDesc, bool, MetadataType> resolver = null) { TypeDesc loadedType; StringBuilder genericTypeDefName = new StringBuilder(name.Length); var ch = name.Begin(); var nameEnd = name.End(); for (; ch < nameEnd; ++ch) { // Always pass escaped characters through. if (ch.Current == '\\') { genericTypeDefName.Append(ch.Current); ++ch; if (ch < nameEnd) { genericTypeDefName.Append(ch.Current); } continue; } // The type def name ends if // The start of a generic argument list if (ch.Current == '[') { break; } // Indication that the type is a pointer if (ch.Current == '*') { break; } // Indication that the type is a reference if (ch.Current == '&') { break; } // A comma that indicates that the rest of the name is an assembly reference if (ch.Current == ',') { break; } genericTypeDefName.Append(ch.Current); } ModuleDesc homeModule = module; AssemblyName homeAssembly = FindAssemblyIfNamePresent(name); if (homeAssembly != null) { homeModule = module.Context.ResolveAssembly(homeAssembly); } MetadataType typeDef = resolver != null?resolver(genericTypeDefName.ToString(), homeModule, throwIfNotFound) : ResolveCustomAttributeTypeDefinitionName(genericTypeDefName.ToString(), homeModule, throwIfNotFound); if (typeDef == null) { return(null); } ArrayBuilder <TypeDesc> genericArgs = new ArrayBuilder <TypeDesc>(); // Followed by generic instantiation parameters (but check for the array case) if (ch < nameEnd && ch.Current == '[' && (ch + 1) < nameEnd && (ch + 1).Current != ']' && (ch + 1).Current != ',') { ch++; // truncate the '[' var genericInstantiationEnd = ch + ReadTypeArgument(ch, nameEnd, true); // find the end of the instantiation list while (ch < genericInstantiationEnd) { if (ch.Current == ',') { ch++; } int argLen = ReadTypeArgument(ch, name.End(), false); string typeArgName; if (ch.Current == '[') { // This type argument name is stringified, // we need to remove the [] from around it ch++; typeArgName = StringIterator.Substring(ch, ch + (argLen - 2)); ch += argLen - 1; } else { typeArgName = StringIterator.Substring(ch, ch + argLen); ch += argLen; } TypeDesc argType = module.GetTypeByCustomAttributeTypeName(typeArgName, throwIfNotFound, resolver); if (argType == null) { return(null); } genericArgs.Add(argType); } Debug.Assert(ch == genericInstantiationEnd); ch++; loadedType = typeDef.MakeInstantiatedType(genericArgs.ToArray()); } else { // Non-generic type loadedType = typeDef; } // At this point the characters following may be any number of * characters to indicate pointer depth while (ch < nameEnd) { if (ch.Current == '*') { loadedType = loadedType.MakePointerType(); } else { break; } ch++; } // Followed by any number of "[]" or "[,*]" pairs to indicate arrays int commasSeen = 0; bool bracketSeen = false; while (ch < nameEnd) { if (ch.Current == '[') { ch++; commasSeen = 0; bracketSeen = true; } else if (ch.Current == ']') { if (!bracketSeen) { break; } ch++; if (commasSeen == 0) { loadedType = loadedType.MakeArrayType(); } else { loadedType = loadedType.MakeArrayType(commasSeen + 1); } bracketSeen = false; } else if (ch.Current == ',') { if (!bracketSeen) { break; } ch++; commasSeen++; } else { break; } } // Followed by at most one & character to indicate a byref. if (ch < nameEnd) { if (ch.Current == '&') { loadedType = loadedType.MakeByRefType(); ch++; } } return(loadedType); }
public NativeStructTypeHashtable(InteropStateManager interopStateManager, ModuleDesc owningModule) { _interopStateManager = interopStateManager; _owningModule = owningModule; }
public static void ThrowTypeLoadException(string @namespace, string name, ModuleDesc module) { ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, Format.Type(@namespace, name), Format.Module(module)); }
public InlineArrayHashTable(InteropStateManager interopStateManager, ModuleDesc owningModule) { _interopStateManager = interopStateManager; _owningModule = owningModule; }
private void ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement) { var typeNameAttribute = typeElement.Attribute("Name"); if (typeNameAttribute == null) throw new Exception(); var dynamicDegreeAttribute = typeElement.Attribute("Dynamic"); if (dynamicDegreeAttribute != null) { if (dynamicDegreeAttribute.Value != "Required All") throw new NotSupportedException(); } string typeName = typeNameAttribute.Value; TypeDesc type = containingModule.GetTypeByCustomAttributeTypeName(typeName); rootProvider.AddCompilationRoot(type, "RD.XML root"); if (type.IsDefType) { foreach (var method in type.GetMethods()) { if (method.IsAbstract || method.HasInstantiation) continue; rootProvider.AddCompilationRoot(method, "RD.XML root"); } } }
private ScopeReference HandleScopeReference(Cts.ModuleDesc module) { return(_scopeRefs.GetOrCreate(module, _initScopeRef ?? (_initScopeRef = InitializeScopeReference))); }
private ScopeDefinition HandleScopeDefinition(Cts.ModuleDesc module) { return(_scopeDefs.GetOrCreate(module, _initScopeDef ?? (_initScopeDef = InitializeScopeDefinition))); }
private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition) { var assemblyDesc = module as Cts.IAssemblyDesc; if (assemblyDesc != null) { var assemblyName = assemblyDesc.GetName(); scopeDefinition.Name = HandleString(assemblyName.Name); #if NETFX_45 // With NET 4.5 contract System.Reflection 4.0.0.0 EcmaModule has no way // to set Culture in its AssemblyName. scopeDefinition.Culture = HandleString(assemblyName.CultureName ?? ""); #else scopeDefinition.Culture = HandleString(assemblyName.CultureName); #endif scopeDefinition.MajorVersion = checked ((ushort)assemblyName.Version.Major); scopeDefinition.MinorVersion = checked ((ushort)assemblyName.Version.Minor); scopeDefinition.BuildNumber = checked ((ushort)assemblyName.Version.Build); scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision); Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey); Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable); scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags; if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime) { scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9); } if ((scopeDefinition.Flags & AssemblyFlags.PublicKey) != 0) { scopeDefinition.PublicKey = assemblyName.GetPublicKey(); } else { scopeDefinition.PublicKey = assemblyName.GetPublicKeyToken(); } Cts.MetadataType moduleType = module.GetGlobalModuleType(); if (moduleType != null && _policy.GeneratesMetadata(moduleType)) { scopeDefinition.GlobalModuleType = (TypeDefinition)HandleType(moduleType); } Cts.Ecma.EcmaAssembly ecmaAssembly = module as Cts.Ecma.EcmaAssembly; if (ecmaAssembly != null) { Ecma.CustomAttributeHandleCollection customAttributes = ecmaAssembly.AssemblyDefinition.GetCustomAttributes(); if (customAttributes.Count > 0) { scopeDefinition.CustomAttributes = HandleCustomAttributes(ecmaAssembly, customAttributes); } Cts.MethodDesc entryPoint = ecmaAssembly.EntryPoint; if (entryPoint != null && _policy.GeneratesMetadata(entryPoint)) { scopeDefinition.EntryPoint = (QualifiedMethod)HandleQualifiedMethod(entryPoint); } Ecma.MetadataReader reader = ecmaAssembly.MetadataReader; Ecma.ModuleDefinition moduleDefinition = reader.GetModuleDefinition(); scopeDefinition.ModuleName = HandleString(reader.GetString(moduleDefinition.Name)); scopeDefinition.Mvid = reader.GetGuid(moduleDefinition.Mvid).ToByteArray(); // This is rather awkward because ModuleDefinition doesn't offer means to get to the custom attributes Ecma.CustomAttributeHandleCollection moduleAttributes = reader.GetCustomAttributes(Ecma.Ecma335.MetadataTokens.EntityHandle(0x1)); if (moduleAttributes.Count > 0) { scopeDefinition.ModuleCustomAttributes = HandleCustomAttributes(ecmaAssembly, moduleAttributes); } HandleTypeForwarders(ecmaAssembly); } } else { throw new NotSupportedException("Multi-module assemblies"); } }
public ILTypeNameFormatter(ModuleDesc thisModule) { _thisModule = thisModule; }
public static string Module(ModuleDesc module) { if (module == null) return "?"; IAssemblyDesc assembly = module as IAssemblyDesc; if (assembly != null) { return assembly.GetName().FullName; } else { Debug.Assert(false, "Multi-module assemblies"); return module.ToString(); } }
protected void InitializeSystemModule(ModuleDesc systemModule) { Debug.Assert(SystemModule == null); SystemModule = systemModule; }