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

📄 compiler.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 3 页
字号:
' ' 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' #If DEBUG Then#Const EXTENDEDDEBUG = 0#End If''' <summary>''' The compiler''' </summary>''' <remarks></remarks>Public Class Compiler    Inherits BaseObject    ''' <summary>    ''' The filename of the resulting assembly.    ''' </summary>    ''' <remarks></remarks>    Private m_OutFilename As String    ''' <summary>    ''' The reporting object    ''' </summary>    ''' <remarks></remarks>    Private m_Report As New Report(Me)    ''' <summary>    ''' A helper    ''' </summary>    ''' <remarks></remarks>    Private m_Helper As New Helper(Me)    ''' <summary>    ''' The parser    ''' </summary>    ''' <remarks></remarks>    Private m_Parser As Parser    ''' <summary>    ''' Represents the commandline passed on to the compiler    ''' </summary>    ''' <remarks></remarks>    Private m_CommandLine As New CommandLine(Me)    ''' <summary>    ''' The scanner of the code    ''' </summary>    ''' <remarks></remarks>    Private m_Scanner As New Scanner(Me)    ''' <summary>    ''' The token manager.    ''' </summary>    ''' <remarks></remarks>    Private m_tm As tm    ''' <summary>    ''' Contains info about all the types and namespaces available.    ''' </summary>    ''' <remarks></remarks>    Private m_TypeManager As New TypeManager(Me)    ''' <summary>    ''' The compiling assembly    ''' </summary>    ''' <remarks></remarks>    Friend theAss As AssemblyDeclaration    ''' <summary>    ''' The created assembly    ''' </summary>    ''' <remarks></remarks>    Public AssemblyBuilder As System.Reflection.Emit.AssemblyBuilder#If ENABLECECIL Then    Public AssemblyBuilderCecil As Mono.Cecil.AssemblyDefinition#End If    ''' <summary>    ''' The one and only module in the assembly    ''' </summary>    ''' <remarks></remarks>    Public ModuleBuilder As System.Reflection.Emit.ModuleBuilder#If ENABLECECIL Then    Public ModuleBuilderCecil As Mono.Cecil.ModuleDefinition#End If    ''' <summary>    ''' Represents the conditinal compiler.    ''' </summary>    ''' <remarks></remarks>    Private m_ConditionalCompiler As ConditionalCompiler    Private m_TypeCache As TypeCache#If ENABLECECIL Then    Private m_CecilTypeCache As CecilTypeCache#End If    'Private SequenceCompleted(CompilerSequence.Finished) As Boolean    Private SequenceTime(CompilerSequence.End) As DateTime    Private m_TypeResolver As TypeResolution    Private m_NameResolver As NameResolution    Private m_SymbolWriter As System.Diagnostics.SymbolStore.ISymbolWriter    Sub New()        MyBase.New(Nothing)    End Sub    Public Sub VerifyConsistency(ByVal result As Boolean, Optional ByVal Location As String = "")        If Report.Errors = 0 AndAlso result = False Then            Report.WriteLine(vbnc.Report.ReportLevels.Debug, "No errors, but compilation failed? " & Location)            Throw New InternalException("Consistency check failed")        ElseIf Report.Errors > 0 AndAlso result Then            Report.WriteLine(vbnc.Report.ReportLevels.Debug, Report.Errors.ToString & " errors, but compilation succeeded? " & Location)            Throw New InternalException("Consistency check failed")        End If    End Sub    ReadOnly Property OutFileName() As String        Get            Return m_OutFilename        End Get    End Property#If ENABLECECIL Then    ReadOnly Property CecilTypeCache() As CecilTypeCache        Get            Return m_CecilTypeCache        End Get    End Property#End If    ReadOnly Property TypeCache() As TypeCache        Get            Return m_TypeCache        End Get    End Property    ReadOnly Property SymbolWriter() As System.Diagnostics.SymbolStore.ISymbolWriter        Get            Return m_SymbolWriter        End Get    End Property    ''' <summary>    ''' Contains info about all the types and namespaces available.    ''' </summary>    ''' <remarks></remarks>    Friend ReadOnly Property TypeManager() As TypeManager        Get            Return m_TypeManager        End Get    End Property    ''' <summary>    ''' The global reporting object    ''' </summary>    ''' <remarks></remarks>    Friend Shadows ReadOnly Property Report() As Report        Get            Return m_Report        End Get    End Property    Friend ReadOnly Property Parser() As Parser        Get            Return m_Parser        End Get    End Property    ''' <summary>    ''' Represents the commandline passed on to the compiler    ''' </summary>    ''' <remarks></remarks>    Friend Property CommandLine() As CommandLine        Get            Return m_CommandLine        End Get        Set(ByVal value As CommandLine)            m_CommandLine = value        End Set    End Property    ''' <summary>    ''' The scanner of the code    ''' </summary>    ''' <remarks></remarks>    Friend ReadOnly Property Scanner() As Scanner        Get            Return m_Scanner        End Get    End Property    Friend Overrides ReadOnly Property tm() As tm        Get            Return m_tm        End Get    End Property    Friend ReadOnly Property ConditionalCompiler() As ConditionalCompiler        Get            Return m_ConditionalCompiler        End Get    End Property    Friend ReadOnly Property Helper() As Helper        Get            Return m_Helper        End Get    End Property    Friend ReadOnly Property TypeResolver() As TypeResolution        Get            Return m_TypeResolver        End Get    End Property    Friend ReadOnly Property TypeResolution() As TypeResolution        Get            Return m_TypeResolver        End Get    End Property    Friend ReadOnly Property NameResolver() As NameResolution        Get            Return m_NameResolver        End Get    End Property    ReadOnly Property EmittingDebugInfo() As Boolean        Get            Return m_CommandLine.DebugInfo <> vbnc.CommandLine.DebugTypes.None        End Get    End Property    Function HasPassedSequencePoint(ByVal Point As CompilerSequence) As Boolean        Return SequenceTime(Point) > #1/1/1900#    End Function    Private Function CreateTestOutputFilename(ByVal Filename As String, ByVal TestType As String) As String        Dim dir As String        dir = IO.Path.GetDirectoryName(Filename)        If dir = "" Then dir = Environment.CurrentDirectory        'dir = IO.Path.Combine(IO.Path.GetDirectoryName(Filename), "testoutput")        If IO.Directory.Exists(dir) = False Then IO.Directory.CreateDirectory(dir)        Return IO.Path.Combine(dir, IO.Path.GetFileName(Filename) & "." & TestType & ".output.xml")    End Function    Function Compile(ByVal CommandLine As String()) As Integer        'Try        'Show the help if there was an error parsing commandline        If m_CommandLine.Parse(CommandLine) = False Then            ShowHelp()            Return 1        End If        Return Compile()        'Catch ex As Exception        '    ShowExceptionInfo(ex)        '    Return -1        'End Try    End Function    Friend Function Compile(ByVal Options As CommandLine) As Boolean        m_CommandLine = Options        Return Compile() = 0    End Function    Function Compile_CalculateOutputFilename() As Boolean        If CommandLine.Out = "" Then            'Get the first filename            m_OutFilename = CommandLine.Files(0).FileName            'Strip the extension            m_OutFilename = m_OutFilename.Substring(0, m_OutFilename.Length - IO.Path.GetExtension(m_OutFilename).Length)            If m_OutFilename.EndsWith(".") = False Then m_OutFilename &= "."            'Put on the correct extension            If CommandLine.Target = vbnc.CommandLine.Targets.Console OrElse CommandLine.Target = vbnc.CommandLine.Targets.Winexe Then                m_OutFilename &= "exe"            ElseIf CommandLine.Target = vbnc.CommandLine.Targets.Library Then                m_OutFilename &= "dll"            ElseIf CommandLine.Target = vbnc.CommandLine.Targets.Module Then                m_OutFilename &= "netmodule"            Else                Throw New InternalException(Me)            End If        Else            m_OutFilename = CommandLine.Out        End If        m_OutFilename = IO.Path.GetFullPath(m_OutFilename)        Return True    End Function    Private Function Compile_CreateAssemblyAndModuleBuilders() As Boolean        Dim assemblyName As Reflection.AssemblyName        assemblyName = Me.Assembly.GetName        AssemblyBuilder = System.AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, System.Reflection.Emit.AssemblyBuilderAccess.Save, IO.Path.GetDirectoryName(m_OutFilename))        ModuleBuilder = AssemblyBuilder.DefineDynamicModule(assemblyName.Name, IO.Path.GetFileName(m_OutFilename), EmittingDebugInfo)#If DEBUGREFLECTION Then        vbnc.Helper.DebugReflection_AppendLine("{0} = System.AppDomain.CurrentDomain.DefineDynamicAssembly({1}, System.Reflection.Emit.AssemblyBuilderAccess.Save, ""{2}"")", AssemblyBuilder, assemblyName, IO.Path.GetDirectoryName(m_OutFilename))        vbnc.Helper.DebugReflection_AppendLine("{0} = {4}.DefineDynamicModule(""{1}"", ""DEBUGREFLECTED{2}"", {3})", ModuleBuilder, assemblyName.Name, IO.Path.GetFileName(m_OutFilename), EmittingDebugInfo, AssemblyBuilder)#End If        If m_CommandLine.DebugInfo <> vbnc.CommandLine.DebugTypes.None Then            m_SymbolWriter = ModuleBuilder.GetSymWriter        End If#If ENABLECECIL Then        AssemblyBuilderCecil = Mono.Cecil.AssemblyFactory.DefineAssembly(assemblyName.Name, Mono.Cecil.AssemblyKind.Dll)        ModuleBuilderCecil = AssemblyBuilderCecil.MainModule#End If        Return Compiler.Report.Errors = 0    End Function    Private Function Compile_Parse() As Boolean        Dim result As Boolean = True        Dim RootNamespace As String        If CommandLine.RootNamespace = "" Then            RootNamespace = "" '(IO.Path.GetFileNameWithoutExtension(m_OutFilename))        Else            RootNamespace = (CommandLine.RootNamespace)        End If        m_Scanner = New Scanner(Me)        m_ConditionalCompiler = New ConditionalCompiler(Me, m_Scanner)

⌨️ 快捷键说明

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