📄 orelseexpression.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' Public Class OrElseExpression Inherits BinaryExpression Protected Overrides Function GenerateCodeInternal(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True Dim opType As TypeCode = MyBase.OperandTypeCode ValidateBeforeGenerateCode(Info) Select Case opType Case TypeCode.Boolean, TypeCode.Object If opType = TypeCode.Object Then Helper.Assert(Helper.CompareType(OperandType, Compiler.TypeCache.System_Object)) End If Dim loadtrue, endexp As Reflection.Emit.Label loadtrue = Info.ILGen.DefineLabel endexp = Info.ILGen.DefineLabel result = m_LeftExpression.GenerateCode(Info) AndAlso result If opType = TypeCode.Object Then Emitter.EmitCall(Info, Compiler.TypeCache.MS_VB_CS_Conversions__ToBoolean_Object) End If Emitter.EmitBranchIfTrue(Info, loadtrue) result = m_RightExpression.GenerateCode(Info) AndAlso result If opType = TypeCode.Object Then Emitter.EmitCall(Info, Compiler.TypeCache.MS_VB_CS_Conversions__ToBoolean_Object) End If Emitter.EmitBranchIfTrue(Info, loadtrue) Emitter.EmitLoadValue(Info, False) 'Load false value Emitter.EmitBranch(Info, endexp) Info.ILGen.MarkLabel(loadtrue) Emitter.EmitLoadValue(Info, True) 'Load true value Info.ILGen.MarkLabel(endexp) 'The end of the expression Info.Stack.Pop(Compiler.TypeCache.System_Boolean) 'Both a true and a false value was added to the stack, remove one. If opType = TypeCode.Object Then Emitter.EmitBox(Info, Compiler.TypeCache.System_Boolean) Emitter.EmitCall(Info, Compiler.TypeCache.System_Runtime_CompilerServices_RuntimeHelpers__GetObjectValue_Object) End If Case Else Throw New InternalException(Me) End Select Return result End Function Sub New(ByVal Parent As ParsedObject, ByVal LExp As Expression, ByVal RExp As Expression) MyBase.New(Parent, LExp, RExp) End Sub Public Overrides ReadOnly Property Keyword() As KS Get Return KS.OrElse End Get End Property Public Overrides ReadOnly Property IsConstant() As Boolean Get Return MyBase.IsConstant 'CHECK: is this true? End Get End Property Public Overrides ReadOnly Property ConstantValue() As Object Get Dim rvalue, lvalue As Object lvalue = m_LeftExpression.ConstantValue rvalue = m_RightExpression.ConstantValue If lvalue Is Nothing Or rvalue Is Nothing Then Return Nothing ElseIf TypeOf lvalue Is Boolean = False Then Throw New InternalException(Me) 'TODO: Add error ElseIf TypeOf rvalue Is Boolean = False Then Throw New InternalException(Me) 'TODO: Add error Else Return CBool(lvalue) OrElse CBool(rvalue) End If End Get End PropertyEnd Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -