Expression ResolveMemberAccessOnNamespace(AliasNamespace nrr, string identifier, IList <IType> typeArguments, bool parameterizeResultType) { if (typeArguments.Count == 0) { INamespace childNamespace = nrr.Namespace.GetChildNamespace(identifier); if (childNamespace != null) { return(new AliasNamespace(childNamespace, Location)); } } ITypeDefinition def = nrr.Namespace.GetTypeDefinition(identifier, typeArguments.Count); if (def != null) { if (parameterizeResultType && typeArguments.Count > 0) { return(new TypeExpression(new ParameterizedTypeSpec(def, typeArguments), loc)); } else { return(new TypeExpression(def, loc)); } } return(ErrorResult); }
public override Expression Resolve(ResolveContext resolver) { AliasNamespace target = new AliasNamespace(alias, Location); AST.Expression targetRR = target.Resolve(resolver); if (targetRR.IsError) { return(targetRR); } IList <IType> typeArgs = typeArgumentsrefs.Resolve(resolver.CurrentTypeResolveContext); if (LookForAttribute) { var wa = ResolveMemberAccess(resolver, targetRR, name + "Attribute", typeArgs, lookupMode); if (wa == null || wa.IsError) { wa = ResolveMemberAccess(resolver, targetRR, name, typeArgs, lookupMode); if (wa == null || wa.IsError) { resolver.Report.Error(6, loc, "This name `{0}' does not exist in the current context", name); } } LookForAttribute = false; return(wa); } else { var wa = ResolveMemberAccess(resolver, targetRR, name, typeArgs, lookupMode); if (wa == null || wa.IsError) { resolver.Report.Error(6, loc, "This name `{0}' does not exist in the current context", name); } return(wa); } }
public AliasNamespace(string alias, AliasNamespace nameNs) : base(alias, nameNs.loc) { ns = nameNs.Namespace; _resolved = true; }
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) { AliasNamespace anr = other as AliasNamespace; return(anr != null && this.name == anr.name); }
/// <summary> /// Returns the namespace that is referenced; or null if no such namespace is found. /// </summary> public INamespace ResolveNamespace(ResolveContext resolver) { AliasNamespace nrr = Resolve(resolver) as AliasNamespace; return(nrr != null ? nrr.Namespace : null); }
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); }