📄 assemblydeclaration.vb
字号:
' ' Visual Basic.Net Compiler' Copyright (C) 2004 - 2007 Rolf Bjarne Kvinge, RKvinge@novell.com' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA' #Const DEBUGRESOLVE = True#If DEBUG Then#Const EXTENDEDDEBUG = 0#End IfImports System.Reflection.Emit''' <summary>''' This is the root for the parse tree''' Start ::=''' [ OptionStatement+ ]''' [ ImportsStatement+ ]''' [ AttributesStatement+ ]''' [ NamespaceMemberDeclaration+ ]''' </summary>''' <remarks></remarks>Public Class AssemblyDeclaration Inherits ParsedObject ''' <summary> ''' The attributes of this assembly. ''' </summary> ''' <remarks></remarks> Private m_Attributes As New Attributes(Me) ''' <summary> ''' The name of the assembly. ''' </summary> ''' <remarks></remarks> Private m_Name As String ''' <summary> ''' All the non-nested types in this assembly. ''' </summary> ''' <remarks></remarks> Private m_Members As MemberDeclarations ''' <summary> ''' All the types as an array of type declarations. ''' </summary> ''' <remarks></remarks> Private m_TypeDeclarations() As TypeDeclaration ''' <summary> ''' All the types as an array of type descriptors ''' </summary> ''' <remarks></remarks> Private m_Types() As TypeDescriptor Private m_GroupedClasses As Generic.List(Of MyGroupData) Property GroupedClasses() As Generic.List(Of MyGroupData) Get Return m_GroupedClasses End Get Set(ByVal value As Generic.List(Of MyGroupData)) m_GroupedClasses = value End Set End Property ReadOnly Property TypeDeclarations() As TypeDeclaration() Get Return m_TypeDeclarations End Get End Property Sub New(ByVal Parent As Compiler) MyBase.New(Parent) End Sub Sub Init(ByVal Types As MemberDeclarations, ByVal Attributes As Attributes) If m_Attributes Is Nothing Then m_Attributes = Attributes Else m_Attributes.AddRange(Attributes) End If m_Members = Types m_TypeDeclarations = m_Members.GetSpecificMembers(Of TypeDeclaration).ToArray ReDim m_Types(m_TypeDeclarations.Length - 1) For i As Integer = 0 To m_Types.Length - 1 m_Types(i) = m_TypeDeclarations(i).TypeDescriptor Next Helper.Assert(m_Members.Count = m_TypeDeclarations.Length) End Sub Private Function DefineType(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.DefineType AndAlso result For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = DefineType(NestedType) AndAlso result Next Return result End Function Private Function DefineTypeHierarchy(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.DefineTypeHierarchy AndAlso result For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = DefineTypeHierarchy(NestedType) AndAlso result Next Return result End Function Private Function DefineMembers(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True Helper.Assert(Type.TypeBuilder IsNot Nothing OrElse Type.EnumBuilder IsNot Nothing) For Each i As IMember In Type.Members.GetSpecificMembers(Of IMember)() If TypeOf i Is TypeDeclaration Then 'If TypeOf i Is DelegateDeclaration = False Then result = DefineMembers(DirectCast(i, TypeDeclaration)) AndAlso result vbnc.Helper.Assert(result = (Report.Errors = 0)) 'Else 'Skip the delagete declarations, they are already defined. 'End If ElseIf TypeOf i Is IDefinableMember Then result = DirectCast(i, IDefinableMember).DefineMember AndAlso result vbnc.Helper.Assert(result = (Report.Errors = 0)) Else Throw New InternalException("Type " & CObj(i).GetType.ToString & " is not a definable object") End If Next Return result End Function Private Function DefineTypeParameters(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.DefineTypeParameters AndAlso result For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = DefineTypeParameters(NestedType) AndAlso result Next Return result End Function Friend Function Emit(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.GenerateCode(Nothing) AndAlso result result = Type.Members.GenerateCode(Nothing) AndAlso result For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = Emit(NestedType) AndAlso result Next Return result End Function Private Function CreateType(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.CreateType AndAlso result For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = CreateType(NestedType) AndAlso result Next Return result End Function Overrides Function ResolveCode(ByVal Info As ResolveInfo) As Boolean Dim result As Boolean = True For Each type As TypeDeclaration In m_TypeDeclarations#If EXTENDEDDEBUG Then Dim iCount As Integer iCount += 1 Try System.Console.ForegroundColor = ConsoleColor.Green Catch ex As Exception End Try Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "ResolveCode " & type.FullName & " (" & iCount & " of " & m_TypeDeclarations.Length & " types)") Try System.Console.ResetColor() Catch ex As Exception End Try#End If result = type.ResolveCode(Info) AndAlso result 'vbnc.Helper.Assert(result = (Report.Errors = 0)) Next result = m_Attributes.ResolveCode(Info) AndAlso result 'vbnc.Helper.Assert(result = (Report.Errors = 0)) Return result End Function Function ResolveTypes() As Boolean Dim result As Boolean = True For Each type As TypeDeclaration In m_TypeDeclarations#If EXTENDEDDEBUG Then Dim iCount As Integer iCount += 1 Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "ResolveType " & type.FullName & " (" & iCount & " of " & m_TypeDeclarations.Length & " types)")#End If result = ResolveType(type) AndAlso result Next Return result End Function Private Shared Function ResolveType(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True result = Type.ResolveType AndAlso result For Each n As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = ResolveType(n) AndAlso result Next Return result End Function Function CreateImplicitTypes() As Boolean Dim result As Boolean = True For Each Type As TypeDeclaration In Me.Types#If EXTENDEDDEBUG Then Dim iCount As Integer iCount += 1 Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "CreateImplicitTypes " & Type.FullName & " (" & iCount & " of " & m_TypeDeclarations.Length & " types)")#End If Dim tmp As IHasImplicitTypes = TryCast(Type, IHasImplicitTypes) If tmp IsNot Nothing Then result = tmp.CreateImplicitTypes AndAlso result result = CreateImplicitTypes(Type) AndAlso result Next Return result End Function Private Function CreateImplicitTypes(ByVal Type As TypeDeclaration) As Boolean Dim result As Boolean = True For Each NestedType As TypeDeclaration In Type.Members.GetSpecificMembers(Of TypeDeclaration)() result = CreateImplicitTypes(NestedType) AndAlso result Next For Each Member As IHasImplicitTypes In Type.Members.GetSpecificMembers(Of IHasImplicitTypes)() result = Member.CreateImplicitTypes() AndAlso result Next Return result End Function Overrides Function ResolveTypeReferences() As Boolean Dim result As Boolean = True For Each type As TypeDeclaration In m_TypeDeclarations#If EXTENDEDDEBUG Then Dim iCount As Integer iCount += 1 Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, "ResolveTypeReferences " & type.FullName & " (" & iCount & " of " & m_TypeDeclarations.Length & " types)")#End If result = ResolveTypeReferences(type) AndAlso result
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -