simplenameexpression.vb
来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 907 行 · 第 1/4 页
VB
907 行
' ' 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 EXTENDEDDEBUG = 0#End If''' <summary>''' A single identifier followed by an optional type argument list.''' Classifications: Variable, Type, Value, Namespace''' ''' SimpleNameExpression ::= Identifier [ "(" "Of" TypeArgumentList ")" ]''' </summary>''' <remarks></remarks>Public Class SimpleNameExpression Inherits Expression Private m_Identifier As Token Private m_TypeArgumentList As TypeArgumentList Sub New(ByVal Parent As ParsedObject) MyBase.New(Parent) End Sub Sub Init(ByVal Identifier As Token, ByVal TypeArgumentList As TypeArgumentList) m_Identifier = Identifier m_TypeArgumentList = TypeArgumentList End Sub Public Overrides ReadOnly Property AsString() As String Get If m_TypeArgumentList Is Nothing Then Return m_Identifier.Identifier Else Return m_Identifier.Identifier & "(Of <type arguments>)" End If End Get End Property Public Overrides Function Clone(Optional ByVal NewParent As ParsedObject = Nothing) As Expression If NewParent Is Nothing Then NewParent = Me.Parent Dim result As New SimpleNameExpression(NewParent) If m_TypeArgumentList Is Nothing Then result.Init(m_Identifier, Nothing) Else result.Init(m_Identifier, m_TypeArgumentList.Clone(result)) End If Return result End Function Property Identifier() As Token Get Return m_Identifier End Get Set(ByVal value As Token) m_Identifier = value End Set End Property Overrides ReadOnly Property ExpressionType() As Type Get Dim result As Type Select Case Classification.Classification Case ExpressionClassification.Classifications.Value result = Classification.AsValueClassification.Type Case ExpressionClassification.Classifications.Variable result = Classification.AsVariableClassification.Type Case ExpressionClassification.Classifications.Type Helper.NotImplemented() : result = Nothing Case ExpressionClassification.Classifications.Namespace Helper.NotImplemented() : result = Nothing Case ExpressionClassification.Classifications.PropertyGroup result = Classification.AsPropertyGroup.Type Case ExpressionClassification.Classifications.PropertyAccess result = Classification.AsPropertyAccess.Type Case ExpressionClassification.Classifications.MethodGroup result = Classification.AsMethodGroupClassification.Type Case Else Throw New InternalException(Me) End Select Helper.Assert(result IsNot Nothing) Return result End Get End Property Public Overrides Function ResolveTypeReferences() As Boolean Dim result As Boolean = True If m_TypeArgumentList IsNot Nothing Then result = m_TypeArgumentList.ResolveTypeReferences AndAlso result Return result End Function Public Overrides Function ToString() As String Return m_Identifier.Identifier End Function Protected Overrides Function GenerateCodeInternal(ByVal Info As EmitInfo) As Boolean Dim result As Boolean = True Helper.Assert(Info.DesiredType IsNot Nothing OrElse Info.RHSExpression IsNot Nothing) If Info.IsRHS Then If Info.DesiredType IsNot Nothing Then If Info.DesiredType.IsGenericParameter AndAlso Me.ExpressionType.IsGenericParameter Then Helper.Assert(Me.Classification.CanBeValueClassification) Dim tmp As Expression tmp = Me.ReclassifyToValueExpression() result = tmp.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result result = tmp.GenerateCode(Info) AndAlso result ElseIf Info.DesiredType.IsByRef = False AndAlso Me.ExpressionType.IsGenericParameter = False Then If Me.Classification.CanBeValueClassification Then Dim tmp As Expression tmp = Me.ReclassifyToValueExpression() result = tmp.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result result = tmp.Classification.GenerateCode(Info) AndAlso result Else Throw New InternalException(Me) End If Else If Me.Classification.IsVariableClassification Then If Me.ExpressionType.IsByRef Then Emitter.EmitLoadVariable(Info, Me.Classification.AsVariableClassification) Else Emitter.EmitLoadVariableLocation(Info, Me.Classification.AsVariableClassification) End If Else Throw New InternalException(Me) End If End If Else If Me.Classification.CanBeValueClassification Then Dim tmp As Expression tmp = Me.ReclassifyToValueExpression() result = tmp.ResolveExpression(ResolveInfo.Default(Info.Compiler)) AndAlso result result = tmp.GenerateCode(Info) AndAlso result Else Throw New InternalException(Me) End If End If ElseIf Info.IsLHS Then If Me.Classification.IsVariableClassification Then result = Me.Classification.AsVariableClassification.GenerateCode(Info) AndAlso result ElseIf Me.Classification.IsPropertyGroupClassification Then Helper.NotImplemented() ElseIf Me.Classification.IsValueClassification Then Throw New InternalException(Me) Else Throw New InternalException(Me) End If Else Throw New InternalException(Me) End If Return result End Function Public Overrides ReadOnly Property IsConstant() As Boolean Get Return Classification.IsConstant End Get End Property Public Overrides ReadOnly Property ConstantValue() As Object Get Return Classification.ConstantValue End Get End Property Shared Function IsMe(ByVal tm As tm) As Boolean Return tm.CurrentToken.IsIdentifier End Function Protected Overrides Function ResolveExpressionInternal(ByVal Info As ResolveInfo) As Boolean Dim Name As String = m_Identifier.Identifier If False Then Helper.Stop() End If '--------------------------------------------------------------------------------------------------------- 'A simple name expression consists of a single identifier followed by an optional type argument list. 'The name is resolved and classified as follows: '--------------------------------------------------------------------------------------------------------- '* Starting with the immediately enclosing block and continuing with each enclosing outer block (if any), ' if the identifier matches the name of a local variable, static variable, constant local, method type ' parameter, or parameter, then the identifier refers to the matching entity. The expression is ' classified as a variable if it is a local variable, static variable, or parameter. The expression ' is classified as a type if it is a method type parameter. The expression is classified as a value ' if it is a constant local with the following exception. If the local variable matched is the ' implicit function or Get accessor return local variable, and the expression is part of an ' invocation expression, invocation statement, or an AddressOf expression, then no match occurs and ' resolution continues. '--------------------------------------------------------------------------------------------------------- '* For each nested type containing the expression, starting from the innermost and going to the ' outermost, if a lookup of the identifier in the type produces a match with an accessible member: '** If the matching type member is a type parameter, then the result is classified as a type and ' is the matching type parameter. '** Otherwise, if the type is the immediately enclosing type and the lookup identifies a non-shared ' type member, then the result is the same as a member access of the form Me.E, where E is ' the identifier. '** Otherwise, the result is exactly the same as a member access of the form T.E, where T is the ' type containing the matching member and E is the identifier. In this case, it is an error for the ' identifier to refer to a non-shared member. '--------------------------------------------------------------------------------------------------------- '* For each nested namespace, starting from the innermost and going to the outermost namespace, ' do the following: '** If the namespace contains an accessible namespace member with the given name, then the identifier ' refers to that member and, depending on the member, is classified as a namespace or a type. '** Otherwise, if the namespace contains one or more accessible standard modules, and a member name ' lookup of the identifier produces an accessible match in exactly one standard module, then the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?