⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typenameresolutioninfo.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 3 页
字号:
        '**	If the namespace contains one or more accessible standard modules, and R matches the name of an         '** accessible nested type in exactly one standard module, then the unqualified name refers to that nested type        Dim foundModules As Generic.List(Of Type)        foundModules = Helper.FilterToModules(FromWhere.Compiler, Types)        If foundModules.Count > 0 Then            Dim typesInAllModules As New Generic.List(Of Type)            For Each [module] As Type In foundModules                Dim typeInCurrentModule As Type                typeInCurrentModule = [module].GetNestedType(RName)                If typeInCurrentModule IsNot Nothing Then typesInAllModules.Add(typeInCurrentModule)            Next            If typesInAllModules.Count = 1 Then                m_FoundObjects.AddRange(typesInAllModules.ToArray)                Return True            ElseIf typesInAllModules.Count > 1 Then                '** If R matches the name of accessible nested types in more than one standard module, a compile-time                 '** error occurs.                Helper.AddError()                Return False            End If        End If        Return False    End Function    Private Function CheckNamespaces(ByVal R As String, ByVal TypeArgumentCount As Integer) As Boolean        '---------------------------------------------------------------------------------------------------------        '* For each nested namespace containing the name reference, starting from the innermost namespace and         '* going to the outermost namespace, do the following:        '** (...)        '---------------------------------------------------------------------------------------------------------        'Check all the namespaces up to the outermost namespace (not including)        Dim declaringtype As TypeDeclaration = FromWhere.FindFirstParent(Of TypeDeclaration)()        Dim ns As String        If declaringtype IsNot Nothing Then            ns = declaringtype.Namespace        Else            ns = String.Empty        End If        Dim current As BaseObject = FromWhere        'Dim dotR As String = "." & R        'Dim nsDotR As String = ns & dotR        Do            If CheckNamespace(R, FromWhere.Compiler.TypeManager.GetTypesByNamespace(ns), TypeArgumentCount) Then Return True            If Helper.NameCompare(ns, R) Then                m_FoundObjects.Add(FromWhere.Compiler.TypeManager.Namespaces(ns))                Return True            End If            If ns.Length > R.Length + 1 AndAlso ns.EndsWith(R, NameResolution.StringComparison) AndAlso ns(ns.Length - R.Length - 1) = "."c Then                m_FoundObjects.Add(FromWhere.Compiler.TypeManager.Namespaces(ns))                Return True            End If            If ns <> String.Empty AndAlso TypeArgumentCount = 0 Then                Dim nSpace As [Namespace]                nSpace = FromWhere.Compiler.TypeManager.Namespaces.FindNamespace(ns, R)                If nSpace IsNot Nothing Then                    m_FoundObjects.Add(nSpace)                    Return True                End If            End If            ns = vbnc.Helper.GetNamespaceParent(ns)            'nsDotR = ns & dotR        Loop Until ns Is Nothing        'Check the outermost namespace        'First the current compiling outermost namespace        If CheckNamespace(R, FromWhere.Compiler.TypeManager.GetTypesByNamespace(String.Empty), TypeArgumentCount) Then Return True        'then all the namespaces in the referenced assemblies        Return CheckOutermostNamespace(R, TypeArgumentCount)    End Function    Private Function CheckImportsAlias(ByVal R As String, ByVal [Imports] As ImportsClauses, ByVal TypeArgumentCount As Integer) As Boolean        '---------------------------------------------------------------------------------------------------------        '* If the source file has one or more import aliases, and R matches the name of one of them, then         '* the unqualified name refers to that import alias.        '---------------------------------------------------------------------------------------------------------        ' (...)        '---------------------------------------------------------------------------------------------------------        '* If the compilation environment defines one or more import aliases, and R matches the name of one of         '* them, then the unqualified name refers to that import alias.        '---------------------------------------------------------------------------------------------------------        For Each import As ImportsClause In [Imports]            If import.IsAliasClause Then                If NameResolution.CompareName(import.AsAliasClause.Name, R) Then                    m_FoundObjects.Add(import)                    Return True                End If            End If        Next        Return False    End Function    Private Function CheckImports(ByVal R As String, ByVal [Imports] As ImportsClauses, ByVal TypeArgumentCount As Integer) As Boolean        '---------------------------------------------------------------------------------------------------------        '*	If the source file containing the name reference has one or more imports:        '**	If R matches the name of an accessible type in exactly one import, then the unqualified name refers to         '** that type. If R matches the name of an accessible type in more than one import and all are not the         '** same entity, a compile-time error occurs.        '**	If R matches the name of a namespace in exactly one import, then the unqualified name refers to that        '** namespace. If R matches the name of a namespace in more than one import and all are not the same entity, a         '** compile-time error occurs.        '**	If the imports contain one or more accessible standard modules, and R matches the name of an accessible         '** nested type in exactly one standard module, then the unqualified name refers to that type. If R matches         '** the name of accessible nested types in more than one standard module, a compile-time error occurs.        '---------------------------------------------------------------------------------------------------------        ' (...)        '---------------------------------------------------------------------------------------------------------        '* If the compilation environment defines one or more imports:        '**	If R matches the name of an accessible type in exactly one import, then the unqualified name refers to         '** that type. If R matches the name of an accessible type in more than one import, a compile-time error         '** occurs.        '**	If R matches the name of a namespace in exactly one import, then the unqualified name refers to that        '** namespace. If R matches the name of a namespace in more than one import, a compile-time error occurs.        '**	If the imports contain one or more accessible standard modules, and R matches the name of an accessible        '** nested type in exactly one standard module, then the unqualified name refers to that type. If R matches the        '** name of accessible nested types in more than one standard module, a compile-time error occurs.        '---------------------------------------------------------------------------------------------------------        Dim nsclauses As New Generic.List(Of ImportsNamespaceClause)        For Each imp As ImportsClause In [Imports]            If imp.IsNamespaceClause Then nsclauses.Add(imp.AsNamespaceClause)        Next        Dim tpFound As New Generic.List(Of Object)        Dim genericR As String = Helper.CreateGenericTypename(R, TypeArgumentCount)        '**	If R matches the name of an accessible type in exactly one import, then the unqualified name refers to         '** that type. If R matches the name of an accessible type in more than one import, a compile-time error         '** occurs.        For Each nsimp As ImportsNamespaceClause In nsclauses            If nsimp.IsTypeImport Then                Dim tp As Type                tp = nsimp.TypeImported.GetNestedType(genericR)                If tp IsNot Nothing Then tpFound.Add(tp)            ElseIf nsimp.IsNamespaceImport Then                Dim nsName As String = nsimp.NamespaceImported.FullName                If FromWhere.Compiler.TypeManager.TypesByNamespace.ContainsKey(nsName) Then                    Dim foundType As Type                    foundType = FromWhere.Compiler.TypeManager.TypesByNamespace(nsName).Item(genericR)                    If foundType IsNot Nothing Then tpFound.Add(foundType)                End If            Else                Continue For            End If        Next        If tpFound.Count = 1 Then            m_FoundObjects.Add(tpFound(0))            Return True        ElseIf tpFound.Count > 0 Then            Helper.AddError()            Return False        End If        '**	If R matches the name of a namespace in exactly one import, then the unqualified name refers to that        '** namespace. If R matches the name of a namespace in more than one import, a compile-time error occurs.        'Helper.Stop()        For Each nsimp As ImportsNamespaceClause In nsclauses            If nsimp.IsNamespaceImport Then                Dim nsName As String = nsimp.NamespaceImported.FullName                Dim nsCombined As String = String.Concat(nsName, ".", Helper.CreateGenericTypename(R, TypeArgumentCount))                If FromWhere.Compiler.TypeManager.Namespaces.ContainsKey(nsCombined) Then                    tpFound.Add(FromWhere.Compiler.TypeManager.Namespaces(nsCombined))                End If            ElseIf nsimp.IsTypeImport Then                'Skip this            Else                Continue For            End If        Next        If tpFound.Count = 1 Then            m_FoundObjects.Add(tpFound(0))            Return True        ElseIf tpFound.Count > 0 Then            Helper.AddError()            Return False        End If        '**	If the imports contain one or more accessible standard modules, and R matches the name of an accessible        '** nested type in exactly one standard module, then the unqualified name refers to that type. If R matches the                 '** name of accessible nested types in more than one standard module, a compile-time error occurs.        'Helper.Stop()        Dim modules As New TypeList        For Each nsimp As ImportsNamespaceClause In nsclauses            If nsimp.IsTypeImport Then                Dim tp As Type                tp = nsimp.TypeImported.GetNestedType(genericR)                If tp IsNot Nothing AndAlso Helper.IsModule(FromWhere.Compiler, tp) Then modules.Add(tp)            ElseIf nsimp.IsNamespaceImport Then                Dim nsName As String = nsimp.NamespaceImported.FullName                modules.AddRange(FromWhere.Compiler.TypeManager.GetModulesByNamespace(nsName).ToTypeList)            Else                Continue For            End If        Next        If CheckModules(modules, R, TypeArgumentCount) Then Return True        Return False    End Function    Private Function ResolveUnqualifiedName(ByVal Rs As String(), ByVal TypeArgumentCount As Integer) As Boolean        For Each R As String In Rs            '---------------------------------------------------------------------------------------------------------            ' Given an unqualified name R, the following steps describe how to determine to which namespace or type an             ' unqualified name refers:            '---------------------------------------------------------------------------------------------------------            '---------------------------------------------------------------------------------------------------------            '* For each nested type containing the name reference, starting from the innermost type and going to the            '* outermost, if R matches the name of an accessible nested type or a type parameter in the current type,             '* then the unqualified name refers to that type or type parameter.            '---------------------------------------------------------------------------------------------------------            If CheckNestedTypesOrTypeParameters(R, TypeArgumentCount) Then Return True            '---------------------------------------------------------------------------------------------------------            '* For each nested namespace containing the name reference, starting from the innermost namespace and             '* going to the outermost namespace, do the following:            '*            '**	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.            '*            '**	If the namespace contains one or more accessible standard modules, and R matches the name of an             '** accessible nested type in exactly one standard module, then the unqualified name refers to that nested type            '*            '** If R matches the name of accessible nested types in more than one standard module, a compile-time             '** error occurs.            '---------------------------------------------------------------------------------------------------------            If CheckNamespaces(R, TypeArgumentCount) Then Return True            '---------------------------------------------------------------------------------------------------------            '* If the source file has one or more import aliases, and R matches the name of one of them, then             '* the unqualified name refers to that import alias.            '---------------------------------------------------------------------------------------------------------            Helper.Assert(FromWhere IsNot Nothing)            'Helper.Assert(FromWhere.HasLocation)            Helper.Assert(FromWhere.File IsNot Nothing)            Helper.Assert(FromWhere.File.Imports IsNot Nothing)            If CheckImportsAlias(R, FromWhere.File.Imports, TypeArgumentCount) Then Return True            '---------------------------------------------------------------------------------------------------------            '*	If the source file containing the name reference has one or more imports:            '**	If R matches the name of an accessible type in exactly one import, then the unqualified name refers to             '** that type. If R matches the name of an accessible type in more than one import and all are not the             '** same entity, a compile-time error occurs.            '**	If R matches the name of a namespace in exactly one import, then the unqualified name refers to that            '** namespace. If R matches the name of a namespace in more than one import and all are not the same entity, a             '** compile-time error occurs.            '**	If the imports contain one or more accessible standard modules, and R matches the name of an accessible             '** nested type in exactly one standard module, then the unqualified name refers to that type. If R matches             '** the name of accessible nested types in more than one standard module, a compile-time error occurs.            '---------------------------------------------------------------------------------------------------------            If CheckImports(R, FromWhere.File.Imports, TypeArgumentCount) Then Return True            '---------------------------------------------------------------------------------------------------------            '* If the compilation environment defines one or more import aliases, and R matches the name of one of             '* them, then the unqualified name refers to that import alias.            '---------------------------------------------------------------------------------------------------------            If CheckImportsAlias(R, FromWhere.Compiler.CommandLine.Imports.Clauses, TypeArgumentCount) Then Return True            '---------------------------------------------------------------------------------------------------------            '* If the compilation environment defines one or more imports:            '**	If R matches the name of an accessible type in exactly one import, then the unqualified name refers to             '** that type. If R matches the name of an accessible type in more than one import, a compile-time error             '** occurs.            '**	If R matches the name of a namespace in exactly one import, then the unqualified name refers to that            '** namespace. If R matches the name of a namespace in more than one import, a compile-time error occurs.            '**	If the imports contain one or more accessible standard modules, and R matches the name of an accessible            '** nested type in exactly one standard module, then the unqualified name refers to that type. If R matches the                             '** name of accessible nested types in more than one standard module, a compile-time error occurs.            '---------------------------------------------------------------------------------------------------------            If CheckImports(R, FromWhere.Compiler.CommandLine.Imports.Clauses, TypeArgumentCount) Then Return True        Next        '---------------------------------------------------------------------------------------------------------        '* Otherwise, a compile-time error occurs.        '---------------------------------------------------------------------------------------------------------        FromWhere.Compiler.Report.ShowMessage(Messages.VBNC30451, FromWhere.Location, Rs(0))        '---------------------------------------------------------------------------------------------------------        '* Note           '* An implication of this resolution process is that type members do not shadow namespaces or types         '* when resolving namespace or type names.        '* If the type name is a constructed type name (i.e. it includes a type argument list), then only types         '* with the same arity as the type argument list are matched.        '---------------------------------------------------------------------------------------------------------        Return False    End FunctionEnd Class

⌨️ 快捷键说明

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