simplenameexpression.vb

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

VB
907
字号
        '** If I identifies an event, the result is an event access with an associated instance expression of E.        If Helper.IsEventDeclaration(first) Then            If TypeOf first Is EventInfo Then                Return New EventAccessClassification(Me, DirectCast(first, EventInfo), CreateMeExpression)            Else                Throw New InternalException(Me)            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.        '(not applicable)        '** 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.        '(not applicable)        '** Otherwise, E.I is an invalid member reference, and a compile-time error occurs.        Helper.AddError()        Return Nothing    End Function    Private Function CheckOutermostNamespace(ByVal R As String) As Boolean        '---------------------------------------------------------------------------------------------------------        '* For each nested namespace, starting from the innermost and going to the outermost namespace,         '  do the following:        '** If the namespace contains an accessible namespace member with the given name, then the identifier        '   refers to that member and, depending on the member, is classified as a namespace or a type.        '** 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.        '**	If R matches the name of an accessible type or nested namespace in the current namespace, then the        '** unqualified name refers to that type or nested namespace.        '---------------------------------------------------------------------------------------------------------        Dim foundNamespace As [Namespace] = Nothing        Dim foundType As Type        foundType = Compiler.TypeManager.TypesByNamespace("").Item(R)        If foundType Is Nothing AndAlso Compiler.Assembly.Name <> "" Then            foundType = Compiler.TypeManager.TypesByNamespace(Compiler.Assembly.Name).Item(R)        End If        foundNamespace = Compiler.TypeManager.Namespaces(R)        If foundNamespace IsNot Nothing AndAlso foundType Is Nothing Then            Classification = New NamespaceClassification(Me, foundNamespace)            Return True        ElseIf foundNamespace Is Nothing AndAlso foundType IsNot Nothing Then            Classification = New TypeClassification(Me, foundType)            Return True        ElseIf foundNamespace IsNot Nothing AndAlso foundType IsNot Nothing Then            Helper.AddError()        End If        If foundNamespace Is Nothing Then Return False        Dim modules As TypeDictionary        Dim members As Generic.List(Of MemberInfo)        modules = Compiler.TypeManager.GetModulesByNamespace(foundNamespace.ToString)        members = Helper.GetMembersOfTypes(Compiler, modules, R)        If members.Count = 1 Then            Helper.Assert(Helper.IsTypeDeclaration(members(0)))            Classification = New TypeClassification(Me, members(0))        ElseIf members.Count > 1 Then            Helper.AddError()        End If        Return False    End Function    Private Function ResolveAliasImports(ByVal imps As ImportsClauses, ByVal Name As String) As Boolean        Dim import As ImportsClause = imps.Item(Name)        Dim nsimport As ImportsNamespaceClause        If import IsNot Nothing Then            nsimport = import.AsAliasClause.NamespaceClause            If nsimport.IsNamespaceImport Then                Classification = New NamespaceClassification(Me, nsimport.NamespaceImported)                Return True            ElseIf nsimport.IsTypeImport Then                Classification = New TypeClassification(Me, nsimport.TypeImported)                Return True            Else                Throw New InternalException(Me)            End If        End If        Return False    End Function    Private Function ResolveImports(ByVal imps As ImportsClauses, ByVal Name As String) As Boolean        '---------------------------------------------------------------------------------------------------------        '* If the (source file / compilation environment) 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.        '---------------------------------------------------------------------------------------------------------        Dim impmembers As New Generic.List(Of MemberInfo)        Dim result As Generic.List(Of MemberInfo) = Nothing        For Each imp As ImportsClause In imps            If imp.IsNamespaceClause Then                If imp.AsNamespaceClause.IsNamespaceImport Then                    'The specified name can only be a type.                    If Compiler.TypeManager.TypesByNamespace.ContainsKey(imp.AsNamespaceClause.Name) Then                        result = Compiler.TypeManager.GetTypesByNamespaceAndName(imp.AsNamespaceClause.Name, Name)                        'Helper.FilterByName(Compiler.TypeManager.TypesByNamespace(imp.AsNamespaceClause.Name).ToTypeList, Name, result)                    End If                ElseIf imp.AsNamespaceClause.IsTypeImport Then                    'result.AddRange(Helper.FilterByName(imp.AsNamespaceClause.TypeImported.GetMembers, Name))                    'result.AddRange(Compiler.TypeManager.GetCache(imp.AsNamespaceClause.TypeImported).LookupMembersFlattened(Name))                    result = Compiler.TypeManager.GetCache(imp.AsNamespaceClause.TypeImported).LookupMembersFlattened(Name)                Else                    Continue For 'This import was not resolved correctly, so don't use it.                End If            End If            If result IsNot Nothing AndAlso result.Count > 0 Then                If impmembers.Count > 0 Then                    Helper.AddError("If the identifier matches the name of an accessible type or type member in more than one import, a compile-time error occurs.")                End If                impmembers.AddRange(result)                'result.Clear()            End If        Next        If impmembers.Count > 0 Then            '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 Helper.IsMethodDeclaration(impmembers(0)) Then                Classification = New MethodGroupClassification(Me, Nothing, Nothing, impmembers)                Return True            End If            If Helper.IsTypeDeclaration(impmembers(0)) Then                Classification = New TypeClassification(Me, impmembers(0))                Return True            End If            Helper.NotImplemented("Found " & impmembers.Count & " impmembers.")        End If        Dim nsmembers As Generic.List(Of [Namespace])        nsmembers = imps.GetNamespaces(Me, Name)        If nsmembers.Count = 1 Then            '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.            Classification = New NamespaceClassification(Me, nsmembers(0))            Return True        ElseIf nsmembers.Count > 1 Then            Helper.AddError()        End If        '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.        Dim modules As TypeList = imps.GetModules(Me)        Dim found As Generic.List(Of MemberInfo)        found = Helper.GetMembersOfTypes(Compiler, modules, Name)        If SetClassificationOfModuleMembers(found) Then            Return True        End If        Return False    End Function    Private Function SetClassificationOfModuleMembers(ByVal found As Generic.List(Of MemberInfo)) As Boolean        If found.Count <= 0 Then            Return False        End If        If Helper.IsMethodDeclaration(found(0)) Then            Classification = New MethodGroupClassification(Me, Nothing, Nothing, found)            Return True        End If        If found.Count > 1 Then            Helper.AddError()        End If        If Helper.IsTypeDeclaration(found(0)) Then            Classification = New TypeClassification(Me, found(0))            Return True        End If        Dim first As MemberInfo = found(0)        If Helper.IsFieldDeclaration(first) Then            Dim var As FieldInfo = DirectCast(first, FieldInfo)            Helper.Assert(Parent.FindFirstParent(Of EnumDeclaration)() Is Nothing)            Classification = New VariableClassification(Me, var, Nothing)            Return True        End If        If Helper.IsPropertyDeclaration(first) Then            Dim var As PropertyInfo = DirectCast(first, PropertyInfo)            Classification = New PropertyAccessClassification(Me, var, Nothing, Nothing)            Return True        End If        Helper.NotImplemented("Found " & found.Count & " of type " & found(0).GetType.Name & " in location: " & Me.Location.ToString(Compiler))        Return True    End Function    '#If DEBUG Then    '    Public Overrides Sub Dump(ByVal Dumper As IndentedTextWriter)    '        m_Identifier.Dump(Dumper)    '        If m_TypeArgumentList IsNot Nothing Then    '            Dumper.Write("(Of ")    '            Compiler.Dumper.Dump(m_TypeArgumentList)    '            Dumper.Write(")")    '        End If    '    End Sub    '#End IfEnd Class

⌨️ 快捷键说明

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