From 20141d53a04a42ca261e031ccab2adb5be47742c Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Mon, 13 May 2019 13:34:45 +0300 Subject: [PATCH 1/2] Support for TreatWarningsAsErrors, SuperClass, ContextSuperClass options in build task, fixes #278 --- .../Antlr4.CodeGenerator.targets | 10 ++++-- .../Antlr4ClassGenerationTask.cs | 21 ++++++++++++ .../Antlr4ClassGenerationTaskInternal.cs | 33 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets b/runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets index 5201f3f3..b08e384b 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets @@ -85,6 +85,9 @@ true false false + false + + @@ -149,7 +152,10 @@ GenerateVisitor="%(Antlr4.Visitor)" ForceAtn="%(Antlr4.ForceAtn)" AbstractGrammar="%(Antlr4.Abstract)" - UseCSharpGenerator="$(Antlr4UseCSharpGenerator)"> + UseCSharpGenerator="$(Antlr4UseCSharpGenerator)" + TreatWarningsAsErrors="%(Antlr4.TreatWarningsAsErrors)" + SuperClass="%(Antlr4.SuperClass)" + ContextSuperClass="%(Antlr4.ContextSuperClass)"> @@ -196,7 +202,7 @@ - + diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs index 00dab1d7..d315ffaa 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs @@ -151,6 +151,24 @@ public bool UseCSharpGenerator set; } + public bool TreatWarningsAsErrors + { + get; + set; + } + + public string SuperClass + { + get; + set; + } + + public string ContextSuperClass + { + get; + set; + } + [Output] public ITaskItem[] GeneratedCodeFiles { @@ -306,6 +324,9 @@ private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper() wrapper.JavaInstallation = JavaInstallation; wrapper.JavaExecutable = JavaExecutable; wrapper.UseCSharpGenerator = UseCSharpGenerator; + wrapper.TreatWarningsAsErrors = TreatWarningsAsErrors; + wrapper.SuperClass = SuperClass; + wrapper.ContextSuperClass = ContextSuperClass; return wrapper; } diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs index 852d4e8c..fe4b7436 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTaskInternal.cs @@ -121,6 +121,24 @@ public bool UseCSharpGenerator set; } + public bool TreatWarningsAsErrors + { + get; + set; + } + + public string SuperClass + { + get; + set; + } + + public string ContextSuperClass + { + get; + set; + } + public IList SourceCodeFiles { get @@ -282,6 +300,21 @@ public bool Execute() arguments.Add(TargetNamespace); } + if (TreatWarningsAsErrors) + arguments.Add("-Werror"); + + if (!string.IsNullOrEmpty(SuperClass)) + { + arguments.Add("-DsuperClass"); + arguments.Add(SuperClass); + } + + if (!string.IsNullOrEmpty(ContextSuperClass)) + { + arguments.Add("-DcontextSuperClass"); + arguments.Add(ContextSuperClass); + } + arguments.AddRange(SourceCodeFiles); #if NETSTANDARD From 9ceb743b0636a266aa9b643f3595b198f097bf24 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Mon, 13 May 2019 14:04:06 +0300 Subject: [PATCH 2/2] Extend Readme.md with new info about TreatWarningsAsErrors, SuperClass, ContextSuperClass properties --- Readme.md | 3 +++ runtime/CSharp/Antlr4BuildTasks/Antlr4.xml | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Readme.md b/Readme.md index dab64df6..5b3fde95 100644 --- a/Readme.md +++ b/Readme.md @@ -149,6 +149,9 @@ The following table describes the properties available for customizing the code | `ForceAtn` | Force ATN | `True` or `False` | When `True`, the generated parser will use `AdaptivePredict` for all decisions, including LL(1) decisions. | | `Listener` | Generate Listener | `True` or `False` | When `True`, a parse tree listener interface and base class will be generated for the parLitser. | | `Visitor` | Generate Visitor | `True` or `False` | When `True`, a parse tree visitor interface and base class will be generated for the parser. | +| `TreatWarningsAsErrors` | Treat Warnings as Errors | `True` or `False` | When `True`, the warning are treated as errors. | +| `SuperClass` | SuperClass | `string` | Set the superclass of the generated parser or lexer. For combined grammars, it sets the superclass of the parser. | +| `ContextSuperClass` | ContextSuperClass | `string` | Specify the super class of parse tree internal nodes. Should derive from ultimately RuleContext at minimum. | #### Using the ANTLR Language Support extension diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4.xml b/runtime/CSharp/Antlr4BuildTasks/Antlr4.xml index 6cc287ad..edd5114b 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4.xml +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4.xml @@ -40,6 +40,24 @@ DisplayName="Abstract Grammar" Default="false" Description="When true, the generated classes are marked as abstract." /> + + +