Skip to content

Commit 54dbece

Browse files
KvanTTTparrt
authored andcommitted
ATN serialized data: remove shifting by 2, remove UUID; fix #3515
Regenerate XPathLexer files
1 parent 95f2ab0 commit 54dbece

File tree

20 files changed

+369
-1574
lines changed

20 files changed

+369
-1574
lines changed

runtime/CSharp/src/Atn/ATNDeserializer.cs

Lines changed: 5 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Globalization;
8-
using System.IO;
9-
using Antlr4.Runtime.Atn;
108
using Antlr4.Runtime.Dfa;
119
using Antlr4.Runtime.Misc;
1210
using Antlr4.Runtime.Sharpen;
@@ -16,53 +14,11 @@ namespace Antlr4.Runtime.Atn
1614
/// <author>Sam Harwell</author>
1715
public class ATNDeserializer
1816
{
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;
6018

6119
[NotNull]
6220
private readonly ATNDeserializationOptions deserializationOptions;
6321

64-
private Guid uuid;
65-
6622
public ATNDeserializer()
6723
: this(ATNDeserializationOptions.Default)
6824
{
@@ -77,66 +33,21 @@ public ATNDeserializer(ATNDeserializationOptions deserializationOptions)
7733
this.deserializationOptions = deserializationOptions;
7834
}
7935

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-
12236
char[] data;
12337
int p;
12438

12539
public virtual ATN Deserialize(char[] data)
12640
{
127-
Reset (data);
41+
this.data = data;
12842
CheckVersion ();
129-
CheckUUID ();
13043
ATN atn = ReadATN ();
13144
ReadStates (atn);
13245
ReadRules (atn);
13346
ReadModes (atn);
13447
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);
14051
ReadDecisions (atn);
14152
ReadLexerActions (atn);
14253
MarkPrecedenceDecisions(atn);
@@ -546,16 +457,6 @@ protected internal virtual ATN ReadATN()
546457
return new ATN(grammarType, maxTokenType);
547458
}
548459

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-
559460
protected internal virtual void CheckVersion()
560461
{
561462
int version = ReadInt();
@@ -566,18 +467,6 @@ protected internal virtual void CheckVersion()
566467
}
567468
}
568469

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-
581470
/// <summary>
582471
/// Analyze the
583472
/// <see cref="StarLoopEntryState"/>
@@ -1083,25 +972,6 @@ protected internal int ReadInt32()
1083972
return (int)data[p++] | ((int)data[p++] << 16);
1084973
}
1085974

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-
1105975
[return: NotNull]
1106976
protected internal virtual Transition EdgeFactory(ATN atn, TransitionType type, int src, int trg, int arg1, int arg2, int arg3, IList<IntervalSet> sets)
1107977
{

0 commit comments

Comments
 (0)