');
- if (current.GetReturnState(i) == PredictionContext.EmptyFullStateKey)
- {
- nodes.Append('$');
- }
- else if (current.GetReturnState(i) == PredictionContext.EmptyLocalStateKey)
- {
- nodes.Append('*');
- }
- }
- }
- else
- {
- nodes.Append(contextIds[current]);
- }
-
- nodes.AppendLine("\"];");
-
- for (int i = 0; i < current.Size; i++)
- {
- if (current.GetReturnState(i) == PredictionContext.EmptyFullStateKey
- || current.GetReturnState(i) == PredictionContext.EmptyLocalStateKey)
- {
- continue;
- }
-
- if (!visited.ContainsKey(current.GetParent(i)))
- {
- visited[current.GetParent(i)] = current.GetParent(i);
- contextIds[current.GetParent(i)] = contextIds.Count;
- workList.Push(current.GetParent(i));
- }
-
- edges.Append(" s").Append(contextIds[current]);
- if (current.Size > 1)
- {
- edges.Append(":p").Append(i);
- }
-
- edges.Append("->");
- edges.Append('s').Append(contextIds[current.GetParent(i)]);
- edges.Append("[label=\"").Append(current.GetReturnState(i)).Append("\"]");
- edges.AppendLine(";");
- }
- }
-
- StringBuilder builder = new StringBuilder();
- builder.AppendLine("digraph G {");
- builder.AppendLine("rankdir=LR;");
- builder.Append(nodes);
- builder.Append(edges);
- builder.AppendLine("}");
- return builder.ToString();
- }
-
- private class IdentityHashMap : Dictionary
- where TKey : class
- {
- public IdentityHashMap()
- : base(IdentityEqualityComparer.Default)
- {
- }
- }
-
- private class IdentityEqualityComparer : IEqualityComparer
- where T : class
- {
- private static readonly IdentityEqualityComparer _default = new IdentityEqualityComparer();
-
- public static IdentityEqualityComparer Default
- {
- get
- {
- return _default;
- }
- }
-
- public bool Equals(T x, T y)
- {
- return x == y;
- }
-
- public int GetHashCode(T obj)
- {
- return RuntimeHelpers.GetHashCode(obj);
- }
- }
- }
-}
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TestIntervalSet.cs b/runtime/CSharp/Antlr4.Runtime.Test/TestIntervalSet.cs
deleted file mode 100644
index 2e5f67a27..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/TestIntervalSet.cs
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- * [The "BSD license"]
- * Copyright (c) 2013 Terence Parr
- * Copyright (c) 2013 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-namespace Antlr4.Runtime.Test
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Antlr4.Runtime.Misc;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
-
- [TestClass]
- public class TestIntervalSet
- {
- [TestMethod]
- public void TestSingleElement()
- {
- IntervalSet s = IntervalSet.Of(99);
- String expecting = "99";
- Assert.AreEqual(s.ToString(), expecting);
- }
-
- [TestMethod]
- public void TestIsolatedElements()
- {
- IntervalSet s = new IntervalSet();
- s.Add(1);
- s.Add('z');
- s.Add('\uFFF0');
- String expecting = "{1, 122, 65520}";
- Assert.AreEqual(s.ToString(), expecting);
- }
-
- [TestMethod]
- public void TestMixedRangesAndElements()
- {
- IntervalSet s = new IntervalSet();
- s.Add(1);
- s.Add('a', 'z');
- s.Add('0', '9');
- String expecting = "{1, 48..57, 97..122}";
- Assert.AreEqual(s.ToString(), expecting);
- }
-
- [TestMethod]
- public void TestSimpleAnd()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(13, 15);
- String expecting = "{13..15}";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestRangeAndIsolatedElement()
- {
- IntervalSet s = IntervalSet.Of('a', 'z');
- IntervalSet s2 = IntervalSet.Of('d');
- String expecting = "100";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestEmptyIntersection()
- {
- IntervalSet s = IntervalSet.Of('a', 'z');
- IntervalSet s2 = IntervalSet.Of('0', '9');
- String expecting = "{}";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestEmptyIntersectionSingleElements()
- {
- IntervalSet s = IntervalSet.Of('a');
- IntervalSet s2 = IntervalSet.Of('d');
- String expecting = "{}";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestNotSingleElement()
- {
- IntervalSet vocabulary = IntervalSet.Of(1, 1000);
- vocabulary.Add(2000, 3000);
- IntervalSet s = IntervalSet.Of(50, 50);
- String expecting = "{1..49, 51..1000, 2000..3000}";
- String result = (s.Complement(vocabulary)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestNotSet()
- {
- IntervalSet vocabulary = IntervalSet.Of(1, 1000);
- IntervalSet s = IntervalSet.Of(50, 60);
- s.Add(5);
- s.Add(250, 300);
- String expecting = "{1..4, 6..49, 61..249, 301..1000}";
- String result = (s.Complement(vocabulary)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestNotEqualSet()
- {
- IntervalSet vocabulary = IntervalSet.Of(1, 1000);
- IntervalSet s = IntervalSet.Of(1, 1000);
- String expecting = "{}";
- String result = (s.Complement(vocabulary)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestNotSetEdgeElement()
- {
- IntervalSet vocabulary = IntervalSet.Of(1, 2);
- IntervalSet s = IntervalSet.Of(1);
- String expecting = "2";
- String result = (s.Complement(vocabulary)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestNotSetFragmentedVocabulary()
- {
- IntervalSet vocabulary = IntervalSet.Of(1, 255);
- vocabulary.Add(1000, 2000);
- vocabulary.Add(9999);
- IntervalSet s = IntervalSet.Of(50, 60);
- s.Add(3);
- s.Add(250, 300);
- s.Add(10000); // this is outside range of vocab and should be ignored
- String expecting = "{1..2, 4..49, 61..249, 1000..2000, 9999}";
- String result = (s.Complement(vocabulary)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSubtractOfCompletelyContainedRange()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(12, 15);
- String expecting = "{10..11, 16..20}";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSubtractOfOverlappingRangeFromLeft()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(5, 11);
- String expecting = "{12..20}";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
-
- IntervalSet s3 = IntervalSet.Of(5, 10);
- expecting = "{11..20}";
- result = (s.Subtract(s3)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSubtractOfOverlappingRangeFromRight()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(15, 25);
- String expecting = "{10..14}";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
-
- IntervalSet s3 = IntervalSet.Of(20, 25);
- expecting = "{10..19}";
- result = (s.Subtract(s3)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSubtractOfCompletelyCoveredRange()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(1, 25);
- String expecting = "{}";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSubtractOfRangeSpanningMultipleRanges()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- s.Add(30, 40);
- s.Add(50, 60); // s has 3 ranges now: 10..20, 30..40, 50..60
- IntervalSet s2 = IntervalSet.Of(5, 55); // covers one and touches 2nd range
- String expecting = "{56..60}";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
-
- IntervalSet s3 = IntervalSet.Of(15, 55); // touches both
- expecting = "{10..14, 56..60}";
- result = (s.Subtract(s3)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- /** The following was broken:
- {0..113, 115..65534}-{0..115, 117..65534}=116..65534
- */
- [TestMethod]
- public void TestSubtractOfWackyRange()
- {
- IntervalSet s = IntervalSet.Of(0, 113);
- s.Add(115, 200);
- IntervalSet s2 = IntervalSet.Of(0, 115);
- s2.Add(117, 200);
- String expecting = "116";
- String result = (s.Subtract(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSimpleEquals()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(10, 20);
- Assert.AreEqual(s, s2);
-
- IntervalSet s3 = IntervalSet.Of(15, 55);
- Assert.AreNotEqual(s, s3);
- }
-
- [TestMethod]
- public void TestEquals()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- s.Add(2);
- s.Add(499, 501);
- IntervalSet s2 = IntervalSet.Of(10, 20);
- s2.Add(2);
- s2.Add(499, 501);
- Assert.AreEqual(s, s2);
-
- IntervalSet s3 = IntervalSet.Of(10, 20);
- s3.Add(2);
- Assert.AreNotEqual(s, s3);
- }
-
- [TestMethod]
- public void TestSingleElementMinusDisjointSet()
- {
- IntervalSet s = IntervalSet.Of(15, 15);
- IntervalSet s2 = IntervalSet.Of(1, 5);
- s2.Add(10, 20);
- String expecting = "{}"; // 15 - {1..5, 10..20} = {}
- String result = s.Subtract(s2).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestMembership()
- {
- IntervalSet s = IntervalSet.Of(15, 15);
- s.Add(50, 60);
- Assert.IsFalse(s.Contains(0));
- Assert.IsFalse(s.Contains(20));
- Assert.IsFalse(s.Contains(100));
- Assert.IsTrue(s.Contains(15));
- Assert.IsTrue(s.Contains(55));
- Assert.IsTrue(s.Contains(50));
- Assert.IsTrue(s.Contains(60));
- }
-
- // {2,15,18} & 10..20
- [TestMethod]
- public void TestIntersectionWithTwoContainedElements()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(2, 2);
- s2.Add(15);
- s2.Add(18);
- String expecting = "{15, 18}";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestIntersectionWithTwoContainedElementsReversed()
- {
- IntervalSet s = IntervalSet.Of(10, 20);
- IntervalSet s2 = IntervalSet.Of(2, 2);
- s2.Add(15);
- s2.Add(18);
- String expecting = "{15, 18}";
- String result = (s2.And(s)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestComplement()
- {
- IntervalSet s = IntervalSet.Of(100, 100);
- s.Add(101, 101);
- IntervalSet s2 = IntervalSet.Of(100, 102);
- String expecting = "102";
- String result = (s.Complement(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestComplement2()
- {
- IntervalSet s = IntervalSet.Of(100, 101);
- IntervalSet s2 = IntervalSet.Of(100, 102);
- String expecting = "102";
- String result = (s.Complement(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestComplement3()
- {
- IntervalSet s = IntervalSet.Of(1, 96);
- s.Add(99, Lexer.MaxCharValue);
- String expecting = "{97..98}";
- String result = (s.Complement(1, Lexer.MaxCharValue)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestMergeOfRangesAndSingleValues()
- {
- // {0..41, 42, 43..65534}
- IntervalSet s = IntervalSet.Of(0, 41);
- s.Add(42);
- s.Add(43, 65534);
- String expecting = "{0..65534}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestMergeOfRangesAndSingleValuesReverse()
- {
- IntervalSet s = IntervalSet.Of(43, 65534);
- s.Add(42);
- s.Add(0, 41);
- String expecting = "{0..65534}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestMergeWhereAdditionMergesTwoExistingIntervals()
- {
- // 42, 10, {0..9, 11..41, 43..65534}
- IntervalSet s = IntervalSet.Of(42);
- s.Add(10);
- s.Add(0, 9);
- s.Add(43, 65534);
- s.Add(11, 41);
- String expecting = "{0..65534}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- /**
- * This case is responsible for antlr/antlr4#153.
- * https://github.com/antlr/antlr4/issues/153
- */
- [TestMethod]
- public void TestMergeWhereAdditionMergesThreeExistingIntervals()
- {
- IntervalSet s = new IntervalSet();
- s.Add(0);
- s.Add(3);
- s.Add(5);
- s.Add(0, 7);
- String expecting = "{0..7}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestMergeWithDoubleOverlap()
- {
- IntervalSet s = IntervalSet.Of(1, 10);
- s.Add(20, 30);
- s.Add(5, 25); // overlaps two!
- String expecting = "{1..30}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestSize()
- {
- IntervalSet s = IntervalSet.Of(20, 30);
- s.Add(50, 55);
- s.Add(5, 19);
- String expecting = "32";
- String result = s.Count.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestToList()
- {
- IntervalSet s = IntervalSet.Of(20, 25);
- s.Add(50, 55);
- s.Add(5, 5);
- int[] expecting = { 5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55 };
- IList result = s.ToList();
- CollectionAssert.AreEquivalent(expecting, result.ToArray());
- }
-
- /** The following was broken:
- * {'\u0000'..'s', 'u'..'\uFFFE'} & {'\u0000'..'q', 's'..'\uFFFE'}=
- * {'\u0000'..'q', 's'}!!!! broken...
- * 'q' is 113 ascii
- * 'u' is 117
- */
- [TestMethod]
- public void TestNotRIntersectionNotT()
- {
- IntervalSet s = IntervalSet.Of(0, 's');
- s.Add('u', 200);
- IntervalSet s2 = IntervalSet.Of(0, 'q');
- s2.Add('s', 200);
- String expecting = "{0..113, 115, 117..200}";
- String result = (s.And(s2)).ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestRmSingleElement()
- {
- IntervalSet s = IntervalSet.Of(1, 10);
- s.Add(-3, -3);
- s.Remove(-3);
- String expecting = "{1..10}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestRmLeftSide()
- {
- IntervalSet s = IntervalSet.Of(1, 10);
- s.Add(-3, -3);
- s.Remove(1);
- String expecting = "{-3, 2..10}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestRmRightSide()
- {
- IntervalSet s = IntervalSet.Of(1, 10);
- s.Add(-3, -3);
- s.Remove(10);
- String expecting = "{-3, 1..9}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
-
- [TestMethod]
- public void TestRmMiddleRange()
- {
- IntervalSet s = IntervalSet.Of(1, 10);
- s.Add(-3, -3);
- s.Remove(5);
- String expecting = "{-3, 1..4, 6..10}";
- String result = s.ToString();
- Assert.AreEqual(expecting, result);
- }
- }
-}
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TestPerformance.cs b/runtime/CSharp/Antlr4.Runtime.Test/TestPerformance.cs
deleted file mode 100644
index b852fabc0..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/TestPerformance.cs
+++ /dev/null
@@ -1,1198 +0,0 @@
-namespace Antlr4.Runtime.Test
-{
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Text;
- using Antlr4.Runtime;
- using Antlr4.Runtime.Atn;
- using Antlr4.Runtime.Dfa;
- using Antlr4.Runtime.Misc;
- using Antlr4.Runtime.Tree;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using BitSet = Sharpen.BitSet;
- using Checksum = Sharpen.Checksum;
- using CRC32 = Sharpen.CRC32;
- using Debug = System.Diagnostics.Debug;
- using DirectoryInfo = System.IO.DirectoryInfo;
- using File = System.IO.File;
- using FileInfo = System.IO.FileInfo;
- using Interlocked = System.Threading.Interlocked;
- using IOException = System.IO.IOException;
- using Path = System.IO.Path;
- using SearchOption = System.IO.SearchOption;
- using Stopwatch = System.Diagnostics.Stopwatch;
- using Stream = System.IO.Stream;
- using StreamReader = System.IO.StreamReader;
- using Thread = System.Threading.Thread;
-
-#if NET40PLUS
- using System.Collections.Concurrent;
- using System.Threading.Tasks;
- using System.Threading.Tasks.Schedulers;
- using CancellationToken = System.Threading.CancellationToken;
-#endif
-
- [TestClass]
- public class TestPerformance : BaseTest
- {
- /**
- * Parse all java files under this package within the JDK_SOURCE_ROOT
- * (environment variable or property defined on the Java command line).
- */
- private static readonly string TOP_PACKAGE = "java.lang";
- /**
- * {@code true} to load java files from sub-packages of
- * {@link #TOP_PACKAGE}.
- */
- private static readonly bool RECURSIVE = true;
- /**
- * {@code true} to read all source files from disk into memory before
- * starting the parse. The default value is {@code true} to help prevent
- * drive speed from affecting the performance results. This value may be set
- * to {@code false} to support parsing large input sets which would not
- * otherwise fit into memory.
- */
- private static readonly bool PRELOAD_SOURCES = true;
- /**
- * The encoding to use when reading source files.
- */
- private static readonly Encoding ENCODING = Encoding.UTF8;
-
- /**
- * {@code true} to use the Java grammar with expressions in the v4
- * left-recursive syntax (Java-LR.g4). {@code false} to use the standard
- * grammar (Java.g4). In either case, the grammar is renamed in the
- * temporary directory to Java.g4 before compiling.
- */
- private static readonly bool USE_LR_GRAMMAR = true;
- /**
- * {@code true} to specify the {@code -Xforce-atn} option when generating
- * the grammar, forcing all decisions in {@code JavaParser} to be handled by
- * {@link ParserATNSimulator#adaptivePredict}.
- */
- private static readonly bool FORCE_ATN = false;
- /**
- * {@code true} to specify the {@code -atn} option when generating the
- * grammar. This will cause ANTLR to export the ATN for each decision as a
- * DOT (GraphViz) file.
- */
- private static readonly bool EXPORT_ATN_GRAPHS = true;
- /**
- * {@code true} to specify the {@code -XdbgST} option when generating the
- * grammar.
- */
- private static readonly bool DEBUG_TEMPLATES = false;
- /**
- * {@code true} to specify the {@code -XdbgSTWait} option when generating the
- * grammar.
- */
- private static readonly bool DEBUG_TEMPLATES_WAIT = DEBUG_TEMPLATES;
- /**
- * {@code true} to delete temporary (generated and compiled) files when the
- * test completes.
- */
- private static readonly bool DELETE_TEMP_FILES = true;
-
- /**
- * {@code true} to call {@link System#gc} and then wait for 5 seconds at the
- * end of the test to make it easier for a profiler to grab a heap dump at
- * the end of the test run.
- */
- private static readonly bool PAUSE_FOR_HEAP_DUMP = false;
-
- /**
- * Parse each file with {@code JavaParser.compilationUnit}.
- */
- private static readonly bool RUN_PARSER = true;
- /**
- * {@code true} to use {@link BailErrorStrategy}, {@code false} to use
- * {@link DefaultErrorStrategy}.
- */
- private static readonly bool BAIL_ON_ERROR = false;
- /**
- * {@code true} to compute a checksum for verifying consistency across
- * optimizations and multiple passes.
- */
- private static readonly bool COMPUTE_CHECKSUM = true;
- /**
- * This value is passed to {@link Parser#setBuildParseTree}.
- */
- private static readonly bool BUILD_PARSE_TREES = false;
- /**
- * Use
- * {@link ParseTreeWalker#DEFAULT}{@code .}{@link ParseTreeWalker#walk walk}
- * with the {@code JavaParserBaseListener} to show parse tree walking
- * overhead. If {@link #BUILD_PARSE_TREES} is {@code false}, the listener
- * will instead be called during the parsing process via
- * {@link Parser#addParseListener}.
- */
- private static readonly bool BLANK_LISTENER = false;
-
- private static readonly bool EXPORT_LARGEST_CONFIG_CONTEXTS = false;
-
- /**
- * Shows the number of {@link DFAState} and {@link ATNConfig} instances in
- * the DFA cache at the end of each pass. If {@link #REUSE_LEXER_DFA} and/or
- * {@link #REUSE_PARSER_DFA} are false, the corresponding instance numbers
- * will only apply to one file (the last file if {@link #NUMBER_OF_THREADS}
- * is 0, otherwise the last file which was parsed on the first thread).
- */
- private static readonly bool SHOW_DFA_STATE_STATS = true;
-
- private static readonly bool ENABLE_LEXER_DFA = true;
-
- private static readonly bool ENABLE_PARSER_DFA = true;
-
- private static readonly PredictionMode PREDICTION_MODE = PredictionMode.Ll;
- private static readonly bool FORCE_GLOBAL_CONTEXT = false;
- private static readonly bool TRY_LOCAL_CONTEXT_FIRST = true;
- private static readonly bool OPTIMIZE_LL1 = true;
- private static readonly bool OPTIMIZE_UNIQUE_CLOSURE = true;
- private static readonly bool OPTIMIZE_TAIL_CALLS = true;
- private static readonly bool TAIL_CALL_PRESERVES_SLL = true;
- private static readonly bool TREAT_SLLK1_CONFLICT_AS_AMBIGUITY = false;
-
- private static readonly bool TWO_STAGE_PARSING = true;
-
- private static readonly bool SHOW_CONFIG_STATS = false;
-
- private static readonly bool REPORT_SYNTAX_ERRORS = true;
- private static readonly bool REPORT_AMBIGUITIES = false;
- private static readonly bool REPORT_FULL_CONTEXT = false;
- private static readonly bool REPORT_CONTEXT_SENSITIVITY = REPORT_FULL_CONTEXT;
-
- /**
- * If {@code true}, a single {@code JavaLexer} will be used, and
- * {@link Lexer#setInputStream} will be called to initialize it for each
- * source file. Otherwise, a new instance will be created for each file.
- */
- private static readonly bool REUSE_LEXER = false;
- /**
- * If {@code true}, a single DFA will be used for lexing which is shared
- * across all threads and files. Otherwise, each file will be lexed with its
- * own DFA which is accomplished by creating one ATN instance per thread and
- * clearing its DFA cache before lexing each file.
- */
- private static readonly bool REUSE_LEXER_DFA = true;
- /**
- * If {@code true}, a single {@code JavaParser} will be used, and
- * {@link Parser#setInputStream} will be called to initialize it for each
- * source file. Otherwise, a new instance will be created for each file.
- */
- private static readonly bool REUSE_PARSER = false;
- /**
- * If {@code true}, a single DFA will be used for parsing which is shared
- * across all threads and files. Otherwise, each file will be parsed with
- * its own DFA which is accomplished by creating one ATN instance per thread
- * and clearing its DFA cache before parsing each file.
- */
- private static readonly bool REUSE_PARSER_DFA = true;
- /**
- * If {@code true}, the shared lexer and parser are reset after each pass.
- * If {@code false}, all passes after the first will be fully "warmed up",
- * which makes them faster and can compare them to the first warm-up pass,
- * but it will not distinguish bytecode load/JIT time from warm-up time
- * during the first pass.
- */
- private static readonly bool CLEAR_DFA = false;
- /**
- * Total number of passes to make over the source.
- */
- private static readonly int PASSES = 4;
-
- /**
- * Number of parser threads to use.
- *
- *
- * This value is ignored for .NET Framework 3.5 and earlier.
- *
- */
- private static readonly int NUMBER_OF_THREADS = 1;
-
- private static readonly Lexer[] sharedLexers = new Lexer[NUMBER_OF_THREADS];
- private static readonly ATN[] sharedLexerATNs = new ATN[NUMBER_OF_THREADS];
-
- private static readonly Parser[] sharedParsers = new Parser[NUMBER_OF_THREADS];
- private static readonly ATN[] sharedParserATNs = new ATN[NUMBER_OF_THREADS];
-
- private static readonly IParseTreeListener[] sharedListeners = new IParseTreeListener[NUMBER_OF_THREADS];
-
- private static int tokenCount;
- private int currentPass;
-
- [TestMethod]
- //[Ignore]
- public void compileJdk()
- {
- string jdkSourceRoot = getSourceRoot("JDK");
- Assert.IsTrue(jdkSourceRoot != null && !string.IsNullOrEmpty(jdkSourceRoot), "The JDK_SOURCE_ROOT environment variable must be set for performance testing.");
-
- compileJavaParser(USE_LR_GRAMMAR);
- string lexerName = "JavaLexer";
- string parserName = "JavaParser";
- string listenerName = "JavaBaseListener";
- string entryPoint = "compilationUnit";
- ParserFactory factory = getParserFactory(lexerName, parserName, listenerName, entryPoint);
-
- if (!string.IsNullOrEmpty(TOP_PACKAGE))
- {
- jdkSourceRoot = jdkSourceRoot + '/' + TOP_PACKAGE.Replace('.', '/');
- }
-
- DirectoryInfo directory = new DirectoryInfo(jdkSourceRoot);
- Assert.IsTrue(directory.Exists);
-
- IEnumerable sources = LoadSources(directory, "*.java", RECURSIVE);
-
- Console.Out.Write(getOptionsDescription(TOP_PACKAGE));
-
- currentPass = 0;
- parse1(factory, sources);
- for (int i = 0; i < PASSES - 1; i++)
- {
- currentPass = i + 1;
- if (CLEAR_DFA)
- {
- if (sharedLexers.Length > 0)
- {
- sharedLexers[0].Atn.ClearDFA();
- }
-
- if (sharedParsers.Length > 0)
- {
- sharedParsers[0].Atn.ClearDFA();
- }
-
- for (int j = 0; j < sharedLexers.Length; j++)
- sharedLexers[j] = null;
- for (int j = 0; j < sharedParsers.Length; j++)
- sharedParsers[j] = null;
- }
-
- parse2(factory, sources);
- }
-
- sources = null;
- if (PAUSE_FOR_HEAP_DUMP)
- {
- GC.Collect();
- Console.Out.WriteLine("Pausing before application exit.");
- Thread.Sleep(4000);
- }
- }
-
- private string getSourceRoot(string prefix)
- {
- string sourceRoot = Environment.GetEnvironmentVariable(prefix + "_SOURCE_ROOT");
- return sourceRoot;
- }
-
- protected override void eraseTempDir()
- {
- if (DELETE_TEMP_FILES)
- {
- base.eraseTempDir();
- }
- }
-
- public static string getOptionsDescription(string topPackage)
- {
- StringBuilder builder = new StringBuilder();
- builder.Append("Input=");
- if (string.IsNullOrEmpty(topPackage))
- {
- builder.Append("*");
- }
- else
- {
- builder.Append(topPackage).Append(".*");
- }
-
- builder.Append(", Grammar=").Append(USE_LR_GRAMMAR ? "LR" : "Standard");
- builder.Append(", ForceAtn=").Append(FORCE_ATN);
- builder.Append(", Lexer:").Append(ENABLE_LEXER_DFA ? "DFA" : "ATN");
- builder.Append(", Parser:").Append(ENABLE_PARSER_DFA ? "DFA" : "ATN");
-
- builder.AppendLine();
-
- builder.Append("Op=Lex").Append(RUN_PARSER ? "+Parse" : " only");
- builder.Append(", Strategy=").Append(BAIL_ON_ERROR ? typeof(BailErrorStrategy).Name : typeof(DefaultErrorStrategy).Name);
- builder.Append(", BuildParseTree=").Append(BUILD_PARSE_TREES);
- builder.Append(", WalkBlankListener=").Append(BLANK_LISTENER);
-
- builder.AppendLine();
-
- builder.Append("Lexer=").Append(REUSE_LEXER ? "setInputStream" : "newInstance");
- builder.Append(", Parser=").Append(REUSE_PARSER ? "setInputStream" : "newInstance");
- builder.Append(", AfterPass=").Append(CLEAR_DFA ? "newInstance" : "setInputStream");
-
- builder.AppendLine();
-
- builder.Append("UniqueClosure=").Append(OPTIMIZE_UNIQUE_CLOSURE ? "optimize" : "complete");
-
- builder.AppendLine();
-
- return builder.ToString();
- }
-
- /**
- * This method is separate from {@link #parse2} so the first pass can be distinguished when analyzing
- * profiler results.
- */
- protected void parse1(ParserFactory factory, IEnumerable sources)
- {
- GC.Collect();
- parseSources(factory, sources);
- }
-
- /**
- * This method is separate from {@link #parse1} so the first pass can be distinguished when analyzing
- * profiler results.
- */
- protected void parse2(ParserFactory factory, IEnumerable sources)
- {
- GC.Collect();
- parseSources(factory, sources);
- }
-
- protected IList LoadSources(DirectoryInfo directory, string filter, bool recursive)
- {
- IList result = new List();
- LoadSources(directory, filter, recursive, result);
- return result;
- }
-
- protected void LoadSources(DirectoryInfo directory, string filter, bool recursive, ICollection result)
- {
- Debug.Assert(directory.Exists);
-
- FileInfo[] sources = directory.GetFiles(filter, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
- foreach (FileInfo file in sources)
- {
- result.Add(new InputDescriptor(file.FullName));
- }
- }
-
- int configOutputSize = 0;
-
- protected void parseSources(ParserFactory factory, IEnumerable sources)
- {
- Stopwatch startTime = Stopwatch.StartNew();
- Thread.VolatileWrite(ref tokenCount, 0);
- int sourceCount = 0;
- int inputSize = 0;
-
-#if NET40PLUS
- BlockingCollection threadIdentifiers = new BlockingCollection();
- for (int i = 0; i < NUMBER_OF_THREADS; i++)
- threadIdentifiers.Add(i);
-
- ICollection> results = new List>();
- QueuedTaskScheduler executorServiceHost = new QueuedTaskScheduler(NUMBER_OF_THREADS);
- TaskScheduler executorService = executorServiceHost.ActivateNewQueue();
-#else
- ICollection> results = new List>();
-#endif
- foreach (InputDescriptor inputDescriptor in sources)
- {
- ICharStream input = inputDescriptor.GetInputStream();
- sourceCount++;
- input.Seek(0);
- inputSize += input.Size;
-#if NET40PLUS
- Task futureChecksum = Task.Factory.StartNew(new Callable_1(input, factory, threadIdentifiers).call, CancellationToken.None, TaskCreationOptions.None, executorService);
-#else
- Func futureChecksum = new Callable_1(input, factory).call;
-#endif
- results.Add(futureChecksum);
- }
-
- Checksum checksum = new CRC32();
- foreach (var future in results)
- {
-#if NET40PLUS
- int value = future.Result;
-#else
- int value = future();
-#endif
- if (COMPUTE_CHECKSUM)
- {
- updateChecksum(checksum, value);
- }
- }
-
-#if NET40PLUS
- executorServiceHost.Dispose();
-#endif
-
- Console.Out.WriteLine("Total parse time for {0} files ({1} KB, {2} tokens, checksum 0x{3:X8}): {4}ms",
- sourceCount,
- inputSize / 1024,
- Thread.VolatileRead(ref tokenCount),
- COMPUTE_CHECKSUM ? checksum.Value : 0,
- startTime.ElapsedMilliseconds);
-
- if (sharedLexers.Length > 0)
- {
- Lexer lexer = sharedLexers[0];
- LexerATNSimulator lexerInterpreter = lexer.Interpreter;
- DFA[] modeToDFA = lexerInterpreter.atn.modeToDFA;
- if (SHOW_DFA_STATE_STATS)
- {
- int states = 0;
- int configs = 0;
- HashSet uniqueConfigs = new HashSet();
-
- for (int i = 0; i < modeToDFA.Length; i++)
- {
- DFA dfa = modeToDFA[i];
- if (dfa == null || dfa.states == null)
- {
- continue;
- }
-
- states += dfa.states.Count;
- foreach (DFAState state in dfa.states.Values)
- {
- configs += state.configs.Count;
- uniqueConfigs.UnionWith(state.configs);
- }
- }
-
- Console.Out.WriteLine("There are {0} lexer DFAState instances, {1} configs ({2} unique), {3} prediction contexts.", states, configs, uniqueConfigs.Count, lexerInterpreter.atn.ContextCacheSize);
- }
- }
-
- if (RUN_PARSER && sharedParsers.Length > 0)
- {
- Parser parser = sharedParsers[0];
- // make sure the individual DFAState objects actually have unique ATNConfig arrays
- ParserATNSimulator interpreter = parser.Interpreter;
- DFA[] decisionToDFA = interpreter.atn.decisionToDFA;
-
- if (SHOW_DFA_STATE_STATS)
- {
- int states = 0;
- int configs = 0;
- HashSet uniqueConfigs = new HashSet();
-
- for (int i = 0; i < decisionToDFA.Length; i++)
- {
- DFA dfa = decisionToDFA[i];
- if (dfa == null || dfa.states == null)
- {
- continue;
- }
-
- states += dfa.states.Count;
- foreach (DFAState state in dfa.states.Values)
- {
- configs += state.configs.Count;
- uniqueConfigs.UnionWith(state.configs);
- }
- }
-
- Console.Out.WriteLine("There are {0} parser DFAState instances, {1} configs ({2} unique), {3} prediction contexts.", states, configs, uniqueConfigs.Count, interpreter.atn.ContextCacheSize);
- }
-
- int localDfaCount = 0;
- int globalDfaCount = 0;
- int localConfigCount = 0;
- int globalConfigCount = 0;
- int[] contextsInDFAState = new int[0];
-
- for (int i = 0; i < decisionToDFA.Length; i++)
- {
- DFA dfa = decisionToDFA[i];
- if (dfa == null || dfa.states == null)
- {
- continue;
- }
-
- if (SHOW_CONFIG_STATS)
- {
- foreach (DFAState state in dfa.states.Keys)
- {
- if (state.configs.Count >= contextsInDFAState.Length)
- {
- Array.Resize(ref contextsInDFAState, state.configs.Count + 1);
- }
-
- if (state.IsAcceptState)
- {
- bool hasGlobal = false;
- foreach (ATNConfig config in state.configs)
- {
- if (config.ReachesIntoOuterContext)
- {
- globalConfigCount++;
- hasGlobal = true;
- }
- else
- {
- localConfigCount++;
- }
- }
-
- if (hasGlobal)
- {
- globalDfaCount++;
- }
- else
- {
- localDfaCount++;
- }
- }
-
- contextsInDFAState[state.configs.Count]++;
- }
- }
-
- if (EXPORT_LARGEST_CONFIG_CONTEXTS)
- {
- foreach (DFAState state in dfa.states.Keys)
- {
- foreach (ATNConfig config in state.configs)
- {
- string configOutput = config.ToDotString();
- if (configOutput.Length <= configOutputSize)
- {
- continue;
- }
-
- configOutputSize = configOutput.Length;
- writeFile(tmpdir, "d" + dfa.decision + ".s" + state.stateNumber + ".a" + config.Alt + ".config.dot", configOutput);
- }
- }
- }
- }
-
- if (SHOW_CONFIG_STATS && currentPass == 0)
- {
- Console.Out.WriteLine(" DFA accept states: {0} total, {1} with only local context, {2} with a global context", localDfaCount + globalDfaCount, localDfaCount, globalDfaCount);
- Console.Out.WriteLine(" Config stats: {0} total, {1} local, {2} global", localConfigCount + globalConfigCount, localConfigCount, globalConfigCount);
- if (SHOW_DFA_STATE_STATS)
- {
- for (int i = 0; i < contextsInDFAState.Length; i++)
- {
- if (contextsInDFAState[i] != 0)
- {
- Console.Out.WriteLine(" {0} configs = {1}", i, contextsInDFAState[i]);
- }
- }
- }
- }
- }
- }
-
- private class Callable_1
- {
- private readonly ICharStream input;
- private readonly ParserFactory factory;
-#if NET40PLUS
- private readonly BlockingCollection threadNumbers;
-#endif
-
-#if NET40PLUS
- public Callable_1(ICharStream input, ParserFactory factory, BlockingCollection threadNumbers)
-#else
- public Callable_1(ICharStream input, ParserFactory factory)
-#endif
- {
- this.input = input;
- this.factory = factory;
-#if NET40PLUS
- this.threadNumbers = threadNumbers;
-#endif
- }
-
- public int call()
- {
- // this incurred a great deal of overhead and was causing significant variations in performance results.
- //Console.Out.WriteLine("Parsing file {0}", input.getSourceName());
-#if NET40PLUS
- int threadNumber = threadNumbers.Take();
-#else
- int threadNumber = 0;
-#endif
- try
- {
- return factory.parseFile(input, threadNumber);
- }
- finally
- {
-#if NET40PLUS
- threadNumbers.Add(threadNumber);
-#endif
- }
- }
- }
-
- protected void compileJavaParser(bool leftRecursive)
- {
- string grammarFileName = "Java.g4";
- string sourceName = leftRecursive ? "Java-LR.g4" : "Java.g4";
- string body = load(sourceName, null);
- List extraOptions = new List();
- extraOptions.Add("-Werror");
- if (FORCE_ATN)
- {
- extraOptions.Add("-Xforce-atn");
- }
- if (EXPORT_ATN_GRAPHS)
- {
- extraOptions.Add("-atn");
- }
- if (DEBUG_TEMPLATES)
- {
- extraOptions.Add("-XdbgST");
- if (DEBUG_TEMPLATES_WAIT)
- {
- extraOptions.Add("-XdbgSTWait");
- }
- }
- extraOptions.Add("-visitor");
- string[] extraOptionsArray = extraOptions.ToArray();
- bool success = rawGenerateAndBuildRecognizer(grammarFileName, body, "JavaParser", "JavaLexer", true, extraOptionsArray);
- Assert.IsTrue(success);
- }
-
- protected string load(string fileName, [Nullable] Encoding encoding)
- {
- if (fileName == null)
- {
- return null;
- }
-
- Stream stream = typeof(TestPerformance).Assembly.GetManifestResourceStream(typeof(TestPerformance), fileName);
- if (encoding == null)
- return new StreamReader(stream).ReadToEnd();
- else
- return new StreamReader(stream, encoding).ReadToEnd();
- }
-
- private static void updateChecksum(Checksum checksum, int value)
- {
- checksum.Update((value) & 0xFF);
- checksum.Update((int)((uint)value >> 8) & 0xFF);
- checksum.Update((int)((uint)value >> 16) & 0xFF);
- checksum.Update((int)((uint)value >> 24) & 0xFF);
- }
-
- private static void updateChecksum(Checksum checksum, IToken token)
- {
- if (token == null)
- {
- checksum.Update(0);
- return;
- }
-
- updateChecksum(checksum, token.StartIndex);
- updateChecksum(checksum, token.StopIndex);
- updateChecksum(checksum, token.Line);
- updateChecksum(checksum, token.Column);
- updateChecksum(checksum, token.Type);
- updateChecksum(checksum, token.Channel);
- }
-
- protected ParserFactory getParserFactory(string lexerName, string parserName, string listenerName, string entryPoint)
- {
- Assembly loader = Assembly.LoadFile(Path.Combine(tmpdir, "Parser.dll"));
- Type lexerClass = loader.GetType(lexerName);
- Type parserClass = loader.GetType(parserName);
- Type listenerClass = loader.GetType(listenerName);
-
- ConstructorInfo lexerCtor = lexerClass.GetConstructor(new Type[] { typeof(ICharStream) });
- ConstructorInfo parserCtor = parserClass.GetConstructor(new Type[] { typeof(ITokenStream) });
-
- // construct initial instances of the lexer and parser to deserialize their ATNs
- ITokenSource tokenSource = (ITokenSource)lexerCtor.Invoke(new object[] { new AntlrInputStream("") });
- parserCtor.Invoke(new object[] { new CommonTokenStream(tokenSource) });
-
- if (!REUSE_LEXER_DFA)
- {
- FieldInfo lexerSerializedATNField = lexerClass.GetField("_serializedATN");
- string lexerSerializedATN = (string)lexerSerializedATNField.GetValue(null);
- for (int i = 0; i < NUMBER_OF_THREADS; i++)
- {
- sharedLexerATNs[i] = new ATNDeserializer().Deserialize(lexerSerializedATN.ToCharArray());
- }
- }
-
- if (RUN_PARSER && !REUSE_PARSER_DFA)
- {
- FieldInfo parserSerializedATNField = parserClass.GetField("_serializedATN");
- string parserSerializedATN = (string)parserSerializedATNField.GetValue(null);
- for (int i = 0; i < NUMBER_OF_THREADS; i++)
- {
- sharedParserATNs[i] = new ATNDeserializer().Deserialize(parserSerializedATN.ToCharArray());
- }
- }
-
- return new ParserFactory_1(listenerClass, parserClass, lexerCtor, parserCtor, entryPoint);
- }
-
- private class ParserFactory_1 : ParserFactory
- {
- private readonly Type listenerClass;
- private readonly Type parserClass;
-
- private readonly ConstructorInfo lexerCtor;
- private readonly ConstructorInfo parserCtor;
-
- private readonly string entryPoint;
-
- public ParserFactory_1(Type listenerClass, Type parserClass, ConstructorInfo lexerCtor, ConstructorInfo parserCtor, string entryPoint)
- {
- this.listenerClass = listenerClass;
- this.parserClass = parserClass;
- this.lexerCtor = lexerCtor;
- this.parserCtor = parserCtor;
- this.entryPoint = entryPoint;
- }
-
- public int parseFile(ICharStream input, int thread)
- {
- Checksum checksum = new CRC32();
-
- Debug.Assert(thread >= 0 && thread < NUMBER_OF_THREADS);
-
- try
- {
- IParseTreeListener listener = sharedListeners[thread];
- if (listener == null)
- {
- listener = (IParseTreeListener)Activator.CreateInstance(listenerClass);
- sharedListeners[thread] = listener;
- }
-
- Lexer lexer = sharedLexers[thread];
- if (REUSE_LEXER && lexer != null)
- {
- lexer.SetInputStream(input);
- }
- else
- {
- lexer = (Lexer)lexerCtor.Invoke(new object[] { input });
- sharedLexers[thread] = lexer;
- if (!ENABLE_LEXER_DFA)
- {
- lexer.Interpreter = new NonCachingLexerATNSimulator(lexer, lexer.Atn);
- }
- else if (!REUSE_LEXER_DFA)
- {
- lexer.Interpreter = new LexerATNSimulator(lexer, sharedLexerATNs[thread]);
- }
- }
-
- lexer.Interpreter.optimize_tail_calls = OPTIMIZE_TAIL_CALLS;
- if (ENABLE_LEXER_DFA && !REUSE_LEXER_DFA)
- {
- lexer.Interpreter.atn.ClearDFA();
- }
-
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- tokens.Fill();
- Interlocked.Add(ref tokenCount, tokens.Size);
-
- if (COMPUTE_CHECKSUM)
- {
- foreach (IToken token in tokens.GetTokens())
- {
- updateChecksum(checksum, token);
- }
- }
-
- if (!RUN_PARSER)
- {
- return (int)checksum.Value;
- }
-
- Parser parser = sharedParsers[thread];
- if (REUSE_PARSER && parser != null)
- {
- parser.SetInputStream(tokens);
- }
- else
- {
- Parser newParser = (Parser)parserCtor.Invoke(new object[] { tokens });
- parser = newParser;
- sharedParsers[thread] = parser;
- }
-
- parser.RemoveErrorListeners();
- if (!TWO_STAGE_PARSING)
- {
- parser.AddErrorListener(DescriptiveErrorListener.INSTANCE);
- parser.AddErrorListener(new SummarizingDiagnosticErrorListener());
- }
-
- if (!ENABLE_PARSER_DFA)
- {
- parser.Interpreter = new NonCachingParserATNSimulator(parser, parser.Atn);
- }
- else if (!REUSE_PARSER_DFA)
- {
- parser.Interpreter = new ParserATNSimulator(parser, sharedParserATNs[thread]);
- }
-
- if (ENABLE_PARSER_DFA && !REUSE_PARSER_DFA)
- {
- parser.Interpreter.atn.ClearDFA();
- }
-
- parser.Interpreter.PredictionMode = TWO_STAGE_PARSING ? PredictionMode.Sll : PREDICTION_MODE;
- parser.Interpreter.force_global_context = FORCE_GLOBAL_CONTEXT && !TWO_STAGE_PARSING;
- parser.Interpreter.always_try_local_context = TRY_LOCAL_CONTEXT_FIRST || TWO_STAGE_PARSING;
- parser.Interpreter.optimize_ll1 = OPTIMIZE_LL1;
- parser.Interpreter.optimize_unique_closure = OPTIMIZE_UNIQUE_CLOSURE;
- parser.Interpreter.optimize_tail_calls = OPTIMIZE_TAIL_CALLS;
- parser.Interpreter.tail_call_preserves_sll = TAIL_CALL_PRESERVES_SLL;
- parser.Interpreter.treat_sllk1_conflict_as_ambiguity = TREAT_SLLK1_CONFLICT_AS_AMBIGUITY;
- parser.BuildParseTree = BUILD_PARSE_TREES;
- if (!BUILD_PARSE_TREES && BLANK_LISTENER)
- {
- parser.AddParseListener(listener);
- }
- if (BAIL_ON_ERROR || TWO_STAGE_PARSING)
- {
- parser.ErrorHandler = new BailErrorStrategy();
- }
-
- MethodInfo parseMethod = parserClass.GetMethod(entryPoint);
- object parseResult;
-
- IParseTreeListener checksumParserListener = null;
-
- try
- {
- if (COMPUTE_CHECKSUM)
- {
- checksumParserListener = new ChecksumParseTreeListener(checksum);
- parser.AddParseListener(checksumParserListener);
- }
- parseResult = parseMethod.Invoke(parser, null);
- }
- catch (TargetInvocationException ex)
- {
- if (!TWO_STAGE_PARSING)
- {
- throw;
- }
-
- string sourceName = tokens.SourceName;
- sourceName = !string.IsNullOrEmpty(sourceName) ? sourceName + ": " : "";
- Console.Error.WriteLine(sourceName + "Forced to retry with full context.");
-
- if (!(ex.InnerException is ParseCanceledException))
- {
- throw;
- }
-
- tokens.Reset();
- if (REUSE_PARSER && sharedParsers[thread] != null)
- {
- parser.SetInputStream(tokens);
- }
- else
- {
- Parser newParser = (Parser)parserCtor.Invoke(new object[] { tokens });
- parser = newParser;
- sharedParsers[thread] = parser;
- }
-
- parser.RemoveErrorListeners();
- parser.AddErrorListener(DescriptiveErrorListener.INSTANCE);
- parser.AddErrorListener(new SummarizingDiagnosticErrorListener());
- if (!ENABLE_PARSER_DFA)
- {
- parser.Interpreter = new NonCachingParserATNSimulator(parser, parser.Atn);
- }
- parser.Interpreter.PredictionMode = PREDICTION_MODE;
- parser.Interpreter.force_global_context = FORCE_GLOBAL_CONTEXT;
- parser.Interpreter.always_try_local_context = TRY_LOCAL_CONTEXT_FIRST;
- parser.Interpreter.optimize_ll1 = OPTIMIZE_LL1;
- parser.Interpreter.optimize_unique_closure = OPTIMIZE_UNIQUE_CLOSURE;
- parser.Interpreter.optimize_tail_calls = OPTIMIZE_TAIL_CALLS;
- parser.Interpreter.tail_call_preserves_sll = TAIL_CALL_PRESERVES_SLL;
- parser.Interpreter.treat_sllk1_conflict_as_ambiguity = TREAT_SLLK1_CONFLICT_AS_AMBIGUITY;
- parser.BuildParseTree = BUILD_PARSE_TREES;
- if (!BUILD_PARSE_TREES && BLANK_LISTENER)
- {
- parser.AddParseListener(listener);
- }
- if (BAIL_ON_ERROR)
- {
- parser.ErrorHandler = new BailErrorStrategy();
- }
-
- parseResult = parseMethod.Invoke(parser, null);
- }
- finally
- {
- if (checksumParserListener != null)
- {
- parser.RemoveParseListener(checksumParserListener);
- }
- }
-
- Assert.IsInstanceOfType(parseResult, typeof(IParseTree));
- if (BUILD_PARSE_TREES && BLANK_LISTENER)
- {
- ParseTreeWalker.Default.Walk(listener, (ParserRuleContext)parseResult);
- }
- }
- catch (Exception e)
- {
- if (!REPORT_SYNTAX_ERRORS && e is ParseCanceledException)
- {
- return (int)checksum.Value;
- }
-
- throw;
- }
-
- return (int)checksum.Value;
- }
- }
-
- protected interface ParserFactory
- {
- int parseFile(ICharStream input, int thread);
- }
-
- private class DescriptiveErrorListener : BaseErrorListener
- {
- public static DescriptiveErrorListener INSTANCE = new DescriptiveErrorListener();
-
- public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
- {
- if (!REPORT_SYNTAX_ERRORS)
- {
- return;
- }
-
- string sourceName = recognizer.InputStream.SourceName;
- if (!string.IsNullOrEmpty(sourceName))
- {
- sourceName = string.Format("{0}:{1}:{2}: ", sourceName, line, charPositionInLine);
- }
-
- Console.Error.WriteLine(sourceName + "line " + line + ":" + charPositionInLine + " " + msg);
- }
- }
-
- private class SummarizingDiagnosticErrorListener : DiagnosticErrorListener
- {
- public override void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, bool exact, BitSet ambigAlts, ATNConfigSet configs)
- {
- if (!REPORT_AMBIGUITIES)
- {
- return;
- }
-
- base.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
- }
-
- public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, SimulatorState initialState)
- {
- if (!REPORT_FULL_CONTEXT)
- {
- return;
- }
-
- base.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, initialState);
- }
-
- public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, SimulatorState acceptState)
- {
- if (!REPORT_CONTEXT_SENSITIVITY)
- {
- return;
- }
-
- base.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, acceptState);
- }
-
- protected override string GetDecisionDescription(Parser recognizer, DFA dfa)
- {
- string format = "{0}({1})";
- string ruleName = recognizer.RuleNames[recognizer.Atn.decisionToState[dfa.decision].ruleIndex];
- return string.Format(format, dfa.decision, ruleName);
- }
- }
-
- protected class NonCachingLexerATNSimulator : LexerATNSimulator
- {
- public NonCachingLexerATNSimulator(Lexer recog, ATN atn)
- : base(recog, atn)
- {
- }
-
- protected override DFAState AddDFAState(ATNConfigSet configs)
- {
- return null;
- }
- }
-
- protected class NonCachingParserATNSimulator : ParserATNSimulator
- {
- private static readonly EmptyEdgeMap emptyMap = new EmptyEdgeMap(-1, -1);
-
- public NonCachingParserATNSimulator(Parser parser, ATN atn)
- : base(parser, atn)
- {
- }
-
- [return: NotNull]
- protected override DFAState CreateDFAState([NotNull] DFA dfa, [NotNull] ATNConfigSet configs)
- {
- return new DFAState(emptyMap, dfa.EmptyContextEdgeMap, configs);
- }
- }
-
- internal class ChecksumParseTreeListener : IParseTreeListener
- {
- private const int VISIT_TERMINAL = 1;
- private const int VISIT_ERROR_NODE = 2;
- private const int ENTER_RULE = 3;
- private const int EXIT_RULE = 4;
-
- private readonly Checksum checksum;
-
- public ChecksumParseTreeListener(Checksum checksum)
- {
- this.checksum = checksum;
- }
-
- public void VisitTerminal(ITerminalNode node)
- {
- checksum.Update(VISIT_TERMINAL);
- updateChecksum(checksum, node.Symbol);
- }
-
- public void VisitErrorNode(IErrorNode node)
- {
- checksum.Update(VISIT_ERROR_NODE);
- updateChecksum(checksum, node.Symbol);
- }
-
- public void EnterEveryRule(ParserRuleContext ctx)
- {
- checksum.Update(ENTER_RULE);
- updateChecksum(checksum, ctx.RuleIndex);
- updateChecksum(checksum, ctx.Start);
- }
-
- public void ExitEveryRule(ParserRuleContext ctx)
- {
- checksum.Update(EXIT_RULE);
- updateChecksum(checksum, ctx.RuleIndex);
- updateChecksum(checksum, ctx.Stop);
- }
- }
-
- protected sealed class InputDescriptor
- {
- private readonly string source;
- private WeakReference inputStream;
- private CloneableAntlrFileStream strongInputStream;
-
- public InputDescriptor([NotNull] String source)
- {
- this.source = source;
- if (PRELOAD_SOURCES)
- {
- GetInputStream();
- }
- }
-
- [return: NotNull]
- public ICharStream GetInputStream()
- {
- CloneableAntlrFileStream stream;
- if (!TryGetTarget(out stream))
- {
- stream = new CloneableAntlrFileStream(source, ENCODING);
- SetTarget(stream);
- }
-
- return new JavaUnicodeInputStream(stream.CreateCopy());
- }
-
- private void SetTarget(CloneableAntlrFileStream stream)
- {
- if (PRELOAD_SOURCES)
- {
- strongInputStream = stream;
- }
- else
- {
- inputStream = new WeakReference(stream);
- }
- }
-
- private bool TryGetTarget(out CloneableAntlrFileStream stream)
- {
- if (PRELOAD_SOURCES)
- {
- stream = strongInputStream;
- return strongInputStream != null;
- }
- else
- {
- if (inputStream == null)
- {
- stream = null;
- return false;
- }
-
- return inputStream.TryGetTarget(out stream);
- }
- }
- }
-
-#if PORTABLE
- protected class CloneableAntlrFileStream : AntlrInputStream
-#else
- protected class CloneableAntlrFileStream : AntlrFileStream
-#endif
- {
- public CloneableAntlrFileStream(String fileName, Encoding encoding)
-#if PORTABLE
- : base(File.ReadAllText(fileName, encoding))
-#else
- : base(fileName, encoding)
-#endif
- {
- }
-
- public AntlrInputStream CreateCopy()
- {
- AntlrInputStream stream = new AntlrInputStream(this.data, this.n);
- stream.name = this.SourceName;
- return stream;
- }
- }
-
-#if !NET45
- private sealed class WeakReference
- where T : class
- {
- private readonly WeakReference _reference;
-
- public WeakReference(T reference)
- {
- _reference = new WeakReference(reference);
- }
-
- public bool TryGetTarget(out T reference)
- {
- reference = (T)_reference.Target;
- return reference != null;
- }
- }
-#endif
- }
-}
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TestingKey.snk b/runtime/CSharp/Antlr4.Runtime.Test/TestingKey.snk
deleted file mode 100644
index 7d54a3e2b..000000000
Binary files a/runtime/CSharp/Antlr4.Runtime.Test/TestingKey.snk and /dev/null differ
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net20.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net20.config
deleted file mode 100644
index ba2302468..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net20.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net30.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net30.config
deleted file mode 100644
index 553a3b3e6..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net30.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net35-client.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net35-client.config
deleted file mode 100644
index be6a59602..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net35-client.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net40-client.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net40-client.config
deleted file mode 100644
index 9d7ab9386..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net40-client.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net45.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net45.config
deleted file mode 100644
index 475fe0d0c..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.net45.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net40.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net40.config
deleted file mode 100644
index 79cfba0a1..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net40.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net45.config b/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net45.config
deleted file mode 100644
index 39d4c91d2..000000000
--- a/runtime/CSharp/Antlr4.Runtime.Test/packages.Antlr4.Runtime.Test.portable-net45.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net30.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net30.csproj
deleted file mode 100644
index 9fa40db8b..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net30.csproj
+++ /dev/null
@@ -1,276 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {EBBDCC35-43CC-416C-860B-9FC115F1EB42}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v3.0
- 512
- obj\net30\
- ..\
- true
-
-
- true
- full
- false
- bin\net30\Debug\
- $(OutputPath)$(AssemblyName).xml
- DEBUG;TRACE;NET30;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\net30\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;NET30;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net30.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-net30.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-cf.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-cf.csproj
deleted file mode 100644
index ec3a282b8..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-cf.csproj
+++ /dev/null
@@ -1,293 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {C5F9C476-200F-4440-9524-C5C3F9BE16D7}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- WindowsCE
- E2BECB1F-8C8C-41ba-B736-9BE7D946A398
- 5.0
- Antlr4.Runtime.net35-cf
- v3.5
- Windows CE
-
-
- 512
- obj\net35-cf\
- ..\
- true
-
-
- true
- full
- false
- bin\net35-cf\Debug\
- $(OutputPath)\$(AssemblyName).xml
- DEBUG;TRACE;$(PlatformFamilyName);COMPACT;NET35;NET35PLUS;NET30PLUS;NET20PLUS
- true
- true
- prompt
- 4
- true
- Off
- 1591
-
-
- pdbonly
- true
- bin\net35-cf\Release\
- $(OutputPath)\$(AssemblyName).xml
- TRACE;$(PlatformFamilyName);COMPACT;NET35;NET35PLUS;NET30PLUS;NET20PLUS
- true
- true
- prompt
- 4
- true
- Off
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net35-cf.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-net35-cf.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-client.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-client.csproj
deleted file mode 100644
index c0c4feb9a..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net35-client.csproj
+++ /dev/null
@@ -1,276 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {E186FDA3-1411-47EE-94C7-9F3745F0474B}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v3.5
- Client
- 512
- obj\net35-client\
- ..\
- true
-
-
- true
- full
- false
- bin\net35-client\Debug\
- $(OutputPath)$(AssemblyName).xml
- DEBUG;TRACE;NET35;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\net35-client\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;NET35;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net35-client.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-net35-client.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net40-client.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net40-client.csproj
deleted file mode 100644
index 4fa768730..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net40-client.csproj
+++ /dev/null
@@ -1,270 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {423978DF-85A4-409E-A16C-453683FE3969}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v4.0
- Client
- 512
- obj\net40-client\
- ..\
- true
-
-
- true
- full
- false
- bin\net40-client\Debug\
- $(OutputPath)$(AssemblyName).xml
- TRACE;DEBUG;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\net40-client\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net40-client.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-net40-client.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net45.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net45.csproj
deleted file mode 100644
index 63a906833..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net45.csproj
+++ /dev/null
@@ -1,269 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v4.5
- 512
- obj\net45\
- ..\
- true
-
-
- true
- full
- false
- bin\net45\Debug\
- $(OutputPath)$(AssemblyName).xml
- TRACE;DEBUG;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\net45\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-net45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.netcore45.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.netcore45.csproj
deleted file mode 100644
index 71dd360a1..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.netcore45.csproj
+++ /dev/null
@@ -1,261 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {F3145DCA-EA26-4482-80D6-5232A79E2A3A}
- {BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- 512
- obj\netcore45\
- ..\
- true
-
-
- true
- full
- false
- bin\netcore45\Debug\
- $(OutputPath)$(AssemblyName).xml
- TRACE;DEBUG;WINRT;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\netcore45\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;WINRT;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-netcore45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-netcore45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net40.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net40.csproj
deleted file mode 100644
index 482c3f86a..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net40.csproj
+++ /dev/null
@@ -1,267 +0,0 @@
-
-
-
-
-
- 10.0
- Debug
- AnyCPU
- {06C182C5-095C-4D43-9C33-C87E305C6BC2}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v4.0
- Profile328
- 512
- obj\portable-net40\
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- ..\
- true
-
-
- true
- full
- false
- bin\portable-net40\Debug\
- $(OutputPath)$(AssemblyName).xml
- TRACE;DEBUG;PORTABLE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\portable-net40\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;PORTABLE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-portable-net40.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-portable-net40.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net45.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net45.csproj
deleted file mode 100644
index 4ceae4dd0..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.portable-net45.csproj
+++ /dev/null
@@ -1,267 +0,0 @@
-
-
-
-
-
- 11.0
- Debug
- AnyCPU
- {12269283-EE92-4FAA-B849-53CD24F341FA}
- Library
- Properties
- Antlr4.Runtime
- Antlr4.Runtime
- v4.5
- Profile259
- 512
- obj\portable-net45\
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- ..\
- true
-
-
- true
- full
- false
- bin\portable-net45\Debug\
- $(OutputPath)$(AssemblyName).xml
- TRACE;DEBUG;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- pdbonly
- true
- bin\portable-net45\Release\
- $(OutputPath)$(AssemblyName).xml
- TRACE;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS
- prompt
- 4
- 1591
-
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-portable-net45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- antlr-portable-net45.snk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net20.csproj b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.vs2013.csproj
similarity index 83%
rename from runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net20.csproj
rename to runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.vs2013.csproj
index e36e5000d..aaa0562dd 100644
--- a/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.net20.csproj
+++ b/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.vs2013.csproj
@@ -1,6 +1,5 @@
- Debug
@@ -15,6 +14,7 @@
obj\net20\..\true
+ true
@@ -37,15 +37,8 @@
41591
-
- true
-
-
- ..\..\..\..\..\..\keys\antlr\antlr-net20.snk
-
-
@@ -64,8 +57,9 @@
+
+
-
@@ -164,9 +158,6 @@
-
- antlr-net20.snk
-
@@ -190,7 +181,6 @@
-
@@ -248,29 +238,6 @@
-
-
- MSBuild:Compile
- Antlr4.Runtime.Tree.Xpath
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs
deleted file mode 100644
index 97672cb16..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Atn/ATNSerializer.cs
+++ /dev/null
@@ -1,720 +0,0 @@
-/*
- * [The "BSD license"]
- * Copyright (c) 2013 Terence Parr
- * Copyright (c) 2013 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using Antlr4.Runtime.Atn;
-using Antlr4.Runtime.Misc;
-using Antlr4.Runtime.Sharpen;
-
-namespace Antlr4.Runtime.Atn
-{
- public class ATNSerializer
- {
- public ATN atn;
-
- private IList ruleNames;
-
- private IList tokenNames;
-
- public ATNSerializer(ATN atn, IList ruleNames)
- {
- System.Diagnostics.Debug.Assert(atn.grammarType != null);
- this.atn = atn;
- this.ruleNames = ruleNames;
- }
-
- public ATNSerializer(ATN atn, IList ruleNames, IList tokenNames)
- {
- System.Diagnostics.Debug.Assert(atn.grammarType != null);
- this.atn = atn;
- this.ruleNames = ruleNames;
- this.tokenNames = tokenNames;
- }
-
- ///
- /// Serialize state descriptors, edge descriptors, and decision→state map
- /// into list of ints:
- /// grammar-type, (ANTLRParser.LEXER, ...)
- /// max token type,
- /// num states,
- /// state-0-type ruleIndex, state-1-type ruleIndex, ...
- ///
- ///
- /// Serialize state descriptors, edge descriptors, and decision→state map
- /// into list of ints:
- /// grammar-type, (ANTLRParser.LEXER, ...)
- /// max token type,
- /// num states,
- /// state-0-type ruleIndex, state-1-type ruleIndex, ... state-i-type ruleIndex optional-arg ...
- /// num rules,
- /// rule-1-start-state rule-1-args, rule-2-start-state rule-2-args, ...
- /// (args are token type,actionIndex in lexer else 0,0)
- /// num modes,
- /// mode-0-start-state, mode-1-start-state, ... (parser has 0 modes)
- /// num sets
- /// set-0-interval-count intervals, set-1-interval-count intervals, ...
- /// num total edges,
- /// src, trg, edge-type, edge arg1, optional edge arg2 (present always), ...
- /// num decisions,
- /// decision-0-start-state, decision-1-start-state, ...
- /// Convenient to pack into unsigned shorts to make as Java string.
- ///
- public virtual List Serialize()
- {
- List data = new List();
- data.Add(ATNDeserializer.SerializedVersion);
- SerializeUUID(data, ATNDeserializer.SerializedUuid);
- // convert grammar type to ATN const to avoid dependence on ANTLRParser
- data.Add((int)(atn.grammarType));
- data.Add(atn.maxTokenType);
- int nedges = 0;
- IDictionary setIndices = new Dictionary();
- IList sets = new List();
- // dump states, count edges and collect sets while doing so
- List nonGreedyStates = new List();
- List sllStates = new List();
- List precedenceStates = new List();
- data.Add(atn.states.Count);
- foreach (ATNState s in atn.states)
- {
- if (s == null)
- {
- // might be optimized away
- data.Add((int)(StateType.InvalidType));
- continue;
- }
- StateType stateType = s.StateType;
- if (s is DecisionState)
- {
- DecisionState decisionState = (DecisionState)s;
- if (decisionState.nonGreedy)
- {
- nonGreedyStates.Add(s.stateNumber);
- }
- if (decisionState.sll)
- {
- sllStates.Add(s.stateNumber);
- }
- }
- if (s is RuleStartState && ((RuleStartState)s).isPrecedenceRule)
- {
- precedenceStates.Add(s.stateNumber);
- }
- data.Add((int)(stateType));
- if (s.ruleIndex == -1)
- {
- data.Add(char.MaxValue);
- }
- else
- {
- data.Add(s.ruleIndex);
- }
- if (s.StateType == StateType.LoopEnd)
- {
- data.Add(((LoopEndState)s).loopBackState.stateNumber);
- }
- else
- {
- if (s is BlockStartState)
- {
- data.Add(((BlockStartState)s).endState.stateNumber);
- }
- }
- if (s.StateType != StateType.RuleStop)
- {
- // the deserializer can trivially derive these edges, so there's no need to serialize them
- nedges += s.NumberOfTransitions;
- }
- for (int i = 0; i < s.NumberOfTransitions; i++)
- {
- Transition t = s.Transition(i);
- TransitionType edgeType = Transition.serializationTypes.Get(t.GetType());
- if (edgeType == TransitionType.Set || edgeType == TransitionType.NotSet)
- {
- SetTransition st = (SetTransition)t;
- if (!setIndices.ContainsKey(st.set))
- {
- sets.Add(st.set);
- setIndices.Put(st.set, sets.Count - 1);
- }
- }
- }
- }
- // non-greedy states
- data.Add(nonGreedyStates.Size());
- for (int i_1 = 0; i_1 < nonGreedyStates.Size(); i_1++)
- {
- data.Add(nonGreedyStates.Get(i_1));
- }
- // SLL decisions
- data.Add(sllStates.Size());
- for (int i_2 = 0; i_2 < sllStates.Size(); i_2++)
- {
- data.Add(sllStates.Get(i_2));
- }
- // precedence states
- data.Add(precedenceStates.Size());
- for (int i_3 = 0; i_3 < precedenceStates.Size(); i_3++)
- {
- data.Add(precedenceStates.Get(i_3));
- }
- int nrules = atn.ruleToStartState.Length;
- data.Add(nrules);
- for (int r = 0; r < nrules; r++)
- {
- ATNState ruleStartState = atn.ruleToStartState[r];
- data.Add(ruleStartState.stateNumber);
- bool leftFactored = ruleNames[ruleStartState.ruleIndex].IndexOf(ATNSimulator.RuleVariantDelimiter) >= 0;
- data.Add(leftFactored ? 1 : 0);
- if (atn.grammarType == ATNType.Lexer)
- {
- if (atn.ruleToTokenType[r] == TokenConstants.Eof)
- {
- data.Add(char.MaxValue);
- }
- else
- {
- data.Add(atn.ruleToTokenType[r]);
- }
- }
- }
- int nmodes = atn.modeToStartState.Count;
- data.Add(nmodes);
- if (nmodes > 0)
- {
- foreach (ATNState modeStartState in atn.modeToStartState)
- {
- data.Add(modeStartState.stateNumber);
- }
- }
- int nsets = sets.Count;
- data.Add(nsets);
- foreach (IntervalSet set in sets)
- {
- bool containsEof = set.Contains(TokenConstants.Eof);
- if (containsEof && set.GetIntervals()[0].b == TokenConstants.Eof)
- {
- data.Add(set.GetIntervals().Count - 1);
- }
- else
- {
- data.Add(set.GetIntervals().Count);
- }
- data.Add(containsEof ? 1 : 0);
- foreach (Interval I in set.GetIntervals())
- {
- if (I.a == TokenConstants.Eof)
- {
- if (I.b == TokenConstants.Eof)
- {
- continue;
- }
- else
- {
- data.Add(0);
- }
- }
- else
- {
- data.Add(I.a);
- }
- data.Add(I.b);
- }
- }
- data.Add(nedges);
- foreach (ATNState s_1 in atn.states)
- {
- if (s_1 == null)
- {
- // might be optimized away
- continue;
- }
- if (s_1.StateType == StateType.RuleStop)
- {
- continue;
- }
- for (int i = 0; i_3 < s_1.NumberOfTransitions; i_3++)
- {
- Transition t = s_1.Transition(i_3);
- if (atn.states[t.target.stateNumber] == null)
- {
- throw new InvalidOperationException("Cannot serialize a transition to a removed state.");
- }
- int src = s_1.stateNumber;
- int trg = t.target.stateNumber;
- TransitionType edgeType = Transition.serializationTypes.Get(t.GetType());
- int arg1 = 0;
- int arg2 = 0;
- int arg3 = 0;
- switch (edgeType)
- {
- case TransitionType.Rule:
- {
- trg = ((RuleTransition)t).followState.stateNumber;
- arg1 = ((RuleTransition)t).target.stateNumber;
- arg2 = ((RuleTransition)t).ruleIndex;
- arg3 = ((RuleTransition)t).precedence;
- break;
- }
-
- case TransitionType.Precedence:
- {
- PrecedencePredicateTransition ppt = (PrecedencePredicateTransition)t;
- arg1 = ppt.precedence;
- break;
- }
-
- case TransitionType.Predicate:
- {
- PredicateTransition pt = (PredicateTransition)t;
- arg1 = pt.ruleIndex;
- arg2 = pt.predIndex;
- arg3 = pt.isCtxDependent ? 1 : 0;
- break;
- }
-
- case TransitionType.Range:
- {
- arg1 = ((RangeTransition)t).from;
- arg2 = ((RangeTransition)t).to;
- if (arg1 == TokenConstants.Eof)
- {
- arg1 = 0;
- arg3 = 1;
- }
- break;
- }
-
- case TransitionType.Atom:
- {
- arg1 = ((AtomTransition)t).label;
- if (arg1 == TokenConstants.Eof)
- {
- arg1 = 0;
- arg3 = 1;
- }
- break;
- }
-
- case TransitionType.Action:
- {
- ActionTransition at = (ActionTransition)t;
- arg1 = at.ruleIndex;
- arg2 = at.actionIndex;
- if (arg2 == -1)
- {
- arg2 = unchecked((int)(0xFFFF));
- }
- arg3 = at.isCtxDependent ? 1 : 0;
- break;
- }
-
- case TransitionType.Set:
- {
- arg1 = setIndices.Get(((SetTransition)t).set);
- break;
- }
-
- case TransitionType.NotSet:
- {
- arg1 = setIndices.Get(((SetTransition)t).set);
- break;
- }
-
- case TransitionType.Wildcard:
- {
- break;
- }
- }
- data.Add(src);
- data.Add(trg);
- data.Add((int)(edgeType));
- data.Add(arg1);
- data.Add(arg2);
- data.Add(arg3);
- }
- }
- int ndecisions = atn.decisionToState.Count;
- data.Add(ndecisions);
- foreach (DecisionState decStartState in atn.decisionToState)
- {
- data.Add(decStartState.stateNumber);
- }
- //
- // LEXER ACTIONS
- //
- if (atn.grammarType == ATNType.Lexer)
- {
- data.Add(atn.lexerActions.Length);
- foreach (ILexerAction action in atn.lexerActions)
- {
- data.Add((int)(action.ActionType));
- switch (action.ActionType)
- {
- case LexerActionType.Channel:
- {
- int channel = ((LexerChannelAction)action).Channel;
- data.Add(channel != -1 ? channel : unchecked((int)(0xFFFF)));
- data.Add(0);
- break;
- }
-
- case LexerActionType.Custom:
- {
- int ruleIndex = ((LexerCustomAction)action).RuleIndex;
- int actionIndex = ((LexerCustomAction)action).ActionIndex;
- data.Add(ruleIndex != -1 ? ruleIndex : unchecked((int)(0xFFFF)));
- data.Add(actionIndex != -1 ? actionIndex : unchecked((int)(0xFFFF)));
- break;
- }
-
- case LexerActionType.Mode:
- {
- int mode = ((LexerModeAction)action).Mode;
- data.Add(mode != -1 ? mode : unchecked((int)(0xFFFF)));
- data.Add(0);
- break;
- }
-
- case LexerActionType.More:
- {
- data.Add(0);
- data.Add(0);
- break;
- }
-
- case LexerActionType.PopMode:
- {
- data.Add(0);
- data.Add(0);
- break;
- }
-
- case LexerActionType.PushMode:
- {
- mode = ((LexerPushModeAction)action).Mode;
- data.Add(mode != -1 ? mode : unchecked((int)(0xFFFF)));
- data.Add(0);
- break;
- }
-
- case LexerActionType.Skip:
- {
- data.Add(0);
- data.Add(0);
- break;
- }
-
- case LexerActionType.Type:
- {
- int type = ((LexerTypeAction)action).Type;
- data.Add(type != -1 ? type : unchecked((int)(0xFFFF)));
- data.Add(0);
- break;
- }
-
- default:
- {
- string message = string.Format(CultureInfo.CurrentCulture, "The specified lexer action type {0} is not valid.", action.ActionType);
- throw new ArgumentException(message);
- }
- }
- }
- }
- // don't adjust the first value since that's the version number
- for (int i_4 = 1; i_4 < data.Size(); i_4++)
- {
- if (data.Get(i_4) < char.MinValue || data.Get(i_4) > char.MaxValue)
- {
- throw new NotSupportedException("Serialized ATN data element out of range.");
- }
- int value = (data.Get(i_4) + 2) & unchecked((int)(0xFFFF));
- data.Set(i_4, value);
- }
- return data;
- }
-
- public virtual string Decode(char[] data)
- {
- data = data.Clone();
- // don't adjust the first value since that's the version number
- for (int i = 1; i < data.Length; i++)
- {
- data[i] = (char)(data[i] - 2);
- }
- StringBuilder buf = new StringBuilder();
- int p = 0;
- int version = ATNDeserializer.ToInt(data[p++]);
- if (version != ATNDeserializer.SerializedVersion)
- {
- string reason = string.Format("Could not deserialize ATN with version {0} (expected {1}).", version, ATNDeserializer.SerializedVersion);
- throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
- }
- Guid uuid = ATNDeserializer.ToUUID(data, p);
- p += 8;
- if (!uuid.Equals(ATNDeserializer.SerializedUuid))
- {
- string reason = string.Format(CultureInfo.CurrentCulture, "Could not deserialize ATN with UUID {0} (expected {1}).", uuid, ATNDeserializer.SerializedUuid);
- throw new NotSupportedException(new InvalidClassException(typeof(ATN).FullName, reason));
- }
- p++;
- // skip grammarType
- int maxType = ATNDeserializer.ToInt(data[p++]);
- buf.Append("max type ").Append(maxType).Append("\n");
- int nstates = ATNDeserializer.ToInt(data[p++]);
- for (int i_1 = 0; i_1 < nstates; i_1++)
- {
- StateType stype = StateType.Values()[ATNDeserializer.ToInt(data[p++])];
- if (stype == StateType.InvalidType)
- {
- continue;
- }
- // ignore bad type of states
- int ruleIndex = ATNDeserializer.ToInt(data[p++]);
- if (ruleIndex == char.MaxValue)
- {
- ruleIndex = -1;
- }
- string arg = string.Empty;
- if (stype == StateType.LoopEnd)
- {
- int loopBackStateNumber = ATNDeserializer.ToInt(data[p++]);
- arg = " " + loopBackStateNumber;
- }
- else
- {
- if (stype == StateType.PlusBlockStart || stype == StateType.StarBlockStart || stype == StateType.BlockStart)
- {
- int endStateNumber = ATNDeserializer.ToInt(data[p++]);
- arg = " " + endStateNumber;
- }
- }
- buf.Append(i_1).Append(":").Append(ATNState.serializationNames[(int)(stype)]).Append(" ").Append(ruleIndex).Append(arg).Append("\n");
- }
- int numNonGreedyStates = ATNDeserializer.ToInt(data[p++]);
- for (int i_2 = 0; i_2 < numNonGreedyStates; i_2++)
- {
- int stateNumber = ATNDeserializer.ToInt(data[p++]);
- }
- int numSllStates = ATNDeserializer.ToInt(data[p++]);
- for (int i_3 = 0; i_3 < numSllStates; i_3++)
- {
- int stateNumber = ATNDeserializer.ToInt(data[p++]);
- }
- int numPrecedenceStates = ATNDeserializer.ToInt(data[p++]);
- for (int i_4 = 0; i_4 < numPrecedenceStates; i_4++)
- {
- int stateNumber = ATNDeserializer.ToInt(data[p++]);
- }
- int nrules = ATNDeserializer.ToInt(data[p++]);
- for (int i_5 = 0; i_5 < nrules; i_5++)
- {
- int s = ATNDeserializer.ToInt(data[p++]);
- bool leftFactored = ATNDeserializer.ToInt(data[p++]) != 0;
- if (atn.grammarType == ATNType.Lexer)
- {
- int arg1 = ATNDeserializer.ToInt(data[p++]);
- buf.Append("rule ").Append(i_5).Append(":").Append(s).Append(" ").Append(arg1).Append('\n');
- }
- else
- {
- buf.Append("rule ").Append(i_5).Append(":").Append(s).Append('\n');
- }
- }
- int nmodes = ATNDeserializer.ToInt(data[p++]);
- for (int i_6 = 0; i_6 < nmodes; i_6++)
- {
- int s = ATNDeserializer.ToInt(data[p++]);
- buf.Append("mode ").Append(i_6).Append(":").Append(s).Append('\n');
- }
- int nsets = ATNDeserializer.ToInt(data[p++]);
- for (int i_7 = 0; i_7 < nsets; i_7++)
- {
- int nintervals = ATNDeserializer.ToInt(data[p++]);
- buf.Append(i_7).Append(":");
- bool containsEof = data[p++] != 0;
- if (containsEof)
- {
- buf.Append(GetTokenName(TokenConstants.Eof));
- }
- for (int j = 0; j < nintervals; j++)
- {
- if (containsEof || j > 0)
- {
- buf.Append(", ");
- }
- buf.Append(GetTokenName(ATNDeserializer.ToInt(data[p]))).Append("..").Append(GetTokenName(ATNDeserializer.ToInt(data[p + 1])));
- p += 2;
- }
- buf.Append("\n");
- }
- int nedges = ATNDeserializer.ToInt(data[p++]);
- for (int i_8 = 0; i_8 < nedges; i_8++)
- {
- int src = ATNDeserializer.ToInt(data[p]);
- int trg = ATNDeserializer.ToInt(data[p + 1]);
- int ttype = ATNDeserializer.ToInt(data[p + 2]);
- int arg1 = ATNDeserializer.ToInt(data[p + 3]);
- int arg2 = ATNDeserializer.ToInt(data[p + 4]);
- int arg3 = ATNDeserializer.ToInt(data[p + 5]);
- buf.Append(src).Append("->").Append(trg).Append(" ").Append(Transition.serializationNames[ttype]).Append(" ").Append(arg1).Append(",").Append(arg2).Append(",").Append(arg3).Append("\n");
- p += 6;
- }
- int ndecisions = ATNDeserializer.ToInt(data[p++]);
- for (int i_9 = 0; i_9 < ndecisions; i_9++)
- {
- int s = ATNDeserializer.ToInt(data[p++]);
- buf.Append(i_9).Append(":").Append(s).Append("\n");
- }
- if (atn.grammarType == ATNType.Lexer)
- {
- int lexerActionCount = ATNDeserializer.ToInt(data[p++]);
- for (int i_10 = 0; i_10 < lexerActionCount; i_10++)
- {
- LexerActionType actionType = LexerActionType.Values()[ATNDeserializer.ToInt(data[p++])];
- int data1 = ATNDeserializer.ToInt(data[p++]);
- int data2 = ATNDeserializer.ToInt(data[p++]);
- }
- }
- return buf.ToString();
- }
-
- public virtual string GetTokenName(int t)
- {
- if (t == -1)
- {
- return "EOF";
- }
- if (atn.grammarType == ATNType.Lexer && t >= char.MinValue && t <= char.MaxValue)
- {
- switch (t)
- {
- case '\n':
- {
- return "'\\n'";
- }
-
- case '\r':
- {
- return "'\\r'";
- }
-
- case '\t':
- {
- return "'\\t'";
- }
-
- case '\b':
- {
- return "'\\b'";
- }
-
- case '\f':
- {
- return "'\\f'";
- }
-
- case '\\':
- {
- return "'\\\\'";
- }
-
- case '\'':
- {
- return "'\\''";
- }
-
- default:
- {
- if (Character.UnicodeBlock.Of((char)t) == Character.UnicodeBlock.BasicLatin && !char.IsISOControl((char)t))
- {
- return '\'' + char.ToString((char)t) + '\'';
- }
- // turn on the bit above max "\uFFFF" value so that we pad with zeros
- // then only take last 4 digits
- string hex = Sharpen.Runtime.Substring(Antlr4.Runtime.Sharpen.Extensions.ToHexString(t | unchecked((int)(0x10000))).ToUpper(), 1, 5);
- string unicodeStr = "'\\u" + hex + "'";
- return unicodeStr;
- }
- }
- }
- if (tokenNames != null && t >= 0 && t < tokenNames.Count)
- {
- return tokenNames[t];
- }
- return t.ToString();
- }
-
- /// Used by Java target to encode short/int array as chars in string.
- /// Used by Java target to encode short/int array as chars in string.
- public static string GetSerializedAsString(ATN atn, IList ruleNames)
- {
- return new string(GetSerializedAsChars(atn, ruleNames));
- }
-
- public static List GetSerialized(ATN atn, IList ruleNames)
- {
- return new Antlr4.Runtime.Atn.ATNSerializer(atn, ruleNames).Serialize();
- }
-
- public static char[] GetSerializedAsChars(ATN atn, IList ruleNames)
- {
- return Utils.ToCharArray(GetSerialized(atn, ruleNames));
- }
-
- public static string GetDecoded(ATN atn, IList ruleNames, IList tokenNames)
- {
- List serialized = GetSerialized(atn, ruleNames);
- char[] data = Utils.ToCharArray(serialized);
- return new Antlr4.Runtime.Atn.ATNSerializer(atn, ruleNames, tokenNames).Decode(data);
- }
-
- private void SerializeUUID(List data, Guid uuid)
- {
- SerializeLong(data, uuid.GetLeastSignificantBits());
- SerializeLong(data, uuid.GetMostSignificantBits());
- }
-
- private void SerializeLong(List data, long value)
- {
- SerializeInt(data, (int)value);
- SerializeInt(data, (int)(value >> 32));
- }
-
- private void SerializeInt(List data, int value)
- {
- data.Add((char)value);
- data.Add((char)(value >> 16));
- }
- }
-}
diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/DecisionInfo.cs b/runtime/CSharp/Antlr4.Runtime/Atn/DecisionInfo.cs
index 86a347658..9cd92543a 100644
--- a/runtime/CSharp/Antlr4.Runtime/Atn/DecisionInfo.cs
+++ b/runtime/CSharp/Antlr4.Runtime/Atn/DecisionInfo.cs
@@ -31,9 +31,7 @@ using System.Collections.Generic;
using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa;
using Antlr4.Runtime.Sharpen;
-#if !PORTABLE || NET45PLUS
-using Stopwatch = System.Diagnostics.Stopwatch;
-#endif
+
namespace Antlr4.Runtime.Atn
{
@@ -66,24 +64,6 @@ namespace Antlr4.Runtime.Atn
///
public long invocations;
-#if !PORTABLE || NET45PLUS
- ///
- /// The total time spent in
- ///
- /// for
- /// this decision, in nanoseconds.
- ///
- /// The value of this field is computed by ,
- /// and is not adjusted to compensate for JIT
- /// and/or garbage collection overhead. For best accuracy, perform profiling
- /// in a separate process which is warmed up by parsing the input prior to
- /// profiling. If desired, call
- /// to reset the DFA cache to its initial
- /// state before starting the profiling measurement pass.
- ///
- public long timeInPrediction;
-#endif
-
/// The sum of the lookahead required for SLL prediction for this decision.
///
/// The sum of the lookahead required for SLL prediction for this decision.
diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ParseInfo.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ParseInfo.cs
index 13c8d850b..17f9a5c42 100644
--- a/runtime/CSharp/Antlr4.Runtime/Atn/ParseInfo.cs
+++ b/runtime/CSharp/Antlr4.Runtime/Atn/ParseInfo.cs
@@ -81,7 +81,7 @@ namespace Antlr4.Runtime.Atn
///
/// Gets the decision numbers for decisions that required one or more
/// full-context predictions during parsing. These are decisions for which
- ///
+ ///
/// is non-zero.
///
///
@@ -104,29 +104,6 @@ namespace Antlr4.Runtime.Atn
return Ll;
}
-#if !PORTABLE || NET45PLUS
- ///
- /// Gets the total time spent during prediction across all decisions made
- /// during parsing.
- ///
- ///
- /// Gets the total time spent during prediction across all decisions made
- /// during parsing. This value is the sum of
- ///
- /// for all decisions.
- ///
- public virtual long GetTotalTimeInPrediction()
- {
- Antlr4.Runtime.Atn.DecisionInfo[] decisions = atnSimulator.DecisionInfo;
- long t = 0;
- for (int i = 0; i < decisions.Length; i++)
- {
- t += decisions[i].timeInPrediction;
- }
- return t;
- }
-#endif
-
///
/// Gets the total number of SLL lookahead operations across all decisions
/// made during parsing.
@@ -134,7 +111,7 @@ namespace Antlr4.Runtime.Atn
///
/// Gets the total number of SLL lookahead operations across all decisions
/// made during parsing. This value is the sum of
- ///
+ ///
/// for all decisions.
///
public virtual long GetTotalSLLLookaheadOps()
@@ -155,7 +132,7 @@ namespace Antlr4.Runtime.Atn
///
/// Gets the total number of LL lookahead operations across all decisions
/// made during parsing. This value is the sum of
- ///
+ ///
/// for all decisions.
///
public virtual long GetTotalLLLookaheadOps()
diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ParserATNSimulator.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ParserATNSimulator.cs
index 5f338e0cf..1a587cbc0 100644
--- a/runtime/CSharp/Antlr4.Runtime/Atn/ParserATNSimulator.cs
+++ b/runtime/CSharp/Antlr4.Runtime/Atn/ParserATNSimulator.cs
@@ -246,7 +246,6 @@ namespace Antlr4.Runtime.Atn
/// )
/// ;
/// parser.
- ///
/// (new
///
/// ());
@@ -737,7 +736,7 @@ namespace Antlr4.Runtime.Atn
/// and
///
/// is
- ///
+ ///
/// . In that case, only
/// conflict states where
///
diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/ProfilingATNSimulator.cs b/runtime/CSharp/Antlr4.Runtime/Atn/ProfilingATNSimulator.cs
index 1e394750e..50c3cc0aa 100644
--- a/runtime/CSharp/Antlr4.Runtime/Atn/ProfilingATNSimulator.cs
+++ b/runtime/CSharp/Antlr4.Runtime/Atn/ProfilingATNSimulator.cs
@@ -32,9 +32,6 @@ using Antlr4.Runtime;
using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa;
using Antlr4.Runtime.Sharpen;
-#if !PORTABLE || NET45PLUS
-using Stopwatch = System.Diagnostics.Stopwatch;
-#endif
namespace Antlr4.Runtime.Atn
{
@@ -100,14 +97,8 @@ namespace Antlr4.Runtime.Atn
this.currentDecision = decision;
this.currentState = null;
this.conflictingAltResolvedBySLL = ATN.InvalidAltNumber;
-#if !PORTABLE || NET45PLUS
- Stopwatch stopwatch = Stopwatch.StartNew();
-#endif
// expensive but useful info
int alt = base.AdaptivePredict(input, decision, outerContext);
-#if !PORTABLE || NET45PLUS
- decisions[decision].timeInPrediction += stopwatch.ElapsedTicks * 100;
-#endif
decisions[decision].invocations++;
int SLL_k = _sllStopIndex - _startIndex + 1;
decisions[decision].SLL_TotalLook += SLL_k;
diff --git a/runtime/CSharp/Antlr4.Runtime/BufferedTokenStream.cs b/runtime/CSharp/Antlr4.Runtime/BufferedTokenStream.cs
index 5fa17ba60..7442d3037 100644
--- a/runtime/CSharp/Antlr4.Runtime/BufferedTokenStream.cs
+++ b/runtime/CSharp/Antlr4.Runtime/BufferedTokenStream.cs
@@ -106,7 +106,7 @@ namespace Antlr4.Runtime
/// Indicates whether the
///
/// token has been fetched from
- ///
+ ///
/// and added to
///
/// . This field improves
diff --git a/runtime/CSharp/Antlr4.Runtime/CommonToken.cs b/runtime/CSharp/Antlr4.Runtime/CommonToken.cs
index 711815097..090b37183 100644
--- a/runtime/CSharp/Antlr4.Runtime/CommonToken.cs
+++ b/runtime/CSharp/Antlr4.Runtime/CommonToken.cs
@@ -164,14 +164,14 @@ namespace Antlr4.Runtime
///
/// instance, the newly
/// constructed token will share a reference to the
- ///
+ ///
/// field and
/// the
///
/// stored in
///
/// . Otherwise,
- ///
+ ///
/// will
/// be assigned the result of calling
///
diff --git a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs
index a751ab8d1..2a8d6bbf2 100644
--- a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs
+++ b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs
@@ -234,6 +234,7 @@ namespace Antlr4.Runtime.Dfa
/// Get the start state for a specific precedence value.
/// Get the start state for a specific precedence value.
/// The current precedence.
+ /// Whether to get from local of full context.
///
/// The start state corresponding to the specified precedence, or
///
@@ -260,6 +261,7 @@ namespace Antlr4.Runtime.Dfa
/// Set the start state for a specific precedence value.
/// Set the start state for a specific precedence value.
/// The current precedence.
+ /// Whether to set local of full context.
///
/// The start state corresponding to the specified
/// precedence.
diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/Array2DHashSet`1.cs b/runtime/CSharp/Antlr4.Runtime/Misc/Array2DHashSet`1.cs
deleted file mode 100644
index 5ddb06fc0..000000000
--- a/runtime/CSharp/Antlr4.Runtime/Misc/Array2DHashSet`1.cs
+++ /dev/null
@@ -1,689 +0,0 @@
-/*
- * [The "BSD license"]
- * Copyright (c) 2013 Terence Parr
- * Copyright (c) 2013 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Antlr4.Runtime.Misc;
-using Antlr4.Runtime.Sharpen;
-
-namespace Antlr4.Runtime.Misc
-{
- ///
- ///
- /// implementation with closed hashing (open addressing).
- ///
- public class Array2DHashSet : HashSet
- {
- public const int InitalCapacity = 16;
-
- public const int InitalBucketCapacity = 8;
-
- public const double LoadFactor = 0.75;
-
- [NotNull]
- protected internal readonly EqualityComparer comparator;
-
- protected internal T[][] buckets;
-
- /// How many elements in set
- protected internal int n = 0;
-
- protected internal int threshold = (int)(InitalCapacity * LoadFactor);
-
- protected internal int currentPrime = 1;
-
- protected internal int initialBucketCapacity = InitalBucketCapacity;
-
- public Array2DHashSet()
- : this(null, InitalCapacity, InitalBucketCapacity)
- {
- }
-
- public Array2DHashSet(EqualityComparer comparator)
- : this(comparator, InitalCapacity, InitalBucketCapacity)
- {
- }
-
- public Array2DHashSet(EqualityComparer comparator, int initialCapacity, int initialBucketCapacity)
- {
- // must be power of 2
- // when to expand
- // jump by 4 primes each expand or whatever
- if (comparator == null)
- {
- comparator = ObjectEqualityComparator.Instance;
- }
- this.comparator = comparator;
- this.buckets = CreateBuckets(initialCapacity);
- this.initialBucketCapacity = initialBucketCapacity;
- }
-
- ///
- /// Add
- ///
- /// to set if not there; return existing value if already
- /// there. This method performs the same operation as
- ///
- /// aside from
- /// the return value.
- ///
- public T GetOrAdd(T o)
- {
- if (n > threshold)
- {
- Expand();
- }
- return GetOrAddImpl(o);
- }
-
- protected internal virtual T GetOrAddImpl(T o)
- {
- int b = GetBucket(o);
- T[] bucket = buckets[b];
- // NEW BUCKET
- if (bucket == null)
- {
- bucket = CreateBucket(initialBucketCapacity);
- bucket[0] = o;
- buckets[b] = bucket;
- n++;
- return o;
- }
- // LOOK FOR IT IN BUCKET
- for (int i = 0; i < bucket.Length; i++)
- {
- T existing = bucket[i];
- if (existing == null)
- {
- // empty slot; not there, add.
- bucket[i] = o;
- n++;
- return o;
- }
- if (comparator.Equals(existing, o))
- {
- return existing;
- }
- }
- // found existing, quit
- // FULL BUCKET, expand and add to end
- int oldLength = bucket.Length;
- bucket = Arrays.CopyOf(bucket, bucket.Length * 2);
- buckets[b] = bucket;
- bucket[oldLength] = o;
- // add to end
- n++;
- return o;
- }
-
- public virtual T Get(T o)
- {
- if (o == null)
- {
- return o;
- }
- int b = GetBucket(o);
- T[] bucket = buckets[b];
- if (bucket == null)
- {
- return null;
- }
- // no bucket
- foreach (T e in bucket)
- {
- if (e == null)
- {
- return null;
- }
- // empty slot; not there
- if (comparator.Equals(e, o))
- {
- return e;
- }
- }
- return null;
- }
-
- protected internal int GetBucket(T o)
- {
- int hash = comparator.GetHashCode(o);
- int b = hash & (buckets.Length - 1);
- // assumes len is power of 2
- return b;
- }
-
- public override int GetHashCode()
- {
- int hash = MurmurHash.Initialize();
- foreach (T[] bucket in buckets)
- {
- if (bucket == null)
- {
- continue;
- }
- foreach (T o in bucket)
- {
- if (o == null)
- {
- break;
- }
- hash = MurmurHash.Update(hash, comparator.GetHashCode(o));
- }
- }
- hash = MurmurHash.Finish(hash, Count);
- return hash;
- }
-
- public override bool Equals(object o)
- {
- if (o == this)
- {
- return true;
- }
- if (!(o is Antlr4.Runtime.Misc.Array2DHashSet))
- {
- return false;
- }
- Antlr4.Runtime.Misc.Array2DHashSet