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

📄 variableclassification.vb

📁 大名鼎鼎的mono是.NET平台的跨平台(支持linux
💻 VB
📖 第 1 页 / 共 2 页
字号:
' ' 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' Imports System.ReflectionImports System.Reflection.Emit''' <summary>''' Every variable has an associated type, namely the declared type of the variable.''' </summary>''' <remarks></remarks>Public Class VariableClassification    Inherits ExpressionClassification    Private m_ParameterInfo As ParameterInfo    Private m_FieldInfo As FieldInfo    Private m_LocalBuilder As LocalBuilder    Private m_InstanceExpression As Expression    Private m_Parameter As Parameter    Private m_Variable As VariableDeclaration    Private m_Method As IMethod    Private m_Expression As Expression    Private m_ExpressionType As Type    Private m_ArrayVariable As Expression    Private m_Arguments As ArgumentList    ReadOnly Property Method() As IMethod        Get            Return m_Method        End Get    End Property    ReadOnly Property Expression() As Expression        Get            Return m_Expression        End Get    End Property    ReadOnly Property ArrayVariable() As Expression        Get            Return m_ArrayVariable        End Get    End Property    ReadOnly Property Arguments() As ArgumentList        Get            Return m_Arguments        End Get    End Property    Public Overrides ReadOnly Property IsConstant() As Boolean        Get            If Me.FieldInfo IsNot Nothing Then                If Me.FieldInfo.IsLiteral Then                    ConstantValue = Me.FieldInfo.GetValue(Nothing)                    Return True                ElseIf Me.FieldInfo.IsInitOnly Then                    Dim decAttrs() As Object                    Dim fD As FieldDescriptor = TryCast(Me.FieldInfo, FieldDescriptor)                    If fD IsNot Nothing Then                        If fD.Declaration.Modifiers.Is(ModifierMasks.Const) Then Return True                        If Helper.IsEnum(Compiler, fD.DeclaringType) Then Return True                        Return False                    End If                    decAttrs = Me.FieldInfo.GetCustomAttributes(Compiler.TypeCache.System_Runtime_CompilerServices_DecimalConstantAttribute, False)                    If decAttrs IsNot Nothing AndAlso decAttrs.Length = 1 Then                        ConstantValue = DirectCast(decAttrs(0), System.Runtime.CompilerServices.DecimalConstantAttribute).Value()                        Return True                    End If                    Dim dtAttrs() As Object                    dtAttrs = Me.FieldInfo.GetCustomAttributes(Compiler.TypeCache.System_Runtime_CompilerServices_DateTimeConstantAttribute, False)                    If dtAttrs IsNot Nothing AndAlso dtAttrs.Length = 1 Then                        ConstantValue = DirectCast(dtAttrs(0), System.Runtime.CompilerServices.DateTimeConstantAttribute).Value()                        Return True                    End If                    Return False                Else                    Return False                End If            Else                Return False            End If        End Get    End Property    ReadOnly Property ParameterInfo() As ParameterInfo        Get            Return m_ParameterInfo        End Get    End Property    ReadOnly Property LocalBuilder() As LocalBuilder        Get            If m_Variable IsNot Nothing Then                Return m_Variable.LocalBuilder            Else                Return Nothing            End If        End Get    End Property    ReadOnly Property FieldInfo() As FieldInfo        Get            If m_Variable IsNot Nothing AndAlso m_Variable.FieldBuilder IsNot Nothing Then                Return m_Variable.FieldBuilder            Else                Return m_FieldInfo            End If        End Get    End Property    ''' <summary>    ''' Loads the value of the variable.    ''' </summary>    ''' <param name="Info"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Friend Function GenerateCodeAsValue(ByVal Info As EmitInfo) As Boolean        Dim result As Boolean = True        Helper.Assert(Info.DesiredType IsNot Nothing)        If m_InstanceExpression IsNot Nothing Then            result = m_InstanceExpression.GenerateCode(Info) AndAlso result        End If        If FieldInfo IsNot Nothing Then            If Info.IsRHS Then                Emitter.EmitLoadVariable(Info, FieldInfo)            Else                Helper.NotImplemented()            End If        ElseIf LocalBuilder IsNot Nothing Then            If Info.IsRHS Then                Emitter.EmitLoadVariable(Info, LocalBuilder)            Else                Helper.NotImplemented()            End If        ElseIf ParameterInfo IsNot Nothing Then            Helper.Assert(m_InstanceExpression Is Nothing)            If Info.IsRHS Then                Emitter.EmitLoadVariable(Info, ParameterInfo)            Else                Helper.NotImplemented()            End If        ElseIf m_ArrayVariable IsNot Nothing Then            result = Helper.EmitLoadArrayElement(Info, m_ArrayVariable, m_Arguments) AndAlso result        ElseIf m_Expression IsNot Nothing Then            result = m_Expression.GenerateCode(Info) AndAlso result        Else            Throw New InternalException(Me)        End If        If Info.DesiredType.IsByRef Then            Dim elementType As Type = Info.DesiredType.GetElementType            Dim local As LocalBuilder            local = Info.ILGen.DeclareLocal(elementType)            Emitter.EmitStoreVariable(Info, local)            Emitter.EmitLoadVariableLocation(Info, local)        End If        Return result    End Function    ''' <summary>    ''' Stores at the address of the variable.    ''' </summary>    ''' <param name="Info"></param>    ''' <returns></returns>    ''' <remarks></remarks>    Friend Overrides Function GenerateCode(ByVal Info As EmitInfo) As Boolean        Dim result As Boolean = True        If m_Expression IsNot Nothing Then            Return m_Expression.GenerateCode(Info)        End If        Helper.Assert(Info.IsRHS AndAlso Info.RHSExpression Is Nothing OrElse Info.IsLHS AndAlso Info.RHSExpression IsNot Nothing)

⌨️ 快捷键说明

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