protected override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            var count = parameterMap.GetCountForKey(name);
            if (count == 1)
            {
                ParameterSymbol p;
                parameterMap.TryGetSingleValue(name, out p);
                result.MergeEqual(originalBinder.CheckViability(p, arity, options, null, diagnose, ref useSiteDiagnostics));
            }
            else if (count > 1)
            {
                var parameters = parameterMap[name];
                foreach (var sym in parameters)
                {
                    result.MergeEqual(originalBinder.CheckViability(sym, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }
        internal sealed override void LookupSymbolsInSingleBinder(
            LookupResult result,
            string name,
            int arity,
            ConsList<Symbol> basesBeingResolved,
            LookupOptions options,
            Binder originalBinder,
            bool diagnose,
            ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) != 0)
            {
                return;
            }

            var local = this.LookupPlaceholder(name);
            if ((object)local == null)
            {
                base.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);
            }
            else
            {
                result.MergeEqual(this.CheckViability(local, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved));
            }
        }
        public LookupService(String databaseFile, LookupOptions options)
        {
            _dbReader = options == LookupOptions.GEOIP_MEMORY_CACHE
                ? new StreamDbReader(databaseFile)
                : new CachedDbReader(databaseFile);

            Init();
        }
        public LookupService(Stream stream, LookupOptions options)
        {
            _dbReader = options == LookupOptions.GEOIP_MEMORY_CACHE
                ? new StreamDbReader(stream)
                : new CachedDbReader(stream);

            Init();
        }
Example #5
0
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     var hostObjectType = GetHostObjectType();
     if (hostObjectType.Kind != SymbolKind.ErrorType)
     {
         AddMemberLookupSymbolsInfo(result, hostObjectType, options, originalBinder);
     }
 }
Example #6
0
        protected override void AddLookupSymbolsInfoInSingleBinder(
            LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            // Add types within namespaces imported through usings, but don't add nested namespaces.
            LookupOptions usingOptions = (options & ~(LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) | LookupOptions.MustNotBeNamespace;

            Imports.AddLookupSymbolsInfoInUsings(ConsolidatedUsings, this, result, usingOptions);
        }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (options.CanConsiderLocals())
     {
         foreach (var parameter in primaryCtor.Parameters)
         {
             if (originalBinder.CanAddLookupSymbolInfo(parameter, options, null))
             {
                 result.AddSymbol(parameter, parameter.Name, 0);
             }
         }
     }
 }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (CanConsiderTypeParameters(options))
     {
         foreach (var parameter in _namedType.TypeParameters)
         {
             if (originalBinder.CanAddLookupSymbolInfo(parameter, options, null))
             {
                 result.AddSymbol(parameter, parameter.Name, 0);
             }
         }
     }
 }
		public DicResult Lookup(LangPair lang, string text, string ui = null, LookupOptions flags = 0)
		{
			RestRequest request = new RestRequest("lookup");
			request.AddParameter("key", _key);
			request.AddParameter("lang", lang.ToString().ToLowerInvariant());
			request.AddParameter("text", text);
			
			if (!string.IsNullOrEmpty(ui))
				request.AddParameter("ui", ui);
			if (flags != 0)
				request.AddParameter("flags", (int)flags);

			return SendRequest<DicResult>(request);
		}
Example #10
0
        internal override void LookupSymbolsInSingleBinder(LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            _sourceBinder.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, this, diagnose, ref useSiteDiagnostics);

            var symbols = result.Symbols;
            for (int i = 0; i < symbols.Count; i++)
            {
                // Type parameters requiring mapping to the target type and
                // should be found by WithMethodTypeParametersBinder instead.
                var parameter = (ParameterSymbol)symbols[i];
                Debug.Assert(parameter.ContainingSymbol == _sourceBinder.ContainingMemberOrLambda);
                symbols[i] = _targetParameters[parameter.Ordinal + _parameterOffset];
            }
        }
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert(result.IsClear);

            if ((options & LookupOptions.NamespaceAliasesOnly) != 0)
            {
                return;
            }

            foreach (var parameterSymbol in parameterMap[name])
            {
                result.MergeEqual(originalBinder.CheckViability(parameterSymbol, arity, options, null, diagnose, ref useSiteDiagnostics));
            }
        }
Example #12
0
        protected override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            foreach (ParameterSymbol parameter in parameters)
            {
                if (parameter.Name == name)
                {
                    result.MergeEqual(originalBinder.CheckViability(parameter, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }
Example #13
0
 internal override void GetCandidateExtensionMethods(
     bool searchUsingsNotNamespace,
     ArrayBuilder<MethodSymbol> methods,
     string name,
     int arity,
     LookupOptions options,
     bool isCallerSemanticModel)
 {
     if (searchUsingsNotNamespace)
     {
         foreach (var nsOrType in ConsolidatedUsings)
         {
             if (nsOrType.NamespaceOrType.Kind == SymbolKind.Namespace)
             {
                 ((NamespaceSymbol)nsOrType.NamespaceOrType).GetExtensionMethods(methods, name, arity, options);
             }
         }
     }
 }
Example #14
0
 internal override void LookupSymbolsInSingleBinder(
     LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
 {
     var hostObjectType = GetHostObjectType();
     if (hostObjectType.Kind == SymbolKind.ErrorType)
     {
         // The name '{0}' does not exist in the current context (are you missing a reference to assembly '{1}'?)
         result.SetFrom(new CSDiagnosticInfo(
             ErrorCode.ERR_NameNotInContextPossibleMissingReference,
             new object[] { name, ((MissingMetadataTypeSymbol)hostObjectType).ContainingAssembly.Identity },
             ImmutableArray<Symbol>.Empty,
             ImmutableArray<Location>.Empty
         ));
     }
     else
     {
         LookupMembersInternal(result, hostObjectType, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);
     }
 }
Example #15
0
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if (!ShouldLookInUsings(options))
            {
                return;
            }

            LookupResult tmp = LookupResult.GetInstance();

            // usings:
            Imports.Empty.LookupSymbolInUsings(ConsolidatedUsings, originalBinder, tmp, name, arity, basesBeingResolved, options, diagnose, ref useSiteDiagnostics);

            // if we found a viable result in imported namespaces, use it instead of unviable symbols found in source:
            if (tmp.IsMultiViable)
            {
                result.MergeEqual(tmp);
            }

            tmp.Free();
        }
Example #16
0
        internal sealed override void LookupSymbolsInSingleBinder(
            LookupResult result,
            string name,
            int arity,
            ConsList<Symbol> basesBeingResolved,
            LookupOptions options,
            Binder originalBinder,
            bool diagnose,
            ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) != 0)
            {
                return;
            }

            if (name.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
            {
                var valueText = name.Substring(2);
                ulong address;
                if (!ulong.TryParse(valueText, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out address))
                {
                    // Invalid value should have been caught by Lexer.
                    throw ExceptionUtilities.UnexpectedValue(valueText);
                }
                var local = new ObjectAddressLocalSymbol(_containingMethod, name, this.Compilation.GetSpecialType(SpecialType.System_Object), address);
                result.MergeEqual(this.CheckViability(local, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved));
            }
            else
            {
                LocalSymbol lowercaseReturnValueAlias;
                if (_lowercaseReturnValueAliases.TryGetValue(name, out lowercaseReturnValueAlias))
                {
                    result.MergeEqual(this.CheckViability(lowercaseReturnValueAlias, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved));
                }
                else
                {
                    base.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);
                }
            }
        }
 public TaxonSelectorContentProvider(User user, TaxonExplorer explorer, LookupOptions options)
 {
     this.User = user;
     _explorer = explorer;
     _options = options;
 }
        /// <summary>
        /// Looks up the key value and returns the corresponding mapping.
        /// </summary>
        /// <typeparam name="TMapping">Mapping type.</typeparam>
        /// <typeparam name="TKey">Key type.</typeparam>
        /// <param name="key">Input key value.</param>
        /// <param name="lookupOptions">Whether to use cache and/or storage for lookups.</param>
        /// <param name="constructMapping">Delegate to construct a mapping object.</param>
        /// <param name="errorCategory">Category under which errors must be thrown.</param>
        /// <returns>Mapping that contains the key value.</returns>
        protected TMapping Lookup <TMapping, TKey>(
            TKey key,
            LookupOptions lookupOptions,
            Func <ShardMapManager, ShardMap, IStoreMapping, TMapping> constructMapping,
            ShardManagementErrorCategory errorCategory)
            where TMapping : class, IShardProvider
        {
            ShardKey sk = new ShardKey(ShardKey.ShardKeyTypeFromType(typeof(TKey)), key);

            // Try to lookup in cache. Note the interation with cache removal later in this method.
            bool tryLookupInCache = lookupOptions.HasFlag(LookupOptions.LookupInCache);

            if (tryLookupInCache)
            {
                ICacheStoreMapping cachedMapping = this.Manager.Cache.LookupMappingByKey(this.ShardMap.StoreShardMap, sk);
                if (cachedMapping != null)
                {
                    return(constructMapping(this.Manager, this.ShardMap, cachedMapping.Mapping));
                }
            }

            // Cache-miss (or didn't use cache), find mapping for given key in GSM.
            if (lookupOptions.HasFlag(LookupOptions.LookupInStore))
            {
                IStoreResults gsmResult;

                Stopwatch stopwatch = Stopwatch.StartNew();

                using (IStoreOperationGlobal op = this.Manager.StoreOperationFactory.CreateFindMappingByKeyGlobalOperation(
                           this.Manager,
                           "Lookup",
                           this.ShardMap.StoreShardMap,
                           sk,
                           CacheStoreMappingUpdatePolicy.OverwriteExisting,
                           errorCategory,
                           true,
                           false))
                {
                    gsmResult = op.Do();
                }

                stopwatch.Stop();

                Tracer.TraceVerbose(
                    TraceSourceConstants.ComponentNames.BaseShardMapper,
                    "Lookup",
                    "Lookup key from GSM complete; Key type : {0}; Result: {1}; Duration: {2}",
                    typeof(TKey),
                    gsmResult.Result,
                    stopwatch.Elapsed);

                // If mapping was found, return it.
                if (gsmResult.Result != StoreResult.MappingNotFoundForKey)
                {
                    return(gsmResult.StoreMappings.Select(sm => constructMapping(this.Manager, this.ShardMap, sm)).Single());
                }

                // If we could not locate the mapping, then we might need to update the cache to remove it.
                //
                // Only do this if we didn't already try to return the mapping from the cache (since, if it was found,
                // we would have already returned it earlier).
                if (!tryLookupInCache)
                {
                    ICacheStoreMapping cachedMapping =
                        this.Manager.Cache.LookupMappingByKey(this.ShardMap.StoreShardMap, sk);
                    if (cachedMapping != null)
                    {
                        this.Manager.Cache.DeleteMapping(cachedMapping.Mapping);
                    }
                }
            }

            // Mapping not found - return null
            return(null);
        }
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert(result.IsClear);

            if ((options & LookupOptions.NamespaceAliasesOnly) != 0)
            {
                return;
            }

            foreach (var parameterSymbol in parameterMap[name])
            {
                result.MergeEqual(originalBinder.CheckViability(parameterSymbol, arity, options, null, diagnose, ref useSiteDiagnostics));
            }
        }
Example #20
0
 public TypeAnnotationConverter(ExpressionEval eval,
                                LookupOptions options = LookupOptions.Global | LookupOptions.Builtins)
 {
     _eval    = eval ?? throw new ArgumentNullException(nameof(eval));
     _options = options;
 }
Example #21
0
 public static IMember LookupNameInScopes(this IExpressionEvaluator eval, string name, LookupOptions options = LookupOptions.Normal)
 => eval.LookupNameInScopes(name, out _, out _, options);
Example #22
0
        // Note: we do not mark nodes when looking up arities or names.  This is because these two
        // types of lookup are only around to make the public
        // SemanticModel.LookupNames/LookupSymbols work and do not count as usages of the directives
        // when the actual code is bound.

        internal void AddLookupSymbolsInfoInAliases(Binder binder, LookupSymbolsInfo result, LookupOptions options)
        {
            if (this.UsingAliases != null)
            {
                foreach (var usingAlias in this.UsingAliases.Values)
                {
                    var usingAliasSymbol = usingAlias.Alias.GetAliasTarget(basesBeingResolved: null);
                    if (binder.CanAddLookupSymbolInfo(usingAliasSymbol, options, null))
                    {
                        result.AddSymbol(usingAlias.Alias, usingAlias.Alias.Name, 0);
                    }
                }
            }

            // TODO (tomat): extern aliases?
        }
