5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . Globalization ;
8
- using System . IO ;
9
- using Antlr4 . Runtime . Atn ;
10
8
using Antlr4 . Runtime . Dfa ;
11
9
using Antlr4 . Runtime . Misc ;
12
10
using Antlr4 . Runtime . Sharpen ;
@@ -16,53 +14,11 @@ namespace Antlr4.Runtime.Atn
16
14
/// <author>Sam Harwell</author>
17
15
public class ATNDeserializer
18
16
{
19
- public static readonly int SerializedVersion = 3 ;
20
-
21
- /// <summary>This is the earliest supported serialized UUID.</summary>
22
- /// <remarks>This is the earliest supported serialized UUID.</remarks>
23
- private static readonly Guid BaseSerializedUuid ;
24
-
25
- /// <summary>
26
- /// This UUID indicates the serialized ATN contains two sets of
27
- /// IntervalSets, where the second set's values are encoded as
28
- /// 32-bit integers to support the full Unicode SMP range up to U+10FFFF.
29
- /// </summary>
30
- /// <remarks>
31
- /// This UUID indicates the serialized ATN contains two sets of
32
- /// IntervalSets, where the second set's values are encoded as
33
- /// 32-bit integers to support the full Unicode SMP range up to U+10FFFF.
34
- /// </remarks>
35
- private static readonly Guid AddedUnicodeSmp ;
36
-
37
- /// <summary>
38
- /// This list contains all of the currently supported UUIDs, ordered by when
39
- /// the feature first appeared in this branch.
40
- /// </summary>
41
- /// <remarks>
42
- /// This list contains all of the currently supported UUIDs, ordered by when
43
- /// the feature first appeared in this branch.
44
- /// </remarks>
45
- private static readonly IList < Guid > SupportedUuids ;
46
-
47
- /// <summary>This is the current serialized UUID.</summary>
48
- /// <remarks>This is the current serialized UUID.</remarks>
49
- public static readonly Guid SerializedUuid ;
50
-
51
- static ATNDeserializer ( )
52
- {
53
- BaseSerializedUuid = new Guid ( "AADB8D7E-AEEF-4415-AD2B-8204D6CF042E" ) ;
54
- AddedUnicodeSmp = new Guid ( "59627784-3BE5-417A-B9EB-8131A7286089" ) ;
55
- SupportedUuids = new List < Guid > ( ) ;
56
- SupportedUuids . Add ( BaseSerializedUuid ) ;
57
- SupportedUuids . Add ( AddedUnicodeSmp ) ;
58
- SerializedUuid = AddedUnicodeSmp ;
59
- }
17
+ public static readonly int SerializedVersion = 4 ;
60
18
61
19
[ NotNull ]
62
20
private readonly ATNDeserializationOptions deserializationOptions ;
63
21
64
- private Guid uuid ;
65
-
66
22
public ATNDeserializer ( )
67
23
: this ( ATNDeserializationOptions . Default )
68
24
{
@@ -77,66 +33,21 @@ public ATNDeserializer(ATNDeserializationOptions deserializationOptions)
77
33
this . deserializationOptions = deserializationOptions ;
78
34
}
79
35
80
- /// <summary>
81
- /// Determines if a particular serialized representation of an ATN supports
82
- /// a particular feature, identified by the
83
- /// <see cref="Guid"/>
84
- /// used for serializing
85
- /// the ATN at the time the feature was first introduced.
86
- /// </summary>
87
- /// <param name="feature">
88
- /// The
89
- /// <see cref="Guid"/>
90
- /// marking the first time the feature was
91
- /// supported in the serialized ATN.
92
- /// </param>
93
- /// <param name="actualUuid">
94
- /// The
95
- /// <see cref="Guid"/>
96
- /// of the actual serialized ATN which is
97
- /// currently being deserialized.
98
- /// </param>
99
- /// <returns>
100
- ///
101
- /// <see langword="true"/>
102
- /// if the
103
- /// <paramref name="actualUuid"/>
104
- /// value represents a
105
- /// serialized ATN at or after the feature identified by
106
- /// <paramref name="feature"/>
107
- /// was
108
- /// introduced; otherwise,
109
- /// <see langword="false"/>
110
- /// .
111
- /// </returns>
112
- protected internal virtual bool IsFeatureSupported ( Guid feature , Guid actualUuid )
113
- {
114
- int featureIndex = SupportedUuids . IndexOf ( feature ) ;
115
- if ( featureIndex < 0 )
116
- {
117
- return false ;
118
- }
119
- return SupportedUuids . IndexOf ( actualUuid ) >= featureIndex ;
120
- }
121
-
122
36
char [ ] data ;
123
37
int p ;
124
38
125
39
public virtual ATN Deserialize ( char [ ] data )
126
40
{
127
- Reset ( data ) ;
41
+ this . data = data ;
128
42
CheckVersion ( ) ;
129
- CheckUUID ( ) ;
130
43
ATN atn = ReadATN ( ) ;
131
44
ReadStates ( atn ) ;
132
45
ReadRules ( atn ) ;
133
46
ReadModes ( atn ) ;
134
47
IList < IntervalSet > sets = new List < IntervalSet > ( ) ;
135
- ReadSets ( atn , sets , this . ReadInt ) ;
136
- if ( IsFeatureSupported ( AddedUnicodeSmp , uuid ) ) {
137
- ReadSets ( atn , sets , this . ReadInt32 ) ;
138
- }
139
- ReadEdges ( atn , sets ) ;
48
+ ReadSets ( atn , sets , ReadInt ) ;
49
+ ReadSets ( atn , sets , ReadInt32 ) ;
50
+ ReadEdges ( atn , sets ) ;
140
51
ReadDecisions ( atn ) ;
141
52
ReadLexerActions ( atn ) ;
142
53
MarkPrecedenceDecisions ( atn ) ;
@@ -546,16 +457,6 @@ protected internal virtual ATN ReadATN()
546
457
return new ATN ( grammarType , maxTokenType ) ;
547
458
}
548
459
549
- protected internal virtual void CheckUUID ( )
550
- {
551
- uuid = ReadUUID ( ) ;
552
- if ( ! SupportedUuids . Contains ( uuid ) )
553
- {
554
- string reason = string . Format ( CultureInfo . CurrentCulture , "Could not deserialize ATN with UUID {0} (expected {1} or a legacy UUID)." , uuid , SerializedUuid ) ;
555
- throw new NotSupportedException ( reason ) ;
556
- }
557
- }
558
-
559
460
protected internal virtual void CheckVersion ( )
560
461
{
561
462
int version = ReadInt ( ) ;
@@ -566,18 +467,6 @@ protected internal virtual void CheckVersion()
566
467
}
567
468
}
568
469
569
- protected internal virtual void Reset ( char [ ] data )
570
- {
571
- this . data = new char [ data . Length ] ;
572
- // don't adjust the first value since that's the version number
573
- this . data [ 0 ] = data [ 0 ] ;
574
- for ( int i = 1 ; i < data . Length ; i ++ )
575
- {
576
- this . data [ i ] = ( char ) ( data [ i ] - 2 ) ;
577
- }
578
- this . p = 0 ;
579
- }
580
-
581
470
/// <summary>
582
471
/// Analyze the
583
472
/// <see cref="StarLoopEntryState"/>
@@ -1083,25 +972,6 @@ protected internal int ReadInt32()
1083
972
return ( int ) data [ p ++ ] | ( ( int ) data [ p ++ ] << 16 ) ;
1084
973
}
1085
974
1086
- protected internal long ReadLong ( )
1087
- {
1088
- long lowOrder = ReadInt32 ( ) & unchecked ( ( long ) ( 0x00000000FFFFFFFFL ) ) ;
1089
- return lowOrder | ( ( long ) ReadInt32 ( ) << 32 ) ;
1090
- }
1091
-
1092
- protected internal Guid ReadUUID ( )
1093
- {
1094
- byte [ ] d = BitConverter . GetBytes ( ReadLong ( ) ) ;
1095
- if ( BitConverter . IsLittleEndian )
1096
- {
1097
- Array . Reverse ( d ) ;
1098
- }
1099
- short c = ( short ) ReadInt ( ) ;
1100
- short b = ( short ) ReadInt ( ) ;
1101
- int a = ReadInt32 ( ) ;
1102
- return new Guid ( a , b , c , d ) ;
1103
- }
1104
-
1105
975
[ return : NotNull ]
1106
976
protected internal virtual Transition EdgeFactory ( ATN atn , TransitionType type , int src , int trg , int arg1 , int arg2 , int arg3 , IList < IntervalSet > sets )
1107
977
{
0 commit comments