invocationorindexexpression.vb
来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 549 行 · 第 1/2 页
VB
549 行
' ' 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' ''' <summary>''' InvocationExpression: Expression [ "(" [ ArgumentList ] ")" ]''' IndexExpression: Expression "(" [ ArgumentList ] ")"''' Note that for the index expression the parenthesis are not optional.''' This is reflected by the fact that m_ArgumentList is not nothing if ''' parenthesis are provided.''' Classifications: Value, Void (InvocationExpression) Value, Variable, PropertyAccess (IndexExpression)''' ''' If a parameter is a value parameter, the matching argument expression must be classified as a value. ''' The value is converted to the type of the parameter and passed in as the parameter at run time. ''' ''' If the parameter is a reference parameter and the matching argument expression is classified as a variable''' whose type is the same as the parameter, then a reference to the variable is passed in as the parameter at run time.''' Otherwise, if the matching argument expression is classified as a variable, value, or property access, ''' then a temporary variable of the type of the parameter is allocated. Before the method invocation at run time, ''' the argument expression is reclassified as a value, converted to the type of the parameter, ''' and assigned to the temporary variable. Then a reference to the temporary variable is passed in as the parameter. ''' After the method invocation is evaluated, if the argument expression is classified as a variable or property access, ''' the temporary variable is assigned to the variable expression or the property access expression. ''' If the property access expression has no Set accessor, then the assignment is not performed.''' </summary>''' <remarks></remarks>Public Class InvocationOrIndexExpression Inherits Expression Private m_Expression As Expression Private m_ArgumentList As ArgumentList Private m_ConstantValue As Object Private m_ExpressionType As Type ' AscW is replaced with the first parameter casted to Integer when: ' /novbruntimeref is used ' the called AscW is declared in the module being compiled ' the called AscW is Shared or is declared in a Module ' the first argument of the the called AscW is a ByVal Char Private m_AscWExpression As Expression ''' <summary> ''' If this method is not nothing then the arguments are emitted and then the method is called. ''' </summary> ''' <remarks></remarks> Private m_InvocationMethod As MethodInfo Sub New(ByVal Parent As ParsedObject) MyBase.New(Parent) End Sub Shadows Sub Init(ByVal Expression As Expression, ByVal ArgumentList As ArgumentList) m_Expression = Expression m_ArgumentList = ArgumentList End Sub Public Overrides ReadOnly Property IsConstant() As Boolean Get If m_ConstantValue IsNot Nothing Then Return True If m_AscWExpression IsNot Nothing Then If m_AscWExpression.IsConstant Then m_ConstantValue = Microsoft.VisualBasic.AscW(CChar(m_AscWExpression.ConstantValue)) Return True Else Return False End If End If If m_ArgumentList.Count <> 1 Then Return False If m_Expression.Classification.IsMethodGroupClassification Then Dim param As Object Dim mgc As MethodGroupClassification = m_Expression.Classification.AsMethodGroupClassification If mgc.IsLateBound Then Return False Dim mi As MethodInfo = mgc.ResolvedMethodInfo If mi Is Nothing Then Return False If Not (m_ArgumentList(0).Expression IsNot Nothing AndAlso m_ArgumentList(0).Expression.IsConstant) Then Return False param = m_ArgumentList(0).Expression.ConstantValue If Compiler.NameResolver.IsConstantMethod(mi, param, m_ConstantValue) = False Then Return False Return True Else Return False End If End Get End Property Public Overrides ReadOnly Property ConstantValue() As Object Get If Me.IsConstant Then 'Necessary, since the property loads the constant value if it is a constant. Return m_ConstantValue Else Throw New InternalException(Me) End If End Get End Property ReadOnly Property Expression() As Expression Get Return m_Expression End Get End Property Overrides ReadOnly Property ExpressionType() As Type Get Helper.Assert(m_ExpressionType IsNot Nothing) Return m_ExpressionType End Get End Property Protected Overrides Function GenerateCodeInternal(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True If m_AscWExpression IsNot Nothing Then result = m_AscWExpression.GenerateCode(Info.Clone(True, False, Compiler.TypeCache.System_Char)) AndAlso result Info.Stack.SwitchHead(Compiler.TypeCache.System_Char, Compiler.TypeCache.System_Int32) Return result End If If m_InvocationMethod IsNot Nothing Then result = Helper.EmitArgumentsAndCallOrCallVirt(Info, m_Expression, m_ArgumentList, m_InvocationMethod) AndAlso result Return True End If If Classification.IsLateBoundClassification Then result = LateBoundAccessToExpression.EmitLateCall(Info, Classification.AsLateBoundAccess) AndAlso result Else Select Case m_Expression.Classification.Classification Case ExpressionClassification.Classifications.MethodGroup With m_Expression.Classification.AsMethodGroupClassification result = Helper.EmitArgumentsAndCallOrCallVirt(Info, .InstanceExpression, m_ArgumentList, .ResolvedMethod) End With Case ExpressionClassification.Classifications.Value If Info.IsRHS Then If Me.Classification.IsVariableClassification Then result = Me.Classification.GenerateCode(Info) AndAlso result Else result = m_Expression.GenerateCode(Info) AndAlso result End If Else Helper.NotImplemented() End If Case ExpressionClassification.Classifications.PropertyAccess If Info.IsRHS Then If Me.Classification.IsVariableClassification Then result = Me.Classification.GenerateCode(Info) AndAlso result Else result = m_Expression.GenerateCode(Info) AndAlso result End If Else Helper.NotImplemented() End If Case ExpressionClassification.Classifications.PropertyGroup 'Helper.NotImplemented() Dim pgC As PropertyGroupClassification pgC = m_Expression.Classification.AsPropertyGroup result = pgC.GenerateCodeAsValue(Info) AndAlso result Case ExpressionClassification.Classifications.Variable If Info.IsRHS Then If Classification.IsValueClassification Then result = Classification.AsValueClassification.GenerateCode(Info) AndAlso result ElseIf Classification.IsPropertyGroupClassification Then result = Classification.AsPropertyGroup.GenerateCodeAsValue(Info) AndAlso result Else result = Classification.AsVariableClassification.GenerateCodeAsValue(Info) AndAlso result End If Else result = Classification.GenerateCode(Info) AndAlso result End If Case ExpressionClassification.Classifications.LateBoundAccess result = LateBoundAccessToExpression.EmitLateCall(Info, Classification.AsLateBoundAccess) AndAlso result Case Else Throw New InternalException(Me) End Select End If Return result End Function Shared Function IsBinaryMe(ByVal tm As tm) As Boolean Return tm.CurrentToken.Equals(KS.LParenthesis) End Function Shared Function CreateAndParseTo(ByRef result As Expression) As Boolean Helper.NotImplemented() End Function Public Overrides Function ResolveTypeReferences() As Boolean Dim result As Boolean = True result = m_Expression.ResolveTypeReferences AndAlso result If m_ArgumentList IsNot Nothing Then result = m_ArgumentList.ResolveTypeReferences AndAlso result Return result End Function Protected Overrides Function ResolveExpressionInternal(ByVal Info As ResolveInfo) As Boolean Dim result As Boolean = True result = m_Expression.ResolveExpression(New ResolveInfo(Info.Compiler, True, , False)) AndAlso result If result = False Then Return False If m_ArgumentList IsNot Nothing Then result = m_ArgumentList.ResolveCode(ResolveInfo.Default(Info.Compiler)) AndAlso result If result = False Then Return False 'Check the classification of the arguments, can be value, variable, propertyaccess For i As Integer = 0 To m_ArgumentList.Count - 1 If m_ArgumentList(i).Expression IsNot Nothing Then Select Case m_ArgumentList(i).Expression.Classification.Classification Case ExpressionClassification.Classifications.Value 'ok Case ExpressionClassification.Classifications.Variable 'ok Case ExpressionClassification.Classifications.PropertyAccess 'ok Case ExpressionClassification.Classifications.MethodPointer 'ok? Case ExpressionClassification.Classifications.PropertyGroup m_ArgumentList(i).Expression = m_ArgumentList(i).Expression.ReclassifyToPropertyAccessExpression result = m_ArgumentList(i).Expression.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result Case Else 'reclassify to value If m_ArgumentList(i).Expression.Classification.CanBeValueClassification Then m_ArgumentList(i).Expression = m_ArgumentList(i).Expression.ReclassifyToValueExpression result = m_ArgumentList(i).Expression.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result Else Helper.AddError() End If End Select End If Next If result = False Then Return result Select Case m_Expression.Classification.Classification Case ExpressionClassification.Classifications.LateBoundAccess Dim lae As LateBoundAccessClassification = m_Expression.Classification.AsLateBoundAccess lae.Arguments = m_ArgumentList Classification = lae Case ExpressionClassification.Classifications.MethodGroup 'This is an invocation expression. result = ResolveMethodInvocation() AndAlso result Case ExpressionClassification.Classifications.Value If m_Expression.ExpressionType.IsArray Then result = ResolveArrayInvocation(m_Expression.ExpressionType) AndAlso result Else result = ResolveIndexInvocation(Info.Compiler, m_Expression.ExpressionType) AndAlso result End If Case ExpressionClassification.Classifications.PropertyAccess If m_Expression.ExpressionType.IsArray Then result = ResolveArrayInvocation(m_Expression.ExpressionType) AndAlso result Else result = ResolveIndexInvocation(Info.Compiler, m_Expression.ExpressionType) AndAlso result End If Case ExpressionClassification.Classifications.PropertyGroup result = ResolvePropertyGroupInvocation() AndAlso result
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?