Example #23
0
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result,
            string name,
            int arity,
            ConsList <TypeSymbol> basesBeingResolved,
            LookupOptions options,
            Binder originalBinder,
            bool diagnose,
            ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo
            )
        {
            Debug.Assert(result.IsClear);

            if (IsSubmissionClass)
            {
                this.LookupMembersInternal(
                    result,
                    _container,
                    name,
                    arity,
                    basesBeingResolved,
                    options,
                    originalBinder,
                    diagnose,
                    ref useSiteInfo
                    );
                return;
            }

            var imports = GetImports(basesBeingResolved);

            // first lookup members of the namespace
            if ((options & LookupOptions.NamespaceAliasesOnly) == 0 && _container != null)
            {
                this.LookupMembersInternal(
                    result,
                    _container,
                    name,
                    arity,
                    basesBeingResolved,
                    options,
                    originalBinder,
                    diagnose,
                    ref useSiteInfo
                    );

                if (result.IsMultiViable)
                {
                    // symbols cannot conflict with using alias names
                    if (
                        arity == 0 &&
                        imports.IsUsingAlias(name, originalBinder.IsSemanticModelBinder)
                        )
                    {
                        CSDiagnosticInfo diagInfo = new CSDiagnosticInfo(
                            ErrorCode.ERR_ConflictAliasAndMember,
                            name,
                            _container
                            );
                        var error = new ExtendedErrorTypeSymbol(
                            (NamespaceOrTypeSymbol)null,
                            name,
                            arity,
                            diagInfo,
                            unreported: true
                            );
                        result.SetFrom(LookupResult.Good(error)); // force lookup to be done w/ error symbol as result
                    }

                    return;
                }
            }

            // next try using aliases or symbols in imported namespaces
            imports.LookupSymbol(
                originalBinder,
                result,
                name,
                arity,
                basesBeingResolved,
                options,
                diagnose,
                ref useSiteInfo
                );
        }
Example #24
0
        internal static ContentRoot?GetContentRootForElement(DependencyObject?dependencyObject, LookupOptions options = LookupOptions.WarningIfNotFound)
        {
            if (GetForElement(dependencyObject, options) is { } visualTree)
            {
                return(visualTree.ContentRoot);
            }

            if (dependencyObject?.GetContext().ContentRootCoordinator.CoreWindowContentRoot is ContentRoot contentRoot)
            {
                return(contentRoot);
            }

            return(null);
        }
Example #25
0
        internal static VisualTree?GetVisualTreeViaTreeWalk(DependencyObject element, LookupOptions options)
        {
            DependencyObject?currentAncestor = element;

            const bool isDebugMode =
#if VISUALTREEWALK_DEBUG
                true;
#else
                false;
#endif

            VisualTree?result = null;

            // We cap the tree walk because we've found at least one case (Skype app -- 19h1) where there's a cycle in the tree.
            int iterationsLeft = 1000;

            // Walk up the tree to find either the XamlIslandRoot or RootVisual
            while (currentAncestor != null && iterationsLeft != 0)
            {
                --iterationsLeft;
                if (currentAncestor.GetVisualTree() is VisualTree visualTree)
                {
                    if (isDebugMode)
                    {
                        // In debug mode, let's keep walking up the tree, even though
                        // we found the answer, just to make sure the tree is consistent.
#pragma warning disable CS0162 // Unreachable code detected
                        if (result != null)
                        {
                            MUX_ASSERT(visualTree == result);
                        }
                        else
                        {
                            result = visualTree;
                        }
#pragma warning restore CS0162 // Unreachable code detected
                    }
                    else
                    {
                        return(visualTree);
                    }
                }

                if (currentAncestor is XamlIslandRoot xamlIslandRoot)
                {
                    return(xamlIslandRoot.ContentRoot.VisualTree);
                }
                else if (currentAncestor is RootVisual rootVisual)
                {
                    return(rootVisual.AssociatedVisualTree);
                }

                DependencyObject?nextAncestor = null;
                //TODO Uno: Uncomment and implement
                if (false)                //currentAncestor.DoesAllowMultipleAssociation() && currentAncestor.GetParentCount() > 1)
                {
                    // We cannot travese up a tree through a multiply associated element.  Our goal is to support DOs being
                    // shared between XAML trees.  We've seen cases where we traverse up the tree through CSetter objects,
                    // so for now we allow the traversal if there's one unique parent.  TODO: This could be fragile?  Allowing
                    // the traversal to happen when the parent count is 1 means that if this element gets another parent later,
                    // we're now in an inconsistent state.
                    // Bug 19548424: Investigate places where an element entering the tree doesn't have a unique VisualTree ptr
                }
                else
                {
                    nextAncestor = currentAncestor.GetParentInternal(false /* public parent only */);
                }

                //TODO Uno: Uncomment and implement
                ////
                //// We have a few tricks to figure out which VisualTree an element may be associated with.
                //// There is now a cached weak VisualTree pointer on each DO that we update when we do a live
                //// enter, so we may be able to remove some of these lookups.  Let's investigate this with bug 19548424.
                ////

                //if (Popup popup = do_pointer_cast<CPopup>(currentAncestor))
                //{
                //	if (CDependencyObject * owner = popup->GetToolTipOwner())
                //	{
                //		nextAncestor = owner;
                //	}

                //	if (CFlyoutBase * flyout = popup->GetAssociatedFlyoutNoRef())
                //	{
                //		if (VisualTree * visualTree = VisualTree::GetForElementNoRef(flyout))
                //		{
                //			return visualTree;
                //		}
                //	}

                //	if (nextAncestor == null && popup->IsOpen())
                //	{
                //		// If the popup is open, its child will be parented to a PopupRoot.  We
                //		// can quickly fine the root from there.
                //		CUIElement* popupChild = popup->GetChildNoRef();
                //		if (popupChild)
                //		{
                //			nextAncestor = popupChild->GetParentInternal(false /* public parent only */);
                //		}
                //	}
                //}

                //if (nextAncestor == null)
                //{
                //	if (CCollection * collection = do_pointer_cast<CCollection>(currentAncestor))
                //	{
                //		nextAncestor = collection->GetOwner();
                //	}
                //}

                //// If the next visual parent is null, check the logical parent. Popups are connected to their child with
                //// a logical link. Only allow the walk up if the logical parent is a popup.
                //if (nextAncestor == null)
                //{
                //	if (CUIElement * currentUIE = do_pointer_cast<CUIElement>(currentAncestor))
                //	{
                //		CPopup* nextAncestorPopup = do_pointer_cast<CPopup>(currentUIE->GetLogicalParentNoRef());
                //		nextAncestor = nextAncestorPopup;
                //	}
                //}

                currentAncestor = nextAncestor;
            }
            if (result == null)
            {
                if (options == LookupOptions.WarningIfNotFound)
                {
                    // We didn't find anything
                    VisualTreeNotFoundWarning();
                }
            }
            return(result);
        }
Example #26
0
        internal static FocusManager?GetFocusManagerForElement(DependencyObject?dependencyObject, LookupOptions options = LookupOptions.WarningIfNotFound)
        {
            if (GetContentRootForElement(dependencyObject, options) is { } contentRoot)
            {
                return(contentRoot.FocusManager);
            }

            if (dependencyObject?.GetContext().ContentRootCoordinator.CoreWindowContentRoot is ContentRoot coreWindowContentRoot)
            {
                return(coreWindowContentRoot.FocusManager);
            }

            return(null);
        }
Example #27
0
        internal void LookupSymbolInAliases(
            Binder originalBinder,
            LookupResult result,
            string name,
            int arity,
            ConsList <TypeSymbol> basesBeingResolved,
            LookupOptions options,
            bool diagnose,
            ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo
            )
        {
            bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder;

            AliasAndUsingDirective alias;

            if (this.UsingAliases.TryGetValue(name, out alias))
            {
                // Found a match in our list of normal aliases.  Mark the alias as being seen so that
                // it won't be reported to the user as something that can be removed.
                var res = originalBinder.CheckViability(
                    alias.Alias,
                    arity,
                    options,
                    null,
                    diagnose,
                    ref useSiteInfo,
                    basesBeingResolved
                    );
                if (res.Kind == LookupResultKind.Viable)
                {
                    MarkImportDirective(alias.UsingDirective, callerIsSemanticModel);
                }

                result.MergeEqual(res);
            }

            foreach (var a in this.ExternAliases)
            {
                if (a.Alias.Name == name)
                {
                    // Found a match in our list of extern aliases.  Mark the extern alias as being
                    // seen so that it won't be reported to the user as something that can be
                    // removed.
                    var res = originalBinder.CheckViability(
                        a.Alias,
                        arity,
                        options,
                        null,
                        diagnose,
                        ref useSiteInfo,
                        basesBeingResolved
                        );
                    if (res.Kind == LookupResultKind.Viable)
                    {
                        MarkImportDirective(a.ExternAliasDirective, callerIsSemanticModel);
                    }

                    result.MergeEqual(res);
                }
            }
        }
Example #28
0
        internal void LookupExtensionMethodsInUsings(
            ArrayBuilder <MethodSymbol> methods,
            string name,
            int arity,
            LookupOptions options,
            Binder originalBinder
            )
        {
            var binderFlags = originalBinder.Flags;

            if (binderFlags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            Debug.Assert(methods.Count == 0);

            bool callerIsSemanticModel = binderFlags.Includes(BinderFlags.SemanticModel);

            // We need to avoid collecting multiple candidates for an extension method imported both through a namespace and a static class
            // We will look for duplicates only if both of the following flags are set to true
            bool seenNamespaceWithExtensionMethods   = false;
            bool seenStaticClassWithExtensionMethods = false;

            foreach (var nsOrType in this.Usings)
            {
                switch (nsOrType.NamespaceOrType.Kind)
                {
                case SymbolKind.Namespace:
                {
                    var count = methods.Count;
                    ((NamespaceSymbol)nsOrType.NamespaceOrType).GetExtensionMethods(
                        methods,
                        name,
                        arity,
                        options
                        );

                    // If we found any extension methods, then consider this using as used.
                    if (methods.Count != count)
                    {
                        MarkImportDirective(nsOrType.UsingDirective, callerIsSemanticModel);
                        seenNamespaceWithExtensionMethods = true;
                    }
                    break;
                }

                case SymbolKind.NamedType:
                {
                    var count = methods.Count;
                    ((NamedTypeSymbol)nsOrType.NamespaceOrType).GetExtensionMethods(
                        methods,
                        name,
                        arity,
                        options
                        );

                    // If we found any extension methods, then consider this using as used.
                    if (methods.Count != count)
                    {
                        MarkImportDirective(nsOrType.UsingDirective, callerIsSemanticModel);
                        seenStaticClassWithExtensionMethods = true;
                    }
                    break;
                }
                }
            }

            if (seenNamespaceWithExtensionMethods && seenStaticClassWithExtensionMethods)
            {
                methods.RemoveDuplicates();
            }
        }
Example #29
0
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (CanConsiderTypeParameters(options))
     {
         foreach (var parameter in _typeArguments)
         {
             if (originalBinder.CanAddLookupSymbolInfo(parameter.TypeSymbol, options, result, null))
             {
                 result.AddSymbol(parameter.TypeSymbol, parameter.Name, 0);
             }
         }
     }
 }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (options.CanConsiderLocals())
     {
         foreach (var parameter in _parameters)
         {
             if (originalBinder.CanAddLookupSymbolInfo(parameter, options, result, null))
             {
                 result.AddSymbol(parameter, parameter.Name, 0);
             }
         }
     }
 }
Example #31
0
        private void AppendSymbolsWithNameAndArity(
            ArrayBuilder<Symbol> results,
            string name,
            int arity,
            Binder binder,
            NamespaceOrTypeSymbol container,
            LookupOptions options)
        {
            Debug.Assert(results != null);

            // Don't need to de-dup since AllMethodsOnArityZero can't be set at this point (not exposed in CommonLookupOptions).
            Debug.Assert((options & LookupOptions.AllMethodsOnArityZero) == 0);

            var lookupResult = LookupResult.GetInstance();

            HashSet<DiagnosticInfo> useSiteDiagnostics = null;
            binder.LookupSymbolsSimpleName(
                lookupResult,
                container,
                name,
                arity,
                basesBeingResolved: null,
                options: options & ~LookupOptions.IncludeExtensionMethods,
                diagnose: false,
                useSiteDiagnostics: ref useSiteDiagnostics);

            if (lookupResult.IsMultiViable)
            {
                if (lookupResult.Symbols.Any(t => t.Kind == SymbolKind.NamedType || t.Kind == SymbolKind.Namespace || t.Kind == SymbolKind.ErrorType))
                {
                    // binder.ResultSymbol is defined only for type/namespace lookups
                    bool wasError;
                    var diagnostics = DiagnosticBag.GetInstance();  // client code never expects a null diagnostic bag.
                    Symbol singleSymbol = binder.ResultSymbol(lookupResult, name, arity, this.Root, diagnostics, true, out wasError, container, options);
                    diagnostics.Free();

                    if (!wasError)
                    {
                        results.Add(singleSymbol);
                    }
                    else
                    {
                        results.AddRange(lookupResult.Symbols);
                    }
                }
                else
                {
                    results.AddRange(lookupResult.Symbols);
                }
            }

            lookupResult.Free();
        }
Example #32
0
        private static void AddAliasSymbolToResult(LookupSymbolsInfo result, AliasSymbol aliasSymbol, LookupOptions options, Binder originalBinder)
        {
            var targetSymbol = aliasSymbol.GetAliasTarget(basesBeingResolved: null);

            if (originalBinder.CanAddLookupSymbolInfo(targetSymbol, options, result, accessThroughType: null, aliasSymbol: aliasSymbol))
            {
                result.AddSymbol(aliasSymbol, aliasSymbol.Name, 0);
            }
        }
Example #33
0
        internal static void AddLookupSymbolsInfoInUsings(
            ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, Binder binder, LookupSymbolsInfo result, LookupOptions options)
        {
            Debug.Assert(!options.CanConsiderNamespaces());

            // look in all using namespaces
            foreach (var namespaceSymbol in usings)
            {
                foreach (var member in namespaceSymbol.NamespaceOrType.GetMembersUnordered())
                {
                    if (binder.CanAddLookupSymbolInfo(member, options, null))
                    {
                        result.AddSymbol(member, member.Name, member.GetArity());
                    }
                }
            }
        }
 internal override void LookupSymbolsInSingleBinder(LookupResult result, string symbolId, LookupOptions options, Binder originalBinder, bool diagnose)
 {
     if (options.CanConsiderCatalogues())
     {
         originalBinder.CheckViability(result, NamespaceSymbol.Catalogues, symbolId, options, diagnose);
     }
 }
Example #35
0
        private Binder XSLookupSymbolsInternal(
            LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert(result.IsClear);
            Debug.Assert(options.AreValid());

            // X# looks for functions first
            //if (Compilation.Options.HasRuntime)
            {
                // check for function calls method calls outside the current class
                bool check = (options.HasFlag(LookupOptions.MustNotBeInstance) && !options.HasFlag(LookupOptions.MustNotBeMethod));
                if (check)
                {
                    var funcOptions = options;
                    funcOptions |= LookupOptions.MustBeInvocableIfMember;
                    Binder scope = this;
                    while (scope != null)
                    {
                        if (scope is InContainerBinder && scope.ContainingType == null) // at the namespace level, so outside of all types
                        {
                            scope.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, funcOptions, this, diagnose, ref useSiteDiagnostics);
                            FilterResults(result, options);
                            if (!result.IsClear)
                            {
                                break;
                            }
                        }
                        scope = scope.Next;
                    }
                }
            }
            LookupResult functionResults = LookupResult.GetInstance();

            if (!result.IsClear)
            {
                foreach (var symbol in result.Symbols)
                {
                    if (symbol is MethodSymbol)
                    {
                        var ms = symbol as MethodSymbol;
                        if (ms.IsStatic && ms.ContainingType.Name.EndsWith("Functions", XSharpString.Comparison))
                        {
                            SingleLookupResult single = new SingleLookupResult(LookupResultKind.Viable, ms, null);
                            functionResults.MergeEqual(single);
                        }
                    }
                }
                result.Clear();
            }
            Binder binder = null;

            for (var scope = this; scope != null && !result.IsMultiViable; scope = scope.Next)
            {
                if (binder != null)
                {
                    var tmp = LookupResult.GetInstance();
                    scope.LookupSymbolsInSingleBinder(tmp, name, arity, basesBeingResolved, options, this, diagnose, ref useSiteDiagnostics);
                    FilterResults(tmp, options);
                    result.MergeEqual(tmp);
                    tmp.Free();
                }
                else
                {
                    scope.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, this, diagnose, ref useSiteDiagnostics);
                    FilterResults(result, options);
                    if (!result.IsClear)
                    {
                        binder = scope;
                    }
                }
            }
            if (!functionResults.IsClear)
            {
                // compare the function results with the overall results found
                // create a list of functions and methods
                // function first and then the methods
                LookupResult mergedResults = LookupResult.GetInstance();
                mergedResults.MergeEqual(functionResults);
                // now add the symbols from result that do not exist
                for (int j = 0; j < result.Symbols.Count; j++)
                {
                    var sym   = result.Symbols[j];
                    var found = false;
                    for (int i = 0; i < mergedResults.Symbols.Count; i++)
                    {
                        if (sym == mergedResults.Symbols[i])
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        SingleLookupResult single = new SingleLookupResult(LookupResultKind.Viable, sym, null);
                        mergedResults.MergeEqual(single);
                    }
                }
                result.Clear();
                result.MergeEqual(mergedResults);
            }
            // C563 Make sure the error is generated for Inaccessible types.
            if (!result.IsClear && result.Kind == LookupResultKind.Inaccessible && result.Error != null)
            {
                // we only want to add this for internal fields (globals)
                if (result.Symbols[0].Kind == SymbolKind.Field)
                {
                    if (useSiteDiagnostics == null)
                    {
                        useSiteDiagnostics = new HashSet <DiagnosticInfo>();
                    }
                    useSiteDiagnostics.Add(result.Error);
                }
            }
            return(binder);
        }
Example #36
0
 internal override void GetExtensionMethods(ArrayBuilder <MethodSymbol> methods, string name, int arity, LookupOptions options)
 {
     foreach (NamespaceSymbol namespaceSymbol in _namespacesToMerge)
     {
         namespaceSymbol.GetExtensionMethods(methods, name, arity, options);
     }
 }
Example #37
0
 private static bool OnlyOneBitSet(LookupOptions o)
 {
     return (o & (o - 1)) == 0;
 }
Example #38
0
        internal override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            if (CanConsiderTypeParameters(options))
            {
                foreach (var kvp in TypeParameterMap)
                {
                    foreach (TypeParameterSymbol typeParameter in kvp.Value)
                    {
                        // In any context where this binder applies, the type parameters are always viable/speakable.
                        Debug.Assert(!result.CanBeAdded(typeParameter.Name) || originalBinder.CanAddLookupSymbolInfo(typeParameter, options, result, null));

                        result.AddSymbol(typeParameter, kvp.Key, 0);
                    }
                }
            }
        }
Example #39
0
 internal override void GetCandidateExtensionMethods(
     bool searchUsingsNotNamespace,
     ArrayBuilder<MethodSymbol> methods,
     string name,
     int arity,
     LookupOptions options,
     bool isCallerSemanticModel)
 {
     if (searchUsingsNotNamespace)
     {
         this.GetImports().LookupExtensionMethodsInUsings(methods, name, arity, options, isCallerSemanticModel);
     }
     else
     {
         if (_container.Kind == SymbolKind.Namespace)
         {
             ((NamespaceSymbol)_container).GetExtensionMethods(methods, name, arity, options);
         }
         else if (((NamedTypeSymbol)_container).IsScriptClass)
         {
             for (var submission = this.Compilation; submission != null; submission = submission.PreviousSubmission)
             {
                 var scriptClass = submission.ScriptClass;
                 if ((object)scriptClass != null)
                 {
                     scriptClass.GetExtensionMethods(methods, name, arity, options);
                 }
             }
         }
     }
 }
Example #40
0
 private static bool OnlyOneBitSet(LookupOptions o)
 {
     return((o & (o - 1)) == 0);
 }
Example #41
0
        /// <summary>
        /// Look for any symbols in scope with the given name and arity.
        /// </summary>
        /// <remarks>
        /// Makes a second attempt if the results are not viable, in order to produce more detailed failure information (symbols and diagnostics).
        /// </remarks>
        private Binder XSLookupSymbolsWithFallback(LookupResult result, string name, int arity, ref HashSet <DiagnosticInfo> useSiteDiagnostics, ConsList <Symbol> basesBeingResolved = null, LookupOptions options = LookupOptions.Default)
        {
            Debug.Assert(options.AreValid());

            // don't create diagnosis instances unless lookup fails
            var binder = this.LookupSymbolsInternal(result, name, arity, basesBeingResolved, options, diagnose: false, useSiteDiagnostics: ref useSiteDiagnostics);

            FilterResults(result, options);
            if (result.Kind != LookupResultKind.Viable && result.Kind != LookupResultKind.Empty)
            {
                result.Clear();
                // retry to get diagnosis
                var otherBinder = this.LookupSymbolsInternal(result, name, arity, basesBeingResolved, options, diagnose: true, useSiteDiagnostics: ref useSiteDiagnostics);
                Debug.Assert(binder == otherBinder);
            }

            Debug.Assert(result.IsMultiViable || result.IsClear || result.Error != null);
            return(binder);
        }
Example #42
0
 internal static bool CanConsiderLocals(this LookupOptions options)
 {
     return((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) == 0);
 }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (options.CanConsiderMembers())
     {
         foreach (var kvp in _parameterMap)
         {
             result.AddSymbol(null, kvp.Key, 0);
         }
     }
 }
Example #44
0
 internal override void GetCandidateExtensionMethods(
     bool searchUsingsNotNamespace,
     ArrayBuilder<MethodSymbol> methods,
     string name,
     int arity,
     LookupOptions options,
     Binder originalBinder)
 {
     if (searchUsingsNotNamespace)
     {
         this.GetImports(basesBeingResolved: null).LookupExtensionMethodsInUsings(methods, name, arity, options, originalBinder);
     }
     else if (_container?.Kind == SymbolKind.Namespace)
     {
         ((NamespaceSymbol)_container).GetExtensionMethods(methods, name, arity, options);
     }
     else if (IsSubmissionClass)
     {
         for (var submission = this.Compilation; submission != null; submission = submission.PreviousSubmission)
         {
             submission.ScriptClass?.GetExtensionMethods(methods, name, arity, options);
         }
     }
 }
 protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
 {
     if (options.CanConsiderMembers())
     {
         foreach (var kvp in _parameterMap)
         {
             result.AddSymbol(null, kvp.Key, 0);
         }
     }
 }
