protected override void LookupSymbolsInSingleBinder( LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Debug.Assert(options.AreValid()); Debug.Assert(result.IsClear); if ((options & LookupOptions.LabelsOnly) != 0) { var labelsMap = this.LabelsMap; if (labelsMap != null) { LabelSymbol labelSymbol; if (labelsMap.TryGetValue(name, out labelSymbol)) { result.MergeEqual(LookupResult.Good(labelSymbol)); } } return; } var localsMap = this.LocalsMap; if (localsMap != null && (options & LookupOptions.NamespaceAliasesOnly) == 0) { LocalSymbol localSymbol; if (localsMap.TryGetValue(name, out localSymbol)) { result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved)); } } }
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)); } } }
protected override void LookupSymbolsInSingleBinder( LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { if (parameterMap == null || (options & LookupOptions.NamespaceAliasesOnly) != 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 override void LookupSymbolsInSingleBinder( LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Debug.Assert(options.AreValid()); Debug.Assert(result.IsClear); if ((options & LookupOptions.LabelsOnly) != 0) { var labelsMap = this.LabelsMap; if (labelsMap != null) { LabelSymbol labelSymbol; if (labelsMap.TryGetValue(name, out labelSymbol)) { result.MergeEqual(LookupResult.Good(labelSymbol)); } } return; } var localsMap = this.LocalsMap; if (localsMap != null && (options & LookupOptions.NamespaceAliasesOnly) == 0) { LocalSymbol localSymbol; if (localsMap.TryGetValue(name, out localSymbol)) { #if XSHARP if ((options & LookupOptions.MustBeInvocableIfMember) == 0 || localSymbol.Type.TypeKind == TypeKind.Delegate) { result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved)); } #else result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved)); #endif } } var localFunctionsMap = this.LocalFunctionsMap; if (localFunctionsMap != null && options.CanConsiderLocals()) { LocalFunctionSymbol localSymbol; if (localFunctionsMap.TryGetValue(name, out localSymbol)) { result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved)); } } }
internal void LookupSymbolInAliases( Binder originalBinder, LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { 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 useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(alias.UsingDirective, callerIsSemanticModel); } result.MergeEqual(res); } foreach (var a in this.ExternAliases) { #if XSHARP if (XSharpString.Equals(a.Alias.Name, name)) #else if (a.Alias.Name == name) #endif { // 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 useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(a.ExternAliasDirective, callerIsSemanticModel); } result.MergeEqual(res); } } }
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 (_methodSymbol.ParameterCount == 0 || (options & LookupOptions.NamespaceAliasesOnly) != 0) { return; } var parameterMap = _lazyParameterMap; if (parameterMap == null) { var parameters = _methodSymbol.Parameters; parameterMap = new MultiDictionary <string, ParameterSymbol>(parameters.Length, EqualityComparer <string> .Default); foreach (var parameter in parameters) { parameterMap.Add(parameter.Name, parameter); } _lazyParameterMap = parameterMap; } foreach (var parameterSymbol in parameterMap[name]) { result.MergeEqual(originalBinder.CheckViability(parameterSymbol, arity, options, null, diagnose, ref useSiteDiagnostics)); } }
internal override void LookupSymbolsInSingleBinder(LookupResult result, string name, int arity, ConsList <TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo) { bool foundParameter = false; if (_withParametersBinder is not null && IsNameofOperator) { _withParametersBinder.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteInfo); if (!result.IsClear) { if (result.IsMultiViable) { return; } foundParameter = true; } } if (_withTypeParametersBinder is not null && IsNameofOperator) { if (foundParameter) { var tmp = LookupResult.GetInstance(); _withTypeParametersBinder.LookupSymbolsInSingleBinder(tmp, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteInfo); result.MergeEqual(tmp); } else { _withTypeParametersBinder.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteInfo); } } }
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); bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in this.GetUsings(basesBeingResolved)) { ImmutableArray <Symbol> candidates = Binder.GetCandidateMembers(typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder); foreach (Symbol symbol in candidates) { if (!IsValidLookupCandidateInUsings(symbol)) { continue; } // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability(symbol, arity, options, null, diagnose, ref useSiteInfo, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(typeOrNamespace.UsingDirectiveReference, callerIsSemanticModel); } result.MergeEqual(res); } } }
internal void LookupSymbolInUsings( ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, Binder originalBinder, LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in usings) { ImmutableArray <Symbol> candidates = Binder.GetCandidateMembers(typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder); foreach (Symbol symbol in candidates) { // lookup via "using namespace" ignores namespaces inside if (symbol.Kind != SymbolKind.Namespace) { // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability(symbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(typeOrNamespace.UsingDirective, callerIsSemanticModel); } result.MergeEqual(res); } } } }
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 ((options & LookupOptions.NamespaceAliasesOnly) != 0) { return; } foreach (var parameterSymbol in parameterMap[name]) { result.MergeEqual( originalBinder.CheckViability( parameterSymbol, arity, options, null, diagnose, ref useSiteInfo ) ); } }
internal static void LookupSymbolInUsings( ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, Binder originalBinder, LookupResult result, string name, int arity, ConsList <TypeSymbol> basesBeingResolved, LookupOptions options, bool diagnose, ref CompoundUseSiteInfo <AssemblySymbol> useSiteInfo ) { if (originalBinder.Flags.Includes(BinderFlags.InScriptUsing)) { return; } bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in usings) { ImmutableArray <Symbol> candidates = Binder.GetCandidateMembers( typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder ); foreach (Symbol symbol in candidates) { if (!IsValidLookupCandidateInUsings(symbol)) { continue; } // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability( symbol, arity, options, null, diagnose, ref useSiteInfo, basesBeingResolved ); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective( originalBinder.Compilation, typeOrNamespace.UsingDirective, callerIsSemanticModel ); } result.MergeEqual(res); } } }
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(options.AreValid()); Debug.Assert(result.IsClear); if ((options & LookupOptions.LabelsOnly) != 0) { var labelsMap = this.LabelsMap; if (labelsMap != null) { LabelSymbol labelSymbol; if (labelsMap.TryGetValue(name, out labelSymbol)) { result.MergeEqual(LookupResult.Good(labelSymbol)); } } return; } var localsMap = this.LocalsMap; if (localsMap != null && (options & LookupOptions.NamespaceAliasesOnly) == 0) { LocalSymbol localSymbol; if (localsMap.TryGetValue(name, out localSymbol)) { result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteInfo, basesBeingResolved)); } } var localFunctionsMap = this.LocalFunctionsMap; if (localFunctionsMap != null && options.CanConsiderLocals()) { LocalFunctionSymbol localSymbol; if (localFunctionsMap.TryGetValue(name, out localSymbol)) { result.MergeEqual(originalBinder.CheckViability(localSymbol, arity, options, null, diagnose, ref useSiteInfo, basesBeingResolved)); } } }
/// <summary> /// Tries to look up symbols inside a witness type parameter. /// <para> /// This lookup checks all of the concepts this witness implements /// to see if any contain a viable method matching the symbol. /// </para> /// <para> /// This lookup approach only works for methods and properties, and /// returns members whose parents are type parameters. We rely on /// later stages to detect this and resolve it back to a proper /// statement. /// </para> /// </summary> /// <param name="witness"> /// The type witness into which we are looking. /// </param> /// <param name="result"> /// The lookup result to populate. /// </param> /// <param name="name"> /// The name of the member being looked-up. /// </param> /// <param name="arity"> /// The arity of the member being looked up. /// </param> /// <param name="basesBeingResolved"> /// The set of bases being resolved. /// </param> /// <param name="options"> /// The lookup options in effect. /// </param> /// <param name="originalBinder"> /// The top-level binder. /// </param> /// <param name="diagnose"> /// Whether or not we are diagnosing. /// </param> /// <param name="useSiteDiagnostics"> /// Diagnostics set at the use-site. /// </param> internal void LookupSymbolsInWitness( TypeParameterSymbol witness, LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Debug.Assert(witness.IsConceptWitness); var concepts = witness.ProvidedConcepts; if (concepts.IsDefaultOrEmpty) { return; } foreach (var c in concepts) { var members = GetCandidateMembers(c, name, options, originalBinder); foreach (var member in members) { switch (member.Kind) { case SymbolKind.Method: var method = (MethodSymbol)member; // Suppose our witness is W : C<A>, and this finds C<A>.M(x). // We need to return that we found W.M(x), but W is a type // parameter! While we can handle this later on in binding, // the main issue is changing C<A> to W, for which we use // a synthesized method symbol. var witnessMethod = new SynthesizedWitnessMethodSymbol(method, witness); SingleLookupResult resultOfThisMethod = originalBinder.CheckViability(witnessMethod, arity, options, witness, diagnose, ref useSiteDiagnostics, basesBeingResolved); result.MergeEqual(resultOfThisMethod); break; case SymbolKind.Property: var prop = (PropertySymbol)member; var witnessProp = new SynthesizedWitnessPropertySymbol(prop, witness); SingleLookupResult resultOfThisProp = originalBinder.CheckViability(witnessProp, arity, options, witness, diagnose, ref useSiteDiagnostics, basesBeingResolved); result.MergeEqual(resultOfThisProp); break; // We don't allow other types to be fields of a witness } } } }
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 & LookupMask) != 0) { return; } foreach (var typeParameter in TypeParameterMap[name]) { result.MergeEqual(originalBinder.CheckViability(typeParameter, arity, options, null, diagnose, ref useSiteDiagnostics)); } }
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 (_parameterMap == null || (options & LookupOptions.NamespaceAliasesOnly) != 0) { return; } foreach (var parameterSymbol in _parameterMap[name]) { result.MergeEqual(originalBinder.CheckViability(parameterSymbol, arity, options, null, diagnose, ref useSiteDiagnostics)); } }
internal override void LookupSymbolsInSingleBinder( LookupResult result, string name, int arity, ConsList <TypeSymbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Debug.Assert(result.IsClear); if ((options & LookupMask) != 0) { return; } foreach (var typeParameter in TypeParameterMap[name]) { result.MergeEqual(originalBinder.CheckViability(typeParameter, arity, options, null, diagnose, ref useSiteDiagnostics)); } }
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)); } } }
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)); } } }
internal virtual void LookupConceptMethodsInSingleBinder(LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics, ConceptSearchOptions coptions) { var conceptBuilder = ArrayBuilder <NamedTypeSymbol> .GetInstance(); GetConcepts(coptions, conceptBuilder, originalBinder, ref useSiteDiagnostics); var concepts = conceptBuilder.ToImmutableAndFree(); foreach (var concept in concepts) { var methodBuilder = ArrayBuilder <MethodSymbol> .GetInstance(); AddConceptMethods(concept, methodBuilder, name, arity, options, coptions); foreach (var method in methodBuilder.ToImmutableAndFree()) { SingleLookupResult resultOfThisMethod = originalBinder.CheckViability(method, arity, options, concept, diagnose, ref useSiteDiagnostics, basesBeingResolved); result.MergeEqual(resultOfThisMethod); } } }
internal 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) != 0) { 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(); }
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(); }
/// <summary> /// Tries to look up symbols inside a witness type parameter. /// <para> /// This lookup checks all of the concepts this witness implements /// to see if any contain a viable method matching the symbol. /// </para> /// <para> /// This lookup approach only works for methods, and returns a /// method whose parent is a type parameter. We rely on later /// binder stages to detect this and resolve it back to a proper /// statement. /// </para> /// </summary> /// <param name="witness"> /// The type witness into which we are looking. /// </param> /// <param name="result"> /// The lookup result to populate. /// </param> /// <param name="name"> /// The name of the member being looked-up. /// </param> /// <param name="arity"> /// The arity of the member being looked up. /// </param> /// <param name="basesBeingResolved"> /// The set of bases being resolved. /// </param> /// <param name="options"> /// The lookup options in effect. /// </param> /// <param name="originalBinder"> /// The top-level binder. /// </param> /// <param name="diagnose"> /// Whether or not we are diagnosing. /// </param> /// <param name="useSiteDiagnostics"> /// Diagnostics set at the use-site. /// </param> internal void LookupSymbolsInWitness( TypeParameterSymbol witness, LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, Binder originalBinder, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Debug.Assert(witness.IsConceptWitness); // Concepts are just interfaces, so we look at every possible // interface this witness has been constrained to implement. foreach (var iface in witness.AllEffectiveInterfacesNoUseSiteDiagnostics) { if (!iface.IsConcept) { continue; } // We're assuming that the above handles inheritance for us. // This may be a mistake. var members = GetCandidateMembers(iface, name, options, originalBinder); foreach (var member in members) { // Don't bother trying to resolve non-methods: // concepts can't have them, and we only have shims for // dealing with methods later on anyway. if (member.Kind != SymbolKind.Method) { continue; } var method = member as MethodSymbol; Debug.Assert(method != null); // Suppose our witness is W : C<A>, and this finds C<A>.M(x). // We need to return that we found W.M(x), but W is a type // parameter! While we can handle this later on in binding, // the main issue is changing C<A> to W, for which we use // a synthesized method symbol. var witnessMethod = new SynthesizedWitnessMethodSymbol(method, witness); SingleLookupResult resultOfThisMember = originalBinder.CheckViability(witnessMethod, arity, options, witness, diagnose, ref useSiteDiagnostics, basesBeingResolved); result.MergeEqual(resultOfThisMember); } } }
internal void LookupSymbolInUsings( ImmutableArray<NamespaceOrTypeAndUsingDirective> usings, Binder originalBinder, LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics) { bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in usings) { ImmutableArray<Symbol> candidates = Binder.GetCandidateMembers(typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder); foreach (Symbol symbol in candidates) { // lookup via "using namespace" ignores namespaces inside if (symbol.Kind != SymbolKind.Namespace) { // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability(symbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(typeOrNamespace.UsingDirective, callerIsSemanticModel); } result.MergeEqual(res); } } } }
internal static void LookupSymbolInUsings( ImmutableArray <NamespaceOrTypeAndUsingDirective> usings, Binder originalBinder, LookupResult result, string name, int arity, ConsList <Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in usings) { ImmutableArray <Symbol> candidates = Binder.GetCandidateMembers(typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder); foreach (Symbol symbol in candidates) { switch (symbol.Kind) { // lookup via "using namespace" ignores namespaces inside case SymbolKind.Namespace: continue; // lookup via "using static" ignores extension methods and non-static methods case SymbolKind.Method: if (!symbol.IsStatic || ((MethodSymbol)symbol).IsExtensionMethod) { continue; } break; // types are considered static members for purposes of "using static" feature // regardless of whether they are declared with "static" modifier or not case SymbolKind.NamedType: break; // lookup via "using static" ignores non-static members default: if (!symbol.IsStatic) { continue; } break; } // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability(symbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(originalBinder.Compilation, typeOrNamespace.UsingDirective, callerIsSemanticModel); } result.MergeEqual(res); } } }
internal void LookupSymbolInUsings( ImmutableArray<NamespaceOrTypeAndUsingDirective> usings, Binder originalBinder, LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics) { bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; foreach (var typeOrNamespace in usings) { ImmutableArray<Symbol> candidates = Binder.GetCandidateMembers(typeOrNamespace.NamespaceOrType, name, options, originalBinder: originalBinder); foreach (Symbol symbol in candidates) { switch (symbol.Kind) { // lookup via "using namespace" ignores namespaces inside case SymbolKind.Namespace: continue; // lookup via "using static" ignores extension methods and non-static methods case SymbolKind.Method: if (!symbol.IsStatic || ((MethodSymbol)symbol).IsExtensionMethod) { continue; } break; // types are considered static members for purposes of "using static" feature // regardless of whether they are declared with "static" modifier or not case SymbolKind.NamedType: break; // lookup via "using static" ignores non-static members default: if (!symbol.IsStatic) { continue; } break; } // Found a match in our list of normal using directives. Mark the directive // as being seen so that it won't be reported to the user as something that // can be removed. var res = originalBinder.CheckViability(symbol, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(typeOrNamespace.UsingDirective, callerIsSemanticModel); } result.MergeEqual(res); } } }
internal void LookupSymbolInAliases( Binder originalBinder, LookupResult result, string name, int arity, ConsList<Symbol> basesBeingResolved, LookupOptions options, bool diagnose, ref HashSet<DiagnosticInfo> useSiteDiagnostics) { bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder; AliasAndUsingDirective alias; if (this.UsingAliases != null && 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 useSiteDiagnostics, 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 useSiteDiagnostics, basesBeingResolved); if (res.Kind == LookupResultKind.Viable) { MarkImportDirective(a.ExternAliasDirective, callerIsSemanticModel); } result.MergeEqual(res); } } }
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); }