From dc8fc4f94f8482be2e7a08d4f7bb82f2d70c48cd Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Mon, 28 Dec 2020 13:51:17 +0300 Subject: [PATCH] Fix dotnet build, remove not used code --- .../v4/test/runtime/csharp/Antlr4.Test.csproj | 2 +- .../test/runtime/csharp/BaseCSharpTest.java | 42 +------------- .../Antlr4.Runtime/Antlr4.Runtime.csproj | 9 +-- .../Antlr4.Runtime/ParserRuleContext.cs | 56 +++++++++---------- .../Sharpen/SerializableAttribute.cs | 16 ------ 5 files changed, 33 insertions(+), 92 deletions(-) delete mode 100644 runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Sharpen/SerializableAttribute.cs diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/Antlr4.Test.csproj b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/Antlr4.Test.csproj index 3611a9857..b6436700f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/Antlr4.Test.csproj +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/Antlr4.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp3.1 $(NoWarn);CS3021 Test Exe diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java index 68f779291..bc356fd8f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java @@ -166,40 +166,6 @@ public class BaseCSharpTest implements RuntimeTestSupport { return antlrToolErrors.toString(); } - protected org.antlr.v4.Tool newTool(String[] args) { - Tool tool = new Tool(args); - return tool; - } - - protected Tool newTool() { - org.antlr.v4.Tool tool = new Tool(new String[]{"-o", tmpdir}); - return tool; - } - - protected String load(String fileName, String encoding) - throws IOException { - if (fileName == null) { - return null; - } - - String fullFileName = getClass().getPackage().getName().replace('.', '/') + '/' + fileName; - int size = 65000; - InputStreamReader isr; - InputStream fis = getClass().getClassLoader().getResourceAsStream(fullFileName); - if (encoding != null) { - isr = new InputStreamReader(fis, encoding); - } else { - isr = new InputStreamReader(fis); - } - try { - char[] data = new char[size]; - int n = isr.read(data); - return new String(data, 0, n); - } finally { - isr.close(); - } - } - protected String execLexer(String grammarFileName, String grammarStr, String lexerName, @@ -232,7 +198,7 @@ public class BaseCSharpTest implements RuntimeTestSupport { return output; } - Set sourceFiles = new HashSet(); + Set sourceFiles = new HashSet<>(); private void addSourceFiles(String... files) { for (String file : files) @@ -346,12 +312,8 @@ public class BaseCSharpTest implements RuntimeTestSupport { } } - private boolean isWindows() { - return System.getProperty("os.name").toLowerCase().contains("windows"); - } - private String locateExec() { - return new File(tmpdir, "bin/Release/netcoreapp2.0/Test.dll").getAbsolutePath(); + return new File(tmpdir, "bin/Release/netcoreapp3.1/Test.dll").getAbsolutePath(); } public boolean buildProject() { diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.csproj b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.csproj index b3c9c73fe..0da3e7abe 100644 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.csproj +++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.csproj @@ -15,14 +15,14 @@ Eric Vergnaud, Terence Parr, Sam Harwell The .NET Core C# ANTLR 4 runtime from the ANTLR Organization The runtime library for parsers generated by the C# target of the standard ANTLR 4 tool. - Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. + Copyright (c) 2012-2020 The ANTLR Project. All rights reserved. true - https://github.com/antlr/antlr4/blob/master/LICENSE.txt + BSD-3-Clause https://github.com/antlr/antlr4 + https://raw.github.com/antlr/website-antlr4/master/images/icons/antlr.png https://github.com/antlr/antlr4/releases antlr parsing grammar - 1.6.1 false false false @@ -44,7 +44,4 @@ true lib\Release - - NETSTANDARD20 - diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/ParserRuleContext.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/ParserRuleContext.cs index 4503db1dc..79c22daa5 100644 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/ParserRuleContext.cs +++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/ParserRuleContext.cs @@ -34,7 +34,7 @@ namespace Antlr4.Runtime /// public class ParserRuleContext : RuleContext { - public static readonly Antlr4.Runtime.ParserRuleContext EMPTY = new Antlr4.Runtime.ParserRuleContext(); + public static readonly Antlr4.Runtime.ParserRuleContext EMPTY = new Antlr4.Runtime.ParserRuleContext(); /// /// If we are debugging or building a parse tree for a visitor, @@ -174,6 +174,7 @@ namespace Antlr4.Runtime { children = new List(); } + children.Add(t); } @@ -183,6 +184,7 @@ namespace Antlr4.Runtime { children = new List(); } + children.Add(ruleInvocation); } @@ -236,6 +238,7 @@ namespace Antlr4.Runtime { return default(T); } + int j = -1; // what element have we found with ctxType? foreach (IParseTree o in children) @@ -245,10 +248,11 @@ namespace Antlr4.Runtime j++; if (j == i) { - return (T)o; + return (T) o; } } } + return default(T); } @@ -258,13 +262,14 @@ namespace Antlr4.Runtime { return null; } + int j = -1; // what token with ttype have we found? foreach (IParseTree o in children) { if (o is ITerminalNode) { - ITerminalNode tnode = (ITerminalNode)o; + ITerminalNode tnode = (ITerminalNode) o; IToken symbol = tnode.Symbol; if (symbol.Type == ttype) { @@ -276,21 +281,23 @@ namespace Antlr4.Runtime } } } + return null; } - public virtual IReadOnlyList GetTokens(int ttype) + public virtual ITerminalNode[] GetTokens(int ttype) { if (children == null) { return Collections.EmptyList(); } + List tokens = null; foreach (IParseTree o in children) { if (o is ITerminalNode) { - ITerminalNode tnode = (ITerminalNode)o; + ITerminalNode tnode = (ITerminalNode) o; IToken symbol = tnode.Symbol; if (symbol.Type == ttype) { @@ -298,16 +305,18 @@ namespace Antlr4.Runtime { tokens = new List(); } + tokens.Add(tnode); } } } + if (tokens == null) { return Collections.EmptyList(); } - return tokens; + return tokens.ToArray(); } public virtual T GetRuleContext(int i) @@ -316,13 +325,14 @@ namespace Antlr4.Runtime return GetChild(i); } - public virtual IReadOnlyList GetRuleContexts() + public virtual T[] GetRuleContexts() where T : Antlr4.Runtime.ParserRuleContext { if (children == null) { return Collections.EmptyList(); } + List contexts = null; foreach (IParseTree o in children) { @@ -332,23 +342,22 @@ namespace Antlr4.Runtime { contexts = new List(); } - contexts.Add((T)o); + + contexts.Add((T) o); } } + if (contexts == null) { return Collections.EmptyList(); } - return contexts; + return contexts.ToArray(); } public override int ChildCount { - get - { - return children != null ? children.Count : 0; - } + get { return children != null ? children.Count : 0; } } public override Interval SourceInterval @@ -359,32 +368,21 @@ namespace Antlr4.Runtime { return Interval.Invalid; } + return Interval.Of(_start.TokenIndex, _stop.TokenIndex); } } public virtual IToken Start { - get - { - return _start; - } - set - { - _start = value; - } + get { return _start; } + set { _start = value; } } public virtual IToken Stop { - get - { - return _stop; - } - set - { - _stop = value; - } + get { return _stop; } + set { _stop = value; } } /// Used for rule context info debugging during parse-time, not so much for ATN debugging diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Sharpen/SerializableAttribute.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Sharpen/SerializableAttribute.cs deleted file mode 100644 index ff18f30b9..000000000 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Sharpen/SerializableAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. - * Use of this file is governed by the BSD 3-clause license that - * can be found in the LICENSE.txt file in the project root. - */ - -#if NETSTANDARD20 - -namespace System -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)] - internal sealed class SerializableAttribute : Attribute - { - } -} - -#endif \ No newline at end of file