📄 expression.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' Imports System.ReflectionImports System.Reflection.Emit#If DEBUG Then#Const EXTENDEDDEBUG = 0#End If''' <summary>'''Expression ::=''' SimpleExpression |''' TypeExpression |''' MemberAccessExpression |''' DictionaryAccessExpression |''' IndexExpression |''' NewExpression |''' CastExpression |''' OperatorExpression''' '''SimpleExpression ::=''' LiteralExpression |''' ParenthesizedExpression |''' InstanceExpression |''' SimpleNameExpression |''' AddressOfExpression''' '''TypeExpression ::=''' GetTypeExpression |''' TypeOfIsExpression |''' IsExpression''' '''NewExpression ::=''' ObjectCreationExpression |''' ArrayCreationExpression |''' DelegateCreationExpression''' '''OperatorExpression ::=''' ArithmeticOperatorExpression |''' RelationalOperatorExpression |''' LikeOperatorExpression |''' ConcatenationOperatorExpression |''' ShortCircuitLogicalOperatorExpression |''' LogicalOperatorExpression |''' ShiftOperatorExpression''' '''ArithmeticOperatorExpression ::=''' UnaryPlusExpression |''' UnaryMinusExpression |''' AdditionOperatorExpression |''' SubtractionOperatorExpression |''' MultiplicationOperatorExpression |''' DivisionOperatorExpression |''' ModuloOperatorExpression |''' ExponentOperatorExpression''' </summary>''' <remarks></remarks>Public MustInherit Class Expression Inherits ParsedObject ''' <summary> ''' The classification of this expression ''' </summary> ''' <remarks></remarks> Private m_Classification As ExpressionClassification#If DEBUG Then ReadOnly Property Where() As String Get Return Location.ToString(Compiler) End Get End Property#End If ''' <summary> ''' First finds a code block, then finds the specified type in the code block. ''' </summary> ''' <typeparam name="T"></typeparam> ''' <returns></returns> ''' <remarks></remarks> Function FindFirstParentOfCodeBlock(Of T)() As T Dim cb As CodeBlock = Me.FindFirstParent(Of CodeBlock)() If cb IsNot Nothing Then Return cb.FindFirstParent(Of T)() Else Return Nothing End If End Function ''' <summary> ''' Get the parent code block. Might be nothing! ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Function FindParentCodeBlock() As CodeBlock If TypeOf Parent Is CodeBlock Then Return DirectCast(Parent, CodeBlock) Else If TypeOf Parent Is Expression Then Return DirectCast(Parent, Expression).FindParentCodeBlock ElseIf TypeOf Parent Is BlockStatement Then Return DirectCast(Parent, BlockStatement).CodeBlock ElseIf TypeOf Parent Is Statement Then Return DirectCast(Parent, Statement).FindParentCodeBlock Else Return Nothing End If End If End Function ''' <summary> ''' The classification of this expression ''' </summary> ''' <remarks></remarks> Property Classification() As ExpressionClassification Get Return m_Classification End Get Set(ByVal value As ExpressionClassification) m_Classification = value End Set End Property ''' <summary> ''' The type of the expression. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Overridable ReadOnly Property ExpressionType() As Type Get Helper.NotImplemented("Expression.ExpressionType (Type = " & Me.GetType.ToString & ")") Return Nothing End Get End Property Sub New(ByVal Parent As ParsedObject) MyBase.New(Parent) End Sub ''' <summary> ''' The default implementation returns false. ''' </summary> ''' <value></value> ''' <remarks></remarks> Overridable ReadOnly Property IsConstant() As Boolean Get Return False 'm_Classification.IsConstant End Get End Property ''' <summary> ''' The default implementation throws an internal exception. ''' </summary> ''' <value></value> ''' <remarks></remarks> Overridable ReadOnly Property ConstantValue() As Object Get Helper.Assert(m_Classification IsNot Nothing) Return m_Classification.ConstantValue End Get End Property Friend NotOverridable Overrides Function GenerateCode(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True If Me.IsConstant Then If Helper.CompareType(Me.ExpressionType, Compiler.TypeCache.Nothing) Then Emitter.EmitLoadValue(Info, Me.ConstantValue) ElseIf Info.DesiredType IsNot Nothing AndAlso Info.DesiredType.IsByRef Then Emitter.EmitLoadValueAddress(Info, Me.ConstantValue) Else Emitter.EmitLoadValue(Info.Clone(Me.ExpressionType), Me.ConstantValue) End If ElseIf TypeOf Me.Classification Is MethodGroupClassification Then result = Me.Classification.AsMethodGroupClassification.GenerateCode(Info) AndAlso result Else result = GenerateCodeInternal(Info) AndAlso result End If Return result End Function Protected Overridable Function GenerateCodeInternal(ByVal Info As EmitInfo) As Boolean Helper.NotImplemented() : Return False End Function#Region "Resolution region" ''' <summary> ''' Has this expression been resolved? ''' </summary> ''' <remarks></remarks> Private m_Resolved As Boolean ''' <summary> ''' Is this expression beeing resolved (in Resolve / DoResolve) ''' </summary> ''' <remarks></remarks> Private m_Resolving As Boolean Function ResolveExpression(ByVal ResolveInfo As ResolveInfo) As Boolean Dim result As Boolean = True Helper.Assert(ResolveInfo IsNot Nothing) StartResolve() result = ResolveExpressionInternal(ResolveInfo) AndAlso result#If EXTENDEDDEBUG Then Helper.Assert(result = False OrElse m_Classification IsNot Nothing, "Classification is nothing! (type of expression = " & Me.GetType.ToString & ")") Helper.Assert(ResolveInfo.CanFail OrElse result = (Compiler.Report.Errors = 0))#End If EndResolve(result) Return result End Function <Obsolete()> Function ResolveExpression() As Boolean Return ResolveExpression(ResolveInfo.Default(Parent.Compiler)) End Function ''' <summary> ''' Call StartResolve to enable check for recursive resolving. ''' Call EndResolve when finished resolving.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -