simplenameexpression.vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 907 行 · 第 1/4 页

VB
907
字号
            End If            'Otherwise, if the namespace contains one or more accessible standard modules, and a member name             'lookup of the identifier produces an accessible match in exactly one standard module, then the             'result is exactly the same as a member access of the form M.E, where M is the standard module             'containing the matching member and E is the identifier. If the identifier matches accessible type             'members in more than one standard module, a compile-time error occurs.            Dim modulemembers As Generic.List(Of MemberInfo)            modulemembers = Helper.GetMembersOfTypes(Compiler, Compiler.TypeManager.GetModulesByNamespace(currentNS), Name)            If modulemembers.Count = 1 Then                Return SetClassificationOfModuleMembers(modulemembers)            ElseIf modulemembers.Count > 1 Then                Helper.AddError()            End If            currentNS = Helper.GetNamespaceParent(currentNS)        End While        If CheckOutermostNamespace(Name) Then Return True        '* If the source file has one or more import aliases, and the identifier matches the name of one of them,        '   then the identifier refers to that namespace or type.        If ResolveAliasImports(Me.Location.File(Compiler).Imports, Name) Then Return True        '* If the source file containing the name reference has one or more imports:        '** If the identifier matches the name of an accessible type or type member in exactly one import,         '   then the identifier refers to that type or type member. If the identifier matches the name of         '   an accessible type or type member in more than one import, a compile-time error occurs.        '** If the identifier matches the name of a namespace in exactly one import, then the identifier         '   refers to that namespace. If the identifier matches the name of a namespace in more than one import,         '   a compile-time error occurs.        '** Otherwise, if the imports contain one or more accessible standard modules, and a member name         '   lookup of the identifier produces an accessible match in exactly one standard module, then         '   the result is exactly the same as a member access of the form M.E, where M is the standard         '   module containing the matching member and E is the identifier. If the identifier matches         '   accessible type members in more than one standard module, a compile-time error occurs.        If ResolveImports(Me.Location.File(Compiler).Imports, Name) Then Return True        '* If the compilation environment defines one or more import aliases, and the identifier matches         '  the name of one of them, then the identifier refers to that namespace or type.        If ResolveAliasImports(Me.Compiler.CommandLine.Imports.Clauses, Name) Then Return True        '* If the compilation environment defines one or more imports:        '** If the identifier matches the name of an accessible type or type member in exactly one import,         '   then the identifier refers to that type or type member. If the identifier matches the name         '   of an accessible type or type member in more than one import, a compile-time error occurs.        '** If the identifier matches the name of a namespace in exactly one import, then the identifier         '   refers to that namespace. If the identifier matches the name of a namespace in more than         '   one import, a compile-time error occurs.        '** Otherwise, if the imports contain one or more accessible standard modules, and a member name         '   lookup of the identifier produces an accessible match in exactly one standard module, then the result         '   is exactly the same as a member access of the form M.E, where M is the standard module containing         '   the matching member and E is the identifier. If the identifier matches accessible type members in         '   more than one standard module, a compile-time error occurs.        If ResolveImports(Me.Compiler.CommandLine.Imports.Clauses, Name) Then Return True        If Location.File(Compiler).IsOptionExplicitOn = False AndAlso Info.CanBeImplicitSimpleName Then            Dim parent_method As MethodBaseDeclaration            parent_method = Me.FindFirstParent(Of MethodBaseDeclaration)()            If method IsNot Nothing Then                Dim varD As VariableDeclaration                Dim varType As Type                If m_Identifier.HasTypeCharacter Then                    varType = TypeCharacters.TypeCharacterToType(Compiler, m_Identifier.TypeCharacter)                Else                    varType = Compiler.TypeCache.System_Object                End If                varD = New VariableDeclaration(parent_method.Code, Nothing, Nothing, m_Identifier, False, Nothing, Nothing, Nothing)                varD.Init(Nothing, Nothing, m_Identifier.Identifier, varType)                parent_method.Code.AddVariable(varD)                Me.Classification = New VariableClassification(Me, varD)                Return True            End If        End If        '* Otherwise, the name given by the identifier is undefined and a compile-time error occurs.        Compiler.Report.ShowMessage(Messages.VBNC30451, Me.Location, Name)        Return False    End Function    Private Function GetTypeClassification(ByVal members As Generic.List(Of MemberInfo), ByVal type As IType) As ExpressionClassification        'Otherwise, the result is exactly the same as a member access of the form T.E, where T is the         'type containing the matching member and E is the identifier. In this case, it is an error for the         'identifier to refer to a non-shared member.        Dim first As MemberInfo = members(0)        '* 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.        '(not applicable)        '** 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            Return New MethodGroupClassification(Me, Nothing, Nothing, members)        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            Return New PropertyGroupClassification(Me, Nothing, members)        End If        If members.Count > 1 Then Throw New InternalException(Me)        '** If I identifies a type, then the result is that type.        If Helper.IsTypeDeclaration(first) Then            Return New TypeClassification(Me, first)        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 var As FieldInfo = TryCast(first, FieldInfo)            Dim constructor As ConstructorDeclaration = Me.FindFirstParent(Of ConstructorDeclaration)()            If var.IsStatic AndAlso var.IsInitOnly AndAlso _             (constructor Is Nothing OrElse constructor.Modifiers.Is(ModifierMasks.Shared) = False) Then                Return New ValueClassification(Me, var, Nothing)            Else                Return New VariableClassification(Me, var, Nothing)            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 EventInfo = DirectCast(first, EventInfo)            If red.GetAddMethod.IsStatic OrElse red.GetRemoveMethod.IsStatic Then                Return New EventAccessClassification(Me, red, Nothing)            End If        End If        '** If I identifies a constant, then the result is the value of that constant.        If first.MemberType = MemberTypes.Field AndAlso DirectCast(first, FieldInfo).IsLiteral Then            Return New ValueClassification(Me, DirectCast(first, FieldInfo), Nothing)        End If        '** If I identifies an enumeration member, then the result is the value of that enumeration member.        If Helper.IsEnumFieldDeclaration(first) Then            Return New ValueClassification(Me, DirectCast(first, FieldInfo), Nothing)        End If        '** Otherwise, E.I is an invalid member reference, and a compile-time error occurs.        Helper.AddError()        Return Nothing    End Function    Private Function CreateMeExpression() As MeExpression        Dim result As New MeExpression(Me)        If result.ResolveExpression(ResolveInfo.Default(Parent.Compiler)) = False Then Throw New InternalException(Me)        Return result    End Function    Private Function GetMeClassification(ByVal members As Generic.List(Of MemberInfo), ByVal type As IType) As ExpressionClassification        Dim result As ExpressionClassification        Dim first As MemberInfo = members(0)        'Otherwise, if the type is the immediately enclosing type and the lookup identifies a non-shared         'type member, then the result is the same as a member access of the form Me.E, where E is         'the identifier.        '* 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.        '(not applicable)        '** 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 Helper.IsMethodDeclaration(first) Then            result = New MethodGroupClassification(Me, CreateMeExpression, Nothing, members)            Return result        End If        '** If I identifies one or more properties, then the result is a property group with an         '   associated instance expression of E.        If Helper.IsPropertyDeclaration(first) Then            result = New PropertyGroupClassification(Me, CreateMeExpression, members)            Return result        End If        If members.Count > 1 Then            Compiler.Report.WriteLine("Found " & members.Count & " members for SimpleNameExpression = " & Me.ToString & ", " & Me.Location.ToString(Compiler))            For i As Integer = 0 To members.Count - 1                Compiler.Report.WriteLine(">#" & (i + 1).ToString & ".MemberType=" & members(i).MemberType.ToString & ",DeclaringType=" & members(i).DeclaringType.FullName)            Next            Helper.Stop()        End If        '** 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 Helper.IsFieldDeclaration(first) Then            Dim var As FieldInfo = DirectCast(first, FieldInfo)            Helper.Assert(Parent.FindFirstParent(Of EnumDeclaration)() Is Nothing)            Dim ctorParent As ConstructorDeclaration            Dim methodParent As IMethod            Dim typeParent As TypeDeclaration            Dim isNotInCtorAndReadOnly As Boolean            ctorParent = FindFirstParent(Of ConstructorDeclaration)()            methodParent = FindFirstParent(Of IMethod)()            typeParent = FindFirstParent(Of TypeDeclaration)()            isNotInCtorAndReadOnly = var.IsInitOnly AndAlso (ctorParent Is Nothing OrElse ctorParent.Modifiers.Is(ModifierMasks.Shared) <> var.IsStatic) AndAlso (typeParent Is Nothing OrElse typeParent.IsShared <> var.IsStatic)            If isNotInCtorAndReadOnly Then ' >?? (Parent.FindFirstParent(Of IMethod).Modifiers.Is(KS.Shared) <> var.IsStatic) Then                Return New ValueClassification(Me, var, CreateMeExpression)            ElseIf TypeOf type Is ClassDeclaration Then                Return New VariableClassification(Me, var, CreateMeExpression)            ElseIf TypeOf type Is StructureDeclaration Then                Return New VariableClassification(Me, var, CreateMeExpression)            Else                Throw New InternalException(Me)            End If        End If

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?