diff --git a/src/Compilers/VisualBasic/Portable/Analysis/MissingRuntimeMemberDiagnosticHelper.vb b/src/Compilers/VisualBasic/Portable/Analysis/MissingRuntimeMemberDiagnosticHelper.vb
index 3c4bf0d54ae8a..fba454ec8058c 100644
--- a/src/Compilers/VisualBasic/Portable/Analysis/MissingRuntimeMemberDiagnosticHelper.vb
+++ b/src/Compilers/VisualBasic/Portable/Analysis/MissingRuntimeMemberDiagnosticHelper.vb
@@ -10,13 +10,14 @@ Namespace Microsoft.CodeAnalysis
' Details on these types and the feature name which is displayed in the diagnostic
' for those items missing in VB Core compilation.
- Private ReadOnly metadataNames As New Dictionary(Of String, String) From {
- {"Microsoft.VisualBasic.CompilerServices.Operators", "Late binding"},
- {"Microsoft.VisualBasic.CompilerServices.NewLateBinding", "Late binding"},
- {"Microsoft.VisualBasic.CompilerServices.LikeOperator", "Like operator"},
- {"Microsoft.VisualBasic.CompilerServices.ProjectData", "Unstructured exception handling"},
- {"Microsoft.VisualBasic.CompilerServices.ProjectData.CreateProjectError", "Unstructured exception handling"}
- }
+ Private ReadOnly metadataNames As New Dictionary(Of String, String) From
+ {
+ {"Microsoft.VisualBasic.CompilerServices.Operators", "Late binding"},
+ {"Microsoft.VisualBasic.CompilerServices.NewLateBinding", "Late binding"},
+ {"Microsoft.VisualBasic.CompilerServices.LikeOperator", "Like operator"},
+ {"Microsoft.VisualBasic.CompilerServices.ProjectData", "Unstructured exception handling"},
+ {"Microsoft.VisualBasic.CompilerServices.ProjectData.CreateProjectError", "Unstructured exception handling"}
+ }
Friend Function GetDiagnosticForMissingRuntimeHelper(typename As String, membername As String, embedVBCoreRuntime As Boolean) As DiagnosticInfo
Dim diag As DiagnosticInfo
diff --git a/src/Compilers/VisualBasic/Portable/BasicCodeAnalysis.vbproj b/src/Compilers/VisualBasic/Portable/BasicCodeAnalysis.vbproj
index 140c0a5f3eb6e..bfcd4f810b834 100644
--- a/src/Compilers/VisualBasic/Portable/BasicCodeAnalysis.vbproj
+++ b/src/Compilers/VisualBasic/Portable/BasicCodeAnalysis.vbproj
@@ -945,6 +945,7 @@
+
diff --git a/src/Compilers/VisualBasic/Portable/Parser/ParseReportError.vb b/src/Compilers/VisualBasic/Portable/Parser/ParseReportError.vb
index d800f0f70d16f..d1b52c8795e21 100644
--- a/src/Compilers/VisualBasic/Portable/Parser/ParseReportError.vb
+++ b/src/Compilers/VisualBasic/Portable/Parser/ParseReportError.vb
@@ -113,14 +113,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function ReportModifiersOnStatementError(errorId As ERRID, attributes As SyntaxList(Of AttributeListSyntax), modifiers As SyntaxList(Of KeywordSyntax), keyword As KeywordSyntax) As KeywordSyntax
- If modifiers.Any Then
- keyword = keyword.AddLeadingSyntax(modifiers.Node, errorId)
- End If
-
- If attributes.Any Then
- keyword = keyword.AddLeadingSyntax(attributes.Node, errorId)
- End If
-
+ If modifiers.Any Then keyword = keyword.AddLeadingSyntax(modifiers.Node, errorId)
+ If attributes.Any Then keyword = keyword.AddLeadingSyntax(attributes.Node, errorId)
Return keyword
End Function
@@ -142,12 +136,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' // A FEATUREID_* constant defined in errors.inc
' // the string for the version that /LangVersion is targeting
' .Parser::ReportSyntaxErrorForLanguageFeature( [ unsigned Errid ] [ _In_ Token* Start ] [ unsigned Feature ] [ _In_opt_z_ const WCHAR* wszVersion ] )
- Private Sub ReportSyntaxErrorForLanguageFeature(
- Errid As ERRID,
- Start As SyntaxToken,
- Feature As UInteger,
- wszVersion As String
- )
+ Private Sub ReportSyntaxErrorForLanguageFeature( Errid As ERRID, Start As SyntaxToken, Feature As UInteger, wszVersion As String)
#If UNDONE Then 'davidsch
m_ErrorCount += 1
diff --git a/src/Compilers/VisualBasic/Portable/Parser/ParseScan.vb b/src/Compilers/VisualBasic/Portable/Parser/ParseScan.vb
index 51e476daf0621..13c25c9095f51 100644
--- a/src/Compilers/VisualBasic/Portable/Parser/ParseScan.vb
+++ b/src/Compilers/VisualBasic/Portable/Parser/ParseScan.vb
@@ -21,13 +21,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' The scanner scans the fist token of a statement differently with regard to trivia. It we peek past the EOL and then get the token.
' The token may not have the correct trivia attached to it when we get it. The solution is to attach the state to the token so we
' know if we peeked the token in the first token of new statement state or the next token of a statement state.
-
- If PeekToken(i).Kind = SyntaxKind.StatementTerminatorToken Then
- If PeekToken(i + 1).Kind <> SyntaxKind.EmptyToken Then
- Return True
- End If
- End If
- Return False
+ Return (PeekToken(i).Kind = SyntaxKind.StatementTerminatorToken) AndAlso (PeekToken(i + 1).Kind <> SyntaxKind.EmptyToken)
End Function
'TODO - This is really peekToken skipping optional statementterminator
@@ -128,38 +122,31 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
'Parser::BeginsGeneric // A generic is signified by '(' [tkStatementTerminator] tkOF
Private Function BeginsGeneric(Optional nonArrayName As Boolean = False, Optional allowGenericsWithoutOf As Boolean = False) As Boolean
-
- If CurrentToken.Kind = SyntaxKind.OpenParenToken Then
-
- If nonArrayName Then
- Return True
- End If
-
- Dim t = PeekPastStatementTerminator()
-
- If t.Kind = SyntaxKind.OfKeyword Then
- Return True
- ElseIf allowGenericsWithoutOf Then
- ' // To enable a better user experience in some common generics'
- ' // error scenarios, we special case foo(Integer) and
- ' // foo(Integer, garbage).
- ' //
- ' // "(Integer" indicates possibly type parameters with missing "of",
- ' // but not "(Integer." and "Integer!" because they could possibly
- ' // imply qualified names or expressions. Also note that "Integer :="
- ' // could imply named arguments. Here "Integer" is just an example,
- ' // it could be any intrinsic type.
- ' //
- If SyntaxFacts.IsPredefinedTypeOrVariant(t.Kind) Then
- Select Case PeekToken(2).Kind
- Case SyntaxKind.CloseParenToken, SyntaxKind.CommaToken
- Return True
- End Select
- End If
+ If CurrentToken.Kind <> SyntaxKind.OpenParenToken Then Return False
+ If nonArrayName Then Return True
+ Dim t = PeekPastStatementTerminator()
+
+ If t.Kind = SyntaxKind.OfKeyword Then Return True
+ If allowGenericsWithoutOf Then
+ ' // To enable a better user experience in some common generics'
+ ' // error scenarios, we special case foo(Integer) and
+ ' // foo(Integer, garbage).
+ ' //
+ ' // "(Integer" indicates possibly type parameters with missing "of",
+ ' // but not "(Integer." and "Integer!" because they could possibly
+ ' // imply qualified names or expressions. Also note that "Integer :="
+ ' // could imply named arguments. Here "Integer" is just an example,
+ ' // it could be any intrinsic type.
+ ' //
+ If SyntaxFacts.IsPredefinedTypeOrVariant(t.Kind) Then
+ Select Case PeekToken(2).Kind
+ Case SyntaxKind.CloseParenToken, SyntaxKind.CommaToken
+ Return True
+ End Select
End If
-
End If
+
Return False
End Function
@@ -259,9 +246,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Exit While
End If
- If IsTokenOrKeyword(CurrentToken, resyncTokens) Then
- Exit While
- End If
+ If IsTokenOrKeyword(CurrentToken, resyncTokens) Then Exit While
+
skippedTokens.Add(CurrentToken)
GetNextToken(state)
@@ -285,18 +271,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ResyncAndConsumeStatementTerminator() As SyntaxList(Of SyntaxToken)
Dim skippedTokens = Me._pool.Allocate(Of SyntaxToken)()
- While CurrentToken.Kind <> SyntaxKind.EndOfFileToken AndAlso
- CurrentToken.Kind <> SyntaxKind.StatementTerminatorToken
+ While (CurrentToken.Kind <> SyntaxKind.EndOfFileToken) AndAlso (CurrentToken.Kind <> SyntaxKind.StatementTerminatorToken)
skippedTokens.Add(CurrentToken)
GetNextToken(ScannerState.VB)
End While
If CurrentToken.Kind = SyntaxKind.StatementTerminatorToken Then
- If CurrentToken.HasLeadingTrivia Then
- skippedTokens.Add(CurrentToken)
- End If
-
+ If CurrentToken.HasLeadingTrivia Then skippedTokens.Add(CurrentToken)
GetNextToken(ScannerState.VB)
End If
@@ -368,10 +350,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function TryEatNewLineIfFollowedBy(kind As SyntaxKind) As Boolean
Debug.Assert(CanUseInTryGetToken(kind))
- If NextLineStartsWith(kind) Then
- 'Add trivia to the token that has been peeked on next line
- Return TryEatNewLine()
- End If
+ If NextLineStartsWith(kind) Then Return TryEatNewLine() 'Add trivia to the token that has been peeked on next line
+
Return False
End Function
@@ -387,9 +367,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function TryEatNewLineIfNotFollowedBy(kind As SyntaxKind) As Boolean
Debug.Assert(CanUseInTryGetToken(kind))
- If Not NextLineStartsWith(kind) Then
- Return TryEatNewLine()
- End If
+ If Not NextLineStartsWith(kind) Then Return TryEatNewLine()
Return False
End Function
@@ -408,10 +386,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If CurrentToken.IsEndOfLine Then
Dim nextToken = PeekToken(1)
- If nextToken.Kind = kind Then
- Return True
+ If nextToken.Kind = kind Then Return True
- ElseIf nextToken.Kind = SyntaxKind.IdentifierToken Then
+ if nextToken.Kind = SyntaxKind.IdentifierToken Then
Dim contextualKind As SyntaxKind = Nothing
If TryIdentifierAsContextualKeyword(nextToken, contextualKind) AndAlso contextualKind = kind Then
Return True
diff --git a/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb b/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb
index d88b99da430fa..a4dd757fb82ea 100644
--- a/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb
+++ b/src/Compilers/VisualBasic/Portable/Parser/ParserFeature.vb
@@ -51,30 +51,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Friend Function GetResourceId(feature As Feature) As ERRID
Select Case feature
- Case Feature.AutoProperties
- Return ERRID.FEATURE_AutoProperties
- Case Feature.LineContinuation
- Return ERRID.FEATURE_LineContinuation
- Case Feature.StatementLambdas
- Return ERRID.FEATURE_StatementLambdas
- Case Feature.CoContraVariance
- Return ERRID.FEATURE_CoContraVariance
- Case Feature.CollectionInitializers
- Return ERRID.FEATURE_CollectionInitializers
- Case Feature.SubLambdas
- Return ERRID.FEATURE_SubLambdas
- Case Feature.ArrayLiterals
- Return ERRID.FEATURE_ArrayLiterals
- Case Feature.AsyncExpressions
- Return ERRID.FEATURE_AsyncExpressions
- Case Feature.Iterators
- Return ERRID.FEATURE_Iterators
- Case Feature.GlobalNamespace
- Return ERRID.FEATURE_GlobalNamespace
- Case Feature.NullPropagatingOperator
- Return ERRID.FEATURE_NullPropagatingOperator
- Case Feature.NameOfExpressions
- Return ERRID.FEATURE_NameOfExpressions
+ Case Feature.AutoProperties : Return ERRID.FEATURE_AutoProperties
+ Case Feature.LineContinuation : Return ERRID.FEATURE_LineContinuation
+ Case Feature.StatementLambdas : Return ERRID.FEATURE_StatementLambdas
+ Case Feature.CoContraVariance : Return ERRID.FEATURE_CoContraVariance
+ Case Feature.CollectionInitializers : Return ERRID.FEATURE_CollectionInitializers
+ Case Feature.SubLambdas : Return ERRID.FEATURE_SubLambdas
+ Case Feature.ArrayLiterals : Return ERRID.FEATURE_ArrayLiterals
+ Case Feature.AsyncExpressions : Return ERRID.FEATURE_AsyncExpressions
+ Case Feature.Iterators : Return ERRID.FEATURE_Iterators
+ Case Feature.GlobalNamespace : Return ERRID.FEATURE_GlobalNamespace
+ Case Feature.NullPropagatingOperator : Return ERRID.FEATURE_NullPropagatingOperator
+ Case Feature.NameOfExpressions : Return ERRID.FEATURE_NameOfExpressions
Case Else
Throw ExceptionUtilities.UnexpectedValue(feature)
End Select
diff --git a/src/Compilers/VisualBasic/Portable/PredefinedPreprocessorSymbols.vb b/src/Compilers/VisualBasic/Portable/PredefinedPreprocessorSymbols.vb
index 849b13b9db6de..859c73e8b6a56 100644
--- a/src/Compilers/VisualBasic/Portable/PredefinedPreprocessorSymbols.vb
+++ b/src/Compilers/VisualBasic/Portable/PredefinedPreprocessorSymbols.vb
@@ -37,16 +37,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' An ImmutableArray of KeyValue pairs representing existing symbols.
''' Array of symbols that include VBC_VER and TARGET.
Public Function AddPredefinedPreprocessorSymbols(kind As OutputKind, symbols As ImmutableArray(Of KeyValuePair(Of String, Object))) As ImmutableArray(Of KeyValuePair(Of String, Object))
- If Not kind.IsValid Then
- Throw New ArgumentOutOfRangeException("kind")
- End If
+ If Not kind.IsValid Then Throw New ArgumentOutOfRangeException("kind")
Const CompilerVersionSymbol = "VBC_VER"
Const TargetSymbol = "TARGET"
- If symbols.IsDefault Then
- symbols = ImmutableArray(Of KeyValuePair(Of String, Object)).Empty
- End If
+ If symbols.IsDefault Then symbols = ImmutableArray(Of KeyValuePair(Of String, Object)).Empty
If symbols.FirstOrDefault(Function(entry) IdentifierComparison.Equals(entry.Key, CompilerVersionSymbol)).Key Is Nothing Then
' This number should always line up with the current version of the compilerString
@@ -62,24 +58,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Function GetTargetString(kind As OutputKind) As String
Select Case kind
- Case OutputKind.ConsoleApplication
- Return "exe"
-
- Case OutputKind.DynamicallyLinkedLibrary
- Return "library"
-
- Case OutputKind.NetModule
- Return "module"
-
- Case OutputKind.WindowsApplication
- Return "winexe"
-
- Case OutputKind.WindowsRuntimeApplication
- Return "appcontainerexe"
-
- Case OutputKind.WindowsRuntimeMetadata
- Return "winmdobj"
-
+ Case OutputKind.ConsoleApplication : Return "exe"
+ Case OutputKind.DynamicallyLinkedLibrary : Return "library"
+ Case OutputKind.NetModule : Return "module"
+ Case OutputKind.WindowsApplication : Return "winexe"
+ Case OutputKind.WindowsRuntimeApplication : Return "appcontainerexe"
+ Case OutputKind.WindowsRuntimeMetadata : Return "winmdobj"
Case Else
Throw ExceptionUtilities.UnexpectedValue(kind)
End Select
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/Blender.vb b/src/Compilers/VisualBasic/Portable/Scanner/Blender.vb
index e01a47a99bf26..a9424d71518de 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/Blender.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/Blender.vb
@@ -62,18 +62,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Shared Sub PushReverseTerminal(stack As Stack(Of GreenNode), tk As SyntaxToken)
Dim trivia = tk.GetTrailingTrivia
-
- If trivia IsNot Nothing Then
- PushChildReverse(stack, trivia)
- End If
-
+ If trivia IsNot Nothing Then PushChildReverse(stack, trivia)
PushChildReverse(stack, DirectCast(tk.WithLeadingTrivia(Nothing).WithTrailingTrivia(Nothing), SyntaxToken))
-
trivia = tk.GetLeadingTrivia
-
- If trivia IsNot Nothing Then
- PushChildReverse(stack, trivia)
- End If
+ If trivia IsNot Nothing Then PushChildReverse(stack, trivia)
End Sub
Private Shared Sub PushChildReverse(stack As Stack(Of GreenNode), child As GreenNode)
@@ -94,22 +86,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim fullSpan = New TextSpan(0, root.FullWidth)
Dim start = NearestStatementThatContainsPosition(root, span.Start, fullSpan)
Debug.Assert(start.Start <= span.Start)
- If span.Length = 0 Then
- Return start
- Else
- Dim [end] = NearestStatementThatContainsPosition(root, span.End - 1, fullSpan)
- Debug.Assert([end].End >= span.End)
- Return TextSpan.FromBounds(start.Start, [end].End)
- End If
+ If span.Length = 0 Then Return start
+ Dim [end] = NearestStatementThatContainsPosition(root, span.End - 1, fullSpan)
+ Debug.Assert([end].End >= span.End)
+ Return TextSpan.FromBounds(start.Start, [end].End)
End Function
'''
''' Not guaranteed to return the span of a StatementSyntax.
'''
- Private Shared Function NearestStatementThatContainsPosition(
- node As SyntaxNode,
- position As Integer,
- rootFullSpan As TextSpan) As TextSpan
+ Private Shared Function NearestStatementThatContainsPosition( node As SyntaxNode, position As Integer, rootFullSpan As TextSpan) As TextSpan
If Not node.FullSpan.Contains(position) Then
Debug.Assert(node.FullSpan.End = position)
@@ -119,9 +105,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If node.Kind = SyntaxKind.CompilationUnit OrElse IsStatementLike(node) Then
Do
Dim child = node.ChildThatContainsPosition(position).AsNode()
- If child Is Nothing OrElse Not IsStatementLike(child) Then
- Return node.FullSpan
- End If
+ If child Is Nothing OrElse Not IsStatementLike(child) Then Return node.FullSpan
node = child
Loop
End If
@@ -161,31 +145,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' Move to the left by the look ahead required by the Scanner.
For i As Integer = 0 To Scanner.MaxTokensLookAheadBeyondEOL
Dim node = root.FindTokenInternal(start)
- If node.Kind = SyntaxKind.None Then
- Exit For
- Else
- start = node.Position
- If start = 0 Then
- Exit For
- Else
- start -= 1
- End If
- End If
+ If node.Kind = SyntaxKind.None Then Exit For
+ start = node.Position
+ If start = 0 Then Exit For
+ start -= 1
Next
End If
' Allow for look behind of some number of characters.
- If [end] < fullWidth Then
- [end] += Scanner.MaxCharsLookBehind
- End If
-
+ If [end] < fullWidth Then [end] += Scanner.MaxCharsLookBehind
+
Return TextSpan.FromBounds(start, [end])
End Function
- Friend Sub New(newText As SourceText,
- changes As TextChangeRange(),
- baseTreeRoot As SyntaxTree,
- options As VisualBasicParseOptions)
+ Friend Sub New(newText As SourceText, changes As TextChangeRange(), baseTreeRoot As SyntaxTree, options As VisualBasicParseOptions)
MyBase.New(newText, options)
@@ -200,9 +173,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
TryCrumbleOnce()
- If _currentNode Is Nothing Then
- Return ' tree seems to be empty
- End If
+ If _currentNode Is Nothing Then Return ' tree seems to be empty
_change = TextChangeRange.Collapse(changes)
@@ -217,21 +188,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' Parser requires look ahead of some number of tokens
' beyond EOL and some number of characters back.
' Expand the change range to accomodate look ahead/behind.
- Dim span = ExpandToNearestStatements(
- _baseTreeRoot,
- ExpandByLookAheadAndBehind(_baseTreeRoot, _change.Span))
+ Dim span = ExpandToNearestStatements( _baseTreeRoot, ExpandByLookAheadAndBehind(_baseTreeRoot, _change.Span))
_affectedRange = New TextChangeRange(span, span.Length - _change.Span.Length + _change.NewLength)
End Sub
Private Function MapNewPositionToOldTree(position As Integer) As Integer
- If position < _change.Span.Start Then
- Return position
- End If
-
- If position >= _change.Span.Start + _change.NewLength Then
- Return position - _change.NewLength + _change.Span.Length
- End If
-
+ If position < _change.Span.Start Then Return position
+ If position >= _change.Span.Start + _change.NewLength Then Return position - _change.NewLength + _change.Span.Length
Return -1
End Function
@@ -247,9 +210,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
_curNodeLength = node.FullWidth
' move blender preprocessor state forward if possible
- If _nextPreprocessorStateGetter.Valid Then
- _currentPreprocessorState = _nextPreprocessorStateGetter.State()
- End If
+ If _nextPreprocessorStateGetter.Valid Then _currentPreprocessorState = _nextPreprocessorStateGetter.State()
_nextPreprocessorStateGetter = New NextPreprocessorStateGetter(_currentPreprocessorState, DirectCast(node, VisualBasicSyntaxNode))
@@ -265,23 +226,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
''' Returns false if current node cannot be crumbled.
'''
Friend Overrides Function TryCrumbleOnce() As Boolean
- If _currentNode Is Nothing Then
- Return False
- End If
+ If _currentNode Is Nothing Then Return False
If _currentNode.SlotCount = 0 Then
- If Not _currentNode.ContainsStructuredTrivia Then
- ' terminal with no structured trivia is not interesting
- Return False
- End If
-
+ If Not _currentNode.ContainsStructuredTrivia Then Return False ' terminal with no structured trivia is not interesting
' try reusing structured trivia (in particular XML)
PushReverseTerminal(_nodeStack, DirectCast(_currentNode, SyntaxToken))
Else
- If Not ShouldCrumble(_currentNode) Then
- Return False
- End If
-
+ If Not ShouldCrumble(_currentNode) Then Return False
PushReverseNonterminal(_nodeStack, _currentNode)
End If
@@ -335,37 +287,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Debug.Assert(_currentNode IsNot Nothing)
Dim mappedPosition = MapNewPositionToOldTree(position)
-
- If mappedPosition = -1 Then
- Return Nothing
- End If
-
+ If mappedPosition = -1 Then Return Nothing
Do
' too far ahead
- If _curNodeStart > mappedPosition Then
- Return Nothing
- End If
+ If _curNodeStart > mappedPosition Then Return Nothing
' node ends before or on the mappedPosition
' whole node is unusable, move to the next node
If (_curNodeStart + _curNodeLength) <= mappedPosition Then
- If TryPopNode() Then
- Continue Do
- Else
- Return Nothing
- End If
- End If
-
- If _curNodeStart = mappedPosition AndAlso CanReuseNode(_currentNode) Then
- ' have some node
- Exit Do
+ If TryPopNode() Then Continue Do
+ Return Nothing
End If
+ If _curNodeStart = mappedPosition AndAlso CanReuseNode(_currentNode) Then Exit Do ' have some node
' current node spans the position or node is not usable
' try crumbling and look through children
- If Not TryCrumbleOnce() Then
- Return Nothing
- End If
+ If Not TryCrumbleOnce() Then Return Nothing
Loop
' zero-length nodes are ambiguous when given a particular position
@@ -379,18 +316,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
'''
Friend Overrides Function GetCurrentSyntaxNode() As VisualBasicSyntaxNode
' not going to get any nodes if there is no current node.
- If _currentNode Is Nothing Then
- Return Nothing
- End If
+ If _currentNode Is Nothing Then Return Nothing
' node must start where the current token starts.
Dim start = _currentToken.Position
' position is in affected range - no point trying.
Dim range = New TextSpan(_affectedRange.Span.Start, _affectedRange.NewLength)
- If range.Contains(start) Then
- Return Nothing
- End If
+ If range.Contains(start) Then Return Nothing
Dim nonterminal = GetCurrentNode(start)
Return nonterminal
@@ -401,58 +334,39 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
''' The reasons for it not be usable are typically that it intersects affected range.
'''
Private Function CanReuseNode(node As VisualBasicSyntaxNode) As Boolean
- If node Is Nothing Then
- Return False
- End If
-
- If node.SlotCount = 0 Then
- Return False
- End If
-
+ If node Is Nothing Then Return False
+ If node.SlotCount = 0 Then Return False
' TODO: This is a temporary measure to get around contextual errors.
' The problem is that some errors are contextual, but get attached to inner nodes.
' as a result in a case when an edit changes the context the error may be invalidated
' but since the node with actual error did not change the error will stay.
- If node.ContainsDiagnostics Then
- Return False
- End If
-
+ If node.ContainsDiagnostics Then Return False
' As of 2013/03/14, the compiler never attempts to incrementally parse a tree containing
' annotations. Our goal in instituting this restriction is to prevent API clients from
' taking a depedency on the survival of annotations.
- If node.ContainsAnnotations Then
- Return False
- End If
+ If node.ContainsAnnotations Then Return False
' If the node is an If statement, we need to determine whether it is a
' single-line or multi-line If. That requires the scanner to be positioned
' correctly relative to the end of line terminator if any, and currently we
' do not guarantee that. (See bug #16557.) For now, for simplicity, we
' do not reuse If statements.
- If node.Kind = SyntaxKind.IfStatement Then
- Return False
- End If
+ If node.Kind = SyntaxKind.IfStatement Then Return False
Dim _curNodeSpan = New TextSpan(_curNodeStart, _curNodeLength)
' TextSpan.OverlapsWith does not handle empty spans so
' empty spans need to be handled explicitly.
Debug.Assert(_curNodeSpan.Length > 0)
If _affectedRange.Span.Length = 0 Then
- If _curNodeSpan.Contains(_affectedRange.Span.Start) Then
- Return False
- End If
+ If _curNodeSpan.Contains(_affectedRange.Span.Start) Then Return False
Else
- If _curNodeSpan.OverlapsWith(_affectedRange.Span) Then
- Return False
- End If
+ If _curNodeSpan.OverlapsWith(_affectedRange.Span) Then Return False
End If
' we cannot use nodes that contain directives since we need to process
' directives individually.
' We however can use individual directives.
- If node.ContainsDirectives AndAlso Not TypeOf node Is DirectiveTriviaSyntax Then
- Return _scannerPreprocessorState.IsEquivalentTo(_currentPreprocessorState)
- End If
+ If node.ContainsDirectives AndAlso Not TypeOf node Is DirectiveTriviaSyntax Then Return _scannerPreprocessorState.IsEquivalentTo(_currentPreprocessorState)
' sometimes nodes contain linebreaks in leading trivia
' if we are in VBAllowLeadingMultilineTrivia state (common case), it is ok.
@@ -463,9 +377,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Return False
End If
- If _currentNode.IsMissing Then
- Return Nothing
- End If
+ If _currentNode.IsMissing Then Return Nothing
Return True
End Function
@@ -473,16 +385,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ContainsLeadingLineBreaks(node As VisualBasicSyntaxNode) As Boolean
Dim lt = node.GetLeadingTrivia
If lt IsNot Nothing Then
- If lt.Kind = SyntaxKind.EndOfLineTrivia Then
- Return True
- End If
+ If lt.Kind = SyntaxKind.EndOfLineTrivia Then Return True
Dim asList = TryCast(lt, SyntaxList)
If asList IsNot Nothing Then
For i As Integer = 0 To asList.SlotCount - 1
- If lt.GetSlot(i).RawKind = SyntaxKind.EndOfLineTrivia Then
- Return True
- End If
+ If lt.GetSlot(i).RawKind = SyntaxKind.EndOfLineTrivia Then Return True
Next
End If
End If
@@ -491,9 +399,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Friend Overrides Sub MoveToNextSyntaxNode()
- If _currentNode Is Nothing Then
- Return
- End If
+ If _currentNode Is Nothing Then Return
+
Debug.Assert(CanReuseNode(_currentNode), "this node could not have been used.")
Debug.Assert(_nextPreprocessorStateGetter.Valid, "we should have _nextPreprocessorState")
@@ -528,9 +435,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Sub
Friend Overrides Sub MoveToNextSyntaxNodeInTrivia()
- If _currentNode Is Nothing Then
- Return
- End If
+ If _currentNode Is Nothing Then Return
Debug.Assert(CanReuseNode(_currentNode), "this node could not have been used.")
@@ -563,10 +468,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Property
Public Function State() As PreprocessorState
- If _nextState Is Nothing Then
- _nextState = ApplyDirectives(Me._state, Me._node)
- End If
-
+ If _nextState Is Nothing Then _nextState = ApplyDirectives(Me._state, Me._node)
Return _nextState
End Function
End Structure
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/Directives.vb b/src/Compilers/VisualBasic/Portable/Scanner/Directives.vb
index eee01a6cb17e2..130a5aa09fb16 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/Directives.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/Directives.vb
@@ -22,10 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Debug.Assert(IsAtNewLine())
' leading whitespace until we see # should be regular whitespace
- If CanGetChar() AndAlso IsWhitespace(PeekChar()) Then
- Dim ws = ScanWhitespace()
- tList.Add(ws)
- End If
+ If CanGetChar() AndAlso IsWhitespace(Peek()) Then tList.Add(ScanWhitespace())
' SAVE the lookahead state and clear current token
Dim restorePoint = CreateRestorePoint()
@@ -74,15 +71,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim disabledCode As SyntaxList(Of VisualBasicSyntaxNode) = Nothing
Dim statement As DirectiveTriviaSyntax = directiveTrivia
- Dim newState = ApplyDirective(_scannerPreprocessorState,
- statement)
+ Dim newState = ApplyDirective(_scannerPreprocessorState, statement)
_scannerPreprocessorState = newState
' if we are in a not taken branch, skip text
Dim conditionals = newState.ConditionalStack
- If conditionals.Count <> 0 AndAlso
- Not conditionals.Peek.BranchTaken = ConditionalState.BranchTakenState.Taken Then
+ If (conditionals.Count <> 0) AndAlso Not (conditionals.Peek.BranchTaken = ConditionalState.BranchTakenState.Taken) Then
' we should not see #const inside disabled sections
Debug.Assert(statement.Kind <> SyntaxKind.ConstDirectiveTrivia)
@@ -96,17 +91,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' processing statement could add an error to it,
' so we may need to rebuild the trivia node
- If statement IsNot directiveTrivia Then
- directiveTrivia = statement
- End If
+ If statement IsNot directiveTrivia Then directiveTrivia = statement
' add the directive trivia to the list
tList.Add(directiveTrivia)
' if had disabled code, add that too
- If disabledCode.Node IsNot Nothing Then
- tList.AddRange(disabledCode)
- End If
+ If disabledCode.Node IsNot Nothing Then tList.AddRange(disabledCode)
End Sub
'''
@@ -114,10 +105,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
''' Entry point for blender
'''
Protected Shared Function ApplyDirectives(preprocessorState As PreprocessorState, node As VisualBasicSyntaxNode) As PreprocessorState
- If node.ContainsDirectives Then
- preprocessorState = ApplyDirectivesRecursive(preprocessorState, node)
- End If
-
+ If node.ContainsDirectives Then preprocessorState = ApplyDirectivesRecursive(preprocessorState, node)
Return preprocessorState
End Function
@@ -152,14 +140,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim tk = DirectCast(node, SyntaxToken)
Dim trivia = tk.GetLeadingTrivia
- If trivia IsNot Nothing AndAlso trivia.ContainsDirectives Then
- preprocessorState = ApplyDirectivesRecursive(preprocessorState, trivia)
- End If
+ If trivia IsNot Nothing AndAlso trivia.ContainsDirectives Then preprocessorState = ApplyDirectivesRecursive(preprocessorState, trivia)
trivia = tk.GetTrailingTrivia
- If trivia IsNot Nothing AndAlso trivia.ContainsDirectives Then
- preprocessorState = ApplyDirectivesRecursive(preprocessorState, trivia)
- End If
+ If trivia IsNot Nothing AndAlso trivia.ContainsDirectives Then preprocessorState = ApplyDirectivesRecursive(preprocessorState, trivia)
Return preprocessorState
End Function
@@ -172,46 +156,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Select Case statement.Kind
Case SyntaxKind.ConstDirectiveTrivia
Dim conditionalsStack = preprocessorState.ConditionalStack
- If conditionalsStack.Count <> 0 AndAlso
- Not conditionalsStack.Peek.BranchTaken = ConditionalState.BranchTakenState.Taken Then
-
+ If (conditionalsStack.Count <> 0) AndAlso Not (conditionalsStack.Peek.BranchTaken = ConditionalState.BranchTakenState.Taken) Then
' const inside disabled text - do not evaluate
Else
' interpret the const
preprocessorState = preprocessorState.InterpretConstDirective(statement)
End If
- Case SyntaxKind.IfDirectiveTrivia
- preprocessorState = preprocessorState.InterpretIfDirective(statement)
-
- Case SyntaxKind.ElseIfDirectiveTrivia
- preprocessorState = preprocessorState.InterpretElseIfDirective(statement)
-
- Case SyntaxKind.ElseDirectiveTrivia
- preprocessorState = preprocessorState.InterpretElseDirective(statement)
-
- Case SyntaxKind.EndIfDirectiveTrivia
- preprocessorState = preprocessorState.InterpretEndIfDirective(statement)
-
- Case SyntaxKind.RegionDirectiveTrivia
- preprocessorState = preprocessorState.InterpretRegionDirective(statement)
-
- Case SyntaxKind.EndRegionDirectiveTrivia
- preprocessorState = preprocessorState.InterpretEndRegionDirective(statement)
-
- Case SyntaxKind.ExternalSourceDirectiveTrivia
- preprocessorState = preprocessorState.InterpretExternalSourceDirective(statement)
-
- Case SyntaxKind.EndExternalSourceDirectiveTrivia
- preprocessorState = preprocessorState.InterpretEndExternalSourceDirective(statement)
-
+ Case SyntaxKind.IfDirectiveTrivia : preprocessorState = preprocessorState.InterpretIfDirective(statement)
+ Case SyntaxKind.ElseIfDirectiveTrivia : preprocessorState = preprocessorState.InterpretElseIfDirective(statement)
+ Case SyntaxKind.ElseDirectiveTrivia : preprocessorState = preprocessorState.InterpretElseDirective(statement)
+ Case SyntaxKind.EndIfDirectiveTrivia : preprocessorState = preprocessorState.InterpretEndIfDirective(statement)
+ Case SyntaxKind.RegionDirectiveTrivia : preprocessorState = preprocessorState.InterpretRegionDirective(statement)
+ Case SyntaxKind.EndRegionDirectiveTrivia : preprocessorState = preprocessorState.InterpretEndRegionDirective(statement)
+ Case SyntaxKind.ExternalSourceDirectiveTrivia : preprocessorState = preprocessorState.InterpretExternalSourceDirective(statement)
+ Case SyntaxKind.EndExternalSourceDirectiveTrivia : preprocessorState = preprocessorState.InterpretEndExternalSourceDirective(statement)
Case SyntaxKind.ExternalChecksumDirectiveTrivia,
- SyntaxKind.BadDirectiveTrivia,
- SyntaxKind.EnableWarningDirectiveTrivia, 'TODO: Add support for processing #Enable and #Disable
- SyntaxKind.DisableWarningDirectiveTrivia
-
+ SyntaxKind.BadDirectiveTrivia,
+ SyntaxKind.EnableWarningDirectiveTrivia, 'TODO: Add support for processing #Enable and #Disable
+ SyntaxKind.DisableWarningDirectiveTrivia
' These directives require no processing
-
Case Else
Throw ExceptionUtilities.UnexpectedValue(statement.Kind)
End Select
@@ -263,8 +227,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' as its instances can get associated with multiple tokens.
Friend NotInheritable Class PreprocessorState
Private ReadOnly _symbols As ImmutableDictionary(Of String, CConst)
- Private ReadOnly _conditionals As ImmutableStack(Of ConditionalState)
- Private ReadOnly _regionDirectives As ImmutableStack(Of RegionDirectiveTriviaSyntax)
+ Private ReadOnly _conditionals As ImmutableStack(Of ConditionalState)
+ Private ReadOnly _regionDirectives As ImmutableStack(Of RegionDirectiveTriviaSyntax)
Private ReadOnly _externalSourceDirective As ExternalSourceDirectiveTriviaSyntax
Friend Sub New(symbols As ImmutableDictionary(Of String, CConst))
@@ -273,10 +237,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
_regionDirectives = ImmutableStack.Create(Of RegionDirectiveTriviaSyntax)()
End Sub
- Private Sub New(symbols As ImmutableDictionary(Of String, CConst),
- conditionals As ImmutableStack(Of ConditionalState),
- regionDirectives As ImmutableStack(Of RegionDirectiveTriviaSyntax),
- externalSourceDirective As ExternalSourceDirectiveTriviaSyntax)
+ Private Sub New( symbols As ImmutableDictionary(Of String, CConst),
+ conditionals As ImmutableStack(Of ConditionalState),
+ regionDirectives As ImmutableStack(Of RegionDirectiveTriviaSyntax),
+ externalSourceDirective As ExternalSourceDirectiveTriviaSyntax)
Me._symbols = symbols
Me._conditionals = conditionals
@@ -328,51 +292,35 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Friend Function InterpretConstDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
Debug.Assert(statement.Kind = SyntaxKind.ConstDirectiveTrivia)
-
Dim constDirective = DirectCast(statement, ConstDirectiveTriviaSyntax)
Dim value = ExpressionEvaluator.EvaluateExpression(constDirective.Value, _symbols)
-
Dim err = value.ErrorId
- If err <> 0 Then
- statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
- End If
-
+ If err <> 0 Then statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
Return SetSymbol(constDirective.Name.IdentifierText, value)
End Function
Friend Function InterpretExternalSourceDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
Dim externalSourceDirective = DirectCast(statement, ExternalSourceDirectiveTriviaSyntax)
-
- If _externalSourceDirective IsNot Nothing Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_NestedExternalSource)
- Return Me
- Else
- Return WithExternalSource(externalSourceDirective)
- End If
+ If _externalSourceDirective Is Nothing Then Return WithExternalSource(externalSourceDirective)
+ statement = Parser.ReportSyntaxError(statement, ERRID.ERR_NestedExternalSource)
+ Return Me
End Function
Friend Function InterpretEndExternalSourceDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
- If _externalSourceDirective Is Nothing Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_EndExternalSource)
- Return Me
- Else
- Return WithExternalSource(Nothing)
- End If
+ If _externalSourceDirective IsNot Nothing Then Return WithExternalSource(Nothing)
+ statement = Parser.ReportSyntaxError(statement, ERRID.ERR_EndExternalSource)
+ Return Me
End Function
Friend Function InterpretRegionDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
Dim regionDirective = DirectCast(statement, RegionDirectiveTriviaSyntax)
-
Return WithRegions(_regionDirectives.Push(regionDirective))
End Function
Friend Function InterpretEndRegionDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
- If _regionDirectives.Count = 0 Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_EndRegionNoRegion)
- Return Me
- Else
- Return WithRegions(_regionDirectives.Pop())
- End If
+ If _regionDirectives.Count <> 0 Then Return WithRegions(_regionDirectives.Pop())
+ Return Me
+ statement = Parser.ReportSyntaxError(statement, ERRID.ERR_EndRegionNoRegion)
End Function
' // Interpret a conditional compilation #if or #elseif.
@@ -388,13 +336,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim value = ExpressionEvaluator.EvaluateCondition(ifDirective.Condition, _symbols)
Dim err = value.ErrorId
- If err <> 0 Then
- statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
- End If
+ If err <> 0 Then statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
- Dim takeThisBranch = If(value.IsBad OrElse value.IsBooleanTrue,
- ConditionalState.BranchTakenState.Taken,
- ConditionalState.BranchTakenState.NotTaken)
+ Dim takeThisBranch = If(value.IsBad OrElse value.IsBooleanTrue, ConditionalState.BranchTakenState.Taken, ConditionalState.BranchTakenState.NotTaken)
Return WithConditionals(_conditionals.Push(New ConditionalState(takeThisBranch, False, DirectCast(statement, IfDirectiveTriviaSyntax))))
End Function
@@ -411,9 +355,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
condition = conditionals.Peek
conditionals = conditionals.Pop
- If condition.ElseSeen Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbElseifAfterElse)
- End If
+ If condition.ElseSeen Then statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbElseifAfterElse)
End If
' TODO - Is the following comment still relevant? How should the error be reported?
@@ -424,19 +366,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim value = ExpressionEvaluator.EvaluateCondition(ifDirective.Condition, _symbols)
Dim err = value.ErrorId
- If err <> 0 Then
- statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
- End If
+ If err <> 0 Then statement = Parser.ReportSyntaxError(statement, err, value.ErrorArgs)
Dim takeThisBranch = condition.BranchTaken
-
- If takeThisBranch = ConditionalState.BranchTakenState.Taken Then
- takeThisBranch = ConditionalState.BranchTakenState.AlreadyTaken
-
- ElseIf takeThisBranch = ConditionalState.BranchTakenState.NotTaken AndAlso Not value.IsBad AndAlso value.IsBooleanTrue Then
- takeThisBranch = ConditionalState.BranchTakenState.Taken
-
- End If
+ Select Case takeThisBranch
+ Case ConditionalState.BranchTakenState.Taken : takeThisBranch = ConditionalState.BranchTakenState.AlreadyTaken
+ Case ConditionalState.BranchTakenState.NotTaken
+ If Not value.IsBad AndAlso value.IsBooleanTrue Then takeThisBranch = ConditionalState.BranchTakenState.Taken
+ End Select
condition = New ConditionalState(takeThisBranch, condition.ElseSeen, DirectCast(statement, IfDirectiveTriviaSyntax))
@@ -456,31 +393,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim condition = conditionals.Peek
conditionals = conditionals.Pop
- If condition.ElseSeen Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbElseNoMatchingIf)
- End If
+ If condition.ElseSeen Then statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbElseNoMatchingIf)
Dim takeThisBranch = condition.BranchTaken
-
- If takeThisBranch = ConditionalState.BranchTakenState.Taken Then
- takeThisBranch = ConditionalState.BranchTakenState.AlreadyTaken
-
- ElseIf takeThisBranch = ConditionalState.BranchTakenState.NotTaken Then
- takeThisBranch = ConditionalState.BranchTakenState.Taken
-
- End If
+ Select Case takeThisBranch
+ Case ConditionalState.BranchTakenState.Taken : takeThisBranch = ConditionalState.BranchTakenState.AlreadyTaken
+ Case ConditionalState.BranchTakenState.NotTaken : takeThisBranch = ConditionalState.BranchTakenState.Taken
+ End Select
condition = New ConditionalState(takeThisBranch, True, condition.IfDirective)
Return WithConditionals(conditionals.Push(condition))
End Function
Friend Function InterpretEndIfDirective(ByRef statement As DirectiveTriviaSyntax) As PreprocessorState
- If _conditionals.Count = 0 Then
- statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbNoMatchingIf)
- Return Me
- Else
- Return WithConditionals(_conditionals.Pop())
- End If
+ If _conditionals.Count <> 0 Then Return WithConditionals(_conditionals.Pop())
+ statement = Parser.ReportSyntaxError(statement, ERRID.ERR_LbNoMatchingIf)
+ Return Me
End Function
Friend Function IsEquivalentTo(other As PreprocessorState) As Boolean
@@ -493,12 +421,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
other._externalSourceDirective IsNot Nothing Then
Return False
End If
-
- If Me._regionDirectives.Count <> other._regionDirectives.Count Then
- Return False
- End If
-
- Return True
+ Return Me._regionDirectives.Count = other._regionDirectives.Count
End Function
End Class
@@ -517,15 +440,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim NestedConditionalsToSkip As Integer = 0
' Accumulate span of text we're skipping.
- Dim startSkipped As Integer = -1 ' Start location of skipping
- Dim lengthSkipped As Integer = 0 ' Length of skipped text.
+ Dim startSkipped = -1 ' Start location of skipping
+ Dim lengthSkipped = 0 ' Length of skipped text.
While True
Dim skippedSpan = Me.SkipToNextConditionalLine()
- If startSkipped < 0 Then
- startSkipped = skippedSpan.Start
- End If
+ If startSkipped < 0 Then startSkipped = skippedSpan.Start
lengthSkipped += skippedSpan.Length
Dim curToken = GetCurrentToken()
@@ -596,11 +517,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Select
End While
- If lengthSkipped > 0 Then
- Return New SyntaxList(Of VisualBasicSyntaxNode)(Me.GetDisabledTextAt(New TextSpan(startSkipped, lengthSkipped)))
- Else
- Return New SyntaxList(Of VisualBasicSyntaxNode)(Nothing)
- End If
+ If lengthSkipped = 0 Then Return New SyntaxList(Of VisualBasicSyntaxNode)(Nothing)
+ Return New SyntaxList(Of VisualBasicSyntaxNode)(Me.GetDisabledTextAt(New TextSpan(startSkipped, lengthSkipped)))
End Function
' // If compilation ends in the middle of a non-skipped conditional section,
@@ -618,9 +536,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
For Each state In _scannerPreprocessorState.ConditionalStack
Dim ifDirective As IfDirectiveTriviaSyntax = state.IfDirective
If ifDirective IsNot Nothing Then
- If notClosedIfDirectives Is Nothing Then
- notClosedIfDirectives = ArrayBuilder(Of IfDirectiveTriviaSyntax).GetInstance()
- End If
+ If notClosedIfDirectives Is Nothing Then notClosedIfDirectives = ArrayBuilder(Of IfDirectiveTriviaSyntax).GetInstance()
notClosedIfDirectives.Add(ifDirective)
End If
Next
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/KeywordTable.vb b/src/Compilers/VisualBasic/Portable/Scanner/KeywordTable.vb
index 1c88f0f488dcb..4660988cf2582 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/KeywordTable.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/KeywordTable.vb
@@ -292,13 +292,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
Friend Shared Function TokenOfString(tokenName As String) As SyntaxKind
Debug.Assert(tokenName IsNot Nothing)
-
tokenName = EnsureHalfWidth(tokenName)
-
Dim kind As SyntaxKind
- If Not _Keywords.TryGetValue(tokenName, kind) Then
- kind = SyntaxKind.IdentifierToken
- End If
+ If Not _Keywords.TryGetValue(tokenName, kind) Then kind = SyntaxKind.IdentifierToken
Return kind
End Function
@@ -307,30 +303,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
For i As Integer = 0 To s.Length - 1
Dim ch = s(i)
-
If SyntaxFacts.IsFullWidth(ch) Then
ch = SyntaxFacts.MakeHalfWidth(ch)
-
If result Is Nothing Then
result = New Char(s.Length - 1) {}
For j As Integer = 0 To i - 1
result(j) = s(j)
Next
End If
-
result(i) = ch
Else
- If result IsNot Nothing Then
- result(i) = ch
- End If
+ If result IsNot Nothing Then result(i) = ch
End If
Next
- If result IsNot Nothing Then
- Return New String(result)
- Else
- Return s
- End If
+ Return If( result IsNot Nothing, New String(result), s)
End Function
Friend Shared Function CanFollowExpression(kind As SyntaxKind) As Boolean
@@ -343,29 +330,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
Friend Shared Function IsQueryClause(kind As SyntaxKind) As Boolean
Dim description As KeywordDescription = Nothing
- If (_KeywordProperties.TryGetValue(kind, description)) Then
- Return description.kdIsQueryClause
- End If
+ If (_KeywordProperties.TryGetValue(kind, description)) Then Return description.kdIsQueryClause
Return False
End Function
Friend Shared Function TokenOpPrec(kind As SyntaxKind) As OperatorPrecedence
Dim description As KeywordDescription = Nothing
- If (_KeywordProperties.TryGetValue(kind, description)) Then
- Return description.kdOperPrec
- End If
-
+ If (_KeywordProperties.TryGetValue(kind, description)) Then Return description.kdOperPrec
Debug.Assert(False, "the kind is not found")
-
Return PrecedenceNone
End Function
- Private Shared Sub AddKeyword(
- Token As SyntaxKind,
- New7To8 As Boolean,
- Precedence As OperatorPrecedence,
- isQueryClause As Boolean,
- canFollowExpr As Boolean)
+ Private Shared Sub AddKeyword( Token As SyntaxKind, New7To8 As Boolean, Precedence As OperatorPrecedence, isQueryClause As Boolean, canFollowExpr As Boolean)
Dim keyword As New KeywordDescription(New7To8, Precedence, isQueryClause, canFollowExpr)
_KeywordProperties.Add(Token, keyword)
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb b/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb
index 79c3297b687a0..05fe11d064255 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/Scanner.vb
@@ -227,8 +227,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
token = MakeEofToken(leadingTrivia)
Else
' // Don't break up surrogate pairs
- Dim c = PeekChar()
- Dim length = If(IsHighSurrogate(c) AndAlso CanGetCharAtOffset(1) AndAlso IsLowSurrogate(PeekAheadChar(1)), 2, 1)
+ Dim c = Peek()
+ Dim length = If(IsHighSurrogate(c) AndAlso CanGetCharAtOffset(1) AndAlso IsLowSurrogate(Peek(1)), 2, 1)
token = MakeBadToken(leadingTrivia, length, ERRID.ERR_IllegalChar)
End If
@@ -257,7 +257,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim condLineStart = _lineBufferOffset
While (CanGetChar())
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case (c)
@@ -267,7 +267,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Continue While
Case SPACE, CHARACTER_TABULATION
- Debug.Assert(IsWhitespace(PeekChar()))
+ Debug.Assert(IsWhitespace(Peek()))
EatWhitespace()
Continue While
@@ -313,7 +313,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Sub EatThroughLine()
While CanGetChar()
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
If IsNewLine(c) Then
EatThroughLineBreak(c)
@@ -455,11 +455,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Debug.Assert(CanGetCharAtOffset(here))
Debug.Assert(IsNewLine(StartCharacter))
- Debug.Assert(StartCharacter = PeekAheadChar(here))
+ Debug.Assert(StartCharacter = Peek(here))
If StartCharacter = CARRIAGE_RETURN AndAlso
CanGetCharAtOffset(here + 1) AndAlso
- PeekAheadChar(here + 1) = LINE_FEED Then
+ Peek(here + 1) = LINE_FEED Then
Return 2
End If
@@ -509,14 +509,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Return False
End If
- Dim ch As Char = PeekChar()
+ Dim ch As Char = Peek()
If Not IsUnderscore(ch) Then
Return False
End If
Dim Here = 1
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If IsWhitespace(ch) Then
Here += 1
Else
@@ -548,7 +548,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' include the new line and any additional spaces as trivia.
If startComment = 0 AndAlso
CanGetCharAtOffset(Here) AndAlso
- Not IsNewLine(PeekAheadChar(Here)) Then
+ Not IsNewLine(Peek(Here)) Then
tList.Add(MakeEndOfLineTrivia(GetText(newLine)))
If spaces > 0 Then
@@ -573,7 +573,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Return Nothing
End If
- Dim ch = PeekChar()
+ Dim ch = Peek()
' optimization for a common case
' the ASCII range between ': and ~ , with exception of except "'", "_" and R cannot start trivia
@@ -609,7 +609,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End If
End If
- Dim ch = PeekChar()
+ Dim ch = Peek()
If IsWhitespace(ch) Then
' eat until linebreak or nonwhitespace
Dim wslen = GetWhitespaceLength(1)
@@ -646,31 +646,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function StartsXmlDoc(Here As Integer) As Boolean
Return _options.DocumentationMode >= DocumentationMode.Parse AndAlso
CanGetCharAtOffset(Here + 3) AndAlso
- IsSingleQuote(PeekAheadChar(Here)) AndAlso
- IsSingleQuote(PeekAheadChar(Here + 1)) AndAlso
- IsSingleQuote(PeekAheadChar(Here + 2)) AndAlso
- Not IsSingleQuote(PeekAheadChar(Here + 3))
+ IsSingleQuote(Peek(Here)) AndAlso
+ IsSingleQuote(Peek(Here + 1)) AndAlso
+ IsSingleQuote(Peek(Here + 2)) AndAlso
+ Not IsSingleQuote(Peek(Here + 3))
End Function
' check for #
Private Function StartsDirective(Here As Integer) As Boolean
If CanGetCharAtOffset(Here) Then
- Dim ch = PeekAheadChar(Here)
+ Dim ch = Peek(Here)
Return IsHash(ch)
End If
Return False
End Function
Private Function IsAtNewLine() As Boolean
- Return _lineBufferOffset = 0 OrElse IsNewLine(PeekAheadChar(-1))
+ Return _lineBufferOffset = 0 OrElse IsNewLine(Peek(-1))
End Function
Private Function IsAfterWhitespace() As Boolean
- If _lineBufferOffset = 0 Then
- Return True
- End If
+ If _lineBufferOffset = 0 Then Return True
- Dim prevChar = PeekAheadChar(-1)
+ Dim prevChar = Peek(-1)
Return IsWhitespace(prevChar)
End Function
@@ -699,7 +697,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Sub ScanSingleLineTriviaInXmlDoc(tList As SyntaxListBuilder)
If CanGetChar() Then
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case (c)
' // Whitespace
' // S ::= (#x20 | #x9 | #xD | #xA)+
@@ -731,7 +729,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Sub ScanWhitespaceAndLineContinuations(tList As SyntaxListBuilder)
- If CanGetChar() AndAlso IsWhitespace(PeekChar()) Then
+ If CanGetChar() AndAlso IsWhitespace(Peek()) Then
tList.Add(ScanWhitespace(1))
' collect { lineCont, ws }
While ScanLineContinuation(tList)
@@ -803,7 +801,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If CanGetChar() Then
- Dim ch As Char = PeekChar()
+ Dim ch As Char = Peek()
Dim startOfTerminatorTrivia = _lineBufferOffset
If IsNewLine(ch) Then
@@ -819,7 +817,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Exit Do
End If
- ch = PeekAheadChar(len)
+ ch = Peek(len)
If Not IsColonAndNotColonEquals(ch, offset:=len) Then
Exit Do
End If
@@ -855,7 +853,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function GetWhitespaceLength(len As Integer) As Integer
' eat until linebreak or nonwhitespace
- While CanGetCharAtOffset(len) AndAlso IsWhitespace(PeekAheadChar(len))
+ While CanGetCharAtOffset(len) AndAlso IsWhitespace(Peek(len))
len += 1
End While
Return len
@@ -863,7 +861,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function GetXmlWhitespaceLength(len As Integer) As Integer
' eat until linebreak or nonwhitespace
- While CanGetCharAtOffset(len) AndAlso IsXmlWhitespace(PeekAheadChar(len))
+ While CanGetCharAtOffset(len) AndAlso IsXmlWhitespace(Peek(len))
len += 1
End While
Return len
@@ -887,12 +885,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Sub EatWhitespace()
Debug.Assert(CanGetChar)
- Debug.Assert(IsWhitespace(PeekChar()))
+ Debug.Assert(IsWhitespace(Peek()))
AdvanceChar()
' eat until linebreak or nonwhitespace
- While CanGetChar() AndAlso IsWhitespace(PeekChar)
+ While CanGetChar() AndAlso IsWhitespace(Peek)
AdvanceChar()
End While
End Sub
@@ -900,18 +898,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function PeekStartComment(i As Integer) As Integer
If CanGetCharAtOffset(i) Then
- Dim ch = PeekAheadChar(i)
+ Dim ch = Peek(i)
If IsSingleQuote(ch) Then
Return 1
ElseIf MatchOneOrAnotherOrFullwidth(ch, "R"c, "r"c) AndAlso
- CanGetCharAtOffset(i + 2) AndAlso MatchOneOrAnotherOrFullwidth(PeekAheadChar(i + 1), "E"c, "e"c) AndAlso
- MatchOneOrAnotherOrFullwidth(PeekAheadChar(i + 2), "M"c, "m"c) Then
+ CanGetCharAtOffset(i + 2) AndAlso MatchOneOrAnotherOrFullwidth(Peek(i + 1), "E"c, "e"c) AndAlso
+ MatchOneOrAnotherOrFullwidth(Peek(i + 2), "M"c, "m"c) Then
- If Not CanGetCharAtOffset(i + 3) OrElse IsNewLine(PeekAheadChar(i + 3)) Then
+ If Not CanGetCharAtOffset(i + 3) OrElse IsNewLine(Peek(i + 3)) Then
' have only 'REM'
Return 3
- ElseIf Not IsIdentifierPartCharacter(PeekAheadChar(i + 3)) Then
+ ElseIf Not IsIdentifierPartCharacter(Peek(i + 3)) Then
' have 'REM '
Return 4
End If
@@ -930,7 +928,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' eat all chars until EoL
While CanGetCharAtOffset(length) AndAlso
- Not IsNewLine(PeekAheadChar(length))
+ Not IsNewLine(Peek(length))
length += 1
End While
@@ -956,166 +954,133 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ScanColonAsTrivia() As SyntaxTrivia
Debug.Assert(CanGetChar())
- Debug.Assert(IsColonAndNotColonEquals(PeekChar(), offset:=0))
+ Debug.Assert(IsColonAndNotColonEquals(Peek(), offset:=0))
Return MakeColonTrivia(GetText(1))
End Function
#End Region
- ' at this point it is very likely that we are located at
- ' the beginning of a token
- Private Function TryScanToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
-
- If Not CanGetChar() Then
- Return MakeEofToken(precedingTrivia)
- End If
+ Private Function ScanToken_Unified(
+ precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode),
+ ch As Char, FullWidthChar As Boolean) As SyntaxToken
+ Dim lengthWithMaybeEquals = 1
- Dim ch As Char = PeekChar()
Select Case ch
- Case CARRIAGE_RETURN, LINE_FEED, NEXT_LINE, LINE_SEPARATOR, PARAGRAPH_SEPARATOR
+ Case CARRIAGE_RETURN, LINE_FEED
Return ScanNewlineAsStatementTerminator(ch, precedingTrivia)
+ Case NEXT_LINE, LINE_SEPARATOR, PARAGRAPH_SEPARATOR
+ If Not FullWidthChar Then Return ScanNewlineAsStatementTerminator(ch, precedingTrivia)
+
+
Case " "c, CHARACTER_TABULATION, "'"c
Debug.Assert(False, String.Format("Unexpected char: &H{0:x}", AscW(ch)))
Return Nothing ' trivia cannot start a token
- Case "@"c
- Return MakeAtToken(precedingTrivia, False)
-
- Case "("c
- Return MakeOpenParenToken(precedingTrivia, False)
-
- Case ")"c
- Return MakeCloseParenToken(precedingTrivia, False)
-
- Case "{"c
- Return MakeOpenBraceToken(precedingTrivia, False)
-
- Case "}"c
- Return MakeCloseBraceToken(precedingTrivia, False)
-
- Case ","c
- Return MakeCommaToken(precedingTrivia, False)
+ Case "@"c : Return MakeAtToken(precedingTrivia, FullWidthChar)
+ Case "("c : Return MakeOpenParenToken(precedingTrivia, FullWidthChar)
+ Case ")"c : Return MakeCloseParenToken(precedingTrivia, FullWidthChar)
+ Case "{"c : Return MakeOpenBraceToken(precedingTrivia, FullWidthChar)
+ Case "}"c : Return MakeCloseBraceToken(precedingTrivia, FullWidthChar)
+ Case ","c : Return MakeCommaToken(precedingTrivia, FullWidthChar)
Case "#"c
Dim dl = ScanDateLiteral(precedingTrivia)
If dl IsNot Nothing Then
Return dl
Else
- Return MakeHashToken(precedingTrivia, False)
+ Return MakeHashToken(precedingTrivia, FullWidthChar)
End If
Case "&"c
- If CanGetCharAtOffset(1) AndAlso BeginsBaseLiteral(PeekAheadChar(1)) Then
+ If CanGetCharAtOffset(1) AndAlso BeginsBaseLiteral(Peek(1)) Then
Return ScanNumericLiteral(precedingTrivia)
End If
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeAmpersandEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeAmpersandToken(precedingTrivia, False)
+ Return MakeAmpersandToken(precedingTrivia, FullWidthChar)
End If
- Case "="c
- Return MakeEqualsToken(precedingTrivia, False)
-
- Case "<"c
- Return ScanLeftAngleBracket(precedingTrivia, False, _scanSingleLineTriviaFunc)
-
- Case ">"c
- Return ScanRightAngleBracket(precedingTrivia, False)
+ Case "="c : Return MakeEqualsToken(precedingTrivia, FullWidthChar)
+ Case "<"c : Return ScanLeftAngleBracket(precedingTrivia, FullWidthChar, _scanSingleLineTriviaFunc)
+ Case ">"c : Return ScanRightAngleBracket(precedingTrivia, FullWidthChar)
Case ":"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeColonEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return ScanColonAsStatementTerminator(precedingTrivia, False)
+ Return ScanColonAsStatementTerminator(precedingTrivia, FullWidthChar)
End If
Case "+"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakePlusEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakePlusToken(precedingTrivia, False)
+ Return MakePlusToken(precedingTrivia, FullWidthChar)
End If
Case "-"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeMinusEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeMinusToken(precedingTrivia, False)
+ Return MakeMinusToken(precedingTrivia, FullWidthChar)
End If
Case "*"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeAsteriskEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeAsteriskToken(precedingTrivia, False)
+ Return MakeAsteriskToken(precedingTrivia, FullWidthChar)
End If
Case "/"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeSlashEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeSlashToken(precedingTrivia, False)
+ Return MakeSlashToken(precedingTrivia, FullWidthChar)
End If
Case "\"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeBackSlashEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeBackslashToken(precedingTrivia, False)
+ Return MakeBackslashToken(precedingTrivia, FullWidthChar)
End If
Case "^"c
- Dim lengthWithMaybeEquals = 1
If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
Return MakeCaretEqualsToken(precedingTrivia, lengthWithMaybeEquals)
Else
- Return MakeCaretToken(precedingTrivia, False)
+ Return MakeCaretToken(precedingTrivia, FullWidthChar)
End If
- Case "!"c
- Return MakeExclamationToken(precedingTrivia, False)
-
+ Case "!"c : Return MakeExclamationToken(precedingTrivia, FullWidthChar)
Case "."c
- If CanGetCharAtOffset(1) AndAlso IsDecimalDigit(PeekAheadChar(1)) Then
+ If CanGetCharAtOffset(1) AndAlso IsDecimalDigit(Peek(1)) Then
Return ScanNumericLiteral(precedingTrivia)
Else
- Return MakeDotToken(precedingTrivia, False)
+ Return MakeDotToken(precedingTrivia, FullWidthChar)
End If
- Case "0"c,
- "1"c,
- "2"c,
- "3"c,
- "4"c,
- "5"c,
- "6"c,
- "7"c,
- "8"c,
- "9"c
+ Case "0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c
Return ScanNumericLiteral(precedingTrivia)
- Case """"c
- Return ScanStringLiteral(precedingTrivia)
-
+ Case """"c : Return ScanStringLiteral(precedingTrivia)
Case "A"c
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(1) = "s"c AndAlso
- PeekAheadChar(2) = " "c Then
+ Peek(1) = "s"c AndAlso
+ Peek(2) = " "c Then
- ' TODO: do we allow widechars in keywords?
- Dim spelling = "As"
- AdvanceChar(2)
+ Dim spelling As String
+ If FullWidthChar Then
+ spelling = GetText(2)
+ Else
+ spelling = "As"
+ AdvanceChar(2)
+ End If
Return MakeKeyword(SyntaxKind.AsKeyword, spelling, precedingTrivia)
Else
Return ScanIdentifierOrKeyword(precedingTrivia)
@@ -1123,13 +1088,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case "E"c
If CanGetCharAtOffset(3) AndAlso
- PeekAheadChar(1) = "n"c AndAlso
- PeekAheadChar(2) = "d"c AndAlso
- PeekAheadChar(3) = " "c Then
+ Peek(1) = "n"c AndAlso
+ Peek(2) = "d"c AndAlso
+ Peek(3) = " "c Then
- ' TODO: do we allow widechars in keywords?
- Dim spelling = "End"
- AdvanceChar(3)
+ Dim spelling As String
+ If FullWidthChar THen
+ spelling =GetText(3)
+ Else
+ spelling = "End"
+ AdvanceChar(3)
+ End If
Return MakeKeyword(SyntaxKind.EndKeyword, spelling, precedingTrivia)
Else
Return ScanIdentifierOrKeyword(precedingTrivia)
@@ -1137,293 +1106,88 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case "I"c
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(1) = "f"c AndAlso
- PeekAheadChar(2) = " "c Then
+ Peek(1) = "f"c AndAlso
+ Peek(2) = " "c Then
' TODO: do we allow widechars in keywords?
- Dim spelling = "If"
- AdvanceChar(2)
+ Dim spelling As String
+ If FullWidthChar Then
+ spelling = GetText(3)
+ Else
+ spelling = "If"
+ AdvanceChar(3)
+ End If
Return MakeKeyword(SyntaxKind.IfKeyword, spelling, precedingTrivia)
Else
Return ScanIdentifierOrKeyword(precedingTrivia)
End If
- Case "a"c To "z"c
+ Case "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c, "i"c, "j"c, "k"c, "l"c, "m"c,
+ "n"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c, "v"c, "w"c, "x"c, "y"c, "z"c
Return ScanIdentifierOrKeyword(precedingTrivia)
Case "B"c, "C"c, "D"c, "F"c, "G"c, "H"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c,
- "R"c, "S"c, "T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c
+ "R"c, "S"c, "T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c
Return ScanIdentifierOrKeyword(precedingTrivia)
Case "_"c
- If CanGetCharAtOffset(1) AndAlso IsIdentifierPartCharacter(PeekAheadChar(1)) Then
+ If CanGetCharAtOffset(1) AndAlso IsIdentifierPartCharacter(Peek(1)) Then
Return ScanIdentifierOrKeyword(precedingTrivia)
End If
Dim err As ERRID = ERRID.ERR_ExpectedIdentifier
Dim len = GetWhitespaceLength(1)
- If Not CanGetCharAtOffset(len) OrElse IsNewLine(PeekAheadChar(len)) OrElse PeekStartComment(len) > 0 Then
+ If Not CanGetCharAtOffset(len) OrElse IsNewLine(Peek(len)) OrElse PeekStartComment(len) > 0 Then
err = ERRID.ERR_LineContWithCommentOrNoPrecSpace
End If
' not a line continuation and cannot start identifier.
Return MakeBadToken(precedingTrivia, 1, err)
- Case "["c
- Return ScanBracketedIdentifier(precedingTrivia)
-
- Case "?"c
- Return MakeQuestionToken(precedingTrivia, False)
+ Case "["c : Return ScanBracketedIdentifier(precedingTrivia)
+ Case "?"c : Return MakeQuestionToken(precedingTrivia, FullWidthChar)
Case "%"c
- If CanGetCharAtOffset(1) AndAlso
- PeekAheadChar(1) = ">"c Then
+ If CanGetCharAtOffset(1) AndAlso Peek(1) = ">"c Then
Return XmlMakeEndEmbeddedToken(precedingTrivia, _scanSingleLineTriviaFunc)
End If
-
Case "$"c, FULLWIDTH_DOLLAR_SIGN
- If CanGetCharAtOffset(1) AndAlso IsDoubleQuote(PeekAheadChar(1)) Then
- Return MakePunctuationToken(precedingTrivia, 2, SyntaxKind.DollarSignDoubleQuoteToken)
- End If
-
+ If Not FullWidthChar Then
+ If CanGetCharAtOffset(1) AndAlso IsDoubleQuote(Peek(1)) Then
+ Return MakePunctuationToken(precedingTrivia, 2, SyntaxKind.DollarSignDoubleQuoteToken)
+ End If
+ End IF
End Select
- If IsIdentifierStartCharacter(ch) Then
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Debug.Assert(Not IsNewLine(ch))
-
- If IsDoubleQuote(ch) Then
- Return ScanStringLiteral(precedingTrivia)
- End If
-
- If IsFullWidth(ch) Then
- ch = MakeHalfWidth(ch)
- Return ScanTokenFullWidth(precedingTrivia, ch)
+ If IsIdentifierStartCharacter(ch) Then Return ScanIdentifierOrKeyword(precedingTrivia)
+ If FullWidthChar Then
+ Debug.Assert(Not IsNewLine(ch))
+ Debug.Assert(Not IsDoubleQuote(ch))
+ Else
+ Debug.Assert(Not IsNewLine(ch))
+ If IsDoubleQuote(ch) Then Return ScanStringLiteral(precedingTrivia)
+ If IsFullWidth(ch) Then
+ ch = MakeHalfWidth(ch)
+ Return ScanTokenFullWidth(precedingTrivia, ch)
+ End If
End If
Return Nothing
End Function
- ' REVIEW: Is there a better way to reuse this logic?
- Private Function ScanTokenFullWidth(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), ch As Char) As SyntaxToken
- Select Case ch
- Case CARRIAGE_RETURN, LINE_FEED
- Return ScanNewlineAsStatementTerminator(ch, precedingTrivia)
-
- Case " "c, CHARACTER_TABULATION, "'"c
- Debug.Assert(False, String.Format("Unexpected char: &H{0:x}", AscW(ch)))
- Return Nothing ' trivia cannot start a token
-
- Case "@"c
- Return MakeAtToken(precedingTrivia, True)
-
- Case "("c
- Return MakeOpenParenToken(precedingTrivia, True)
-
- Case ")"c
- Return MakeCloseParenToken(precedingTrivia, True)
-
- Case "{"c
- Return MakeOpenBraceToken(precedingTrivia, True)
-
- Case "}"c
- Return MakeCloseBraceToken(precedingTrivia, True)
-
- Case ","c
- Return MakeCommaToken(precedingTrivia, True)
-
- Case "#"c
- Dim dl = ScanDateLiteral(precedingTrivia)
- If dl IsNot Nothing Then
- Return dl
- Else
- Return MakeHashToken(precedingTrivia, True)
- End If
-
- Case "&"c
- If CanGetCharAtOffset(1) AndAlso BeginsBaseLiteral(PeekAheadChar(1)) Then
- Return ScanNumericLiteral(precedingTrivia)
- End If
-
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeAmpersandEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeAmpersandToken(precedingTrivia, True)
- End If
-
- Case "="c
- Return MakeEqualsToken(precedingTrivia, True)
-
- Case "<"c
- Return ScanLeftAngleBracket(precedingTrivia, True, _scanSingleLineTriviaFunc)
-
- Case ">"c
- Return ScanRightAngleBracket(precedingTrivia, True)
-
- Case ":"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeColonEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return ScanColonAsStatementTerminator(precedingTrivia, True)
- End If
-
- Case "+"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakePlusEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakePlusToken(precedingTrivia, True)
- End If
-
- Case "-"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeMinusEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeMinusToken(precedingTrivia, True)
- End If
-
- Case "*"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeAsteriskEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeAsteriskToken(precedingTrivia, True)
- End If
-
- Case "/"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeSlashEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeSlashToken(precedingTrivia, True)
- End If
-
- Case "\"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeBackSlashEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeBackslashToken(precedingTrivia, True)
- End If
-
- Case "^"c
- Dim lengthWithMaybeEquals = 1
- If TrySkipFollowingEquals(lengthWithMaybeEquals) Then
- Return MakeCaretEqualsToken(precedingTrivia, lengthWithMaybeEquals)
- Else
- Return MakeCaretToken(precedingTrivia, True)
- End If
-
- Case "!"c
- Return MakeExclamationToken(precedingTrivia, True)
-
- Case "."c
- If CanGetCharAtOffset(1) AndAlso IsDecimalDigit(PeekAheadChar(1)) Then
- Return ScanNumericLiteral(precedingTrivia)
- Else
- Return MakeDotToken(precedingTrivia, True)
- End If
-
- Case "0"c,
- "1"c,
- "2"c,
- "3"c,
- "4"c,
- "5"c,
- "6"c,
- "7"c,
- "8"c,
- "9"c
- Return ScanNumericLiteral(precedingTrivia)
-
- Case """"c
- Return ScanStringLiteral(precedingTrivia)
-
- Case "A"c
- If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(1) = "s"c AndAlso
- PeekAheadChar(2) = " "c Then
-
- Dim spelling = GetText(2)
- Return MakeKeyword(SyntaxKind.AsKeyword, spelling, precedingTrivia)
- Else
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Case "E"c
- If CanGetCharAtOffset(3) AndAlso
- PeekAheadChar(1) = "n"c AndAlso
- PeekAheadChar(2) = "d"c AndAlso
- PeekAheadChar(3) = " "c Then
-
- Dim spelling = GetText(3)
- Return MakeKeyword(SyntaxKind.EndKeyword, spelling, precedingTrivia)
- Else
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Case "I"c
- If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(1) = "f"c AndAlso
- PeekAheadChar(2) = " "c Then
-
- ' TODO: do we allow widechars in keywords?
- Dim spelling = GetText(2)
- Return MakeKeyword(SyntaxKind.IfKeyword, spelling, precedingTrivia)
- Else
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Case "a"c To "z"c
- Return ScanIdentifierOrKeyword(precedingTrivia)
-
- Case "B"c, "C"c, "D"c, "F"c, "G"c, "H"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c,
- "R"c, "S"c, "T"c, "U"c, "V"c, "W"c, "X"c, "Y"c, "Z"c
- Return ScanIdentifierOrKeyword(precedingTrivia)
-
- Case "_"c
- If CanGetCharAtOffset(1) AndAlso IsIdentifierPartCharacter(PeekAheadChar(1)) Then
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Dim err As ERRID = ERRID.ERR_ExpectedIdentifier
- Dim len = GetWhitespaceLength(1)
- If Not CanGetCharAtOffset(len) OrElse IsNewLine(PeekAheadChar(len)) OrElse PeekStartComment(len) > 0 Then
- err = ERRID.ERR_LineContWithCommentOrNoPrecSpace
- End If
-
- ' not a line continuation and cannot start identifier.
- Return MakeBadToken(precedingTrivia, 1, err)
-
- Case "["c
- Return ScanBracketedIdentifier(precedingTrivia)
-
- Case "?"c
- Return MakeQuestionToken(precedingTrivia, True)
-
- Case "%"c
- If CanGetCharAtOffset(1) AndAlso
- PeekAheadChar(1) = ">"c Then
- Return XmlMakeEndEmbeddedToken(precedingTrivia, _scanSingleLineTriviaFunc)
- End If
-
- End Select
-
- If IsIdentifierStartCharacter(ch) Then
- Return ScanIdentifierOrKeyword(precedingTrivia)
- End If
-
- Debug.Assert(Not IsNewLine(ch))
- Debug.Assert(Not IsDoubleQuote(ch))
+ ' at this point it is very likely that we are located at
+ ' the beginning of a token
+ Private Function TryScanToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
+ If Not CanGetChar() Then Return MakeEofToken(precedingTrivia)
+ Dim ch As Char = Peek()
+ Return ScanToken_Unified(precedingTrivia, ch, False)
+ End Function
- Return Nothing
+ Private Function ScanTokenFullWidth(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), ch As Char) As SyntaxToken
+ Return ScanToken_Unified(precedingTrivia, ch, True)
End Function
+
' // Allow whitespace between the characters of a two-character token.
Private Function TrySkipFollowingEquals(ByRef Index As Integer) As Boolean
Debug.Assert(Index > 0)
@@ -1433,7 +1197,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim eq As Char
While CanGetCharAtOffset(Here)
- eq = PeekAheadChar(Here)
+ eq = Peek(Here)
Here += 1
If Not IsWhitespace(eq) Then
If eq = "="c OrElse eq = FULLWIDTH_EQUALS_SIGN Then
@@ -1449,7 +1213,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ScanRightAngleBracket(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), charIsFullWidth As Boolean) As SyntaxToken
Debug.Assert(CanGetChar) ' >
- Debug.Assert(PeekChar() = ">"c OrElse PeekChar() = FULLWIDTH_GREATER_THAN_SIGN)
+ Debug.Assert(Peek() = ">"c OrElse Peek() = FULLWIDTH_GREATER_THAN_SIGN)
Dim length As Integer = 1
@@ -1457,7 +1221,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
length = GetWhitespaceLength(length)
If CanGetCharAtOffset(length) Then
- Dim c As Char = PeekAheadChar(length)
+ Dim c As Char = Peek(length)
If c = "="c OrElse c = FULLWIDTH_EQUALS_SIGN Then
length += 1
@@ -1476,29 +1240,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ScanLeftAngleBracket(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), charIsFullWidth As Boolean, scanTrailingTrivia As ScanTriviaFunc) As SyntaxToken
Debug.Assert(CanGetChar) ' <
- Debug.Assert(PeekChar() = "<"c OrElse PeekChar() = FULLWIDTH_LESS_THAN_SIGN)
+ Debug.Assert(Peek() = "<"c OrElse Peek() = FULLWIDTH_LESS_THAN_SIGN)
Dim length As Integer = 1
' Check for XML tokens
If Not charIsFullWidth AndAlso CanGetCharAtOffset(length) Then
- Dim c As Char = PeekAheadChar(length)
+ Dim c As Char = Peek(length)
Select Case c
Case "!"c
If CanGetCharAtOffset(length + 2) Then
- Select Case (PeekAheadChar(length + 1))
+ Select Case (Peek(length + 1))
Case "-"c
- If CanGetCharAtOffset(length + 3) AndAlso PeekAheadChar(length + 2) = "-"c Then
+ If CanGetCharAtOffset(length + 3) AndAlso Peek(length + 2) = "-"c Then
Return XmlMakeBeginCommentToken(precedingTrivia, scanTrailingTrivia)
End If
Case "["c
If CanGetCharAtOffset(length + 8) AndAlso
- PeekAheadChar(length + 2) = "C"c AndAlso
- PeekAheadChar(length + 3) = "D"c AndAlso
- PeekAheadChar(length + 4) = "A"c AndAlso
- PeekAheadChar(length + 5) = "T"c AndAlso
- PeekAheadChar(length + 6) = "A"c AndAlso
- PeekAheadChar(length + 7) = "["c Then
+ Peek(length + 2) = "C"c AndAlso
+ Peek(length + 3) = "D"c AndAlso
+ Peek(length + 4) = "A"c AndAlso
+ Peek(length + 5) = "T"c AndAlso
+ Peek(length + 6) = "A"c AndAlso
+ Peek(length + 7) = "["c Then
Return XmlMakeBeginCDataToken(precedingTrivia, scanTrailingTrivia)
End If
@@ -1516,7 +1280,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
length = GetWhitespaceLength(length)
If CanGetCharAtOffset(length) Then
- Dim c As Char = PeekAheadChar(length)
+ Dim c As Char = Peek(length)
If c = "="c OrElse c = FULLWIDTH_EQUALS_SIGN Then
length += 1
@@ -1528,7 +1292,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
length += 1
If CanGetCharAtOffset(length) Then
- c = PeekAheadChar(length)
+ c = Peek(length)
'if the second "<" is a part of "<%" - like in "<<%" , we do not want to use it.
If c <> "%"c AndAlso c <> FULLWIDTH_PERCENT_SIGN Then
@@ -1576,12 +1340,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function ScanIdentifierOrKeyword(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
Debug.Assert(CanGetChar)
- Debug.Assert(IsIdentifierStartCharacter(PeekChar))
+ Debug.Assert(IsIdentifierStartCharacter(Peek))
Debug.Assert(PeekStartComment(0) = 0) ' comment should be handled by caller
- Dim ch = PeekChar()
+ Dim ch = Peek()
If CanGetCharAtOffset(1) Then
- Dim ch1 = PeekAheadChar(1)
+ Dim ch1 = Peek(1)
If IsConnectorPunctuation(ch) AndAlso Not IsIdentifierPartCharacter(ch1) Then
Return MakeBadToken(precedingTrivia, 1, ERRID.ERR_ExpectedIdentifier)
End If
@@ -1593,7 +1357,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' // < 128 test is inline here. (This loop gets a *lot* of traffic.)
' TODO: make sure we get good perf here
While CanGetCharAtOffset(len)
- ch = PeekAheadChar(len)
+ ch = Peek(len)
Dim code = Convert.ToUInt16(ch)
If code < 128 AndAlso IsNarrowIdentifierCharacter(code) OrElse
@@ -1608,14 +1372,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
'Check for a type character
Dim TypeCharacter As TypeCharacter = TypeCharacter.None
If CanGetCharAtOffset(len) Then
- ch = PeekAheadChar(len)
+ ch = Peek(len)
FullWidthRepeat:
Select Case ch
Case "!"c
' // If the ! is followed by an identifier it is a dictionary lookup operator, not a type character.
If CanGetCharAtOffset(len + 1) Then
- Dim NextChar As Char = PeekAheadChar(len + 1)
+ Dim NextChar As Char = Peek(len + 1)
If IsIdentifierStartCharacter(NextChar) OrElse
MatchOneOrAnotherOrFullwidth(NextChar, "["c, "]"c) Then
@@ -1694,7 +1458,7 @@ FullWidthRepeat:
Private Function ScanBracketedIdentifier(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
Debug.Assert(CanGetChar) ' [
- Debug.Assert(PeekChar() = "["c OrElse PeekChar() = FULLWIDTH_LEFT_SQUARE_BRACKET)
+ Debug.Assert(Peek() = "["c OrElse Peek() = FULLWIDTH_LEFT_SQUARE_BRACKET)
Dim IdStart As Integer = 1
Dim Here As Integer = IdStart
@@ -1705,20 +1469,20 @@ FullWidthRepeat:
Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_MissingEndBrack)
End If
- Dim ch = PeekAheadChar(Here)
+ Dim ch = Peek(Here)
' check if we can start an ident.
If Not IsIdentifierStartCharacter(ch) OrElse
(IsConnectorPunctuation(ch) AndAlso
Not (CanGetCharAtOffset(Here + 1) AndAlso
- IsIdentifierPartCharacter(PeekAheadChar(Here + 1)))) Then
+ IsIdentifierPartCharacter(Peek(Here + 1)))) Then
InvalidIdentifier = True
End If
' check ident until ]
While CanGetCharAtOffset(Here)
- Dim [Next] As Char = PeekAheadChar(Here)
+ Dim [Next] As Char = Peek(Here)
If [Next] = "]"c OrElse [Next] = FULLWIDTH_RIGHT_SQUARE_BRACKET Then
Dim IdStringLength As Integer = Here - IdStart
@@ -1780,10 +1544,10 @@ FullWidthRepeat:
' // First read a leading base specifier, if present, followed by a sequence of zero
' // or more digits.
- Dim ch = PeekChar()
+ Dim ch = Peek()
If ch = "&"c OrElse ch = FULLWIDTH_AMPERSAND Then
Here += 1
- ch = If(CanGetCharAtOffset(Here), PeekAheadChar(Here), ChrW(0))
+ ch = If(CanGetCharAtOffset(Here), Peek(Here), ChrW(0))
FullWidthRepeat:
Select Case ch
@@ -1793,7 +1557,7 @@ FullWidthRepeat:
Base = LiteralBase.Hexadecimal
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsHexDigit(ch) Then
Exit While
End If
@@ -1806,7 +1570,7 @@ FullWidthRepeat:
Base = LiteralBase.Octal
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsOctalDigit(ch) Then
Exit While
End If
@@ -1825,7 +1589,7 @@ FullWidthRepeat:
' no base specifier - just go through decimal digits.
IntegerLiteralStart = Here
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsDecimalDigit(ch) Then
Exit While
End If
@@ -1840,16 +1604,16 @@ FullWidthRepeat:
' // read the rest of a float literal.
If Base = LiteralBase.Decimal AndAlso CanGetCharAtOffset(Here) Then
' // First read a '.' followed by a sequence of one or more digits.
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If (ch = "."c Or ch = FULLWIDTH_FULL_STOP) AndAlso
CanGetCharAtOffset(Here + 1) AndAlso
- IsDecimalDigit(PeekAheadChar(Here + 1)) Then
+ IsDecimalDigit(Peek(Here + 1)) Then
Here += 2 ' skip dot and first digit
' all following decimal digits belong to the literal (fractional part)
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsDecimalDigit(ch) Then
Exit While
End If
@@ -1860,21 +1624,21 @@ FullWidthRepeat:
' // Read an exponent symbol followed by an optional sign and a sequence of
' // one or more digits.
- If CanGetCharAtOffset(Here) AndAlso BeginsExponent(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso BeginsExponent(Peek(Here)) Then
Here += 1
If CanGetCharAtOffset(Here) Then
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If MatchOneOrAnotherOrFullwidth(ch, "+"c, "-"c) Then
Here += 1
End If
End If
- If CanGetCharAtOffset(Here) AndAlso IsDecimalDigit(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsDecimalDigit(Peek(Here)) Then
Here += 1
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsDecimalDigit(ch) Then
Exit While
End If
@@ -1897,7 +1661,7 @@ FullWidthRepeat:
Dim TypeCharacter As TypeCharacter = TypeCharacter.None
If CanGetCharAtOffset(Here) Then
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
FullWidthRepeat2:
Select Case ch
@@ -1974,7 +1738,7 @@ FullWidthRepeat2:
' check if this was not attempt to use obsolete exponent
If CanGetCharAtOffset(Here + 1) Then
- ch = PeekAheadChar(Here + 1)
+ ch = Peek(Here + 1)
If IsDecimalDigit(ch) OrElse MatchOneOrAnotherOrFullwidth(ch, "+"c, "-"c) Then
Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_ObsoleteExponent)
@@ -1986,7 +1750,7 @@ FullWidthRepeat2:
Case "U"c, "u"c
If literalKind <> NumericLiteralKind.Float AndAlso CanGetCharAtOffset(Here + 1) Then
- Dim NextChar As Char = PeekAheadChar(Here + 1)
+ Dim NextChar As Char = Peek(Here + 1)
'unsigned suffixes - US, UL, UI
If MatchOneOrAnotherOrFullwidth(NextChar, "S"c, "s"c) Then
@@ -2022,12 +1786,12 @@ FullWidthRepeat2:
If IntegerLiteralStart = IntegerLiteralEnd Then
Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_Syntax)
Else
- IntegralValue = IntegralLiteralCharacterValue(PeekAheadChar(IntegerLiteralStart))
+ IntegralValue = IntegralLiteralCharacterValue(Peek(IntegerLiteralStart))
If Base = LiteralBase.Decimal Then
' Init For loop
For LiteralCharacter As Integer = IntegerLiteralStart + 1 To IntegerLiteralEnd - 1
- Dim NextCharacterValue As UInteger = IntegralLiteralCharacterValue(PeekAheadChar(LiteralCharacter))
+ Dim NextCharacterValue As UInteger = IntegralLiteralCharacterValue(Peek(LiteralCharacter))
If IntegralValue < 1844674407370955161UL OrElse
(IntegralValue = 1844674407370955161UL AndAlso NextCharacterValue <= 5UI) Then
@@ -2052,7 +1816,7 @@ FullWidthRepeat2:
Overflows = True
End If
- IntegralValue = (IntegralValue << Shift) + IntegralLiteralCharacterValue(PeekAheadChar(LiteralCharacter))
+ IntegralValue = (IntegralValue << Shift) + IntegralLiteralCharacterValue(Peek(LiteralCharacter))
Next
End If
@@ -2094,7 +1858,7 @@ FullWidthRepeat2:
' // Copy the text of the literal to deal with fullwidth
Dim scratch = GetScratch()
For i = 0 To literalWithoutTypeChar - 1
- Dim curCh = PeekAheadChar(i)
+ Dim curCh = Peek(i)
scratch.Append(If(IsFullWidth(curCh), MakeHalfWidth(curCh), curCh))
Next
Dim LiteralSpelling = GetScratchTextInterned(scratch)
@@ -2168,7 +1932,7 @@ FullWidthRepeat2:
Return False
End If
- Dim ch = PeekAheadChar(Here)
+ Dim ch = Peek(Here)
If Not IsDecimalDigit(ch) Then
Return False
End If
@@ -2177,7 +1941,7 @@ FullWidthRepeat2:
Here += 1
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If Not IsDecimalDigit(ch) Then
Exit While
@@ -2200,7 +1964,7 @@ FullWidthRepeat2:
Private Function ScanDateLiteral(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
Debug.Assert(CanGetChar)
- Debug.Assert(IsHash(PeekChar()))
+ Debug.Assert(IsHash(Peek()))
Dim Here As Integer = 1 'skip #
Dim FirstValue As Integer
@@ -2232,7 +1996,7 @@ FullWidthRepeat2:
' // If we see a /, then it's a date
- If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then
Dim FirstDateSeparator As Integer = Here
' // We've got a date
@@ -2252,10 +2016,10 @@ FullWidthRepeat2:
End If
' Do we have a day value?
- If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then
' // Check to see they used a consistent separator
- If PeekAheadChar(Here) <> PeekAheadChar(FirstDateSeparator) Then
+ If Peek(Here) <> Peek(FirstDateSeparator) Then
GoTo baddate
End If
@@ -2278,10 +2042,10 @@ FullWidthRepeat2:
' // Do we have a year value?
- If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsDateSeparatorCharacter(Peek(Here)) Then
' // Check to see they used a consistent separator
- If PeekAheadChar(Here) <> PeekAheadChar(FirstDateSeparator) Then
+ If Peek(Here) <> Peek(FirstDateSeparator) Then
GoTo baddate
End If
@@ -2321,7 +2085,7 @@ FullWidthRepeat2:
If HaveTimeValue Then
' // Do we see a :?
- If CanGetCharAtOffset(Here) AndAlso IsColon(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsColon(Peek(Here)) Then
Here += 1
' // Now let's get the minute value
@@ -2334,7 +2098,7 @@ FullWidthRepeat2:
' // Do we have a second value?
- If CanGetCharAtOffset(Here) AndAlso IsColon(PeekAheadChar(Here)) Then
+ If CanGetCharAtOffset(Here) AndAlso IsColon(Peek(Here)) Then
' // Yes.
HaveSecondValue = True
Here += 1
@@ -2350,14 +2114,14 @@ FullWidthRepeat2:
' // Check AM/PM
If CanGetCharAtOffset(Here) Then
- If PeekAheadChar(Here) = "A"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_A OrElse
- PeekAheadChar(Here) = "a"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_SMALL_LETTER_A Then
+ If Peek(Here) = "A"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_A OrElse
+ Peek(Here) = "a"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_A Then
HaveAM = True
Here += 1
- ElseIf PeekAheadChar(Here) = "P"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_P OrElse
- PeekAheadChar(Here) = "p"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_SMALL_LETTER_P Then
+ ElseIf Peek(Here) = "P"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_P OrElse
+ Peek(Here) = "p"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_P Then
HavePM = True
Here += 1
@@ -2365,8 +2129,8 @@ FullWidthRepeat2:
End If
If CanGetCharAtOffset(Here) AndAlso (HaveAM OrElse HavePM) Then
- If PeekAheadChar(Here) = "M"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_M OrElse
- PeekAheadChar(Here) = "m"c OrElse PeekAheadChar(Here) = FULLWIDTH_LATIN_SMALL_LETTER_M Then
+ If Peek(Here) = "M"c OrElse Peek(Here) = FULLWIDTH_LATIN_CAPITAL_LETTER_M OrElse
+ Peek(Here) = "m"c OrElse Peek(Here) = FULLWIDTH_LATIN_SMALL_LETTER_M Then
Here = GetWhitespaceLength(Here + 1)
@@ -2383,7 +2147,7 @@ FullWidthRepeat2:
End If
End If
- If Not CanGetCharAtOffset(Here) OrElse Not IsHash(PeekAheadChar(Here)) Then
+ If Not CanGetCharAtOffset(Here) OrElse Not IsHash(Peek(Here)) Then
GoTo baddate
End If
@@ -2490,18 +2254,18 @@ baddate:
' // otherwise, it's not a date
While CanGetCharAtOffset(Here)
- Dim ch As Char = PeekAheadChar(Here)
+ Dim ch As Char = Peek(Here)
If IsHash(ch) OrElse IsNewLine(ch) Then
Exit While
End If
Here += 1
End While
- If Not CanGetCharAtOffset(Here) OrElse IsNewLine(PeekAheadChar(Here)) Then
+ If Not CanGetCharAtOffset(Here) OrElse IsNewLine(Peek(Here)) Then
' // No closing #
Return Nothing
Else
- Debug.Assert(IsHash(PeekAheadChar(Here)))
+ Debug.Assert(IsHash(Peek(Here)))
Here += 1 ' consume trailing #
Return MakeBadToken(precedingTrivia, Here, ERRID.ERR_InvalidDate)
End If
@@ -2509,7 +2273,7 @@ baddate:
Private Function ScanStringLiteral(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As SyntaxToken
Debug.Assert(CanGetChar)
- Debug.Assert(IsDoubleQuote(PeekChar))
+ Debug.Assert(IsDoubleQuote(Peek))
Dim length As Integer = 1
Dim ch As Char
@@ -2518,25 +2282,25 @@ baddate:
' // Check for a Char literal, which can be of the form:
' // """"c or ""c
- If CanGetCharAtOffset(3) AndAlso IsDoubleQuote(PeekAheadChar(2)) Then
- If IsDoubleQuote(PeekAheadChar(1)) Then
- If IsDoubleQuote(PeekAheadChar(3)) AndAlso
+ If CanGetCharAtOffset(3) AndAlso IsDoubleQuote(Peek(2)) Then
+ If IsDoubleQuote(Peek(1)) Then
+ If IsDoubleQuote(Peek(3)) AndAlso
CanGetCharAtOffset(4) AndAlso
- IsLetterC(PeekAheadChar(4)) Then
+ IsLetterC(Peek(4)) Then
' // Double-quote Char literal: """"c
Return MakeCharacterLiteralToken(precedingTrivia, """"c, 5)
End If
- ElseIf IsLetterC(PeekAheadChar(3)) Then
+ ElseIf IsLetterC(Peek(3)) Then
' // Char literal. "x"c
- Return MakeCharacterLiteralToken(precedingTrivia, PeekAheadChar(1), 4)
+ Return MakeCharacterLiteralToken(precedingTrivia, Peek(1), 4)
End If
End If
If CanGetCharAtOffset(2) AndAlso
- IsDoubleQuote(PeekAheadChar(1)) AndAlso
- IsLetterC(PeekAheadChar(2)) Then
+ IsDoubleQuote(Peek(1)) AndAlso
+ IsLetterC(Peek(2)) Then
' // Error. ""c is not a legal char constant
Return MakeBadToken(precedingTrivia, 3, ERRID.ERR_IllegalCharConstant)
@@ -2544,11 +2308,11 @@ baddate:
Dim scratch = GetScratch()
While CanGetCharAtOffset(length)
- ch = PeekAheadChar(length)
+ ch = Peek(length)
If IsDoubleQuote(ch) Then
If CanGetCharAtOffset(length + 1) Then
- ch = PeekAheadChar(length + 1)
+ ch = Peek(length + 1)
If IsDoubleQuote(ch) Then
' // An escaped double quote
@@ -2667,4 +2431,4 @@ baddate:
Return (_isScanningForExpressionCompiler AndAlso c = "$"c) OrElse SyntaxFacts.IsIdentifierStartCharacter(c)
End Function
End Class
-End Namespace
+End Namespace
\ No newline at end of file
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb
index ad575d06cb8c8..1ade4838bda3f 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerBuffer.vb
@@ -4,6 +4,7 @@
' Contains the definition of the Scanner, which produces tokens from text
'-----------------------------------------------------------------------------
+Imports System.Runtime.InteropServices
Imports System.Text
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
@@ -95,14 +96,43 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Return p
End Function
+ Friend Function TryPeek(at As Integer, <[In], Out> ByRef c As Char) As Boolean
+ If Not CanGetCharAtOffset(at) Then Return False
+ c = Peek(at)
+ Return True
+ End Function
+ Friend Function NextAre(ahead As Integer, text As String) As Boolean
+ Dim n = text.Length
+ If Not CanGetCharAtOffset(ahead) Then Return False
+ For i = 0 To n - 1
+ Dim c As Char
+ If TryPeek(i + 1, c) = False OrElse c = text(i) Then Return False
+ Next
+ Return True
+ End Function
+ Friend Function NextAre(ahead As Integer, first As Integer, text As String) As Boolean
+ Dim n = text.Length
+ If Not CanGetCharAtOffset(ahead) Then Return False
+ For i = first To n - 1
+ Dim c As Char
+ If TryPeek(i + 1, c) = False OrElse c = text(i - first) Then Return False
+ Next
+ Return True
+ End Function
+
+ Friend Function PeekIs(ahead As Integer, eq As Char) As Boolean
+ Dim c As Char
+ Return TryPeek(ahead, c) AndAlso (c = eq)
+ End Function
+
' PERF CRITICAL
- Private Function PeekAheadChar(skip As Integer) As Char
- Debug.Assert(CanGetCharAtOffset(skip))
- Debug.Assert(skip >= -MaxCharsLookBehind)
+ Private Function Peek(ahead As Integer) As Char
+ Debug.Assert(CanGetCharAtOffset(ahead))
+ Debug.Assert(ahead >= -MaxCharsLookBehind)
Dim position = _lineBufferOffset
Dim page = _curPage
- position += skip
+ position += ahead
Dim ch = page._arr(position And PAGE_MASK)
@@ -118,24 +148,23 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
' PERF CRITICAL
- Friend Function PeekChar() As Char
+ Friend Function Peek() As Char
Dim page = _curPage
- Dim position = _lineBufferOffset
- Dim ch = page._arr(position And PAGE_MASK)
-
+ Dim pos = _lineBufferOffset
+ Dim ch = page._arr(pos And PAGE_MASK)
Dim start = page._pageStart
- Dim expectedStart = position And NOT_PAGE_MASK
+ Dim expectedStart = pos And NOT_PAGE_MASK
If start <> expectedStart Then
- page = GetPage(position)
- ch = page._arr(position And PAGE_MASK)
+ page = GetPage(pos)
+ ch = page._arr(pos And PAGE_MASK)
End If
Return ch
End Function
Friend Function GetChar() As String
- Return Intern(PeekChar())
+ Return Intern(Peek())
End Function
Friend Function GetText(start As Integer, length As Integer) As String
@@ -157,11 +186,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If page._pageStart = (start And NOT_PAGE_MASK) AndAlso
offsetInPage + length < PAGE_SIZE Then
Dim arr() As Char = page._arr
-
' Always intern CR+LF since it occurs so frequently
- If length = 2 AndAlso arr(offsetInPage) = ChrW(13) AndAlso arr(offsetInPage + 1) = ChrW(10) Then
- Return vbCrLf
- End If
+ If length = 2 AndAlso arr(offsetInPage) = ChrW(13) AndAlso arr(offsetInPage + 1) = ChrW(10) Then Return vbCrLf
Return New String(arr, offsetInPage, length)
End If
@@ -172,18 +198,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim textOffset = start And PAGE_MASK
Dim page = GetPage(start)
- If textOffset + length < PAGE_SIZE Then
- If suppressInterning Then
- Return New String(page._arr, textOffset, length)
- Else
- Return Intern(page._arr, textOffset, length)
- End If
- End If
-
+ If textOffset + length < PAGE_SIZE Then Return If(suppressInterning, New String(page._arr, textOffset, length), Intern(page._arr, textOffset, length))
' make a string builder that is big enough, but not too big
- If _builder Is Nothing Then
- _builder = New StringBuilder(Math.Min(length, 1024))
- End If
+ If _builder Is Nothing Then _builder = New StringBuilder(Math.Min(length, 1024))
Dim cnt = Math.Min(length, PAGE_SIZE - textOffset)
_builder.Append(page._arr, textOffset, cnt)
@@ -201,12 +218,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
start += cnt
Loop While length > 0
- Dim result As String
- If suppressInterning Then
- result = _builder.ToString
- Else
- result = _stringTable.Add(_builder)
- End If
+ Dim result As String = If(suppressInterning, _builder.ToString, _stringTable.Add(_builder))
If result.Length < 1024 Then
_builder.Clear()
Else
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb
index 57215ffbf4467..26db15e7c5ce4 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerInterpolatedString.vb
@@ -10,35 +10,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Partial Friend Class Scanner
Private Function ScanInterpolatedStringPunctuation() As SyntaxToken
- If Not CanGetChar() Then
- Return MakeEndOfInterpolatedStringToken()
- End If
-
+ If Not CanGetChar() Then Return MakeEndOfInterpolatedStringToken()
Dim kind As SyntaxKind
Dim leadingTriviaLength = GetWhitespaceLength(0)
Dim offset = leadingTriviaLength
Dim length As Integer
- If Not CanGetCharAtOffset(offset) Then
- Return MakeEndOfInterpolatedStringToken()
- End If
+ If Not CanGetCharAtOffset(offset) Then Return MakeEndOfInterpolatedStringToken()
- Dim c = PeekAheadChar(offset)
+ Dim c = Peek(offset)
' This should only ever happen for $" or }
Debug.Assert(leadingTriviaLength = 0 OrElse c = "$"c OrElse c = FULLWIDTH_DOLLAR_SIGN OrElse IsRightCurlyBracket(c))
' Another } may follow the close brace of an interpolation if the interpolation lacked a format clause.
' This is because the normal escaping rules only apply when parsing the format string.
- Debug.Assert(Not CanGetCharAtOffset(1) OrElse PeekAheadChar(offset + 1) <> c OrElse IsRightCurlyBracket(c), "Escape sequence not detected.")
+ Debug.Assert(Not CanGetCharAtOffset(1) OrElse Peek(offset + 1) <> c OrElse IsRightCurlyBracket(c), "Escape sequence not detected.")
Dim scanTrailingTrivia As Boolean
Select Case c
Case "$"c, FULLWIDTH_DOLLAR_SIGN
- If CanGetCharAtOffset(offset + 1) AndAlso IsDoubleQuote(PeekAheadChar(offset + 1)) Then
+ If CanGetCharAtOffset(offset + 1) AndAlso IsDoubleQuote(Peek(offset + 1)) Then
kind = SyntaxKind.DollarSignDoubleQuoteToken
length = 2
scanTrailingTrivia = False ' Trailing whitespace should be scanned as interpolated string text.
@@ -74,7 +69,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case Else
If IsDoubleQuote(c) Then
- Debug.Assert(Not CanGetCharAtOffset(offset + 1) OrElse Not IsDoubleQuote(PeekAheadChar(offset + 1)))
+ Debug.Assert(Not CanGetCharAtOffset(offset + 1) OrElse Not IsDoubleQuote(Peek(offset + 1)))
kind = SyntaxKind.DoubleQuoteToken
length = 1
@@ -96,42 +91,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function ScanInterpolatedStringContent() As SyntaxToken
- If IsInterpolatedStringPunctuation() Then
- Return ScanInterpolatedStringPunctuation()
- Else
- Return ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia:=False)
- End If
+ If IsInterpolatedStringPunctuation() Then Return ScanInterpolatedStringPunctuation()
+ Return ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia:=False)
End Function
Private Function ScanInterpolatedStringFormatString() As SyntaxToken
- If IsInterpolatedStringPunctuation() Then
- Return ScanInterpolatedStringPunctuation()
- Else
- Return ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia:=True)
- End If
+ If IsInterpolatedStringPunctuation() Then Return ScanInterpolatedStringPunctuation()
+ Return ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia:=True)
End Function
Private Function IsInterpolatedStringPunctuation(Optional offset As Integer = 0) As Boolean
If Not CanGetCharAtOffset(offset) Then Return False
-
- Dim c = PeekAheadChar(offset)
-
- If IsLeftCurlyBracket(c) Then
- Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsLeftCurlyBracket(PeekAheadChar(offset + 1))
-
- ElseIf IsRightCurlyBracket(c) Then
- Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsRightCurlyBracket(PeekAheadChar(offset + 1))
-
- ElseIf IsDoubleQuote(c)
+ Dim c = Peek(offset)
+ Select Case True
+ Case IsLeftCurlyBracket(c) : Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsLeftCurlyBracket(Peek(offset + 1))
+ Case IsRightCurlyBracket(c) : Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsRightCurlyBracket(Peek(offset + 1))
+ Case IsDoubleQuote(c)
'A subtle difference between this case and the one above.
' In both interpolated and literal strings the two quote characters used in an escape sequence don't have to match.
' It's enough that the next character is *a* quote char. It doesn't have to be the same quote.
' If we want to preserve consistency the quotes need to be special cased.
- Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsDoubleQuote(PeekAheadChar(offset + 1))
-
- Else
+ Return Not CanGetCharAtOffset(offset + 1) OrElse Not IsDoubleQuote(Peek(offset + 1))
+ Case Else
Return False
- End If
+ End Select
End Function
Private Function ScanInterpolatedStringText(scanTrailingWhitespaceAsTrivia As Boolean) As SyntaxToken
@@ -143,14 +126,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Do While CanGetCharAtOffset(offset)
- Dim c = PeekAheadChar(offset)
+ Dim c = Peek(offset)
' Any combination of fullwidth and ASCII curly braces of the same direction is an escaping sequence for the corresponding ASCII curly brace.
' We insert that curly brace doubled and because this is the escaping sequence understood by String.Format, that will be replaced by a single brace.
' This is deliberate design and it aligns with existing rules for double quote escaping in strings.
If IsLeftCurlyBracket(c) Then
- If CanGetCharAtOffset(offset + 1) AndAlso IsLeftCurlyBracket(PeekAheadChar(offset + 1)) Then
+ If CanGetCharAtOffset(offset + 1) AndAlso IsLeftCurlyBracket(Peek(offset + 1)) Then
' This is an escape sequence.
valueBuilder.Append("{{")
@@ -164,7 +147,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
ElseIf IsRightCurlyBracket(c) Then
- If CanGetCharAtOffset(offset + 1) AndAlso IsRightCurlyBracket(PeekAheadChar(offset + 1)) Then
+ If CanGetCharAtOffset(offset + 1) AndAlso IsRightCurlyBracket(Peek(offset + 1)) Then
' This is an escape sequence.
valueBuilder.Append("}}")
@@ -178,7 +161,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
ElseIf IsDoubleQuote(c)
- If CanGetCharAtOffset(offset + 1) AndAlso IsDoubleQuote(PeekAheadChar(offset + 1)) Then
+ If CanGetCharAtOffset(offset + 1) AndAlso IsDoubleQuote(Peek(offset + 1)) Then
' This is a VB double quote escape. Oddly enough this logic allows mixing and matching of
' smart and dumb double quotes in any order. Regardless we always emit as a standard double quote.
' This is consistent with their handling in string literals.
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb b/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb
index 4cbc319537e4a..fe941bb4222cf 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/ScannerXml.vb
@@ -37,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If Not CanGetCharAtOffset(len) Then
Exit Do
End If
- c = PeekAheadChar(len)
+ c = Peek(len)
Loop
If len > 0 Then
@@ -70,7 +70,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim leadingTrivia As SyntaxList(Of VisualBasicSyntaxNode) = Nothing
While CanGetChar()
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case (c)
' // Whitespace
@@ -93,7 +93,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
leadingTrivia = ScanXmlTrivia(c)
Case "/"c
- If CanGetCharAtOffset(1) AndAlso PeekAheadChar(1) = ">" Then
+ If CanGetCharAtOffset(1) AndAlso Peek(1) = ">" Then
Return XmlMakeEndEmptyElementToken(leadingTrivia)
End If
Return XmlMakeDivToken(leadingTrivia)
@@ -114,34 +114,34 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case "<"c
If CanGetCharAtOffset(1) Then
- Dim ch As Char = PeekAheadChar(1)
+ Dim ch As Char = Peek(1)
Select Case ch
Case "!"c
If CanGetCharAtOffset(2) Then
- Select Case (PeekAheadChar(2))
+ Select Case (Peek(2))
Case "-"c
- If CanGetCharAtOffset(3) AndAlso PeekAheadChar(3) = "-"c Then
+ If CanGetCharAtOffset(3) AndAlso Peek(3) = "-"c Then
Return XmlMakeBeginCommentToken(leadingTrivia, _scanNoTriviaFunc)
End If
Case "["c
If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "C"c AndAlso
- PeekAheadChar(4) = "D"c AndAlso
- PeekAheadChar(5) = "A"c AndAlso
- PeekAheadChar(6) = "T"c AndAlso
- PeekAheadChar(7) = "A"c AndAlso
- PeekAheadChar(8) = "["c Then
+ Peek(3) = "C"c AndAlso
+ Peek(4) = "D"c AndAlso
+ Peek(5) = "A"c AndAlso
+ Peek(6) = "T"c AndAlso
+ Peek(7) = "A"c AndAlso
+ Peek(8) = "["c Then
Return XmlMakeBeginCDataToken(leadingTrivia, _scanNoTriviaFunc)
End If
Case "D"c
If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "O"c AndAlso
- PeekAheadChar(4) = "C"c AndAlso
- PeekAheadChar(5) = "T"c AndAlso
- PeekAheadChar(6) = "Y"c AndAlso
- PeekAheadChar(7) = "P"c AndAlso
- PeekAheadChar(8) = "E"c Then
+ Peek(3) = "O"c AndAlso
+ Peek(4) = "C"c AndAlso
+ Peek(5) = "T"c AndAlso
+ Peek(6) = "Y"c AndAlso
+ Peek(7) = "P"c AndAlso
+ Peek(8) = "E"c Then
Return XmlMakeBeginDTDToken(leadingTrivia)
End If
End Select
@@ -149,7 +149,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Return XmlLessThanExclamationToken(state, leadingTrivia)
Case "%"c
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(2) = "=" Then
+ Peek(2) = "=" Then
Return XmlMakeBeginEmbeddedToken(leadingTrivia)
End If
@@ -164,7 +164,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case "?"c
- If CanGetCharAtOffset(1) AndAlso PeekAheadChar(1) = ">"c Then
+ If CanGetCharAtOffset(1) AndAlso Peek(1) = ">"c Then
' // Create token for the '?>' termination sequence
Return XmlMakeEndProcessingInstructionToken(leadingTrivia)
End If
@@ -233,7 +233,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim token As SyntaxToken
Dim possibleStatement As Boolean = False
Dim offsets = CreateOffsetRestorePoint()
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case c
Case "#"c,
@@ -257,7 +257,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
If name IsNot Nothing AndAlso Not name.IsMissing Then
If name.PossibleKeywordKind <> SyntaxKind.XmlNameToken Then
leadingTrivia = ScanSingleLineTrivia()
- c = PeekChar()
+ c = Peek()
possibleStatement =
c = "("c OrElse c = FULLWIDTH_LEFT_PARENTHESIS
End If
@@ -320,7 +320,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim IsAllWhitespace As Boolean = True
' lets do an unusual peek-behind to make sure we are not restarting after a non-Ws char.
If _lineBufferOffset > 0 Then
- Dim prevChar = PeekAheadChar(-1)
+ Dim prevChar = Peek(-1)
If prevChar <> ">"c AndAlso Not XmlCharType.IsWhiteSpace(prevChar) Then
IsAllWhitespace = False
End If
@@ -329,7 +329,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim scratch = GetScratch()
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
@@ -356,47 +356,47 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Else
scratch.Clear() ' will not use this
Here = 0 ' consumed chars.
- precedingTrivia = ScanXmlTrivia(PeekChar)
+ precedingTrivia = ScanXmlTrivia(Peek)
End If
End If
Debug.Assert(Here = 0)
If CanGetCharAtOffset(1) Then
- Dim ch As Char = PeekAheadChar(1)
+ Dim ch As Char = Peek(1)
Select Case ch
Case "!"c
If CanGetCharAtOffset(2) Then
- Select Case (PeekAheadChar(2))
+ Select Case (Peek(2))
Case "-"c
- If CanGetCharAtOffset(3) AndAlso PeekAheadChar(3) = "-"c Then
+ If CanGetCharAtOffset(3) AndAlso Peek(3) = "-"c Then
Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
End If
Case "["c
If CanGetCharAtOffset(8) AndAlso _
- PeekAheadChar(3) = "C"c AndAlso _
- PeekAheadChar(4) = "D"c AndAlso _
- PeekAheadChar(5) = "A"c AndAlso _
- PeekAheadChar(6) = "T"c AndAlso _
- PeekAheadChar(7) = "A"c AndAlso _
- PeekAheadChar(8) = "["c Then
+ Peek(3) = "C"c AndAlso _
+ Peek(4) = "D"c AndAlso _
+ Peek(5) = "A"c AndAlso _
+ Peek(6) = "T"c AndAlso _
+ Peek(7) = "A"c AndAlso _
+ Peek(8) = "["c Then
Return XmlMakeBeginCDataToken(precedingTrivia, _scanNoTriviaFunc)
End If
Case "D"c
If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "O"c AndAlso
- PeekAheadChar(4) = "C"c AndAlso
- PeekAheadChar(5) = "T"c AndAlso
- PeekAheadChar(6) = "Y"c AndAlso
- PeekAheadChar(7) = "P"c AndAlso
- PeekAheadChar(8) = "E"c Then
+ Peek(3) = "O"c AndAlso
+ Peek(4) = "C"c AndAlso
+ Peek(5) = "T"c AndAlso
+ Peek(6) = "Y"c AndAlso
+ Peek(7) = "P"c AndAlso
+ Peek(8) = "E"c Then
Return XmlMakeBeginDTDToken(precedingTrivia)
End If
End Select
End If
Case "%"c
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(2) = "=" Then
+ Peek(2) = "=" Then
Return XmlMakeBeginEmbeddedToken(precedingTrivia)
End If
@@ -411,8 +411,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Case "]"c
If CanGetCharAtOffset(Here + 2) AndAlso _
- PeekAheadChar(Here + 1) = "]"c AndAlso _
- PeekAheadChar(Here + 2) = ">"c Then
+ Peek(Here + 1) = "]"c AndAlso _
+ Peek(Here + 2) = ">"c Then
' // If valid characters found then return them.
If Here <> 0 Then
@@ -529,7 +529,7 @@ ScanChars:
Dim Here = 0
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
@@ -537,7 +537,7 @@ ScanChars:
Case "-"c
If CanGetCharAtOffset(Here + 1) AndAlso _
- PeekAheadChar(Here + 1) = "-"c Then
+ Peek(Here + 1) = "-"c Then
' // --> terminates an Xml comment but otherwise -- is an illegal character sequence.
' // The scanner will always returns "--" as a separate comment data string and the
@@ -550,7 +550,7 @@ ScanChars:
If CanGetCharAtOffset(Here + 2) Then
- c = PeekAheadChar(Here + 2)
+ c = Peek(Here + 2)
Here += 2
' // if > is not found then this is an error. Return the -- string
@@ -622,7 +622,7 @@ ScanChars:
Dim Here = 0
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
@@ -632,8 +632,8 @@ ScanChars:
Case "]"c
If CanGetCharAtOffset(Here + 2) AndAlso _
- PeekAheadChar(Here + 1) = "]"c AndAlso _
- PeekAheadChar(Here + 2) = ">"c Then
+ Peek(Here + 1) = "]"c AndAlso _
+ Peek(Here + 2) = ">"c Then
'// If valid characters found then return them.
If Here <> 0 Then
@@ -690,7 +690,7 @@ ScanChars:
If state = ScannerState.StartProcessingInstruction AndAlso CanGetChar() Then
' // Whitespace
' // S ::= (#x20 | #x9 | #xD | #xA)+
- Dim c = PeekChar()
+ Dim c = Peek()
Select Case c
Case CARRIAGE_RETURN, LINE_FEED, " "c, CHARACTER_TABULATION
Dim wsTrivia = ScanXmlTrivia(c)
@@ -700,7 +700,7 @@ ScanChars:
Dim Here = 0
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
@@ -709,7 +709,7 @@ ScanChars:
Case "?"c
If CanGetCharAtOffset(Here + 1) AndAlso _
- PeekAheadChar(Here + 1) = ">"c Then
+ Peek(Here + 1) = ">"c Then
'// If valid characters found then return them.
If Here <> 0 Then
@@ -761,7 +761,7 @@ CleanUp:
Dim precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode) = Nothing
While CanGetChar()
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case (c)
' // Whitespace
@@ -773,27 +773,27 @@ CleanUp:
Case "<"c
If CanGetCharAtOffset(1) Then
- Dim ch As Char = PeekAheadChar(1)
+ Dim ch As Char = Peek(1)
Select Case ch
Case "!"c
If CanGetCharAtOffset(3) AndAlso
- PeekAheadChar(2) = "-"c AndAlso
- PeekAheadChar(3) = "-"c Then
+ Peek(2) = "-"c AndAlso
+ Peek(3) = "-"c Then
Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
ElseIf CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(2) = "D"c AndAlso
- PeekAheadChar(3) = "O"c AndAlso
- PeekAheadChar(4) = "C"c AndAlso
- PeekAheadChar(5) = "T"c AndAlso
- PeekAheadChar(6) = "Y"c AndAlso
- PeekAheadChar(7) = "P"c AndAlso
- PeekAheadChar(8) = "E"c Then
+ Peek(2) = "D"c AndAlso
+ Peek(3) = "O"c AndAlso
+ Peek(4) = "C"c AndAlso
+ Peek(5) = "T"c AndAlso
+ Peek(6) = "Y"c AndAlso
+ Peek(7) = "P"c AndAlso
+ Peek(8) = "E"c Then
Return XmlMakeBeginDTDToken(precedingTrivia)
End If
Case "%"c
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(2) = "=" Then
+ Peek(2) = "=" Then
Return XmlMakeBeginEmbeddedToken(precedingTrivia)
End If
@@ -849,7 +849,7 @@ CleanUp:
Dim scratch = GetScratch()
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
@@ -876,7 +876,7 @@ CleanUp:
End If
Case "/"c
- If CanGetCharAtOffset(Here + 1) AndAlso PeekAheadChar(Here + 1) = ">"c Then
+ If CanGetCharAtOffset(Here + 1) AndAlso Peek(Here + 1) = ">"c Then
If Here <> 0 Then
Return XmlMakeAttributeDataToken(Nothing, Here, scratch)
Else
@@ -942,7 +942,7 @@ ScanChars:
Dim scratch = GetScratch()
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
If c = terminatingChar Or c = altTerminatingChar Then
If Here > 0 Then
result = XmlMakeAttributeDataToken(precedingTrivia, Here, scratch)
@@ -976,8 +976,8 @@ ScanChars:
Else
' report unexpected <%= in a special way.
If CanGetCharAtOffset(2) AndAlso
- PeekAheadChar(1) = "%"c AndAlso
- PeekAheadChar(2) = "=" Then
+ Peek(1) = "%"c AndAlso
+ Peek(2) = "=" Then
Dim errEmbedStart = XmlMakeAttributeDataToken(precedingTrivia, 3, "<%=")
Dim errEmberinfo = ErrorFactory.ErrorInfo(ERRID.ERR_QuotedEmbeddedExpression)
@@ -1045,10 +1045,10 @@ CleanUp:
Private Function ScanSurrogatePair(c1 As Char, Here As Integer) As XmlCharResult
Debug.Assert(Here >= 0)
Debug.Assert(CanGetCharAtOffset(Here))
- Debug.Assert(PeekAheadChar(Here) = c1)
+ Debug.Assert(Peek(Here) = c1)
If IsHighSurrogate(c1) AndAlso CanGetCharAtOffset(Here + 1) Then
- Dim c2 = PeekAheadChar(Here + 1)
+ Dim c2 = Peek(Here + 1)
If IsLowSurrogate(c2) Then
Return New XmlCharResult(c1, c2)
@@ -1090,7 +1090,7 @@ CleanUp:
Debug.Assert(Here >= 0)
Debug.Assert(CanGetCharAtOffset(Here))
- Dim c = PeekAheadChar(Here)
+ Dim c = Peek(Here)
If Not isValidUtf16(c) Then
Return Nothing
@@ -1122,7 +1122,7 @@ CleanUp:
'TODO - Fix ScanXmlNCName to conform to XML spec instead of old loose scanning.
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
@@ -1199,11 +1199,11 @@ CreateNCNameToken:
Private Function ScanXmlReference(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As XmlTextTokenSyntax
Debug.Assert(CanGetChar)
- Debug.Assert(PeekChar() = "&"c)
+ Debug.Assert(Peek() = "&"c)
' skip 1 char for "&"
If CanGetCharAtOffset(1) Then
- Dim c As Char = PeekAheadChar(1)
+ Dim c As Char = Peek(1)
Select Case (c)
Case "#"c
@@ -1218,7 +1218,7 @@ CreateNCNameToken:
value = Intern({result.Char1, result.Char2})
End If
- If CanGetCharAtOffset(Here) AndAlso PeekAheadChar(Here) = ";"c Then
+ If CanGetCharAtOffset(Here) AndAlso Peek(Here) = ";"c Then
Return XmlMakeEntityLiteralToken(precedingTrivia, Here + 1, value)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, Here, value)
@@ -1232,10 +1232,10 @@ CreateNCNameToken:
' // '
If CanGetCharAtOffset(4) AndAlso
- PeekAheadChar(2) = "m"c AndAlso
- PeekAheadChar(3) = "p"c Then
+ Peek(2) = "m"c AndAlso
+ Peek(3) = "p"c Then
- If PeekAheadChar(4) = ";"c Then
+ If Peek(4) = ";"c Then
Return XmlMakeAmpLiteralToken(precedingTrivia)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 4, "&")
@@ -1244,11 +1244,11 @@ CreateNCNameToken:
End If
ElseIf CanGetCharAtOffset(5) AndAlso
- PeekAheadChar(2) = "p"c AndAlso
- PeekAheadChar(3) = "o"c AndAlso
- PeekAheadChar(4) = "s"c Then
+ Peek(2) = "p"c AndAlso
+ Peek(3) = "o"c AndAlso
+ Peek(4) = "s"c Then
- If PeekAheadChar(5) = ";"c Then
+ If Peek(5) = ";"c Then
Return XmlMakeAposLiteralToken(precedingTrivia)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 5, "'")
@@ -1261,9 +1261,9 @@ CreateNCNameToken:
' // <
If CanGetCharAtOffset(3) AndAlso
- PeekAheadChar(2) = "t"c Then
+ Peek(2) = "t"c Then
- If PeekAheadChar(3) = ";"c Then
+ If Peek(3) = ";"c Then
Return XmlMakeLtLiteralToken(precedingTrivia)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 3, "<")
@@ -1276,9 +1276,9 @@ CreateNCNameToken:
' // >
If CanGetCharAtOffset(3) AndAlso
- PeekAheadChar(2) = "t"c Then
+ Peek(2) = "t"c Then
- If PeekAheadChar(3) = ";"c Then
+ If Peek(3) = ";"c Then
Return XmlMakeGtLiteralToken(precedingTrivia)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 3, ">")
@@ -1291,11 +1291,11 @@ CreateNCNameToken:
' // "
If CanGetCharAtOffset(5) AndAlso
- PeekAheadChar(2) = "u"c AndAlso
- PeekAheadChar(3) = "o"c AndAlso
- PeekAheadChar(4) = "t"c Then
+ Peek(2) = "u"c AndAlso
+ Peek(3) = "o"c AndAlso
+ Peek(4) = "t"c Then
- If PeekAheadChar(5) = ";"c Then
+ If Peek(5) = ";"c Then
Return XmlMakeQuotLiteralToken(precedingTrivia)
Else
Dim noSemicolon = XmlMakeEntityLiteralToken(precedingTrivia, 5, """")
@@ -1324,12 +1324,12 @@ CreateNCNameToken:
Dim charRefSb As New StringBuilder
Dim Here = index
- Dim ch = PeekAheadChar(Here)
+ Dim ch = Peek(Here)
If ch = "x"c Then
Here += 1
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If XmlCharType.IsHexDigit(ch) Then
charRefSb.Append(ch)
Else
@@ -1346,7 +1346,7 @@ CreateNCNameToken:
End If
Else
While CanGetCharAtOffset(Here)
- ch = PeekAheadChar(Here)
+ ch = Peek(Here)
If XmlCharType.IsDigit(ch) Then
charRefSb.Append(ch)
Else
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/TokenFactories.vb b/src/Compilers/VisualBasic/Portable/Scanner/TokenFactories.vb
index 935772988ab10..10e0b80e589cf 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/TokenFactories.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/TokenFactories.vb
@@ -30,10 +30,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Shared ReadOnly triviaKeyEquality As Func(Of TriviaKey, SyntaxTrivia, Boolean) =
Function(key, value) (key.spelling Is value.Text) AndAlso (key.kind = value.Kind)
- Private Shared ReadOnly singleSpaceWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
- Private Shared ReadOnly fourSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
- Private Shared ReadOnly eightSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
- Private Shared ReadOnly twelveSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
+ Private Shared ReadOnly singleSpaceWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
+ Private Shared ReadOnly fourSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
+ Private Shared ReadOnly eightSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
+ Private Shared ReadOnly twelveSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
Private Shared ReadOnly sixteenSpacesWhitespaceTrivia As SyntaxTrivia = SyntaxFactory.WhitespaceTrivia(" ")
@@ -67,14 +67,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Shared ReadOnly wsListKeyEquality As Func(Of SyntaxListBuilder, SyntaxList(Of VisualBasicSyntaxNode), Boolean) =
Function(builder, list)
- If builder.Count <> list.Count Then
- Return False
- End If
-
+ If builder.Count <> list.Count Then Return False
For i = 0 To builder.Count - 1
- If builder(i) IsNot list.ItemUntyped(i) Then
- Return False
- End If
+ If builder(i) IsNot list.ItemUntyped(i) Then Return False
Next
Return True
End Function
@@ -104,15 +99,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Function(key)
Dim code = RuntimeHelpers.GetHashCode(key.spelling)
Dim trivia = key.pTrivia
- If trivia IsNot Nothing Then
- code = code Xor (RuntimeHelpers.GetHashCode(trivia) << 1)
- End If
-
+ If trivia IsNot Nothing Then code = code Xor (RuntimeHelpers.GetHashCode(trivia) << 1)
trivia = key.fTrivia
- If trivia IsNot Nothing Then
- code = code Xor RuntimeHelpers.GetHashCode(trivia)
- End If
-
+ If trivia IsNot Nothing Then code = code Xor RuntimeHelpers.GetHashCode(trivia)
Return code
End Function
@@ -221,66 +210,43 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Friend Function MakeTriviaArray(builder As SyntaxListBuilder) As SyntaxList(Of VisualBasicSyntaxNode)
- If builder.Count = 0 Then
- Return Nothing
- End If
+ If builder.Count = 0 Then Return Nothing
Dim foundTrivia As SyntaxList(Of VisualBasicSyntaxNode) = Nothing
Dim useCache = CanCache(builder)
- If useCache Then
- Return _wslTable.GetOrMakeValue(builder)
- Else
- Return builder.ToList
- End If
+ Return If( useCache, _wslTable.GetOrMakeValue(builder), builder.ToList)
End Function
#End Region
#Region "Identifiers"
- Private Function MakeIdentifier(spelling As String,
- contextualKind As SyntaxKind,
- isBracketed As Boolean,
- BaseSpelling As String,
- TypeCharacter As TypeCharacter,
- leadingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As IdentifierTokenSyntax
-
+ Private Function MakeIdentifier( spelling As String,
+ contextualKind As SyntaxKind,
+ isBracketed As Boolean,
+ BaseSpelling As String,
+ TypeCharacter As TypeCharacter,
+ leadingTrivia As SyntaxList(Of VisualBasicSyntaxNode)
+ ) As IdentifierTokenSyntax
Dim followingTrivia = ScanSingleLineTrivia()
-
- Return MakeIdentifier(spelling,
- contextualKind,
- isBracketed,
- BaseSpelling,
- TypeCharacter,
- leadingTrivia,
- followingTrivia)
-
+ Return MakeIdentifier(spelling, contextualKind, isBracketed, BaseSpelling, TypeCharacter, leadingTrivia, followingTrivia)
End Function
Friend Function MakeIdentifier(keyword As KeywordSyntax) As IdentifierTokenSyntax
- Return MakeIdentifier(keyword.Text,
- keyword.Kind,
- False,
- keyword.Text,
- TypeCharacter.None,
- keyword.GetLeadingTrivia,
- keyword.GetTrailingTrivia)
- End Function
-
- Private Function MakeIdentifier(spelling As String,
- contextualKind As SyntaxKind,
- isBracketed As Boolean,
- BaseSpelling As String,
- TypeCharacter As TypeCharacter,
- precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode),
- followingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As IdentifierTokenSyntax
+ Return MakeIdentifier( keyword.Text, keyword.Kind, False, keyword.Text, TypeCharacter.None, keyword.GetLeadingTrivia, keyword.GetTrailingTrivia)
+ End Function
- Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
+ Private Function MakeIdentifier ( spelling As String,
+ contextualKind As SyntaxKind,
+ isBracketed As Boolean,
+ BaseSpelling As String,
+ TypeCharacter As TypeCharacter,
+ precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode),
+ followingTrivia As SyntaxList(Of VisualBasicSyntaxNode)
+ ) As IdentifierTokenSyntax
+ Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
Dim id As IdentifierTokenSyntax = Nothing
- If _idTable.TryGetValue(tp, id) Then
- Return id
- End If
-
+ If _idTable.TryGetValue(tp, id) Then Return id
If contextualKind <> SyntaxKind.IdentifierToken OrElse
isBracketed = True OrElse
TypeCharacter <> TypeCharacter.None Then
@@ -298,36 +264,23 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "Keywords"
- Private Function MakeKeyword(tokenType As SyntaxKind,
- spelling As String,
- precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As KeywordSyntax
-
+ Private Function MakeKeyword(tokenType As SyntaxKind, spelling As String, precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As KeywordSyntax
Dim followingTrivia = ScanSingleLineTrivia()
-
- Return MakeKeyword(tokenType,
- spelling,
- precedingTrivia,
- followingTrivia)
+ Return MakeKeyword(tokenType, spelling, precedingTrivia, followingTrivia)
End Function
- Friend Function MakeKeyword(identifier As IdentifierTokenSyntax) As KeywordSyntax
- Debug.Assert(identifier.PossibleKeywordKind <> SyntaxKind.IdentifierToken AndAlso
- Not identifier.IsBracketed AndAlso
- (identifier.TypeCharacter = TypeCharacter.None OrElse identifier.PossibleKeywordKind = SyntaxKind.MidKeyword))
+ Friend Function MakeKeyword(id As IdentifierTokenSyntax) As KeywordSyntax
+ Debug.Assert(id.PossibleKeywordKind <> SyntaxKind.IdentifierToken AndAlso
+ Not id.IsBracketed AndAlso
+ (id.TypeCharacter = TypeCharacter.None OrElse id.PossibleKeywordKind = SyntaxKind.MidKeyword))
- Return MakeKeyword(identifier.PossibleKeywordKind,
- identifier.Text,
- identifier.GetLeadingTrivia,
- identifier.GetTrailingTrivia)
+ Return MakeKeyword(id.PossibleKeywordKind, id.Text, id.GetLeadingTrivia, id.GetTrailingTrivia)
End Function
Friend Function MakeKeyword(xmlName As XmlNameTokenSyntax) As KeywordSyntax
Debug.Assert(xmlName.PossibleKeywordKind <> SyntaxKind.XmlNameToken)
- Return MakeKeyword(xmlName.PossibleKeywordKind,
- xmlName.Text,
- xmlName.GetLeadingTrivia,
- xmlName.GetTrailingTrivia)
+ Return MakeKeyword(xmlName.PossibleKeywordKind, xmlName.Text, xmlName.GetLeadingTrivia, xmlName.GetTrailingTrivia)
End Function
Private Function MakeKeyword(tokenType As SyntaxKind,
@@ -338,9 +291,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
Dim kw As KeywordSyntax = Nothing
- If _kwTable.TryGetValue(tp, kw) Then
- Return kw
- End If
+ If _kwTable.TryGetValue(tp, kw) Then Return kw
kw = New KeywordSyntax(tokenType, spelling, precedingTrivia.Node, followingTrivia.Node)
_kwTable.Add(tp, kw)
@@ -375,10 +326,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
Dim p As PunctuationSyntax = Nothing
- If _punctTable.TryGetValue(tp, p) Then
- Return p
- End If
-
+ If _punctTable.TryGetValue(tp, p) Then Return p
p = New PunctuationSyntax(kind, spelling, precedingTrivia.Node, followingTrivia.Node)
_punctTable.Add(tp, p)
Return p
@@ -448,7 +396,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function MakeColonToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), charIsFullWidth As Boolean) As PunctuationSyntax
- Debug.Assert(PeekChar() = If(charIsFullWidth, FULLWIDTH_COLON, ":"c))
+ Debug.Assert(Peek() = If(charIsFullWidth, FULLWIDTH_COLON, ":"c))
Debug.Assert(Not precedingTrivia.Any())
Dim width = _endOfTerminatorTrivia - _lineBufferOffset
@@ -625,22 +573,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim spelling = GetText(length)
Dim followingTrivia = ScanSingleLineTrivia()
-
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
-
Dim p As SyntaxToken = Nothing
- If _literalTable.TryGetValue(tp, p) Then
- Return p
- End If
-
- p = SyntaxFactory.IntegerLiteralToken(
- spelling,
- base,
- typeCharacter,
- integralValue,
- precedingTrivia.Node,
- followingTrivia.Node)
-
+ If _literalTable.TryGetValue(tp, p) Then Return p
+ p = SyntaxFactory.IntegerLiteralToken( spelling, base, typeCharacter, integralValue, precedingTrivia.Node, followingTrivia.Node)
_literalTable.Add(tp, p)
Return p
End Function
@@ -648,14 +584,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function MakeCharacterLiteralToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), value As Char, length As Integer) As SyntaxToken
Dim spelling = GetText(length)
Dim followingTrivia = ScanSingleLineTrivia()
-
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
-
Dim p As SyntaxToken = Nothing
- If _literalTable.TryGetValue(tp, p) Then
- Return p
- End If
-
+ If _literalTable.TryGetValue(tp, p) Then Return p
p = SyntaxFactory.CharacterLiteralToken(spelling, value, precedingTrivia.Node, followingTrivia.Node)
_literalTable.Add(tp, p)
Return p
@@ -664,14 +595,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function MakeDateLiteralToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), value As DateTime, length As Integer) As SyntaxToken
Dim spelling = GetText(length)
Dim followingTrivia = ScanSingleLineTrivia()
-
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
-
Dim p As SyntaxToken = Nothing
- If _literalTable.TryGetValue(tp, p) Then
- Return p
- End If
-
+ If _literalTable.TryGetValue(tp, p) Then Return p
p = SyntaxFactory.DateLiteralToken(spelling, value, precedingTrivia.Node, followingTrivia.Node)
_literalTable.Add(tp, p)
Return p
@@ -684,21 +610,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim spelling = GetText(length)
Dim followingTrivia = ScanSingleLineTrivia()
-
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
-
Dim p As SyntaxToken = Nothing
- If _literalTable.TryGetValue(tp, p) Then
- Return p
- End If
-
- p = SyntaxFactory.FloatingLiteralToken(
- spelling,
- typeCharacter,
- floatingValue,
- precedingTrivia.Node,
- followingTrivia.Node)
-
+ If _literalTable.TryGetValue(tp, p) Then Return p
+ p = SyntaxFactory.FloatingLiteralToken( spelling, typeCharacter, floatingValue, precedingTrivia.Node, followingTrivia.Node)
_literalTable.Add(tp, p)
Return p
End Function
@@ -714,17 +629,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim tp As New TokenParts(precedingTrivia, followingTrivia, spelling)
Dim p As SyntaxToken = Nothing
- If _literalTable.TryGetValue(tp, p) Then
- Return p
- End If
-
- p = SyntaxFactory.DecimalLiteralToken(
- spelling,
- typeCharacter,
- decimalValue,
- precedingTrivia.Node,
- followingTrivia.Node)
-
+ If _literalTable.TryGetValue(tp, p) Then Return p
+ p = SyntaxFactory.DecimalLiteralToken( spelling, typeCharacter, decimalValue, precedingTrivia.Node, followingTrivia.Node)
_literalTable.Add(tp, p)
Return p
End Function
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/TokenStream.vb b/src/Compilers/VisualBasic/Portable/Scanner/TokenStream.vb
index 4fde0ae08af31..cf363d62dabbd 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/TokenStream.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/TokenStream.vb
@@ -202,13 +202,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Friend ReadOnly Property LastToken As SyntaxToken
Get
Dim count = _tokens.Count
- If count > 0 Then
- Return _tokens(count - 1).InnerTokenObject
- ElseIf _currentToken.InnerTokenObject IsNot Nothing Then
- Return _currentToken.InnerTokenObject
- Else
- Return _prevToken.InnerTokenObject
- End If
+ If count > 0 Then Return _tokens(count - 1).InnerTokenObject
+ If _currentToken.InnerTokenObject IsNot Nothing Then Return _currentToken.InnerTokenObject
+ Return _prevToken.InnerTokenObject
End Get
End Property
@@ -387,11 +383,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Friend Function PeekNextToken(state As ScannerState) As SyntaxToken
If _tokens.Count > 0 Then
Dim tk = _tokens(0)
- If tk.State = state Then
- Return tk.InnerTokenObject
- Else
- AbandonPeekedTokens()
- End If
+ If tk.State = state Then Return tk.InnerTokenObject
+ AbandonPeekedTokens()
End If
' ensure that current token has been read
@@ -425,22 +418,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End If
' just want the token #1
- If tokenOffset = 1 Then
- Return PeekNextToken(state)
- End If
-
+ If tokenOffset = 1 Then Return PeekNextToken(state)
Dim offsetInQueue = tokenOffset - 1
Debug.Assert(offsetInQueue <= _tokens.Count)
' asking for next after already read (common case)
- If offsetInQueue = _tokens.Count Then
- Return GetTokenAndAddToQueue(state)
- End If
-
+ If offsetInQueue = _tokens.Count Then Return GetTokenAndAddToQueue(state)
' already have in right state
- If offsetInQueue < _tokens.Count AndAlso _tokens(offsetInQueue).State = state Then
- Return _tokens(offsetInQueue).InnerTokenObject
- End If
+ If offsetInQueue < _tokens.Count AndAlso _tokens(offsetInQueue).State = state Then Return _tokens(offsetInQueue).InnerTokenObject
' we have tokens at given offset (and maybe after), but they are not in right state.
' need to rollback
@@ -477,10 +462,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Sub
Private Sub AbandonPeekedTokens()
- If _tokens.Count = 0 Then
- Return
- End If
-
+ If _tokens.Count = 0 Then Return
RevertState(_tokens(0))
_tokens.Clear()
End Sub
@@ -525,9 +507,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function SaveAndClearTokens() As ScannerToken()
- If _tokens.Count = 0 Then
- Return Nothing
- End If
+ If _tokens.Count = 0 Then Return Nothing
Dim tokens = _tokens.ToArray()
_tokens.Clear()
Return tokens
@@ -535,9 +515,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Sub RestoreTokens(tokens As ScannerToken())
_tokens.Clear()
- If tokens IsNot Nothing Then
- _tokens.AddRange(tokens)
- End If
+ If tokens IsNot Nothing Then _tokens.AddRange(tokens)
End Sub
Private Structure LineBufferAndEndOfTerminatorOffsets
@@ -573,74 +551,37 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Sub
Private Function GetScannerToken(state As ScannerState) As SyntaxToken
- Dim token As SyntaxToken = Nothing
-
Select Case state
- Case ScannerState.VB
- token = Me.GetNextToken(allowLeadingMultilineTrivia:=False)
-
- Case ScannerState.VBAllowLeadingMultilineTrivia
- token = Me.GetNextToken(allowLeadingMultilineTrivia:=Not IsScanningDirective)
-
- Case ScannerState.Misc
- token = Me.ScanXmlMisc()
-
- Case ScannerState.Element,
- ScannerState.EndElement,
- ScannerState.DocType
- token = Me.ScanXmlElement(state)
-
- Case ScannerState.Content
- token = Me.ScanXmlContent()
-
- Case ScannerState.CData
- token = Me.ScanXmlCData()
-
- Case ScannerState.StartProcessingInstruction,
- ScannerState.ProcessingInstruction
- token = Me.ScanXmlPIData(state)
-
- Case ScannerState.Comment
- token = Me.ScanXmlComment()
-
- Case ScannerState.SingleQuotedString
- token = Me.ScanXmlStringSingle()
-
- Case ScannerState.SmartSingleQuotedString
- token = Me.ScanXmlStringSmartSingle()
-
- Case ScannerState.QuotedString
- token = Me.ScanXmlStringDouble()
-
- Case ScannerState.SmartQuotedString
- token = Me.ScanXmlStringSmartDouble()
-
- Case ScannerState.UnQuotedString
- token = Me.ScanXmlStringUnQuoted()
-
- Case ScannerState.InterpolatedStringPunctuation
- token = Me.ScanInterpolatedStringPunctuation()
-
- Case ScannerState.InterpolatedStringContent
- token = Me.ScanInterpolatedStringContent()
-
- Case ScannerState.InterpolatedStringFormatString
- token = Me.ScanInterpolatedStringFormatString()
-
+ Case ScannerState.VB : Return Me.GetNextToken(allowLeadingMultilineTrivia:=False)
+ Case ScannerState.VBAllowLeadingMultilineTrivia : Return Me.GetNextToken(allowLeadingMultilineTrivia:=Not IsScanningDirective)
+ Case ScannerState.Misc : Return Me.ScanXmlMisc()
+ Case ScannerState.Element,
+ ScannerState.EndElement,
+ ScannerState.DocType : Return Me.ScanXmlElement(state)
+ Case ScannerState.Content : Return Me.ScanXmlContent()
+ Case ScannerState.CData : Return Me.ScanXmlCData()
+ Case ScannerState.StartProcessingInstruction,
+ ScannerState.ProcessingInstruction : Return Me.ScanXmlPIData(state)
+ Case ScannerState.Comment : Return Me.ScanXmlComment()
+ Case ScannerState.SingleQuotedString : Return Me.ScanXmlStringSingle()
+ Case ScannerState.SmartSingleQuotedString : Return Me.ScanXmlStringSmartSingle()
+ Case ScannerState.QuotedString : Return Me.ScanXmlStringDouble()
+ Case ScannerState.SmartQuotedString : Return Me.ScanXmlStringSmartDouble()
+ Case ScannerState.UnQuotedString : Return Me.ScanXmlStringUnQuoted()
+ Case ScannerState.InterpolatedStringPunctuation : Return Me.ScanInterpolatedStringPunctuation()
+ Case ScannerState.InterpolatedStringContent : Return Me.ScanInterpolatedStringContent()
+ Case ScannerState.InterpolatedStringFormatString : Return Me.ScanInterpolatedStringFormatString()
Case Else
Throw ExceptionUtilities.UnexpectedValue(state)
-
End Select
-
- Return token
End Function
Protected Structure ScannerToken
- Friend Sub New(preprocessorState As PreprocessorState,
- lineBufferOffset As Integer,
+ Friend Sub New(preprocessorState As PreprocessorState,
+ lineBufferOffset As Integer,
endOfTerminatorTrivia As Integer,
- token As SyntaxToken,
- state As ScannerState)
+ token As SyntaxToken,
+ state As ScannerState)
Me.PreprocessorState = preprocessorState
Me.Position = lineBufferOffset
Me.EndOfTerminatorTrivia = endOfTerminatorTrivia
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/XmlCharacterGlobalHelpers.vb b/src/Compilers/VisualBasic/Portable/Scanner/XmlCharacterGlobalHelpers.vb
index 334353d146dd9..d9e4f7a87d41b 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/XmlCharacterGlobalHelpers.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/XmlCharacterGlobalHelpers.vb
@@ -28,14 +28,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Friend Function HexToUTF16(pwcText As StringBuilder) As Scanner.XmlCharResult
Debug.Assert(pwcText IsNot Nothing)
-
Dim ulCode As UInteger
- If TryHexToUnicode(pwcText, ulCode) Then
-
- If ValidateXmlChar(ulCode) Then
- Return UnicodeToUTF16(ulCode)
- End If
- End If
+ If TryHexToUnicode(pwcText, ulCode) AndAlso ValidateXmlChar(ulCode) Then Return UnicodeToUTF16(ulCode)
Return Nothing
End Function
@@ -49,26 +43,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
For i = 0 To n
wch = pwcText(i)
-
- If XmlCharType.InRange(wch, "0"c, "9"c) Then
- ulCode = (ulCode * 16UI) + CUInt(AscW(wch)) - CUInt(AscW("0"c))
-
- ElseIf XmlCharType.InRange(wch, "a"c, "f"c) Then
- ulCode = (ulCode * 16UI) + 10UI + CUInt(AscW(wch)) - CUInt(AscW("a"c))
-
- ElseIf XmlCharType.InRange(wch, "A"c, "F"c) Then
- ulCode = (ulCode * 16UI) + 10UI + CUInt(AscW(wch)) - CUInt(AscW("A"c))
- Else
- Return False
- End If
-
- If ulCode > &H10FFFF Then
- ' // overflow
- Return False
- End If
-
+ Select Case True
+ Case XmlCharType.InRange(wch, "0"c, "9"c) : ulCode = (ulCode * 16UI) + CUInt(AscW(wch)) - CUInt(AscW("0"c))
+ Case XmlCharType.InRange(wch, "a"c, "f"c) : ulCode = (ulCode * 16UI) + 10UI + CUInt(AscW(wch)) - CUInt(AscW("a"c))
+ Case XmlCharType.InRange(wch, "A"c, "F"c) : ulCode = (ulCode * 16UI) + 10UI + CUInt(AscW(wch)) - CUInt(AscW("A"c))
+ Case Else
+ Return False
+ End Select
+ If ulCode > &H10FFFF Then Return False ' // overflow
Next
-
pulCode = CUInt(ulCode)
Return True
End Function
@@ -76,19 +59,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Friend Function DecToUTF16(pwcText As StringBuilder) As Scanner.XmlCharResult
Debug.Assert(pwcText IsNot Nothing)
Dim ulCode As UShort
-
- If TryDecToUnicode(pwcText, ulCode) Then
- If ValidateXmlChar(ulCode) Then
- Return UnicodeToUTF16(ulCode)
- End If
- End If
+ If TryDecToUnicode(pwcText, ulCode) AndAlso ValidateXmlChar(ulCode) Then Return UnicodeToUTF16(ulCode)
Return Nothing
End Function
- Friend Function TryDecToUnicode(
- pwcText As StringBuilder,
- ByRef pulCode As UShort
- ) As Boolean
+ Friend Function TryDecToUnicode( pwcText As StringBuilder, ByRef pulCode As UShort ) As Boolean
Debug.Assert(pwcText IsNot Nothing)
Dim ulCode As Integer = 0
@@ -96,20 +71,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim n = pwcText.Length - 1
For i = 0 To n
-
wch = pwcText(i)
-
- If XmlCharType.InRange(wch, "0"c, "9"c) Then
- ulCode = (ulCode * 10) + AscW(wch) - AscW("0"c)
- Else
- Return False
- End If
-
- If ulCode > &H10FFFF Then
- ' // overflow
-
- Return False
- End If
+ If Not XmlCharType.InRange(wch, "0"c, "9"c) Then Return False
+ ulCode = (ulCode * 10) + AscW(wch) - AscW("0"c)
+ If ulCode > &H10FFFF Then Return False' // overflow
Next
pulCode = CUShort(ulCode)
@@ -128,15 +93,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function UnicodeToUTF16(ulCode As UInteger) As Scanner.XmlCharResult
- If ulCode > &HFFFF Then
-
- Return New Scanner.XmlCharResult( _
- Convert.ToChar(&HD7C0US + (ulCode >> 10US)), _
- Convert.ToChar(&HDC00US Or (ulCode And &H3FFUS)) _
- )
- Else
- Return New Scanner.XmlCharResult(Convert.ToChar(ulCode))
- End If
+ If ulCode <= &HFFFF Then Return New Scanner.XmlCharResult(Convert.ToChar(ulCode))
+ Return New Scanner.XmlCharResult(Convert.ToChar(&HD7C0US + (ulCode >> 10US)), Convert.ToChar(&HDC00US Or (ulCode And &H3FFUS)) )
End Function
Friend Function UTF16ToUnicode(ch As Scanner.XmlCharResult) As Integer
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/XmlDocComments.vb b/src/Compilers/VisualBasic/Portable/Scanner/XmlDocComments.vb
index 4d1affff4a98b..0694cfb1cd2dc 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/XmlDocComments.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/XmlDocComments.vb
@@ -10,6 +10,7 @@ Imports System.Text
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.CodeAnalysis.VisualBasic.SyntaxFacts
+Imports Exts.Char
Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Partial Friend Class Scanner
@@ -51,7 +52,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Debug.Assert(IsAtNewLine)
' leading whitespace until we see ''' should be regular whitespace
- If CanGetChar() AndAlso IsWhitespace(PeekChar()) Then
+ If CanGetChar() AndAlso IsWhitespace(Peek()) Then
Dim ws = ScanWhitespace()
tList.Add(ws)
End If
@@ -149,20 +150,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function TrySkipXmlDocMarker(ByRef len As Integer) As Boolean
Dim Here = len
While CanGetCharAtOffset(Here)
- Dim c = PeekAheadChar(Here)
- If IsWhitespace(c) Then
- Here += 1
- Else
- Exit While
- End If
+ Dim c = Peek(Here)
+ If Not IsWhitespace(c) Then Exit While
+ Here += 1
End While
- If StartsXmlDoc(Here) Then
- len = Here + 3
- Return True
- Else
- Return False
- End If
+ If StartsXmlDoc(Here) Then len = Here + 3 : Return True
+ Return False
+
End Function
' scans (ws)'''
@@ -170,11 +165,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Debug.Assert(IsAtNewLine() OrElse IsStartingFirstXmlDocLine)
Dim len = 0
- If TrySkipXmlDocMarker(len) Then
- Return MakeDocumentationCommentExteriorTrivia(GetText(len))
- Else
- Return Nothing
- End If
+ If TrySkipXmlDocMarker(len) Then Return MakeDocumentationCommentExteriorTrivia(GetText(len))
+ Return Nothing
End Function
'''
@@ -182,11 +174,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
'''
Private Function ScanXmlTriviaInXmlDoc(c As Char, triviaList As SyntaxListBuilder(Of VisualBasicSyntaxNode)) As Boolean
Debug.Assert(IsScanningXmlDoc)
- Debug.Assert(c = CARRIAGE_RETURN OrElse c = LINE_FEED OrElse c = " "c OrElse c = CHARACTER_TABULATION)
+ Debug.Assert(c.IsAnyOf(CARRIAGE_RETURN, LINE_FEED, " "c, CHARACTER_TABULATION))
Dim len = 0
Do
- If c = " "c OrElse c = CHARACTER_TABULATION Then
+ If c.IsAnyOf(" "c, CHARACTER_TABULATION) Then
len += 1
ElseIf IsNewLine(c) Then
@@ -212,7 +204,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Exit Do
End If
- c = PeekAheadChar(len)
+ c = Peek(len)
Loop
If len > 0 Then
@@ -242,13 +234,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Dim scratch = GetScratch()
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
- If Here <> 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- End If
+ If Here <> 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
Here = SkipLineBreak(c, Here)
@@ -270,69 +260,37 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Here += 1
Case "&"c
- If Here <> 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- End If
+ If Here <> 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
Return ScanXmlReference(precedingTrivia)
Case "<"c
- If Here <> 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- End If
+ If Here <> 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
Debug.Assert(Here = 0)
If CanGetCharAtOffset(1) Then
- Dim ch As Char = PeekAheadChar(1)
+ Dim ch As Char = Peek(1)
Select Case ch
Case "!"c
If CanGetCharAtOffset(2) Then
- Select Case (PeekAheadChar(2))
- Case "-"c
- If CanGetCharAtOffset(3) AndAlso PeekAheadChar(3) = "-"c Then
- Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
- End If
- Case "["c
- If CanGetCharAtOffset(8) AndAlso _
- PeekAheadChar(3) = "C"c AndAlso _
- PeekAheadChar(4) = "D"c AndAlso _
- PeekAheadChar(5) = "A"c AndAlso _
- PeekAheadChar(6) = "T"c AndAlso _
- PeekAheadChar(7) = "A"c AndAlso _
- PeekAheadChar(8) = "["c Then
-
- Return XmlMakeBeginCDataToken(precedingTrivia, _scanNoTriviaFunc)
- End If
- Case "D"c
- If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "O"c AndAlso
- PeekAheadChar(4) = "C"c AndAlso
- PeekAheadChar(5) = "T"c AndAlso
- PeekAheadChar(6) = "Y"c AndAlso
- PeekAheadChar(7) = "P"c AndAlso
- PeekAheadChar(8) = "E"c Then
- Return XmlMakeBeginDTDToken(precedingTrivia)
- End If
+ Select Case (Peek(2))
+ Case "-"c : If PeekIs(3,"-"c) Then Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "["c : If NextAre(8, 3, "CDATA[") Then Return XmlMakeBeginCDataToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "D"c : If NextAre(8, 3, "OCTYPE") Then Return XmlMakeBeginDTDToken(precedingTrivia)
End Select
End If
- Case "?"c
- Return XmlMakeBeginProcessingInstructionToken(precedingTrivia, _scanNoTriviaFunc)
- Case "/"c
- Return XmlMakeBeginEndElementToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "?"c : Return XmlMakeBeginProcessingInstructionToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "/"c : Return XmlMakeBeginEndElementToken(precedingTrivia, _scanNoTriviaFunc)
End Select
End If
Return XmlMakeLessToken(precedingTrivia)
Case "]"c
- If CanGetCharAtOffset(Here + 2) AndAlso _
- PeekAheadChar(Here + 1) = "]"c AndAlso _
- PeekAheadChar(Here + 2) = ">"c Then
+ If NextAre(Here, 1, "]>") Then
' // If valid characters found then return them.
- If Here <> 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- End If
+ If Here <> 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
' // Create an invalid character data token for the illegal ']]>' sequence
Return XmlMakeTextLiteralToken(precedingTrivia, 3, ERRID.ERR_XmlEndCDataNotAllowedInContent)
@@ -345,11 +303,9 @@ ScanChars:
If xmlCh.Length = 0 Then
' bad char
- If Here > 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- Else
- Return XmlMakeBadToken(precedingTrivia, 1, ERRID.ERR_IllegalChar)
- End If
+ If Here > 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
+
+ Return XmlMakeBadToken(precedingTrivia, 1, ERRID.ERR_IllegalChar)
End If
xmlCh.AppendTo(scratch)
@@ -358,11 +314,8 @@ ScanChars:
End While
' no more chars
- If Here > 0 Then
- Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
- Else
- Return MakeEofToken(precedingTrivia)
- End If
+ If Here > 0 Then Return XmlMakeTextLiteralToken(precedingTrivia, Here, scratch)
+ Return MakeEofToken(precedingTrivia)
End Function
Friend Function ScanXmlPIDataInXmlDoc(state As ScannerState) As SyntaxToken
@@ -379,16 +332,14 @@ ScanChars:
If IsAtNewLine() Then
Dim xDocTrivia = ScanXmlDocTrivia()
- If xDocTrivia Is Nothing Then
- Return MakeEofToken() ' XmlDoc lines must start with XmlDocTrivia
- End If
+ If xDocTrivia Is Nothing Then Return MakeEofToken() ' XmlDoc lines must start with XmlDocTrivia
precedingTrivia.Add(xDocTrivia)
End If
If state = ScannerState.StartProcessingInstruction AndAlso CanGetChar() Then
' // Whitespace
' // S ::= (#x20 | #x9 | #xD | #xA)+
- Dim c = PeekChar()
+ Dim c = Peek()
Select Case c
Case CARRIAGE_RETURN, LINE_FEED, " "c, CHARACTER_TABULATION
Dim offsets = CreateOffsetRestorePoint()
@@ -403,7 +354,7 @@ ScanChars:
Dim Here = 0
While CanGetCharAtOffset(Here)
- Dim c As Char = PeekAheadChar(Here)
+ Dim c As Char = Peek(Here)
Select Case (c)
Case CARRIAGE_RETURN, LINE_FEED
@@ -411,8 +362,7 @@ ScanChars:
GoTo CleanUp
Case "?"c
- If CanGetCharAtOffset(Here + 1) AndAlso _
- PeekAheadChar(Here + 1) = ">"c Then
+ If PeekIs(Here + 1, ">"c) Then
'// If valid characters found then return them.
If Here <> 0 Then
@@ -437,11 +387,10 @@ ScanChars:
' bad char
If Here <> 0 Then
result = XmlMakeProcessingInstructionToken(precedingTrivia.ToList, Here)
- GoTo CleanUp
Else
result = XmlMakeBadToken(precedingTrivia.ToList, 1, ERRID.ERR_IllegalChar)
- GoTo CleanUp
End If
+ GoTo CleanUp
End Select
End While
@@ -471,9 +420,7 @@ CleanUp:
If IsAtNewLine() AndAlso Not Me.DoNotRequireXmlDocCommentPrefix Then
Dim xDocTrivia = ScanXmlDocTrivia()
- If xDocTrivia Is Nothing Then
- Return MakeEofToken() ' XmlDoc lines must start with XmlDocTrivia
- End If
+ If xDocTrivia Is Nothing Then Return MakeEofToken() ' XmlDoc lines must start with XmlDocTrivia
precedingTrivia = New SyntaxList(Of VisualBasicSyntaxNode)(xDocTrivia)
End If
@@ -485,7 +432,7 @@ CleanUp:
Return MakeEofToken(precedingTrivia)
End If
- Dim c As Char = PeekChar()
+ Dim c As Char = Peek()
Select Case (c)
' // Whitespace
@@ -504,16 +451,12 @@ CleanUp:
End If
Case "/"c
- If CanGetCharAtOffset(1) AndAlso PeekAheadChar(1) = ">" Then
- Return XmlMakeEndEmptyElementToken(precedingTrivia)
- End If
- Return XmlMakeDivToken(precedingTrivia)
+ If PeekIs(1,">"c) Then Return XmlMakeEndEmptyElementToken(precedingTrivia)
- Case ">"c
- Return XmlMakeGreaterToken(precedingTrivia)
+ Return XmlMakeDivToken(precedingTrivia)
- Case "="c
- Return XmlMakeEqualsToken(precedingTrivia)
+ Case ">"c : Return XmlMakeGreaterToken(precedingTrivia)
+ Case "="c : Return XmlMakeEqualsToken(precedingTrivia)
Case "'"c, LEFT_SINGLE_QUOTATION_MARK, RIGHT_SINGLE_QUOTATION_MARK
Return XmlMakeSingleQuoteToken(precedingTrivia, c, isOpening:=True)
@@ -523,78 +466,35 @@ CleanUp:
Case "<"c
If CanGetCharAtOffset(1) Then
- Dim ch As Char = PeekAheadChar(1)
+ Dim ch As Char = Peek(1)
Select Case ch
Case "!"c
If CanGetCharAtOffset(2) Then
- Select Case (PeekAheadChar(2))
- Case "-"c
- If CanGetCharAtOffset(3) AndAlso PeekAheadChar(3) = "-"c Then
- Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
- End If
- Case "["c
- If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "C"c AndAlso
- PeekAheadChar(4) = "D"c AndAlso
- PeekAheadChar(5) = "A"c AndAlso
- PeekAheadChar(6) = "T"c AndAlso
- PeekAheadChar(7) = "A"c AndAlso
- PeekAheadChar(8) = "["c Then
-
- Return XmlMakeBeginCDataToken(precedingTrivia, _scanNoTriviaFunc)
- End If
- Case "D"c
- If CanGetCharAtOffset(8) AndAlso
- PeekAheadChar(3) = "O"c AndAlso
- PeekAheadChar(4) = "C"c AndAlso
- PeekAheadChar(5) = "T"c AndAlso
- PeekAheadChar(6) = "Y"c AndAlso
- PeekAheadChar(7) = "P"c AndAlso
- PeekAheadChar(8) = "E"c Then
- Return XmlMakeBeginDTDToken(precedingTrivia)
- End If
+ Select Case (Peek(2))
+ Case "-"c : If PeekIs(3,"-"c) Then Return XmlMakeBeginCommentToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "["c : If NextAre(8,3,"CDATA[") Then Return XmlMakeBeginCDataToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "D"c : If NextAre(8,3,"OCTYPE") Then Return XmlMakeBeginDTDToken(precedingTrivia)
End Select
End If
Return XmlLessThanExclamationToken(state, precedingTrivia)
- Case "?"c
- Return XmlMakeBeginProcessingInstructionToken(precedingTrivia, _scanNoTriviaFunc)
- Case "/"c
- Return XmlMakeBeginEndElementToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "?"c : Return XmlMakeBeginProcessingInstructionToken(precedingTrivia, _scanNoTriviaFunc)
+ Case "/"c : Return XmlMakeBeginEndElementToken(precedingTrivia, _scanNoTriviaFunc)
End Select
End If
Return XmlMakeLessToken(precedingTrivia)
Case "?"c
- If CanGetCharAtOffset(1) AndAlso PeekAheadChar(1) = ">"c Then
- ' // Create token for the '?>' termination sequence
- Return XmlMakeEndProcessingInstructionToken(precedingTrivia)
- End If
-
+ If PeekIs(1,">"c) Then Return XmlMakeEndProcessingInstructionToken(precedingTrivia) ' // Create token for the '?>' termination sequence
Return MakeQuestionToken(precedingTrivia, False)
- Case "("c
- Return XmlMakeLeftParenToken(precedingTrivia)
-
- Case ")"c
- Return XmlMakeRightParenToken(precedingTrivia)
-
- Case "!"c,
- ";"c,
- "#"c,
- ","c,
- "}"c
+ Case "("c : Return XmlMakeLeftParenToken(precedingTrivia)
+ Case ")"c : Return XmlMakeRightParenToken(precedingTrivia)
+ Case "!"c, ";"c, "#"c, ","c, "}"c
Return XmlMakeBadToken(precedingTrivia, 1, ERRID.ERR_IllegalXmlNameChar)
-
- Case ":"c
- Return XmlMakeColonToken(precedingTrivia)
-
- Case "["c
- Return XmlMakeOpenBracketToken(state, precedingTrivia)
-
- Case "]"c
- Return XmlMakeCloseBracketToken(state, precedingTrivia)
-
+ Case ":"c : Return XmlMakeColonToken(precedingTrivia)
+ Case "["c : Return XmlMakeOpenBracketToken(state, precedingTrivia)
+ Case "]"c : Return XmlMakeCloseBracketToken(state, precedingTrivia)
Case Else
' // Because of weak scanning of QName, this state must always handle
' // '=' | '\'' | '"'| '/' | '>' | '<' | '?'
diff --git a/src/Compilers/VisualBasic/Portable/Scanner/XmlTokenFactories.vb b/src/Compilers/VisualBasic/Portable/Scanner/XmlTokenFactories.vb
index 3043edd3e03a5..8ae1928432e52 100644
--- a/src/Compilers/VisualBasic/Portable/Scanner/XmlTokenFactories.vb
+++ b/src/Compilers/VisualBasic/Portable/Scanner/XmlTokenFactories.vb
@@ -113,7 +113,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function XmlMakeSingleQuoteToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode),
spelling As Char,
isOpening As Boolean) As PunctuationSyntax
- Debug.Assert(PeekChar() = spelling)
+ Debug.Assert(Peek() = spelling)
AdvanceChar()
@@ -129,7 +129,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Private Function XmlMakeDoubleQuoteToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode),
spelling As Char,
isOpening As Boolean) As PunctuationSyntax
- Debug.Assert(PeekChar() = spelling)
+ Debug.Assert(Peek() = spelling)
AdvanceChar()
@@ -297,8 +297,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function XmlMakeBeginEndElementToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), scanTrailingTrivia As ScanTriviaFunc) As PunctuationSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "/"c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "/"c)
AdvanceChar(2)
Dim followingTrivia = scanTrailingTrivia()
@@ -306,8 +306,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function XmlMakeEndEmptyElementToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As PunctuationSyntax
- Debug.Assert(PeekChar() = "/"c)
- Debug.Assert(PeekAheadChar(1) = ">"c)
+ Debug.Assert(Peek() = "/"c)
+ Debug.Assert(Peek(1) = ">"c)
AdvanceChar(2)
Return MakePunctuationToken(SyntaxKind.SlashGreaterThanToken, "/>", precedingTrivia, Nothing)
@@ -315,20 +315,20 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "EmbeddedToken"
Private Function XmlMakeBeginEmbeddedToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As PunctuationSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "%"c)
- Debug.Assert(PeekAheadChar(2) = "="c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "%"c)
+ Debug.Assert(Peek(2) = "="c)
AdvanceChar(3)
Return MakePunctuationToken(SyntaxKind.LessThanPercentEqualsToken, "<%=", precedingTrivia, Nothing)
End Function
Private Function XmlMakeEndEmbeddedToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), scanTrailingTrivia As ScanTriviaFunc) As PunctuationSyntax
- Debug.Assert(PeekChar() = "%"c OrElse PeekChar() = FULLWIDTH_PERCENT_SIGN)
- Debug.Assert(PeekAheadChar(1) = ">"c)
+ Debug.Assert(Peek() = "%"c OrElse Peek() = FULLWIDTH_PERCENT_SIGN)
+ Debug.Assert(Peek(1) = ">"c)
Dim spelling As String
- If PeekChar() = "%"c Then
+ If Peek() = "%"c Then
AdvanceChar(2)
spelling = "%>"
Else
@@ -343,34 +343,34 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "DTD"
Private Function XmlMakeBeginDTDToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As BadTokenSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "!"c)
- Debug.Assert(PeekAheadChar(2) = "D"c)
- Debug.Assert(PeekAheadChar(3) = "O"c)
- Debug.Assert(PeekAheadChar(4) = "C"c)
- Debug.Assert(PeekAheadChar(5) = "T"c)
- Debug.Assert(PeekAheadChar(6) = "Y"c)
- Debug.Assert(PeekAheadChar(7) = "P"c)
- Debug.Assert(PeekAheadChar(8) = "E"c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "!"c)
+ Debug.Assert(Peek(2) = "D"c)
+ Debug.Assert(Peek(3) = "O"c)
+ Debug.Assert(Peek(4) = "C"c)
+ Debug.Assert(Peek(5) = "T"c)
+ Debug.Assert(Peek(6) = "Y"c)
+ Debug.Assert(Peek(7) = "P"c)
+ Debug.Assert(Peek(8) = "E"c)
Return XmlMakeBadToken(SyntaxSubKind.BeginDocTypeToken, precedingTrivia, 9, ERRID.ERR_DTDNotSupported)
End Function
Private Function XmlLessThanExclamationToken(state As ScannerState, precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As BadTokenSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "!"c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "!"c)
Return XmlMakeBadToken(SyntaxSubKind.LessThanExclamationToken, precedingTrivia, 2, If(state = ScannerState.DocType, ERRID.ERR_DTDNotSupported, ERRID.ERR_Syntax))
End Function
Private Function XmlMakeOpenBracketToken(state As ScannerState, precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As BadTokenSyntax
- Debug.Assert(PeekChar() = "["c)
+ Debug.Assert(Peek() = "["c)
Return XmlMakeBadToken(SyntaxSubKind.OpenBracketToken, precedingTrivia, 1, If(state = ScannerState.DocType, ERRID.ERR_DTDNotSupported, ERRID.ERR_IllegalXmlNameChar))
End Function
Private Function XmlMakeCloseBracketToken(state As ScannerState, precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As BadTokenSyntax
- Debug.Assert(PeekChar() = "]"c)
+ Debug.Assert(Peek() = "]"c)
Return XmlMakeBadToken(SyntaxSubKind.CloseBracketToken, precedingTrivia, 1, If(state = ScannerState.DocType, ERRID.ERR_DTDNotSupported, ERRID.ERR_IllegalXmlNameChar))
End Function
@@ -379,8 +379,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "ProcessingInstruction"
Private Function XmlMakeBeginProcessingInstructionToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), scanTrailingTrivia As ScanTriviaFunc) As PunctuationSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "?"c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "?"c)
AdvanceChar(2)
Dim followingTrivia = scanTrailingTrivia()
@@ -397,8 +397,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function XmlMakeEndProcessingInstructionToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As PunctuationSyntax
- Debug.Assert(PeekChar() = "?"c)
- Debug.Assert(PeekAheadChar(1) = ">"c)
+ Debug.Assert(Peek() = "?"c)
+ Debug.Assert(Peek(1) = ">"c)
AdvanceChar(2)
Return MakePunctuationToken(SyntaxKind.QuestionGreaterThanToken, "?>", precedingTrivia, Nothing)
@@ -408,10 +408,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "Comment"
Private Function XmlMakeBeginCommentToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), scanTrailingTrivia As ScanTriviaFunc) As PunctuationSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "!"c)
- Debug.Assert(PeekAheadChar(2) = "-"c)
- Debug.Assert(PeekAheadChar(3) = "-"c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "!"c)
+ Debug.Assert(Peek(2) = "-"c)
+ Debug.Assert(Peek(3) = "-"c)
AdvanceChar(4)
Dim followingTrivia = scanTrailingTrivia()
@@ -428,9 +428,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function XmlMakeEndCommentToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As PunctuationSyntax
- Debug.Assert(PeekChar() = "-"c)
- Debug.Assert(PeekAheadChar(1) = "-"c)
- Debug.Assert(PeekAheadChar(2) = ">"c)
+ Debug.Assert(Peek() = "-"c)
+ Debug.Assert(Peek(1) = "-"c)
+ Debug.Assert(Peek(2) = ">"c)
AdvanceChar(3)
Return MakePunctuationToken(SyntaxKind.MinusMinusGreaterThanToken, "-->", precedingTrivia, Nothing)
@@ -440,15 +440,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
#Region "CData"
Private Function XmlMakeBeginCDataToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode), scanTrailingTrivia As ScanTriviaFunc) As PunctuationSyntax
- Debug.Assert(PeekChar() = "<"c)
- Debug.Assert(PeekAheadChar(1) = "!"c)
- Debug.Assert(PeekAheadChar(2) = "["c)
- Debug.Assert(PeekAheadChar(3) = "C"c)
- Debug.Assert(PeekAheadChar(4) = "D"c)
- Debug.Assert(PeekAheadChar(5) = "A"c)
- Debug.Assert(PeekAheadChar(6) = "T"c)
- Debug.Assert(PeekAheadChar(7) = "A"c)
- Debug.Assert(PeekAheadChar(8) = "["c)
+ Debug.Assert(Peek() = "<"c)
+ Debug.Assert(Peek(1) = "!"c)
+ Debug.Assert(Peek(2) = "["c)
+ Debug.Assert(Peek(3) = "C"c)
+ Debug.Assert(Peek(4) = "D"c)
+ Debug.Assert(Peek(5) = "A"c)
+ Debug.Assert(Peek(6) = "T"c)
+ Debug.Assert(Peek(7) = "A"c)
+ Debug.Assert(Peek(8) = "["c)
AdvanceChar(9)
Dim followingTrivia = scanTrailingTrivia()
@@ -460,9 +460,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
End Function
Private Function XmlMakeEndCDataToken(precedingTrivia As SyntaxList(Of VisualBasicSyntaxNode)) As PunctuationSyntax
- Debug.Assert(PeekChar() = "]"c)
- Debug.Assert(PeekAheadChar(1) = "]"c)
- Debug.Assert(PeekAheadChar(2) = ">"c)
+ Debug.Assert(Peek() = "]"c)
+ Debug.Assert(Peek(1) = "]"c)
+ Debug.Assert(Peek(2) = ">"c)
AdvanceChar(3)
Return MakePunctuationToken(SyntaxKind.EndCDataToken, "]]>", precedingTrivia, Nothing)
diff --git a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb
index 055421cac4eb5..455998d01a894 100644
--- a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb
+++ b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb
@@ -9,6 +9,7 @@ Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports TypeKind = Microsoft.CodeAnalysis.TypeKind
+Imports WKMN = Microsoft.CodeAnalysis.WellKnownMemberNames
Namespace Microsoft.CodeAnalysis.VisualBasic
@@ -53,22 +54,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public ReadOnly Property UnaryOperatorKind As UnaryOperatorKind
Get
- If Not IsUnary Then
- Return UnaryOperatorKind.Error
- End If
-
- Return CType(m_Id >> 2, UnaryOperatorKind)
+ If IsUnary Then Return CType(m_Id >> 2, UnaryOperatorKind)
+ Return UnaryOperatorKind.Error
End Get
End Property
Public ReadOnly Property BinaryOperatorKind As BinaryOperatorKind
Get
- If Not IsBinary Then
- Return BinaryOperatorKind.Error
- End If
-
- Return CType(m_Id >> 2, BinaryOperatorKind)
- End Get
+ If IsBinary Then Return CType(m_Id >> 2, BinaryOperatorKind)
+ Return BinaryOperatorKind.Error
+ End Get
End Property
End Structure
@@ -85,40 +80,40 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Shared Sub New()
Dim operators As New Dictionary(Of String, OperatorInfo)(IdentifierComparison.Comparer)
- operators.Add(WellKnownMemberNames.OnesComplementOperatorName, New OperatorInfo(UnaryOperatorKind.Not))
- operators.Add(WellKnownMemberNames.TrueOperatorName, New OperatorInfo(UnaryOperatorKind.IsTrue))
- operators.Add(WellKnownMemberNames.FalseOperatorName, New OperatorInfo(UnaryOperatorKind.IsFalse))
- operators.Add(WellKnownMemberNames.UnaryPlusOperatorName, New OperatorInfo(UnaryOperatorKind.Plus))
- operators.Add(WellKnownMemberNames.AdditionOperatorName, New OperatorInfo(BinaryOperatorKind.Add))
- operators.Add(WellKnownMemberNames.UnaryNegationOperatorName, New OperatorInfo(UnaryOperatorKind.Minus))
- operators.Add(WellKnownMemberNames.SubtractionOperatorName, New OperatorInfo(BinaryOperatorKind.Subtract))
- operators.Add(WellKnownMemberNames.MultiplyOperatorName, New OperatorInfo(BinaryOperatorKind.Multiply))
- operators.Add(WellKnownMemberNames.DivisionOperatorName, New OperatorInfo(BinaryOperatorKind.Divide))
- operators.Add(WellKnownMemberNames.IntegerDivisionOperatorName, New OperatorInfo(BinaryOperatorKind.IntegerDivide))
- operators.Add(WellKnownMemberNames.ModulusOperatorName, New OperatorInfo(BinaryOperatorKind.Modulo))
- operators.Add(WellKnownMemberNames.ExponentOperatorName, New OperatorInfo(BinaryOperatorKind.Power))
- operators.Add(WellKnownMemberNames.EqualityOperatorName, New OperatorInfo(BinaryOperatorKind.Equals))
- operators.Add(WellKnownMemberNames.InequalityOperatorName, New OperatorInfo(BinaryOperatorKind.NotEquals))
- operators.Add(WellKnownMemberNames.LessThanOperatorName, New OperatorInfo(BinaryOperatorKind.LessThan))
- operators.Add(WellKnownMemberNames.GreaterThanOperatorName, New OperatorInfo(BinaryOperatorKind.GreaterThan))
- operators.Add(WellKnownMemberNames.LessThanOrEqualOperatorName, New OperatorInfo(BinaryOperatorKind.LessThanOrEqual))
- operators.Add(WellKnownMemberNames.GreaterThanOrEqualOperatorName, New OperatorInfo(BinaryOperatorKind.GreaterThanOrEqual))
- operators.Add(WellKnownMemberNames.LikeOperatorName, New OperatorInfo(BinaryOperatorKind.Like))
- operators.Add(WellKnownMemberNames.ConcatenateOperatorName, New OperatorInfo(BinaryOperatorKind.Concatenate))
- operators.Add(WellKnownMemberNames.BitwiseAndOperatorName, New OperatorInfo(BinaryOperatorKind.And))
- operators.Add(WellKnownMemberNames.BitwiseOrOperatorName, New OperatorInfo(BinaryOperatorKind.Or))
- operators.Add(WellKnownMemberNames.ExclusiveOrOperatorName, New OperatorInfo(BinaryOperatorKind.Xor))
- operators.Add(WellKnownMemberNames.LeftShiftOperatorName, New OperatorInfo(BinaryOperatorKind.LeftShift))
- operators.Add(WellKnownMemberNames.RightShiftOperatorName, New OperatorInfo(BinaryOperatorKind.RightShift))
- operators.Add(WellKnownMemberNames.ImplicitConversionName, New OperatorInfo(UnaryOperatorKind.Implicit))
- operators.Add(WellKnownMemberNames.ExplicitConversionName, New OperatorInfo(UnaryOperatorKind.Explicit))
+ operators.Add(WKMN.OnesComplementOperatorName, New OperatorInfo(UnaryOperatorKind.Not))
+ operators.Add(WKMN.TrueOperatorName, New OperatorInfo(UnaryOperatorKind.IsTrue))
+ operators.Add(WKMN.FalseOperatorName, New OperatorInfo(UnaryOperatorKind.IsFalse))
+ operators.Add(WKMN.UnaryPlusOperatorName, New OperatorInfo(UnaryOperatorKind.Plus))
+ operators.Add(WKMN.AdditionOperatorName, New OperatorInfo(BinaryOperatorKind.Add))
+ operators.Add(WKMN.UnaryNegationOperatorName, New OperatorInfo(UnaryOperatorKind.Minus))
+ operators.Add(WKMN.SubtractionOperatorName, New OperatorInfo(BinaryOperatorKind.Subtract))
+ operators.Add(WKMN.MultiplyOperatorName, New OperatorInfo(BinaryOperatorKind.Multiply))
+ operators.Add(WKMN.DivisionOperatorName, New OperatorInfo(BinaryOperatorKind.Divide))
+ operators.Add(WKMN.IntegerDivisionOperatorName, New OperatorInfo(BinaryOperatorKind.IntegerDivide))
+ operators.Add(WKMN.ModulusOperatorName, New OperatorInfo(BinaryOperatorKind.Modulo))
+ operators.Add(WKMN.ExponentOperatorName, New OperatorInfo(BinaryOperatorKind.Power))
+ operators.Add(WKMN.EqualityOperatorName, New OperatorInfo(BinaryOperatorKind.Equals))
+ operators.Add(WKMN.InequalityOperatorName, New OperatorInfo(BinaryOperatorKind.NotEquals))
+ operators.Add(WKMN.LessThanOperatorName, New OperatorInfo(BinaryOperatorKind.LessThan))
+ operators.Add(WKMN.GreaterThanOperatorName, New OperatorInfo(BinaryOperatorKind.GreaterThan))
+ operators.Add(WKMN.LessThanOrEqualOperatorName, New OperatorInfo(BinaryOperatorKind.LessThanOrEqual))
+ operators.Add(WKMN.GreaterThanOrEqualOperatorName, New OperatorInfo(BinaryOperatorKind.GreaterThanOrEqual))
+ operators.Add(WKMN.LikeOperatorName, New OperatorInfo(BinaryOperatorKind.Like))
+ operators.Add(WKMN.ConcatenateOperatorName, New OperatorInfo(BinaryOperatorKind.Concatenate))
+ operators.Add(WKMN.BitwiseAndOperatorName, New OperatorInfo(BinaryOperatorKind.And))
+ operators.Add(WKMN.BitwiseOrOperatorName, New OperatorInfo(BinaryOperatorKind.Or))
+ operators.Add(WKMN.ExclusiveOrOperatorName, New OperatorInfo(BinaryOperatorKind.Xor))
+ operators.Add(WKMN.LeftShiftOperatorName, New OperatorInfo(BinaryOperatorKind.LeftShift))
+ operators.Add(WKMN.RightShiftOperatorName, New OperatorInfo(BinaryOperatorKind.RightShift))
+ operators.Add(WKMN.ImplicitConversionName, New OperatorInfo(UnaryOperatorKind.Implicit))
+ operators.Add(WKMN.ExplicitConversionName, New OperatorInfo(UnaryOperatorKind.Explicit))
' These cannot be declared in source, but can be imported.
- operators.Add(WellKnownMemberNames.LogicalNotOperatorName, New OperatorInfo(UnaryOperatorKind.Not))
- operators.Add(WellKnownMemberNames.LogicalAndOperatorName, New OperatorInfo(BinaryOperatorKind.And))
- operators.Add(WellKnownMemberNames.LogicalOrOperatorName, New OperatorInfo(BinaryOperatorKind.Or))
- operators.Add(WellKnownMemberNames.UnsignedLeftShiftOperatorName, New OperatorInfo(BinaryOperatorKind.LeftShift))
- operators.Add(WellKnownMemberNames.UnsignedRightShiftOperatorName, New OperatorInfo(BinaryOperatorKind.RightShift))
+ operators.Add(WKMN.LogicalNotOperatorName, New OperatorInfo(UnaryOperatorKind.Not))
+ operators.Add(WKMN.LogicalAndOperatorName, New OperatorInfo(BinaryOperatorKind.And))
+ operators.Add(WKMN.LogicalOrOperatorName, New OperatorInfo(BinaryOperatorKind.Or))
+ operators.Add(WKMN.UnsignedLeftShiftOperatorName, New OperatorInfo(BinaryOperatorKind.LeftShift))
+ operators.Add(WKMN.UnsignedRightShiftOperatorName, New OperatorInfo(BinaryOperatorKind.RightShift))
OperatorNames = operators
End Sub
@@ -129,27 +124,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Friend Shared Function GetOperatorTokenKind(opInfo As OperatorInfo) As SyntaxKind
- If opInfo.IsUnary Then
- Return GetOperatorTokenKind(opInfo.UnaryOperatorKind)
- Else
- Return GetOperatorTokenKind(opInfo.BinaryOperatorKind)
- End If
+ If opInfo.IsUnary Then Return GetOperatorTokenKind(opInfo.UnaryOperatorKind)
+ Return GetOperatorTokenKind(opInfo.BinaryOperatorKind)
End Function
Friend Shared Function GetOperatorTokenKind(op As UnaryOperatorKind) As SyntaxKind
Select Case op
- Case UnaryOperatorKind.IsFalse
- Return SyntaxKind.IsFalseKeyword
- Case UnaryOperatorKind.IsTrue
- Return SyntaxKind.IsTrueKeyword
- Case UnaryOperatorKind.Minus
- Return SyntaxKind.MinusToken
- Case UnaryOperatorKind.Not
- Return SyntaxKind.NotKeyword
- Case UnaryOperatorKind.Plus
- Return SyntaxKind.PlusToken
- Case UnaryOperatorKind.Implicit, UnaryOperatorKind.Explicit
- Return SyntaxKind.CTypeKeyword
+ Case UnaryOperatorKind.IsFalse : Return SyntaxKind.IsFalseKeyword
+ Case UnaryOperatorKind.IsTrue : Return SyntaxKind.IsTrueKeyword
+ Case UnaryOperatorKind.Minus : Return SyntaxKind.MinusToken
+ Case UnaryOperatorKind.Not : Return SyntaxKind.NotKeyword
+ Case UnaryOperatorKind.Plus : Return SyntaxKind.PlusToken
+ Case UnaryOperatorKind.Implicit,
+ UnaryOperatorKind.Explicit : Return SyntaxKind.CTypeKeyword
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
@@ -157,55 +144,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Shared Function GetOperatorTokenKind(op As BinaryOperatorKind) As SyntaxKind
Select Case op
- Case BinaryOperatorKind.Add
- Return SyntaxKind.PlusToken
- Case BinaryOperatorKind.Subtract
- Return SyntaxKind.MinusToken
- Case BinaryOperatorKind.Multiply
- Return SyntaxKind.AsteriskToken
- Case BinaryOperatorKind.Divide
- Return SyntaxKind.SlashToken
- Case BinaryOperatorKind.IntegerDivide
- Return SyntaxKind.BackslashToken
- Case BinaryOperatorKind.Modulo
- Return SyntaxKind.ModKeyword
- Case BinaryOperatorKind.Power
- Return SyntaxKind.CaretToken
- Case BinaryOperatorKind.Equals
- Return SyntaxKind.EqualsToken
- Case BinaryOperatorKind.NotEquals
- Return SyntaxKind.LessThanGreaterThanToken
- Case BinaryOperatorKind.LessThan
- Return SyntaxKind.LessThanToken
- Case BinaryOperatorKind.GreaterThan
- Return SyntaxKind.GreaterThanToken
- Case BinaryOperatorKind.LessThanOrEqual
- Return SyntaxKind.LessThanEqualsToken
- Case BinaryOperatorKind.GreaterThanOrEqual
- Return SyntaxKind.GreaterThanEqualsToken
- Case BinaryOperatorKind.Like
- Return SyntaxKind.LikeKeyword
- Case BinaryOperatorKind.Concatenate
- Return SyntaxKind.AmpersandToken
- Case BinaryOperatorKind.And
- Return SyntaxKind.AndKeyword
- Case BinaryOperatorKind.Or
- Return SyntaxKind.OrKeyword
- Case BinaryOperatorKind.Xor
- Return SyntaxKind.XorKeyword
- Case BinaryOperatorKind.LeftShift
- Return SyntaxKind.LessThanLessThanToken
- Case BinaryOperatorKind.RightShift
- Return SyntaxKind.GreaterThanGreaterThanToken
- Case BinaryOperatorKind.AndAlso
- Return SyntaxKind.AndAlsoKeyword
- Case BinaryOperatorKind.OrElse
- Return SyntaxKind.OrElseKeyword
- Case BinaryOperatorKind.Is
- Return SyntaxKind.IsKeyword
- Case BinaryOperatorKind.IsNot
- Return SyntaxKind.IsNotKeyword
-
+ Case BinaryOperatorKind.Add : Return SyntaxKind.PlusToken
+ Case BinaryOperatorKind.Subtract : Return SyntaxKind.MinusToken
+ Case BinaryOperatorKind.Multiply : Return SyntaxKind.AsteriskToken
+ Case BinaryOperatorKind.Divide : Return SyntaxKind.SlashToken
+ Case BinaryOperatorKind.IntegerDivide : Return SyntaxKind.BackslashToken
+ Case BinaryOperatorKind.Modulo : Return SyntaxKind.ModKeyword
+ Case BinaryOperatorKind.Power : Return SyntaxKind.CaretToken
+ Case BinaryOperatorKind.Equals : Return SyntaxKind.EqualsToken
+ Case BinaryOperatorKind.NotEquals : Return SyntaxKind.LessThanGreaterThanToken
+ Case BinaryOperatorKind.LessThan : Return SyntaxKind.LessThanToken
+ Case BinaryOperatorKind.GreaterThan : Return SyntaxKind.GreaterThanToken
+ Case BinaryOperatorKind.LessThanOrEqual : Return SyntaxKind.LessThanEqualsToken
+ Case BinaryOperatorKind.GreaterThanOrEqual : Return SyntaxKind.GreaterThanEqualsToken
+ Case BinaryOperatorKind.Like : Return SyntaxKind.LikeKeyword
+ Case BinaryOperatorKind.Concatenate : Return SyntaxKind.AmpersandToken
+ Case BinaryOperatorKind.And : Return SyntaxKind.AndKeyword
+ Case BinaryOperatorKind.Or : Return SyntaxKind.OrKeyword
+ Case BinaryOperatorKind.Xor : Return SyntaxKind.XorKeyword
+ Case BinaryOperatorKind.LeftShift : Return SyntaxKind.LessThanLessThanToken
+ Case BinaryOperatorKind.RightShift : Return SyntaxKind.GreaterThanGreaterThanToken
+ Case BinaryOperatorKind.AndAlso : Return SyntaxKind.AndAlsoKeyword
+ Case BinaryOperatorKind.OrElse : Return SyntaxKind.OrElseKeyword
+ Case BinaryOperatorKind.Is : Return SyntaxKind.IsKeyword
+ Case BinaryOperatorKind.IsNot : Return SyntaxKind.IsNotKeyword
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
@@ -214,46 +176,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Shared Function TryGetOperatorName(op As BinaryOperatorKind) As String
Select Case (op And BinaryOperatorKind.OpMask)
- Case BinaryOperatorKind.Add
- Return WellKnownMemberNames.AdditionOperatorName
- Case BinaryOperatorKind.Concatenate
- Return WellKnownMemberNames.ConcatenateOperatorName
- Case BinaryOperatorKind.Like
- Return WellKnownMemberNames.LikeOperatorName
- Case BinaryOperatorKind.Equals
- Return WellKnownMemberNames.EqualityOperatorName
- Case BinaryOperatorKind.NotEquals
- Return WellKnownMemberNames.InequalityOperatorName
- Case BinaryOperatorKind.LessThanOrEqual
- Return WellKnownMemberNames.LessThanOrEqualOperatorName
- Case BinaryOperatorKind.GreaterThanOrEqual
- Return WellKnownMemberNames.GreaterThanOrEqualOperatorName
- Case BinaryOperatorKind.LessThan
- Return WellKnownMemberNames.LessThanOperatorName
- Case BinaryOperatorKind.GreaterThan
- Return WellKnownMemberNames.GreaterThanOperatorName
- Case BinaryOperatorKind.Subtract
- Return WellKnownMemberNames.SubtractionOperatorName
- Case BinaryOperatorKind.Multiply
- Return WellKnownMemberNames.MultiplyOperatorName
- Case BinaryOperatorKind.Power
- Return WellKnownMemberNames.ExponentOperatorName
- Case BinaryOperatorKind.Divide
- Return WellKnownMemberNames.DivisionOperatorName
- Case BinaryOperatorKind.Modulo
- Return WellKnownMemberNames.ModulusOperatorName
- Case BinaryOperatorKind.IntegerDivide
- Return WellKnownMemberNames.IntegerDivisionOperatorName
- Case BinaryOperatorKind.LeftShift
- Return WellKnownMemberNames.LeftShiftOperatorName
- Case BinaryOperatorKind.RightShift
- Return WellKnownMemberNames.RightShiftOperatorName
- Case BinaryOperatorKind.Xor
- Return WellKnownMemberNames.ExclusiveOrOperatorName
- Case BinaryOperatorKind.Or
- Return WellKnownMemberNames.BitwiseOrOperatorName
- Case BinaryOperatorKind.And
- Return WellKnownMemberNames.BitwiseAndOperatorName
+ Case BinaryOperatorKind.Add : Return WKMN.AdditionOperatorName
+ Case BinaryOperatorKind.Concatenate : Return WKMN.ConcatenateOperatorName
+ Case BinaryOperatorKind.Like : Return WKMN.LikeOperatorName
+ Case BinaryOperatorKind.Equals : Return WKMN.EqualityOperatorName
+ Case BinaryOperatorKind.NotEquals : Return WKMN.InequalityOperatorName
+ Case BinaryOperatorKind.LessThanOrEqual : Return WKMN.LessThanOrEqualOperatorName
+ Case BinaryOperatorKind.GreaterThanOrEqual : Return WKMN.GreaterThanOrEqualOperatorName
+ Case BinaryOperatorKind.LessThan : Return WKMN.LessThanOperatorName
+ Case BinaryOperatorKind.GreaterThan : Return WKMN.GreaterThanOperatorName
+ Case BinaryOperatorKind.Subtract : Return WKMN.SubtractionOperatorName
+ Case BinaryOperatorKind.Multiply : Return WKMN.MultiplyOperatorName
+ Case BinaryOperatorKind.Power : Return WKMN.ExponentOperatorName
+ Case BinaryOperatorKind.Divide : Return WKMN.DivisionOperatorName
+ Case BinaryOperatorKind.Modulo : Return WKMN.ModulusOperatorName
+ Case BinaryOperatorKind.IntegerDivide : Return WKMN.IntegerDivisionOperatorName
+ Case BinaryOperatorKind.LeftShift : Return WKMN.LeftShiftOperatorName
+ Case BinaryOperatorKind.RightShift : Return WKMN.RightShiftOperatorName
+ Case BinaryOperatorKind.Xor : Return WKMN.ExclusiveOrOperatorName
+ Case BinaryOperatorKind.Or : Return WKMN.BitwiseOrOperatorName
+ Case BinaryOperatorKind.And : Return WKMN.BitwiseAndOperatorName
Case Else
Return Nothing
@@ -265,39 +207,27 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Friend Shared Function TryGetOperatorName(op As UnaryOperatorKind) As String
-
Select Case (op And UnaryOperatorKind.OpMask)
- Case UnaryOperatorKind.Plus
- Return WellKnownMemberNames.UnaryPlusOperatorName
- Case UnaryOperatorKind.Minus
- Return WellKnownMemberNames.UnaryNegationOperatorName
- Case UnaryOperatorKind.Not
- Return WellKnownMemberNames.OnesComplementOperatorName
- Case UnaryOperatorKind.Implicit
- Return WellKnownMemberNames.ImplicitConversionName
- Case UnaryOperatorKind.Explicit
- Return WellKnownMemberNames.ExplicitConversionName
- Case UnaryOperatorKind.IsTrue
- Return WellKnownMemberNames.TrueOperatorName
- Case UnaryOperatorKind.IsFalse
- Return WellKnownMemberNames.FalseOperatorName
-
+ Case UnaryOperatorKind.Plus : Return WKMN.UnaryPlusOperatorName
+ Case UnaryOperatorKind.Minus : Return WKMN.UnaryNegationOperatorName
+ Case UnaryOperatorKind.Not : Return WKMN.OnesComplementOperatorName
+ Case UnaryOperatorKind.Implicit : Return WKMN.ImplicitConversionName
+ Case UnaryOperatorKind.Explicit : Return WKMN.ExplicitConversionName
+ Case UnaryOperatorKind.IsTrue : Return WKMN.TrueOperatorName
+ Case UnaryOperatorKind.IsFalse : Return WKMN.FalseOperatorName
Case Else
Return Nothing
End Select
End Function
- Friend Shared Function ValidateOverloadedOperator(
- method As MethodSymbol,
- opInfo As OperatorInfo,
- Optional diagnosticsOpt As DiagnosticBag = Nothing
- ) As Boolean
+ Friend Shared Function ValidateOverloadedOperator ( method As MethodSymbol,
+ opInfo As OperatorInfo,
+ Optional diagnosticsOpt As DiagnosticBag = Nothing
+ ) As Boolean
Debug.Assert(method.IsMethodKindBasedOnSyntax OrElse diagnosticsOpt Is Nothing)
Debug.Assert(opInfo.ParamCount <> 0)
- If method.ParameterCount <> opInfo.ParamCount Then
- Return False
- End If
+ If method.ParameterCount <> opInfo.ParamCount Then Return False
Dim result As Boolean = True
Dim containingType As NamedTypeSymbol = method.ContainingType
@@ -461,12 +391,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim result As UnaryOperatorKind
Select Case opCode
- Case SyntaxKind.UnaryPlusExpression
- result = UnaryOperatorKind.Plus
- Case SyntaxKind.UnaryMinusExpression
- result = UnaryOperatorKind.Minus
- Case SyntaxKind.NotExpression
- result = UnaryOperatorKind.Not
+ Case SyntaxKind.UnaryPlusExpression : result = UnaryOperatorKind.Plus
+ Case SyntaxKind.UnaryMinusExpression : result = UnaryOperatorKind.Minus
+ Case SyntaxKind.NotExpression : result = UnaryOperatorKind.Not
Case Else
Throw ExceptionUtilities.UnexpectedValue(opCode)
End Select
@@ -554,10 +481,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
'''
''' Returns result type of the operator or SpecialType.None if operator is not supported.
'''
- Friend Shared Function ResolveNotLiftedIntrinsicUnaryOperator(
- opCode As UnaryOperatorKind,
- operandSpecialType As SpecialType
- ) As SpecialType
+ Friend Shared Function ResolveNotLiftedIntrinsicUnaryOperator _
+ ( opCode As UnaryOperatorKind, operandSpecialType As SpecialType) As SpecialType
Dim intrinsicOperatorType As SpecialType
@@ -648,17 +573,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
intrinsicOperatorType = operandSpecialType
- Case SpecialType.System_UInt16
- intrinsicOperatorType = SpecialType.System_Int32
-
- Case SpecialType.System_UInt32
- intrinsicOperatorType = SpecialType.System_Int64
-
- Case SpecialType.System_UInt64
- intrinsicOperatorType = SpecialType.System_Decimal
-
- Case SpecialType.System_String
- intrinsicOperatorType = SpecialType.System_Double
+ Case SpecialType.System_UInt16 : intrinsicOperatorType = SpecialType.System_Int32
+ Case SpecialType.System_UInt32 : intrinsicOperatorType = SpecialType.System_Int64
+ Case SpecialType.System_UInt64 : intrinsicOperatorType = SpecialType.System_Decimal
+ Case SpecialType.System_String : intrinsicOperatorType = SpecialType.System_Double
Case Else
intrinsicOperatorType = SpecialType.None
@@ -1047,30 +965,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim resultUnderlying = resultType.GetEnumUnderlyingTypeOrSelf()
If leftUnderlying.IsIntegralType() OrElse leftUnderlying.IsCharType() OrElse leftUnderlying.IsDateTimeType() Then
- result = FoldIntegralCharOrDateTimeBinaryOperator(
- op,
- leftConstantValue,
- rightConstantValue,
- leftUnderlying,
- resultUnderlying,
- integerOverflow,
- divideByZero)
+ result = FoldIntegralCharOrDateTimeBinaryOperator(op, leftConstantValue, rightConstantValue,
+ leftUnderlying, resultUnderlying,
+ integerOverflow, divideByZero)
ElseIf leftUnderlying.IsFloatingType() Then
- result = FoldFloatingBinaryOperator(
- op,
- leftConstantValue,
- rightConstantValue,
- leftUnderlying,
- resultUnderlying)
+ result = FoldFloatingBinaryOperator(op, leftConstantValue, rightConstantValue, leftUnderlying, resultUnderlying)
ElseIf leftUnderlying.IsDecimalType() Then
- result = FoldDecimalBinaryOperator(
- op,
- leftConstantValue,
- rightConstantValue,
- resultUnderlying,
- divideByZero)
+ result = FoldDecimalBinaryOperator(op, leftConstantValue, rightConstantValue, resultUnderlying, divideByZero)
ElseIf leftUnderlying.IsStringType() Then
' During normal compilation we never fold string comparison with
@@ -1078,21 +981,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' this code path in EE and folds comparison regardless of Option Compare.
' I am not sure if we need this in Roslyn, will ignore Option Compare Text for now.
Debug.Assert((operatorKind And BinaryOperatorKind.CompareText) = 0)
- result = FoldStringBinaryOperator(
- op,
- leftConstantValue,
- rightConstantValue,
- compoundStringLength)
-
- If result.IsBad Then
- compoundLengthOutOfLimit = True
- End If
+ result = FoldStringBinaryOperator(op, leftConstantValue, rightConstantValue, compoundStringLength)
+
+ If result.IsBad Then compoundLengthOutOfLimit = True
ElseIf leftUnderlying.IsBooleanType() Then
- result = FoldBooleanBinaryOperator(
- op,
- leftConstantValue,
- rightConstantValue)
+ result = FoldBooleanBinaryOperator(op, leftConstantValue, rightConstantValue)
End If
Debug.Assert(result IsNot Nothing)
@@ -1288,38 +1182,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim result As ConstantValue
- Dim leftValue As Double = If(operandType.IsSingleType, left.SingleValue, left.DoubleValue)
- Dim rightValue As Double = If(operandType.IsSingleType, right.SingleValue, right.DoubleValue)
+ Dim L_Value As Double = If(operandType.IsSingleType, left.SingleValue, left.DoubleValue)
+ Dim R_Value As Double = If(operandType.IsSingleType, right.SingleValue, right.DoubleValue)
If resultType.IsBooleanType() Then
Dim resultValue As Boolean
Select Case op
- Case BinaryOperatorKind.Equals
- resultValue = (leftValue = rightValue)
-
- Case BinaryOperatorKind.NotEquals
- resultValue = (leftValue <> rightValue)
-
- Case BinaryOperatorKind.LessThanOrEqual
- resultValue = (leftValue <= rightValue)
-
- Case BinaryOperatorKind.GreaterThanOrEqual
- resultValue = (leftValue >= rightValue)
-
- Case BinaryOperatorKind.LessThan
- resultValue = (leftValue < rightValue)
-
- Case BinaryOperatorKind.GreaterThan
- resultValue = (leftValue > rightValue)
-
+ Case BinaryOperatorKind.Equals : resultValue = (L_Value = R_Value)
+ Case BinaryOperatorKind.NotEquals : resultValue = (L_Value <> R_Value)
+ Case BinaryOperatorKind.LessThanOrEqual : resultValue = (L_Value <= R_Value)
+ Case BinaryOperatorKind.GreaterThanOrEqual : resultValue = (L_Value >= R_Value)
+ Case BinaryOperatorKind.LessThan : resultValue = (L_Value < R_Value)
+ Case BinaryOperatorKind.GreaterThan : resultValue = (L_Value > R_Value)
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
-
result = ConstantValue.Create(resultValue)
-
Else
' Compute the result in 64-bit arithmetic, and determine if the
@@ -1330,42 +1210,42 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Select Case op
Case BinaryOperatorKind.Add
- resultValue = leftValue + rightValue
+ resultValue = L_Value + R_Value
Case BinaryOperatorKind.Subtract
- resultValue = leftValue - rightValue
+ resultValue = L_Value - R_Value
Case BinaryOperatorKind.Multiply
- resultValue = leftValue * rightValue
+ resultValue = L_Value * R_Value
Case BinaryOperatorKind.Power
' VSW#463059: Special case CRT changes to match CLR behavior.
- If Double.IsInfinity(rightValue) Then
- If leftValue.Equals(1.0) Then
- resultValue = leftValue
+ If Double.IsInfinity(R_Value) Then
+ If L_Value.Equals(1.0) Then
+ resultValue = L_Value
Exit Select
End If
- If leftValue.Equals(-1.0) Then
+ If L_Value.Equals(-1.0) Then
resultValue = Double.NaN
Exit Select
End If
ElseIf (
- Double.IsNaN(rightValue)
+ Double.IsNaN(R_Value)
) Then
resultValue = Double.NaN
Exit Select
End If
- resultValue = Math.Pow(leftValue, rightValue)
+ resultValue = Math.Pow(L_Value, R_Value)
Case BinaryOperatorKind.Divide
' We have decided not to detect zerodivide in compile-time
' evaluation of floating expressions.
- resultValue = leftValue / rightValue
+ resultValue = L_Value / R_Value
Case BinaryOperatorKind.Modulo
@@ -1376,7 +1256,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' Dev10 compiler used fmod function here and it behaves differently. It looks like
' ILOpCode.Rem operation, that we use to emit Mod operator, produces result consistent
' with fmod.
- resultValue = leftValue Mod rightValue
+ resultValue = L_Value Mod R_Value
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
@@ -1419,25 +1299,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim comparisonResult As Integer = leftValue.CompareTo(rightValue)
Select Case op
-
- Case BinaryOperatorKind.Equals
- resultValue = (comparisonResult = 0)
-
- Case BinaryOperatorKind.NotEquals
- resultValue = Not (comparisonResult = 0)
-
- Case BinaryOperatorKind.LessThanOrEqual
- resultValue = (comparisonResult <= 0)
-
- Case BinaryOperatorKind.GreaterThanOrEqual
- resultValue = (comparisonResult >= 0)
-
- Case BinaryOperatorKind.LessThan
- resultValue = (comparisonResult < 0)
-
- Case BinaryOperatorKind.GreaterThan
- resultValue = (comparisonResult > 0)
-
+ Case BinaryOperatorKind.Equals : resultValue = (comparisonResult = 0)
+ Case BinaryOperatorKind.NotEquals : resultValue = Not (comparisonResult = 0)
+ Case BinaryOperatorKind.LessThanOrEqual : resultValue = (comparisonResult <= 0)
+ Case BinaryOperatorKind.GreaterThanOrEqual : resultValue = (comparisonResult >= 0)
+ Case BinaryOperatorKind.LessThan : resultValue = (comparisonResult < 0)
+ Case BinaryOperatorKind.GreaterThan : resultValue = (comparisonResult > 0)
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
@@ -1449,25 +1316,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Try
Select Case op
- Case BinaryOperatorKind.Add
- resultValue = Decimal.Add(leftValue, rightValue)
-
- Case BinaryOperatorKind.Subtract
- resultValue = Decimal.Subtract(leftValue, rightValue)
-
- Case BinaryOperatorKind.Multiply
- resultValue = Decimal.Multiply(leftValue, rightValue)
-
- Case BinaryOperatorKind.Divide
- resultValue = Decimal.Divide(leftValue, rightValue)
-
- Case BinaryOperatorKind.Modulo
- resultValue = Decimal.Remainder(leftValue, rightValue)
-
+ Case BinaryOperatorKind.Add : resultValue = Decimal.Add(leftValue, rightValue)
+ Case BinaryOperatorKind.Subtract : resultValue = Decimal.Subtract(leftValue, rightValue)
+ Case BinaryOperatorKind.Multiply : resultValue = Decimal.Multiply(leftValue, rightValue)
+ Case BinaryOperatorKind.Divide : resultValue = Decimal.Divide(leftValue, rightValue)
+ Case BinaryOperatorKind.Modulo : resultValue = Decimal.Remainder(leftValue, rightValue)
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
-
Catch ex As OverflowException
overflow = True
Catch ex As DivideByZeroException
@@ -1487,39 +1343,39 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
'''
''' Returns ConstantValue.Bad if, and only if, compound string length is out of supported limit.
''' The parameter contains value corresponding to the
- ''' node, or zero, which will trigger inference. Upon return, it will
+ ''' node, or zero, which will trigger inference. Upon return, it will
''' be adjusted to correspond future result node.
'''
Private Shared Function FoldStringBinaryOperator(
op As BinaryOperatorKind,
- left As ConstantValue,
- right As ConstantValue,
+ l As ConstantValue,
+ r As ConstantValue,
<[In], Out> Optional ByRef compoundStringLength As Integer = 0
) As ConstantValue
Debug.Assert((op And BinaryOperatorKind.OpMask) = op)
Dim result As ConstantValue
- Dim leftValue As String = If(left.IsNothing, String.Empty, left.StringValue)
- Dim rightValue As String = If(right.IsNothing, String.Empty, right.StringValue)
+ Dim L_Value As String = If(l.IsNothing, String.Empty, l.StringValue)
+ Dim R_Value As String = If(r.IsNothing, String.Empty, r.StringValue)
Select Case op
Case BinaryOperatorKind.Concatenate
If compoundStringLength = 0 Then
' Infer. Keep it simple for now.
- compoundStringLength = leftValue.Length
+ compoundStringLength = L_Value.Length
End If
- Debug.Assert(compoundStringLength >= leftValue.Length)
+ Debug.Assert(compoundStringLength >= L_Value.Length)
- Dim newCompoundLength = CLng(compoundStringLength) + CLng(leftValue.Length) + CLng(rightValue.Length)
+ Dim newCompoundLength = CLng(compoundStringLength) + CLng(L_Value.Length) + CLng(R_Value.Length)
If newCompoundLength > Integer.MaxValue Then
Return ConstantValue.Bad
End If
Try
- result = ConstantValue.Create(String.Concat(leftValue, rightValue))
+ result = ConstantValue.Create(String.Concat(L_Value, R_Value))
compoundStringLength = CInt(newCompoundLength)
Catch e As System.OutOfMemoryException
Return ConstantValue.Bad
@@ -1534,26 +1390,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim stringComparisonSucceeds As Boolean = False
- Dim comparisonResult As Integer = String.Compare(leftValue, rightValue, StringComparison.Ordinal)
+ Dim comparisonResult As Integer = String.Compare(L_Value, R_Value, StringComparison.Ordinal)
Select Case op
- Case BinaryOperatorKind.Equals
- stringComparisonSucceeds = (comparisonResult = 0)
-
- Case BinaryOperatorKind.NotEquals
- stringComparisonSucceeds = (comparisonResult <> 0)
-
- Case BinaryOperatorKind.GreaterThan
- stringComparisonSucceeds = (comparisonResult > 0)
-
- Case BinaryOperatorKind.GreaterThanOrEqual
- stringComparisonSucceeds = (comparisonResult >= 0)
-
- Case BinaryOperatorKind.LessThan
- stringComparisonSucceeds = (comparisonResult < 0)
-
- Case BinaryOperatorKind.LessThanOrEqual
- stringComparisonSucceeds = (comparisonResult <= 0)
+ Case BinaryOperatorKind.Equals : stringComparisonSucceeds = (comparisonResult = 0)
+ Case BinaryOperatorKind.NotEquals : stringComparisonSucceeds = (comparisonResult <> 0)
+ Case BinaryOperatorKind.GreaterThan : stringComparisonSucceeds = (comparisonResult > 0)
+ Case BinaryOperatorKind.GreaterThanOrEqual : stringComparisonSucceeds = (comparisonResult >= 0)
+ Case BinaryOperatorKind.LessThan : stringComparisonSucceeds = (comparisonResult < 0)
+ Case BinaryOperatorKind.LessThanOrEqual : stringComparisonSucceeds = (comparisonResult <= 0)
End Select
@@ -1568,75 +1413,47 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private Shared Function FoldBooleanBinaryOperator(
op As BinaryOperatorKind,
- left As ConstantValue,
- right As ConstantValue
+ l As ConstantValue,
+ r As ConstantValue
) As ConstantValue
Debug.Assert((op And BinaryOperatorKind.OpMask) = op)
- Dim result As ConstantValue
-
- Dim leftValue As Boolean = left.BooleanValue
- Dim rightValue As Boolean = right.BooleanValue
+ Dim L_Value As Boolean = l.BooleanValue
+ Dim R_Value As Boolean = r.BooleanValue
Dim operationSucceeds As Boolean = False
Select Case op
- Case BinaryOperatorKind.Equals
- operationSucceeds = (leftValue = rightValue)
-
- Case BinaryOperatorKind.NotEquals
- operationSucceeds = (leftValue <> rightValue)
-
- Case BinaryOperatorKind.GreaterThan
- ' Amazingly, False > True.
- operationSucceeds = (leftValue = False AndAlso rightValue = True)
-
- Case BinaryOperatorKind.GreaterThanOrEqual
- operationSucceeds = (leftValue = False OrElse rightValue = True)
-
- Case BinaryOperatorKind.LessThan
- operationSucceeds = (leftValue = True AndAlso rightValue = False)
-
- Case BinaryOperatorKind.LessThanOrEqual
- operationSucceeds = (leftValue = True OrElse rightValue = False)
-
- Case BinaryOperatorKind.Xor
- operationSucceeds = (leftValue Xor rightValue)
-
+ Case BinaryOperatorKind.Equals : operationSucceeds = (L_Value = R_Value)
+ Case BinaryOperatorKind.NotEquals : operationSucceeds = (L_Value <> R_Value)
+ Case BinaryOperatorKind.GreaterThan : operationSucceeds = (L_Value = False AndAlso R_Value = True) ' Amazingly, False > True.
+ Case BinaryOperatorKind.GreaterThanOrEqual : operationSucceeds = (L_Value = False OrElse R_Value = True)
+ Case BinaryOperatorKind.LessThan : operationSucceeds = (L_Value = True AndAlso R_Value = False)
+ Case BinaryOperatorKind.LessThanOrEqual : operationSucceeds = (L_Value = True OrElse R_Value = False)
+ Case BinaryOperatorKind.Xor : operationSucceeds = (L_Value Xor R_Value)
Case BinaryOperatorKind.OrElse,
- BinaryOperatorKind.Or
-
- operationSucceeds = (leftValue OrElse rightValue)
-
+ BinaryOperatorKind.Or : operationSucceeds = (L_Value OrElse R_Value)
Case BinaryOperatorKind.AndAlso,
- BinaryOperatorKind.And
- operationSucceeds = (leftValue AndAlso rightValue)
+ BinaryOperatorKind.And : operationSucceeds = (L_Value AndAlso R_Value)
Case Else
Throw ExceptionUtilities.UnexpectedValue(op)
End Select
- result = ConstantValue.Create(operationSucceeds)
-
- Return result
+ Return ConstantValue.Create(operationSucceeds)
End Function
'''
''' Returns result type of the operator or SpecialType.None if operator is not supported.
'''
- Friend Shared Function ResolveNotLiftedIntrinsicBinaryOperator(
- opCode As BinaryOperatorKind,
- left As SpecialType,
- right As SpecialType
- ) As SpecialType
+ Friend Shared Function ResolveNotLiftedIntrinsicBinaryOperator _
+ ( opCode As BinaryOperatorKind, l As SpecialType, r As SpecialType ) As SpecialType
- Dim leftIndex = left.TypeToIndex()
- Dim rightIndex = right.TypeToIndex()
+ Dim lx = l.TypeToIndex()
+ Dim rx = r.TypeToIndex()
- If Not (leftIndex.HasValue AndAlso rightIndex.HasValue) Then
- Return SpecialType.None
- End If
+ If Not (lx.HasValue AndAlso rx.HasValue) Then Return SpecialType.None
Dim tableKind As BinaryOperatorTables.TableKind
@@ -1687,7 +1504,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Throw ExceptionUtilities.UnexpectedValue(opCode)
End Select
- Return CType(BinaryOperatorTables.Table(tableKind, leftIndex.Value, rightIndex.Value), SpecialType)
+ Return CType(BinaryOperatorTables.Table(tableKind, lx.Value, rx.Value), SpecialType)
End Function
Private Class BinaryOperatorTables
@@ -2143,13 +1960,8 @@ Done:
applicable.Clear()
applicableCount = 0
Else
- If Conversions.IsIdentityConversion(conversionIn) Then
- mostSpecificSourceType = source
- End If
-
- If Conversions.IsIdentityConversion(conversionOut) Then
- mostSpecificTargetType = destination
- End If
+ If Conversions.IsIdentityConversion(conversionIn) Then mostSpecificSourceType = source
+ If Conversions.IsIdentityConversion(conversionOut) Then mostSpecificTargetType = destination
applicable(currentIndex) = True
applicableCount += 1
@@ -2166,10 +1978,7 @@ Done:
#End If
If bestMatch IsNot Nothing Then
- If bestMatchIsAmbiguous Then
- bestMatch = Nothing
- End If
-
+ If bestMatchIsAmbiguous Then bestMatch = Nothing
Return True
End If
@@ -2185,10 +1994,7 @@ Done:
typeSet = ArrayBuilder(Of TypeSymbol).GetInstance()
For i As Integer = 0 To opSet.Count - 1
- If Not applicable(i) Then
- Continue For
- End If
-
+ If Not applicable(i) Then Continue For
typeSet.Add(opSet(i).Parameters(0).Type)
Next
@@ -2205,10 +2011,7 @@ Done:
End If
For i As Integer = 0 To opSet.Count - 1
- If Not applicable(i) Then
- Continue For
- End If
-
+ If Not applicable(i) Then Continue For
typeSet.Add(opSet(i).ReturnType)
Next
@@ -2217,17 +2020,14 @@ Done:
mostSpecificTargetType = MostEncompassing(typeSet, useSiteDiagnostics)
End If
- If typeSet IsNot Nothing Then
- typeSet.Free()
- End If
+ If typeSet IsNot Nothing Then typeSet.Free()
+
If mostSpecificSourceType IsNot Nothing AndAlso mostSpecificTargetType IsNot Nothing Then
bestMatch = ChooseMostSpecificConversionOperator(opSet, applicable, mostSpecificSourceType, mostSpecificTargetType, bestMatchIsAmbiguous)
End If
- If bestMatch IsNot Nothing AndAlso bestMatchIsAmbiguous Then
- bestMatch = Nothing
- End If
+ If bestMatch IsNot Nothing AndAlso bestMatchIsAmbiguous Then bestMatch = Nothing
Else
For i As Integer = 0 To opSet.Count - 1
If applicable(i) Then
@@ -2258,9 +2058,8 @@ Done:
bestMatchIsAmbiguous = False
For i As Integer = 0 To opSet.Count - 1
- If Not applicable(i) Then
- Continue For
- End If
+ If Not applicable(i) Then Continue For
+
Dim method As MethodSymbol = opSet(i)
@@ -2556,10 +2355,7 @@ Done:
Next
#End If
If bestMatch IsNot Nothing Then
- If bestMatchIsAmbiguous Then
- bestMatch = Nothing
- End If
-
+ If bestMatchIsAmbiguous Then bestMatch = Nothing
Return True
End If
@@ -2575,14 +2371,10 @@ Done:
typeSet = ArrayBuilder(Of TypeSymbol).GetInstance()
For i As Integer = 0 To opSet.Count - 1
- If Not applicable(i) Then
- Continue For
- End If
+ If Not applicable(i) Then Continue For
If haveWideningInConversions <> 0 Then
- If Not Conversions.IsWideningConversion(conversionKinds(i).Key) Then
- Continue For
- End If
+ If Not Conversions.IsWideningConversion(conversionKinds(i).Key) Then Continue For
Else
Debug.Assert(Conversions.IsNarrowingConversion(conversionKinds(i).Key))
End If
@@ -2607,14 +2399,10 @@ Done:
End If
For i As Integer = 0 To opSet.Count - 1
- If Not applicable(i) Then
- Continue For
- End If
+ If Not applicable(i) Then Continue For
If haveWideningOutConversions <> 0 Then
- If Not Conversions.IsWideningConversion(conversionKinds(i).Value) Then
- Continue For
- End If
+ If Not Conversions.IsWideningConversion(conversionKinds(i).Value) Then Continue For
Else
Debug.Assert(Conversions.IsNarrowingConversion(conversionKinds(i).Value))
End If
@@ -2631,9 +2419,7 @@ Done:
End If
End If
- If typeSet IsNot Nothing Then
- typeSet.Free()
- End If
+ If typeSet IsNot Nothing Then typeSet.Free()
If mostSpecificSourceType IsNot Nothing AndAlso mostSpecificTargetType IsNot Nothing Then
bestMatch = ChooseMostSpecificConversionOperator(opSet, applicable, mostSpecificSourceType, mostSpecificTargetType, bestMatchIsAmbiguous)
@@ -2678,9 +2464,7 @@ Done:
Debug.Assert(Not type.IsErrorType())
For j As Integer = 0 To typeSet.Count - 1
- If i = j Then
- Continue For
- End If
+ If i = j Then Continue For
Dim conv As ConversionKind = Conversions.ClassifyPredefinedConversion(type, typeSet(j), useSiteDiagnostics)
@@ -2723,10 +2507,7 @@ Next_i:
Debug.Assert(Not type.IsErrorType())
For j As Integer = 0 To typeSet.Count - 1
- If i = j Then
- Continue For
- End If
-
+ If i = j Then Continue For
Dim conv As ConversionKind = Conversions.ClassifyPredefinedConversion(typeSet(j), type, useSiteDiagnostics)
If Not Conversions.IsWideningConversion(conv) Then
@@ -2778,9 +2559,7 @@ Next_i:
''' Returns number of types in the list of {input type, output type} that refer to a generic type parameter.
'''
Private Shared Function DetermineConversionOperatorDegreeOfGenericity(method As MethodSymbol) As Integer
- If Not method.ContainingType.IsGenericType Then
- Return 0
- End If
+ If Not method.ContainingType.IsGenericType Then Return 0
Dim result As Integer = 0
Dim definition As MethodSymbol = method.OriginalDefinition
@@ -2804,9 +2583,7 @@ Next_i:
Debug.Assert(method.MethodKind = MethodKind.Conversion)
Dim forth As Char = method.Name(3)
- If forth = "I"c OrElse forth = "i"c Then
- Return True
- End If
+ If forth = "I"c OrElse forth = "i"c Then Return True
Debug.Assert(forth = "E"c OrElse forth = "e"c)
Return False
@@ -2824,8 +2601,8 @@ Next_i:
<[In], Out> ByRef useSiteDiagnostics As HashSet(Of DiagnosticInfo)
)
CollectUserDefinedOperators(source, destination, MethodKind.Conversion,
- WellKnownMemberNames.ImplicitConversionName, New OperatorInfo(UnaryOperatorKind.Implicit),
- WellKnownMemberNames.ExplicitConversionName, New OperatorInfo(UnaryOperatorKind.Explicit),
+ WKMN.ImplicitConversionName, New OperatorInfo(UnaryOperatorKind.Implicit),
+ WKMN.ExplicitConversionName, New OperatorInfo(UnaryOperatorKind.Explicit),
opSet, useSiteDiagnostics)
End Sub
@@ -2847,9 +2624,7 @@ Next_i:
)
type1 = GetTypeToLookForOperatorsIn(type1, useSiteDiagnostics)
- If type2 IsNot Nothing Then
- type2 = GetTypeToLookForOperatorsIn(type2, useSiteDiagnostics)
- End If
+ If type2 IsNot Nothing Then type2 = GetTypeToLookForOperatorsIn(type2, useSiteDiagnostics)
Dim commonAncestor As NamedTypeSymbol = Nothing
@@ -2909,9 +2684,8 @@ Next_i:
Dim method = DirectCast(member, MethodSymbol)
If method.MethodKind = opKind Then
- If method.IsShadows Then
- stopClimbing = True
- End If
+ If method.IsShadows Then stopClimbing = True
+
' Operators that were declared in syntax may not satisfy all the constraints on user-defined operators -
' they require extra validation.
@@ -2943,7 +2717,7 @@ Next_i:
Dim opSet = ArrayBuilder(Of MethodSymbol).GetInstance()
CollectUserDefinedOperators(argument.Type, Nothing, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.TrueOperatorName, New OperatorInfo(UnaryOperatorKind.IsTrue),
+ WKMN.TrueOperatorName, New OperatorInfo(UnaryOperatorKind.IsTrue),
Nothing, Nothing,
opSet, useSiteDiagnostics)
@@ -2957,7 +2731,7 @@ Next_i:
Dim opSet = ArrayBuilder(Of MethodSymbol).GetInstance()
CollectUserDefinedOperators(argument.Type, Nothing, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.FalseOperatorName, New OperatorInfo(UnaryOperatorKind.IsFalse),
+ WKMN.FalseOperatorName, New OperatorInfo(UnaryOperatorKind.IsFalse),
Nothing, Nothing,
opSet, useSiteDiagnostics)
@@ -2980,17 +2754,17 @@ Next_i:
Case UnaryOperatorKind.Not
Dim opInfo As New OperatorInfo(UnaryOperatorKind.Not)
CollectUserDefinedOperators(argument.Type, Nothing, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.OnesComplementOperatorName, opInfo,
- WellKnownMemberNames.LogicalNotOperatorName, opInfo,
+ WKMN.OnesComplementOperatorName, opInfo,
+ WKMN.LogicalNotOperatorName, opInfo,
opSet, useSiteDiagnostics)
Case UnaryOperatorKind.Minus
CollectUserDefinedOperators(argument.Type, Nothing, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.UnaryNegationOperatorName, New OperatorInfo(UnaryOperatorKind.Minus),
+ WKMN.UnaryNegationOperatorName, New OperatorInfo(UnaryOperatorKind.Minus),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case UnaryOperatorKind.Plus
CollectUserDefinedOperators(argument.Type, Nothing, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.UnaryPlusOperatorName, New OperatorInfo(UnaryOperatorKind.Minus),
+ WKMN.UnaryPlusOperatorName, New OperatorInfo(UnaryOperatorKind.Minus),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case Else
@@ -3016,108 +2790,108 @@ Next_i:
Select Case opKind
Case BinaryOperatorKind.Add
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.AdditionOperatorName, New OperatorInfo(opKind),
+ WKMN.AdditionOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Subtract
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.SubtractionOperatorName, New OperatorInfo(opKind),
+ WKMN.SubtractionOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Multiply
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.MultiplyOperatorName, New OperatorInfo(opKind),
+ WKMN.MultiplyOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Divide
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.DivisionOperatorName, New OperatorInfo(opKind),
+ WKMN.DivisionOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.IntegerDivide
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.IntegerDivisionOperatorName, New OperatorInfo(opKind),
+ WKMN.IntegerDivisionOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Modulo
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.ModulusOperatorName, New OperatorInfo(opKind),
+ WKMN.ModulusOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Power
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.ExponentOperatorName, New OperatorInfo(opKind),
+ WKMN.ExponentOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Equals
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.EqualityOperatorName, New OperatorInfo(opKind),
+ WKMN.EqualityOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.NotEquals
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.InequalityOperatorName, New OperatorInfo(opKind),
+ WKMN.InequalityOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.LessThan
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.LessThanOperatorName, New OperatorInfo(opKind),
+ WKMN.LessThanOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.GreaterThan
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.GreaterThanOperatorName, New OperatorInfo(opKind),
+ WKMN.GreaterThanOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.LessThanOrEqual
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.LessThanOrEqualOperatorName, New OperatorInfo(opKind),
+ WKMN.LessThanOrEqualOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.GreaterThanOrEqual
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.GreaterThanOrEqualOperatorName, New OperatorInfo(opKind),
+ WKMN.GreaterThanOrEqualOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Like
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.LikeOperatorName, New OperatorInfo(opKind),
+ WKMN.LikeOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Concatenate
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.ConcatenateOperatorName, New OperatorInfo(opKind),
+ WKMN.ConcatenateOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.And, BinaryOperatorKind.AndAlso
Dim opInfo As New OperatorInfo(opKind)
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.BitwiseAndOperatorName, opInfo,
- WellKnownMemberNames.LogicalAndOperatorName, opInfo,
+ WKMN.BitwiseAndOperatorName, opInfo,
+ WKMN.LogicalAndOperatorName, opInfo,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Or, BinaryOperatorKind.OrElse
Dim opInfo As New OperatorInfo(opKind)
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.BitwiseOrOperatorName, opInfo,
- WellKnownMemberNames.LogicalOrOperatorName, opInfo,
+ WKMN.BitwiseOrOperatorName, opInfo,
+ WKMN.LogicalOrOperatorName, opInfo,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.Xor
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.ExclusiveOrOperatorName, New OperatorInfo(opKind),
+ WKMN.ExclusiveOrOperatorName, New OperatorInfo(opKind),
Nothing, Nothing,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.LeftShift
Dim opInfo As New OperatorInfo(opKind)
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.LeftShiftOperatorName, opInfo,
- WellKnownMemberNames.UnsignedLeftShiftOperatorName, opInfo,
+ WKMN.LeftShiftOperatorName, opInfo,
+ WKMN.UnsignedLeftShiftOperatorName, opInfo,
opSet, useSiteDiagnostics)
Case BinaryOperatorKind.RightShift
Dim opInfo As New OperatorInfo(opKind)
CollectUserDefinedOperators(left.Type, right.Type, MethodKind.UserDefinedOperator,
- WellKnownMemberNames.RightShiftOperatorName, opInfo,
- WellKnownMemberNames.UnsignedRightShiftOperatorName, opInfo,
+ WKMN.RightShiftOperatorName, opInfo,
+ WKMN.UnsignedRightShiftOperatorName, opInfo,
opSet, useSiteDiagnostics)
Case Else
Throw ExceptionUtilities.UnexpectedValue(opKind)
@@ -3171,10 +2945,7 @@ Next_i:
Dim useSiteErrorInfo As DiagnosticInfo = method.GetUseSiteErrorInfo()
If useSiteErrorInfo IsNot Nothing Then
- If useSiteDiagnostics Is Nothing Then
- useSiteDiagnostics = New HashSet(Of DiagnosticInfo)()
- End If
-
+ If useSiteDiagnostics Is Nothing Then useSiteDiagnostics = New HashSet(Of DiagnosticInfo)()
useSiteDiagnostics.Add(useSiteErrorInfo)
If includeEliminatedCandidates Then
@@ -3194,8 +2965,8 @@ Next_i:
Dim param2 As ParameterSymbol = Nothing
Dim type2 As TypeSymbol = Nothing
- Dim isNullable2 As Boolean = False
- Dim canLift2 As Boolean = False
+ Dim isNullable2 = False
+ Dim canLift2 = False
If argument2 IsNot Nothing AndAlso Not isNullable1 Then
param2 = method.Parameters(1)
@@ -3206,18 +2977,12 @@ Next_i:
If (canLift1 OrElse canLift2) AndAlso Not isNullable1 AndAlso Not isNullable2 Then
' Should lift this operator.
- If canLift1 Then
- param1 = LiftParameterSymbol(param1, nullableOfT)
- End If
-
- If canLift2 Then
- param2 = LiftParameterSymbol(param2, nullableOfT)
- End If
+ If canLift1 Then param1 = LiftParameterSymbol(param1, nullableOfT)
+ If canLift2 Then param2 = LiftParameterSymbol(param2, nullableOfT)
Dim returnType As TypeSymbol = method.ReturnType
- If CanLiftType(returnType) Then
- returnType = nullableOfT.Construct(returnType)
- End If
+ If CanLiftType(returnType) Then returnType = nullableOfT.Construct(returnType)
+
CombineCandidates(candidates,
New CandidateAnalysisResult(New LiftedOperatorCandidate(method,
@@ -3255,15 +3020,10 @@ Next_i:
End Function
Private Shared Function LiftParameterSymbol(param As ParameterSymbol, nullableOfT As NamedTypeSymbol) As ParameterSymbol
-
- If param.IsDefinition Then
- Return New LiftedParameterSymbol(param, nullableOfT.Construct(param.Type))
- Else
- Dim definition As ParameterSymbol = param.OriginalDefinition
-
- Return SubstitutedParameterSymbol.CreateMethodParameter(DirectCast(param.ContainingSymbol, SubstitutedMethodSymbol),
- New LiftedParameterSymbol(definition, nullableOfT.Construct(definition.Type)))
- End If
+ If param.IsDefinition Then Return New LiftedParameterSymbol(param, nullableOfT.Construct(param.Type))
+ Dim definition As ParameterSymbol = param.OriginalDefinition
+ Return SubstitutedParameterSymbol.CreateMethodParameter(DirectCast(param.ContainingSymbol, SubstitutedMethodSymbol),
+ New LiftedParameterSymbol(definition, nullableOfT.Construct(definition.Type)))
End Function
Private NotInheritable Class LiftedParameterSymbol
diff --git a/src/Compilers/VisualBasic/Portable/Semantics/SemanticFacts.vb b/src/Compilers/VisualBasic/Portable/Semantics/SemanticFacts.vb
index 948df14b41343..1f81b7f080c14 100644
--- a/src/Compilers/VisualBasic/Portable/Semantics/SemanticFacts.vb
+++ b/src/Compilers/VisualBasic/Portable/Semantics/SemanticFacts.vb
@@ -37,13 +37,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public Shared Function IsSymbolAccessible(symbol As Symbol,
within As NamedTypeSymbol,
Optional throughTypeOpt As NamedTypeSymbol = Nothing) As Boolean
- If symbol Is Nothing Then
- Throw New ArgumentNullException("symbol")
- End If
-
- If within Is Nothing Then
- Throw New ArgumentNullException("within")
- End If
+ If symbol Is Nothing Then Throw New ArgumentNullException("symbol")
+ If within Is Nothing Then Throw New ArgumentNullException("within")
Return AccessCheck.IsSymbolAccessible(symbol, within, throughTypeOpt, useSiteDiagnostics:=Nothing)
End Function
@@ -57,14 +52,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' True if symbol is acessible. False otherwise.
Public Shared Function IsSymbolAccessible(symbol As Symbol,
within As AssemblySymbol) As Boolean
- If symbol Is Nothing Then
- Throw New ArgumentNullException("symbol")
- End If
-
- If within Is Nothing Then
- Throw New ArgumentNullException("within")
- End If
-
+ If symbol Is Nothing Then Throw New ArgumentNullException("symbol")
+ If within Is Nothing Then Throw New ArgumentNullException("within")
Return AccessCheck.IsSymbolAccessible(symbol, within, useSiteDiagnostics:=Nothing)
End Function
diff --git a/src/Compilers/VisualBasic/Portable/StringConstants.vb b/src/Compilers/VisualBasic/Portable/StringConstants.vb
index fbc8c00c4c22c..6cef5364666c5 100644
--- a/src/Compilers/VisualBasic/Portable/StringConstants.vb
+++ b/src/Compilers/VisualBasic/Portable/StringConstants.vb
@@ -11,116 +11,104 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub
' non localizable strings
- Friend Const AnonymousTypeName As String = ""
- Friend Const AnonymousMethodName As String = ""
- Friend Const AsEnumerableMethod As String = "AsEnumerable"
- Friend Const AsQueryableMethod As String = "AsQueryable"
- Friend Const DistinctMethod As String = "Distinct"
- Friend Const CastMethod As String = "Cast"
- Friend Const DelegateConstructorInstanceParameterName As String = "TargetObject"
- Friend Const DelegateConstructorMethodParameterName As String = "TargetMethod"
- Friend Const DelegateMethodCallbackParameterName As String = "DelegateCallback"
- Friend Const DelegateMethodInstanceParameterName As String = "DelegateAsyncState"
- Friend Const DelegateMethodResultParameterName As String = "DelegateAsyncResult"
- Friend Const DelegateStubParameterPrefix As String = "a"
- Friend Const ElementAtMethod As String = "ElementAtOrDefault"
- Friend Const Group As String = "$VB$Group"
- Friend Const GroupByMethod As String = "GroupBy"
- Friend Const GroupJoinMethod As String = "GroupJoin"
- Friend Const It As String = "$VB$It"
- Friend Const It1 As String = "$VB$It1"
- Friend Const It2 As String = "$VB$It2"
- Friend Const ItAnonymous As String = "$VB$ItAnonymous"
- Friend Const JoinMethod As String = "Join"
- Friend Const Lambda As String = "Lambda"
- Friend Const NamedSymbolErrorName As String = "?"
- Friend Const OrderByDescendingMethod As String = "OrderByDescending"
- Friend Const OrderByMethod As String = "OrderBy"
- Friend Const SelectManyMethod As String = "SelectMany"
- Friend Const SelectMethod As String = "Select"
- Friend Const SkipMethod As String = "Skip"
- Friend Const SkipWhileMethod As String = "SkipWhile"
- Friend Const TakeMethod As String = "Take"
- Friend Const TakeWhileMethod As String = "TakeWhile"
- Friend Const ThenByDescendingMethod As String = "ThenByDescending"
- Friend Const ThenByMethod As String = "ThenBy"
- Friend Const UnnamedNamespaceErrName As String = ""
- Friend Const WhereMethod As String = "Where"
+ Friend Const AnonymousTypeName = ""
+ Friend Const AnonymousMethodName = ""
+ Friend Const AsEnumerableMethod = "AsEnumerable"
+ Friend Const AsQueryableMethod = "AsQueryable"
+ Friend Const DistinctMethod = "Distinct"
+ Friend Const CastMethod = "Cast"
+ Friend Const DelegateConstructorInstanceParameterName = "TargetObject"
+ Friend Const DelegateConstructorMethodParameterName = "TargetMethod"
+ Friend Const DelegateMethodCallbackParameterName = "DelegateCallback"
+ Friend Const DelegateMethodInstanceParameterName = "DelegateAsyncState"
+ Friend Const DelegateMethodResultParameterName = "DelegateAsyncResult"
+ Friend Const DelegateStubParameterPrefix = "a"
+ Friend Const ElementAtMethod = "ElementAtOrDefault"
+ Friend Const Group = "$VB$Group"
+ Friend Const GroupByMethod = "GroupBy"
+ Friend Const GroupJoinMethod = "GroupJoin"
+ Friend Const It = "$VB$It"
+ Friend Const It1 = "$VB$It1"
+ Friend Const It2 = "$VB$It2"
+ Friend Const ItAnonymous = "$VB$ItAnonymous"
+ Friend Const JoinMethod = "Join"
+ Friend Const Lambda = "Lambda"
+ Friend Const NamedSymbolErrorName = "?"
+ Friend Const OrderByDescendingMethod = "OrderByDescending"
+ Friend Const OrderByMethod = "OrderBy"
+ Friend Const SelectManyMethod = "SelectMany"
+ Friend Const SelectMethod = "Select"
+ Friend Const SkipMethod = "Skip"
+ Friend Const SkipWhileMethod = "SkipWhile"
+ Friend Const TakeMethod = "Take"
+ Friend Const TakeWhileMethod = "TakeWhile"
+ Friend Const ThenByDescendingMethod = "ThenByDescending"
+ Friend Const ThenByMethod = "ThenBy"
+ Friend Const UnnamedNamespaceErrName = ""
+ Friend Const WhereMethod = "Where"
' EE recognized names (prefixes):
- Friend Const HoistedMeName As String = "$VB$Me"
- Friend Const HoistedUserVariablePrefix As String = "$VB$Local_"
- Friend Const HoistedSpecialVariablePrefix As String = "$VB$NonLocal_" ' prefixes Me and Closure variables when hoisted
- Friend Const HoistedWithLocalPrefix As String = "$W"
- Friend Const StateMachineHoistedUserVariablePrefix As String = "$VB$ResumableLocal_"
- Friend Const ClosureVariablePrefix As String = "$VB$Closure_"
- Friend Const DisplayClassPrefix As String = "_Closure$__"
- Friend Const StateMachineTypeNamePrefix As String = "VB$StateMachine_"
+ Friend Const HoistedMeName = "$VB$Me"
+ Friend Const HoistedUserVariablePrefix = "$VB$Local_"
+ Friend Const HoistedSpecialVariablePrefix = "$VB$NonLocal_" ' prefixes Me and Closure variables when hoisted
+ Friend Const HoistedWithLocalPrefix = "$W"
+ Friend Const StateMachineHoistedUserVariablePrefix = "$VB$ResumableLocal_"
+ Friend Const ClosureVariablePrefix = "$VB$Closure_"
+ Friend Const DisplayClassPrefix = "_Closure$__"
+ Friend Const StateMachineTypeNamePrefix = "VB$StateMachine_"
' Do not change the following strings. Other teams (FxCop) use this string to identify lambda functions in its analysis
' If you have to change this string, please contact the VB language PM and consider the impact of that break.
- Friend Const LambdaMethodNamePrefix As String = "_Lambda$__"
- Friend Const DisplayClassGenericParameterNamePrefix As String = "$CLS"
- Friend Const BaseMethodWrapperNamePrefix As String = "$VB$ClosureStub_"
+ Friend Const LambdaMethodNamePrefix = "_Lambda$__"
+ Friend Const DisplayClassGenericParameterNamePrefix = "$CLS"
+ Friend Const BaseMethodWrapperNamePrefix = "$VB$ClosureStub_"
' Microsoft.VisualStudio.VIL.VisualStudioHost.AsyncReturnStackFrame depends on these names.
- Friend Const StateMachineBuilderFieldName As String = "$Builder"
- Friend Const StateMachineStateFieldName As String = "$State"
-
- Friend Const DelegateRelaxationDisplayClassPrefix As String = DisplayClassPrefix & "R"
- Friend Const DelegateRelaxationMethodNamePrefix As String = LambdaMethodNamePrefix & "R"
- Friend Const HoistedSynthesizedLocalPrefix As String = "$S"
- Friend Const LambdaCacheFieldPrefix As String = "$I"
- Friend Const DelegateRelaxationCacheFieldPrefix As String = "$IR"
- Friend Const StateMachineAwaiterFieldPrefix As String = "$A"
- Friend Const ReusableHoistedLocalFieldName As String = "$U"
- Friend Const StateMachineExpressionCapturePrefix As String = "$V"
-
- Friend Const StateMachineTypeParameterPrefix As String = "SM$"
-
- Friend Const IteratorCurrentFieldName As String = "$Current"
- Friend Const IteratorInitialThreadIdName As String = "$InitialThreadId"
- Friend Const IteratorParameterProxyPrefix As String = "$P_"
-
- Friend Const StaticLocalFieldNamePrefix = "$STATIC$"
-
- Friend Const PropertyGetPrefix As String = "get_"
- Friend Const PropertySetPrefix As String = "set_"
- Friend Const WinMdPropertySetPrefix As String = "put_"
-
- Friend Const ValueParameterName As String = "Value"
- Friend Const WithEventsValueParameterName As String = "WithEventsValue"
- Friend Const AutoPropertyValueParameterName As String = "AutoPropertyValue"
-
- Friend Const DefaultXmlnsPrefix As String = ""
- Friend Const DefaultXmlNamespace As String = ""
- Friend Const XmlPrefix As String = "xml"
- Friend Const XmlNamespace As String = "http://www.w3.org/XML/1998/namespace"
- Friend Const XmlnsPrefix As String = "xmlns"
- Friend Const XmlnsNamespace As String = "http://www.w3.org/2000/xmlns/"
-
- Friend Const XmlAddMethodName As String = "Add"
- Friend Const XmlGetMethodName As String = "Get"
- Friend Const XmlElementsMethodName As String = "Elements"
- Friend Const XmlDescendantsMethodName As String = "Descendants"
- Friend Const XmlAttributeValueMethodName As String = "AttributeValue"
- Friend Const XmlCreateAttributeMethodName As String = "CreateAttribute"
- Friend Const XmlCreateNamespaceAttributeMethodName As String = "CreateNamespaceAttribute"
- Friend Const XmlRemoveNamespaceAttributesMethodName As String = "RemoveNamespaceAttributes"
-
- Friend Const ValueProperty As String = "Value"
+ Friend Const StateMachineBuilderFieldName = "$Builder"
+ Friend Const StateMachineStateFieldName = "$State"
+
+ Friend Const DelegateRelaxationDisplayClassPrefix = DisplayClassPrefix & "R"
+ Friend Const DelegateRelaxationMethodNamePrefix = LambdaMethodNamePrefix & "R"
+ Friend Const HoistedSynthesizedLocalPrefix = "$S"
+ Friend Const LambdaCacheFieldPrefix = "$I"
+ Friend Const DelegateRelaxationCacheFieldPrefix = "$IR"
+ Friend Const StateMachineAwaiterFieldPrefix = "$A"
+ Friend Const ReusableHoistedLocalFieldName = "$U"
+ Friend Const StateMachineExpressionCapturePrefix = "$V"
+ Friend Const StateMachineTypeParameterPrefix = "SM$"
+ Friend Const IteratorCurrentFieldName = "$Current"
+ Friend Const IteratorInitialThreadIdName = "$InitialThreadId"
+ Friend Const IteratorParameterProxyPrefix = "$P_"
+ Friend Const StaticLocalFieldNamePrefix = "$STATIC$"
+ Friend Const PropertyGetPrefix = "get_"
+ Friend Const PropertySetPrefix = "set_"
+ Friend Const WinMdPropertySetPrefix = "put_"
+ Friend Const ValueParameterName = "Value"
+ Friend Const WithEventsValueParameterName = "WithEventsValue"
+ Friend Const AutoPropertyValueParameterName = "AutoPropertyValue"
+ Friend Const DefaultXmlnsPrefix = ""
+ Friend Const DefaultXmlNamespace = ""
+ Friend Const XmlPrefix = "xml"
+ Friend Const XmlNamespace = "http://www.w3.org/XML/1998/namespace"
+ Friend Const XmlnsPrefix = "xmlns"
+ Friend Const XmlnsNamespace = "http://www.w3.org/2000/xmlns/"
+ Friend Const XmlAddMethodName = "Add"
+ Friend Const XmlGetMethodName = "Get"
+ Friend Const XmlElementsMethodName = "Elements"
+ Friend Const XmlDescendantsMethodName = "Descendants"
+ Friend Const XmlAttributeValueMethodName = "AttributeValue"
+ Friend Const XmlCreateAttributeMethodName = "CreateAttribute"
+ Friend Const XmlCreateNamespaceAttributeMethodName = "CreateNamespaceAttribute"
+ Friend Const XmlRemoveNamespaceAttributesMethodName = "RemoveNamespaceAttributes"
+ Friend Const ValueProperty = "Value"
End Class
Friend Module Constants
- Friend Const ATTACH_LISTENER_PREFIX As String = "add_"
-
- Friend Const REMOVE_LISTENER_PREFIX As String = "remove_"
-
- Friend Const FIRE_LISTENER_PREFIX As String = "raise_"
-
- Friend Const EVENT_DELEGATE_SUFFIX As String = "EventHandler"
-
- Friend Const EVENT_VARIABLE_SUFFIX As String = "Event"
+ Friend Const ATTACH_LISTENER_PREFIX = "add_"
+ Friend Const REMOVE_LISTENER_PREFIX = "remove_"
+ Friend Const FIRE_LISTENER_PREFIX = "raise_"
+ Friend Const EVENT_DELEGATE_SUFFIX = "EventHandler"
+ Friend Const EVENT_VARIABLE_SUFFIX = "Event"
End Module
End Namespace
diff --git a/src/Compilers/VisualBasic/Portable/VisualBasicExtensions.vb b/src/Compilers/VisualBasic/Portable/VisualBasicExtensions.vb
index e3d47d8e9b60c..34508fc77dda6 100644
--- a/src/Compilers/VisualBasic/Portable/VisualBasicExtensions.vb
+++ b/src/Compilers/VisualBasic/Portable/VisualBasicExtensions.vb
@@ -208,11 +208,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Function GetLocation(syntaxReference As SyntaxReference) As Location
Dim tree = TryCast(syntaxReference.SyntaxTree, VisualBasicSyntaxTree)
If syntaxReference.SyntaxTree IsNot Nothing Then
- If tree.IsEmbeddedSyntaxTree Then
- Return New EmbeddedTreeLocation(tree.GetEmbeddedKind, syntaxReference.Span)
- ElseIf tree.IsMyTemplate Then
- Return New MyTemplateLocation(tree, syntaxReference.Span)
- End If
+ If tree.IsEmbeddedSyntaxTree Then Return New EmbeddedTreeLocation(tree.GetEmbeddedKind, syntaxReference.Span)
+ If tree.IsMyTemplate Then Return New MyTemplateLocation(tree, syntaxReference.Span)
End If
Return New SourceLocation(syntaxReference)
End Function
diff --git a/src/Compilers/VisualBasic/Portable/_Exts/Char.vb b/src/Compilers/VisualBasic/Portable/_Exts/Char.vb
new file mode 100644
index 0000000000000..3ae1656715b96
--- /dev/null
+++ b/src/Compilers/VisualBasic/Portable/_Exts/Char.vb
@@ -0,0 +1,33 @@
+Imports System.Runtime.CompilerServices
+
+Namespace Global.Exts
+
+ Friend Module [Char]
+
+
+ Public Function IsAnyOf(c As Char, c0 As Char, c1 As Char) As Boolean
+ Return (c = c0) OrElse (c = c1)
+ End Function
+
+
+ Public Function IsAnyOf(c As Char, c0 As Char, c1 As Char, c2 As Char) As Boolean
+ Return (c = c0) OrElse (c = c1) OrElse (c = c2)
+ End Function
+
+
+ Public Function IsAnyOf(c As Char, c0 As Char, c1 As Char, c2 As Char, c3 As Char) As Boolean
+ Return (c = c0) OrElse (c = c1) OrElse (c = c2) OrElse (c = c3)
+ End Function
+
+
+ Public Function IsAnyOf(c As Char, c0 As Char, c1 As Char, c2 As Char, c3 As Char, c4 As Char) As Boolean
+ Return (c = c0) OrElse (c = c1) OrElse (c = c2) OrElse (c = c3) OrElse (c = c4)
+ End Function
+
+ Public Function IsAnyOf(c As Char, c0 As Char, c1 As Char, c2 As Char, c3 As Char, c4 As Char, c5 As Char) As Boolean
+ Return (c = c0) OrElse (c = c1) OrElse (c = c2) OrElse (c = c3) OrElse (c = c4) OrElse (c = c5)
+ End Function
+
+ End Module
+
+ End Namespace
\ No newline at end of file