Example #46
0
        /// <summary>
        /// Gets the available named symbols in the context of the specified location and optional
        /// container. Only symbols that are accessible and visible from the given location are
        /// returned.
        /// </summary>
        /// <param name="position">The character position for determining the enclosing declaration
        /// scope and accessibility.</param>
        /// <param name="container">The container to search for symbols within. If null then the
        /// enclosing declaration scope around position is used.</param>
        /// <param name="name">The name of the symbol to find. If null is specified then symbols
        /// with any names are returned.</param>
        /// <param name="options">Additional options that affect the lookup process.</param>
        /// <param name="useBaseReferenceAccessibility">Ignore 'throughType' in accessibility checking. 
        /// Used in checking accessibility of symbols accessed via 'MyBase' or 'base'.</param>
        /// <remarks>
        /// The "position" is used to determine what variables are visible and accessible. Even if
        /// "container" is specified, the "position" location is significant for determining which
        /// members of "containing" are accessible. 
        /// </remarks>
        /// <exception cref="ArgumentException">Throws an argument exception if the passed lookup options are invalid.</exception>
        private ImmutableArray<Symbol> LookupSymbolsInternal(
            int position,
            NamespaceOrTypeSymbol container,
            string name,
            LookupOptions options,
            bool useBaseReferenceAccessibility)
        {
            Debug.Assert((options & LookupOptions.UseBaseReferenceAccessibility) == 0, "Use the useBaseReferenceAccessibility parameter.");
            if (useBaseReferenceAccessibility)
            {
                options |= LookupOptions.UseBaseReferenceAccessibility;
            }
            Debug.Assert(!options.IsAttributeTypeLookup()); // Not exposed publicly.

            options.ThrowIfInvalid();

            SyntaxToken token;
            position = CheckAndAdjustPosition(position, out token);

            if ((object)container == null || container.Kind == SymbolKind.Namespace)
            {
                options &= ~LookupOptions.IncludeExtensionMethods;
            }

            var binder = GetEnclosingBinder(position);
            if (binder == null)
            {
                return ImmutableArray<Symbol>.Empty;
            }

            if (useBaseReferenceAccessibility)
            {
                Debug.Assert((object)container == null);
                TypeSymbol containingType = binder.ContainingType;
                TypeSymbol baseType = null;

                // For a script class or a submission class base should have no members.
                if ((object)containingType != null && containingType.Kind == SymbolKind.NamedType && ((NamedTypeSymbol)containingType).IsScriptClass)
                {
                    return ImmutableArray<Symbol>.Empty;
                }

                if ((object)containingType == null || (object)(baseType = containingType.BaseTypeNoUseSiteDiagnostics) == null)
                {
                    throw new ArgumentException(
                        "Not a valid position for a call to LookupBaseMembers (must be in a type with a base type)",
                        nameof(position));
                }
                container = baseType;
            }

            if (!binder.IsInMethodBody &&
                (options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) == 0)
            {
                // Method type parameters are not in scope outside a method
                // body unless the position is either:
                // a) in a type-only context inside an expression, or
                // b) inside of an XML name attribute in an XML doc comment.
                var parentExpr = token.Parent as ExpressionSyntax;
                if (parentExpr != null && !(parentExpr.Parent is XmlNameAttributeSyntax) && !SyntaxFacts.IsInTypeOnlyContext(parentExpr))
                {
                    options |= LookupOptions.MustNotBeMethodTypeParameter;
                }
            }

            var info = LookupSymbolsInfo.GetInstance();

            if ((object)container == null)
            {
                binder.AddLookupSymbolsInfo(info, options);
            }
            else
            {
                binder.AddMemberLookupSymbolsInfo(info, container, options, binder);
            }

            var results = ArrayBuilder<Symbol>.GetInstance(info.Count);

            if (name == null)
            {
                // If they didn't provide a name, then look up all names and associated arities 
                // and find all the corresponding symbols.
                foreach (string foundName in info.Names)
                {
                    AppendSymbolsWithName(results, foundName, binder, container, options, info);
                }
            }
            else
            {
                // They provided a name.  Find all the arities for that name, and then look all of those up.
                AppendSymbolsWithName(results, name, binder, container, options, info);
            }

            info.Free();


            if ((options & LookupOptions.IncludeExtensionMethods) != 0)
            {
                var lookupResult = LookupResult.GetInstance();

                options |= LookupOptions.AllMethodsOnArityZero;
                options &= ~LookupOptions.MustBeInstance;

                HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                binder.LookupExtensionMethods(lookupResult, name, 0, options, ref useSiteDiagnostics);

                if (lookupResult.IsMultiViable)
                {
                    TypeSymbol containingType = (TypeSymbol)container;
                    foreach (MethodSymbol extensionMethod in lookupResult.Symbols)
                    {
                        var reduced = extensionMethod.ReduceExtensionMethod(containingType);
                        if ((object)reduced != null)
                        {
                            results.Add(reduced);
                        }
                    }
                }

                lookupResult.Free();
            }

            ImmutableArray<Symbol> sealedResults = results.ToImmutableAndFree();
            return name == null
                ? FilterNotReferencable(sealedResults)
                : sealedResults;
        }
 internal override void GetCandidateExtensionMethods(
     bool searchUsingsNotNamespace,
     ArrayBuilder<MethodSymbol> methods,
     string name,
     int arity,
     LookupOptions options,
     bool isCallerSemanticModel)
 {
     if (searchUsingsNotNamespace)
     {
         this.GetImports().LookupExtensionMethodsInUsings(methods, name, arity, options, isCallerSemanticModel);
     }
     else
     {
         if (_container.Kind == SymbolKind.Namespace)
         {
             ((NamespaceSymbol)_container).GetExtensionMethods(methods, name, arity, options);
         }
     }
 }
Example #48
0
        private static void AddLookupSymbolsInfoInUsings(
            ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            if (originalBinder.Flags.Includes(BinderFlags.InScriptUsing))
            {
                return;
            }

            Debug.Assert(!options.CanConsiderNamespaces());

            // look in all using namespaces
            foreach (var namespaceSymbol in usings)
            {
                foreach (var member in namespaceSymbol.NamespaceOrType.GetMembersUnordered())
                {
                    if (IsValidLookupCandidateInUsings(member) && originalBinder.CanAddLookupSymbolInfo(member, options, result, null))
                    {
                        result.AddSymbol(member, member.Name, member.GetArity());
                    }
                }
            }
        }
 protected sealed override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo info, LookupOptions options, Binder originalBinder)
 {
     throw new NotImplementedException();
 }
        protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            this.AddMemberLookupSymbolsInfo(result, _container, options, originalBinder);

            // if we are looking only for labels we do not need to search through the imports
            if (!_container.IsSubmissionClass && ((options & LookupOptions.LabelsOnly) == 0))
            {
                var imports = GetImports(basesBeingResolved: null);

                imports.AddLookupSymbolsInfoInAliases(this, result, options);

                // Add types within namespaces imported through usings, but don't add nested namespaces.
                LookupOptions usingOptions = (options & ~(LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly)) | LookupOptions.MustNotBeNamespace;
                Imports.AddLookupSymbolsInfoInUsings(imports.Usings, this, result, usingOptions);
            }
        }
Example #51
0
        protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            if (_container != null)
            {
                this.AddMemberLookupSymbolsInfo(result, _container, options, originalBinder);
            }

            // If we are looking only for labels we do not need to search through the imports.
            // Submission imports are handled by AddMemberLookupSymbolsInfo (above).
            if (!IsSubmissionClass && ((options & LookupOptions.LabelsOnly) == 0))
            {
                var imports = GetImports(basesBeingResolved: null);
                imports.AddLookupSymbolsInfo(result, options, originalBinder);
            }
        }
Example #52
0
        protected override void AddLookupSymbolsInfoInSingleBinder(LookupSymbolsInfo result, LookupOptions options, Binder originalBinder)
        {
            if (_container != null)
            {
                this.AddMemberLookupSymbolsInfo(result, _container, options, originalBinder);
            }

            // If we are looking only for labels we do not need to search through the imports.
            // Submission imports are handled by AddMemberLookupSymbolsInfo (above).
            if (!IsSubmissionClass && ((options & LookupOptions.LabelsOnly) == 0))
            {
                var imports = GetImports(basesBeingResolved: null);
                imports.AddLookupSymbolsInfo(result, options, originalBinder);
            }
        }
Example #53
0
        private void AppendSymbolsWithName(ArrayBuilder<Symbol> results, string name, Binder binder, NamespaceOrTypeSymbol container, LookupOptions options, LookupSymbolsInfo info)
        {
            LookupSymbolsInfo.IArityEnumerable arities;
            Symbol uniqueSymbol;

            if (info.TryGetAritiesAndUniqueSymbol(name, out arities, out uniqueSymbol))
            {
                if ((object)uniqueSymbol != null)
                {
                    // This name mapped to something unique.  We don't need to proceed
                    // with a costly lookup.  Just add it straight to the results.
                    results.Add(uniqueSymbol);
                }
                else
                {
                    // The name maps to multiple symbols. Actually do a real lookup so 
                    // that we will properly figure out hiding and whatnot.
                    if (arities != null)
                    {
                        foreach (var arity in arities)
                        {
                            this.AppendSymbolsWithNameAndArity(results, name, arity, binder, container, options);
                        }
                    }
                    else
                    {
                        //non-unique symbol with non-zero arity doesn't seem possible.
                        this.AppendSymbolsWithNameAndArity(results, name, 0, binder, container, options);
                    }
                }
            }
        }
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList <TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            foreach (ParameterSymbol parameter in _parameters)
            {
                if (parameter.Name == name)
                {
                    result.MergeEqual(originalBinder.CheckViability(parameter, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }
Example #55
0
 internal static bool CanConsiderNamespaces(this LookupOptions options)
 {
     return((options & (LookupOptions.MustNotBeNamespace | LookupOptions.MustBeInvocableIfMember | LookupOptions.MustBeInstance | LookupOptions.LabelsOnly)) == 0);
 }
        public IMember LookupNameInScopes(string name, out IScope scope, out IVariable v, LookupOptions options)
        {
            scope = null;
            var classMembers = (options & LookupOptions.ClassMembers) == LookupOptions.ClassMembers;

            switch (options)
            {
            case LookupOptions.All:
            case LookupOptions.Normal:
                // Regular lookup: all scopes and builtins.
                for (var s = CurrentScope; s != null; s = (Scope)s.OuterScope)
                {
                    if (s.Variables.TryGetVariable(name, out var v1) && (!v1.IsClassMember || classMembers))
                    {
                        scope = s;
                        break;
                    }
                }
                break;

            case LookupOptions.Global:
            case LookupOptions.Global | LookupOptions.Builtins:
                // Global scope only.
                if (GlobalScope.Variables.Contains(name))
                {
                    scope = GlobalScope;
                }
                break;

            case LookupOptions.Nonlocal:
            case LookupOptions.Nonlocal | LookupOptions.Builtins:
                // All scopes but current and global ones.
                for (var s = CurrentScope.OuterScope as Scope; s != null && s != GlobalScope; s = (Scope)s.OuterScope)
                {
                    if (s.Variables.Contains(name))
                    {
                        scope = s;
                        break;
                    }
                }
                break;

            case LookupOptions.Local:
            case LookupOptions.Local | LookupOptions.Builtins:
                // Just the current scope
                if (CurrentScope.Variables.Contains(name))
                {
                    scope = CurrentScope;
                }
                break;

            default:
                Debug.Fail("Unsupported name lookup combination");
                break;
            }

            v = scope?.Variables[name];
            var value = v?.Value;

            if (value == null && options.HasFlag(LookupOptions.Builtins))
            {
                var builtins = Interpreter.ModuleResolution.BuiltinsModule;
                value = Interpreter.ModuleResolution.BuiltinsModule.GetMember(name);
                if (Module != builtins && options.HasFlag(LookupOptions.Builtins))
                {
                    value = builtins.GetMember(name);
                    scope = builtins.GlobalScope;
                }
            }

            return(value);
        }
        internal override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
        {
            Debug.Assert(result.IsClear);

            if (_container.IsSubmissionClass)
            {
                this.LookupMembersInternal(result, _container, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);
                return;
            }

            var imports = GetImports(basesBeingResolved);

            // first lookup members of the namespace
            if ((options & LookupOptions.NamespaceAliasesOnly) == 0)
            {
                this.LookupMembersInternal(result, _container, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);

                if (result.IsMultiViable)
                {
                    // symbols cannot conflict with using alias names
                    if (arity == 0 && imports.IsUsingAlias(name, originalBinder.IsSemanticModelBinder))
                    {
                        CSDiagnosticInfo diagInfo = new CSDiagnosticInfo(ErrorCode.ERR_ConflictAliasAndMember, name, _container);
                        var error = new ExtendedErrorTypeSymbol((NamespaceOrTypeSymbol)null, name, arity, diagInfo, unreported: true);
                        result.SetFrom(LookupResult.Good(error)); // force lookup to be done w/ error symbol as result
                    }

                    return;
                }
            }

            // next try using aliases or symbols in imported namespaces
            imports.LookupSymbol(originalBinder, result, name, arity, basesBeingResolved, options, diagnose, ref useSiteDiagnostics);
        }
Example #58
0
 internal static bool IsAttributeTypeLookup(this LookupOptions options)
 {
     return((options & LookupOptions.AttributeTypeOnly) == LookupOptions.AttributeTypeOnly);
 }
 internal override void GetExtensionMethods(ArrayBuilder<MethodSymbol> methods, string name, int arity, LookupOptions options)
 {
     foreach (NamespaceSymbol namespaceSymbol in namespacesToMerge)
     {
         namespaceSymbol.GetExtensionMethods(methods, name, arity, options);
     }
 }
        protected override void LookupSymbolsInSingleBinder(
            LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics)
        {
            if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.MustBeInvocableIfMember)) != 0)
            {
                return;
            }

            Debug.Assert(result.IsClear);

            var count = parameterMap.GetCountForKey(name);

            if (count == 1)
            {
                ParameterSymbol p;
                parameterMap.TryGetSingleValue(name, out p);
                result.MergeEqual(originalBinder.CheckViability(p, arity, options, null, diagnose, ref useSiteDiagnostics));
            }
            else if (count > 1)
            {
                var parameters = parameterMap[name];
                foreach (var sym in parameters)
                {
                    result.MergeEqual(originalBinder.CheckViability(sym, arity, options, null, diagnose, ref useSiteDiagnostics));
                }
            }
        }