-
Notifications
You must be signed in to change notification settings - Fork 4k
/
LanguageVersion.vb
197 lines (175 loc) · 7.08 KB
/
LanguageVersion.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Runtime.CompilerServices
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Namespace Microsoft.CodeAnalysis.VisualBasic
''' <summary>
''' Supported Visual Basic language versions.
''' </summary>
Public Enum LanguageVersion
[Default] = 0
VisualBasic9 = 9
VisualBasic10 = 10
VisualBasic11 = 11
VisualBasic12 = 12
VisualBasic14 = 14
VisualBasic15 = 15
VisualBasic15_3 = 1503
VisualBasic15_5 = 1505
VisualBasic16 = 1600
Latest = Integer.MaxValue
End Enum
Friend Module LanguageVersionEnumBounds
<Extension>
Friend Function IsValid(value As LanguageVersion) As Boolean
Select Case value
Case LanguageVersion.VisualBasic9,
LanguageVersion.VisualBasic10,
LanguageVersion.VisualBasic11,
LanguageVersion.VisualBasic12,
LanguageVersion.VisualBasic14,
LanguageVersion.VisualBasic15,
LanguageVersion.VisualBasic15_3,
LanguageVersion.VisualBasic15_5,
LanguageVersion.VisualBasic16
Return True
End Select
Return False
End Function
<Extension>
Friend Function GetErrorName(value As LanguageVersion) As String
Select Case value
Case LanguageVersion.VisualBasic9
Return "9.0"
Case LanguageVersion.VisualBasic10
Return "10.0"
Case LanguageVersion.VisualBasic11
Return "11.0"
Case LanguageVersion.VisualBasic12
Return "12.0"
Case LanguageVersion.VisualBasic14
Return "14.0"
Case LanguageVersion.VisualBasic15
Return "15.0"
Case LanguageVersion.VisualBasic15_3
Return "15.3"
Case LanguageVersion.VisualBasic15_5
Return "15.5"
Case LanguageVersion.VisualBasic16
Return "16"
Case Else
Throw ExceptionUtilities.UnexpectedValue(value)
End Select
End Function
End Module
Public Module LanguageVersionFacts
''' <summary>
''' Map a language version (such as Default, Latest, Or VisualBasicN) to a specific version (VisualBasicN).
''' </summary>
<Extension>
Public Function MapSpecifiedToEffectiveVersion(version As LanguageVersion) As LanguageVersion
Select Case version
Case LanguageVersion.Latest,
LanguageVersion.Default
Return LanguageVersion.VisualBasic16
Case Else
Return version
End Select
End Function
Friend ReadOnly Property CurrentVersion As LanguageVersion
Get
Return LanguageVersion.VisualBasic16
End Get
End Property
''' <summary>
''' Displays the version number in the format understood on the command-line (/langver flag).
''' For instance, "9", "15", "latest".
''' </summary>
<Extension>
Public Function ToDisplayString(version As LanguageVersion) As String
Select Case version
Case LanguageVersion.VisualBasic9
Return "9"
Case LanguageVersion.VisualBasic10
Return "10"
Case LanguageVersion.VisualBasic11
Return "11"
Case LanguageVersion.VisualBasic12
Return "12"
Case LanguageVersion.VisualBasic14
Return "14"
Case LanguageVersion.VisualBasic15
Return "15"
Case LanguageVersion.VisualBasic15_3
Return "15.3"
Case LanguageVersion.VisualBasic15_5
Return "15.5"
Case LanguageVersion.VisualBasic16
Return "16"
Case LanguageVersion.Default
Return "default"
Case LanguageVersion.Latest
Return "latest"
Case Else
Throw ExceptionUtilities.UnexpectedValue(version)
End Select
End Function
''' <summary>
''' Parse a LanguageVersion from a string input, as the command-line compiler does.
''' </summary>
Public Function TryParse(version As String, ByRef result As LanguageVersion) As Boolean
If version Is Nothing Then
result = LanguageVersion.Default
Return False
End If
Select Case version.ToLowerInvariant()
Case "9", "9.0"
result = LanguageVersion.VisualBasic9
Case "10", "10.0"
result = LanguageVersion.VisualBasic10
Case "11", "11.0"
result = LanguageVersion.VisualBasic11
Case "12", "12.0"
result = LanguageVersion.VisualBasic12
Case "14", "14.0"
result = LanguageVersion.VisualBasic14
Case "15", "15.0"
result = LanguageVersion.VisualBasic15
Case "15.3"
result = LanguageVersion.VisualBasic15_3
Case "15.5"
result = LanguageVersion.VisualBasic15_5
Case "16"
result = LanguageVersion.VisualBasic16
Case "default"
result = LanguageVersion.Default
Case "latest"
result = LanguageVersion.Latest
Case Else
result = LanguageVersion.Default
Return False
End Select
Return True
End Function
''' <summary>Inference of tuple element names was added in VB 15.3</summary>
<Extension>
Friend Function DisallowInferredTupleElementNames(self As LanguageVersion) As Boolean
Return self < Feature.InferredTupleNames.GetLanguageVersion()
End Function
<Extension>
Friend Function AllowNonTrailingNamedArguments(self As LanguageVersion) As Boolean
Return self >= Feature.NonTrailingNamedArguments.GetLanguageVersion()
End Function
End Module
Friend Class VisualBasicRequiredLanguageVersion
Inherits RequiredLanguageVersion
Friend ReadOnly Property Version As LanguageVersion
Friend Sub New(version As LanguageVersion)
Me.Version = version
End Sub
Public Overrides Function ToString() As String
Return Version.ToDisplayString()
End Function
End Class
End Namespace