@@ -562,22 +563,20 @@ public virtual ITokenFactory TokenFactory
[return: NotNull]
public virtual ATN GetATNWithBypassAlts()
{
- string serializedAtn = SerializedAtn;
+ int[] serializedAtn = SerializedAtn;
if (serializedAtn == null)
{
throw new NotSupportedException("The current parser does not support an ATN with bypass alternatives.");
}
- lock (bypassAltsAtnCache)
+ lock (this)
{
- ATN result = bypassAltsAtnCache.Get(serializedAtn);
- if (result == null)
- {
- ATNDeserializationOptions deserializationOptions = new ATNDeserializationOptions();
- deserializationOptions.GenerateRuleBypassTransitions = true;
- result = new ATNDeserializer(deserializationOptions).Deserialize(serializedAtn.ToCharArray());
- bypassAltsAtnCache.Put(serializedAtn, result);
+ if ( bypassAltsAtnCache!=null ) {
+ return bypassAltsAtnCache;
}
- return result;
+ ATNDeserializationOptions deserializationOptions = new ATNDeserializationOptions();
+ deserializationOptions.GenerateRuleBypassTransitions = true;
+ bypassAltsAtnCache = new ATNDeserializer(deserializationOptions).Deserialize(serializedAtn);
+ return bypassAltsAtnCache;
}
}
diff --git a/runtime/CSharp/src/Recognizer.cs b/runtime/CSharp/src/Recognizer.cs
index 5f24bb00e4..0ab2894551 100644
--- a/runtime/CSharp/src/Recognizer.cs
+++ b/runtime/CSharp/src/Recognizer.cs
@@ -131,7 +131,7 @@ public virtual int GetTokenType(string tokenName)
/// For interpreters, we don't know their serialized ATN despite having
/// created the interpreter from it.
///
- public virtual string SerializedAtn
+ public virtual int[] SerializedAtn
{
[return: NotNull]
get
diff --git a/runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs b/runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs
index 6deab10811..d2cb6e9665 100644
--- a/runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs
+++ b/runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs
@@ -301,7 +301,11 @@ public virtual ParseTreePattern Compile(string pattern, int patternRuleIndex)
IList