diff --git a/runtime/CSharp/.nuget/NuGet.Config b/runtime/CSharp/.nuget/NuGet.Config deleted file mode 100644 index 67f8ea046..000000000 --- a/runtime/CSharp/.nuget/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/runtime/CSharp/.nuget/NuGet.VS2008.targets b/runtime/CSharp/.nuget/NuGet.VS2008.targets deleted file mode 100644 index a50c8a66d..000000000 --- a/runtime/CSharp/.nuget/NuGet.VS2008.targets +++ /dev/null @@ -1,101 +0,0 @@ - - - - $(MSBuildProjectDirectory)\..\ - - - false - - - false - - - true - - - - - - - - - - - $(SolutionDir).nuget - - - - - $(SolutionDir).nuget - - - - packages.$(MSBuildProjectName).config - - - - - - $(PackagesProjectConfig) - - - - - packages.config - - - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 $(NuGetExePath) - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - "$(SolutionDir) " - "$(SolutionDir)" - - - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) - $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - diff --git a/runtime/CSharp/.nuget/NuGet.exe b/runtime/CSharp/.nuget/NuGet.exe deleted file mode 100644 index 9cba6edbf..000000000 Binary files a/runtime/CSharp/.nuget/NuGet.exe and /dev/null differ diff --git a/runtime/CSharp/.nuget/NuGet.targets b/runtime/CSharp/.nuget/NuGet.targets deleted file mode 100644 index 2c3545bc7..000000000 --- a/runtime/CSharp/.nuget/NuGet.targets +++ /dev/null @@ -1,151 +0,0 @@ - - - - $(MSBuildProjectDirectory)\..\ - - - false - - - false - - - true - - - false - - - - - - - - - - - $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) - - - - - $(SolutionDir).nuget - - - - packages.$(MSBuildProjectName.Replace(' ', '_')).config - - - - - - $(PackagesProjectConfig) - - - - - packages.config - - - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 $(NuGetExePath) - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - "$(SolutionDir) " - "$(SolutionDir)" - - - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) - $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net20.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net20.csproj deleted file mode 100644 index e4eb212c4..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net20.csproj +++ /dev/null @@ -1,127 +0,0 @@ - - - - - Debug - AnyCPU - {0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.net20 - v3.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\net20\ - ..\ - true - - - true - full - false - bin\net20\Debug\ - DEBUG;TRACE;NET20;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\net20\Release\ - TRACE;NET20;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {e1a46d9d-66cb-46e8-93b0-7fc87299abef} - Antlr4.Runtime.net20 - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.net30.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net30.csproj deleted file mode 100644 index 53fb7d063..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net30.csproj +++ /dev/null @@ -1,127 +0,0 @@ - - - - - Debug - AnyCPU - {8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.net30 - v3.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\net30\ - ..\ - true - - - true - full - false - bin\net30\Debug\ - DEBUG;TRACE;NET30;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\net30\Release\ - TRACE;NET30;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {ebbdcc35-43cc-416c-860b-9fc115f1eb42} - Antlr4.Runtime.net30 - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.net35-client.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net35-client.csproj deleted file mode 100644 index 0791a16a3..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net35-client.csproj +++ /dev/null @@ -1,127 +0,0 @@ - - - - - Debug - AnyCPU - {C4A38390-8AA3-45AE-9A70-C392146B37D0} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.net35_client - v3.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\net35\ - ..\ - true - - - true - full - false - bin\net35\Debug\ - DEBUG;TRACE;NET35;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\net35\Release\ - TRACE;NET35;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {e186fda3-1411-47ee-94c7-9f3745f0474b} - Antlr4.Runtime.net35-client - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.net40-client.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net40-client.csproj deleted file mode 100644 index 9e528e8eb..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net40-client.csproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - AnyCPU - {706D364A-CD4E-4720-B94C-0DB82AF7B433} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.net40_client - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\net40\ - ..\ - true - - - true - full - false - bin\net40\Debug\ - DEBUG;TRACE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\net40\Release\ - TRACE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {423978df-85a4-409e-a16c-453683fe3969} - Antlr4.Runtime.net40-client - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.net45.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net45.csproj deleted file mode 100644 index 46d00d3a4..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.net45.csproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - AnyCPU - {9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.net45 - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\net45\ - ..\ - true - - - true - full - false - bin\net45\Debug\ - DEBUG;TRACE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\net45\Release\ - TRACE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {e1d192de-5347-48c4-a9f4-a8cba2af3869} - Antlr4.Runtime.net45 - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.portable-net40.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.portable-net40.csproj deleted file mode 100644 index b5ac880c6..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.portable-net40.csproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - AnyCPU - {97C32E42-51B2-4A29-B005-769B63CFEFCA} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.portable_net40 - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\portable-net40\ - ..\ - true - - - true - full - false - bin\portable-net40\Debug\ - DEBUG;TRACE;PORTABLE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\portable-net40\Release\ - TRACE;PORTABLE;NET40;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {06c182c5-095c-4d43-9c33-c87e305c6bc2} - Antlr4.Runtime.portable-net40 - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/Antlr4.Runtime.Test.portable-net45.csproj b/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.portable-net45.csproj deleted file mode 100644 index e4c60d563..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Antlr4.Runtime.Test.portable-net45.csproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - AnyCPU - {5844076E-3C92-4122-BB7A-0D745C3F5334} - Library - Properties - Antlr4.Runtime.Test - Antlr4.Runtime.Test.portable_net45 - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - obj\portable-net45\ - ..\ - true - - - true - full - false - bin\portable-net45\Debug\ - DEBUG;TRACE;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - pdbonly - true - bin\portable-net45\Release\ - TRACE;PORTABLE;NET45;NET45PLUS;NET40PLUS;NET35PLUS;NET30PLUS;NET20PLUS - prompt - 4 - true - - - true - - - TestingKey.snk - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {12269283-ee92-4faa-b849-53cd24f341fa} - Antlr4.Runtime.portable-net45 - - - - - - - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - 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.Test/BaseTest.cs b/runtime/CSharp/Antlr4.Runtime.Test/BaseTest.cs deleted file mode 100644 index df9dbd717..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/BaseTest.cs +++ /dev/null @@ -1,1213 +0,0 @@ -namespace Antlr4.Runtime.Test -{ - using System; - using System.Collections.Generic; - using System.Text; - using Antlr4.Runtime.Misc; - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Microsoft.Win32; - using Directory = System.IO.Directory; - using DirectoryInfo = System.IO.DirectoryInfo; - using File = System.IO.File; - using IOException = System.IO.IOException; - using Path = System.IO.Path; - using TextReader = System.IO.TextReader; - using Thread = System.Threading.Thread; - - public abstract class BaseTest - { -#if false - // -J-Dorg.antlr.v4.test.BaseTest.level=FINE - private static readonly Logger LOGGER = Logger.getLogger(typeof(BaseTest).getName()); - - public static readonly string newline = System.getProperty("line.separator"); - public static readonly string pathSep = System.getProperty("path.separator"); - - public static readonly bool TEST_IN_SAME_PROCESS = Boolean.parseBoolean(System.getProperty("antlr.testinprocess")); - public static readonly bool STRICT_COMPILE_CHECKS = Boolean.parseBoolean(System.getProperty("antlr.strictcompile")); - - /** - * Build up the full classpath we need, including the surefire path (if present) - */ - public static readonly string CLASSPATH = System.getProperty("java.class.path"); -#endif - - public string tmpdir = null; - - /** If error during parser execution, store stderr here; can't return - * stdout and stderr. This doesn't trap errors from running antlr. - */ - protected string stderrDuringParse; - - public TestContext TestContext - { - get; - set; - } - - [TestCleanup] - public void TestCleanup() - { - if (TestContext.CurrentTestOutcome == UnitTestOutcome.Passed) - { - // remove tmpdir if no error. - eraseTempDir(); - } - } - - [TestInitialize] - public void TestInitialize() - { - // new output dir for each test - string tempTestFolder = GetType().Name + "-" + (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); - string dir = Path.Combine(Path.GetTempPath(), tempTestFolder); - if (Directory.Exists(dir)) - throw new InvalidOperationException(); - - tmpdir = dir; - } - - protected static string WindowsFolder - { - get - { -#if NET40PLUS - return Environment.GetFolderPath(Environment.SpecialFolder.Windows); -#else - string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System); - return Path.GetDirectoryName(systemFolder); -#endif - } - } - - protected static string UserProfile - { - get - { -#if NET40PLUS - return Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); -#else - string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - return Path.GetDirectoryName(documentsFolder); -#endif - } - } - - protected static string PathCombine(params string[] paths) - { -#if NET40PLUS - return Path.Combine(paths); -#else - string result = paths[0]; - for (int i = 1; i < paths.Length; i++) - result = Path.Combine(result, paths[i]); - - return result; -#endif - } - - /** Wow! much faster than compiling outside of VM. Finicky though. - * Had rules called r and modulo. Wouldn't compile til I changed to 'a'. - */ - protected virtual bool compile(params string[] fileNames) - { - DirectoryInfo outputDir = new DirectoryInfo(tmpdir); - try - { - string compiler = PathCombine(WindowsFolder, "Microsoft.NET", "Framework64", "v4.0.30319", "csc.exe"); - - List args = new List(); - args.AddRange(getCompileOptions()); - - bool hasTestClass = false; - foreach (String fileName in fileNames) - { - if (fileName.Equals("Test.cs")) - { - hasTestClass = true; - } - - if (fileName.EndsWith(".dll")) - { - args.Add("/reference:" + fileName); - } - else - { - args.Add(fileName); - } - } - - if (hasTestClass) - { - args.Insert(1, "/target:exe"); - args.Insert(1, "/reference:Parser.dll"); - args.Insert(1, "/out:Test.exe"); - } - else - { - args.Insert(1, "/target:library"); - args.Insert(1, "/out:Parser.dll"); - } - - System.Diagnostics.Process process = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(compiler, '"' + Utils.Join("\" \"", args) + '"') - { - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - RedirectStandardError = true, - WorkingDirectory = tmpdir - }); - - StreamVacuum stdout = new StreamVacuum(process.StandardOutput); - StreamVacuum stderr = new StreamVacuum(process.StandardError); - stdout.start(); - stderr.start(); - process.WaitForExit(); - stdout.join(); - stderr.join(); - if (stdout.ToString().Length > 0) - { - Console.Error.WriteLine("compile stdout from: " + Utils.Join(" ", args)); - Console.Error.WriteLine(stdout); - } - if (stderr.ToString().Length > 0) - { - Console.Error.WriteLine("compile stderr from: " + Utils.Join(" ", args)); - Console.Error.WriteLine(stderr); - } - int ret = process.ExitCode; - return ret == 0; - } - catch (Exception) - { - Console.Error.WriteLine("can't exec compilation"); - //e.printStackTrace(System.err); - return false; - } - } - - public virtual IList getCompileOptions() - { - IList compileOptions = new List(); - compileOptions.Add("/debug"); - compileOptions.Add("/warn:4"); - compileOptions.Add("/nologo"); - compileOptions.Add("/reference:" + typeof(Lexer).Assembly.Location); - return compileOptions; - } - -#if false - public string getBootClassPath() - { - string path = System.getProperty("bootclasspath.java6"); - if (path != null) - { - return path; - } - - path = System.getProperty("java6.home"); - if (path == null) - { - path = System.getenv("JAVA6_HOME"); - } - - if (path != null) - { - return path + File.separatorChar + "lib" + File.separatorChar + "rt.jar"; - } - - return null; - } -#endif - - protected virtual string JavaHome - { - get - { - string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment"; -#if NET40PLUS - using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default).OpenSubKey(javaKey)) -#else - using (var baseKey = Registry.LocalMachine.OpenSubKey(javaKey)) -#endif - { - string currentVersion = baseKey.GetValue("CurrentVersion").ToString(); - using (var homeKey = baseKey.OpenSubKey(currentVersion)) - return homeKey.GetValue("JavaHome").ToString(); - } - } - } - - protected virtual string MavenHome - { - get - { - string mavenHome = Environment.GetEnvironmentVariable("M2_HOME"); - if (!Directory.Exists(mavenHome)) - mavenHome = Path.Combine(UserProfile, ".m2"); - - return mavenHome; - } - } - - protected virtual string GetMavenArtifact(string groupId, string artifactId, string version, string classifier = null) - { - string folder = PathCombine(MavenHome, "repository", groupId.Replace('.', Path.DirectorySeparatorChar), artifactId, version); - string fileNameFormat = string.IsNullOrEmpty(classifier) ? "{0}-{1}.jar" : "{0}-{1}-{2}.jar"; - string fileName = string.Format(fileNameFormat, artifactId, version, classifier); - return Path.Combine(folder, fileName); - } - - /** Return true if all is ok, no errors */ - protected virtual bool antlr(string fileName, string grammarFileName, string grammarStr, bool defaultListener, params string[] extraOptions) - { - mkdir(tmpdir); - writeFile(tmpdir, fileName, grammarStr); - try - { - string compiler = PathCombine(JavaHome, "bin", "java.exe"); - - List classpath = new List(); - classpath.Add(GetMavenArtifact("com.tunnelvisionlabs", "antlr4-csharp", "4.3-SNAPSHOT")); - classpath.Add(GetMavenArtifact("com.tunnelvisionlabs", "antlr4-runtime", "4.3")); - classpath.Add(GetMavenArtifact("com.tunnelvisionlabs", "antlr4", "4.3")); - classpath.Add(GetMavenArtifact("org.antlr", "antlr-runtime", "3.5.2")); - classpath.Add(GetMavenArtifact("org.antlr", "ST4", "4.0.8")); - - List options = new List(); - options.Add("-cp"); - options.Add(Utils.Join(";", classpath)); - options.Add("org.antlr.v4.Tool"); - - options.AddRange(extraOptions); - options.Add("-o"); - options.Add(tmpdir); - options.Add("-lib"); - options.Add(tmpdir); - -#if PORTABLE - options.Add("-Dlanguage=CSharp_v4_5"); -#elif NET45 - options.Add("-Dlanguage=CSharp_v4_5"); -#elif NET40 - options.Add("-Dlanguage=CSharp_v4_0"); -#elif NET35 - options.Add("-Dlanguage=CSharp_v3_5"); -#elif NET30 - options.Add("-Dlanguage=CSharp_v3_0"); -#elif NET20 - options.Add("-Dlanguage=CSharp_v2_0"); -#else -#error Unknown assembly. -#endif - - options.Add(grammarFileName); - - System.Diagnostics.Process process = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(compiler, '"' + Utils.Join("\" \"", options) + '"') - { - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - RedirectStandardError = true, - WorkingDirectory = tmpdir - }); - - StreamVacuum stdout = new StreamVacuum(process.StandardOutput); - StreamVacuum stderr = new StreamVacuum(process.StandardError); - stdout.start(); - stderr.start(); - process.WaitForExit(); - stdout.join(); - stderr.join(); - if (stdout.ToString().Length > 0) - { - Console.Error.WriteLine("compile stdout from: " + Utils.Join(" ", options)); - Console.Error.WriteLine(stdout); - } - if (stderr.ToString().Length > 0) - { - Console.Error.WriteLine("compile stderr from: " + Utils.Join(" ", options)); - Console.Error.WriteLine(stderr); - } - int ret = process.ExitCode; - return ret == 0; - } - catch (Exception) - { - Console.Error.WriteLine("can't exec compilation"); - //e.printStackTrace(System.err); - return false; - } - } - -#if false - protected string execLexer(string grammarFileName, - string grammarStr, - string lexerName, - string input) - { - return execLexer(grammarFileName, grammarStr, lexerName, input, false); - } - - protected string execLexer(string grammarFileName, - string grammarStr, - string lexerName, - string input, - bool showDFA) - { - bool success = rawGenerateAndBuildRecognizer(grammarFileName, - grammarStr, - null, - lexerName); - Assert.IsTrue(success); - writeFile(tmpdir, "input", input); - writeLexerTestFile(lexerName, showDFA); - compile("Test.java"); - string output = execClass("Test"); - if (stderrDuringParse != null && stderrDuringParse.Length > 0) - { - Console.Error.WriteLine(stderrDuringParse); - } - return output; - } - - protected string execParser(string grammarFileName, - string grammarStr, - string parserName, - string lexerName, - string startRuleName, - string input, bool debug) - { - bool success = rawGenerateAndBuildRecognizer(grammarFileName, - grammarStr, - parserName, - lexerName, - "-visitor"); - Assert.IsTrue(success); - writeFile(tmpdir, "input", input); - return rawExecRecognizer(parserName, - lexerName, - startRuleName, - debug); - } -#endif - - /** Return true if all is well */ - protected virtual bool rawGenerateAndBuildRecognizer(string grammarFileName, - string grammarStr, - [Nullable] string parserName, - string lexerName, - params string[] extraOptions) - { - return rawGenerateAndBuildRecognizer(grammarFileName, grammarStr, parserName, lexerName, false, extraOptions); - } - - /** Return true if all is well */ - protected virtual bool rawGenerateAndBuildRecognizer(string grammarFileName, - string grammarStr, - [Nullable] string parserName, - string lexerName, - bool defaultListener, - params string[] extraOptions) - { - bool allIsWell = - antlr(grammarFileName, grammarFileName, grammarStr, defaultListener, extraOptions); - if (!allIsWell) - { - return false; - } - - List files = new List(); - if (lexerName != null) - { - files.Add(lexerName + ".cs"); - } - if (parserName != null) - { - files.Add(parserName + ".cs"); - HashSet optionsSet = new HashSet(extraOptions); - if (!optionsSet.Contains("-no-listener")) - { - files.Add(grammarFileName.Substring(0, grammarFileName.LastIndexOf('.')) + "BaseListener.cs"); - files.Add(grammarFileName.Substring(0, grammarFileName.LastIndexOf('.')) + "Listener.cs"); - } - if (optionsSet.Contains("-visitor")) - { - files.Add(grammarFileName.Substring(0, grammarFileName.LastIndexOf('.')) + "BaseVisitor.cs"); - files.Add(grammarFileName.Substring(0, grammarFileName.LastIndexOf('.')) + "Visitor.cs"); - } - } - allIsWell = compile(files.ToArray()); - return allIsWell; - } - -#if false - protected string rawExecRecognizer(string parserName, - string lexerName, - string parserStartRuleName, - bool debug) - { - this.stderrDuringParse = null; - if (parserName == null) - { - writeLexerTestFile(lexerName, false); - } - else - { - writeTestFile(parserName, - lexerName, - parserStartRuleName, - debug); - } - - compile("Test.java"); - return execClass("Test"); - } - - public string execRecognizer() - { - return execClass("Test"); - } - - public string execClass(string className) - { - if (TEST_IN_SAME_PROCESS) - { - try - { - ClassLoader loader = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader()); - Class mainClass = (Class)loader.loadClass(className); - Method mainMethod = mainClass.getDeclaredMethod("main", typeof(string[])); - PipedInputStream stdoutIn = new PipedInputStream(); - PipedInputStream stderrIn = new PipedInputStream(); - PipedOutputStream stdoutOut = new PipedOutputStream(stdoutIn); - PipedOutputStream stderrOut = new PipedOutputStream(stderrIn); - StreamVacuum stdoutVacuum = new StreamVacuum(stdoutIn); - StreamVacuum stderrVacuum = new StreamVacuum(stderrIn); - - PrintStream originalOut = Console.Out; - System.setOut(new PrintStream(stdoutOut)); - try - { - PrintStream originalErr = System.err; - try - { - System.setErr(new PrintStream(stderrOut)); - stdoutVacuum.start(); - stderrVacuum.start(); - mainMethod.invoke(null, (Object)new string[] { new File(tmpdir, "input").getAbsolutePath() }); - } - finally - { - System.setErr(originalErr); - } - } - finally - { - System.setOut(originalOut); - } - - stdoutOut.close(); - stderrOut.close(); - stdoutVacuum.join(); - stderrVacuum.join(); - string output = stdoutVacuum.tostring(); - if (stderrVacuum.tostring().length() > 0) - { - this.stderrDuringParse = stderrVacuum.tostring(); - Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); - } - return output; - } - catch (MalformedURLException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (InterruptedException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (IllegalAccessException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (IllegalArgumentException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (InvocationTargetException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (NoSuchMethodException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (SecurityException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - catch (ClassNotFoundException ex) - { - LOGGER.log(Level.SEVERE, null, ex); - } - } - - try - { - string[] args = new string[] { - "java", "-classpath", tmpdir+pathSep+CLASSPATH, - className, new File(tmpdir, "input").getAbsolutePath() - }; - //string cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir, "input").getAbsolutePath(); - //Console.WriteLine("execParser: "+cmdLine); - Process process = - Runtime.getRuntime().exec(args, null, new File(tmpdir)); - StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream()); - StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream()); - stdoutVacuum.start(); - stderrVacuum.start(); - process.waitFor(); - stdoutVacuum.join(); - stderrVacuum.join(); - string output = stdoutVacuum.tostring(); - if (stderrVacuum.tostring().length() > 0) - { - this.stderrDuringParse = stderrVacuum.tostring(); - Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); - } - return output; - } - catch (Exception e) - { - Console.Error.WriteLine("can't exec recognizer"); - e.printStackTrace(System.err); - } - return null; - } - - public void testErrors(string[] pairs, bool printTree) - { - for (int i = 0; i < pairs.length; i += 2) - { - string input = pairs[i]; - string expect = pairs[i + 1]; - ErrorQueue equeue = new ErrorQueue(); - Grammar g = null; - try - { - string[] lines = input.split("\n"); - string fileName = getFilenameFromFirstLineOfGrammar(lines[0]); - if (input.startsWith("lexer ")) - { - g = new LexerGrammar(fileName, input, equeue); - } - else - { - g = new Grammar(fileName, input, equeue); - } - } - catch (UnsupportedOperationException ex) - { - } - catch (org.antlr.runtime.RecognitionException re) - { - re.printStackTrace(System.err); - } - string actual = equeue.tostring(g != null ? g.tool : new Tool()); - Console.Error.WriteLine(actual); - string msg = input; - msg = msg.replaceAll("\n", "\\\\n"); - msg = msg.replaceAll("\r", "\\\\r"); - msg = msg.replaceAll("\t", "\\\\t"); - - assertEquals("error in: " + msg, expect, actual); - } - } - - public string getFilenameFromFirstLineOfGrammar(string line) - { - string fileName = ""; - int grIndex = line.lastIndexOf("grammar"); - int semi = line.lastIndexOf(';'); - if (grIndex >= 0 && semi >= 0) - { - int space = line.indexOf(' ', grIndex); - fileName = line.substring(space + 1, semi) + Tool.GRAMMAR_EXTENSION; - } - if (fileName.length() == Tool.GRAMMAR_EXTENSION.length()) - fileName = ""; - return fileName; - } - - // void ambig(IList msgs, int[] expectedAmbigAlts, string expectedAmbigInput) - // throws Exception - // { - // ambig(msgs, 0, expectedAmbigAlts, expectedAmbigInput); - // } - - // void ambig(IList msgs, int i, int[] expectedAmbigAlts, string expectedAmbigInput) - // throws Exception - // { - // IList amsgs = getMessagesOfType(msgs, AmbiguityMessage.class); - // AmbiguityMessage a = (AmbiguityMessage)amsgs.get(i); - // if ( a==null ) assertNull(expectedAmbigAlts); - // else { - // assertEquals(a.conflictingAlts.tostring(), Arrays.tostring(expectedAmbigAlts)); - // } - // assertEquals(expectedAmbigInput, a.input); - // } - - // void unreachable(IList msgs, int[] expectedUnreachableAlts) - // throws Exception - // { - // unreachable(msgs, 0, expectedUnreachableAlts); - // } - - // void unreachable(IList msgs, int i, int[] expectedUnreachableAlts) - // throws Exception - // { - // IList amsgs = getMessagesOfType(msgs, UnreachableAltsMessage.class); - // UnreachableAltsMessage u = (UnreachableAltsMessage)amsgs.get(i); - // if ( u==null ) assertNull(expectedUnreachableAlts); - // else { - // assertEquals(u.conflictingAlts.tostring(), Arrays.tostring(expectedUnreachableAlts)); - // } - // } - - IList getMessagesOfType(IList msgs, Class c) - { - IList filtered = new List(); - foreach (ANTLRMessage m in msgs) - { - if (m.getClass() == c) - filtered.add(m); - } - return filtered; - } - - void checkRuleATN(Grammar g, string ruleName, string expecting) - { - ParserATNFactory f = new ParserATNFactory(g); - ATN atn = f.createATN(); - - DOTGenerator dot = new DOTGenerator(g); - Console.WriteLine(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index])); - - Rule r = g.getRule(ruleName); - ATNState startState = atn.ruleToStartState[r.index]; - ATNPrinter serializer = new ATNPrinter(g, startState); - string result = serializer.asstring(); - - //System.out.print(result); - assertEquals(expecting, result); - } - - public void testActions(string templates, string actionName, string action, string expected) - { - int lp = templates.indexOf('('); - string name = templates.substring(0, lp); - STGroup group = new STGroupstring(templates); - ST st = group.getInstanceOf(name); - st.add(actionName, action); - string grammar = st.render(); - ErrorQueue equeue = new ErrorQueue(); - Grammar g = new Grammar(grammar); - if (g.ast != null && !g.ast.hasErrors) - { - SemanticPipeline sem = new SemanticPipeline(g); - sem.process(); - - ATNFactory factory = new ParserATNFactory(g); - if (g.isLexer()) - factory = new LexerATNFactory((LexerGrammar)g); - g.atn = factory.createATN(); - - CodeGenerator gen = new CodeGenerator(g); - ST outputFileST = gen.generateParser(); - string output = outputFileST.render(); - //Console.WriteLine(output); - string b = "#" + actionName + "#"; - int start = output.indexOf(b); - string e = "#end-" + actionName + "#"; - int end = output.indexOf(e); - string snippet = output.substring(start + b.length(), end); - assertEquals(expected, snippet); - } - if (equeue.Count > 0) - { - Console.Error.WriteLine(equeue.tostring(g.tool)); - } - } -#endif - - public class StreamVacuum - { - private readonly StringBuilder buf = new StringBuilder(); - private readonly TextReader @in; - private Thread sucker; - - public StreamVacuum(TextReader @in) - { - this.@in = @in; - } - - public void start() - { - sucker = new Thread(run); - sucker.Start(); - } - - public void run() - { - try - { - string line = @in.ReadLine(); - while (line != null) - { - buf.AppendLine(line); - line = @in.ReadLine(); - } - } - catch (IOException) - { - Console.Error.WriteLine("can't read output from process"); - } - } - - /** wait for the thread to finish */ - public void join() /*throws InterruptedException*/ { - sucker.Join(); - } - - public override string ToString() - { - return buf.ToString(); - } - } - -#if false - protected void checkGrammarSemanticsError(ErrorQueue equeue, - GrammarSemanticsMessage expectedMessage) - { - ANTLRMessage foundMsg = null; - for (int i = 0; i < equeue.errors.Count; i++) - { - ANTLRMessage m = equeue.errors.get(i); - if (m.getErrorType() == expectedMessage.getErrorType()) - { - foundMsg = m; - } - } - assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg); - Assert.IsTrue("error is not a GrammarSemanticsMessage", - foundMsg is GrammarSemanticsMessage); - assertEquals(Arrays.tostring(expectedMessage.getArgs()), Arrays.tostring(foundMsg.getArgs())); - if (equeue.Count != 1) - { - Console.Error.WriteLine(equeue); - } - } - - protected void checkGrammarSemanticsWarning(ErrorQueue equeue, - GrammarSemanticsMessage expectedMessage) - { - ANTLRMessage foundMsg = null; - for (int i = 0; i < equeue.warnings.Count; i++) - { - ANTLRMessage m = equeue.warnings.get(i); - if (m.getErrorType() == expectedMessage.getErrorType()) - { - foundMsg = m; - } - } - assertNotNull("no error; " + expectedMessage.getErrorType() + " expected", foundMsg); - Assert.IsTrue("error is not a GrammarSemanticsMessage", - foundMsg is GrammarSemanticsMessage); - assertEquals(Arrays.tostring(expectedMessage.getArgs()), Arrays.tostring(foundMsg.getArgs())); - if (equeue.Count != 1) - { - Console.Error.WriteLine(equeue); - } - } - - protected void checkError(ErrorQueue equeue, - ANTLRMessage expectedMessage) - { - //Console.WriteLine("errors="+equeue); - ANTLRMessage foundMsg = null; - for (int i = 0; i < equeue.errors.Count; i++) - { - ANTLRMessage m = equeue.errors.get(i); - if (m.getErrorType() == expectedMessage.getErrorType()) - { - foundMsg = m; - } - } - Assert.IsTrue("no error; " + expectedMessage.getErrorType() + " expected", !equeue.errors.isEmpty()); - Assert.IsTrue("too many errors; " + equeue.errors, equeue.errors.Count <= 1); - assertNotNull("couldn't find expected error: " + expectedMessage.getErrorType(), foundMsg); - /* - Assert.IsTrue("error is not a GrammarSemanticsMessage", - foundMsg is GrammarSemanticsMessage); - */ - assertArrayEquals(expectedMessage.getArgs(), foundMsg.getArgs()); - } - - public class FilteringTokenStream : CommonTokenStream - { - public FilteringTokenStream(TokenSource src) - { - super(src); - } - Set hide = new HashSet(); - protected override bool sync(int i) - { - if (!super.sync(i)) - { - return false; - } - - Token t = get(i); - if (hide.contains(t.getType())) - { - ((WritableToken)t).setChannel(Token.HIDDEN_CHANNEL); - } - - return true; - } - public void setTokenTypeChannel(int ttype, int channel) - { - hide.add(ttype); - } - } -#endif - - public static void writeFile(string dir, string fileName, string content) - { - File.WriteAllText(Path.Combine(dir, fileName), content); - } - - protected void mkdir(string dir) - { - Directory.CreateDirectory(dir); - } - -#if false - protected void writeTestFile(string parserName, - string lexerName, - string parserStartRuleName, - bool debug) - { - ST outputFileST = new ST( - "import org.antlr.v4.runtime.*;\n" + - "import org.antlr.v4.runtime.tree.*;\n" + - "\n" + - "public class Test {\n" + - " public static void main(string[] args) throws Exception {\n" + - " CharStream input = new ANTLRFileStream(args[0]);\n" + - " lex = new (input);\n" + - " CommonTokenStream tokens = new CommonTokenStream(lex);\n" + - " \n" + - " parser.setBuildParseTree(true);\n" + - " parser.getInterpreter().reportAmbiguities = true;\n" + - " ParserRuleContext tree = parser.();\n" + - " ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n" + - " }\n" + - "\n" + - " static class TreeShapeListener implements ParseTreeListener {\n" + - " @Override public void visitTerminal(TerminalNode node) { }\n" + - " @Override public void visitErrorNode(ErrorNode node) { }\n" + - " @Override public void exitEveryRule(ParserRuleContext ctx) { }\n" + - "\n" + - " @Override\n" + - " public void enterEveryRule(ParserRuleContext ctx) {\n" + - " for (int i = 0; i \\< ctx.getChildCount(); i++) {\n" + - " ParseTree parent = ctx.getChild(i).getParent();\n" + - " if (!(parent is RuleNode) || ((RuleNode)parent).getRuleContext() != ctx) {\n" + - " throw new IllegalStateException(\"Invalid parse tree shape detected.\");\n" + - " }\n" + - " }\n" + - " }\n" + - " }\n" + - "}" - ); - ST createParserST = new ST(" parser = new (tokens);\n"); - if (debug) - { - createParserST = - new ST( - " parser = new (tokens);\n" + - " parser.addErrorListener(new DiagnosticErrorListener());\n"); - } - outputFileST.add("createParser", createParserST); - outputFileST.add("parserName", parserName); - outputFileST.add("lexerName", lexerName); - outputFileST.add("parserStartRuleName", parserStartRuleName); - writeFile(tmpdir, "Test.java", outputFileST.render()); - } - - protected void writeLexerTestFile(string lexerName, bool showDFA) - { - ST outputFileST = new ST( - "import org.antlr.v4.runtime.*;\n" + - "\n" + - "public class Test {\n" + - " public static void main(string[] args) throws Exception {\n" + - " CharStream input = new ANTLRFileStream(args[0]);\n" + - " lex = new (input);\n" + - " CommonTokenStream tokens = new CommonTokenStream(lex);\n" + - " tokens.fill();\n" + - " for (Object t : tokens.getTokens()) Console.WriteLine(t);\n" + - (showDFA ? "System.out.print(lex.getInterpreter().getDFA(Lexer.DEFAULT_MODE).toLexerstring());\n" : "") + - " }\n" + - "}" - ); - - outputFileST.add("lexerName", lexerName); - writeFile(tmpdir, "Test.java", outputFileST.render()); - } - - public void writeRecognizerAndCompile(string parserName, string lexerName, - string parserStartRuleName, - bool debug) - { - if (parserName == null) - { - writeLexerTestFile(lexerName, debug); - } - else - { - writeTestFile(parserName, - lexerName, - parserStartRuleName, - debug); - } - - compile("Test.java"); - } - - - protected void eraseFiles(string filesEndingWith) - { - File tmpdirF = new File(tmpdir); - string[] files = tmpdirF.list(); - for (int i = 0; files != null && i < files.length; i++) - { - if (files[i].endsWith(filesEndingWith)) - { - new File(tmpdir + "/" + files[i]).delete(); - } - } - } - - protected void eraseFiles() - { - if (tmpdir == null) - { - return; - } - - File tmpdirF = new File(tmpdir); - string[] files = tmpdirF.list(); - for (int i = 0; files != null && i < files.length; i++) - { - new File(tmpdir + "/" + files[i]).delete(); - } - } -#endif - - protected virtual void eraseTempDir() - { - if (!Path.GetTempPath().Equals(Path.GetDirectoryName(tmpdir) + Path.DirectorySeparatorChar)) - { - throw new InvalidOperationException(); - } - - Directory.Delete(tmpdir, true); - } - -#if false - public string getFirstLineOfException() - { - if (this.stderrDuringParse == null) - { - return null; - } - string[] lines = this.stderrDuringParse.split("\n"); - string prefix = "Exception in thread \"main\" "; - return lines[0].substring(prefix.length(), lines[0].length()); - } - - /** - * When looking at a result set that consists of a Map/HashTable - * we cannot rely on the output order, as the hashing algorithm or other aspects - * of the implementation may be different on differnt JDKs or platforms. Hence - * we take the Map, convert the keys to a IList, sort them and stringify the Map, which is a - * bit of a hack, but guarantees that we get the same order on all systems. We assume that - * the keys are strings. - * - * @param m The Map that contains keys we wish to return in sorted order - * @return A string that represents all the keys in sorted order. - */ - public string sortMapTostring(Map m) - { - // Pass in crap, and get nothing back - // - if (m == null) - { - return null; - } - - Console.WriteLine("Map tostring looks like: " + m.tostring()); - - // Sort the keys in the Map - // - TreeMap nset = new TreeMap(m); - - Console.WriteLine("Tree map looks like: " + nset.tostring()); - return nset.tostring(); - } - - public IList realElements(IList elements) - { - return elements.subList(Token.MIN_USER_TOKEN_TYPE, elements.Count); - } - - public void assertNotNullOrEmpty(string message, string text) - { - assertNotNull(message, text); - assertFalse(message, text.isEmpty()); - } - - public void assertNotNullOrEmpty(string text) - { - assertNotNull(text); - assertFalse(text.isEmpty()); - } - - public class IntTokenStream : TokenStream - { - IntegerList types; - int p = 0; - public IntTokenStream(IntegerList types) - { - this.types = types; - } - - public override void consume() - { - p++; - } - - public override int LA(int i) - { - return LT(i).getType(); - } - - public override int mark() - { - return index(); - } - - public override int index() - { - return p; - } - - public override void release(int marker) - { - seek(marker); - } - - public override void seek(int index) - { - p = index; - } - - public override int size() - { - return types.Count; - } - - public override string getSourceName() - { - return null; - } - - public override Token LT(int i) - { - CommonToken t; - int rawIndex = p + i - 1; - if (rawIndex >= types.Count) - t = new CommonToken(Token.EOF); - else - t = new CommonToken(types.get(rawIndex)); - t.setTokenIndex(rawIndex); - return t; - } - - public override Token get(int i) - { - return new org.antlr.v4.runtime.CommonToken(types.get(i)); - } - - public override TokenSource getTokenSource() - { - return null; - } - - [return: NotNull] - public override string getText() - { - throw new UnsupportedOperationException("can't give strings"); - } - - [return: NotNull] - public override string getText(Interval interval) - { - throw new UnsupportedOperationException("can't give strings"); - } - - [return: NotNull] - public override string getText(RuleContext ctx) - { - throw new UnsupportedOperationException("can't give strings"); - } - - [return: NotNull] - public override string getText(Token start, Token stop) - { - throw new UnsupportedOperationException("can't give strings"); - } - } - - /** Sort a list */ - public IList sort(IList data) - { - IList dup = new List(); - dup.addAll(data); - Collections.sort(dup); - return dup; - } - - /** Return map sorted by key */ - public LinkedHashMap sort(Map data) - { - LinkedHashMap dup = new LinkedHashMap(); - IList keys = new List(); - keys.addAll(data.keySet()); - Collections.sort(keys); - foreach (K k in keys) - { - dup.put(k, data.get(k)); - } - return dup; - } -#endif - } -} diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Java-LR.g4 b/runtime/CSharp/Antlr4.Runtime.Test/Java-LR.g4 deleted file mode 100644 index 9c088a800..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Java-LR.g4 +++ /dev/null @@ -1,1293 +0,0 @@ -/* - [The "BSD licence"] - Copyright (c) 2007-2008 Terence Parr - 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. -*/ -/** A Java 1.5 grammar for ANTLR v3 derived from the spec - * - * This is a very close representation of the spec; the changes - * are comestic (remove left recursion) and also fixes (the spec - * isn't exactly perfect). I have run this on the 1.4.2 source - * and some nasty looking enums from 1.5, but have not really - * tested for 1.5 compatibility. - * - * I built this with: java -Xmx100M org.antlr.Tool java.g - * and got two errors that are ok (for now): - * java.g:691:9: Decision can match input such as - * "'0'..'9'{'E', 'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}" - * using multiple alternatives: 3, 4 - * As a result, alternative(s) 4 were disabled for that input - * java.g:734:35: Decision can match input such as "{'$', 'A'..'Z', - * '_', 'a'..'z', '\u00C0'..'\u00D6', '\u00D8'..'\u00F6', - * '\u00F8'..'\u1FFF', '\u3040'..'\u318F', '\u3300'..'\u337F', - * '\u3400'..'\u3D2D', '\u4E00'..'\u9FFF', '\uF900'..'\uFAFF'}" - * using multiple alternatives: 1, 2 - * As a result, alternative(s) 2 were disabled for that input - * - * You can turn enum on/off as a keyword :) - * - * Version 1.0 -- initial release July 5, 2006 (requires 3.0b2 or higher) - * - * Primary author: Terence Parr, July 2006 - * - * Version 1.0.1 -- corrections by Koen Vanderkimpen & Marko van Dooren, - * October 25, 2006; - * fixed normalInterfaceDeclaration: now uses typeParameters instead - * of typeParameter (according to JLS, 3rd edition) - * fixed castExpression: no longer allows expression next to type - * (according to semantics in JLS, in contrast with syntax in JLS) - * - * Version 1.0.2 -- Terence Parr, Nov 27, 2006 - * java spec I built this from had some bizarre for-loop control. - * Looked weird and so I looked elsewhere...Yep, it's messed up. - * simplified. - * - * Version 1.0.3 -- Chris Hogue, Feb 26, 2007 - * Factored out an annotationName rule and used it in the annotation rule. - * Not sure why, but typeName wasn't recognizing references to inner - * annotations (e.g. @InterfaceName.InnerAnnotation()) - * Factored out the elementValue section of an annotation reference. Created - * elementValuePair and elementValuePairs rules, then used them in the - * annotation rule. Allows it to recognize annotation references with - * multiple, comma separated attributes. - * Updated elementValueArrayInitializer so that it allows multiple elements. - * (It was only allowing 0 or 1 element). - * Updated localVariableDeclaration to allow annotations. Interestingly the JLS - * doesn't appear to indicate this is legal, but it does work as of at least - * JDK 1.5.0_06. - * Moved the Identifier portion of annotationTypeElementRest to annotationMethodRest. - * Because annotationConstantRest already references variableDeclarator which - * has the Identifier portion in it, the parser would fail on constants in - * annotation definitions because it expected two identifiers. - * Added optional trailing ';' to the alternatives in annotationTypeElementRest. - * Wouldn't handle an inner interface that has a trailing ';'. - * Swapped the expression and type rule reference order in castExpression to - * make it check for genericized casts first. It was failing to recognize a - * statement like "Class TYPE = (Class)...;" because it was seeing - * 'Class'. - * Changed createdName to use typeArguments instead of nonWildcardTypeArguments. - * Changed the 'this' alternative in primary to allow 'identifierSuffix' rather than - * just 'arguments'. The case it couldn't handle was a call to an explicit - * generic method invocation (e.g. this.doSomething()). Using identifierSuffix - * may be overly aggressive--perhaps should create a more constrained thisSuffix rule? - * - * Version 1.0.4 -- Hiroaki Nakamura, May 3, 2007 - * - * Fixed formalParameterDecls, localVariableDeclaration, forInit, - * and forVarControl to use variableModifier* not 'final'? (annotation)? - * - * Version 1.0.5 -- Terence, June 21, 2007 - * --a[i].foo didn't work. Fixed unaryExpression - * - * Version 1.0.6 -- John Ridgway, March 17, 2008 - * Made "assert" a switchable keyword like "enum". - * Fixed compilationUnit to disallow "annotation importDeclaration ...". - * Changed "Identifier ('.' Identifier)*" to "qualifiedName" in more - * places. - * Changed modifier* and/or variableModifier* to classOrInterfaceModifiers, - * modifiers or variableModifiers, as appropriate. - * Renamed "bound" to "typeBound" to better match language in the JLS. - * Added "memberDeclaration" which rewrites to methodDeclaration or - * fieldDeclaration and pulled type into memberDeclaration. So we parse - * type and then move on to decide whether we're dealing with a field - * or a method. - * Modified "constructorDeclaration" to use "constructorBody" instead of - * "methodBody". constructorBody starts with explicitConstructorInvocation, - * then goes on to blockStatement*. Pulling explicitConstructorInvocation - * out of expressions allowed me to simplify "primary". - * Changed variableDeclarator to simplify it. - * Changed type to use classOrInterfaceType, thus simplifying it; of course - * I then had to add classOrInterfaceType, but it is used in several - * places. - * Fixed annotations, old version allowed "@X(y,z)", which is illegal. - * Added optional comma to end of "elementValueArrayInitializer"; as per JLS. - * Changed annotationTypeElementRest to use normalClassDeclaration and - * normalInterfaceDeclaration rather than classDeclaration and - * interfaceDeclaration, thus getting rid of a couple of grammar ambiguities. - * Split localVariableDeclaration into localVariableDeclarationStatement - * (includes the terminating semi-colon) and localVariableDeclaration. - * This allowed me to use localVariableDeclaration in "forInit" clauses, - * simplifying them. - * Changed switchBlockStatementGroup to use multiple labels. This adds an - * ambiguity, but if one uses appropriately greedy parsing it yields the - * parse that is closest to the meaning of the switch statement. - * Renamed "forVarControl" to "enhancedForControl" -- JLS language. - * Added semantic predicates to test for shift operations rather than other - * things. Thus, for instance, the string "< <" will never be treated - * as a left-shift operator. - * In "creator" we rule out "nonWildcardTypeArguments" on arrayCreation, - * which are illegal. - * Moved "nonWildcardTypeArguments into innerCreator. - * Removed 'super' superSuffix from explicitGenericInvocation, since that - * is only used in explicitConstructorInvocation at the beginning of a - * constructorBody. (This is part of the simplification of expressions - * mentioned earlier.) - * Simplified primary (got rid of those things that are only used in - * explicitConstructorInvocation). - * Lexer -- removed "Exponent?" from FloatingPointLiteral choice 4, since it - * led to an ambiguity. - * - * This grammar successfully parses every .java file in the JDK 1.5 source - * tree (excluding those whose file names include '-', which are not - * valid Java compilation units). - * - * June 26, 2008 - * - * conditionalExpression had wrong precedence x?y:z. - * - * February 26, 2011 - * added left-recursive expression rule - * - * Known remaining problems: - * "Letter" and "JavaIDDigit" are wrong. The actual specification of - * "Letter" should be "a character for which the method - * Character.isJavaIdentifierStart(int) returns true." A "Java - * letter-or-digit is a character for which the method - * Character.isJavaIdentifierPart(int) returns true." - */ -grammar Java; - -@lexer::members { - -private static bool IsJavaIdentifierCharacter(char c, bool start) -{ - switch (char.GetUnicodeCategory(c)) - { - case System.Globalization.UnicodeCategory.UppercaseLetter: - case System.Globalization.UnicodeCategory.LowercaseLetter: - case System.Globalization.UnicodeCategory.TitlecaseLetter: - case System.Globalization.UnicodeCategory.ModifierLetter: - case System.Globalization.UnicodeCategory.OtherLetter: - // isLetter returns true - return true; - - case System.Globalization.UnicodeCategory.LetterNumber: - // getType returns LETTER_NUMBER - return true; - - case System.Globalization.UnicodeCategory.CurrencySymbol: - // a currency symbol (such as "$") - return true; - - case System.Globalization.UnicodeCategory.ConnectorPunctuation: - // a connecting punctuation character (such as "_") - return true; - - case System.Globalization.UnicodeCategory.DecimalDigitNumber: - // it is a digit - return !start; - - case System.Globalization.UnicodeCategory.SpacingCombiningMark: - // it is a combining mark - return !start; - - case System.Globalization.UnicodeCategory.NonSpacingMark: - // it is a non-spacing mark - return !start; - - default: - return false; - } -} - -} - -// starting point for parsing a java file -/* The annotations are separated out to make parsing faster, but must be associated with - a packageDeclaration or a typeDeclaration (and not an empty one). */ -compilationUnit - : annotations - ( packageDeclaration importDeclaration* typeDeclaration* - | classOrInterfaceDeclaration typeDeclaration* - ) - EOF - | packageDeclaration? importDeclaration* typeDeclaration* - EOF - ; - -packageDeclaration - : 'package' qualifiedName ';' - ; - -importDeclaration - : 'import' 'static'? qualifiedName ('.' '*')? ';' - ; - -typeDeclaration - : classOrInterfaceDeclaration - | ';' - ; - -classOrInterfaceDeclaration - : classOrInterfaceModifiers (classDeclaration | interfaceDeclaration) - ; - -classOrInterfaceModifiers - : classOrInterfaceModifier* - ; - -classOrInterfaceModifier - : annotation // class or interface - | ( 'public' // class or interface - | 'protected' // class or interface - | 'private' // class or interface - | 'abstract' // class or interface - | 'static' // class or interface - | 'final' // class only -- does not apply to interfaces - | 'strictfp' // class or interface - ) - ; - -modifiers - : modifier* - ; - -classDeclaration - : normalClassDeclaration - | enumDeclaration - ; - -normalClassDeclaration - : 'class' Identifier typeParameters? - ('extends' type)? - ('implements' typeList)? - classBody - ; - -typeParameters - : '<' typeParameter (',' typeParameter)* '>' - ; - -typeParameter - : Identifier ('extends' typeBound)? - ; - -typeBound - : type ('&' type)* - ; - -enumDeclaration - : ENUM Identifier ('implements' typeList)? enumBody - ; - -enumBody - : '{' enumConstants? ','? enumBodyDeclarations? '}' - ; - -enumConstants - : enumConstant (',' enumConstant)* - ; - -enumConstant - : annotations? Identifier arguments? classBody? - ; - -enumBodyDeclarations - : ';' (classBodyDeclaration)* - ; - -interfaceDeclaration - : normalInterfaceDeclaration - | annotationTypeDeclaration - ; - -normalInterfaceDeclaration - : 'interface' Identifier typeParameters? ('extends' typeList)? interfaceBody - ; - -typeList - : type (',' type)* - ; - -classBody - : '{' classBodyDeclaration* '}' - ; - -interfaceBody - : '{' interfaceBodyDeclaration* '}' - ; - -classBodyDeclaration - : ';' - | 'static'? block - | modifiers memberDecl - ; - -memberDecl - : genericMethodOrConstructorDecl - | memberDeclaration - | 'void' Identifier voidMethodDeclaratorRest - | Identifier constructorDeclaratorRest - | interfaceDeclaration - | classDeclaration - ; - -memberDeclaration - : type (methodDeclaration | fieldDeclaration) - ; - -genericMethodOrConstructorDecl - : typeParameters genericMethodOrConstructorRest - ; - -genericMethodOrConstructorRest - : (type | 'void') Identifier methodDeclaratorRest - | Identifier constructorDeclaratorRest - ; - -methodDeclaration - : Identifier methodDeclaratorRest - ; - -fieldDeclaration - : variableDeclarators ';' - ; - -interfaceBodyDeclaration - : modifiers interfaceMemberDecl - | ';' - ; - -interfaceMemberDecl - : interfaceMethodOrFieldDecl - | interfaceGenericMethodDecl - | 'void' Identifier voidInterfaceMethodDeclaratorRest - | interfaceDeclaration - | classDeclaration - ; - -interfaceMethodOrFieldDecl - : type Identifier interfaceMethodOrFieldRest - ; - -interfaceMethodOrFieldRest - : constantDeclaratorsRest ';' - | interfaceMethodDeclaratorRest - ; - -methodDeclaratorRest - : formalParameters ('[' ']')* - ('throws' qualifiedNameList)? - ( methodBody - | ';' - ) - ; - -voidMethodDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? - ( methodBody - | ';' - ) - ; - -interfaceMethodDeclaratorRest - : formalParameters ('[' ']')* ('throws' qualifiedNameList)? ';' - ; - -interfaceGenericMethodDecl - : typeParameters (type | 'void') Identifier - interfaceMethodDeclaratorRest - ; - -voidInterfaceMethodDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? ';' - ; - -constructorDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? constructorBody - ; - -constantDeclarator - : Identifier constantDeclaratorRest - ; - -variableDeclarators - : variableDeclarator (',' variableDeclarator)* - ; - -variableDeclarator - : variableDeclaratorId ('=' variableInitializer)? - ; - -constantDeclaratorsRest - : constantDeclaratorRest (',' constantDeclarator)* - ; - -constantDeclaratorRest - : ('[' ']')* '=' variableInitializer - ; - -variableDeclaratorId - : Identifier ('[' ']')* - ; - -variableInitializer - : arrayInitializer - | expression - ; - -arrayInitializer - : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}' - ; - -modifier - : annotation - | ( 'public' - | 'protected' - | 'private' - | 'static' - | 'abstract' - | 'final' - | 'native' - | 'synchronized' - | 'transient' - | 'volatile' - | 'strictfp' - ) - ; - -packageOrTypeName - : qualifiedName - ; - -enumConstantName - : Identifier - ; - -typeName - : qualifiedName - ; - -type - : classOrInterfaceType ('[' ']')* - | primitiveType ('[' ']')* - ; - -classOrInterfaceType - : Identifier typeArguments? ('.' Identifier typeArguments? )* - ; - -primitiveType - : 'boolean' - | 'char' - | 'byte' - | 'short' - | 'int' - | 'long' - | 'float' - | 'double' - ; - -variableModifier - : 'final' - | annotation - ; - -typeArguments - : '<' typeArgument (',' typeArgument)* '>' - ; - -typeArgument - : type - | '?' (('extends' | 'super') type)? - ; - -qualifiedNameList - : qualifiedName (',' qualifiedName)* - ; - -formalParameters - : '(' formalParameterDecls? ')' - ; - -formalParameterDecls - : variableModifiers type formalParameterDeclsRest - ; - -formalParameterDeclsRest - : variableDeclaratorId (',' formalParameterDecls)? - | '...' variableDeclaratorId - ; - -methodBody - : block - ; - -constructorBody - : block - ; - -qualifiedName - : Identifier ('.' Identifier)* - ; - -literal - : IntegerLiteral - | FloatingPointLiteral - | CharacterLiteral - | StringLiteral - | BooleanLiteral - | 'null' - ; - -// ANNOTATIONS - -annotations - : annotation+ - ; - -annotation - : '@' annotationName ( '(' ( elementValuePairs | elementValue )? ')' )? - ; - -annotationName - : Identifier ('.' Identifier)* - ; - -elementValuePairs - : elementValuePair (',' elementValuePair)* - ; - -elementValuePair - : Identifier '=' elementValue - ; - -elementValue - : expression - | annotation - | elementValueArrayInitializer - ; - -elementValueArrayInitializer - : '{' (elementValue (',' elementValue)*)? (',')? '}' - ; - -annotationTypeDeclaration - : '@' 'interface' Identifier annotationTypeBody - ; - -annotationTypeBody - : '{' (annotationTypeElementDeclaration)* '}' - ; - -annotationTypeElementDeclaration - : modifiers annotationTypeElementRest - | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler - ; - -annotationTypeElementRest - : type annotationMethodOrConstantRest ';' - | normalClassDeclaration ';'? - | normalInterfaceDeclaration ';'? - | enumDeclaration ';'? - | annotationTypeDeclaration ';'? - ; - -annotationMethodOrConstantRest - : annotationMethodRest - | annotationConstantRest - ; - -annotationMethodRest - : Identifier '(' ')' defaultValue? - ; - -annotationConstantRest - : variableDeclarators - ; - -defaultValue - : 'default' elementValue - ; - -// STATEMENTS / BLOCKS - -block - : '{' blockStatement* '}' - ; - -blockStatement - : localVariableDeclarationStatement - | classOrInterfaceDeclaration - | statement - ; - -localVariableDeclarationStatement - : localVariableDeclaration ';' - ; - -localVariableDeclaration - : variableModifiers type variableDeclarators - ; - -variableModifiers - : variableModifier* - ; - -statement - : block - | ASSERT expression (':' expression)? ';' - | 'if' parExpression statement ('else' statement)? - | 'for' '(' forControl ')' statement - | 'while' parExpression statement - | 'do' statement 'while' parExpression ';' - | 'try' block (catches finallyBlock? | finallyBlock) - | 'try' resourceSpecification block catches? finallyBlock? - | 'switch' parExpression '{' switchBlockStatementGroups '}' - | 'synchronized' parExpression block - | 'return' expression? ';' - | 'throw' expression ';' - | 'break' Identifier? ';' - | 'continue' Identifier? ';' - | ';' - | statementExpression ';' - | Identifier ':' statement - ; - -catches - : catchClause+ - ; - -catchClause - : 'catch' '(' variableModifiers catchType Identifier ')' block - ; - -catchType - : qualifiedName ('|' qualifiedName)* - ; - -finallyBlock - : 'finally' block - ; - -resourceSpecification - : '(' resources ';'? ')' - ; - -resources - : resource (';' resource)* - ; - -resource - : variableModifiers classOrInterfaceType variableDeclaratorId '=' expression - ; - -formalParameter - : variableModifiers type variableDeclaratorId - ; - -switchBlockStatementGroups - : (switchBlockStatementGroup)* - ; - -/* The change here (switchLabel -> switchLabel+) technically makes this grammar - ambiguous; but with appropriately greedy parsing it yields the most - appropriate AST, one in which each group, except possibly the last one, has - labels and statements. */ -switchBlockStatementGroup - : switchLabel+ blockStatement* - ; - -switchLabel - : 'case' constantExpression ':' - | 'case' enumConstantName ':' - | 'default' ':' - ; - -forControl - : enhancedForControl - | forInit? ';' expression? ';' forUpdate? - ; - -forInit - : localVariableDeclaration - | expressionList - ; - -enhancedForControl - : variableModifiers type Identifier ':' expression - ; - -forUpdate - : expressionList - ; - -// EXPRESSIONS - -parExpression - : '(' expression ')' - ; - -expressionList - : expression (',' expression)* - ; - -statementExpression - : expression - ; - -constantExpression - : expression - ; - -expression - : primary - | expression '.' Identifier - | expression '.' 'this' - | expression '.' 'new' nonWildcardTypeArguments? innerCreator - | expression '.' 'super' superSuffix - | expression '.' explicitGenericInvocation - | 'new' creator - | expression '[' expression ']' - | '(' type ')' expression - | expression ('++' | '--') - | expression '(' expressionList? ')' - | ('+'|'-'|'++'|'--') expression - | ('~'|'!') expression - | expression ('*'|'/'|'%') expression - | expression ('+'|'-') expression - | expression ('<' '<' | '>' '>' '>' | '>' '>') expression - | expression ('<=' | '>=' | '>' | '<') expression - | expression 'instanceof' type - | expression ('==' | '!=') expression - | expression '&' expression - | expression '^' expression - | expression '|' expression - | expression '&&' expression - | expression '||' expression - | expression '?' expression ':' expression - | expression - ( '=' - | '+=' - | '-=' - | '*=' - | '/=' - | '&=' - | '|=' - | '^=' - | '>>=' - | '>>>=' - | '<<=' - | '%=' - ) - expression - ; - -primary - : '(' expression ')' - | 'this' - | 'super' - | literal - | Identifier - | type '.' 'class' - | 'void' '.' 'class' - | nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments) - ; - -creator - : nonWildcardTypeArguments createdName classCreatorRest - | createdName (arrayCreatorRest | classCreatorRest) - ; - -createdName - : Identifier typeArgumentsOrDiamond? ('.' Identifier typeArgumentsOrDiamond?)* - | primitiveType - ; - -innerCreator - : Identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest - ; - -arrayCreatorRest - : '[' - ( ']' ('[' ']')* arrayInitializer - | expression ']' ('[' expression ']')* ('[' ']')* - ) - ; - -classCreatorRest - : arguments classBody? - ; - -explicitGenericInvocation - : nonWildcardTypeArguments explicitGenericInvocationSuffix - ; - -nonWildcardTypeArguments - : '<' typeList '>' - ; - -typeArgumentsOrDiamond - : '<' '>' - | typeArguments - ; - -nonWildcardTypeArgumentsOrDiamond - : '<' '>' - | nonWildcardTypeArguments - ; - -superSuffix - : arguments - | '.' Identifier arguments? - ; - -explicitGenericInvocationSuffix - : 'super' superSuffix - | Identifier arguments - ; - -arguments - : '(' expressionList? ')' - ; - -// LEXER - -// §3.9 Keywords - -ABSTRACT : 'abstract'; -ASSERT : 'assert'; -BOOLEAN : 'boolean'; -BREAK : 'break'; -BYTE : 'byte'; -CASE : 'case'; -CATCH : 'catch'; -CHAR : 'char'; -CLASS : 'class'; -CONST : 'const'; -CONTINUE : 'continue'; -DEFAULT : 'default'; -DO : 'do'; -DOUBLE : 'double'; -ELSE : 'else'; -ENUM : 'enum'; -EXTENDS : 'extends'; -FINAL : 'final'; -FINALLY : 'finally'; -FLOAT : 'float'; -FOR : 'for'; -IF : 'if'; -GOTO : 'goto'; -IMPLEMENTS : 'implements'; -IMPORT : 'import'; -INSTANCEOF : 'instanceof'; -INT : 'int'; -INTERFACE : 'interface'; -LONG : 'long'; -NATIVE : 'native'; -NEW : 'new'; -PACKAGE : 'package'; -PRIVATE : 'private'; -PROTECTED : 'protected'; -PUBLIC : 'public'; -RETURN : 'return'; -SHORT : 'short'; -STATIC : 'static'; -STRICTFP : 'strictfp'; -SUPER : 'super'; -SWITCH : 'switch'; -SYNCHRONIZED : 'synchronized'; -THIS : 'this'; -THROW : 'throw'; -THROWS : 'throws'; -TRANSIENT : 'transient'; -TRY : 'try'; -VOID : 'void'; -VOLATILE : 'volatile'; -WHILE : 'while'; - -// §3.10.1 Integer Literals - -IntegerLiteral - : DecimalIntegerLiteral - | HexIntegerLiteral - | OctalIntegerLiteral - | BinaryIntegerLiteral - ; - -fragment -DecimalIntegerLiteral - : DecimalNumeral IntegerTypeSuffix? - ; - -fragment -HexIntegerLiteral - : HexNumeral IntegerTypeSuffix? - ; - -fragment -OctalIntegerLiteral - : OctalNumeral IntegerTypeSuffix? - ; - -fragment -BinaryIntegerLiteral - : BinaryNumeral IntegerTypeSuffix? - ; - -fragment -IntegerTypeSuffix - : [lL] - ; - -fragment -DecimalNumeral - : '0' - | NonZeroDigit (Digits? | Underscores Digits) - ; - -fragment -Digits - : Digit (DigitsAndUnderscores? Digit)? - ; - -fragment -Digit - : '0' - | NonZeroDigit - ; - -fragment -NonZeroDigit - : [1-9] - ; - -fragment -DigitsAndUnderscores - : DigitOrUnderscore+ - ; - -fragment -DigitOrUnderscore - : Digit - | '_' - ; - -fragment -Underscores - : '_'+ - ; - -fragment -HexNumeral - : '0' [xX] HexDigits - ; - -fragment -HexDigits - : HexDigit (HexDigitsAndUnderscores? HexDigit)? - ; - -fragment -HexDigit - : [0-9a-fA-F] - ; - -fragment -HexDigitsAndUnderscores - : HexDigitOrUnderscore+ - ; - -fragment -HexDigitOrUnderscore - : HexDigit - | '_' - ; - -fragment -OctalNumeral - : '0' Underscores? OctalDigits - ; - -fragment -OctalDigits - : OctalDigit (OctalDigitsAndUnderscores? OctalDigit)? - ; - -fragment -OctalDigit - : [0-7] - ; - -fragment -OctalDigitsAndUnderscores - : OctalDigitOrUnderscore+ - ; - -fragment -OctalDigitOrUnderscore - : OctalDigit - | '_' - ; - -fragment -BinaryNumeral - : '0' [bB] BinaryDigits - ; - -fragment -BinaryDigits - : BinaryDigit (BinaryDigitsAndUnderscores? BinaryDigit)? - ; - -fragment -BinaryDigit - : [01] - ; - -fragment -BinaryDigitsAndUnderscores - : BinaryDigitOrUnderscore+ - ; - -fragment -BinaryDigitOrUnderscore - : BinaryDigit - | '_' - ; - -// §3.10.2 Floating-Point Literals - -FloatingPointLiteral - : DecimalFloatingPointLiteral - | HexadecimalFloatingPointLiteral - ; - -fragment -DecimalFloatingPointLiteral - : Digits '.' Digits? ExponentPart? FloatTypeSuffix? - | '.' Digits ExponentPart? FloatTypeSuffix? - | Digits ExponentPart FloatTypeSuffix? - | Digits FloatTypeSuffix - ; - -fragment -ExponentPart - : ExponentIndicator SignedInteger - ; - -fragment -ExponentIndicator - : [eE] - ; - -fragment -SignedInteger - : Sign? Digits - ; - -fragment -Sign - : [+-] - ; - -fragment -FloatTypeSuffix - : [fFdD] - ; - -fragment -HexadecimalFloatingPointLiteral - : HexSignificand BinaryExponent FloatTypeSuffix? - ; - -fragment -HexSignificand - : HexNumeral '.'? - | '0' [xX] HexDigits? '.' HexDigits - ; - -fragment -BinaryExponent - : BinaryExponentIndicator SignedInteger - ; - -fragment -BinaryExponentIndicator - : [pP] - ; - -// §3.10.3 Boolean Literals - -BooleanLiteral - : 'true' - | 'false' - ; - -// §3.10.4 Character Literals - -CharacterLiteral - : '\'' SingleCharacter '\'' - | '\'' EscapeSequence '\'' - ; - -fragment -SingleCharacter - : ~['\\] - ; - -// §3.10.5 String Literals - -StringLiteral - : '"' StringCharacters? '"' - ; - -fragment -StringCharacters - : StringCharacter+ - ; - -fragment -StringCharacter - : ~["\\] - | EscapeSequence - ; - -// §3.10.6 Escape Sequences for Character and String Literals - -fragment -EscapeSequence - : '\\' [btnfr"'\\] - | OctalEscape - ; - -fragment -OctalEscape - : '\\' OctalDigit - | '\\' OctalDigit OctalDigit - | '\\' ZeroToThree OctalDigit OctalDigit - ; - -fragment -ZeroToThree - : [0-3] - ; - -// §3.10.7 The Null Literal - -NullLiteral - : 'null' - ; - -// §3.11 Separators - -LPAREN : '('; -RPAREN : ')'; -LBRACE : '{'; -RBRACE : '}'; -LBRACK : '['; -RBRACK : ']'; -SEMI : ';'; -COMMA : ','; -DOT : '.'; - -// §3.12 Operators - -ASSIGN : '='; -GT : '>'; -LT : '<'; -BANG : '!'; -TILDE : '~'; -QUESTION : '?'; -COLON : ':'; -EQUAL : '=='; -LE : '<='; -GE : '>='; -NOTEQUAL : '!='; -AND : '&&'; -OR : '||'; -INC : '++'; -DEC : '--'; -ADD : '+'; -SUB : '-'; -MUL : '*'; -DIV : '/'; -BITAND : '&'; -BITOR : '|'; -CARET : '^'; -MOD : '%'; - -ADD_ASSIGN : '+='; -SUB_ASSIGN : '-='; -MUL_ASSIGN : '*='; -DIV_ASSIGN : '/='; -AND_ASSIGN : '&='; -OR_ASSIGN : '|='; -XOR_ASSIGN : '^='; -MOD_ASSIGN : '%='; -LSHIFT_ASSIGN : '<<='; -RSHIFT_ASSIGN : '>>='; -URSHIFT_ASSIGN : '>>>='; - -// §3.8 Identifiers (must appear after all keywords in the grammar) - -Identifier - : JavaLetter JavaLetterOrDigit* - ; - -fragment -JavaLetter - : [a-zA-Z$_] // these are the "java letters" below 0xFF - | // covers all characters above 0xFF which are not a surrogate - ~[\u0000-\u00FF\uD800-\uDBFF] - {IsJavaIdentifierCharacter((char)_input.La(-1), true)}? - //| // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF - // [\uD800-\uDBFF] [\uDC00-\uDFFF] - // {Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.La(-2), (char)_input.La(-1)))}? - ; - -fragment -JavaLetterOrDigit - : [a-zA-Z0-9$_] // these are the "java letters or digits" below 0xFF - | // covers all characters above 0xFF which are not a surrogate - ~[\u0000-\u00FF\uD800-\uDBFF] - {IsJavaIdentifierCharacter((char)_input.La(-1), false)}? - //| // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF - // [\uD800-\uDBFF] [\uDC00-\uDFFF] - // {Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.La(-2), (char)_input.La(-1)))}? - ; - -// -// Additional symbols not defined in the lexical specification -// - -AT : '@'; -ELLIPSIS : '...'; - -// -// Whitespace and comments -// - -WS : [ \t\r\n\u000C]+ -> skip - ; - -COMMENT - : '/*' .*? '*/' -> skip - ; - -LINE_COMMENT - : '//' ~[\r\n]* -> skip - ; diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Java.g4 b/runtime/CSharp/Antlr4.Runtime.Test/Java.g4 deleted file mode 100644 index 26b0e9b2e..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Java.g4 +++ /dev/null @@ -1,1377 +0,0 @@ -/* - [The "BSD licence"] - Copyright (c) 2007-2008 Terence Parr - 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. -*/ -/** A Java 1.5 grammar for ANTLR v3 derived from the spec - * - * This is a very close representation of the spec; the changes - * are comestic (remove left recursion) and also fixes (the spec - * isn't exactly perfect). I have run this on the 1.4.2 source - * and some nasty looking enums from 1.5, but have not really - * tested for 1.5 compatibility. - * - * I built this with: java -Xmx100M org.antlr.Tool java.g - * and got two errors that are ok (for now): - * java.g:691:9: Decision can match input such as - * "'0'..'9'{'E', 'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}" - * using multiple alternatives: 3, 4 - * As a result, alternative(s) 4 were disabled for that input - * java.g:734:35: Decision can match input such as "{'$', 'A'..'Z', - * '_', 'a'..'z', '\u00C0'..'\u00D6', '\u00D8'..'\u00F6', - * '\u00F8'..'\u1FFF', '\u3040'..'\u318F', '\u3300'..'\u337F', - * '\u3400'..'\u3D2D', '\u4E00'..'\u9FFF', '\uF900'..'\uFAFF'}" - * using multiple alternatives: 1, 2 - * As a result, alternative(s) 2 were disabled for that input - * - * You can turn enum on/off as a keyword :) - * - * Version 1.0 -- initial release July 5, 2006 (requires 3.0b2 or higher) - * - * Primary author: Terence Parr, July 2006 - * - * Version 1.0.1 -- corrections by Koen Vanderkimpen & Marko van Dooren, - * October 25, 2006; - * fixed normalInterfaceDeclaration: now uses typeParameters instead - * of typeParameter (according to JLS, 3rd edition) - * fixed castExpression: no longer allows expression next to type - * (according to semantics in JLS, in contrast with syntax in JLS) - * - * Version 1.0.2 -- Terence Parr, Nov 27, 2006 - * java spec I built this from had some bizarre for-loop control. - * Looked weird and so I looked elsewhere...Yep, it's messed up. - * simplified. - * - * Version 1.0.3 -- Chris Hogue, Feb 26, 2007 - * Factored out an annotationName rule and used it in the annotation rule. - * Not sure why, but typeName wasn't recognizing references to inner - * annotations (e.g. @InterfaceName.InnerAnnotation()) - * Factored out the elementValue section of an annotation reference. Created - * elementValuePair and elementValuePairs rules, then used them in the - * annotation rule. Allows it to recognize annotation references with - * multiple, comma separated attributes. - * Updated elementValueArrayInitializer so that it allows multiple elements. - * (It was only allowing 0 or 1 element). - * Updated localVariableDeclaration to allow annotations. Interestingly the JLS - * doesn't appear to indicate this is legal, but it does work as of at least - * JDK 1.5.0_06. - * Moved the Identifier portion of annotationTypeElementRest to annotationMethodRest. - * Because annotationConstantRest already references variableDeclarator which - * has the Identifier portion in it, the parser would fail on constants in - * annotation definitions because it expected two identifiers. - * Added optional trailing ';' to the alternatives in annotationTypeElementRest. - * Wouldn't handle an inner interface that has a trailing ';'. - * Swapped the expression and type rule reference order in castExpression to - * make it check for genericized casts first. It was failing to recognize a - * statement like "Class TYPE = (Class)...;" because it was seeing - * 'Class'. - * Changed createdName to use typeArguments instead of nonWildcardTypeArguments. - * Changed the 'this' alternative in primary to allow 'identifierSuffix' rather than - * just 'arguments'. The case it couldn't handle was a call to an explicit - * generic method invocation (e.g. this.doSomething()). Using identifierSuffix - * may be overly aggressive--perhaps should create a more constrained thisSuffix rule? - * - * Version 1.0.4 -- Hiroaki Nakamura, May 3, 2007 - * - * Fixed formalParameterDecls, localVariableDeclaration, forInit, - * and forVarControl to use variableModifier* not 'final'? (annotation)? - * - * Version 1.0.5 -- Terence, June 21, 2007 - * --a[i].foo didn't work. Fixed unaryExpression - * - * Version 1.0.6 -- John Ridgway, March 17, 2008 - * Made "assert" a switchable keyword like "enum". - * Fixed compilationUnit to disallow "annotation importDeclaration ...". - * Changed "Identifier ('.' Identifier)*" to "qualifiedName" in more - * places. - * Changed modifier* and/or variableModifier* to classOrInterfaceModifiers, - * modifiers or variableModifiers, as appropriate. - * Renamed "bound" to "typeBound" to better match language in the JLS. - * Added "memberDeclaration" which rewrites to methodDeclaration or - * fieldDeclaration and pulled type into memberDeclaration. So we parse - * type and then move on to decide whether we're dealing with a field - * or a method. - * Modified "constructorDeclaration" to use "constructorBody" instead of - * "methodBody". constructorBody starts with explicitConstructorInvocation, - * then goes on to blockStatement*. Pulling explicitConstructorInvocation - * out of expressions allowed me to simplify "primary". - * Changed variableDeclarator to simplify it. - * Changed type to use classOrInterfaceType, thus simplifying it; of course - * I then had to add classOrInterfaceType, but it is used in several - * places. - * Fixed annotations, old version allowed "@X(y,z)", which is illegal. - * Added optional comma to end of "elementValueArrayInitializer"; as per JLS. - * Changed annotationTypeElementRest to use normalClassDeclaration and - * normalInterfaceDeclaration rather than classDeclaration and - * interfaceDeclaration, thus getting rid of a couple of grammar ambiguities. - * Split localVariableDeclaration into localVariableDeclarationStatement - * (includes the terminating semi-colon) and localVariableDeclaration. - * This allowed me to use localVariableDeclaration in "forInit" clauses, - * simplifying them. - * Changed switchBlockStatementGroup to use multiple labels. This adds an - * ambiguity, but if one uses appropriately greedy parsing it yields the - * parse that is closest to the meaning of the switch statement. - * Renamed "forVarControl" to "enhancedForControl" -- JLS language. - * Added semantic predicates to test for shift operations rather than other - * things. Thus, for instance, the string "< <" will never be treated - * as a left-shift operator. - * In "creator" we rule out "nonWildcardTypeArguments" on arrayCreation, - * which are illegal. - * Moved "nonWildcardTypeArguments into innerCreator. - * Removed 'super' superSuffix from explicitGenericInvocation, since that - * is only used in explicitConstructorInvocation at the beginning of a - * constructorBody. (This is part of the simplification of expressions - * mentioned earlier.) - * Simplified primary (got rid of those things that are only used in - * explicitConstructorInvocation). - * Lexer -- removed "Exponent?" from FloatingPointLiteral choice 4, since it - * led to an ambiguity. - * - * This grammar successfully parses every .java file in the JDK 1.5 source - * tree (excluding those whose file names include '-', which are not - * valid Java compilation units). - * - * June 26, 2008 - * - * conditionalExpression had wrong precedence x?y:z. - * - * Known remaining problems: - * "Letter" and "JavaIDDigit" are wrong. The actual specification of - * "Letter" should be "a character for which the method - * Character.isJavaIdentifierStart(int) returns true." A "Java - * letter-or-digit is a character for which the method - * Character.isJavaIdentifierPart(int) returns true." - */ -grammar Java; - -@lexer::members { - -private static bool IsJavaIdentifierCharacter(char c, bool start) -{ - switch (char.GetUnicodeCategory(c)) - { - case System.Globalization.UnicodeCategory.UppercaseLetter: - case System.Globalization.UnicodeCategory.LowercaseLetter: - case System.Globalization.UnicodeCategory.TitlecaseLetter: - case System.Globalization.UnicodeCategory.ModifierLetter: - case System.Globalization.UnicodeCategory.OtherLetter: - // isLetter returns true - return true; - - case System.Globalization.UnicodeCategory.LetterNumber: - // getType returns LETTER_NUMBER - return true; - - case System.Globalization.UnicodeCategory.CurrencySymbol: - // a currency symbol (such as "$") - return true; - - case System.Globalization.UnicodeCategory.ConnectorPunctuation: - // a connecting punctuation character (such as "_") - return true; - - case System.Globalization.UnicodeCategory.DecimalDigitNumber: - // it is a digit - return !start; - - case System.Globalization.UnicodeCategory.SpacingCombiningMark: - // it is a combining mark - return !start; - - case System.Globalization.UnicodeCategory.NonSpacingMark: - // it is a non-spacing mark - return !start; - - default: - return false; - } -} - -} - -// starting point for parsing a java file -/* The annotations are separated out to make parsing faster, but must be associated with - a packageDeclaration or a typeDeclaration (and not an empty one). */ -compilationUnit - : annotations - ( packageDeclaration importDeclaration* typeDeclaration* - | classOrInterfaceDeclaration typeDeclaration* - ) - EOF - | packageDeclaration? importDeclaration* typeDeclaration* - EOF - ; - -packageDeclaration - : 'package' qualifiedName ';' - ; - -importDeclaration - : 'import' 'static'? qualifiedName ('.' '*')? ';' - ; - -typeDeclaration - : classOrInterfaceDeclaration - | ';' - ; - -classOrInterfaceDeclaration - : classOrInterfaceModifiers (classDeclaration | interfaceDeclaration) - ; - -classOrInterfaceModifiers - : classOrInterfaceModifier* - ; - -classOrInterfaceModifier - : annotation // class or interface - | ( 'public' // class or interface - | 'protected' // class or interface - | 'private' // class or interface - | 'abstract' // class or interface - | 'static' // class or interface - | 'final' // class only -- does not apply to interfaces - | 'strictfp' // class or interface - ) - ; - -modifiers - : modifier* - ; - -classDeclaration - : normalClassDeclaration - | enumDeclaration - ; - -normalClassDeclaration - : 'class' Identifier typeParameters? - ('extends' type)? - ('implements' typeList)? - classBody - ; - -typeParameters - : '<' typeParameter (',' typeParameter)* '>' - ; - -typeParameter - : Identifier ('extends' typeBound)? - ; - -typeBound - : type ('&' type)* - ; - -enumDeclaration - : ENUM Identifier ('implements' typeList)? enumBody - ; - -enumBody - : '{' enumConstants? ','? enumBodyDeclarations? '}' - ; - -enumConstants - : enumConstant (',' enumConstant)* - ; - -enumConstant - : annotations? Identifier arguments? classBody? - ; - -enumBodyDeclarations - : ';' (classBodyDeclaration)* - ; - -interfaceDeclaration - : normalInterfaceDeclaration - | annotationTypeDeclaration - ; - -normalInterfaceDeclaration - : 'interface' Identifier typeParameters? ('extends' typeList)? interfaceBody - ; - -typeList - : type (',' type)* - ; - -classBody - : '{' classBodyDeclaration* '}' - ; - -interfaceBody - : '{' interfaceBodyDeclaration* '}' - ; - -classBodyDeclaration - : ';' - | 'static'? block - | modifiers memberDecl - ; - -memberDecl - : genericMethodOrConstructorDecl - | memberDeclaration - | 'void' Identifier voidMethodDeclaratorRest - | Identifier constructorDeclaratorRest - | interfaceDeclaration - | classDeclaration - ; - -memberDeclaration - : type (methodDeclaration | fieldDeclaration) - ; - -genericMethodOrConstructorDecl - : typeParameters genericMethodOrConstructorRest - ; - -genericMethodOrConstructorRest - : (type | 'void') Identifier methodDeclaratorRest - | Identifier constructorDeclaratorRest - ; - -methodDeclaration - : Identifier methodDeclaratorRest - ; - -fieldDeclaration - : variableDeclarators ';' - ; - -interfaceBodyDeclaration - : modifiers interfaceMemberDecl - | ';' - ; - -interfaceMemberDecl - : interfaceMethodOrFieldDecl - | interfaceGenericMethodDecl - | 'void' Identifier voidInterfaceMethodDeclaratorRest - | interfaceDeclaration - | classDeclaration - ; - -interfaceMethodOrFieldDecl - : type Identifier interfaceMethodOrFieldRest - ; - -interfaceMethodOrFieldRest - : constantDeclaratorsRest ';' - | interfaceMethodDeclaratorRest - ; - -methodDeclaratorRest - : formalParameters ('[' ']')* - ('throws' qualifiedNameList)? - ( methodBody - | ';' - ) - ; - -voidMethodDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? - ( methodBody - | ';' - ) - ; - -interfaceMethodDeclaratorRest - : formalParameters ('[' ']')* ('throws' qualifiedNameList)? ';' - ; - -interfaceGenericMethodDecl - : typeParameters (type | 'void') Identifier - interfaceMethodDeclaratorRest - ; - -voidInterfaceMethodDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? ';' - ; - -constructorDeclaratorRest - : formalParameters ('throws' qualifiedNameList)? constructorBody - ; - -constantDeclarator - : Identifier constantDeclaratorRest - ; - -variableDeclarators - : variableDeclarator (',' variableDeclarator)* - ; - -variableDeclarator - : variableDeclaratorId ('=' variableInitializer)? - ; - -constantDeclaratorsRest - : constantDeclaratorRest (',' constantDeclarator)* - ; - -constantDeclaratorRest - : ('[' ']')* '=' variableInitializer - ; - -variableDeclaratorId - : Identifier ('[' ']')* - ; - -variableInitializer - : arrayInitializer - | expression - ; - -arrayInitializer - : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}' - ; - -modifier - : annotation - | ( 'public' - | 'protected' - | 'private' - | 'static' - | 'abstract' - | 'final' - | 'native' - | 'synchronized' - | 'transient' - | 'volatile' - | 'strictfp' - ) - ; - -packageOrTypeName - : qualifiedName - ; - -enumConstantName - : Identifier - ; - -typeName - : qualifiedName - ; - -type - : classOrInterfaceType ('[' ']')* - | primitiveType ('[' ']')* - ; - -classOrInterfaceType - : Identifier typeArguments? ('.' Identifier typeArguments? )* - ; - -primitiveType - : 'boolean' - | 'char' - | 'byte' - | 'short' - | 'int' - | 'long' - | 'float' - | 'double' - ; - -variableModifier - : 'final' - | annotation - ; - -typeArguments - : '<' typeArgument (',' typeArgument)* '>' - ; - -typeArgument - : type - | '?' (('extends' | 'super') type)? - ; - -qualifiedNameList - : qualifiedName (',' qualifiedName)* - ; - -formalParameters - : '(' formalParameterDecls? ')' - ; - -formalParameterDecls - : variableModifiers type formalParameterDeclsRest - ; - -formalParameterDeclsRest - : variableDeclaratorId (',' formalParameterDecls)? - | '...' variableDeclaratorId - ; - -methodBody - : block - ; - -constructorBody - : block - ; - -qualifiedName - : Identifier ('.' Identifier)* - ; - -literal - : IntegerLiteral - | FloatingPointLiteral - | CharacterLiteral - | StringLiteral - | BooleanLiteral - | 'null' - ; - -// ANNOTATIONS - -annotations - : annotation+ - ; - -annotation - : '@' annotationName ( '(' ( elementValuePairs | elementValue )? ')' )? - ; - -annotationName - : Identifier ('.' Identifier)* - ; - -elementValuePairs - : elementValuePair (',' elementValuePair)* - ; - -elementValuePair - : Identifier '=' elementValue - ; - -elementValue - : conditionalExpression - | annotation - | elementValueArrayInitializer - ; - -elementValueArrayInitializer - : '{' (elementValue (',' elementValue)*)? (',')? '}' - ; - -annotationTypeDeclaration - : '@' 'interface' Identifier annotationTypeBody - ; - -annotationTypeBody - : '{' (annotationTypeElementDeclaration)* '}' - ; - -annotationTypeElementDeclaration - : modifiers annotationTypeElementRest - | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler - ; - -annotationTypeElementRest - : type annotationMethodOrConstantRest ';' - | normalClassDeclaration ';'? - | normalInterfaceDeclaration ';'? - | enumDeclaration ';'? - | annotationTypeDeclaration ';'? - ; - -annotationMethodOrConstantRest - : annotationMethodRest - | annotationConstantRest - ; - -annotationMethodRest - : Identifier '(' ')' defaultValue? - ; - -annotationConstantRest - : variableDeclarators - ; - -defaultValue - : 'default' elementValue - ; - -// STATEMENTS / BLOCKS - -block - : '{' blockStatement* '}' - ; - -blockStatement - : localVariableDeclarationStatement - | classOrInterfaceDeclaration - | statement - ; - -localVariableDeclarationStatement - : localVariableDeclaration ';' - ; - -localVariableDeclaration - : variableModifiers type variableDeclarators - ; - -variableModifiers - : variableModifier* - ; - -statement - : block - | ASSERT expression (':' expression)? ';' - | 'if' parExpression statement ('else' statement)? - | 'for' '(' forControl ')' statement - | 'while' parExpression statement - | 'do' statement 'while' parExpression ';' - | 'try' block (catches finallyBlock? | finallyBlock) - | 'try' resourceSpecification block catches? finallyBlock? - | 'switch' parExpression '{' switchBlockStatementGroups '}' - | 'synchronized' parExpression block - | 'return' expression? ';' - | 'throw' expression ';' - | 'break' Identifier? ';' - | 'continue' Identifier? ';' - | ';' - | statementExpression ';' - | Identifier ':' statement - ; - -catches - : catchClause+ - ; - -catchClause - : 'catch' '(' variableModifiers catchType Identifier ')' block - ; - -catchType - : qualifiedName ('|' qualifiedName)* - ; - -finallyBlock - : 'finally' block - ; - -resourceSpecification - : '(' resources ';'? ')' - ; - -resources - : resource (';' resource)* - ; - -resource - : variableModifiers classOrInterfaceType variableDeclaratorId '=' expression - ; - -formalParameter - : variableModifiers type variableDeclaratorId - ; - -switchBlockStatementGroups - : (switchBlockStatementGroup)* - ; - -/* The change here (switchLabel -> switchLabel+) technically makes this grammar - ambiguous; but with appropriately greedy parsing it yields the most - appropriate AST, one in which each group, except possibly the last one, has - labels and statements. */ -switchBlockStatementGroup - : switchLabel+ blockStatement* - ; - -switchLabel - : 'case' constantExpression ':' - | 'case' enumConstantName ':' - | 'default' ':' - ; - -forControl - : enhancedForControl - | forInit? ';' expression? ';' forUpdate? - ; - -forInit - : localVariableDeclaration - | expressionList - ; - -enhancedForControl - : variableModifiers type Identifier ':' expression - ; - -forUpdate - : expressionList - ; - -// EXPRESSIONS - -parExpression - : '(' expression ')' - ; - -expressionList - : expression (',' expression)* - ; - -statementExpression - : expression - ; - -constantExpression - : expression - ; - -expression - : conditionalExpression (assignmentOperator expression)? - ; - -assignmentOperator - : '=' - | '+=' - | '-=' - | '*=' - | '/=' - | '&=' - | '|=' - | '^=' - | '%=' - | '<<=' - | '>>=' - | '>>>=' - ; - -conditionalExpression - : conditionalOrExpression ( '?' expression ':' conditionalExpression )? - ; - -conditionalOrExpression - : conditionalAndExpression ( '||' conditionalAndExpression )* - ; - -conditionalAndExpression - : inclusiveOrExpression ( '&&' inclusiveOrExpression )* - ; - -inclusiveOrExpression - : exclusiveOrExpression ( '|' exclusiveOrExpression )* - ; - -exclusiveOrExpression - : andExpression ( '^' andExpression )* - ; - -andExpression - : equalityExpression ( '&' equalityExpression )* - ; - -equalityExpression - : instanceOfExpression ( ('==' | '!=') instanceOfExpression )* - ; - -instanceOfExpression - : relationalExpression ('instanceof' type)? - ; - -relationalExpression - : shiftExpression ( relationalOp shiftExpression )* - ; - -relationalOp - : '<=' - | '>=' - | '<' - | '>' - ; - -shiftExpression - : additiveExpression ( shiftOp additiveExpression )* - ; - -shiftOp - : t1='<' t2='<' -// { $t1.getLine() == $t2.getLine() && -// $t1.getCharPositionInLine() + 1 == $t2.getCharPositionInLine() }? - | t1='>' t2='>' t3='>' -// { $t1.getLine() == $t2.getLine() && -// $t1.getCharPositionInLine() + 1 == $t2.getCharPositionInLine() && -// $t2.getLine() == $t3.getLine() && -// $t2.getCharPositionInLine() + 1 == $t3.getCharPositionInLine() }? - | t1='>' t2='>' -// { $t1.getLine() == $t2.getLine() && -// $t1.getCharPositionInLine() + 1 == $t2.getCharPositionInLine() }? - ; - - -additiveExpression - : multiplicativeExpression ( ('+' | '-') multiplicativeExpression )* - ; - -multiplicativeExpression - : unaryExpression ( ( '*' | '/' | '%' ) unaryExpression )* - ; - -unaryExpression - : '+' unaryExpression - | '-' unaryExpression - | '++' unaryExpression - | '--' unaryExpression - | unaryExpressionNotPlusMinus - ; - -unaryExpressionNotPlusMinus - : '~' unaryExpression - | '!' unaryExpression - | castExpression - | primary selector* ('++'|'--')? - ; - -castExpression - : '(' primitiveType ')' unaryExpression - | '(' (type | expression) ')' unaryExpressionNotPlusMinus - ; - -primary - : parExpression - | 'this' arguments? - | 'super' superSuffix - | literal - | 'new' creator - | nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments) - | Identifier ('.' Identifier)* identifierSuffix? - | primitiveType ('[' ']')* '.' 'class' - | 'void' '.' 'class' - ; - -identifierSuffix - : ('[' ']')+ '.' 'class' - | '[' expression ']' - | arguments - | '.' 'class' - | '.' explicitGenericInvocation - | '.' 'this' - | '.' 'super' arguments - | '.' 'new' nonWildcardTypeArguments? innerCreator - ; - -creator - : nonWildcardTypeArguments createdName classCreatorRest - | createdName (arrayCreatorRest | classCreatorRest) - ; - -createdName - : Identifier typeArgumentsOrDiamond? ('.' Identifier typeArgumentsOrDiamond?)* - | primitiveType - ; - -innerCreator - : Identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest - ; - -arrayCreatorRest - : '[' - ( ']' ('[' ']')* arrayInitializer - | expression ']' ('[' expression ']')* ('[' ']')* - ) - ; - -classCreatorRest - : arguments classBody? - ; - -explicitGenericInvocation - : nonWildcardTypeArguments explicitGenericInvocationSuffix - ; - -nonWildcardTypeArguments - : '<' typeList '>' - ; - -typeArgumentsOrDiamond - : '<' '>' - | typeArguments - ; - -nonWildcardTypeArgumentsOrDiamond - : '<' '>' - | nonWildcardTypeArguments - ; - -selector - : '.' Identifier arguments? - | '.' explicitGenericInvocation - | '.' 'this' - | '.' 'super' superSuffix - | '.' 'new' nonWildcardTypeArguments? innerCreator - | '[' expression ']' - ; - -superSuffix - : arguments - | '.' Identifier arguments? - ; - -explicitGenericInvocationSuffix - : 'super' superSuffix - | Identifier arguments - ; - -arguments - : '(' expressionList? ')' - ; - -// LEXER - -// §3.9 Keywords - -ABSTRACT : 'abstract'; -ASSERT : 'assert'; -BOOLEAN : 'boolean'; -BREAK : 'break'; -BYTE : 'byte'; -CASE : 'case'; -CATCH : 'catch'; -CHAR : 'char'; -CLASS : 'class'; -CONST : 'const'; -CONTINUE : 'continue'; -DEFAULT : 'default'; -DO : 'do'; -DOUBLE : 'double'; -ELSE : 'else'; -ENUM : 'enum'; -EXTENDS : 'extends'; -FINAL : 'final'; -FINALLY : 'finally'; -FLOAT : 'float'; -FOR : 'for'; -IF : 'if'; -GOTO : 'goto'; -IMPLEMENTS : 'implements'; -IMPORT : 'import'; -INSTANCEOF : 'instanceof'; -INT : 'int'; -INTERFACE : 'interface'; -LONG : 'long'; -NATIVE : 'native'; -NEW : 'new'; -PACKAGE : 'package'; -PRIVATE : 'private'; -PROTECTED : 'protected'; -PUBLIC : 'public'; -RETURN : 'return'; -SHORT : 'short'; -STATIC : 'static'; -STRICTFP : 'strictfp'; -SUPER : 'super'; -SWITCH : 'switch'; -SYNCHRONIZED : 'synchronized'; -THIS : 'this'; -THROW : 'throw'; -THROWS : 'throws'; -TRANSIENT : 'transient'; -TRY : 'try'; -VOID : 'void'; -VOLATILE : 'volatile'; -WHILE : 'while'; - -// §3.10.1 Integer Literals - -IntegerLiteral - : DecimalIntegerLiteral - | HexIntegerLiteral - | OctalIntegerLiteral - | BinaryIntegerLiteral - ; - -fragment -DecimalIntegerLiteral - : DecimalNumeral IntegerTypeSuffix? - ; - -fragment -HexIntegerLiteral - : HexNumeral IntegerTypeSuffix? - ; - -fragment -OctalIntegerLiteral - : OctalNumeral IntegerTypeSuffix? - ; - -fragment -BinaryIntegerLiteral - : BinaryNumeral IntegerTypeSuffix? - ; - -fragment -IntegerTypeSuffix - : [lL] - ; - -fragment -DecimalNumeral - : '0' - | NonZeroDigit (Digits? | Underscores Digits) - ; - -fragment -Digits - : Digit (DigitsAndUnderscores? Digit)? - ; - -fragment -Digit - : '0' - | NonZeroDigit - ; - -fragment -NonZeroDigit - : [1-9] - ; - -fragment -DigitsAndUnderscores - : DigitOrUnderscore+ - ; - -fragment -DigitOrUnderscore - : Digit - | '_' - ; - -fragment -Underscores - : '_'+ - ; - -fragment -HexNumeral - : '0' [xX] HexDigits - ; - -fragment -HexDigits - : HexDigit (HexDigitsAndUnderscores? HexDigit)? - ; - -fragment -HexDigit - : [0-9a-fA-F] - ; - -fragment -HexDigitsAndUnderscores - : HexDigitOrUnderscore+ - ; - -fragment -HexDigitOrUnderscore - : HexDigit - | '_' - ; - -fragment -OctalNumeral - : '0' Underscores? OctalDigits - ; - -fragment -OctalDigits - : OctalDigit (OctalDigitsAndUnderscores? OctalDigit)? - ; - -fragment -OctalDigit - : [0-7] - ; - -fragment -OctalDigitsAndUnderscores - : OctalDigitOrUnderscore+ - ; - -fragment -OctalDigitOrUnderscore - : OctalDigit - | '_' - ; - -fragment -BinaryNumeral - : '0' [bB] BinaryDigits - ; - -fragment -BinaryDigits - : BinaryDigit (BinaryDigitsAndUnderscores? BinaryDigit)? - ; - -fragment -BinaryDigit - : [01] - ; - -fragment -BinaryDigitsAndUnderscores - : BinaryDigitOrUnderscore+ - ; - -fragment -BinaryDigitOrUnderscore - : BinaryDigit - | '_' - ; - -// §3.10.2 Floating-Point Literals - -FloatingPointLiteral - : DecimalFloatingPointLiteral - | HexadecimalFloatingPointLiteral - ; - -fragment -DecimalFloatingPointLiteral - : Digits '.' Digits? ExponentPart? FloatTypeSuffix? - | '.' Digits ExponentPart? FloatTypeSuffix? - | Digits ExponentPart FloatTypeSuffix? - | Digits FloatTypeSuffix - ; - -fragment -ExponentPart - : ExponentIndicator SignedInteger - ; - -fragment -ExponentIndicator - : [eE] - ; - -fragment -SignedInteger - : Sign? Digits - ; - -fragment -Sign - : [+-] - ; - -fragment -FloatTypeSuffix - : [fFdD] - ; - -fragment -HexadecimalFloatingPointLiteral - : HexSignificand BinaryExponent FloatTypeSuffix? - ; - -fragment -HexSignificand - : HexNumeral '.'? - | '0' [xX] HexDigits? '.' HexDigits - ; - -fragment -BinaryExponent - : BinaryExponentIndicator SignedInteger - ; - -fragment -BinaryExponentIndicator - : [pP] - ; - -// §3.10.3 Boolean Literals - -BooleanLiteral - : 'true' - | 'false' - ; - -// §3.10.4 Character Literals - -CharacterLiteral - : '\'' SingleCharacter '\'' - | '\'' EscapeSequence '\'' - ; - -fragment -SingleCharacter - : ~['\\] - ; - -// §3.10.5 String Literals - -StringLiteral - : '"' StringCharacters? '"' - ; - -fragment -StringCharacters - : StringCharacter+ - ; - -fragment -StringCharacter - : ~["\\] - | EscapeSequence - ; - -// §3.10.6 Escape Sequences for Character and String Literals - -fragment -EscapeSequence - : '\\' [btnfr"'\\] - | OctalEscape - ; - -fragment -OctalEscape - : '\\' OctalDigit - | '\\' OctalDigit OctalDigit - | '\\' ZeroToThree OctalDigit OctalDigit - ; - -fragment -ZeroToThree - : [0-3] - ; - -// §3.10.7 The Null Literal - -NullLiteral - : 'null' - ; - -// §3.11 Separators - -LPAREN : '('; -RPAREN : ')'; -LBRACE : '{'; -RBRACE : '}'; -LBRACK : '['; -RBRACK : ']'; -SEMI : ';'; -COMMA : ','; -DOT : '.'; - -// §3.12 Operators - -ASSIGN : '='; -GT : '>'; -LT : '<'; -BANG : '!'; -TILDE : '~'; -QUESTION : '?'; -COLON : ':'; -EQUAL : '=='; -LE : '<='; -GE : '>='; -NOTEQUAL : '!='; -AND : '&&'; -OR : '||'; -INC : '++'; -DEC : '--'; -ADD : '+'; -SUB : '-'; -MUL : '*'; -DIV : '/'; -BITAND : '&'; -BITOR : '|'; -CARET : '^'; -MOD : '%'; - -ADD_ASSIGN : '+='; -SUB_ASSIGN : '-='; -MUL_ASSIGN : '*='; -DIV_ASSIGN : '/='; -AND_ASSIGN : '&='; -OR_ASSIGN : '|='; -XOR_ASSIGN : '^='; -MOD_ASSIGN : '%='; -LSHIFT_ASSIGN : '<<='; -RSHIFT_ASSIGN : '>>='; -URSHIFT_ASSIGN : '>>>='; - -// §3.8 Identifiers (must appear after all keywords in the grammar) - -Identifier - : JavaLetter JavaLetterOrDigit* - ; - -fragment -JavaLetter - : [a-zA-Z$_] // these are the "java letters" below 0xFF - | // covers all characters above 0xFF which are not a surrogate - ~[\u0000-\u00FF\uD800-\uDBFF] - {IsJavaIdentifierCharacter((char)_input.La(-1), true)}? - //| // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF - // [\uD800-\uDBFF] [\uDC00-\uDFFF] - // {Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.La(-2), (char)_input.La(-1)))}? - ; - -fragment -JavaLetterOrDigit - : [a-zA-Z0-9$_] // these are the "java letters or digits" below 0xFF - | // covers all characters above 0xFF which are not a surrogate - ~[\u0000-\u00FF\uD800-\uDBFF] - {IsJavaIdentifierCharacter((char)_input.La(-1), false)}? - //| // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF - // [\uD800-\uDBFF] [\uDC00-\uDFFF] - // {Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.La(-2), (char)_input.La(-1)))}? - ; - -// -// Additional symbols not defined in the lexical specification -// - -AT : '@'; -ELLIPSIS : '...'; - -// -// Whitespace and comments -// - -WS : [ \t\r\n\u000C]+ -> skip - ; - -COMMENT - : '/*' .*? '*/' -> skip - ; - -LINE_COMMENT - : '//' ~[\r\n]* -> skip - ; diff --git a/runtime/CSharp/Antlr4.Runtime.Test/JavaUnicodeInputStream.cs b/runtime/CSharp/Antlr4.Runtime.Test/JavaUnicodeInputStream.cs deleted file mode 100644 index 18615e6e8..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/JavaUnicodeInputStream.cs +++ /dev/null @@ -1,272 +0,0 @@ -namespace Antlr4.Runtime.Test -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using Antlr4.Runtime.Misc; - - public class JavaUnicodeInputStream : ICharStream - { - [NotNull] - private readonly ICharStream _source; - private readonly List _escapeIndexes = new List(); - private readonly List _escapeCharacters = new List(); - private readonly List _escapeIndirectionLevels = new List(); - - private int _escapeListIndex; - private int _range; - private int _slashCount; - - private int _la1; - - public JavaUnicodeInputStream([NotNull] ICharStream source) - { - if (source == null) - throw new ArgumentNullException("source"); - - this._source = source; - this._la1 = source.La(1); - } - - public int Size - { - get - { - return _source.Size; - } - } - - public int Index - { - get - { - return _source.Index; - } - } - - public string SourceName - { - get - { - return _source.SourceName; - } - } - - public String GetText(Interval interval) - { - return _source.GetText(interval); - } - - public void Consume() - { - if (_la1 != '\\') - { - _source.Consume(); - _la1 = _source.La(1); - _range = Math.Max(_range, _source.Index); - _slashCount = 0; - return; - } - - // make sure the next character has been processed - this.La(1); - - if (_escapeListIndex >= _escapeIndexes.Count || _escapeIndexes[_escapeListIndex] != Index) - { - _source.Consume(); - _slashCount++; - } - else - { - int indirectionLevel = _escapeIndirectionLevels[_escapeListIndex]; - for (int i = 0; i < 6 + indirectionLevel; i++) - { - _source.Consume(); - } - - _escapeListIndex++; - _slashCount = 0; - } - - _la1 = _source.La(1); - Debug.Assert(_range >= Index); - } - - public int La(int i) - { - if (i == 1 && _la1 != '\\') - { - return _la1; - } - - if (i <= 0) - { - int desiredIndex = Index + i; - for (int j = _escapeListIndex - 1; j >= 0; j--) - { - if (_escapeIndexes[j] + 6 + _escapeIndirectionLevels[j] > desiredIndex) - { - desiredIndex -= 5 + _escapeIndirectionLevels[j]; - } - - if (_escapeIndexes[j] == desiredIndex) - { - return _escapeCharacters[j]; - } - } - - return _source.La(desiredIndex - Index); - } - else - { - int desiredIndex = Index + i - 1; - for (int j = _escapeListIndex; j < _escapeIndexes.Count; j++) - { - if (_escapeIndexes[j] == desiredIndex) - { - return _escapeCharacters[j]; - } - else if (_escapeIndexes[j] < desiredIndex) - { - desiredIndex += 5 + _escapeIndirectionLevels[j]; - } - else - { - return _source.La(desiredIndex - Index + 1); - } - } - - int currentIndex = Index; - int slashCount = _slashCount; - int indirectionLevel = 0; - for (int j = 0; j < i; j++) - { - int previousIndex = currentIndex; - int c = ReadCharAt(ref currentIndex, ref slashCount, ref indirectionLevel); - if (currentIndex > _range) - { - if (currentIndex - previousIndex > 1) - { - _escapeIndexes.Add(previousIndex); - _escapeCharacters.Add(c); - _escapeIndirectionLevels.Add(indirectionLevel); - } - - _range = currentIndex; - } - - if (j == i - 1) - { - return c; - } - } - - throw new InvalidOperationException("shouldn't be reachable"); - } - } - - public int Mark() - { - return _source.Mark(); - } - - public void Release(int marker) - { - _source.Release(marker); - } - - public void Seek(int index) - { - if (index > _range) - { - throw new NotSupportedException(); - } - - _source.Seek(index); - _la1 = _source.La(1); - - _slashCount = 0; - while (_source.La(-_slashCount - 1) == '\\') - { - _slashCount++; - } - - _escapeListIndex = _escapeIndexes.BinarySearch(_source.Index); - if (_escapeListIndex < 0) - { - _escapeListIndex = -_escapeListIndex - 1; - } - } - - private static bool IsHexDigit(int c) - { - return c >= '0' && c <= '9' - || c >= 'a' && c <= 'f' - || c >= 'A' && c <= 'F'; - } - - private static int HexValue(int c) - { - if (c >= '0' && c <= '9') - { - return c - '0'; - } - - if (c >= 'a' && c <= 'f') - { - return c - 'a' + 10; - } - - if (c >= 'A' && c <= 'F') - { - return c - 'A' + 10; - } - - throw new ArgumentException("c"); - } - - private int ReadCharAt(ref int nextIndex, ref int slashCount, ref int indirectionLevel) - { - bool blockUnicodeEscape = (slashCount % 2) != 0; - - int c0 = _source.La(nextIndex - Index + 1); - if (c0 == '\\') - { - slashCount++; - - if (!blockUnicodeEscape) - { - int c1 = _source.La(nextIndex - Index + 2); - if (c1 == 'u') - { - int c2 = _source.La(nextIndex - Index + 3); - indirectionLevel = 0; - while (c2 == 'u') - { - indirectionLevel++; - c2 = _source.La(nextIndex - Index + 3 + indirectionLevel); - } - - int c3 = _source.La(nextIndex - Index + 4 + indirectionLevel); - int c4 = _source.La(nextIndex - Index + 5 + indirectionLevel); - int c5 = _source.La(nextIndex - Index + 6 + indirectionLevel); - if (IsHexDigit(c2) && IsHexDigit(c3) && IsHexDigit(c4) && IsHexDigit(c5)) - { - int value = HexValue(c2); - value = (value << 4) + HexValue(c3); - value = (value << 4) + HexValue(c4); - value = (value << 4) + HexValue(c5); - - nextIndex += 6 + indirectionLevel; - slashCount = 0; - return value; - } - } - } - } - - nextIndex++; - return c0; - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Properties/AssemblyInfo.cs b/runtime/CSharp/Antlr4.Runtime.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index d59ef0aca..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,68 +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.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Antlr4.Runtime.Test")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] -[assembly: AssemblyProduct("Antlr4.Runtime.Test")] -[assembly: AssemblyCopyright("Copyright © Sam Harwell 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -[assembly: CLSCompliant(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e88a6cd4-d62a-4a1b-a124-47f7fa10ad7e")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/CRC32.cs b/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/CRC32.cs deleted file mode 100644 index da06f3114..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/CRC32.cs +++ /dev/null @@ -1,415 +0,0 @@ -namespace Antlr4.Runtime.Sharpen -{ - using System; - - internal class CRC32 : Checksum - { - private uint _crc; - - public long Value - { - get - { - return (int)_crc; - } - } - - public void Reset() - { - _crc = 0; - } - - public void Update(byte[] buffer, int offset, int length) - { - if (buffer == null) - throw new ArgumentNullException("buffer"); - if (offset < 0) - throw new ArgumentOutOfRangeException("offset"); - if (length < 0) - throw new ArgumentOutOfRangeException("length"); - if (offset > buffer.Length || length > buffer.Length || offset + length > buffer.Length) - throw new ArgumentException(); - - unsafe - { - fixed (byte* data = buffer) - { - _crc = crc32(_crc, data + offset, (uint)length); - } - } - } - - public void Update(int byteValue) - { - byte value = (byte)byteValue; - unsafe - { - _crc = crc32(_crc, &value, 1); - } - } - - /* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - /* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2005 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - - /* @(#) $Id$ */ - - /* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - */ - - /* Definitions for doing the crc four data bytes at a time. */ - - private static uint REV(uint w) - { - return (w >> 24) + ((w >> 8) & 0xff00) + ((w & 0xff00) << 8) + ((w & 0xff) << 24); - } - - private const uint TBLS = 8; - - /* Local functions for crc concatenation */ - - private static readonly uint[][] crc_table; - - static CRC32() - { - crc_table = new uint[TBLS][]; - for (int i = 0; i < TBLS; i++) - crc_table[i] = new uint[256]; - - make_crc_table(); - } - - /* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The first table is simply the CRC of all possible eight bit values. This is - all the information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. The remaining tables - allow for word-at-a-time CRC calculation for both big-endian and little- - endian machines, where a word is four bytes. - */ - private static void make_crc_table() - { - /* terms of polynomial defining this crc (except x^32): */ - byte[] p = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 }; - - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - uint poly = 0U; - for (int n = 0; n < p.Length; n++) - poly |= 1U << (31 - p[n]); - - /* generate a crc for every 8-bit value */ - for (int n = 0; n < 256; n++) - { - uint c = (uint)n; - for (int k = 0; k < 8; k++) - c = (c & 1) != 0 ? poly ^ (c >> 1) : c >> 1; - - crc_table[0][n] = c; - } - - /* generate crc for each value followed by one, two, and three zeros, - and then the byte reversal of those as well as the first table */ - for (int n = 0; n < 256; n++) - { - uint c = crc_table[0][n]; - crc_table[4][n] = REV(c); - for (int k = 1; k < 4; k++) - { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = REV(c); - } - } - } - - /* ========================================================================= - * This function can be used by asm versions of crc32() - */ - private static uint[][] get_crc_table() - { - return crc_table; - } - - ///* ========================================================================= */ - private static unsafe void DO1(ref uint crc, ref byte* buf) - { - crc = crc_table[0][(crc ^ (*buf++)) & 0xFF] ^ (crc >> 8); - } - - private static unsafe void DO8(ref uint crc, ref byte* buf) - { - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - DO1(ref crc, ref buf); - } - - /* ========================================================================= */ - private static unsafe uint crc32(uint crc, byte* buf, uint len) - { - if (buf == null) - return 0; - - if (BitConverter.IsLittleEndian) - return (uint)crc32_little(crc, buf, len); - else - return (uint)crc32_big(crc, buf, len); - } - - ///* ========================================================================= */ - private static unsafe void DOLIT4(ref uint c, ref uint* buf4) - { - c ^= *buf4++; - c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ - crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]; - } - - private static unsafe void DOLIT32(ref uint c, ref uint* buf4) - { - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - DOLIT4(ref c, ref buf4); - } - - /* ========================================================================= */ - private static unsafe uint crc32_little(uint crc, byte* buf, uint len) - { - uint c = (uint)crc; - c = ~c; - while (len != 0 && ((uint)buf & 3) != 0) - { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - len--; - } - - uint* buf4 = (uint*)buf; - while (len >= 32) - { - DOLIT32(ref c, ref buf4); - len -= 32; - } - - while (len >= 4) - { - DOLIT4(ref c, ref buf4); - len -= 4; - } - - buf = (byte*)buf4; - - if (len != 0) - { - do - { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - } while (--len != 0); - } - - c = ~c; - return (uint)c; - } - - ///* ========================================================================= */ - private static unsafe void DOBIG4(ref uint c, ref uint* buf4) - { - c ^= *++buf4; - c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ - crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]; - } - - private static unsafe void DOBIG32(ref uint c, ref uint* buf4) - { - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - DOBIG4(ref c, ref buf4); - } - - /* ========================================================================= */ - private static unsafe uint crc32_big(uint crc, byte* buf, uint len) - { - uint c; - uint* buf4; - - c = REV((uint)crc); - c = ~c; - while (len != 0 && ((uint)buf & 3) != 0) - { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - len--; - } - - buf4 = (uint*)buf; - buf4--; - while (len >= 32) - { - DOBIG32(ref c, ref buf4); - len -= 32; - } - - while (len >= 4) - { - DOBIG4(ref c, ref buf4); - len -= 4; - } - - buf4++; - buf = (byte*)buf4; - - if (len != 0) - do - { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - } while (--len != 0); - c = ~c; - return (uint)(REV(c)); - } - - private const int GF2_DIM = 32; /* dimension of GF(2) vectors (length of CRC) */ - - /* ========================================================================= */ - private static unsafe uint gf2_matrix_times(uint* mat, uint vec) - { - uint sum = 0; - while (vec != 0) - { - if ((vec & 1) != 0) - sum ^= *mat; - - vec >>= 1; - mat++; - } - - return sum; - } - - /* ========================================================================= */ - private static unsafe void gf2_matrix_square(uint* square, uint* mat) - { - for (int n = 0; n < GF2_DIM; n++) - square[n] = gf2_matrix_times(mat, mat[n]); - } - - /* ========================================================================= */ - private static unsafe uint crc32_combine(uint crc1, uint crc2, uint len2) - { - /* degenerate case */ - if (len2 == 0) - return crc1; - - uint* even = stackalloc uint[GF2_DIM]; /* even-power-of-two zeros operator */ - uint* odd = stackalloc uint[GF2_DIM]; /* odd-power-of-two zeros operator */ - - /* put operator for one zero bit in odd */ - odd[0] = 0xEDB88320U; /* CRC-32 polynomial */ - uint row = 1; - for (int n = 1; n < GF2_DIM; n++) - { - odd[n] = row; - row <<= 1; - } - - /* put operator for two zero bits in even */ - gf2_matrix_square(even, odd); - - /* put operator for four zero bits in odd */ - gf2_matrix_square(odd, even); - - /* apply len2 zeros to crc1 (first square will put the operator for one - zero byte, eight zero bits, in even) */ - do - { - /* apply zeros operator for this bit of len2 */ - gf2_matrix_square(even, odd); - if ((len2 & 1) != 0) - crc1 = gf2_matrix_times(even, crc1); - - len2 >>= 1; - - /* if no more bits set, then done */ - if (len2 == 0) - break; - - /* another iteration of the loop with odd and even swapped */ - gf2_matrix_square(odd, even); - if ((len2 & 1) != 0) - crc1 = gf2_matrix_times(odd, crc1); - - len2 >>= 1; - - /* if no more bits set, then done */ - } while (len2 != 0); - - /* return combined crc */ - crc1 ^= crc2; - return crc1; - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/Checksum.cs b/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/Checksum.cs deleted file mode 100644 index 30e70cf16..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/Sharpen/Checksum.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Antlr4.Runtime.Sharpen -{ - internal interface Checksum - { - long Value - { - get; - } - - void Reset(); - - void Update(byte[] buffer, int offset, int length); - - void Update(int byteValue); - } -} diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TaskSchedulers/QueuedTaskScheduler.cs b/runtime/CSharp/Antlr4.Runtime.Test/TaskSchedulers/QueuedTaskScheduler.cs deleted file mode 100644 index 870195503..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/TaskSchedulers/QueuedTaskScheduler.cs +++ /dev/null @@ -1,612 +0,0 @@ -//-------------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// File: QueuedTaskScheduler.cs -// -//-------------------------------------------------------------------------- - -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; - -namespace System.Threading.Tasks.Schedulers -{ - /// - /// Provides a TaskScheduler that provides control over priorities, fairness, and the underlying threads utilized. - /// - [DebuggerTypeProxy(typeof(QueuedTaskSchedulerDebugView))] - [DebuggerDisplay("Id={Id}, Queues={DebugQueueCount}, ScheduledTasks = {DebugTaskCount}")] - public sealed class QueuedTaskScheduler : TaskScheduler, IDisposable - { - /// Debug view for the QueuedTaskScheduler. - private class QueuedTaskSchedulerDebugView - { - /// The scheduler. - private QueuedTaskScheduler _scheduler; - - /// Initializes the debug view. - /// The scheduler. - public QueuedTaskSchedulerDebugView(QueuedTaskScheduler scheduler) - { - if (scheduler == null) throw new ArgumentNullException("scheduler"); - _scheduler = scheduler; - } - - /// Gets all of the Tasks queued to the scheduler directly. - public IEnumerable ScheduledTasks - { - get - { - var tasks = (_scheduler._targetScheduler != null) ? - (IEnumerable)_scheduler._nonthreadsafeTaskQueue : - (IEnumerable)_scheduler._blockingTaskQueue; - return tasks.Where(t => t != null).ToList(); - } - } - - /// Gets the prioritized and fair queues. - public IEnumerable Queues - { - get - { - List queues = new List(); - foreach (var group in _scheduler._queueGroups) queues.AddRange(group.Value); - return queues; - } - } - } - - /// - /// A sorted list of round-robin queue lists. Tasks with the smallest priority value - /// are preferred. Priority groups are round-robin'd through in order of priority. - /// - private readonly SortedList _queueGroups = new SortedList(); - /// Cancellation token used for disposal. - private readonly CancellationTokenSource _disposeCancellation = new CancellationTokenSource(); - /// - /// The maximum allowed concurrency level of this scheduler. If custom threads are - /// used, this represents the number of created threads. - /// - private readonly int _concurrencyLevel; - /// Whether we're processing tasks on the current thread. - private static ThreadLocal _taskProcessingThread = new ThreadLocal(); - - // *** - // *** For when using a target scheduler - // *** - - /// The scheduler onto which actual work is scheduled. - private readonly TaskScheduler _targetScheduler; - /// The queue of tasks to process when using an underlying target scheduler. - private readonly Queue _nonthreadsafeTaskQueue; - /// The number of Tasks that have been queued or that are running whiel using an underlying scheduler. - private int _delegatesQueuedOrRunning = 0; - - // *** - // *** For when using our own threads - // *** - - /// The threads used by the scheduler to process work. - private readonly Thread[] _threads; - /// The collection of tasks to be executed on our custom threads. - private readonly BlockingCollection _blockingTaskQueue; - - // *** - - /// Initializes the scheduler. - public QueuedTaskScheduler() : this(TaskScheduler.Default, 0) { } - - /// Initializes the scheduler. - /// The target underlying scheduler onto which this sceduler's work is queued. - public QueuedTaskScheduler(TaskScheduler targetScheduler) : this(targetScheduler, 0) { } - - /// Initializes the scheduler. - /// The target underlying scheduler onto which this sceduler's work is queued. - /// The maximum degree of concurrency allowed for this scheduler's work. - public QueuedTaskScheduler( - TaskScheduler targetScheduler, - int maxConcurrencyLevel) - { - // Validate arguments - if (targetScheduler == null) throw new ArgumentNullException("underlyingScheduler"); - if (maxConcurrencyLevel < 0) throw new ArgumentOutOfRangeException("concurrencyLevel"); - - // Initialize only those fields relevant to use an underlying scheduler. We don't - // initialize the fields relevant to using our own custom threads. - _targetScheduler = targetScheduler; - _nonthreadsafeTaskQueue = new Queue(); - - // If 0, use the number of logical processors. But make sure whatever value we pick - // is not greater than the degree of parallelism allowed by the underlying scheduler. - _concurrencyLevel = maxConcurrencyLevel != 0 ? maxConcurrencyLevel : Environment.ProcessorCount; - if (targetScheduler.MaximumConcurrencyLevel > 0 && - targetScheduler.MaximumConcurrencyLevel < _concurrencyLevel) - { - _concurrencyLevel = targetScheduler.MaximumConcurrencyLevel; - } - } - - /// Initializes the scheduler. - /// The number of threads to create and use for processing work items. - public QueuedTaskScheduler(int threadCount) : this(threadCount, string.Empty, false, ThreadPriority.Normal, ApartmentState.MTA, 0, null, null) { } - - /// Initializes the scheduler. - /// The number of threads to create and use for processing work items. - /// The name to use for each of the created threads. - /// A Boolean value that indicates whether to use foreground threads instead of background. - /// The priority to assign to each thread. - /// The apartment state to use for each thread. - /// The stack size to use for each thread. - /// An initialization routine to run on each thread. - /// A finalization routine to run on each thread. - public QueuedTaskScheduler( - int threadCount, - string threadName = "", - bool useForegroundThreads = false, - ThreadPriority threadPriority = ThreadPriority.Normal, - ApartmentState threadApartmentState = ApartmentState.MTA, - int threadMaxStackSize = 0, - Action threadInit = null, - Action threadFinally = null) - { - // Validates arguments (some validation is left up to the Thread type itself). - // If the thread count is 0, default to the number of logical processors. - if (threadCount < 0) throw new ArgumentOutOfRangeException("concurrencyLevel"); - else if (threadCount == 0) _concurrencyLevel = Environment.ProcessorCount; - else _concurrencyLevel = threadCount; - - // Initialize the queue used for storing tasks - _blockingTaskQueue = new BlockingCollection(); - - // Create all of the threads - _threads = new Thread[threadCount]; - for (int i = 0; i < threadCount; i++) - { - _threads[i] = new Thread(() => ThreadBasedDispatchLoop(threadInit, threadFinally), threadMaxStackSize) - { - Priority = threadPriority, - IsBackground = !useForegroundThreads, - }; - if (threadName != null) _threads[i].Name = threadName + " (" + i + ")"; - _threads[i].SetApartmentState(threadApartmentState); - } - - // Start all of the threads - foreach (var thread in _threads) thread.Start(); - } - - /// The dispatch loop run by all threads in this scheduler. - /// An initialization routine to run when the thread begins. - /// A finalization routine to run before the thread ends. - private void ThreadBasedDispatchLoop(Action threadInit, Action threadFinally) - { - _taskProcessingThread.Value = true; - if (threadInit != null) threadInit(); - try - { - // If the scheduler is disposed, the cancellation token will be set and - // we'll receive an OperationCanceledException. That OCE should not crash the process. - try - { - // If a thread abort occurs, we'll try to reset it and continue running. - while (true) - { - try - { - // For each task queued to the scheduler, try to execute it. - foreach (var task in _blockingTaskQueue.GetConsumingEnumerable(_disposeCancellation.Token)) - { - // If the task is not null, that means it was queued to this scheduler directly. - // Run it. - if (task != null) - { - TryExecuteTask(task); - } - // If the task is null, that means it's just a placeholder for a task - // queued to one of the subschedulers. Find the next task based on - // priority and fairness and run it. - else - { - // Find the next task based on our ordering rules... - Task targetTask; - QueuedTaskSchedulerQueue queueForTargetTask; - lock (_queueGroups) FindNextTask_NeedsLock(out targetTask, out queueForTargetTask); - - // ... and if we found one, run it - if (targetTask != null) queueForTargetTask.ExecuteTask(targetTask); - } - } - } - catch (ThreadAbortException) - { - // If we received a thread abort, and that thread abort was due to shutting down - // or unloading, let it pass through. Otherwise, reset the abort so we can - // continue processing work items. - if (!Environment.HasShutdownStarted && !AppDomain.CurrentDomain.IsFinalizingForUnload()) - { - Thread.ResetAbort(); - } - } - } - } - catch (OperationCanceledException) { } - } - finally - { - // Run a cleanup routine if there was one - if (threadFinally != null) threadFinally(); - _taskProcessingThread.Value = false; - } - } - - /// Gets the number of queues currently activated. - private int DebugQueueCount - { - get - { - int count = 0; - foreach (var group in _queueGroups) count += group.Value.Count; - return count; - } - } - - /// Gets the number of tasks currently scheduled. - private int DebugTaskCount - { - get - { - return (_targetScheduler != null ? - (IEnumerable)_nonthreadsafeTaskQueue : (IEnumerable)_blockingTaskQueue) - .Where(t => t != null).Count(); - } - } - - /// Find the next task that should be executed, based on priorities and fairness and the like. - /// The found task, or null if none was found. - /// - /// The scheduler associated with the found task. Due to security checks inside of TPL, - /// this scheduler needs to be used to execute that task. - /// - private void FindNextTask_NeedsLock(out Task targetTask, out QueuedTaskSchedulerQueue queueForTargetTask) - { - targetTask = null; - queueForTargetTask = null; - - // Look through each of our queue groups in sorted order. - // This ordering is based on the priority of the queues. - foreach (var queueGroup in _queueGroups) - { - var queues = queueGroup.Value; - - // Within each group, iterate through the queues in a round-robin - // fashion. Every time we iterate again and successfully find a task, - // we'll start in the next location in the group. - foreach (int i in queues.CreateSearchOrder()) - { - queueForTargetTask = queues[i]; - var items = queueForTargetTask._workItems; - if (items.Count > 0) - { - targetTask = items.Dequeue(); - if (queueForTargetTask._disposed && items.Count == 0) - { - RemoveQueue_NeedsLock(queueForTargetTask); - } - queues.NextQueueIndex = (queues.NextQueueIndex + 1) % queueGroup.Value.Count; - return; - } - } - } - } - - /// Queues a task to the scheduler. - /// The task to be queued. - protected override void QueueTask(Task task) - { - // If we've been disposed, no one should be queueing - if (_disposeCancellation.IsCancellationRequested) throw new ObjectDisposedException(GetType().Name); - - // If the target scheduler is null (meaning we're using our own threads), - // add the task to the blocking queue - if (_targetScheduler == null) - { - _blockingTaskQueue.Add(task); - } - // Otherwise, add the task to the non-blocking queue, - // and if there isn't already an executing processing task, - // start one up - else - { - // Queue the task and check whether we should launch a processing - // task (noting it if we do, so that other threads don't result - // in queueing up too many). - bool launchTask = false; - lock (_nonthreadsafeTaskQueue) - { - _nonthreadsafeTaskQueue.Enqueue(task); - if (_delegatesQueuedOrRunning < _concurrencyLevel) - { - ++_delegatesQueuedOrRunning; - launchTask = true; - } - } - - // If necessary, start processing asynchronously - if (launchTask) - { - Task.Factory.StartNew(ProcessPrioritizedAndBatchedTasks, - CancellationToken.None, TaskCreationOptions.None, _targetScheduler); - } - } - } - - /// - /// Process tasks one at a time in the best order. - /// This should be run in a Task generated by QueueTask. - /// It's been separated out into its own method to show up better in Parallel Tasks. - /// - private void ProcessPrioritizedAndBatchedTasks() - { - bool continueProcessing = true; - while (!_disposeCancellation.IsCancellationRequested && continueProcessing) - { - try - { - // Note that we're processing tasks on this thread - _taskProcessingThread.Value = true; - - // Until there are no more tasks to process - while (!_disposeCancellation.IsCancellationRequested) - { - // Try to get the next task. If there aren't any more, we're done. - Task targetTask; - lock (_nonthreadsafeTaskQueue) - { - if (_nonthreadsafeTaskQueue.Count == 0) return; - targetTask = _nonthreadsafeTaskQueue.Dequeue(); - } - - // If the task is null, it's a placeholder for a task in the round-robin queues. - // Find the next one that should be processed. - QueuedTaskSchedulerQueue queueForTargetTask = null; - if (targetTask == null) - { - lock (_queueGroups) FindNextTask_NeedsLock(out targetTask, out queueForTargetTask); - } - - // Now if we finally have a task, run it. If the task - // was associated with one of the round-robin schedulers, we need to use it - // as a thunk to execute its task. - if (targetTask != null) - { - if (queueForTargetTask != null) queueForTargetTask.ExecuteTask(targetTask); - else TryExecuteTask(targetTask); - } - } - } - finally - { - // Now that we think we're done, verify that there really is - // no more work to do. If there's not, highlight - // that we're now less parallel than we were a moment ago. - lock (_nonthreadsafeTaskQueue) - { - if (_nonthreadsafeTaskQueue.Count == 0) - { - _delegatesQueuedOrRunning--; - continueProcessing = false; - _taskProcessingThread.Value = false; - } - } - } - } - } - - /// Notifies the pool that there's a new item to be executed in one of the round-robin queues. - private void NotifyNewWorkItem() { QueueTask(null); } - - /// Tries to execute a task synchronously on the current thread. - /// The task to execute. - /// Whether the task was previously queued. - /// true if the task was executed; otherwise, false. - protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued) - { - // If we're already running tasks on this threads, enable inlining - return _taskProcessingThread.Value && TryExecuteTask(task); - } - - /// Gets the tasks scheduled to this scheduler. - /// An enumerable of all tasks queued to this scheduler. - /// This does not include the tasks on sub-schedulers. Those will be retrieved by the debugger separately. - protected override IEnumerable GetScheduledTasks() - { - // If we're running on our own threads, get the tasks from the blocking queue... - if (_targetScheduler == null) - { - // Get all of the tasks, filtering out nulls, which are just placeholders - // for tasks in other sub-schedulers - return _blockingTaskQueue.Where(t => t != null).ToList(); - } - // otherwise get them from the non-blocking queue... - else - { - return _nonthreadsafeTaskQueue.Where(t => t != null).ToList(); - } - } - - /// Gets the maximum concurrency level to use when processing tasks. - public override int MaximumConcurrencyLevel { get { return _concurrencyLevel; } } - - /// Initiates shutdown of the scheduler. - public void Dispose() - { - _disposeCancellation.Cancel(); - } - - /// Creates and activates a new scheduling queue for this scheduler. - /// The newly created and activated queue at priority 0. - public TaskScheduler ActivateNewQueue() { return ActivateNewQueue(0); } - - /// Creates and activates a new scheduling queue for this scheduler. - /// The priority level for the new queue. - /// The newly created and activated queue at the specified priority. - public TaskScheduler ActivateNewQueue(int priority) - { - // Create the queue - var createdQueue = new QueuedTaskSchedulerQueue(priority, this); - - // Add the queue to the appropriate queue group based on priority - lock (_queueGroups) - { - QueueGroup list; - if (!_queueGroups.TryGetValue(priority, out list)) - { - list = new QueueGroup(); - _queueGroups.Add(priority, list); - } - list.Add(createdQueue); - } - - // Hand the new queue back - return createdQueue; - } - - /// Removes a scheduler from the group. - /// The scheduler to be removed. - private void RemoveQueue_NeedsLock(QueuedTaskSchedulerQueue queue) - { - // Find the group that contains the queue and the queue's index within the group - var queueGroup = _queueGroups[queue._priority]; - int index = queueGroup.IndexOf(queue); - - // We're about to remove the queue, so adjust the index of the next - // round-robin starting location if it'll be affected by the removal - if (queueGroup.NextQueueIndex >= index) queueGroup.NextQueueIndex--; - - // Remove it - queueGroup.RemoveAt(index); - } - - /// A group of queues a the same priority level. - private class QueueGroup : List - { - /// The starting index for the next round-robin traversal. - public int NextQueueIndex = 0; - - /// Creates a search order through this group. - /// An enumerable of indices for this group. - public IEnumerable CreateSearchOrder() - { - for (int i = NextQueueIndex; i < Count; i++) yield return i; - for (int i = 0; i < NextQueueIndex; i++) yield return i; - } - } - - /// Provides a scheduling queue associatd with a QueuedTaskScheduler. - [DebuggerDisplay("QueuePriority = {_priority}, WaitingTasks = {WaitingTasks}")] - [DebuggerTypeProxy(typeof(QueuedTaskSchedulerQueueDebugView))] - private sealed class QueuedTaskSchedulerQueue : TaskScheduler, IDisposable - { - /// A debug view for the queue. - private sealed class QueuedTaskSchedulerQueueDebugView - { - /// The queue. - private readonly QueuedTaskSchedulerQueue _queue; - - /// Initializes the debug view. - /// The queue to be debugged. - public QueuedTaskSchedulerQueueDebugView(QueuedTaskSchedulerQueue queue) - { - if (queue == null) throw new ArgumentNullException("queue"); - _queue = queue; - } - - /// Gets the priority of this queue in its associated scheduler. - public int Priority { get { return _queue._priority; } } - /// Gets the ID of this scheduler. - public int Id { get { return _queue.Id; } } - /// Gets all of the tasks scheduled to this queue. - public IEnumerable ScheduledTasks { get { return _queue.GetScheduledTasks(); } } - /// Gets the QueuedTaskScheduler with which this queue is associated. - public QueuedTaskScheduler AssociatedScheduler { get { return _queue._pool; } } - } - - /// The scheduler with which this pool is associated. - private readonly QueuedTaskScheduler _pool; - /// The work items stored in this queue. - internal readonly Queue _workItems; - /// Whether this queue has been disposed. - internal bool _disposed; - /// Gets the priority for this queue. - internal int _priority; - - /// Initializes the queue. - /// The priority associated with this queue. - /// The scheduler with which this queue is associated. - internal QueuedTaskSchedulerQueue(int priority, QueuedTaskScheduler pool) - { - _priority = priority; - _pool = pool; - _workItems = new Queue(); - } - - /// Gets the number of tasks waiting in this scheduler. - internal int WaitingTasks { get { return _workItems.Count; } } - - /// Gets the tasks scheduled to this scheduler. - /// An enumerable of all tasks queued to this scheduler. - protected override IEnumerable GetScheduledTasks() { return _workItems.ToList(); } - - /// Queues a task to the scheduler. - /// The task to be queued. - protected override void QueueTask(Task task) - { - if (_disposed) throw new ObjectDisposedException(GetType().Name); - - // Queue up the task locally to this queue, and then notify - // the parent scheduler that there's work available - lock (_pool._queueGroups) _workItems.Enqueue(task); - _pool.NotifyNewWorkItem(); - } - - /// Tries to execute a task synchronously on the current thread. - /// The task to execute. - /// Whether the task was previously queued. - /// true if the task was executed; otherwise, false. - protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued) - { - // If we're using our own threads and if this is being called from one of them, - // or if we're currently processing another task on this thread, try running it inline. - return _taskProcessingThread.Value && TryExecuteTask(task); - } - - /// Runs the specified ask. - /// The task to execute. - internal void ExecuteTask(Task task) { TryExecuteTask(task); } - - /// Gets the maximum concurrency level to use when processing tasks. - public override int MaximumConcurrencyLevel { get { return _pool.MaximumConcurrencyLevel; } } - - /// Signals that the queue should be removed from the scheduler as soon as the queue is empty. - public void Dispose() - { - if (!_disposed) - { - lock (_pool._queueGroups) - { - // We only remove the queue if it's empty. If it's not empty, - // we still mark it as disposed, and the associated QueuedTaskScheduler - // will remove the queue when its count hits 0 and its _disposed is true. - if (_workItems.Count == 0) - { - _pool.RemoveQueue_NeedsLock(this); - } - } - _disposed = true; - } - } - } - } -} \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TestBitSet.cs b/runtime/CSharp/Antlr4.Runtime.Test/TestBitSet.cs deleted file mode 100644 index a289f3404..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/TestBitSet.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace Antlr4.Runtime.Test -{ - using Microsoft.VisualStudio.TestTools.UnitTesting; - using Sharpen; - - [TestClass] - public class TestBitSet - { - [TestMethod] - public void TestCardinality1() - { - BitSet set = new BitSet(); - Assert.AreEqual(0, set.Cardinality()); - for (int i = 0; i < 128; i++) - { - set.Set(i); - Assert.AreEqual(i + 1, set.Cardinality()); - Assert.AreEqual(0, set.NextSetBit(0)); - if (i > 0) - Assert.AreEqual(i * 1 - 1, set.NextSetBit(i * 1 - 1)); - } - } - - [TestMethod] - public void TestCardinality2() - { - BitSet set = new BitSet(); - Assert.AreEqual(0, set.Cardinality()); - for (int i = 0; i < 128; i++) - { - set.Set(i * 2); - Assert.AreEqual(i + 1, set.Cardinality()); - Assert.AreEqual(0, set.NextSetBit(0)); - if (i > 0) - Assert.AreEqual(i * 2, set.NextSetBit(i * 2 - 1)); - } - } - - [TestMethod] - public void TestCardinality7() - { - BitSet set = new BitSet(); - Assert.AreEqual(0, set.Cardinality()); - for (int i = 0; i < 128; i++) - { - set.Set(i * 7); - Assert.AreEqual(i + 1, set.Cardinality()); - Assert.AreEqual(0, set.NextSetBit(0)); - if (i > 0) - Assert.AreEqual(i * 7, set.NextSetBit(i * 7 - 1)); - } - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime.Test/TestGraphNodes.cs b/runtime/CSharp/Antlr4.Runtime.Test/TestGraphNodes.cs deleted file mode 100644 index 41acd1eb0..000000000 --- a/runtime/CSharp/Antlr4.Runtime.Test/TestGraphNodes.cs +++ /dev/null @@ -1,1046 +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.Runtime.CompilerServices; - using System.Text; - using Antlr4.Runtime.Atn; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class TestGraphNodes - { - private PredictionContextCache _contextCache; - - [TestInitialize] - public void SetUp() - { - _contextCache = new PredictionContextCache(); - } - - public bool RootIsWildcard - { - get - { - return true; - } - } - - public bool FullContext - { - get - { - return false; - } - } - - [TestMethod] - public void Test_dollar_dollar() - { - PredictionContext r = _contextCache.Join(PredictionContext.EmptyLocal, - PredictionContext.EmptyLocal); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"*\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_dollar_dollar_fullctx() - { - PredictionContext r = _contextCache.Join(PredictionContext.EmptyFull, - PredictionContext.EmptyFull); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"$\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_x_dollar() - { - PredictionContext r = _contextCache.Join(X(false), PredictionContext.EmptyLocal); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"*\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_x_dollar_fullctx() - { - PredictionContext r = _contextCache.Join(X(true), PredictionContext.EmptyFull); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|$\"];" + Environment.NewLine + - " s1[label=\"$\"];" + Environment.NewLine + - " s0:p0->s1[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_dollar_x() - { - PredictionContext r = _contextCache.Join(PredictionContext.EmptyLocal, X(false)); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"*\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_dollar_x_fullctx() - { - PredictionContext r = _contextCache.Join(PredictionContext.EmptyFull, X(true)); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|$\"];" + Environment.NewLine + - " s1[label=\"$\"];" + Environment.NewLine + - " s0:p0->s1[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_a_a() - { - PredictionContext r = _contextCache.Join(A(false), A(false)); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_adollar_ax() - { - PredictionContext a1 = A(false); - PredictionContext x = X(false); - PredictionContext a2 = CreateSingleton(x, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_adollar_ax_fullctx() - { - PredictionContext a1 = A(true); - PredictionContext x = X(true); - PredictionContext a2 = CreateSingleton(x, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[shape=record, label=\"|$\"];" + Environment.NewLine + - " s2[label=\"$\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1:p0->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_axdollar_adollar() - { - PredictionContext x = X(false); - PredictionContext a1 = CreateSingleton(x, 1); - PredictionContext a2 = A(false); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_aadollar_adollar_dollar_fullCtx() - { - PredictionContext empty = PredictionContext.EmptyFull; - PredictionContext child1 = CreateSingleton(empty, 8); - PredictionContext right = _contextCache.Join(empty, child1); - PredictionContext left = CreateSingleton(right, 8); - PredictionContext merged = _contextCache.Join(left, right); - String actual = ToDotString(merged); - Console.WriteLine(actual); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|$\"];" + Environment.NewLine + - " s1[shape=record, label=\"|$\"];" + Environment.NewLine + - " s2[label=\"$\"];" + Environment.NewLine + - " s0:p0->s1[label=\"8\"];" + Environment.NewLine + - " s1:p0->s2[label=\"8\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, actual); - } - - [TestMethod] - public void Test_axdollar_adollar_fullctx() - { - PredictionContext x = X(true); - PredictionContext a1 = CreateSingleton(x, 1); - PredictionContext a2 = A(true); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[shape=record, label=\"|$\"];" + Environment.NewLine + - " s2[label=\"$\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1:p0->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_a_b() - { - PredictionContext r = _contextCache.Join(A(false), B(false)); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_ax_ax_same() - { - PredictionContext x = X(false); - PredictionContext a1 = CreateSingleton(x, 1); - PredictionContext a2 = CreateSingleton(x, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_ax_ax() - { - PredictionContext x1 = X(false); - PredictionContext x2 = X(false); - PredictionContext a1 = CreateSingleton(x1, 1); - PredictionContext a2 = CreateSingleton(x2, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_abx_abx() - { - PredictionContext x1 = X(false); - PredictionContext x2 = X(false); - PredictionContext b1 = CreateSingleton(x1, 2); - PredictionContext b2 = CreateSingleton(x2, 2); - PredictionContext a1 = CreateSingleton(b1, 1); - PredictionContext a2 = CreateSingleton(b2, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s3[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_abx_acx() - { - PredictionContext x1 = X(false); - PredictionContext x2 = X(false); - PredictionContext b = CreateSingleton(x1, 2); - PredictionContext c = CreateSingleton(x2, 3); - PredictionContext a1 = CreateSingleton(b, 1); - PredictionContext a2 = CreateSingleton(c, 1); - PredictionContext r = _contextCache.Join(a1, a2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1:p0->s2[label=\"2\"];" + Environment.NewLine + - " s1:p1->s2[label=\"3\"];" + Environment.NewLine + - " s2->s3[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_ax_bx_same() - { - PredictionContext x = X(false); - PredictionContext a = CreateSingleton(x, 1); - PredictionContext b = CreateSingleton(x, 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s1->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_ax_bx() - { - PredictionContext x1 = X(false); - PredictionContext x2 = X(false); - PredictionContext a = CreateSingleton(x1, 1); - PredictionContext b = CreateSingleton(x2, 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s1->s2[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_ax_by() - { - PredictionContext a = CreateSingleton(X(false), 1); - PredictionContext b = CreateSingleton(Y(false), 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"*\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s3[label=\"10\"];" + Environment.NewLine + - " s1->s3[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_adollar_bx() - { - PredictionContext x2 = X(false); - PredictionContext a = A(false); - PredictionContext b = CreateSingleton(x2, 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s1[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_adollar_bx_fullctx() - { - PredictionContext x2 = X(true); - PredictionContext a = A(true); - PredictionContext b = CreateSingleton(x2, 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s1[label=\"$\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s1[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_aex_bfx() - { - PredictionContext x1 = X(false); - PredictionContext x2 = X(false); - PredictionContext e = CreateSingleton(x1, 5); - PredictionContext f = CreateSingleton(x2, 6); - PredictionContext a = CreateSingleton(e, 1); - PredictionContext b = CreateSingleton(f, 2); - PredictionContext r = _contextCache.Join(a, b); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"3\"];" + Environment.NewLine + - " s4[label=\"*\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s3[label=\"6\"];" + Environment.NewLine + - " s3->s4[label=\"9\"];" + Environment.NewLine + - " s1->s3[label=\"5\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - // Array merges - - [TestMethod] - public void Test_Adollar_Adollar_fullctx() - { - PredictionContext A1 = Array(PredictionContext.EmptyFull); - PredictionContext A2 = Array(PredictionContext.EmptyFull); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"$\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aab_Ac() - { // a,b + c - PredictionContext a = A(false); - PredictionContext b = B(false); - PredictionContext c = C(false); - PredictionContext A1 = Array(a, b); - PredictionContext A2 = Array(c); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s0:p2->s1[label=\"3\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aa_Aa() - { - PredictionContext a1 = A(false); - PredictionContext a2 = A(false); - PredictionContext A1 = Array(a1); - PredictionContext A2 = Array(a2); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aa_Abc() - { // a + b,c - PredictionContext a = A(false); - PredictionContext b = B(false); - PredictionContext c = C(false); - PredictionContext A1 = Array(a); - PredictionContext A2 = Array(b, c); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s0:p2->s1[label=\"3\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aac_Ab() - { // a,c + b - PredictionContext a = A(false); - PredictionContext b = B(false); - PredictionContext c = C(false); - PredictionContext A1 = Array(a, c); - PredictionContext A2 = Array(b); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s0:p2->s1[label=\"3\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aab_Aa() - { // a,b + a - PredictionContext A1 = Array(A(false), B(false)); - PredictionContext A2 = Array(A(false)); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aab_Ab() - { // a,b + b - PredictionContext A1 = Array(A(false), B(false)); - PredictionContext A2 = Array(B(false)); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aax_Aby() - { // ax + by but in arrays - PredictionContext a = CreateSingleton(X(false), 1); - PredictionContext b = CreateSingleton(Y(false), 2); - PredictionContext A1 = Array(a); - PredictionContext A2 = Array(b); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"*\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s2->s3[label=\"10\"];" + Environment.NewLine + - " s1->s3[label=\"9\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aax_Aay() - { // ax + ay -> merged singleton a, array parent - PredictionContext a1 = CreateSingleton(X(false), 1); - PredictionContext a2 = CreateSingleton(Y(false), 1); - PredictionContext A1 = Array(a1); - PredictionContext A2 = Array(a2); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[label=\"0\"];" + Environment.NewLine + - " s1[shape=record, label=\"|\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0->s1[label=\"1\"];" + Environment.NewLine + - " s1:p0->s2[label=\"9\"];" + Environment.NewLine + - " s1:p1->s2[label=\"10\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaxc_Aayd() - { // ax,c + ay,d -> merged a, array parent - PredictionContext a1 = CreateSingleton(X(false), 1); - PredictionContext a2 = CreateSingleton(Y(false), 1); - PredictionContext A1 = Array(a1, C(false)); - PredictionContext A2 = Array(a2, D(false)); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s1[shape=record, label=\"|\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"3\"];" + Environment.NewLine + - " s0:p2->s2[label=\"4\"];" + Environment.NewLine + - " s1:p0->s2[label=\"9\"];" + Environment.NewLine + - " s1:p1->s2[label=\"10\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaubv_Acwdx() - { // au,bv + cw,dx -> [a,b,c,d]->[u,v,w,x] - PredictionContext a = CreateSingleton(U(false), 1); - PredictionContext b = CreateSingleton(V(false), 2); - PredictionContext c = CreateSingleton(W(false), 3); - PredictionContext d = CreateSingleton(X(false), 4); - PredictionContext A1 = Array(a, b); - PredictionContext A2 = Array(c, d); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|||\"];" + Environment.NewLine + - " s4[label=\"4\"];" + Environment.NewLine + - " s5[label=\"*\"];" + Environment.NewLine + - " s3[label=\"3\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s0:p2->s3[label=\"3\"];" + Environment.NewLine + - " s0:p3->s4[label=\"4\"];" + Environment.NewLine + - " s4->s5[label=\"9\"];" + Environment.NewLine + - " s3->s5[label=\"8\"];" + Environment.NewLine + - " s2->s5[label=\"7\"];" + Environment.NewLine + - " s1->s5[label=\"6\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaubv_Abvdx() - { // au,bv + bv,dx -> [a,b,d]->[u,v,x] - PredictionContext a = CreateSingleton(U(false), 1); - PredictionContext b1 = CreateSingleton(V(false), 2); - PredictionContext b2 = CreateSingleton(V(false), 2); - PredictionContext d = CreateSingleton(X(false), 4); - PredictionContext A1 = Array(a, b1); - PredictionContext A2 = Array(b2, d); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s3[label=\"3\"];" + Environment.NewLine + - " s4[label=\"*\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s0:p2->s3[label=\"4\"];" + Environment.NewLine + - " s3->s4[label=\"9\"];" + Environment.NewLine + - " s2->s4[label=\"7\"];" + Environment.NewLine + - " s1->s4[label=\"6\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaubv_Abwdx() - { // au,bv + bw,dx -> [a,b,d]->[u,[v,w],x] - PredictionContext a = CreateSingleton(U(false), 1); - PredictionContext b1 = CreateSingleton(V(false), 2); - PredictionContext b2 = CreateSingleton(W(false), 2); - PredictionContext d = CreateSingleton(X(false), 4); - PredictionContext A1 = Array(a, b1); - PredictionContext A2 = Array(b2, d); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s3[label=\"3\"];" + Environment.NewLine + - " s4[label=\"*\"];" + Environment.NewLine + - " s2[shape=record, label=\"|\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s0:p2->s3[label=\"4\"];" + Environment.NewLine + - " s3->s4[label=\"9\"];" + Environment.NewLine + - " s2:p0->s4[label=\"7\"];" + Environment.NewLine + - " s2:p1->s4[label=\"8\"];" + Environment.NewLine + - " s1->s4[label=\"6\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaubv_Abvdu() - { // au,bv + bv,du -> [a,b,d]->[u,v,u]; u,v shared - PredictionContext a = CreateSingleton(U(false), 1); - PredictionContext b1 = CreateSingleton(V(false), 2); - PredictionContext b2 = CreateSingleton(V(false), 2); - PredictionContext d = CreateSingleton(U(false), 4); - PredictionContext A1 = Array(a, b1); - PredictionContext A2 = Array(b2, d); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"||\"];" + Environment.NewLine + - " s2[label=\"2\"];" + Environment.NewLine + - " s3[label=\"*\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s2[label=\"2\"];" + Environment.NewLine + - " s0:p2->s1[label=\"4\"];" + Environment.NewLine + - " s2->s3[label=\"7\"];" + Environment.NewLine + - " s1->s3[label=\"6\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - [TestMethod] - public void Test_Aaubu_Acudu() - { // au,bu + cu,du -> [a,b,c,d]->[u,u,u,u] - PredictionContext a = CreateSingleton(U(false), 1); - PredictionContext b = CreateSingleton(U(false), 2); - PredictionContext c = CreateSingleton(U(false), 3); - PredictionContext d = CreateSingleton(U(false), 4); - PredictionContext A1 = Array(a, b); - PredictionContext A2 = Array(c, d); - PredictionContext r = _contextCache.Join(A1, A2); - Console.WriteLine(ToDotString(r)); - String expecting = - "digraph G {" + Environment.NewLine + - "rankdir=LR;" + Environment.NewLine + - " s0[shape=record, label=\"|||\"];" + Environment.NewLine + - " s1[label=\"1\"];" + Environment.NewLine + - " s2[label=\"*\"];" + Environment.NewLine + - " s0:p0->s1[label=\"1\"];" + Environment.NewLine + - " s0:p1->s1[label=\"2\"];" + Environment.NewLine + - " s0:p2->s1[label=\"3\"];" + Environment.NewLine + - " s0:p3->s1[label=\"4\"];" + Environment.NewLine + - " s1->s2[label=\"6\"];" + Environment.NewLine + - "}" + Environment.NewLine; - Assert.AreEqual(expecting, ToDotString(r)); - } - - - // ------------ SUPPORT ------------------------- - - protected PredictionContext A(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 1); - } - - private PredictionContext B(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 2); - } - - private PredictionContext C(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 3); - } - - private PredictionContext D(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 4); - } - - private PredictionContext U(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 6); - } - - private PredictionContext V(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 7); - } - - private PredictionContext W(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 8); - } - - private PredictionContext X(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 9); - } - - private PredictionContext Y(bool fullContext) - { - return CreateSingleton(fullContext ? PredictionContext.EmptyFull : PredictionContext.EmptyLocal, 10); - } - - public PredictionContext CreateSingleton(PredictionContext parent, int payload) - { - PredictionContext a = _contextCache.GetChild(parent, payload); - return a; - } - - public PredictionContext Array(params PredictionContext[] nodes) - { - PredictionContext result = nodes[0]; - for (int i = 1; i < nodes.Length; i++) - { - result = _contextCache.Join(result, nodes[i]); - } - - return result; - } - - private static String ToDotString(PredictionContext context) - { - StringBuilder nodes = new StringBuilder(); - StringBuilder edges = new StringBuilder(); - IDictionary visited = new IdentityHashMap(); - IDictionary contextIds = new IdentityHashMap(); - Stack workList = new Stack(); - visited[context] = context; - contextIds[context] = contextIds.Count; - workList.Push(context); - while (workList.Count > 0) - { - PredictionContext current = workList.Pop(); - nodes.Append(" s").Append(contextIds[current]).Append('['); - - if (current.Size > 1) - { - nodes.Append("shape=record, "); - } - - nodes.Append("label=\""); - - if (current.IsEmpty) - { - nodes.Append(PredictionContext.IsEmptyLocal(current) ? '*' : '$'); - } - else if (current.Size > 1) - { - for (int i = 0; i < current.Size; i++) - { - if (i > 0) - { - nodes.Append('|'); - } - - nodes.Append("'); - 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 @@ 4 1591 - - 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 other = (Antlr4.Runtime.Misc.Array2DHashSet)o; - if (other.Count != Count) - { - return false; - } - bool same = this.ContainsAll(other); - return same; - } - - protected internal virtual void Expand() - { - T[][] old = buckets; - currentPrime += 4; - int newCapacity = buckets.Length * 2; - T[][] newTable = CreateBuckets(newCapacity); - int[] newBucketLengths = new int[newTable.Length]; - buckets = newTable; - threshold = (int)(newCapacity * LoadFactor); - // System.out.println("new size="+newCapacity+", thres="+threshold); - // rehash all existing entries - int oldSize = Count; - foreach (T[] bucket in old) - { - if (bucket == null) - { - continue; - } - foreach (T o in bucket) - { - if (o == null) - { - break; - } - int b = GetBucket(o); - int bucketLength = newBucketLengths[b]; - T[] newBucket; - if (bucketLength == 0) - { - // new bucket - newBucket = CreateBucket(initialBucketCapacity); - newTable[b] = newBucket; - } - else - { - newBucket = newTable[b]; - if (bucketLength == newBucket.Length) - { - // expand - newBucket = Arrays.CopyOf(newBucket, newBucket.Length * 2); - newTable[b] = newBucket; - } - } - newBucket[bucketLength] = o; - newBucketLengths[b]++; - } - } - System.Diagnostics.Debug.Assert(n == oldSize); - } - - public bool Add(T t) - { - T existing = GetOrAdd(t); - return existing == t; - } - - public int Count - { - get - { - return n; - } - } - - public bool IsEmpty() - { - return n == 0; - } - - public bool Contains(object o) - { - return ContainsFast(AsElementType(o)); - } - - public virtual bool ContainsFast(T obj) - { - if (obj == null) - { - return false; - } - return Get(obj) != null; - } - - public virtual IEnumerator GetEnumerator() - { - return new Array2DHashSet.SetIterator(this, Sharpen.Collections.ToArray(this)); - } - - public virtual T[] ToArray() - { - T[] a = CreateBucket(Count); - int i = 0; - foreach (T[] bucket in buckets) - { - if (bucket == null) - { - continue; - } - foreach (T o in bucket) - { - if (o == null) - { - break; - } - a[i++] = o; - } - } - return a; - } - - public virtual U[] ToArray(U[] a) - { - if (a.Length < Count) - { - a = Arrays.CopyOf(a, Count); - } - int i = 0; - foreach (T[] bucket in buckets) - { - if (bucket == null) - { - continue; - } - foreach (T o in bucket) - { - if (o == null) - { - break; - } - U targetElement = (U)o; - // array store will check this - a[i++] = targetElement; - } - } - return a; - } - - public bool Remove(object o) - { - return RemoveFast(AsElementType(o)); - } - - public virtual bool RemoveFast(T obj) - { - if (obj == null) - { - return false; - } - int b = GetBucket(obj); - T[] bucket = buckets[b]; - if (bucket == null) - { - // no bucket - return false; - } - for (int i = 0; i < bucket.Length; i++) - { - T e = bucket[i]; - if (e == null) - { - // empty slot; not there - return false; - } - if (comparator.Equals(e, obj)) - { - // found it - // shift all elements to the right down one - System.Array.Copy(bucket, i + 1, bucket, i, bucket.Length - i - 1); - bucket[bucket.Length - 1] = null; - n--; - return true; - } - } - return false; - } - - public virtual bool ContainsAll<_T0>(ICollection<_T0> collection) - { - if (collection is Antlr4.Runtime.Misc.Array2DHashSet) - { - Antlr4.Runtime.Misc.Array2DHashSet s = (Antlr4.Runtime.Misc.Array2DHashSet)collection; - foreach (object[] bucket in s.buckets) - { - if (bucket == null) - { - continue; - } - foreach (object o in bucket) - { - if (o == null) - { - break; - } - if (!this.ContainsFast(AsElementType(o))) - { - return false; - } - } - } - } - else - { - foreach (object o in collection) - { - if (!this.ContainsFast(AsElementType(o))) - { - return false; - } - } - } - return true; - } - - public virtual bool AddAll<_T0>(ICollection<_T0> c) - where _T0 : T - { - bool changed = false; - foreach (T o in c) - { - T existing = GetOrAdd(o); - if (existing != o) - { - changed = true; - } - } - return changed; - } - - public virtual bool RetainAll<_T0>(ICollection<_T0> c) - { - int newsize = 0; - foreach (T[] bucket in buckets) - { - if (bucket == null) - { - continue; - } - int i; - int j; - for (i = 0, j = 0; i < bucket.Length; i++) - { - if (bucket[i] == null) - { - break; - } - if (!c.Contains(bucket[i])) - { - // removed - continue; - } - // keep - if (i != j) - { - bucket[j] = bucket[i]; - } - j++; - newsize++; - } - newsize += j; - while (j < i) - { - bucket[j] = null; - j++; - } - } - bool changed = newsize != n; - n = newsize; - return changed; - } - - public virtual bool RemoveAll<_T0>(ICollection<_T0> c) - { - bool changed = false; - foreach (object o in c) - { - changed |= RemoveFast(AsElementType(o)); - } - return changed; - } - - public virtual void Clear() - { - buckets = CreateBuckets(InitalCapacity); - n = 0; - } - - public override string ToString() - { - if (Count == 0) - { - return "{}"; - } - StringBuilder buf = new StringBuilder(); - buf.Append('{'); - bool first = true; - foreach (T[] bucket in buckets) - { - if (bucket == null) - { - continue; - } - foreach (T o in bucket) - { - if (o == null) - { - break; - } - if (first) - { - first = false; - } - else - { - buf.Append(", "); - } - buf.Append(o.ToString()); - } - } - buf.Append('}'); - return buf.ToString(); - } - - public virtual string ToTableString() - { - StringBuilder buf = new StringBuilder(); - foreach (T[] bucket in buckets) - { - if (bucket == null) - { - buf.Append("null\n"); - continue; - } - buf.Append('['); - bool first = true; - foreach (T o in bucket) - { - if (first) - { - first = false; - } - else - { - buf.Append(" "); - } - if (o == null) - { - buf.Append("_"); - } - else - { - buf.Append(o.ToString()); - } - } - buf.Append("]\n"); - } - return buf.ToString(); - } - - /// - /// Return - /// - /// as an instance of the element type - /// T - /// . If - /// - /// is non-null but known to not be an instance of - /// T - /// , this - /// method returns - /// - /// . The base implementation does not perform any - /// type checks; override this method to provide strong type checks for the - /// - /// and - /// - /// methods to ensure the arguments to - /// the - /// - /// for the set always have the expected - /// types. - /// - /// the object to try and cast to the element type of the set - /// - /// - /// - /// if it could be an instance of - /// T - /// , otherwise - /// - /// . - /// - protected internal virtual T AsElementType(object o) - { - return (T)o; - } - - /// - /// Return an array of - /// T[] - /// with length - /// - /// . - /// - /// the length of the array to return - /// the newly constructed array - protected internal virtual T[][] CreateBuckets(int capacity) - { - return new T[capacity][]; - } - - /// - /// Return an array of - /// T - /// with length - /// - /// . - /// - /// the length of the array to return - /// the newly constructed array - protected internal virtual T[] CreateBucket(int capacity) - { - return new T[capacity]; - } - - protected internal class SetIterator : IEnumerator - { - internal readonly T[] data; - - internal int nextIndex = 0; - - internal bool removed = true; - - public SetIterator(Array2DHashSet _enclosing, T[] data) - { - this._enclosing = _enclosing; - this.data = data; - } - - public virtual bool HasNext() - { - return this.nextIndex < this.data.Length; - } - - public virtual T Next() - { - if (!this.HasNext()) - { - throw new InvalidOperationException(); - } - this.removed = false; - return this.data[this.nextIndex++]; - } - - public virtual void Remove() - { - if (this.removed) - { - throw new InvalidOperationException(); - } - this._enclosing._enclosing.Remove(this.data[this.nextIndex - 1]); - this.removed = true; - } - - private readonly Array2DHashSet _enclosing; - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs b/runtime/CSharp/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs deleted file mode 100644 index c061597f0..000000000 --- a/runtime/CSharp/Antlr4.Runtime/Misc/DoubleKeyMap`3.cs +++ /dev/null @@ -1,106 +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.Collections.Generic; -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Sharpen; - -namespace Antlr4.Runtime.Misc -{ - /// Sometimes we need to map a key to a value but key is two pieces of data. - /// - /// Sometimes we need to map a key to a value but key is two pieces of data. - /// This nested hash table saves creating a single key each time we access - /// map; avoids mem creation. - /// - public class DoubleKeyMap - { - internal IDictionary> data = new LinkedHashMap>(); - - public virtual Value Put(Key1 k1, Key2 k2, Value v) - { - IDictionary data2 = data.Get(k1); - Value prev = null; - if (data2 == null) - { - data2 = new LinkedHashMap(); - data.Put(k1, data2); - } - else - { - prev = data2.Get(k2); - } - data2.Put(k2, v); - return prev; - } - - public virtual Value Get(Key1 k1, Key2 k2) - { - IDictionary data2 = data.Get(k1); - if (data2 == null) - { - return null; - } - return data2.Get(k2); - } - - public virtual IDictionary Get(Key1 k1) - { - return data.Get(k1); - } - - /// Get all values associated with primary key - public virtual ICollection Values(Key1 k1) - { - IDictionary data2 = data.Get(k1); - if (data2 == null) - { - return null; - } - return data2.Values; - } - - /// get all primary keys - public virtual HashSet KeySet() - { - return data.Keys; - } - - /// get all secondary keys associated with a primary key - public virtual HashSet KeySet(Key1 k1) - { - IDictionary data2 = data.Get(k1); - if (data2 == null) - { - return null; - } - return data2.Keys; - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/OrderedHashSet`1.cs b/runtime/CSharp/Antlr4.Runtime/Misc/OrderedHashSet`1.cs deleted file mode 100644 index 37de8630e..000000000 --- a/runtime/CSharp/Antlr4.Runtime/Misc/OrderedHashSet`1.cs +++ /dev/null @@ -1,166 +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 Antlr4.Runtime.Misc; -using Antlr4.Runtime.Sharpen; - -namespace Antlr4.Runtime.Misc -{ - /// A HashMap that remembers the order that the elements were added. - /// - /// A HashMap that remembers the order that the elements were added. - /// You can alter the ith element with set(i,value) too :) Unique list. - /// I need the replace/set-element-i functionality so I'm subclassing - /// LinkedHashSet. - /// - [System.Serializable] - public class OrderedHashSet : LinkedHashSet - { - private const long serialVersionUID = 5281944403755906761L; - - /// Track the elements as they are added to the set - protected internal List elements = new List(); - - public virtual T Get(int i) - { - return elements[i]; - } - - /// - /// Replace an existing value with a new value; updates the element - /// list and the hash table, but not the key as that has not changed. - /// - /// - /// Replace an existing value with a new value; updates the element - /// list and the hash table, but not the key as that has not changed. - /// - public virtual T Set(int i, T value) - { - T oldElement = elements[i]; - elements.Set(i, value); - // update list - base.Remove(oldElement); - // now update the set: remove/add - base.Add(value); - return oldElement; - } - - public virtual bool Remove(int i) - { - T o = elements.RemoveAt(i); - return base.Remove(o); - } - - /// - /// Add a value to list; keep in hashtable for consistency also; - /// Key is object itself. - /// - /// - /// Add a value to list; keep in hashtable for consistency also; - /// Key is object itself. Good for say asking if a certain string is in - /// a list of strings. - /// - public override bool Add(T value) - { - bool result = base.Add(value); - if (result) - { - // only track if new element not in set - elements.Add(value); - } - return result; - } - - public override bool Remove(object o) - { - throw new NotSupportedException(); - } - - public override void Clear() - { - elements.Clear(); - base.Clear(); - } - - public override int GetHashCode() - { - return elements.GetHashCode(); - } - - public override bool Equals(object o) - { - if (!(o is OrderedHashSet)) - { - return false; - } - // System.out.print("equals " + this + ", " + o+" = "); - bool same = elements != null && elements.Equals(((OrderedHashSet)o).elements); - // System.out.println(same); - return same; - } - - public override IEnumerator GetEnumerator() - { - return elements.GetEnumerator(); - } - - /// Return the List holding list of table elements. - /// - /// Return the List holding list of table elements. Note that you are - /// NOT getting a copy so don't write to the list. - /// - public virtual IList Elements - { - get - { - return elements; - } - } - - public override object Clone() - { - OrderedHashSet dup = (OrderedHashSet)base.Clone(); - // safe (result of clone) - dup.elements = new List(this.elements); - return dup; - } - - public override object[] ToArray() - { - return Sharpen.Collections.ToArray(elements); - } - - public override string ToString() - { - return elements.ToString(); - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs b/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs deleted file mode 100644 index 887626544..000000000 --- a/runtime/CSharp/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs +++ /dev/null @@ -1,789 +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; -using System.Collections.Generic; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Sharpen; -using Antlr4.Runtime.Sharpen.Annotation; -using Javax.Annotation.Processing; -using Javax.Lang.Model; -using Javax.Lang.Model.Element; -using Javax.Lang.Model.Type; -using Javax.Tools; - -namespace Antlr4.Runtime.Misc -{ - /// A compile-time validator for rule dependencies. - /// A compile-time validator for rule dependencies. - /// - /// - /// Sam Harwell - public class RuleDependencyProcessor : AbstractProcessor - { - public const string RuleDependencyClassName = "org.antlr.v4.runtime.RuleDependency"; - - public const string RuleDependenciesClassName = "org.antlr.v4.runtime.RuleDependencies"; - - public const string RuleVersionClassName = "org.antlr.v4.runtime.RuleVersion"; - - public RuleDependencyProcessor() - { - } - - public override SourceVersion GetSupportedSourceVersion() - { - SourceVersion latestSupported = SourceVersion.LatestSupported(); - if ((int)(latestSupported) <= 6) - { - return SourceVersion.Release6; - } - else - { - if ((int)(latestSupported) <= 8) - { - return latestSupported; - } - else - { - // this annotation processor is tested through Java 8 - return SourceVersion.Values()[8]; - } - } - } - - public override bool Process<_T0>(HashSet<_T0> annotations, IRoundEnvironment roundEnv) - { - if (!CheckClassNameConstants()) - { - return true; - } - IList> dependencies = GetDependencies(roundEnv); - IDictionary>> recognizerDependencies = new Dictionary>>(); - foreach (Tuple dependency in dependencies) - { - ITypeMirror recognizerType = GetRecognizerType(dependency.Item1); - IList> list = recognizerDependencies.Get(recognizerType); - if (list == null) - { - list = new List>(); - recognizerDependencies.Put(recognizerType, list); - } - list.Add(dependency); - } - foreach (KeyValuePair>> entry in recognizerDependencies.EntrySet()) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating {0} dependencies on rules in {1}.", entry.Value.Count, entry.Key.ToString())); - CheckDependencies(entry.Value, entry.Key); - } - return true; - } - - private bool CheckClassNameConstants() - { - bool success = CheckClassNameConstant(RuleDependencyClassName, typeof(RuleDependency)); - success &= CheckClassNameConstant(RuleDependenciesClassName, typeof(RuleDependencies)); - success &= CheckClassNameConstant(RuleVersionClassName, typeof(RuleVersion)); - return success; - } - - private bool CheckClassNameConstant<_T0>(string className, System.Type<_T0> clazz) - { - Args.NotNull("className", className); - Args.NotNull("clazz", clazz); - if (!className.Equals(clazz.GetCanonicalName())) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unable to process rule dependencies due to class name mismatch: {0} != {1}", className, clazz.GetCanonicalName())); - return false; - } - return true; - } - - private static ITypeMirror GetRecognizerType(RuleDependency dependency) - { - try - { - dependency.Recognizer(); - string message = string.Format("Expected {0} to get the {1}.", typeof(MirroredTypeException).Name, typeof(ITypeMirror).Name); - throw new NotSupportedException(message); - } - catch (MirroredTypeException ex) - { - return ex.GetTypeMirror(); - } - } - - private void CheckDependencies(IList> dependencies, ITypeMirror recognizerType) - { - string[] ruleNames = GetRuleNames(recognizerType); - int[] ruleVersions = GetRuleVersions(recognizerType, ruleNames); - RuleDependencyProcessor.RuleRelations relations = ExtractRuleRelations(recognizerType); - foreach (Tuple dependency in dependencies) - { - try - { - if (!processingEnv.GetTypeUtils().IsAssignable(GetRecognizerType(dependency.Item1), recognizerType)) - { - continue; - } - // this is the rule in the dependency set with the highest version number - int effectiveRule = dependency.Item1.Rule(); - if (effectiveRule < 0 || effectiveRule >= ruleVersions.Length) - { - Tuple ruleReferenceElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); - string message = string.Format("Rule dependency on unknown rule {0}@{1} in {2}", dependency.Item1.Rule(), dependency.Item1.Version(), GetRecognizerType(dependency.Item1).ToString()); - if (ruleReferenceElement != null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, ruleReferenceElement.Item1, ruleReferenceElement.Item2); - } - else - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2); - } - continue; - } - EnumSet dependents = EnumSet.Of(Dependents.Self, dependency.Item1.Dependents()); - ReportUnimplementedDependents(dependency, dependents); - BitSet @checked = new BitSet(); - int highestRequiredDependency = CheckDependencyVersion(dependency, ruleNames, ruleVersions, effectiveRule, null); - if (dependents.Contains(Dependents.Parents)) - { - BitSet parents = relations.parents[dependency.Item1.Rule()]; - for (int parent = parents.NextSetBit(0); parent >= 0; parent = parents.NextSetBit(parent + 1)) - { - if (parent < 0 || parent >= ruleVersions.Length || @checked.Get(parent)) - { - continue; - } - @checked.Set(parent); - int required = CheckDependencyVersion(dependency, ruleNames, ruleVersions, parent, "parent"); - highestRequiredDependency = Math.Max(highestRequiredDependency, required); - } - } - if (dependents.Contains(Dependents.Children)) - { - BitSet children = relations.children[dependency.Item1.Rule()]; - for (int child = children.NextSetBit(0); child >= 0; child = children.NextSetBit(child + 1)) - { - if (child < 0 || child >= ruleVersions.Length || @checked.Get(child)) - { - continue; - } - @checked.Set(child); - int required = CheckDependencyVersion(dependency, ruleNames, ruleVersions, child, "child"); - highestRequiredDependency = Math.Max(highestRequiredDependency, required); - } - } - if (dependents.Contains(Dependents.Ancestors)) - { - BitSet ancestors = relations.GetAncestors(dependency.Item1.Rule()); - for (int ancestor = ancestors.NextSetBit(0); ancestor >= 0; ancestor = ancestors.NextSetBit(ancestor + 1)) - { - if (ancestor < 0 || ancestor >= ruleVersions.Length || @checked.Get(ancestor)) - { - continue; - } - @checked.Set(ancestor); - int required = CheckDependencyVersion(dependency, ruleNames, ruleVersions, ancestor, "ancestor"); - highestRequiredDependency = Math.Max(highestRequiredDependency, required); - } - } - if (dependents.Contains(Dependents.Descendants)) - { - BitSet descendants = relations.GetDescendants(dependency.Item1.Rule()); - for (int descendant = descendants.NextSetBit(0); descendant >= 0; descendant = descendants.NextSetBit(descendant + 1)) - { - if (descendant < 0 || descendant >= ruleVersions.Length || @checked.Get(descendant)) - { - continue; - } - @checked.Set(descendant); - int required = CheckDependencyVersion(dependency, ruleNames, ruleVersions, descendant, "descendant"); - highestRequiredDependency = Math.Max(highestRequiredDependency, required); - } - } - int declaredVersion = dependency.Item1.Version(); - if (declaredVersion > highestRequiredDependency) - { - Tuple versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); - string message = string.Format("Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}", ruleNames[dependency.Item1.Rule()], highestRequiredDependency, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); - if (versionElement != null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); - } - else - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2); - } - } - } - catch (AnnotationTypeMismatchException) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, string.Format("Could not validate rule dependencies for element {0}", dependency.Item2.ToString()), dependency.Item2); - } - } - } - - private static readonly HashSet ImplementedDependents = EnumSet.Of(Dependents.Self, Dependents.Parents, Dependents.Children, Dependents.Ancestors, Dependents.Descendants); - - private void ReportUnimplementedDependents(Tuple dependency, EnumSet dependents) - { - EnumSet unimplemented = dependents.Clone(); - unimplemented.RemoveAll(ImplementedDependents); - if (!unimplemented.IsEmpty()) - { - Tuple dependentsElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Dependents); - if (dependentsElement == null) - { - dependentsElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Rule); - } - string message = string.Format("Cannot validate the following dependents of rule {0}: {1}", dependency.Item1.Rule(), unimplemented); - if (dependentsElement != null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency.Item2, dependentsElement.Item1, dependentsElement.Item2); - } - else - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, message, dependency.Item2); - } - } - } - - private int CheckDependencyVersion(Tuple dependency, string[] ruleNames, int[] ruleVersions, int relatedRule, string relation) - { - string ruleName = ruleNames[dependency.Item1.Rule()]; - string path; - if (relation == null) - { - path = ruleName; - } - else - { - string mismatchedRuleName = ruleNames[relatedRule]; - path = string.Format("rule {0} ({1} of {2})", mismatchedRuleName, relation, ruleName); - } - int declaredVersion = dependency.Item1.Version(); - int actualVersion = ruleVersions[relatedRule]; - if (actualVersion > declaredVersion) - { - Tuple versionElement = FindRuleDependencyProperty(dependency, RuleDependencyProcessor.RuleDependencyProperty.Version); - string message = string.Format("Rule dependency version mismatch: {0} has version {1} (expected <= {2}) in {3}", path, actualVersion, declaredVersion, GetRecognizerType(dependency.Item1).ToString()); - if (versionElement != null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2, versionElement.Item1, versionElement.Item2); - } - else - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, dependency.Item2); - } - } - return actualVersion; - } - - private int[] GetRuleVersions(ITypeMirror recognizerClass, string[] ruleNames) - { - int[] versions = new int[ruleNames.Length]; - IList elements = processingEnv.GetElementUtils().GetAllMembers((ITypeElement)processingEnv.GetTypeUtils().AsElement(recognizerClass)); - foreach (IElement element in elements) - { - if (element.GetKind() != ElementKind.Field) - { - continue; - } - IVariableElement field = (IVariableElement)element; - bool isStatic = element.GetModifiers().Contains(Modifier.Static); - object constantValue = field.GetConstantValue(); - bool isInteger = constantValue is int; - string name = field.GetSimpleName().ToString(); - if (isStatic && isInteger && name.StartsWith("RULE_")) - { - try - { - name = Sharpen.Runtime.Substring(name, "RULE_".Length); - if (name.IsEmpty() || !System.Char.IsLower(name[0])) - { - continue; - } - int index = (int)constantValue; - if (index < 0 || index >= versions.Length) - { - string message = string.Format("Rule index {0} for rule '{1}' out of bounds for recognizer {2}.", index, name, recognizerClass.ToString()); - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); - continue; - } - if (name.IndexOf(ATNSimulator.RuleVariantDelimiter) >= 0) - { - // ignore left-factored pseudo-rules - continue; - } - IExecutableElement ruleMethod = GetRuleMethod(recognizerClass, name); - if (ruleMethod == null) - { - string message = string.Format("Could not find rule method for rule '{0}' in recognizer {1}.", name, recognizerClass.ToString()); - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, message, element); - continue; - } - RuleVersion ruleVersion = ruleMethod.GetAnnotation(); - int version = ruleVersion != null ? ruleVersion.Value() : 0; - versions[index] = version; - } - catch (ArgumentException) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, "Exception occurred while validating rule dependencies.", element); - } - } - } - return versions; - } - - private IExecutableElement GetRuleMethod(ITypeMirror recognizerClass, string name) - { - IList elements = processingEnv.GetElementUtils().GetAllMembers((ITypeElement)processingEnv.GetTypeUtils().AsElement(recognizerClass)); - foreach (IElement element in elements) - { - if (element.GetKind() != ElementKind.Method) - { - continue; - } - IExecutableElement method = (IExecutableElement)element; - if (method.GetSimpleName().ContentEquals(name) && HasRuleVersionAnnotation(method)) - { - return method; - } - } - return null; - } - - private bool HasRuleVersionAnnotation(IExecutableElement method) - { - ITypeElement ruleVersionAnnotationElement = processingEnv.GetElementUtils().GetTypeElement(RuleVersionClassName); - if (ruleVersionAnnotationElement == null) - { - return false; - } - foreach (IAnnotationMirror annotation in method.GetAnnotationMirrors()) - { - if (processingEnv.GetTypeUtils().IsSameType(annotation.GetAnnotationType(), ruleVersionAnnotationElement.AsType())) - { - return true; - } - } - return false; - } - - private string[] GetRuleNames(ITypeMirror recognizerClass) - { - IList result = new List(); - IList elements = processingEnv.GetElementUtils().GetAllMembers((ITypeElement)processingEnv.GetTypeUtils().AsElement(recognizerClass)); - foreach (IElement element in elements) - { - if (element.GetKind() != ElementKind.Field) - { - continue; - } - IVariableElement field = (IVariableElement)element; - bool isStatic = element.GetModifiers().Contains(Modifier.Static); - object constantValue = field.GetConstantValue(); - bool isInteger = constantValue is int; - string name = field.GetSimpleName().ToString(); - if (isStatic && isInteger && name.StartsWith("RULE_")) - { - try - { - name = Sharpen.Runtime.Substring(name, "RULE_".Length); - if (name.IsEmpty() || !System.Char.IsLower(name[0])) - { - continue; - } - int index = (int)constantValue; - if (index < 0) - { - continue; - } - while (result.Count <= index) - { - result.Add(string.Empty); - } - result.Set(index, name); - } - catch (ArgumentException) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, "Exception occurred while validating rule dependencies.", element); - } - } - } - return Sharpen.Collections.ToArray(result, new string[result.Count]); - } - - public static IList> GetDependencies(IRoundEnvironment roundEnv) - { - IList> result = new List>(); - HashSet elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependency)); - foreach (IElement element in elements) - { - RuleDependency dependency = element.GetAnnotation(); - if (dependency == null) - { - continue; - } - result.Add(Tuple.Create(dependency, element)); - } - elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependencies)); - foreach (IElement element_1 in elements) - { - RuleDependencies dependencies = element_1.GetAnnotation(); - if (dependencies == null || dependencies.Value() == null) - { - continue; - } - foreach (RuleDependency dependency in dependencies.Value()) - { - result.Add(Tuple.Create(dependency, element_1)); - } - } - return result; - } - - public enum RuleDependencyProperty - { - Recognizer, - Rule, - Version, - Dependents - } - - [Nullable] - private Tuple FindRuleDependencyProperty(Tuple dependency, RuleDependencyProcessor.RuleDependencyProperty property) - { - ITypeElement ruleDependencyTypeElement = processingEnv.GetElementUtils().GetTypeElement(RuleDependencyClassName); - ITypeElement ruleDependenciesTypeElement = processingEnv.GetElementUtils().GetTypeElement(RuleDependenciesClassName); - IList mirrors = dependency.Item2.GetAnnotationMirrors(); - foreach (IAnnotationMirror annotationMirror in mirrors) - { - if (processingEnv.GetTypeUtils().IsSameType(ruleDependencyTypeElement.AsType(), annotationMirror.GetAnnotationType())) - { - IAnnotationValue element = FindRuleDependencyProperty(dependency, annotationMirror, property); - if (element != null) - { - return Tuple.Create(annotationMirror, element); - } - } - else - { - if (processingEnv.GetTypeUtils().IsSameType(ruleDependenciesTypeElement.AsType(), annotationMirror.GetAnnotationType())) - { - IDictionary values = annotationMirror.GetElementValues(); - foreach (KeyValuePair value in values.EntrySet()) - { - if ("value()".Equals(value.Key.ToString())) - { - IAnnotationValue annotationValue = value.Value; - if (!(annotationValue.GetValue() is IList)) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected array of RuleDependency annotations for annotation property 'value()'.", dependency.Item2, annotationMirror, annotationValue); - break; - } - IList annotationValueList = (IList)annotationValue.GetValue(); - foreach (object obj in annotationValueList) - { - if (!(obj is IAnnotationMirror)) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected RuleDependency annotation mirror for element of property 'value()'.", dependency.Item2, annotationMirror, annotationValue); - break; - } - IAnnotationValue element = FindRuleDependencyProperty(dependency, (IAnnotationMirror)obj, property); - if (element != null) - { - return Tuple.Create((IAnnotationMirror)obj, element); - } - } - } - else - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, string.Format("Unexpected annotation property {0}.", value.Key.ToString()), dependency.Item2, annotationMirror, value.Value); - } - } - } - } - } - return null; - } - - [Nullable] - private IAnnotationValue FindRuleDependencyProperty(Tuple dependency, IAnnotationMirror annotationMirror, RuleDependencyProcessor.RuleDependencyProperty property) - { - IAnnotationValue recognizerValue = null; - IAnnotationValue ruleValue = null; - IAnnotationValue versionValue = null; - IAnnotationValue dependentsValue = null; - IDictionary values = annotationMirror.GetElementValues(); - foreach (KeyValuePair value in values.EntrySet()) - { - IAnnotationValue annotationValue = value.Value; - if ("rule()".Equals(value.Key.ToString())) - { - ruleValue = annotationValue; - if (!(annotationValue.GetValue() is int)) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected int constant for annotation property 'rule()'.", dependency.Item2, annotationMirror, annotationValue); - return null; - } - if ((int)annotationValue.GetValue() != dependency.Item1.Rule()) - { - // this is a valid dependency annotation, but not the one we're looking for - return null; - } - } - else - { - if ("recognizer()".Equals(value.Key.ToString())) - { - recognizerValue = annotationValue; - if (!(annotationValue.GetValue() is ITypeMirror)) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected Class constant for annotation property 'recognizer()'.", dependency.Item2, annotationMirror, annotationValue); - return null; - } - ITypeMirror annotationRecognizer = (ITypeMirror)annotationValue.GetValue(); - ITypeMirror expectedRecognizer = GetRecognizerType(dependency.Item1); - if (!processingEnv.GetTypeUtils().IsSameType(expectedRecognizer, annotationRecognizer)) - { - // this is a valid dependency annotation, but not the one we're looking for - return null; - } - } - else - { - if ("version()".Equals(value.Key.ToString())) - { - versionValue = annotationValue; - if (!(annotationValue.GetValue() is int)) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Expected int constant for annotation property 'version()'.", dependency.Item2, annotationMirror, annotationValue); - return null; - } - if ((int)annotationValue.GetValue() != dependency.Item1.Version()) - { - // this is a valid dependency annotation, but not the one we're looking for - return null; - } - } - } - } - } - if (recognizerValue != null) - { - if (property == RuleDependencyProcessor.RuleDependencyProperty.Recognizer) - { - return recognizerValue; - } - else - { - if (ruleValue != null) - { - if (property == RuleDependencyProcessor.RuleDependencyProperty.Rule) - { - return ruleValue; - } - else - { - if (versionValue != null) - { - if (property == RuleDependencyProcessor.RuleDependencyProperty.Version) - { - return versionValue; - } - else - { - if (property == RuleDependencyProcessor.RuleDependencyProperty.Dependents) - { - return dependentsValue; - } - } - } - } - } - } - } - if (recognizerValue == null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'recognizer()' element in annotation.", dependency.Item2, annotationMirror); - } - if (property == RuleDependencyProcessor.RuleDependencyProperty.Recognizer) - { - return null; - } - if (ruleValue == null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'rule()' element in annotation.", dependency.Item2, annotationMirror); - } - if (property == RuleDependencyProcessor.RuleDependencyProperty.Rule) - { - return null; - } - if (versionValue == null) - { - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Warning, "Could not find 'version()' element in annotation.", dependency.Item2, annotationMirror); - } - return null; - } - - private RuleDependencyProcessor.RuleRelations ExtractRuleRelations(ITypeMirror recognizer) - { - string serializedATN = GetSerializedATN(recognizer); - if (serializedATN == null) - { - return null; - } - ATN atn = new ATNDeserializer().Deserialize(serializedATN.ToCharArray()); - RuleDependencyProcessor.RuleRelations relations = new RuleDependencyProcessor.RuleRelations(atn.ruleToStartState.Length); - foreach (ATNState state in atn.states) - { - if (!state.epsilonOnlyTransitions) - { - continue; - } - foreach (Transition transition in state.Transitions) - { - if (transition.TransitionType != TransitionType.Rule) - { - continue; - } - RuleTransition ruleTransition = (RuleTransition)transition; - relations.AddRuleInvocation(state.ruleIndex, ruleTransition.target.ruleIndex); - } - } - return relations; - } - - private string GetSerializedATN(ITypeMirror recognizerClass) - { - IList elements = processingEnv.GetElementUtils().GetAllMembers((ITypeElement)processingEnv.GetTypeUtils().AsElement(recognizerClass)); - foreach (IElement element in elements) - { - if (element.GetKind() != ElementKind.Field) - { - continue; - } - IVariableElement field = (IVariableElement)element; - bool isStatic = element.GetModifiers().Contains(Modifier.Static); - object constantValue = field.GetConstantValue(); - bool isString = constantValue is string; - string name = field.GetSimpleName().ToString(); - if (isStatic && isString && name.Equals("_serializedATN")) - { - return (string)constantValue; - } - } - processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Error, "Could not retrieve serialized ATN from grammar."); - return null; - } - - private sealed class RuleRelations - { - private readonly BitSet[] parents; - - private readonly BitSet[] children; - - public RuleRelations(int ruleCount) - { - parents = new BitSet[ruleCount]; - for (int i = 0; i < ruleCount; i++) - { - parents[i] = new BitSet(); - } - children = new BitSet[ruleCount]; - for (int i_1 = 0; i_1 < ruleCount; i_1++) - { - children[i_1] = new BitSet(); - } - } - - public bool AddRuleInvocation(int caller, int callee) - { - if (caller < 0) - { - // tokens rule - return false; - } - if (children[caller].Get(callee)) - { - // already added - return false; - } - children[caller].Set(callee); - parents[callee].Set(caller); - return true; - } - - public BitSet GetAncestors(int rule) - { - BitSet ancestors = new BitSet(); - ancestors.Or(parents[rule]); - while (true) - { - int cardinality = ancestors.Cardinality(); - for (int i = ancestors.NextSetBit(0); i >= 0; i = ancestors.NextSetBit(i + 1)) - { - ancestors.Or(parents[i]); - } - if (ancestors.Cardinality() == cardinality) - { - // nothing changed - break; - } - } - return ancestors; - } - - public BitSet GetDescendants(int rule) - { - BitSet descendants = new BitSet(); - descendants.Or(children[rule]); - while (true) - { - int cardinality = descendants.Cardinality(); - for (int i = descendants.NextSetBit(0); i >= 0; i = descendants.NextSetBit(i + 1)) - { - descendants.Or(children[i]); - } - if (descendants.Cardinality() == cardinality) - { - // nothing changed - break; - } - } - return descendants; - } - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime/Misc/TestRig.cs b/runtime/CSharp/Antlr4.Runtime/Misc/TestRig.cs deleted file mode 100644 index 8117beb81..000000000 --- a/runtime/CSharp/Antlr4.Runtime/Misc/TestRig.cs +++ /dev/null @@ -1,335 +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.IO; -using System.Reflection; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Sharpen; -using Antlr4.Runtime.Sharpen.Reflect; - -namespace Antlr4.Runtime.Misc -{ - /// - /// Run a lexer/parser combo, optionally printing tree string or generating - /// postscript file. - /// - /// - /// Run a lexer/parser combo, optionally printing tree string or generating - /// postscript file. Optionally taking input file. - /// $ java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName - /// [-tree] - /// [-tokens] [-gui] [-ps file.ps] - /// [-trace] - /// [-diagnostics] - /// [-SLL] - /// [input-filename(s)] - /// - public class TestRig - { - public const string LexerStartRuleName = "tokens"; - - protected internal string grammarName; - - protected internal string startRuleName; - - protected internal readonly IList inputFiles = new List(); - - protected internal bool printTree = false; - - protected internal bool gui = false; - - protected internal string psFile = null; - - protected internal bool showTokens = false; - - protected internal bool trace = false; - - protected internal bool diagnostics = false; - - protected internal string encoding = null; - - protected internal bool Sll = false; - - /// - public TestRig(string[] args) - { - if (args.Length < 2) - { - System.Console.Error.WriteLine("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName\n" + " [-tokens] [-tree] [-gui] [-ps file.ps] [-encoding encodingname]\n" + " [-trace] [-diagnostics] [-SLL]\n" + " [input-filename(s)]"); - System.Console.Error.WriteLine("Use startRuleName='tokens' if GrammarName is a lexer grammar."); - System.Console.Error.WriteLine("Omitting input-filename makes rig read from stdin."); - return; - } - int i = 0; - grammarName = args[i]; - i++; - startRuleName = args[i]; - i++; - while (i < args.Length) - { - string arg = args[i]; - i++; - if (arg[0] != '-') - { - // input file name - inputFiles.Add(arg); - continue; - } - if (arg.Equals("-tree")) - { - printTree = true; - } - if (arg.Equals("-gui")) - { - gui = true; - } - if (arg.Equals("-tokens")) - { - showTokens = true; - } - else - { - if (arg.Equals("-trace")) - { - trace = true; - } - else - { - if (arg.Equals("-SLL")) - { - Sll = true; - } - else - { - if (arg.Equals("-diagnostics")) - { - diagnostics = true; - } - else - { - if (arg.Equals("-encoding")) - { - if (i >= args.Length) - { - System.Console.Error.WriteLine("missing encoding on -encoding"); - return; - } - encoding = args[i]; - i++; - } - else - { - if (arg.Equals("-ps")) - { - if (i >= args.Length) - { - System.Console.Error.WriteLine("missing filename on -ps"); - return; - } - psFile = args[i]; - i++; - } - } - } - } - } - } - } - } - - /// - public static void Main(string[] args) - { - Antlr4.Runtime.Misc.TestRig testRig = new Antlr4.Runtime.Misc.TestRig(args); - if (args.Length >= 2) - { - testRig.Process(); - } - } - - /// - public virtual void Process() - { - // System.out.println("exec "+grammarName+"."+startRuleName); - string lexerName = grammarName + "Lexer"; - ClassLoader cl = Antlr4.Runtime.Sharpen.Thread.CurrentThread().GetContextClassLoader(); - Type lexerClass = null; - try - { - lexerClass = cl.LoadClass(lexerName).AsSubclass(); - } - catch (TypeLoadException) - { - // might be pure lexer grammar; no Lexer suffix then - lexerName = grammarName; - try - { - lexerClass = cl.LoadClass(lexerName).AsSubclass(); - } - catch (TypeLoadException) - { - System.Console.Error.WriteLine("Can't load " + lexerName + " as lexer or parser"); - return; - } - } - Constructor lexerCtor = lexerClass.GetConstructor(typeof(ICharStream)); - Lexer lexer = lexerCtor.NewInstance((ICharStream)null); - Type parserClass = null; - Parser parser = null; - if (!startRuleName.Equals(LexerStartRuleName)) - { - string parserName = grammarName + "Parser"; - parserClass = cl.LoadClass(parserName).AsSubclass(); - if (parserClass == null) - { - System.Console.Error.WriteLine("Can't load " + parserName); - return; - } - Constructor parserCtor = parserClass.GetConstructor(typeof(ITokenStream)); - parser = parserCtor.NewInstance((ITokenStream)null); - } - if (inputFiles.IsEmpty()) - { - Stream @is = Sharpen.Runtime.@in; - TextReader r; - if (encoding != null) - { - r = new StreamReader(@is, encoding); - } - else - { - r = new StreamReader(@is); - } - Process(lexer, parserClass, parser, @is, r); - return; - } - foreach (string inputFile in inputFiles) - { - Stream @is = Sharpen.Runtime.@in; - if (inputFile != null) - { - @is = new FileInputStream(inputFile); - } - TextReader r; - if (encoding != null) - { - r = new StreamReader(@is, encoding); - } - else - { - r = new StreamReader(@is); - } - if (inputFiles.Count > 1) - { - System.Console.Error.WriteLine(inputFile); - } - Process(lexer, parserClass, parser, @is, r); - } - } - - /// - /// - /// - /// - protected internal virtual void Process<_T0>(Lexer lexer, Type<_T0> parserClass, Parser parser, Stream @is, TextReader r) - where _T0 : Parser - { - try - { - AntlrInputStream input = new AntlrInputStream(r); - lexer.SetInputStream(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.Fill(); - if (showTokens) - { - foreach (object tok in tokens.GetTokens()) - { - System.Console.Out.WriteLine(tok); - } - } - if (startRuleName.Equals(LexerStartRuleName)) - { - return; - } - if (diagnostics) - { - parser.AddErrorListener(new DiagnosticErrorListener()); - parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection; - } - if (printTree || gui || psFile != null) - { - parser.BuildParseTree = true; - } - if (Sll) - { - // overrides diagnostics - parser.Interpreter.PredictionMode = PredictionMode.Sll; - } - parser.SetInputStream(tokens); - parser.Trace = trace; - try - { - MethodInfo startRule = parserClass.GetMethod(startRuleName, (Type[])null); - ParserRuleContext tree = (ParserRuleContext)startRule.Invoke(parser, (object[])null); - if (printTree) - { - System.Console.Out.WriteLine(tree.ToStringTree(parser)); - } - if (gui) - { - tree.Inspect(parser); - } - if (psFile != null) - { - tree.Save(parser, psFile); - } - } - catch (NoSuchMethodException) - { - // Generate postscript - System.Console.Error.WriteLine("No method for rule " + startRuleName + " or it has arguments"); - } - } - finally - { - if (r != null) - { - r.Close(); - } - if (@is != null) - { - @is.Close(); - } - } - } - } -} diff --git a/runtime/CSharp/Antlr4.Runtime/Parser.cs b/runtime/CSharp/Antlr4.Runtime/Parser.cs index 5514a19be..8d13cf52f 100644 --- a/runtime/CSharp/Antlr4.Runtime/Parser.cs +++ b/runtime/CSharp/Antlr4.Runtime/Parser.cs @@ -126,8 +126,7 @@ namespace Antlr4.Runtime /// The input stream. /// The input stream. /// - /// - private ITokenStream _input; + private ITokenStream _input; private readonly List _precedenceStack = new List { 0 }; diff --git a/runtime/CSharp/Antlr4.Runtime/Sharpen/Collections.cs b/runtime/CSharp/Antlr4.Runtime/Sharpen/Collections.cs index f6d3f642f..45cef1426 100644 --- a/runtime/CSharp/Antlr4.Runtime/Sharpen/Collections.cs +++ b/runtime/CSharp/Antlr4.Runtime/Sharpen/Collections.cs @@ -29,6 +29,7 @@ */ namespace Antlr4.Runtime.Sharpen { + using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -87,4 +88,5 @@ namespace Antlr4.Runtime.Sharpen #endif } } + } diff --git a/runtime/CSharp/Antlr4.Runtime/Tree/Xpath/XPathLexer.cs b/runtime/CSharp/Antlr4.Runtime/Tree/Xpath/XPathLexer.cs index cdd38a75a..b7bea17b8 100644 --- a/runtime/CSharp/Antlr4.Runtime/Tree/Xpath/XPathLexer.cs +++ b/runtime/CSharp/Antlr4.Runtime/Tree/Xpath/XPathLexer.cs @@ -25,7 +25,6 @@ using Antlr4.Runtime.Atn; using Antlr4.Runtime.Misc; using DFA = Antlr4.Runtime.Dfa.DFA; -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] [System.CLSCompliant(false)] public partial class XPathLexer : Lexer { public const int diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net20.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net20.config deleted file mode 100644 index ba2302468..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net20.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net30.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net30.config deleted file mode 100644 index 553a3b3e6..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net30.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-cf.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-cf.config deleted file mode 100644 index 892d710c5..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-cf.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-client.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-client.config deleted file mode 100644 index be6a59602..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net35-client.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net40-client.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net40-client.config deleted file mode 100644 index 9d7ab9386..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net40-client.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net45.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net45.config deleted file mode 100644 index 475fe0d0c..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.net45.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.netcore45.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.netcore45.config deleted file mode 100644 index 4f558beae..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.netcore45.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net40.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net40.config deleted file mode 100644 index a0e3698bc..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net40.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net45.config b/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net45.config deleted file mode 100644 index 39d4c91d2..000000000 --- a/runtime/CSharp/Antlr4.Runtime/packages.Antlr4.Runtime.portable-net45.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Test.mono/AssemblyInfo.cs b/runtime/CSharp/Antlr4.Test.mono/AssemblyInfo.cs deleted file mode 100644 index f67408625..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/AssemblyInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle ("Antlr4.Test.mono")] -[assembly: AssemblyDescription ("")] -[assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] -[assembly: AssemblyCopyright ("ericvergnaud")] -[assembly: AssemblyTrademark ("")] -[assembly: AssemblyCulture ("")] -[assembly: CLSCompliant (true)] -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion ("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/runtime/CSharp/Antlr4.Test.mono/T.g4 b/runtime/CSharp/Antlr4.Test.mono/T.g4 deleted file mode 100644 index e219dea4d..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/T.g4 +++ /dev/null @@ -1,13 +0,0 @@ -grammar T; -@members { -bool pred(bool v) { - Console.WriteLine("eval="+v.ToString().ToLower()); - return v; -} -} -s : e {this.pred(true)}? {Console.WriteLine("parse");} '!' ; -t : e {this.pred(false)}? ID ; -e : ID | ; // non-LL(1) so we use ATN -ID : 'a'..'z'+ ; -INT : '0'..'9'+; -WS : (' '|'\n') -> skip ; \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Test.mono/T.tokens b/runtime/CSharp/Antlr4.Test.mono/T.tokens deleted file mode 100644 index f1ce7da40..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/T.tokens +++ /dev/null @@ -1,5 +0,0 @@ -T__0=1 -ID=2 -INT=3 -WS=4 -'!'=1 diff --git a/runtime/CSharp/Antlr4.Test.mono/TBaseListener.cs b/runtime/CSharp/Antlr4.Test.mono/TBaseListener.cs deleted file mode 100644 index ec9351b26..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TBaseListener.cs +++ /dev/null @@ -1,84 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - - -using Antlr4.Runtime.Misc; -using IErrorNode = Antlr4.Runtime.Tree.IErrorNode; -using ITerminalNode = Antlr4.Runtime.Tree.ITerminalNode; -using IToken = Antlr4.Runtime.IToken; -using ParserRuleContext = Antlr4.Runtime.ParserRuleContext; - -/// -/// This class provides an empty implementation of , -/// which can be extended to create a listener which only needs to handle a subset -/// of the available methods. -/// -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public partial class TBaseListener : ITListener { - /// - /// Enter a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void EnterS([NotNull] TParser.SContext context) { } - /// - /// Exit a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void ExitS([NotNull] TParser.SContext context) { } - /// - /// Enter a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void EnterT([NotNull] TParser.TContext context) { } - /// - /// Exit a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void ExitT([NotNull] TParser.TContext context) { } - /// - /// Enter a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void EnterE([NotNull] TParser.EContext context) { } - /// - /// Exit a parse tree produced by . - /// The default implementation does nothing. - /// - /// The parse tree. - public virtual void ExitE([NotNull] TParser.EContext context) { } - - /// - /// The default implementation does nothing. - public virtual void EnterEveryRule([NotNull] ParserRuleContext context) { } - /// - /// The default implementation does nothing. - public virtual void ExitEveryRule([NotNull] ParserRuleContext context) { } - /// - /// The default implementation does nothing. - public virtual void VisitTerminal([NotNull] ITerminalNode node) { } - /// - /// The default implementation does nothing. - public virtual void VisitErrorNode([NotNull] IErrorNode node) { } -} diff --git a/runtime/CSharp/Antlr4.Test.mono/TBaseVisitor.cs b/runtime/CSharp/Antlr4.Test.mono/TBaseVisitor.cs deleted file mode 100644 index 5339580ec..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TBaseVisitor.cs +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using IToken = Antlr4.Runtime.IToken; -using ParserRuleContext = Antlr4.Runtime.ParserRuleContext; - -/// -/// This class provides an empty implementation of , -/// which can be extended to create a visitor which only needs to handle a subset -/// of the available methods. -/// -/// The return type of the visit operation. -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public partial class TBaseVisitor : AbstractParseTreeVisitor, ITVisitor { - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitS([NotNull] TParser.SContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitT([NotNull] TParser.TContext context) { return VisitChildren(context); } - /// - /// Visit a parse tree produced by . - /// - /// The default implementation returns the result of calling - /// on . - /// - /// - /// The parse tree. - /// The visitor result. - public virtual Result VisitE([NotNull] TParser.EContext context) { return VisitChildren(context); } -} diff --git a/runtime/CSharp/Antlr4.Test.mono/TLexer.cs b/runtime/CSharp/Antlr4.Test.mono/TLexer.cs deleted file mode 100644 index bddedaa94..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TLexer.cs +++ /dev/null @@ -1,92 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - -using System; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public partial class TLexer : Lexer { - public const int - T__0=1, ID=2, INT=3, WS=4; - public static string[] modeNames = { - "DEFAULT_MODE" - }; - - public static readonly string[] ruleNames = { - "T__0", "ID", "INT", "WS" - }; - - - bool pred(bool v) { - Console.WriteLine("eval="+v.ToString().ToLower()); - return v; - } - - - public TLexer(ICharStream input) - : base(input) - { - Interpreter = new LexerATNSimulator(this,_ATN); - } - - private static readonly string[] _LiteralNames = { - null, "'!'" - }; - private static readonly string[] _SymbolicNames = { - null, null, "ID", "INT", "WS" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "T.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override string[] ModeNames { get { return modeNames; } } - - public override string SerializedAtn { get { return _serializedATN; } } - - public static readonly string _serializedATN = - "\x3\x430\xD6D1\x8206\xAD2D\x4417\xAEF1\x8D80\xAADD\x2\x6\x1B\b\x1\x4\x2"+ - "\t\x2\x4\x3\t\x3\x4\x4\t\x4\x4\x5\t\x5\x3\x2\x3\x2\x3\x3\x6\x3\xF\n\x3"+ - "\r\x3\xE\x3\x10\x3\x4\x6\x4\x14\n\x4\r\x4\xE\x4\x15\x3\x5\x3\x5\x3\x5"+ - "\x3\x5\x2\x2\x6\x3\x3\x5\x4\a\x5\t\x6\x3\x2\x3\x4\x2\f\f\"\"\x1C\x2\x3"+ - "\x3\x2\x2\x2\x2\x5\x3\x2\x2\x2\x2\a\x3\x2\x2\x2\x2\t\x3\x2\x2\x2\x3\v"+ - "\x3\x2\x2\x2\x5\xE\x3\x2\x2\x2\a\x13\x3\x2\x2\x2\t\x17\x3\x2\x2\x2\v\f"+ - "\a#\x2\x2\f\x4\x3\x2\x2\x2\r\xF\x4\x63|\x2\xE\r\x3\x2\x2\x2\xF\x10\x3"+ - "\x2\x2\x2\x10\xE\x3\x2\x2\x2\x10\x11\x3\x2\x2\x2\x11\x6\x3\x2\x2\x2\x12"+ - "\x14\x4\x32;\x2\x13\x12\x3\x2\x2\x2\x14\x15\x3\x2\x2\x2\x15\x13\x3\x2"+ - "\x2\x2\x15\x16\x3\x2\x2\x2\x16\b\x3\x2\x2\x2\x17\x18\t\x2\x2\x2\x18\x19"+ - "\x3\x2\x2\x2\x19\x1A\b\x5\x2\x2\x1A\n\x3\x2\x2\x2\x5\x2\x10\x15\x3\b\x2"+ - "\x2"; - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN.ToCharArray()); -} diff --git a/runtime/CSharp/Antlr4.Test.mono/TLexer.tokens b/runtime/CSharp/Antlr4.Test.mono/TLexer.tokens deleted file mode 100644 index f1ce7da40..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TLexer.tokens +++ /dev/null @@ -1,5 +0,0 @@ -T__0=1 -ID=2 -INT=3 -WS=4 -'!'=1 diff --git a/runtime/CSharp/Antlr4.Test.mono/TListener.cs b/runtime/CSharp/Antlr4.Test.mono/TListener.cs deleted file mode 100644 index c90107f95..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TListener.cs +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - -using Antlr4.Runtime.Misc; -using IParseTreeListener = Antlr4.Runtime.Tree.IParseTreeListener; -using IToken = Antlr4.Runtime.IToken; - -/// -/// This interface defines a complete listener for a parse tree produced by -/// . -/// -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public interface ITListener : IParseTreeListener { - /// - /// Enter a parse tree produced by . - /// - /// The parse tree. - void EnterS([NotNull] TParser.SContext context); - /// - /// Exit a parse tree produced by . - /// - /// The parse tree. - void ExitS([NotNull] TParser.SContext context); - /// - /// Enter a parse tree produced by . - /// - /// The parse tree. - void EnterT([NotNull] TParser.TContext context); - /// - /// Exit a parse tree produced by . - /// - /// The parse tree. - void ExitT([NotNull] TParser.TContext context); - /// - /// Enter a parse tree produced by . - /// - /// The parse tree. - void EnterE([NotNull] TParser.EContext context); - /// - /// Exit a parse tree produced by . - /// - /// The parse tree. - void ExitE([NotNull] TParser.EContext context); -} diff --git a/runtime/CSharp/Antlr4.Test.mono/TParser.cs b/runtime/CSharp/Antlr4.Test.mono/TParser.cs deleted file mode 100644 index 4e67bc266..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TParser.cs +++ /dev/null @@ -1,257 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - -using System; -using System.Text; -using System.Diagnostics; -using System.Collections.Generic; -using Antlr4.Runtime; -using Antlr4.Runtime.Atn; -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using DFA = Antlr4.Runtime.Dfa.DFA; - -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public partial class TParser : Parser { - public const int - T__0=1, ID=2, INT=3, WS=4; - public const int - RULE_s = 0, RULE_t = 1, RULE_e = 2; - public static readonly string[] ruleNames = { - "s", "t", "e" - }; - - private static readonly string[] _LiteralNames = { - null, "'!'" - }; - private static readonly string[] _SymbolicNames = { - null, null, "ID", "INT", "WS" - }; - public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames); - - [NotNull] - public override IVocabulary Vocabulary - { - get - { - return DefaultVocabulary; - } - } - - public override string GrammarFileName { get { return "T.g4"; } } - - public override string[] RuleNames { get { return ruleNames; } } - - public override string SerializedAtn { get { return _serializedATN; } } - - - bool pred(bool v) { - Console.WriteLine("eval="+v.ToString().ToLower()); - return v; - } - - public TParser(ITokenStream input) - : base(input) - { - Interpreter = new ParserATNSimulator(this,_ATN); - } - public partial class SContext : ParserRuleContext { - public EContext e() { - return GetRuleContext(0); - } - public SContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_s; } } - public override void EnterRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.EnterS(this); - } - public override void ExitRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.ExitS(this); - } - public override TResult Accept(IParseTreeVisitor visitor) { - ITVisitor typedVisitor = visitor as ITVisitor; - if (typedVisitor != null) return typedVisitor.VisitS(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public SContext s() { - SContext _localctx = new SContext(Context, State); - EnterRule(_localctx, 0, RULE_s); - try { - EnterOuterAlt(_localctx, 1); - { - State = 6; e(); - State = 7; - if (!(this.pred(true))) throw new FailedPredicateException(this, "this.pred(true)"); - Console.WriteLine("parse"); - State = 9; Match(T__0); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class TContext : ParserRuleContext { - public EContext e() { - return GetRuleContext(0); - } - public ITerminalNode ID() { return GetToken(TParser.ID, 0); } - public TContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_t; } } - public override void EnterRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.EnterT(this); - } - public override void ExitRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.ExitT(this); - } - public override TResult Accept(IParseTreeVisitor visitor) { - ITVisitor typedVisitor = visitor as ITVisitor; - if (typedVisitor != null) return typedVisitor.VisitT(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public TContext t() { - TContext _localctx = new TContext(Context, State); - EnterRule(_localctx, 2, RULE_t); - try { - EnterOuterAlt(_localctx, 1); - { - State = 11; e(); - State = 12; - if (!(this.pred(false))) throw new FailedPredicateException(this, "this.pred(false)"); - State = 13; Match(ID); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public partial class EContext : ParserRuleContext { - public ITerminalNode ID() { return GetToken(TParser.ID, 0); } - public EContext(ParserRuleContext parent, int invokingState) - : base(parent, invokingState) - { - } - public override int RuleIndex { get { return RULE_e; } } - public override void EnterRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.EnterE(this); - } - public override void ExitRule(IParseTreeListener listener) { - ITListener typedListener = listener as ITListener; - if (typedListener != null) typedListener.ExitE(this); - } - public override TResult Accept(IParseTreeVisitor visitor) { - ITVisitor typedVisitor = visitor as ITVisitor; - if (typedVisitor != null) return typedVisitor.VisitE(this); - else return visitor.VisitChildren(this); - } - } - - [RuleVersion(0)] - public EContext e() { - EContext _localctx = new EContext(Context, State); - EnterRule(_localctx, 4, RULE_e); - try { - State = 17; - switch ( Interpreter.AdaptivePredict(TokenStream,0,Context) ) { - case 1: - EnterOuterAlt(_localctx, 1); - { - State = 15; Match(ID); - } - break; - case 2: - EnterOuterAlt(_localctx, 2); - { - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - ErrorHandler.ReportError(this, re); - ErrorHandler.Recover(this, re); - } - finally { - ExitRule(); - } - return _localctx; - } - - public override bool Sempred(RuleContext _localctx, int ruleIndex, int predIndex) { - switch (ruleIndex) { - case 0: return s_sempred((SContext)_localctx, predIndex); - case 1: return t_sempred((TContext)_localctx, predIndex); - } - return true; - } - private bool s_sempred(SContext _localctx, int predIndex) { - switch (predIndex) { - case 0: return this.pred(true); - } - return true; - } - private bool t_sempred(TContext _localctx, int predIndex) { - switch (predIndex) { - case 1: return this.pred(false); - } - return true; - } - - public static readonly string _serializedATN = - "\x3\x430\xD6D1\x8206\xAD2D\x4417\xAEF1\x8D80\xAADD\x3\x6\x16\x4\x2\t\x2"+ - "\x4\x3\t\x3\x4\x4\t\x4\x3\x2\x3\x2\x3\x2\x3\x2\x3\x2\x3\x3\x3\x3\x3\x3"+ - "\x3\x3\x3\x4\x3\x4\x5\x4\x14\n\x4\x3\x4\x2\x2\x5\x2\x4\x6\x2\x2\x13\x2"+ - "\b\x3\x2\x2\x2\x4\r\x3\x2\x2\x2\x6\x13\x3\x2\x2\x2\b\t\x5\x6\x4\x2\t\n"+ - "\x6\x2\x2\x2\n\v\b\x2\x1\x2\v\f\a\x3\x2\x2\f\x3\x3\x2\x2\x2\r\xE\x5\x6"+ - "\x4\x2\xE\xF\x6\x3\x3\x2\xF\x10\a\x4\x2\x2\x10\x5\x3\x2\x2\x2\x11\x14"+ - "\a\x4\x2\x2\x12\x14\x3\x2\x2\x2\x13\x11\x3\x2\x2\x2\x13\x12\x3\x2\x2\x2"+ - "\x14\a\x3\x2\x2\x2\x3\x13"; - public static readonly ATN _ATN = - new ATNDeserializer().Deserialize(_serializedATN.ToCharArray()); -} diff --git a/runtime/CSharp/Antlr4.Test.mono/TVisitor.cs b/runtime/CSharp/Antlr4.Test.mono/TVisitor.cs deleted file mode 100644 index c90e5cbce..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/TVisitor.cs +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// ANTLR Version: 4.4.1-dev -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -// Generated from /users/ericvergnaud/Development/antlr4/antlr/antlr4-csharp/runtime/CSharp/Antlr4.Test.mono/T.g4 by ANTLR 4.4.1-dev - -// Unreachable code detected -#pragma warning disable 0162 -// The variable '...' is assigned but its value is never used -#pragma warning disable 0219 -// Missing XML comment for publicly visible type or member '...' -#pragma warning disable 1591 - -using Antlr4.Runtime.Misc; -using Antlr4.Runtime.Tree; -using IToken = Antlr4.Runtime.IToken; - -/// -/// This interface defines a complete generic visitor for a parse tree produced -/// by . -/// -/// The return type of the visit operation. -[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.4.1-dev")] -[System.CLSCompliant(false)] -public interface ITVisitor : IParseTreeVisitor { - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitS([NotNull] TParser.SContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitT([NotNull] TParser.TContext context); - /// - /// Visit a parse tree produced by . - /// - /// The parse tree. - /// The visitor result. - Result VisitE([NotNull] TParser.EContext context); -} diff --git a/runtime/CSharp/Antlr4.Test.mono/Test.cs b/runtime/CSharp/Antlr4.Test.mono/Test.cs deleted file mode 100644 index 7af21dcee..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/Test.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using Antlr4.Runtime; -using Antlr4.Runtime.Tree; - -public class Test { - public static void Main(string[] args) { - ICharStream input = new AntlrFileStream("../../input"); - TLexer lex = new TLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lex); - TParser parser = new TParser(tokens); - parser.AddErrorListener(new DiagnosticErrorListener()); - - parser.BuildParseTree = true; - ParserRuleContext tree = parser.s(); - ParseTreeWalker.Default.Walk(new TreeShapeListener(), tree); - } -} - -class TreeShapeListener : IParseTreeListener { - public void VisitTerminal(ITerminalNode node) { } - public void VisitErrorNode(IErrorNode node) { } - public void ExitEveryRule(ParserRuleContext ctx) { } - - public void EnterEveryRule(ParserRuleContext ctx) { - for (int i = 0; i < ctx.ChildCount; i++) { - IParseTree parent = ctx.GetChild(i).Parent; - if (!(parent is IRuleNode) || ((IRuleNode)parent).RuleContext != ctx) { - throw new Exception("Invalid parse tree shape detected."); - } - } - } -} \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.Test.mono/input b/runtime/CSharp/Antlr4.Test.mono/input deleted file mode 100644 index 1bbae8bf1..000000000 --- a/runtime/CSharp/Antlr4.Test.mono/input +++ /dev/null @@ -1 +0,0 @@ -a! \ No newline at end of file diff --git a/runtime/CSharp/Antlr4.VS2008.sln b/runtime/CSharp/Antlr4.VS2008.sln deleted file mode 100644 index 6f666dc70..000000000 --- a/runtime/CSharp/Antlr4.VS2008.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net35-cf", "Antlr4.Runtime\Antlr4.Runtime.net35-cf.csproj", "{C5F9C476-200F-4440-9524-C5C3F9BE16D7}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C5F9C476-200F-4440-9524-C5C3F9BE16D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C5F9C476-200F-4440-9524-C5C3F9BE16D7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C5F9C476-200F-4440-9524-C5C3F9BE16D7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C5F9C476-200F-4440-9524-C5C3F9BE16D7}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/runtime/CSharp/Antlr4.sln b/runtime/CSharp/Antlr4.sln deleted file mode 100644 index b5560919a..000000000 --- a/runtime/CSharp/Antlr4.sln +++ /dev/null @@ -1,145 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net45", "Antlr4.Runtime\Antlr4.Runtime.net45.csproj", "{E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{47C0086D-577C-43DA-ADC7-544F27656E45}" - ProjectSection(SolutionItems) = preProject - ..\..\CreatingTargets.md = ..\..\CreatingTargets.md - ..\..\tool\resources\org\antlr\v4\tool\templates\codegen\CSharp\CSharp.stg = ..\..\tool\resources\org\antlr\v4\tool\templates\codegen\CSharp\CSharp.stg - ..\..\tool\src\org\antlr\v4\codegen\CSharpTarget.java = ..\..\tool\src\org\antlr\v4\codegen\CSharpTarget.java - ..\..\tool\pom.xml = ..\..\tool\pom.xml - ..\..\Readme.md = ..\..\Readme.md - ..\..\reference\sharpen-all-options.txt = ..\..\reference\sharpen-all-options.txt - ..\..\reference\sharpen.md = ..\..\reference\sharpen.md - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.net45", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.net45.csproj", "{9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.net40", "Antlr4BuildTasks\Antlr4BuildTasks.net40.csproj", "{F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net40-client", "Antlr4.Runtime\Antlr4.Runtime.net40-client.csproj", "{423978DF-85A4-409E-A16C-453683FE3969}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net35-client", "Antlr4.Runtime\Antlr4.Runtime.net35-client.csproj", "{E186FDA3-1411-47EE-94C7-9F3745F0474B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net30", "Antlr4.Runtime\Antlr4.Runtime.net30.csproj", "{EBBDCC35-43CC-416C-860B-9FC115F1EB42}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.net20", "Antlr4.Runtime\Antlr4.Runtime.net20.csproj", "{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.net40-client", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.net40-client.csproj", "{706D364A-CD4E-4720-B94C-0DB82AF7B433}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.net35-client", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.net35-client.csproj", "{C4A38390-8AA3-45AE-9A70-C392146B37D0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.net30", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.net30.csproj", "{8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.net20", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.net20.csproj", "{0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.portable-net40", "Antlr4.Runtime\Antlr4.Runtime.portable-net40.csproj", "{06C182C5-095C-4D43-9C33-C87E305C6BC2}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.portable-net40", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.portable-net40.csproj", "{97C32E42-51B2-4A29-B005-769B63CFEFCA}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.net35", "Antlr4BuildTasks\Antlr4BuildTasks.net35.csproj", "{0D3D20E9-3341-4449-80E7-76A4534F0E55}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{4CE79A54-058D-4940-875E-7F6AA9922A7D}" - ProjectSection(SolutionItems) = preProject - ..\..\build\Antlr4.nuspec = ..\..\build\Antlr4.nuspec - ..\..\build\Antlr4.Runtime.nuspec = ..\..\build\Antlr4.Runtime.nuspec - ..\..\build\Antlr4.VS2008.nuspec = ..\..\build\Antlr4.VS2008.nuspec - ..\..\build\build.ps1 = ..\..\build\build.ps1 - ..\..\build\check-key.ps1 = ..\..\build\check-key.ps1 - build\KeyReporting.targets = build\KeyReporting.targets - ..\..\build\keys.ps1 = ..\..\build\keys.ps1 - ..\..\build\push.ps1 = ..\..\build\push.ps1 - ..\..\build\version.ps1 = ..\..\build\version.ps1 - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.portable-net45", "Antlr4.Runtime\Antlr4.Runtime.portable-net45.csproj", "{12269283-EE92-4FAA-B849-53CD24F341FA}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.portable-net45", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.portable-net45.csproj", "{5844076E-3C92-4122-BB7A-0D745C3F5334}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.netcore45", "Antlr4.Runtime\Antlr4.Runtime.netcore45.csproj", "{F3145DCA-EA26-4482-80D6-5232A79E2A3A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E1D192DE-5347-48C4-A9F4-A8CBA2AF3869}.Release|Any CPU.Build.0 = Release|Any CPU - {9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}.Release|Any CPU.Build.0 = Release|Any CPU - {F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}.Release|Any CPU.Build.0 = Release|Any CPU - {423978DF-85A4-409E-A16C-453683FE3969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {423978DF-85A4-409E-A16C-453683FE3969}.Debug|Any CPU.Build.0 = Debug|Any CPU - {423978DF-85A4-409E-A16C-453683FE3969}.Release|Any CPU.ActiveCfg = Release|Any CPU - {423978DF-85A4-409E-A16C-453683FE3969}.Release|Any CPU.Build.0 = Release|Any CPU - {E186FDA3-1411-47EE-94C7-9F3745F0474B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E186FDA3-1411-47EE-94C7-9F3745F0474B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E186FDA3-1411-47EE-94C7-9F3745F0474B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E186FDA3-1411-47EE-94C7-9F3745F0474B}.Release|Any CPU.Build.0 = Release|Any CPU - {EBBDCC35-43CC-416C-860B-9FC115F1EB42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EBBDCC35-43CC-416C-860B-9FC115F1EB42}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EBBDCC35-43CC-416C-860B-9FC115F1EB42}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EBBDCC35-43CC-416C-860B-9FC115F1EB42}.Release|Any CPU.Build.0 = Release|Any CPU - {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.Build.0 = Release|Any CPU - {706D364A-CD4E-4720-B94C-0DB82AF7B433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {706D364A-CD4E-4720-B94C-0DB82AF7B433}.Debug|Any CPU.Build.0 = Debug|Any CPU - {706D364A-CD4E-4720-B94C-0DB82AF7B433}.Release|Any CPU.ActiveCfg = Release|Any CPU - {706D364A-CD4E-4720-B94C-0DB82AF7B433}.Release|Any CPU.Build.0 = Release|Any CPU - {C4A38390-8AA3-45AE-9A70-C392146B37D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C4A38390-8AA3-45AE-9A70-C392146B37D0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C4A38390-8AA3-45AE-9A70-C392146B37D0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C4A38390-8AA3-45AE-9A70-C392146B37D0}.Release|Any CPU.Build.0 = Release|Any CPU - {8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8A2F2331-A4A5-4C7F-8D5D-DEECEF54AEA7}.Release|Any CPU.Build.0 = Release|Any CPU - {0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A4681C4-1248-4ACD-B59F-D6CC17CC2B4C}.Release|Any CPU.Build.0 = Release|Any CPU - {06C182C5-095C-4D43-9C33-C87E305C6BC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06C182C5-095C-4D43-9C33-C87E305C6BC2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06C182C5-095C-4D43-9C33-C87E305C6BC2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06C182C5-095C-4D43-9C33-C87E305C6BC2}.Release|Any CPU.Build.0 = Release|Any CPU - {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.Build.0 = Release|Any CPU - {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.Build.0 = Release|Any CPU - {12269283-EE92-4FAA-B849-53CD24F341FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12269283-EE92-4FAA-B849-53CD24F341FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12269283-EE92-4FAA-B849-53CD24F341FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12269283-EE92-4FAA-B849-53CD24F341FA}.Release|Any CPU.Build.0 = Release|Any CPU - {5844076E-3C92-4122-BB7A-0D745C3F5334}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5844076E-3C92-4122-BB7A-0D745C3F5334}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5844076E-3C92-4122-BB7A-0D745C3F5334}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5844076E-3C92-4122-BB7A-0D745C3F5334}.Release|Any CPU.Build.0 = Release|Any CPU - {F3145DCA-EA26-4482-80D6-5232A79E2A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F3145DCA-EA26-4482-80D6-5232A79E2A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F3145DCA-EA26-4482-80D6-5232A79E2A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F3145DCA-EA26-4482-80D6-5232A79E2A3A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {4CE79A54-058D-4940-875E-7F6AA9922A7D} = {47C0086D-577C-43DA-ADC7-544F27656E45} - EndGlobalSection -EndGlobal diff --git a/runtime/CSharp/Antlr4.vs2013.sln b/runtime/CSharp/Antlr4.vs2013.sln new file mode 100644 index 000000000..760ea02bd --- /dev/null +++ b/runtime/CSharp/Antlr4.vs2013.sln @@ -0,0 +1,24 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{47C0086D-577C-43DA-ADC7-544F27656E45}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.vs2013", "Antlr4.Runtime\Antlr4.Runtime.vs2013.csproj", "{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/runtime/CSharp/Antlr4.userprefs b/runtime/CSharp/Antlr4.vs2013.userprefs similarity index 100% rename from runtime/CSharp/Antlr4.userprefs rename to runtime/CSharp/Antlr4.vs2013.userprefs diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.props b/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.props deleted file mode 100644 index 6240f1ffc..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - - . - - ..\tools\antlr4-csharp-4.4.1-SNAPSHOT-complete.jar - - diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.targets b/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.targets deleted file mode 100644 index 69e5e8c82..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net35.targets +++ /dev/null @@ -1,188 +0,0 @@ - - - - MSBuild - 4.0.0.0 - eb42632606e9261f - Antlr4BuildTasks.net35, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken) - - - - - $(LoadTimeSensitiveTargets); - Antlr4Compile; - Antlr4CompileAddFilesGenerated; - - - $(LoadTimeSensitiveProperties); - Antlr4CompileDependsOn; - Antlr4CompileAddFilesGeneratedDependsOn; - - - - - $(MSBuildBinPath) - $(Antlr4BuildTaskPath) - $(MSBuildBinPath)\Antlr4\antlr4-csharp-4.4.1-SNAPSHOT-complete.jar - $(Antlr4ToolPath) - - JavaSoft - Java Runtime Environment - - - - $(MSBuildProjectFile).Antlr4GeneratedCodeFileListAbsolute.txt - - - - - - - - Antlr4Compile; - Antlr4CompileAddFilesGenerated; - $(PrepareResourcesDependsOn) - - - - - - Antlr4CompileReadGeneratedFileList - - - Antlr4Compile - - - - - - - - - - - - MSBuild:Compile - $(RootNamespace) - CSharp - true - true - false - false - - - - - - - - - - - - - Antlr4DesignTimeGrammarCompilation; - $(CoreCompileDependsOn) - - - - - - - - - - - - - - - - <_IntellisenseOnlyCompile>false - <_IntellisenseOnlyCompile Condition="'$(BuildingProject)' != 'true'">true - - - - - - - - - - - - - - - - - - - - - - - - <_GeneratedCodeFiles Include="@(Antlr4GeneratedCodeFiles)" /> - - - - diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.props b/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.props deleted file mode 100644 index 0ccdf5b9b..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - - . - - ..\tools\antlr4-csharp-4.4.1-SNAPSHOT-complete.jar - - diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.targets b/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.targets deleted file mode 100644 index 185762ea8..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.net40.targets +++ /dev/null @@ -1,182 +0,0 @@ - - - - MSBuild - 4.0.0.0 - eb42632606e9261f - Antlr4BuildTasks.net40, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken) - - - - - $(LoadTimeSensitiveTargets); - Antlr4Compile; - - - $(LoadTimeSensitiveProperties); - Antlr4CompileDependsOn; - - - - - $(MSBuildBinPath) - $(Antlr4BuildTaskPath) - $(MSBuildBinPath)\Antlr4\antlr4-csharp-4.4.1-SNAPSHOT-complete.jar - $(Antlr4ToolPath) - - JavaSoft - Java Runtime Environment - - - - $(MSBuildProjectFile).Antlr4GeneratedCodeFileListAbsolute.txt - - - - - - - - Antlr4Compile; - Antlr4CompileAddFilesGenerated; - $(PrepareResourcesDependsOn) - - - - - - Antlr4CompileReadGeneratedFileList - - - - - - - - - - - - MSBuild:Compile - $(RootNamespace) - CSharp - true - true - false - false - - - - - - - - - - - - - Antlr4DesignTimeGrammarCompilation; - $(CoreCompileDependsOn) - - - - - - - - - - - - - - - - <_IntellisenseOnlyCompile>false - <_IntellisenseOnlyCompile Condition="'$(BuildingProject)' != 'true'">true - - - - - - - - - - - - - - - - - - - - - - - <_GeneratedCodeFiles Include="@(Antlr4GeneratedCodeFiles)" /> - - - - diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net35.csproj b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net35.csproj deleted file mode 100644 index 5d0d2692b..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net35.csproj +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Debug - AnyCPU - {0D3D20E9-3341-4449-80E7-76A4534F0E55} - Library - Properties - Antlr4.Build.Tasks - Antlr4BuildTasks.net35 - v3.5 - 512 - obj\net35\ - - - true - full - false - bin\net35\Debug\ - DEBUG;TRACE;NET35;NET35PLUS - prompt - 4 - ExtendedDesignGuidelineRules.ruleset - - - pdbonly - true - bin\net35\Release\ - TRACE;NET35;NET35PLUS - prompt - 4 - - - true - - - ..\..\..\..\..\..\keys\antlr\Key.snk - - - - - - - - - - - - - - - - - - - - - - Always - - - Always - Designer - - - Key.snk - - - - - CustomDictionary.xml - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net40.csproj b/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net40.csproj deleted file mode 100644 index 7d77c6b89..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4BuildTasks.net40.csproj +++ /dev/null @@ -1,84 +0,0 @@ - - - - - Debug - AnyCPU - {F63DFE80-AE1F-47A6-A31A-E39DA4C837BA} - Library - Properties - Antlr4.Build.Tasks - Antlr4BuildTasks.net40 - v4.0 - 512 - obj\net40\ - - - true - full - false - bin\net40\Debug\ - DEBUG;TRACE;NET40;NET40PLUS;NET35PLUS - prompt - 4 - ExtendedDesignGuidelineRules.ruleset - - - pdbonly - true - bin\net40\Release\ - TRACE;NET40;NET40PLUS;NET35PLUS - prompt - 4 - - - true - - - ..\..\..\..\..\..\keys\antlr\Key.snk - - - - - - - - - - - - - - - - - - - - - - - Always - - - Always - Designer - - - Key.snk - - - - - CustomDictionary.xml - - - - - \ No newline at end of file diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs deleted file mode 100644 index fb4b46dfd..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs +++ /dev/null @@ -1,367 +0,0 @@ -/* - * [The "BSD licence"] - * 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.Build.Tasks -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Diagnostics.CodeAnalysis; - using System.Linq; - using System.Reflection; - using System.Security; - using System.Security.Policy; - using System.Threading; - using Microsoft.Build.Framework; - using Microsoft.Build.Utilities; - using Directory = System.IO.Directory; - using File = System.IO.File; - using FileAttributes = System.IO.FileAttributes; - using Path = System.IO.Path; - - public class Antlr4ClassGenerationTask - : Task - { - private static AppDomain _sharedAppDomain; - - private const string DefaultGeneratedSourceExtension = "g4"; - private List _generatedCodeFiles = new List(); - - public Antlr4ClassGenerationTask() - { - this.GeneratedSourceExtension = DefaultGeneratedSourceExtension; - } - - [Required] - public string ToolPath - { - get; - set; - } - - [Required] - public string OutputPath - { - get; - set; - } - - public string TargetLanguage - { - get; - set; - } - - public string TargetFrameworkVersion - { - get; - set; - } - - public string BuildTaskPath - { - get; - set; - } - - public ITaskItem[] SourceCodeFiles - { - get; - set; - } - - public ITaskItem[] TokensFiles - { - get; - set; - } - - public ITaskItem[] AbstractGrammarFiles - { - get; - set; - } - - public string GeneratedSourceExtension - { - get; - set; - } - - public string TargetNamespace - { - get; - set; - } - - public string[] LanguageSourceExtensions - { - get; - set; - } - - public bool GenerateListener - { - get; - set; - } - - public bool GenerateVisitor - { - get; - set; - } - - public bool ForceAtn - { - get; - set; - } - - public bool AbstractGrammar - { - get; - set; - } - - [Required] - public string JavaVendor - { - get; - set; - } - - [Required] - public string JavaInstallation - { - get; - set; - } - - public string JavaExecutable - { - get; - set; - } - - [Output] - public ITaskItem[] GeneratedCodeFiles - { - get - { - return this._generatedCodeFiles.ToArray(); - } - set - { - this._generatedCodeFiles = new List(value); - } - } - - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - public AppDomain GetAntlrTaskAppDomain() - { - if (_sharedAppDomain != null) - return _sharedAppDomain; - - AppDomainSetup info = new AppDomainSetup - { - ApplicationBase = BuildTaskPath, - LoaderOptimization = LoaderOptimization.MultiDomainHost, - ShadowCopyFiles = "true" - }; - - string friendlyName = "AntlrClassGenerationDomain_" + Guid.NewGuid(); - _sharedAppDomain = AppDomain.CreateDomain(friendlyName, AppDomain.CurrentDomain.Evidence, info, new NamedPermissionSet("FullTrust"), new StrongName[0]); - return _sharedAppDomain; - } - - public override bool Execute() - { - AppDomain domain = null; - bool success; - - if (!Path.IsPathRooted(ToolPath)) - ToolPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), ToolPath); - - if (!Path.IsPathRooted(BuildTaskPath)) - BuildTaskPath = Path.Combine(Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode), BuildTaskPath); - - try - { - domain = GetAntlrTaskAppDomain(); - AntlrClassGenerationTaskInternal wrapper = CreateBuildTaskWrapper(domain); - success = wrapper.Execute(); - - if (success) - { - _generatedCodeFiles.AddRange(wrapper.GeneratedCodeFiles.Select(file => (ITaskItem)new TaskItem(file))); - } - - foreach (BuildMessage message in wrapper.BuildMessages) - { - ProcessBuildMessage(message); - } - } - catch (Exception exception) - { - if (IsFatalException(exception)) - throw; - - ProcessExceptionAsBuildMessage(exception); - success = false; - } - finally - { - if (domain != null && domain != _sharedAppDomain) - AppDomain.Unload(domain); - } - - return success; - } - - private void ProcessExceptionAsBuildMessage(Exception exception) - { - ProcessBuildMessage(new BuildMessage(exception.Message)); - } - - private void ProcessBuildMessage(BuildMessage message) - { - string logMessage; - string errorCode; - errorCode = Log.ExtractMessageCode(message.Message, out logMessage); - if (string.IsNullOrEmpty(errorCode)) - { - errorCode = "AC1000"; - logMessage = "Unknown build error: " + message.Message; - } - - string subcategory = null; - string helpKeyword = null; - - switch (message.Severity) - { - case TraceLevel.Error: - this.Log.LogError(subcategory, errorCode, helpKeyword, message.FileName, message.LineNumber, message.ColumnNumber, 0, 0, logMessage); - break; - case TraceLevel.Warning: - this.Log.LogWarning(subcategory, errorCode, helpKeyword, message.FileName, message.LineNumber, message.ColumnNumber, 0, 0, logMessage); - break; - case TraceLevel.Info: - this.Log.LogMessage(MessageImportance.Normal, logMessage); - break; - case TraceLevel.Verbose: - this.Log.LogMessage(MessageImportance.Low, logMessage); - break; - } - } - - private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper(AppDomain domain) - { - AntlrClassGenerationTaskInternal wrapper = (AntlrClassGenerationTaskInternal)domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(AntlrClassGenerationTaskInternal).FullName); - - IList sourceCodeFiles = null; - if (this.SourceCodeFiles != null) - { - sourceCodeFiles = new List(SourceCodeFiles.Length); - foreach (ITaskItem taskItem in SourceCodeFiles) - sourceCodeFiles.Add(taskItem.ItemSpec); - } - - if (this.TokensFiles != null && this.TokensFiles.Length > 0) - { - Directory.CreateDirectory(OutputPath); - - HashSet copied = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (ITaskItem taskItem in TokensFiles) - { - string fileName = taskItem.ItemSpec; - if (!File.Exists(fileName)) - { - Log.LogError("The tokens file '{0}' does not exist.", fileName); - continue; - } - - string vocabName = Path.GetFileNameWithoutExtension(fileName); - if (!copied.Add(vocabName)) - { - Log.LogWarning("The tokens file '{0}' conflicts with another tokens file in the same project.", fileName); - continue; - } - - string target = Path.Combine(OutputPath, Path.GetFileName(fileName)); - if (!Path.GetExtension(target).Equals(".tokens", StringComparison.OrdinalIgnoreCase)) - { - Log.LogError("The destination for the tokens file '{0}' did not have the correct extension '.tokens'.", target); - continue; - } - - File.Copy(fileName, target, true); - File.SetAttributes(target, File.GetAttributes(target) & ~FileAttributes.ReadOnly); - } - } - - wrapper.ToolPath = ToolPath; - wrapper.SourceCodeFiles = sourceCodeFiles; - wrapper.TargetLanguage = TargetLanguage; - wrapper.TargetFrameworkVersion = TargetFrameworkVersion; - wrapper.OutputPath = OutputPath; - wrapper.LanguageSourceExtensions = LanguageSourceExtensions; - wrapper.TargetNamespace = TargetNamespace; - wrapper.GenerateListener = GenerateListener; - wrapper.GenerateVisitor = GenerateVisitor; - wrapper.ForceAtn = ForceAtn; - wrapper.AbstractGrammar = AbstractGrammar; - wrapper.JavaVendor = JavaVendor; - wrapper.JavaInstallation = JavaInstallation; - wrapper.JavaExecutable = JavaExecutable; - return wrapper; - } - - internal static bool IsFatalException(Exception exception) - { - while (exception != null) - { - if ((exception is OutOfMemoryException) - || (exception is InsufficientMemoryException) - || (exception is ThreadAbortException)) - { - return true; - } - - if (!(exception is TypeInitializationException) && !(exception is TargetInvocationException)) - { - break; - } - - exception = exception.InnerException; - } - - return false; - } - } -} diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs deleted file mode 100644 index d14fc45bf..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs +++ /dev/null @@ -1,428 +0,0 @@ -/* - * [The "BSD licence"] - * 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.Build.Tasks -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Reflection; - using System.Text.RegularExpressions; - using RegistryHive = Microsoft.Win32.RegistryHive; - using RegistryKey = Microsoft.Win32.RegistryKey; -#if NET40PLUS - using RegistryView = Microsoft.Win32.RegistryView; -#else - using Registry = Microsoft.Win32.Registry; -#endif - using StringBuilder = System.Text.StringBuilder; - - internal class AntlrClassGenerationTaskInternal : MarshalByRefObject - { - private List _generatedCodeFiles = new List(); - private IList _sourceCodeFiles = new List(); - private List _buildMessages = new List(); - - public IList GeneratedCodeFiles - { - get - { - return this._generatedCodeFiles; - } - } - - public string ToolPath - { - get; - set; - } - - public string TargetLanguage - { - get; - set; - } - - public string TargetFrameworkVersion - { - get; - set; - } - - public string OutputPath - { - get; - set; - } - - public string TargetNamespace - { - get; - set; - } - - public string[] LanguageSourceExtensions - { - get; - set; - } - - public bool GenerateListener - { - get; - set; - } - - public bool GenerateVisitor - { - get; - set; - } - - public bool ForceAtn - { - get; - set; - } - - public bool AbstractGrammar - { - get; - set; - } - - public string JavaVendor - { - get; - set; - } - - public string JavaInstallation - { - get; - set; - } - - public string JavaExecutable - { - get; - set; - } - - public IList SourceCodeFiles - { - get - { - return this._sourceCodeFiles; - } - set - { - this._sourceCodeFiles = value; - } - } - - public IList BuildMessages - { - get - { - return _buildMessages; - } - } - -#if NET40PLUS - private string JavaHome - { - get - { - string javaHome; - if (TryGetJavaHome(RegistryView.Default, JavaVendor, JavaInstallation, out javaHome)) - return javaHome; - - if (TryGetJavaHome(RegistryView.Registry64, JavaVendor, JavaInstallation, out javaHome)) - return javaHome; - - if (TryGetJavaHome(RegistryView.Registry32, JavaVendor, JavaInstallation, out javaHome)) - return javaHome; - - throw new NotSupportedException("Could not locate a Java installation."); - } - } - - private static bool TryGetJavaHome(RegistryView registryView, string vendor, string installation, out string javaHome) - { - javaHome = null; - - string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation; - using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView)) - { - using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName)) - { - if (javaKey == null) - return false; - - object currentVersion = javaKey.GetValue("CurrentVersion"); - if (currentVersion == null) - return false; - - using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString())) - { - if (homeKey == null || homeKey.GetValue("JavaHome") == null) - return false; - - javaHome = homeKey.GetValue("JavaHome").ToString(); - return !string.IsNullOrEmpty(javaHome); - } - } - } - } -#else - private string JavaHome - { - get - { - string javaHome; - if (TryGetJavaHome(Registry.LocalMachine, JavaVendor, JavaInstallation, out javaHome)) - return javaHome; - - throw new NotSupportedException("Could not locate a Java installation."); - } - } - - private static bool TryGetJavaHome(RegistryKey baseKey, string vendor, string installation, out string javaHome) - { - javaHome = null; - - string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation; - using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName)) - { - if (javaKey == null) - return false; - - object currentVersion = javaKey.GetValue("CurrentVersion"); - if (currentVersion == null) - return false; - - using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString())) - { - if (homeKey == null || homeKey.GetValue("JavaHome") == null) - return false; - - javaHome = homeKey.GetValue("JavaHome").ToString(); - return !string.IsNullOrEmpty(javaHome); - } - } - } -#endif - - public bool Execute() - { - try - { - string java; - if (!string.IsNullOrEmpty(JavaExecutable)) - { - java = JavaExecutable; - } - else - { - string javaHome = JavaHome; - java = Path.Combine(Path.Combine(javaHome, "bin"), "java.exe"); - } - - List arguments = new List(); - arguments.Add("-cp"); - arguments.Add(ToolPath); - arguments.Add("org.antlr.v4.CSharpTool"); - - arguments.Add("-o"); - arguments.Add(OutputPath); - - if (GenerateListener) - arguments.Add("-listener"); - else - arguments.Add("-no-listener"); - - if (GenerateVisitor) - arguments.Add("-visitor"); - else - arguments.Add("-no-visitor"); - - if (ForceAtn) - arguments.Add("-Xforce-atn"); - - if (AbstractGrammar) - arguments.Add("-Dabstract=true"); - - if (!string.IsNullOrEmpty(TargetLanguage)) - { - string framework = TargetFrameworkVersion; - if (string.IsNullOrEmpty(framework)) - framework = "v2.0"; - if (framework.StartsWith("v4.5.")) - framework = "v4.5"; - - string language; - if (TargetLanguage.Equals("CSharp", StringComparison.OrdinalIgnoreCase)) - language = TargetLanguage + '_' + framework.Replace('.', '_'); - else - language = TargetLanguage; - - arguments.Add("-Dlanguage=" + language); - } - - if (!string.IsNullOrEmpty(TargetNamespace)) - { - arguments.Add("-package"); - arguments.Add(TargetNamespace); - } - - arguments.AddRange(SourceCodeFiles); - - ProcessStartInfo startInfo = new ProcessStartInfo(java, JoinArguments(arguments)) - { - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardInput = true, - RedirectStandardOutput = true, - RedirectStandardError = true, - }; - - this.BuildMessages.Add(new BuildMessage(TraceLevel.Info, "Executing command: \"" + startInfo.FileName + "\" " + startInfo.Arguments, "", 0, 0)); - - Process process = new Process(); - process.StartInfo = startInfo; - process.ErrorDataReceived += HandleErrorDataReceived; - process.OutputDataReceived += HandleOutputDataReceived; - process.Start(); - process.BeginErrorReadLine(); - process.BeginOutputReadLine(); - process.StandardInput.Close(); - process.WaitForExit(); - - return process.ExitCode == 0; - //using (LoggingTraceListener traceListener = new LoggingTraceListener(_buildMessages)) - //{ - // SetTraceListener(traceListener); - // ProcessArgs(args.ToArray()); - // process(); - //} - - //_generatedCodeFiles.AddRange(GetGeneratedFiles().Where(file => LanguageSourceExtensions.Contains(Path.GetExtension(file), StringComparer.OrdinalIgnoreCase))); - - //int errorCount = GetNumErrors(); - //return errorCount == 0; - } - catch (Exception e) - { - if (e is TargetInvocationException && e.InnerException != null) - e = e.InnerException; - - _buildMessages.Add(new BuildMessage(e.Message)); - throw; - } - } - - private static string JoinArguments(IEnumerable arguments) - { - if (arguments == null) - throw new ArgumentNullException("arguments"); - - StringBuilder builder = new StringBuilder(); - foreach (string argument in arguments) - { - if (builder.Length > 0) - builder.Append(' '); - - if (argument.IndexOfAny(new[] { '"', ' ' }) < 0) - { - builder.Append(argument); - continue; - } - - // escape a backslash appearing before a quote - string arg = argument.Replace("\\\"", "\\\\\""); - // escape double quotes - arg = arg.Replace("\"", "\\\""); - - // wrap the argument in outer quotes - builder.Append('"').Append(arg).Append('"'); - } - - return builder.ToString(); - } - - private static readonly Regex GeneratedFileMessageFormat = new Regex(@"^Generating file '(?.*?)' for grammar '(?.*?)'$", RegexOptions.Compiled); - - private void HandleErrorDataReceived(object sender, DataReceivedEventArgs e) - { - if (string.IsNullOrEmpty(e.Data)) - return; - - try - { - _buildMessages.Add(new BuildMessage(e.Data)); - } - catch (Exception ex) - { - if (Antlr4ClassGenerationTask.IsFatalException(ex)) - throw; - - _buildMessages.Add(new BuildMessage(ex.Message)); - } - } - - private void HandleOutputDataReceived(object sender, DataReceivedEventArgs e) - { - if (string.IsNullOrEmpty(e.Data)) - return; - - try - { - Match match = GeneratedFileMessageFormat.Match(e.Data); - if (!match.Success) - { - _buildMessages.Add(new BuildMessage(e.Data)); - return; - } - - string fileName = match.Groups["OUTPUT"].Value; - if (LanguageSourceExtensions.Contains(Path.GetExtension(fileName), StringComparer.OrdinalIgnoreCase)) - GeneratedCodeFiles.Add(match.Groups["OUTPUT"].Value); - } - catch (Exception ex) - { - if (Antlr4ClassGenerationTask.IsFatalException(ex)) - throw; - - _buildMessages.Add(new BuildMessage(ex.Message)); - } - } - } -} diff --git a/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs b/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs deleted file mode 100644 index fb0f876b5..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs +++ /dev/null @@ -1,120 +0,0 @@ -/* - * [The "BSD licence"] - * 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.Build.Tasks -{ - using System; - using System.Diagnostics; - using System.Text.RegularExpressions; - - [Serializable] - internal struct BuildMessage - { - private static readonly Regex BuildMessageFormat = new Regex(@"^\s*(?[a-z]+)\((?[0-9]+)\):\s*((?.*):(?[0-9]+):(?[0-9]+):)?\s*(?:syntax error:\s*)?(?.*)$", RegexOptions.Compiled); - - public BuildMessage(string message) - : this(TraceLevel.Error, message, null, 0, 0) - { - try - { - Match match = BuildMessageFormat.Match(message); - if (match.Success) - { - FileName = match.Groups["FILE"].Length > 0 ? match.Groups["FILE"].Value : ""; - LineNumber = match.Groups["LINE"].Length > 0 ? int.Parse(match.Groups["LINE"].Value) : 0; - ColumnNumber = match.Groups["COLUMN"].Length > 0 ? int.Parse(match.Groups["COLUMN"].Value) + 1 : 0; - - switch (match.Groups["SEVERITY"].Value) - { - case "warning": - Severity = TraceLevel.Warning; - break; - case "error": - Severity = TraceLevel.Error; - break; - default: - Severity = TraceLevel.Info; - break; - } - - int code = int.Parse(match.Groups["CODE"].Value); - Message = string.Format("AC{0:0000}: {1}", code, match.Groups["MESSAGE"].Value); - } - else - { - Message = message; - } - } - catch (Exception ex) - { - if (Antlr4ClassGenerationTask.IsFatalException(ex)) - throw; - } - } - - public BuildMessage(TraceLevel severity, string message, string fileName, int lineNumber, int columnNumber) - : this() - { - Severity = severity; - Message = message; - FileName = fileName; - LineNumber = lineNumber; - ColumnNumber = columnNumber; - } - - public TraceLevel Severity - { - get; - set; - } - - public string Message - { - get; - set; - } - - public string FileName - { - get; - set; - } - - public int LineNumber - { - get; - set; - } - - public int ColumnNumber - { - get; - set; - } - } -} diff --git a/runtime/CSharp/Antlr4BuildTasks/GlobalSuppressions.cs b/runtime/CSharp/Antlr4BuildTasks/GlobalSuppressions.cs deleted file mode 100644 index 6df546848..000000000 Binary files a/runtime/CSharp/Antlr4BuildTasks/GlobalSuppressions.cs and /dev/null differ diff --git a/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs b/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs deleted file mode 100644 index 7cce6b570..000000000 --- a/runtime/CSharp/Antlr4BuildTasks/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,75 +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.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -#if NET40 -[assembly: AssemblyTitle("Antlr4BuildTasks.net40")] -[assembly: AssemblyProduct("Antlr4BuildTasks.net40")] -#elif NET35 -[assembly: AssemblyTitle("Antlr4BuildTasks.net35")] -[assembly: AssemblyProduct("Antlr4BuildTasks.net35")] -#else -#error Unknown assembly. -#endif -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] -[assembly: AssemblyCopyright("Copyright © Sam Harwell 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] -[assembly: CLSCompliant(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e79060d9-d211-4367-925a-5541943d3857")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.4.0.0")] -[assembly: AssemblyFileVersion("4.4.1.0")] -[assembly: AssemblyInformationalVersion("4.4.1-dev")] diff --git a/runtime/CSharp/build/CodeAnalysisDictionary.xsd b/runtime/CSharp/build/CodeAnalysisDictionary.xsd deleted file mode 100644 index aaf062ea5..000000000 --- a/runtime/CSharp/build/CodeAnalysisDictionary.xsd +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/runtime/CSharp/build/CustomDictionary.xml b/runtime/CSharp/build/CustomDictionary.xml deleted file mode 100644 index e7ee58453..000000000 --- a/runtime/CSharp/build/CustomDictionary.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Antlr - Atn - - - diff --git a/runtime/CSharp/build/KeyReporting.targets b/runtime/CSharp/build/KeyReporting.targets deleted file mode 100644 index 9a7ac5429..000000000 --- a/runtime/CSharp/build/KeyReporting.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - This project references a strong name key that is missing on this computer. Run 'sn -k {0}' to generate the file. - - - - - diff --git a/runtime/CSharp/Antlr4.Test.mono/Antlr4.Test.mono.csproj b/tool/test/org/antlr/v4/test/rt/csharp/Antlr4.Test.vs2013.csproj similarity index 80% rename from runtime/CSharp/Antlr4.Test.mono/Antlr4.Test.mono.csproj rename to tool/test/org/antlr/v4/test/rt/csharp/Antlr4.Test.vs2013.csproj index 51ab4af13..99ef488f5 100644 --- a/runtime/CSharp/Antlr4.Test.mono/Antlr4.Test.mono.csproj +++ b/tool/test/org/antlr/v4/test/rt/csharp/Antlr4.Test.vs2013.csproj @@ -30,20 +30,15 @@ - - - - - - + - + {E1A46D9D-66CB-46E8-93B0-7FC87299ABEF} - Antlr4.Runtime.mono + Antlr4.Runtime.vs2013 diff --git a/tool/test/org/antlr/v4/test/rt/csharp/BaseTest.java b/tool/test/org/antlr/v4/test/rt/csharp/BaseTest.java index 5fd46d9da..bda1c25da 100644 --- a/tool/test/org/antlr/v4/test/rt/csharp/BaseTest.java +++ b/tool/test/org/antlr/v4/test/rt/csharp/BaseTest.java @@ -421,13 +421,18 @@ public abstract class BaseTest { } private String locateMSBuild() { - return locateTool("xbuild"); + if(isWindows()) + return "\"C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\MSBuild.exe\""; + else + return locateTool("xbuild"); } - private String locateExec() { - return locateTool("mono"); - // new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath(), + private boolean isWindows() { + return System.getProperty("os.name").toLowerCase().contains("windows"); + } + private String locateExec() { + return new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath(); } private String locateTool(String tool) { @@ -451,17 +456,19 @@ public abstract class BaseTest { output.close(); input.close(); // update project - input = Thread.currentThread().getContextClassLoader().getResourceAsStream(pack + "Antlr4.Test.mono.csproj"); + String projectName = isWindows() ? "Antlr4.Test.vs2013.csproj" : "Antlr4.Test.mono.csproj"; + input = Thread.currentThread().getContextClassLoader().getResourceAsStream(pack + projectName); Document prjXml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input); // update runtime project reference String runtimePath = System.getProperty("antlr-csharp-runtime-project"); + String runtimeName = isWindows() ? "Antlr4.Runtime.vs2013.csproj" : "Antlr4.Runtime.mono.csproj"; if(runtimePath==null) - runtimePath = "../../antlr4-csharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj"; + runtimePath = "../../antlr4-csharp/runtime/CSharp/Antlr4.Runtime/" + runtimeName; File projFile = new File(runtimePath); if(!projFile.exists()) throw new RuntimeException("C# runtime project file not found at:" + projFile.getAbsolutePath()); runtimePath = projFile.getAbsolutePath(); - XPathExpression exp = XPathFactory.newInstance().newXPath().compile("/Project/ItemGroup/ProjectReference[@Include='Antlr4.Runtime.mono.csproj']"); + XPathExpression exp = XPathFactory.newInstance().newXPath().compile("/Project/ItemGroup/ProjectReference[@Include='" + runtimeName + "']"); Element node = (Element)exp.evaluate(prjXml, XPathConstants.NODE); node.setAttribute("Include", runtimePath.replace("/", "\\")); // update project file list @@ -494,11 +501,9 @@ public abstract class BaseTest { public String execTest() { try { String exec = locateExec(); - String[] args = new String[] { - exec, - new File(tmpdir, "bin/Release/Test.exe").getAbsolutePath(), - new File(tmpdir, "input").getAbsolutePath() - }; + String[] args = isWindows() ? + new String[] { exec, new File(tmpdir, "input").getAbsolutePath() } : + new String[] { "mono", exec, new File(tmpdir, "input").getAbsolutePath() }; ProcessBuilder pb = new ProcessBuilder(args); pb.directory(new File(tmpdir)); Process p = pb.start();