📄 ccharexpression.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 CCharExpression Inherits ConversionExpression Sub New(ByVal Parent As ParsedObject, ByVal Expression As Expression) MyBase.New(Parent, Expression) End Sub Sub New(ByVal Parent As ParsedObject) MyBase.New(Parent) End Sub Protected Overrides Function GenerateCodeInternal(ByVal Info As EmitInfo) As Boolean Return GenerateCode(Me.Expression, Info) End Function Overloads Shared Function GenerateCode(ByVal Expression As Expression, ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True Dim expType As Type = Expression.ExpressionType Dim expTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, expType) result = Expression.GenerateCode(Info.Clone(Info.Compiler.TypeCache.System_Char)) AndAlso result Select Case expTypeCode Case TypeCode.Char 'Nothing to do Case TypeCode.SByte, TypeCode.Byte, TypeCode.Int16, TypeCode.Int32, TypeCode.Int64, TypeCode.UInt16, TypeCode.UInt32, TypeCode.UInt64 Info.Compiler.Report.ShowMessage(Messages.VBNC32007, expType.Name) result = False Case TypeCode.Boolean, TypeCode.Double, TypeCode.DateTime, TypeCode.Decimal, TypeCode.Single Info.Compiler.Report.ShowMessage(Messages.VBNC30311, expType.Name, expType.Name) result = False Case TypeCode.Object If Helper.CompareType(expType, Info.Compiler.TypeCache.System_Object) Then Emitter.EmitCall(Info, Info.Compiler.TypeCache.MS_VB_CS_Conversions__ToChar_Object) ElseIf Helper.CompareType(expType, Info.Compiler.TypeCache.Nothing) Then 'Nothing to do Else Helper.NotImplemented() End If Case TypeCode.String Emitter.EmitCall(Info, Info.Compiler.TypeCache.MS_VB_CS_Conversions__ToChar_String) Case Else Helper.NotImplemented() End Select Return result End Function Protected Overrides Function ResolveExpressionInternal(ByVal Info As ResolveInfo) As Boolean Dim result As Boolean = True result = MyBase.ResolveExpressionInternal(Info) AndAlso result result = Validate(Info, Expression.ExpressionType) AndAlso result Return result End Function Shared Function Validate(ByVal Info As ResolveInfo, ByVal SourceType As Type) As Boolean Dim result As Boolean = True Dim expType As Type = SourceType Dim expTypeCode As TypeCode = Helper.GetTypeCode(Info.Compiler, expType) Dim ExpressionType As Type = Info.Compiler.TypeCache.System_Char Select Case expTypeCode Case TypeCode.SByte, TypeCode.Byte, TypeCode.Int16, TypeCode.Int32, TypeCode.Int64, TypeCode.UInt16, TypeCode.UInt32, TypeCode.UInt64 Info.Compiler.Report.ShowMessage(Messages.VBNC32007, expType.Name) result = False Case TypeCode.Boolean, TypeCode.Double, TypeCode.DateTime, TypeCode.Decimal, TypeCode.Single Info.Compiler.Report.ShowMessage(Messages.VBNC30311, expType.Name, ExpressionType.Name) result = False End Select Return result End Function Public Overrides ReadOnly Property IsConstant() As Boolean Get Return Expression.IsConstant AndAlso (TypeOf Expression.ConstantValue Is Char OrElse (TypeOf Expression.ConstantValue Is String AndAlso CStr(Expression.ConstantValue).Length = 1)) End Get End Property Public Overrides ReadOnly Property ConstantValue() As Object Get Dim tpCode As TypeCode Dim originalValue As Object originalValue = Expression.ConstantValue tpCode = Helper.GetTypeCode(Compiler, originalValue.GetType) Select Case tpCode Case TypeCode.String If CStr(originalValue).Length = 1 Then Return CChar(originalValue) Else Compiler.Report.ShowMessage(Messages.VBNC30060, originalValue.ToString, ExpressionType.ToString) Return New Char End If Case TypeCode.Char Return CChar(originalValue) Case Else Compiler.Report.ShowMessage(Messages.VBNC30060, originalValue.ToString, ExpressionType.ToString) Return New Char End Select End Get End Property Overrides ReadOnly Property ExpressionType() As Type Get Return Compiler.TypeCache.System_Char '_Descriptor End Get End PropertyEnd Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -