public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { return(new TupleTypeReference( this.Elements.Select(e => e.Type.ToTypeReference(lookupMode, interningProvider)).ToImmutableArray(), this.Elements.Select(e => e.Name).ToImmutableArray() )); }
public MemberAccess(Expression expr, string identifier, Location loc, NameLookupMode lookupMode = NameLookupMode.Expression) : base(identifier, loc) { this.expr = expr; this.typeArgumentsrefs = EmptyList <ITypeReference> .Instance; this.lookupMode = lookupMode; }
public SimpleName(string name, TypeArguments args, Location l, NameLookupMode lookupMode = NameLookupMode.Expression) : base(name, args, l) { this.typeArgumentsrefs = args != null?args.ToTypeReferences(CompilerContext.InternProvider) : EmptyList <ITypeReference> .Instance.ToList(); this.lookupMode = lookupMode; }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type) { TypeOrNamespaceReference t; if (this.IsDoubleColon) { SimpleType st = this.Target as SimpleType; if (st != null) { t = new AliasNamespaceReference(st.Identifier); } else { t = null; } } else { t = this.Target.ToTypeReference(lookupMode) as TypeOrNamespaceReference; } if (t == null) { return(SpecialType.UnknownType); } var typeArguments = new List <ITypeReference>(); foreach (var ta in this.TypeArguments) { typeArguments.Add(ta.ToTypeReference(lookupMode)); } return(new MemberTypeOrNamespaceReference(t, this.MemberName, typeArguments, lookupMode)); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { if (interningProvider == null) { interningProvider = InterningProvider.Dummy; } ITypeReference t = this.BaseType.ToTypeReference(lookupMode, interningProvider); if (this.HasNullableSpecifier) { t = interningProvider.Intern(NullableType.Create(t)); } int pointerRank = this.PointerRank; for (int i = 0; i < pointerRank; i++) { t = interningProvider.Intern(new PointerTypeReference(t)); } foreach (var a in this.ArraySpecifiers.Reverse()) { t = interningProvider.Intern(new ArrayTypeReference(t, a.Dimensions)); } if (this.HasRefSpecifier) { t = interningProvider.Intern(new ByReferenceTypeReference(t)); } return(t); }
public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) { if (identifier == null) throw new ArgumentNullException("identifier"); this.identifier = identifier; this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance; this.lookupMode = lookupMode; }
public SimpleTypeOrNamespaceReference(string identifier, IList <ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) { if (identifier == null) { throw new ArgumentNullException("identifier"); } this.identifier = identifier; this.typeArguments = typeArguments ?? EmptyList <ITypeReference> .Instance; this.lookupMode = lookupMode; }
public MemberTypeOrNamespaceReference(TypeOrNamespaceReference target, string identifier, IList<ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) { if (target == null) throw new ArgumentNullException("target"); if (identifier == null) throw new ArgumentNullException("identifier"); this.target = target; this.identifier = identifier; this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance; this.lookupMode = lookupMode; }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { KnownTypeCode typeCode = GetTypeCodeForPrimitiveType(this.Keyword); if (typeCode == KnownTypeCode.None) { return(new UnknownType(null, this.Keyword)); } else { return(KnownTypeReference.Get(typeCode)); } }
public MemberTypeOrNamespaceReference(TypeOrNamespaceReference target, string identifier, IList <ITypeReference> typeArguments, NameLookupMode lookupMode = NameLookupMode.Type) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } this.target = target; this.identifier = identifier; this.typeArguments = typeArguments ?? EmptyList <ITypeReference> .Instance; this.lookupMode = lookupMode; }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type) { var typeArguments = new List <ITypeReference>(); foreach (var ta in this.TypeArguments) { typeArguments.Add(ta.ToTypeReference(lookupMode)); } if (typeArguments.Count == 0 && string.IsNullOrEmpty(this.Identifier)) { // empty SimpleType is used for typeof(List<>). return(SpecialType.UnboundTypeArgument); } return(new SimpleTypeOrNamespaceReference(this.Identifier, typeArguments, lookupMode)); }
void HandleMemberReference(AstNode wholeNode, AstNode targetNode, Identifier memberName, IEnumerable<AstType> typeArguments, NameLookupMode mode, Action<Script> action) { var result = ctx.Resolve(targetNode); if (!(result is NamespaceResolveResult)) { return; } var wholeResult = ctx.Resolve(wholeNode); if (!(wholeResult is TypeResolveResult)) { return; } var state = ctx.GetResolverStateBefore(wholeNode); var resolvedTypeArguments = typeArguments.Select(ctx.ResolveType).ToList(); var lookupName = state.LookupSimpleNameOrTypeName(memberName.Name, resolvedTypeArguments, mode); if (lookupName is TypeResolveResult && !lookupName.IsError && wholeResult.Type.Equals(lookupName.Type)) { AddIssue(wholeNode.StartLocation, memberName.StartLocation, ctx.TranslateString("Remove redundant namespace usage"), action); } }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type) { ITypeReference t = this.BaseType.ToTypeReference(lookupMode); if (this.HasNullableSpecifier) { t = NullableType.Create(t); } int pointerRank = this.PointerRank; for (int i = 0; i < pointerRank; i++) { t = new PointerTypeReference(t); } foreach (var a in this.ArraySpecifiers.Reverse()) { t = new ArrayTypeReference(t, a.Dimensions); } return(t); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { if (interningProvider == null) { interningProvider = InterningProvider.Dummy; } TypeOrNamespaceReference t; if (this.IsDoubleColon) { SimpleType st = this.Target as SimpleType; if (st != null) { t = interningProvider.Intern(new AliasNamespaceReference(interningProvider.Intern(st.Identifier))); } else { t = null; } } else { t = this.Target.ToTypeReference(lookupMode, interningProvider) as TypeOrNamespaceReference; } if (t == null) { return(SpecialType.UnknownType); } var typeArguments = new List <ITypeReference>(); foreach (var ta in this.TypeArguments) { typeArguments.Add(ta.ToTypeReference(lookupMode, interningProvider)); } string memberName = interningProvider.Intern(this.MemberName); return(interningProvider.Intern(new MemberTypeOrNamespaceReference(t, memberName, interningProvider.InternList(typeArguments), lookupMode))); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { if (interningProvider == null) { interningProvider = InterningProvider.Dummy; } var typeArguments = new List <ITypeReference>(); foreach (var ta in this.TypeArguments) { typeArguments.Add(ta.ToTypeReference(lookupMode, interningProvider)); } string identifier = interningProvider.Intern(this.Identifier); if (typeArguments.Count == 0 && string.IsNullOrEmpty(identifier)) { // empty SimpleType is used for typeof(List<>). return(SpecialType.UnboundTypeArgument); } var t = new SimpleTypeOrNamespaceReference(identifier, interningProvider.InternList(typeArguments), lookupMode); return(interningProvider.Intern(t)); }
public Expression LookupSimpleNameOrTypeName(ResolveContext rc, string identifier, IList <IType> typeArguments, NameLookupMode lookupMode) { // V# 4.0 spec: �8 Namespace and type names; �6.2 Simple Names if (identifier == null) { throw new ArgumentNullException("identifier"); } if (typeArguments == null) { throw new ArgumentNullException("typeArguments"); } int k = typeArguments.Count; if (k == 0) { if (lookupMode == NameLookupMode.Expression || lookupMode == NameLookupMode.InvocationTarget) { // Look in local variables foreach (IVariable v in rc.LocalVariables) { if (v.Name == identifier) { return(new LocalVariableExpression(v, Location)); } } // Look in parameters of current method IParameterizedMember parameterizedMember = rc.CurrentMember as IParameterizedMember; if (parameterizedMember != null) { foreach (IParameter p in parameterizedMember.Parameters) { if (p.Name == identifier) { return(new LocalVariableExpression(p, Location)); } } } } // look in type parameters of current method IMethod m = rc.CurrentMember as IMethod; if (m != null) { foreach (ITypeParameter tp in m.TypeParameters) { if (tp.Name == identifier) { return(new TypeExpression(tp, Location)); } } } } bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument)); Expression r = null; if (rc.currentTypeDefinitionCache != null) { Dictionary <string, Expression> cache = null; bool foundInCache = false; if (k == 0) { switch (lookupMode) { case NameLookupMode.Expression: cache = rc.currentTypeDefinitionCache.SimpleNameLookupCacheExpression; break; case NameLookupMode.InvocationTarget: cache = rc.currentTypeDefinitionCache.SimpleNameLookupCacheInvocationTarget; break; case NameLookupMode.Type: cache = rc.currentTypeDefinitionCache.SimpleTypeLookupCache; break; } if (cache != null) { lock (cache) foundInCache = cache.TryGetValue(identifier, out r); } } if (foundInCache) { r = (r != null ? r.ShallowClone() : null); } else { r = LookInCurrentType(rc, identifier, typeArguments, lookupMode, parameterizeResultType); if (cache != null) { // also cache missing members (r==null) lock (cache) cache[identifier] = r; } } if (r != null) { return(r); } } if (rc.context.CurrentUsingScope == null) { // If no using scope was specified, we still need to look in the global namespace: r = LookInUsingScopeNamespace(rc, null, rc.compilation.RootNamespace, identifier, typeArguments, parameterizeResultType); } else { if (k == 0 && lookupMode != NameLookupMode.TypeInUsingDeclaration) { if (rc.context.CurrentUsingScope.ResolveCache.TryGetValue(identifier, out r)) { r = (r != null ? r.ShallowClone() : null); } else { r = LookInCurrentUsingScope(rc, identifier, typeArguments, false, false); rc.context.CurrentUsingScope.ResolveCache.TryAdd(identifier, r); } } else { r = LookInCurrentUsingScope(rc, identifier, typeArguments, lookupMode == NameLookupMode.TypeInUsingDeclaration, parameterizeResultType); } } if (r != null) { return(r); } if (typeArguments.Count == 0 && identifier == "dynamic") { return(new TypeExpression(SpecialTypeSpec.Dynamic as IType, Location)); } else { return(ErrorResult); } }
public SimpleName(string name, int arity, Location l, NameLookupMode lookupMode = NameLookupMode.Expression) : base(name, arity, l) { this.typeArgumentsrefs = EmptyList <ITypeReference> .Instance; this.lookupMode = lookupMode; }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) { throw new NotImplementedException(); }
public Expression ResolveAsBaseTypeReference(ResolveContext rc) { this.lookupMode = NameLookupMode.BaseTypeReference; return DoResolve(rc); }
public Expression ResolveAsTypeInUsingDeclaration(ResolveContext rc) { this.lookupMode = NameLookupMode.TypeInUsingDeclaration; return DoResolve(rc); }
public Expression ResolveMemberAccess(ResolveContext rc, VSC.AST.Expression target, string identifier, IList <IType> typeArguments, NameLookupMode lookupMode = NameLookupMode.Expression) { // V# 4.0 spec: §7.6.4 bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument)); AliasNamespace nrr = target as AliasNamespace; if (nrr != null) { return(ResolveMemberAccessOnNamespace(nrr, identifier, typeArguments, parameterizeResultType)); } // TODO:Dynamic Resolution //if (target.Type.Kind == TypeKind.Dynamic) // return new DynamicMemberResolveResult(target, identifier); MemberLookup lookup = rc.CreateMemberLookup(lookupMode); Expression result; switch (lookupMode) { case NameLookupMode.Expression: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: false); break; case NameLookupMode.InvocationTarget: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: true); break; case NameLookupMode.Type: case NameLookupMode.TypeInUsingDeclaration: case NameLookupMode.BaseTypeReference: // Don't do the UnknownMemberResolveResult/MethodGroupResolveResult processing, // it's only relevant for expressions. return(lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType)); default: throw new NotSupportedException("Invalid value for NameLookupMode"); } if (result is UnknownMemberExpression) { // We intentionally use all extension methods here, not just the eligible ones. // Proper eligibility checking is only possible for the full invocation // (after we know the remaining arguments). // The eligibility check in GetExtensionMethods is only intended for code completion. var extensionMethods = rc.GetExtensionMethods(identifier, typeArguments); if (extensionMethods.Count > 0) { return(new MethodGroupExpression(target, identifier, EmptyList <MethodListWithDeclaringType> .Instance, typeArguments) { extensionMethods = extensionMethods }); } } else { MethodGroupExpression mgrr = result as MethodGroupExpression; if (mgrr != null) { Debug.Assert(mgrr.extensionMethods == null); // set the values that are necessary to make MethodGroupResolveResult.GetExtensionMethods() work mgrr.resolver = rc; } } return(result); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) { return(SpecialType.UnknownType); }
public MemberAccess(Expression expr, string identifier, TypeArguments args, Location loc, NameLookupMode lookupMode = NameLookupMode.Expression) : base(identifier, args, loc) { this.expr = expr; this.typeArgumentsrefs = targs != null?targs.ToTypeReferences(CompilerContext.InternProvider) : EmptyList <ITypeReference> .Instance.ToList(); this.lookupMode = lookupMode; }
/// <summary> /// Creates a MemberLookup instance using this resolver's settings. /// </summary> public MemberLookup CreateMemberLookup(NameLookupMode lookupMode) { if (lookupMode == NameLookupMode.BaseTypeReference && this.CurrentTypeDefinition != null) { // When looking up a base type reference, treat us as being outside the current type definition // for accessibility purposes. // This avoids a stack overflow when referencing a protected class nested inside the base class // of a parent class. (NameLookupTests.InnerClassInheritingFromProtectedBaseInnerClassShouldNotCauseStackOverflow) return new MemberLookup(this.CurrentTypeDefinition.DeclaringTypeDefinition, this.Compilation.MainAssembly, false); } else { return CreateMemberLookup(); } }
public ResolveResult ResolveMemberAccess(ResolveResult target, string identifier, IList<IType> typeArguments, NameLookupMode lookupMode = NameLookupMode.Expression) { // C# 4.0 spec: §7.6.4 bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument)); NamespaceResolveResult nrr = target as NamespaceResolveResult; if (nrr != null) { return ResolveMemberAccessOnNamespace(nrr, identifier, typeArguments, parameterizeResultType); } if (target.Type.Kind == TypeKind.Dynamic) return DynamicResult; MemberLookup lookup = CreateMemberLookup(lookupMode); ResolveResult result; switch (lookupMode) { case NameLookupMode.Expression: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: false); break; case NameLookupMode.InvocationTarget: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: true); break; case NameLookupMode.Type: case NameLookupMode.TypeInUsingDeclaration: case NameLookupMode.BaseTypeReference: result = lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType); break; default: throw new NotSupportedException("Invalid value for NameLookupMode"); } if (result is UnknownMemberResolveResult) { var extensionMethods = GetExtensionMethods(identifier, typeArguments); if (extensionMethods.Count > 0) { return new MethodGroupResolveResult(target, identifier, EmptyList<MethodListWithDeclaringType>.Instance, typeArguments) { extensionMethods = extensionMethods }; } } else { MethodGroupResolveResult mgrr = result as MethodGroupResolveResult; if (mgrr != null) { Debug.Assert(mgrr.extensionMethods == null); // set the values that are necessary to make MethodGroupResolveResult.GetExtensionMethods() work mgrr.resolver = this; } } return result; }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) { throw new NotSupportedException(); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode) { return(SpecialType.UnknownType); }
public override ITypeReference ToTypeReference(NameLookupMode lookupMode) { throw new NotSupportedException(); }
Expression LookInCurrentType(ResolveContext rc, string identifier, IList <IType> typeArguments, NameLookupMode lookupMode, bool parameterizeResultType) { int k = typeArguments.Count; MemberLookup lookup = rc.CreateMemberLookup(lookupMode); // look in current type definitions for (ITypeDefinition t = rc.CurrentTypeDefinition; t != null; t = t.DeclaringTypeDefinition) { if (k == 0) { // Look for type parameter with that name var typeParameters = t.TypeParameters; // Look at all type parameters, including those copied from outer classes, // so that we can fetch the version with the correct owner. for (int i = 0; i < typeParameters.Count; i++) { if (typeParameters[i].Name == identifier) { return(new TypeExpression(typeParameters[i], Location)); } } } if (lookupMode == NameLookupMode.BaseTypeReference && t == rc.CurrentTypeDefinition) { // don't look in current type when resolving a base type reference continue; } Expression r; if (lookupMode == NameLookupMode.Expression || lookupMode == NameLookupMode.InvocationTarget) { Expression targetResolveResult = (t == rc.CurrentTypeDefinition ? (Expression) new SelfReference(t, Location) : new TypeExpression(t, Location)); r = lookup.Lookup(targetResolveResult, identifier, typeArguments, lookupMode == NameLookupMode.InvocationTarget); } else { r = lookup.LookupType(t, identifier, typeArguments, parameterizeResultType); } if (!(r is UnknownMemberExpression)) // but do return AmbiguousMemberResolveResult { return(r); } } return(null); }
void HandleMemberReference(AstNode wholeNode, AstNode targetNode, Identifier memberName, IEnumerable <AstType> typeArguments, NameLookupMode mode, Action <Script> action) { var result = ctx.Resolve(targetNode); if (!(result is NamespaceResolveResult)) { return; } var wholeResult = ctx.Resolve(wholeNode); if (!(wholeResult is TypeResolveResult)) { return; } var state = ctx.GetResolverStateBefore(wholeNode); var resolvedTypeArguments = typeArguments.Select(ctx.ResolveType).ToList(); var lookupName = state.LookupSimpleNameOrTypeName(memberName.Name, resolvedTypeArguments, mode); if (lookupName is TypeResolveResult && !lookupName.IsError && wholeResult.Type.Equals(lookupName.Type)) { AddIssue(wholeNode.StartLocation, memberName.StartLocation, ctx.TranslateString("Remove redundant namespace usage"), action); } }
public IType ResolveAsType(ResolveContext rc) { this.lookupMode = NameLookupMode.Type; return (this as ITypeReference).Resolve(rc); }
public Expression ResolveAsInvocationTarget(ResolveContext rc) { this.lookupMode = NameLookupMode.InvocationTarget; return DoResolve(rc); }
public ResolveResult ResolveMemberAccess(ResolveResult target, string identifier, IList<IType> typeArguments, NameLookupMode lookupMode = NameLookupMode.Expression) { // C# 4.0 spec: §7.6.4 bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument)); NamespaceResolveResult nrr = target as NamespaceResolveResult; if (nrr != null) { return ResolveMemberAccessOnNamespace(nrr, identifier, typeArguments, parameterizeResultType); } if (target.Type.Kind == TypeKind.Dynamic) return new DynamicMemberResolveResult(target, identifier); MemberLookup lookup = CreateMemberLookup(lookupMode); ResolveResult result; switch (lookupMode) { case NameLookupMode.Expression: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: false); break; case NameLookupMode.InvocationTarget: result = lookup.Lookup(target, identifier, typeArguments, isInvocation: true); break; case NameLookupMode.Type: case NameLookupMode.TypeInUsingDeclaration: case NameLookupMode.BaseTypeReference: // Don't do the UnknownMemberResolveResult/MethodGroupResolveResult processing, // it's only relevant for expressions. return lookup.LookupType(target.Type, identifier, typeArguments, parameterizeResultType); default: throw new NotSupportedException("Invalid value for NameLookupMode"); } if (result is UnknownMemberResolveResult) { // We intentionally use all extension methods here, not just the eligible ones. // Proper eligibility checking is only possible for the full invocation // (after we know the remaining arguments). // The eligibility check in GetExtensionMethods is only intended for code completion. var extensionMethods = GetExtensionMethods(identifier, typeArguments); if (extensionMethods.Count > 0) { return new MethodGroupResolveResult(target, identifier, EmptyList<MethodListWithDeclaringType>.Instance, typeArguments) { extensionMethods = extensionMethods }; } } else { MethodGroupResolveResult mgrr = result as MethodGroupResolveResult; if (mgrr != null) { Debug.Assert(mgrr.extensionMethods == null); // set the values that are necessary to make MethodGroupResolveResult.GetExtensionMethods() work mgrr.resolver = this; } } return result; }
/// <summary> /// Create an ITypeReference for this AstType. /// </summary> /// <remarks> /// The resulting type reference will read the context information from the /// <see cref="ITypeResolveContext"/>: /// For resolving type parameters, the CurrentTypeDefinition/CurrentMember is used. /// For resolving simple names, the current namespace and usings from the CurrentUsingScope /// (on CSharpTypeResolveContext only) is used. /// </remarks> public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null);
/// <summary> /// Create an ITypeReference for this AstType. /// </summary> /// <remarks> /// The resulting type reference will read the context information from the /// <see cref="ITypeResolveContext"/>: /// For resolving type parameters, the CurrentTypeDefinition/CurrentMember is used. /// For resolving simple names, the current namespace and usings from the CurrentUsingScope /// (on CSharpTypeResolveContext only) is used. /// </remarks> public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode = NameLookupMode.Type);
public ResolveResult LookupSimpleNameOrTypeName(string identifier, IList<IType> typeArguments, NameLookupMode lookupMode) { // C# 4.0 spec: §3.8 Namespace and type names; §7.6.2 Simple Names if (identifier == null) throw new ArgumentNullException("identifier"); if (typeArguments == null) throw new ArgumentNullException("typeArguments"); int k = typeArguments.Count; if (k == 0) { if (lookupMode == NameLookupMode.Expression || lookupMode == NameLookupMode.InvocationTarget) { // Look in local variables foreach (IVariable v in this.LocalVariables) { if (v.Name == identifier) { return new LocalResolveResult(v); } } // Look in parameters of current method IParameterizedMember parameterizedMember = this.CurrentMember as IParameterizedMember; if (parameterizedMember != null) { foreach (IParameter p in parameterizedMember.Parameters) { if (p.Name == identifier) { return new LocalResolveResult(p); } } } } // look in type parameters of current method IMethod m = this.CurrentMember as IMethod; if (m != null) { foreach (ITypeParameter tp in m.TypeParameters) { if (tp.Name == identifier) return new TypeResolveResult(tp); } } } bool parameterizeResultType = !(typeArguments.Count != 0 && typeArguments.All(t => t.Kind == TypeKind.UnboundTypeArgument)); ResolveResult r = null; if (currentTypeDefinitionCache != null) { Dictionary<string, ResolveResult> cache = null; bool foundInCache = false; if (k == 0) { switch (lookupMode) { case NameLookupMode.Expression: cache = currentTypeDefinitionCache.SimpleNameLookupCacheExpression; break; case NameLookupMode.InvocationTarget: cache = currentTypeDefinitionCache.SimpleNameLookupCacheInvocationTarget; break; case NameLookupMode.Type: cache = currentTypeDefinitionCache.SimpleTypeLookupCache; break; } if (cache != null) { lock (cache) foundInCache = cache.TryGetValue(identifier, out r); } } if (!foundInCache) { r = LookInCurrentType(identifier, typeArguments, lookupMode, parameterizeResultType); if (cache != null) { // also cache missing members (r==null) lock (cache) cache[identifier] = r; } } if (r != null) return r; } if (context.CurrentUsingScope == null) { // If no using scope was specified, we still need to look in the global namespace: r = LookInUsingScopeNamespace(null, compilation.RootNamespace, identifier, typeArguments, parameterizeResultType); } else { if (k == 0 && lookupMode != NameLookupMode.TypeInUsingDeclaration) { if (!context.CurrentUsingScope.ResolveCache.TryGetValue(identifier, out r)) { r = LookInCurrentUsingScope(identifier, typeArguments, false, false); r = context.CurrentUsingScope.ResolveCache.GetOrAdd(identifier, r); } } else { r = LookInCurrentUsingScope(identifier, typeArguments, lookupMode == NameLookupMode.TypeInUsingDeclaration, parameterizeResultType); } } if (r != null) return r; if (typeArguments.Count == 0 && identifier == "dynamic") { return new TypeResolveResult(SpecialType.Dynamic); } else { return new UnknownIdentifierResolveResult(identifier, typeArguments.Count); } }
ResolveResult LookInCurrentType(string identifier, IList<IType> typeArguments, NameLookupMode lookupMode, bool parameterizeResultType) { int k = typeArguments.Count; MemberLookup lookup = CreateMemberLookup(lookupMode); // look in current type definitions for (ITypeDefinition t = this.CurrentTypeDefinition; t != null; t = t.DeclaringTypeDefinition) { if (k == 0) { // Look for type parameter with that name var typeParameters = t.TypeParameters; // Look at all type parameters, including those copied from outer classes, // so that we can fetch the version with the correct owner. for (int i = 0; i < typeParameters.Count; i++) { if (typeParameters[i].Name == identifier) return new TypeResolveResult(typeParameters[i]); } } if (lookupMode == NameLookupMode.BaseTypeReference && t == this.CurrentTypeDefinition) { // don't look in current type when resolving a base type reference continue; } ResolveResult r; if (lookupMode == NameLookupMode.Expression || lookupMode == NameLookupMode.InvocationTarget) { var targetResolveResult = (t == this.CurrentTypeDefinition ? ResolveThisReference() : new TypeResolveResult(t)); r = lookup.Lookup(targetResolveResult, identifier, typeArguments, lookupMode == NameLookupMode.InvocationTarget); } else { r = lookup.LookupType(t, identifier, typeArguments, parameterizeResultType); } if (!(r is UnknownMemberResolveResult)) // but do return AmbiguousMemberResolveResult return r; } return null; }
public QualifiedAlias(string alias, string identifier, int arity, Location l, NameLookupMode lookupMode = NameLookupMode.Expression) : base(null, identifier, arity, l, lookupMode) { this.alias = alias; }