Exemple #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]);
        }
Exemple #2
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]);
        }