📄 variabledeclaration.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' ''' <summary>''' Represents one single variable of a VariableDeclarator.''' ''' VariableDeclarator ::=''' VariableIdentifiers [ As [ New ] TypeName [ ( ArgumentList ) ] ] |''' VariableIdentifier [ As TypeName ] [ = VariableInitializer ]''' </summary>''' <remarks></remarks>Public Class VariableDeclaration Inherits MemberDeclaration Implements IFieldMember, IHasImplicitMembers Private m_Descriptor As New FieldDescriptor(Me) Private m_VariableIdentifier As VariableIdentifier Private m_IsNew As Boolean Private m_NewExpression As DelegateOrObjectCreationExpression Private m_TypeName As TypeName Private m_VariableInitializer As VariableInitializer Private m_ArgumentList As ArgumentList Private m_Name As String Private m_FieldType As Type Private m_FieldBuilder As FieldBuilder Private m_StaticInitBuilder As FieldBuilder Private m_LocalBuilder As LocalBuilder Private m_WithEventsRedirect As PropertyDeclaration Private m_HandledEvents As New Generic.List(Of EventInfo) Sub New(ByVal Parent As TypeDeclaration) MyBase.New(Parent) End Sub Sub New(ByVal Parent As ParsedObject, ByVal Attributes As Attributes, ByVal Modifiers As Modifiers, ByVal VariableIdentifier As VariableIdentifier, _ ByVal IsNew As Boolean, ByVal TypeName As TypeName, ByVal VariableInitializer As VariableInitializer, ByVal ArgumentList As ArgumentList) MyBase.New(Parent) MyBase.Init(Attributes, Modifiers, VariableIdentifier.Name) m_VariableIdentifier = VariableIdentifier m_IsNew = IsNew m_TypeName = TypeName m_VariableInitializer = VariableInitializer m_ArgumentList = ArgumentList m_Name = m_VariableIdentifier.Name End Sub Sub New(ByVal Parent As ParsedObject, ByVal Attributes As Attributes, ByVal Modifiers As Modifiers, ByVal VariableIdentifier As Token, _ ByVal IsNew As Boolean, ByVal TypeName As TypeName, ByVal VariableInitializer As VariableInitializer, ByVal ArgumentList As ArgumentList) MyBase.New(Parent) MyBase.Init(Attributes, Modifiers, VariableIdentifier.Name) m_VariableIdentifier = New VariableIdentifier(Me, VariableIdentifier) m_IsNew = IsNew m_TypeName = TypeName m_VariableInitializer = VariableInitializer m_ArgumentList = ArgumentList m_Name = m_VariableIdentifier.Name End Sub Sub New(ByVal Parent As ParsedObject, ByVal Attributes As Attributes, ByVal Identifier As Token, _ ByVal IsNew As Boolean, ByVal TypeName As NonArrayTypeName, ByVal VariableInitializer As VariableInitializer, ByVal ArgumentList As ArgumentList) MyBase.New(Parent) MyBase.Init(Attributes, New Modifiers(), Identifier.Name) m_VariableIdentifier = New VariableIdentifier(Me, Identifier) m_IsNew = IsNew m_TypeName = New TypeName(Me, TypeName) m_VariableInitializer = VariableInitializer m_ArgumentList = ArgumentList m_Name = m_VariableIdentifier.Name End Sub Shadows Sub Init(ByVal Attributes As Attributes, ByVal Modifiers As Modifiers, ByVal Name As String, ByVal VariableType As Type) MyBase.Init(Attributes, Modifiers, Name) m_Name = Name m_FieldType = VariableType Helper.Assert(m_Name <> "") Helper.Assert(m_FieldType IsNot Nothing) End Sub Shadows Sub Init(ByVal Attributes As Attributes, ByVal Modifiers As Modifiers, ByVal Name As String, ByVal VariableType As TypeName) MyBase.Init(Attributes, Modifiers, Name) m_Name = Name m_TypeName = VariableType Helper.Assert(m_Name <> "") Helper.Assert(m_TypeName IsNot Nothing) End Sub ReadOnly Property DeclaringMethod() As MethodDeclaration Get Return Me.FindFirstParent(Of MethodDeclaration)() End Get End Property ReadOnly Property HasInitializer() As Boolean Get Return m_IsNew OrElse m_VariableInitializer IsNot Nothing OrElse (m_VariableIdentifier IsNot Nothing AndAlso m_VariableIdentifier.HasArrayNameModifier AndAlso m_VariableIdentifier.ArrayNameModifier.IsArraySizeInitializationModifier) End Get End Property ReadOnly Property LocalBuilder() As LocalBuilder Get Return m_LocalBuilder End Get End Property ReadOnly Property StaticInitBuilder() As FieldBuilder Get Return m_StaticInitBuilder End Get End Property ReadOnly Property FieldBuilder() As FieldBuilder Implements IFieldMember.FieldBuilder Get Return m_FieldBuilder End Get End Property ReadOnly Property VariableType() As Type Get Helper.Assert(m_FieldType IsNot Nothing) Return m_FieldType End Get End Property ReadOnly Property VariableTypeOrTypeBuilder() As Type Get Return Helper.GetTypeOrTypeBuilder(m_FieldType) End Get End Property ReadOnly Property IsLocalVariable() As Boolean Get Return Me.Modifiers.Is(ModifierMasks.Static) = False AndAlso Me.FindFirstParent(Of CodeBlock)() IsNot Nothing End Get End Property ReadOnly Property IsFieldVariable() As Boolean Get Return Not IsLocalVariable End Get End Property ReadOnly Property IsStaticVariable() As Boolean Get Return Me.Modifiers.Is(ModifierMasks.Static) End Get End Property Public Overrides ReadOnly Property MemberDescriptor() As System.Reflection.MemberInfo Get Return m_Descriptor End Get End Property Public ReadOnly Property FieldType() As System.Type Implements IFieldMember.FieldType Get Return m_FieldType End Get End Property ReadOnly Property TypeName() As TypeName Get Return m_TypeName End Get End Property ReadOnly Property IsNew() As Boolean Get Return m_IsNew End Get End Property ReadOnly Property VariableInitializer() As VariableInitializer Get Return m_VariableInitializer End Get End Property ReadOnly Property ArgumentList() As ArgumentList Get Return m_ArgumentList End Get End Property Public Overrides Function ResolveTypeReferences() As Boolean Dim result As Boolean = True result = MyBase.ResolveTypeReferences AndAlso result If result = False Then Return result If m_VariableInitializer IsNot Nothing Then result = m_VariableInitializer.ResolveTypeReferences() AndAlso result If m_TypeName IsNot Nothing Then result = m_TypeName.ResolveTypeReferences AndAlso result If result = False Then Return result If m_FieldType Is Nothing Then 'the declaration might have been created with the type already. If m_TypeName IsNot Nothing Then m_FieldType = m_TypeName.ResolvedType If m_IsNew Then If m_TypeName.IsNonArrayTypeName = False Then Helper.AddError() End If m_NewExpression = New DelegateOrObjectCreationExpression(Me, m_TypeName.AsNonArrayTypeName, m_ArgumentList) End If ElseIf m_VariableIdentifier.Identifier.HasTypeCharacter Then m_FieldType = TypeCharacters.TypeCharacterToType(Compiler, m_VariableIdentifier.Identifier.TypeCharacter) Else If Me.Location.File(Compiler).IsOptionStrictOn Then result = Compiler.Report.ShowMessage(Messages.VBNC30209, Me.Location) AndAlso result Else Helper.AddWarning("Variable type should be specified.") End If m_FieldType = Compiler.TypeCache.System_Object End If End If If m_NewExpression IsNot Nothing Then result = m_NewExpression.ResolveTypeReferences AndAlso result Helper.Assert(m_FieldType IsNot Nothing) Return result End Function Function ResolveMember(ByVal Info As ResolveInfo) As Boolean Implements INonTypeMember.ResolveMember Dim result As Boolean = True
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -