parser(members2).vb

来自「大名鼎鼎的mono是.NET平台的跨平台(支持linux」· VB 代码 · 共 834 行 · 第 1/3 页

VB
834
字号
' ' 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' Partial Class Parser    ''' <summary>    ''' ConstantMemberDeclaration  ::=	[  Attributes  ]  [  ConstantModifier+  ]  "Const"  ConstantDeclarators  StatementTerminator    ''' </summary>    ''' <remarks>    ''' </remarks>    Private Function ParseConstantMemberDeclarations(ByVal Parent As ParsedObject, ByVal Info As ParseAttributableInfo) As Generic.List(Of ConstantDeclaration)        Dim result As New Generic.List(Of ConstantDeclaration)        Dim m_Modifiers As Modifiers        m_Modifiers = ParseModifiers(Parent, ModifierMasks.ConstantModifiers)        tm.AcceptIfNotInternalError(KS.Const)        m_Modifiers.AddModifiers(ModifierMasks.Const)        result = ParseConstantDeclarations(Parent, Info.Attributes, m_Modifiers)        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        Return result    End Function    Private Function ParseConstantDeclarations(ByVal Parent As ParsedObject, ByVal Attributes As Attributes, ByVal Modifiers As Modifiers) As Generic.List(Of ConstantDeclaration)        Dim result As New Generic.List(Of ConstantDeclaration)        Do            Dim newCD As ConstantDeclaration = Nothing            newCD = ParseConstantDeclaration(Parent, New ParseAttributableInfo(Parent.Compiler, Attributes), Modifiers)            If newCD Is Nothing Then Helper.ErrorRecoveryNotImplemented()            result.Add(newCD)        Loop While tm.Accept(KS.Comma)        Return result    End Function    ''' <summary>    ''' MustOverridePropertyMemberDeclaration  ::=    '''	[  Attributes  ]  [  MustOverridePropertyModifier+  ]  "Property" FunctionSignature  [  ImplementsClause  ]    '''		StatementTerminator    ''' </summary>    ''' <remarks></remarks>    Private Function ParseMustOverridePropertyMemberDeclaration(ByVal Parent As TypeDeclaration, ByVal Info As ParseAttributableInfo) As MustOverridePropertyDeclaration        Dim result As New MustOverridePropertyDeclaration(Parent)        Dim m_Modifiers As Modifiers = Nothing        Dim m_Signature As FunctionSignature = Nothing        Dim m_ImplementsClause As MemberImplementsClause = Nothing        m_Modifiers = ParseModifiers(result, ModifierMasks.MustOverridePropertyModifiers)        tm.AcceptIfNotInternalError(KS.Property)        m_Signature = ParseFunctionSignature(result)        If m_Signature Is Nothing Then Helper.ErrorRecoveryNotImplemented()        If MemberImplementsClause.IsMe(tm) Then            m_ImplementsClause = ParseImplementsClause(result)            If m_ImplementsClause Is Nothing Then Helper.ErrorRecoveryNotImplemented()        End If        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(Info.Attributes, m_Modifiers, m_Signature, m_ImplementsClause)        Return result    End Function    ''' <summary>    ''' ConversionOperatorDeclaration    ::=    '''	[  Attributes  ]  [  ConversionOperatorModifier+  ]  "Operator" "CType" "("  Operand  ")"    '''		[  "As"  [  Attributes  ]  TypeName  ]  LineTerminator    '''	[  Block  ]    '''	"End" "Operator" StatementTerminator    ''' </summary>    ''' <remarks></remarks>    Private Function ParseConversionOperatorDeclaration(ByVal Parent As TypeDeclaration, ByVal Info As ParseAttributableInfo) As ConversionOperatorDeclaration        Dim result As New ConversionOperatorDeclaration(Parent)        Dim m_Modifiers As Modifiers = Nothing        Dim m_Operator As Token = Nothing        Dim m_Operand As Operand = Nothing        Dim m_ReturnTypeAttributes As Attributes = Nothing        Dim m_TypeName As TypeName = Nothing        Dim m_Block As CodeBlock = Nothing        m_Modifiers = ParseModifiers(result, ModifierMasks.ConversionOperatorModifiers)        tm.AcceptIfNotInternalError(KS.Operator)        If vbnc.ConversionOperatorDeclaration.IsOverloadableConversionOperator(tm.CurrentToken) Then            m_Operator = tm.CurrentToken : tm.NextToken()        Else            Throw New InternalException(result)        End If        If tm.AcceptIfNotError(KS.LParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        m_Operand = ParseOperand(result)        If m_Operand Is Nothing Then Helper.ErrorRecoveryNotImplemented()        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.Accept(KS.As) Then            If vbnc.Attributes.IsMe(tm) Then                If ParseAttributes(result, m_ReturnTypeAttributes) = False Then Helper.ErrorRecoveryNotImplemented()            End If            m_TypeName = ParseTypeName(result)            If m_TypeName Is Nothing Then Helper.ErrorRecoveryNotImplemented()        End If        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        m_Block = ParseCodeBlock(result, False)        If m_Block Is Nothing Then Helper.ErrorRecoveryNotImplemented()        If tm.AcceptIfNotError(KS.End_Operator) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(Info.Attributes, m_Modifiers, m_Operator, m_Operand, m_ReturnTypeAttributes, m_TypeName, m_Block)        Return result    End Function    ''' <summary>    ''' EnumMemberDeclaration  ::=  [  Attributes  ]  Identifier  [  "="  ConstantExpression  ]  StatementTerminator    ''' </summary>    ''' <remarks></remarks>    Private Function ParseEnumMemberDeclaration(ByVal Parent As ParsedObject, ByVal Info As ParseAttributableInfo, ByVal EnumIndex As Integer) As EnumMemberDeclaration        Dim result As New EnumMemberDeclaration(Parent)        Dim m_Identifier As Token = Nothing        Dim m_ConstantExpression As Expression        If tm.AcceptIdentifier(m_Identifier) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.Accept(KS.Equals) Then            m_ConstantExpression = ParseExpression(result)            If m_ConstantExpression Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            m_ConstantExpression = Nothing        End If        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(EnumIndex, Info.Attributes, m_Identifier, m_ConstantExpression)        Return result    End Function    ''' <summary>    ''' Operand  ::=  [  "ByVal"  ]  Identifier  [  "As"  TypeName  ]    ''' </summary>    ''' <remarks></remarks>    Private Function ParseOperand(ByVal Parent As ParsedObject) As Operand        Dim result As New Operand(Parent)        Dim m_Identifier As Token = Nothing        Dim m_TypeName As TypeName        tm.Accept(KS.ByVal)        If tm.AcceptIdentifier(m_Identifier) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.Accept(KS.As) Then            m_TypeName = ParseTypeName(result)            If m_TypeName Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            m_TypeName = Nothing        End If        result.Init(m_Identifier, m_TypeName)        Return result    End Function    ''' <summary>    ''' BinaryOperatorDeclaration  ::=    '''	[  Attributes  ]  [  OperatorModifier+  ]  "Operator"  OverloadableBinaryOperator    '''		"("  Operand  ","  Operand  ")"  [ "As"  [  Attributes  ]  TypeName  ]  LineTerminator    '''	[  Block  ]    '''	"End" "Operator" StatementTerminator    '''     ''' UnaryOperatorDeclaration  ::=    '''	[  Attributes  ]  [  OperatorModifier+  ]  "Operator" OverloadableUnaryOperator     '''     "("  Operand  ")" 		[  "As" [  Attributes  ]  TypeName  ]  LineTerminator    '''	[  Block  ]    '''	"End" "Operator" StatementTerminator    ''' OverloadableUnaryOperator  ::=  "+"  | "-"  |  "Not"  |  "IsTrue"  |  "IsFalse"    ''' </summary>    ''' <remarks></remarks>    Private Function ParseOperatorDeclaration(ByVal Parent As TypeDeclaration, ByVal Info As ParseAttributableInfo) As OperatorDeclaration        Dim result As New OperatorDeclaration(Parent)        Dim m_Modifiers As Modifiers        Dim m_Operator As Token        Dim m_Operand1 As Operand        Dim m_Operand2 As Operand        Dim m_TypeName As TypeName        Dim m_ReturnTypeAttributes As New Attributes(Parent)        Dim m_Block As CodeBlock        m_Modifiers = ParseModifiers(result, ModifierMasks.OperatorModifiers)        tm.AcceptIfNotInternalError(KS.Operator)        If vbnc.OperatorDeclaration.IsOverloadableOperator(tm.CurrentToken) Then            m_Operator = tm.CurrentToken : tm.NextToken()        Else            Throw New InternalException(result)        End If        If tm.AcceptIfNotError(KS.LParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        m_Operand1 = ParseOperand(result)        If m_Operand1 Is Nothing Then Helper.ErrorRecoveryNotImplemented()        If tm.Accept(KS.Comma) Then            m_Operand2 = ParseOperand(result)            If m_Operand2 Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            m_Operand2 = Nothing        End If        If tm.AcceptIfNotError(KS.RParenthesis) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.Accept(KS.As) Then            If vbnc.Attributes.IsMe(tm) Then                If ParseAttributes(result, m_ReturnTypeAttributes) = False Then Helper.ErrorRecoveryNotImplemented()            End If            m_TypeName = ParseTypeName(result)            If m_TypeName Is Nothing Then Helper.ErrorRecoveryNotImplemented()        Else            m_TypeName = Nothing        End If        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        m_Block = ParseCodeBlock(result, False)        If m_Block Is Nothing Then Helper.ErrorRecoveryNotImplemented()        If tm.AcceptIfNotError(KS.End_Operator) = False Then Helper.ErrorRecoveryNotImplemented()        If tm.AcceptEndOfStatement(, True) = False Then Helper.ErrorRecoveryNotImplemented()        result.Init(Info.Attributes, m_Modifiers, m_Operator, m_Operand1, m_Operand2, m_ReturnTypeAttributes, m_TypeName, m_Block)        Return result    End Function    ''' <summary>    ''' FunctionDeclaration  ::=    '''	[  Attributes  ]  [  ProcedureModifier+  ]  "Function" FunctionSignature  [  HandlesOrImplements  ]    '''		LineTerminator    '''	Block    '''	"End" "Function" StatementTerminator    ''' 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?