📄 memberaccessexpression.vb
字号:
End If End If If result = False Then Return result '* If E is a type parameter, then a compile-time error results. If m_First.Classification.IsTypeClassification AndAlso m_First.Classification.AsTypeClassification.IsTypeParameter Then result = Compiler.Report.ShowMessage(Messages.VBNC32098, Me.Location) AndAlso result If result = False Then Return result End If '* If E is the keyword Global, and I is the name of an accessible type in the global namespace, ' then the result is that type. If TypeOf m_First Is GlobalExpression Then Dim foundType As Type foundType = Compiler.TypeManager.GetTypesByNamespace("").Item(Name) If foundType IsNot Nothing Then Classification = New TypeClassification(Me, foundType) Return True ElseIf Compiler.TypeManager.Namespaces.ContainsKey(Name) Then Classification = New NamespaceClassification(Me, Compiler.TypeManager.Namespaces(Name)) Return True Else Return Compiler.Report.ShowMessage(Messages.VBNC30456, Location, Name, "<Default>") AndAlso result End If End If '* If E is classified as a namespace and I is the name of an accessible member of that namespace, ' then the result is that member. The result is classified as a namespace or a type depending on the member. If m_First.Classification.IsNamespaceClassification Then Dim nstypes As Generic.List(Of Type) = Nothing Dim ns As [Namespace] = m_First.Classification.AsNamespaceClassification.Namespace Dim nsname As String = ns.Name Dim foundns As [Namespace] Dim foundType As Type foundns = Compiler.TypeManager.Namespaces.Item(ns, Name) foundType = Compiler.TypeManager.TypesByNamespace(nsname).Item(Name) If foundns IsNot Nothing AndAlso foundType Is Nothing Then Classification = New NamespaceClassification(Me, foundns) Return True ElseIf foundns Is Nothing AndAlso foundType IsNot Nothing Then Classification = New TypeClassification(Me, foundType) Return True ElseIf foundns IsNot Nothing AndAlso nstypes IsNot Nothing Then Helper.AddError("Found a namespace and a type with the same name.") End If 'TODO: The spec is missing info about modules in namespaces. Doing check anyway. Dim modules As TypeDictionary = Compiler.TypeManager.GetModulesByNamespace(ns.ToString) Dim members As Generic.List(Of MemberInfo) = Helper.GetMembersOfTypes(Compiler, modules, Name) If members.Count > 0 Then Dim first As Object = members(0) If Helper.IsMethodDeclaration(first) Then Classification = New MethodGroupClassification(Me, Nothing, Nothing, members) Return True ElseIf Helper.IsTypeDeclaration(first) Then If members.Count = 1 Then Classification = New TypeClassification(Me, first) Return True Else Helper.AddError() End If ElseIf Helper.IsFieldDeclaration(first) Then If members.Count = 1 Then Classification = New VariableClassification(Me, DirectCast(first, FieldInfo), Nothing) Return True Else Helper.AddError() End If ElseIf Helper.IsPropertyDeclaration(first) Then Classification = New PropertyGroupClassification(Me, Nothing, members) Return True Else Helper.Stop() End If End If End If '* If E is a built-in type or an expression classified as a type, and I is the name of an accessible ' member of E, then E.I is evaluated and classified as follows: '** If I is the keyword New, then a compile-time error occurs. '** If I identifies a type, then the result is that type. '** If I identifies one or more methods, then the result is a method group with the associated ' type argument list and no associated instance expression. '** If I identifies one or more properties, then the result is a property group with no associated ' instance expression. '** If I identifies a shared variable, and if the variable is read-only, and the reference occurs ' outside the shared constructor of the type in which the variable is declared, then the result is the ' value of the shared variable I in E. Otherwise, the result is the shared variable I in E. '** If I identifies a shared event, the result is an event access with no associated instance expression. '** If I identifies a constant, then the result is the value of that constant. '** If I identifies an enumeration member, then the result is the value of that enumeration member. '** Otherwise, E.I is an invalid member reference, and a compile-time error occurs. If m_First.Classification.IsTypeClassification Then If m_Second.IsKeyword AndAlso m_Second.Token.Equals(KS.[New]) Then '** If I is the keyword New, then a compile-time error occurs. Helper.AddError() End If Dim members As Generic.List(Of MemberInfo) 'members = Helper.FilterByName(Helper.GetMembers(Compiler, m_First.Classification.AsTypeClassification.Type), Name) 'members = Helper.FilterByName(Compiler.TypeManager.GetCache(m_First.Classification.AsTypeClassification.Type).FlattenedCache.GetAllMembers.ToArray, Name) members = Compiler.TypeManager.GetCache(m_First.Classification.AsTypeClassification.Type).LookupFlattened(Name).Members Dim withTypeArgs As IdentifierOrKeywordWithTypeArguments withTypeArgs = TryCast(m_Second, IdentifierOrKeywordWithTypeArguments) If withTypeArgs IsNot Nothing Then members = Helper.FilterByTypeArguments(members, withTypeArgs.TypeArguments) End If members = Helper.FilterExternalInaccessible(Me.Compiler, members) Helper.StopIfDebugging(members.Count = 0) If members.Count > 0 Then Dim first As Object = members(0) '** If I identifies one or more methods, then the result is a method group with the associated ' type argument list and no associated instance expression. If Helper.IsMethodDeclaration(first) Then Classification = New MethodGroupClassification(Me, Nothing, Nothing, members) Return True End If '** If I identifies one or more properties, then the result is a property group with no associated ' instance expression. If Helper.IsPropertyDeclaration(first) Then Classification = New PropertyGroupClassification(Me, Nothing, members) Return True End If If members.Count > 1 Then Helper.Stop() '** If I identifies a type, then the result is that type. If Helper.IsTypeDeclaration(first) Then Classification = New TypeClassification(Me, first) Return True End If '** If I identifies a shared variable, and if the variable is read-only, and the reference occurs ' outside the shared constructor of the type in which the variable is declared, then the result is the ' value of the shared variable I in E. Otherwise, the result is the shared variable I in E. If Helper.IsFieldDeclaration(first) Then Dim fld As FieldInfo = TryCast(first, FieldInfo) If fld Is Nothing Then Dim var As VariableDeclaration = TryCast(first, VariableDeclaration) Helper.Assert(var IsNot Nothing) fld = var.FieldBuilder End If Dim constructor As ConstructorDeclaration = Me.FindFirstParent(Of ConstructorDeclaration)() If fld.IsStatic AndAlso CBool(fld.Attributes And FieldAttributes.InitOnly) AndAlso (constructor Is Nothing OrElse constructor.Modifiers.Is(ModifierMasks.Shared) = False) Then Classification = New ValueClassification(Me, fld, Nothing) Return True Else Classification = New VariableClassification(Me, fld, Nothing) Return True End If End If '** If I identifies a shared event, the result is an event access with no associated instance expression. If Helper.IsEventDeclaration(first) Then Dim red As EventDeclaration = TryCast(first, EventDeclaration) Dim red2 As EventInfo = TryCast(first, EventInfo) If red IsNot Nothing AndAlso red.Modifiers.Is(ModifierMasks.Shared) Then Classification = New EventAccessClassification(Me, red.EventDescriptor, Nothing) Return True ElseIf red2 IsNot Nothing AndAlso red2.GetAddMethod(True).IsStatic Then Classification = New EventAccessClassification(Me, red2, Nothing) Return True End If End If '** If I identifies a constant, then the result is the value of that constant. Dim c As ConstantDeclaration = TryCast(first, ConstantDeclaration) If c IsNot Nothing Then Classification = New ValueClassification(Me, c) Return True End If '** If I identifies an enumeration member, then the result is the value of that enumeration member. Dim enummember As EnumMemberDeclaration = TryCast(first, EnumMemberDeclaration) If enummember IsNot Nothing Then Classification = New ValueClassification(Me, enummember) Return True End If '** Otherwise, E.I is an invalid member reference, and a compile-time error occurs. Helper.AddError("Could not resolve name '" & Name & "'" & ", " & Me.Location.ToString(Compiler)) Else Helper.AddError("Could not resolve name '" & Name & "'" & "," & Me.Location.ToString(Compiler)) End If End If '* If E is classified as a variable or value, the type of which is T, and I is the name of an accessible ' member of E, then E.I is evaluated and classified as follows: '** If I is the keyword New and E is an instance expression (Me, MyBase, or MyClass), then the result is ' a method group representing the instance constructors of the type of E with an associated ' instance expression of E and no type argument list. Otherwise, a compile-time error occurs. '** If I identifies one or more methods, then the result is a method group with the associated type ' argument list and an associated instance expression of E. '** If I identifies one or more properties, then the result is a property group with an ' associated instance expression of E. '** If I identifies a shared variable or an instance variable, and if the variable is read-only, ' and the reference occurs outside a constructor of the class in which the variable is declared ' appropriate for the kind of variable (shared or instance), then the result is the value of the ' variable I in the object referenced by E. If T is a reference type, then the result is the variable ' I in the object referenced by E. Otherwise, if T is a value type and the expression E is classified ' as a variable, the result is a variable; otherwise the result is a value. '** If I identifies an event, the result is an event access with an associated instance expression of E. '** If I identifies a constant, then the result is the value of that constant. '** If I identifies an enumeration member, then the result is the value of that enumeration member. '** If T is Object, then the result is a late-bound member lookup classified as a late-bound access ' with an associated instance expression of E. '** Otherwise, E.I is an invalid member reference, and a compile-time error occurs. If m_First.Classification.IsValueClassification OrElse m_First.Classification.IsVariableClassification OrElse m_First.Classification.CanBeValueClassification Then Dim T As Type 'Descriptor If m_First.Classification.IsValueClassification Then T = m_First.Classification.AsValueClassification.Type ElseIf m_First.Classification.IsVariableClassification Then T = m_First.Classification.AsVariableClassification.Type ElseIf m_First.Classification.CanBeValueClassification Then m_First = m_First.ReclassifyToValueExpression result = m_First.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result Helper.Assert(m_First.Classification IsNot Nothing) Helper.Assert(m_First.Classification.AsValueClassification IsNot Nothing) T = m_First.Classification.AsValueClassification.Type Else Throw New InternalException(Me) End If If T.IsByRef Then m_First = m_First.DereferenceByRef() T = m_First.ExpressionType End If '** If I is the keyword New and E is an instance expression (Me, MyBase, or MyClass), then the result is ' a method group representing the instance constructors of the type of E with an associated ' instance expression of E and no type argument list. Otherwise, a compile-time error occurs.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -