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 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 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 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");
            _genericReferenceTypeWithThreeParams = _testModule.GetType("Canonicalization", "GenericReferenceTypeWithThreeParams`3");
            _genericStructTypeWithThreeParams = _testModule.GetType("Canonicalization", "GenericStructTypeWithThreeParams`3");
        }
        public void SetSystemModule(ModuleDesc systemModule)
        {
            InitializeSystemModule(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;
            }
        }
Exemple #7
0
        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));
        }
        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;
                }
            }
        }
Exemple #9
0
 // 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);
     }
 }
Exemple #10
0
        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));
        }
        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());
        }
Exemple #12
0
 // 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);
 }