📄 methodgroupclassification.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' #If DEBUG Then#Const DEBUGMETHODRESOLUTION = 0#Const EXTENDEDDEBUG = 0#End IfImports System.Reflection''' <summary>''' A set of methods overloaded on the same name. ''' A method group may have an associated instance expression and''' an associated type argument list.''' ''' Can be reclassified as a value. The method group expression is ''' interpreted as an invocation expression with the associated type parameter ''' list and empty parenthesis (that is, "f" is interpreted as "f()" and "f(Of Integer)"''' is interpreted as "f(Of Integer)()". This reclassification may actually result in''' the expression being reclassified as void.''' </summary>''' <remarks></remarks>Public Class MethodGroupClassification Inherits ExpressionClassification ''' <summary> ''' The instance expression to the method. ''' </summary> ''' <remarks></remarks> Private m_InstanceExpression As Expression Private m_Parameters As Expression() Private m_TypeArguments As Type() ''' <summary> ''' The group of possible methods. ''' </summary> ''' <remarks></remarks> Private m_Group As Generic.List(Of MemberInfo) ''' <summary> ''' The type where the calling code is found. ''' </summary> ''' <remarks></remarks> Private m_CallingType As TypeDeclaration ''' <summary> ''' Has ResolveGroup been called? ''' </summary> ''' <remarks></remarks> Private m_Resolved As Boolean Private m_Resolver As MethodResolver#If DEBUG Then Private m_OriginalGroup As Generic.List(Of MemberInfo) Sub RevertResolveGroup() m_Group = New Generic.List(Of MemberInfo)(m_OriginalGroup) End Sub#End If <Diagnostics.Conditional("DEBUGMETHODRESOLUTION")> Sub LogResolutionMessage(ByVal msg As String) Compiler.Report.WriteLine(vbnc.Report.ReportLevels.Debug, msg) End Sub ReadOnly Property Parameters() As Expression() Get Return m_Parameters End Get End Property Public Overrides ReadOnly Property IsConstant() As Boolean Get Return False End Get End Property ''' <summary> ''' Has ResolveGroup been called? ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property Resolved() As Boolean Get Return m_Resolved End Get End Property Friend Overrides Function GenerateCode(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True Helper.Assert(m_Resolved) If Info.IsRHS Then result = GenerateCodeAsValue(Info) AndAlso result ElseIf Info.IsLHS Then Helper.NotImplemented() Else Throw New InternalException(Me) End If Return result End Function Function GenerateCodeAsValue(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True Helper.Assert(m_Resolved) 'If m_InstanceExpression IsNot Nothing Then ' Dim instanceExpType As Type ' If ResolvedMethod.DeclaringType.IsValueType Then ' instanceExpType = ResolvedMethod.DeclaringType.MakeByRefType ' Else ' instanceExpType = ResolvedMethod.DeclaringType ' End If ' result = m_InstanceExpression.GenerateCode(Info.Clone(True, False, instanceExpType)) AndAlso result ' 'Emitter.EmitConversion(instanceExpType, Info) 'End If 'Helper.Assert(Type IsNot Nothing) 'If m_Parameters IsNot Nothing Then ' Helper.Assert(ResolvedMethod.GetParameters.Length = m_Parameters.Length) ' Dim expInfo As EmitInfo ' For i As Integer = 0 To m_Parameters.GetUpperBound(0) ' expInfo = Info.Clone(True, False, ResolvedMethod.GetParameters(i).ParameterType) ' result = m_Parameters(i).GenerateCode(Info) AndAlso result ' Next 'Else ' Helper.Assert(ResolvedMethod.GetParameters.Length = 0) 'End If 'Emitter.EmitCallOrCallVirt(Info, ResolvedMethod) Helper.EmitArgumentsAndCallOrCallVirt(Info, m_InstanceExpression, New ArgumentList(Parent, m_Parameters), ResolvedMethod) Return result End Function ''' <summary> ''' Reclassifies the method group to a value, at the same time the method ''' group might be resolved using an empty argument list. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Overloads Function ReclassifyToValue() As ValueClassification Dim result As ValueClassification If m_Resolved = False Then Me.ResolveGroup(New ArgumentList(Me.Parent), Nothing) End If result = New ValueClassification(Me) Return result End Function ''' <summary> ''' The instance expression of the method group. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property InstanceExpression() As Expression Get Return m_InstanceExpression End Get End Property ''' <summary> ''' The type of the method group, is the return type of the method. ''' If this method is a sub, the return type is System.Void. ''' If this is a constructor, the return type is nothing. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property Type() As Type Get If SuccessfullyResolved = False Then Throw New InternalException(Me) Dim m As MethodInfo = ResolvedMethodInfo If m Is Nothing Then Dim c As ConstructorInfo = ResolvedConstructor If c Is Nothing Then Throw New InternalException(Me) Else Return Nothing End If Else If m.ReturnType Is Nothing Then Return Compiler.TypeCache.System_Void Else Return m.ReturnType End If End If End Get End Property ''' <summary> ''' Returns nothing if the resolved method isn't a methodinfo. ''' </summary> ''' <value></value> ''' <remarks></remarks> ReadOnly Property ResolvedMethodInfo() As MethodInfo Get If SuccessfullyResolved = False Then Throw New InternalException(Me) If TypeOf m_Group(0) Is MethodInfo Then Return DirectCast(m_Group(0), MethodInfo) Else Return Nothing End If End Get End Property ''' <summary> ''' Returns nothing if the resolved method isn't a constructorinfo. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> ReadOnly Property ResolvedConstructor() As ConstructorInfo Get If SuccessfullyResolved = False Then Throw New InternalException(Me) If TypeOf m_Group(0) Is ConstructorInfo Then Return DirectCast(m_Group(0), ConstructorInfo) Else Return Nothing End If End Get End Property ''' <summary> ''' Returns the resolved method.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -