示例#1
0
        /// <summary>
        /// Lookup declaration for predefined CorLib type in this Assembly. Only should be
        /// called if it is know that this is the Cor Library (mscorlib).
        /// </summary>
        /// <param name="type"></param>
        public override Symbol GetDeclaredSpecialSymbol(object key)
        {
#if DEBUG
            foreach (var module in this.Modules)
            {
                Debug.Assert(module.ReferencedAssemblies.Length == 0);
            }
#endif

            Symbol result;
            if (_lazySpecialSymbols == null || !_lazySpecialSymbols.ContainsKey(key))
            {
                ModuleSymbol module = this.Modules[0];
                if (key is SpecialType type)
                {
                    MetadataTypeName emittedName = MetadataTypeName.FromFullName(type.GetMetadataName(), useCLSCompliantNameArityEncoding: true);
                    result = module.LookupTopLevelMetadataType(ref emittedName);
                    if (result.Kind != LanguageSymbolKind.ErrorType && result.DeclaredAccessibility != Accessibility.Public)
                    {
                        result = new MissingMetadataTypeSymbol.TopLevel(module, ref emittedName, type);
                    }
                }
                else
                {
                    result = this.Language.CompilationFactory.CreateSpecialSymbol(module, key);
                    if (result == null)
                    {
                        result = new MissingMetadataTypeSymbol.TopLevel(module, string.Empty, key.ToString(), 0, false);
                    }
                }
                RegisterDeclaredSpecialSymbol(key, ref result);
            }

            return(_lazySpecialSymbols[key]);
        }
示例#2
0
        /// <summary>
        /// Lookup a top level type referenced from metadata, names should be
        /// compared case-sensitively.
        /// </summary>
        /// <param name="emittedName">
        /// Full type name, possibly with generic name mangling.
        /// </param>
        /// <returns>
        /// Symbol for the type, or MissingMetadataSymbol if the type isn't found.
        /// </returns>
        /// <remarks></remarks>
        public sealed override NamedTypeSymbol LookupTopLevelMetadataType(ref MetadataTypeName emittedName)
        {
            NamedTypeSymbol result;
            NamespaceSymbol scope = this.GlobalNamespace.LookupNestedNamespace(emittedName.NamespaceSegments);

            if ((object)scope == null)
            {
                // We failed to locate the namespace
                result = new MissingMetadataTypeSymbol.TopLevel(this, ref emittedName);
            }
            else
            {
                result = scope.LookupMetadataType(ref emittedName);
            }

            Debug.Assert((object)result != null);
            return(result);
        }
示例#3
0
        /// <summary>
        /// Lookup declaration for predefined symbol in this Assembly.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Symbol GetDeclaredSpecialSymbol(object key)
        {
#if DEBUG
            foreach (var module in this.Modules)
            {
                Debug.Assert(module.ReferencedAssemblies.Length == 0);
            }
#endif

            MetadataTypeName emittedName = default;
            Symbol           result      = null;
            if (_lazySpecialSymbols == null || !_lazySpecialSymbols.ContainsKey(key))
            {
                ModuleSymbol firstModule = this.Modules[0];
                if (key is SpecialType)
                {
                    emittedName = MetadataTypeName.FromFullName(((SpecialType)key).GetMetadataName(), useCLSCompliantNameArityEncoding: true);
                    result      = firstModule.LookupTopLevelMetadataType(ref emittedName);
                    if (result.Kind == LanguageSymbolKind.ErrorType || result.DeclaredAccessibility != Accessibility.Public)
                    {
                        result = null;
                    }
                }
                else if (key is IModelObject metaSymbol)
                {
                    foreach (var module in this.Modules)
                    {
                        if (module.TryGetSymbol(metaSymbol, out Symbol symbol))
                        {
                            result = symbol;
                            break;
                        }
                    }
                }
                if (result == null)
                {
                    foreach (var module in this.Modules)
                    {
                        var symbol = this.Language.CompilationFactory.CreateSpecialSymbol(module, key);
                        if (symbol != null)
                        {
                            result = symbol;
                            break;
                        }
                    }
                }
                if (result == null || (result.Kind != LanguageSymbolKind.ErrorType && result.DeclaredAccessibility != Accessibility.Public))
                {
                    if (key is SpecialType)
                    {
                        result = new MissingMetadataTypeSymbol.TopLevel(firstModule, ref emittedName, (SpecialType)key);
                    }
                    else
                    {
                        result = new MissingMetadataTypeSymbol.TopLevel(firstModule, string.Empty, key.ToString(), 0, false);
                    }
                }
                RegisterDeclaredSpecialSymbol(key, ref result);
            }

            return(_lazySpecialSymbols[key]);
        }