Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use debugger non user code attribute #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ 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. |

| `IncludeDebuggerNonUserCodeAttribute` | `Include DebuggerNonUserCode attribute` | `True` or `False` | When `True`, each method will have the DebuggerNonUserCode attribute attribute added. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `IncludeDebuggerNonUserCodeAttribute` | `Include DebuggerNonUserCode attribute` | `True` or `False` | When `True`, each method will have the DebuggerNonUserCode attribute attribute added. |
| `IncludeDebuggerNonUserCodeAttribute` | Include `DebuggerNonUserCode` attribute | `True` or `False` | When `True`, each method will have the DebuggerNonUserCode attribute attribute added. |

#### Using the ANTLR Language Support extension

1. Right click the grammar file in **Solution Explorer** and select **Properties**
Expand Down
2 changes: 2 additions & 0 deletions runtime/CSharp/Antlr4.Tool/Codegen/Model/OutputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class OutputFile : OutputModelObject
public readonly string ANTLRVersion;
public readonly string TokenLabelType;
public readonly string InputSymbolType;
public readonly bool IncludeDebuggerNonUserCodeAttribute; // from -DincludeDebuggerNonUserCodeAttribute

protected OutputFile(OutputModelFactory factory, string fileName)
: base(factory)
Expand All @@ -24,6 +25,7 @@ protected OutputFile(OutputModelFactory factory, string fileName)
ANTLRVersion = AntlrTool.VERSION;
TokenLabelType = g.GetOptionString("TokenLabelType");
InputSymbolType = TokenLabelType;
IncludeDebuggerNonUserCodeAttribute = System.StringComparer.OrdinalIgnoreCase.Equals( g.GetOptionString("includeDebuggerNonUserCodeAttribute"), "true" );
}

public virtual IDictionary<string, Action> BuildNamedActions(Grammar g)
Expand Down
1 change: 1 addition & 0 deletions runtime/CSharp/Antlr4.Tool/Tool/Grammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Grammar : AttributeResolver
"tokenVocab",
"language",
"exportMacro",
"includeDebuggerNonUserCodeAttribute",
};

public static readonly ISet<string> lexerOptions = parserOptions;
Expand Down
4 changes: 3 additions & 1 deletion runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Visitor>true</Visitor>
<Abstract>false</Abstract>
<ForceAtn>false</ForceAtn>
<IncludeDebuggerNonUserCodeAttribute>false</IncludeDebuggerNonUserCodeAttribute>
</Antlr4>
</ItemDefinitionGroup>

Expand Down Expand Up @@ -149,7 +150,8 @@
GenerateVisitor="%(Antlr4.Visitor)"
ForceAtn="%(Antlr4.ForceAtn)"
AbstractGrammar="%(Antlr4.Abstract)"
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)">
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)"
IncludeDebuggerNonUserCodeAttribute="$(IncludeDebuggerNonUserCodeAttribute)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IncludeDebuggerNonUserCodeAttribute="$(IncludeDebuggerNonUserCodeAttribute)">
IncludeDebuggerNonUserCodeAttribute="%(Antlr4.IncludeDebuggerNonUserCodeAttribute)">


<Output ItemName="Antlr4GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
</Antlr4ClassGenerationTask>
Expand Down
7 changes: 6 additions & 1 deletion runtime/CSharp/Antlr4BuildTasks/Antlr4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
DisplayName="Abstract Grammar"
Default="false"
Description="When true, the generated classes are marked as abstract." />

<BoolProperty
Category="ANTLR"
Name="IncludeDebuggerNonUserCodeAttribute"
DisplayName="Include DebuggerNonUserCode attribute"
Default="false"
Description="When true, includes the DebuggerNonUserCode attribute against each method." />
<!--
The rest of these properties are not ANTLR-specific, but CPS provides no way to inherit properties, so if we fail to
include them then they will just disappear.
Expand Down
7 changes: 7 additions & 0 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ public bool UseCSharpGenerator
set;
}

public bool IncludeDebuggerNonUserCodeAttribute
{
get;
set;
}

[Output]
public ITaskItem[] GeneratedCodeFiles
{
Expand Down Expand Up @@ -306,6 +312,7 @@ private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper()
wrapper.JavaInstallation = JavaInstallation;
wrapper.JavaExecutable = JavaExecutable;
wrapper.UseCSharpGenerator = UseCSharpGenerator;
wrapper.IncludeDebuggerNonUserCodeAttribute = IncludeDebuggerNonUserCodeAttribute;
return wrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public bool UseCSharpGenerator
set;
}

public bool IncludeDebuggerNonUserCodeAttribute
{
get;
set;
}

public IList<string> SourceCodeFiles
{
get
Expand Down Expand Up @@ -284,6 +290,12 @@ public bool Execute()

arguments.AddRange(SourceCodeFiles);

if (UseCSharpGenerator)
{
if (IncludeDebuggerNonUserCodeAttribute)
arguments.Add("-DincludeDebuggerNonUserCodeAttribute");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arguments.Add("-DincludeDebuggerNonUserCodeAttribute");
arguments.Add("-DincludeDebuggerNonUserCodeAttribute=true");

}

#if NETSTANDARD
if (UseCSharpGenerator)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
/// \</summary>
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<file.ANTLRVersion>")]
[System.CLSCompliant(false)]
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public partial class <file.grammarName>BaseListener : I<file.grammarName>Listener {
<file.listenerNames:{lname |
/// \<summary>
Expand Down Expand Up @@ -184,6 +185,7 @@ using ParserRuleContext = Antlr4.Runtime.ParserRuleContext;
/// \<typeparam name="Result">The return type of the visit operation.\</typeparam>
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<file.ANTLRVersion>")]
[System.CLSCompliant(false)]
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public partial class <file.grammarName>BaseVisitor\<Result> : AbstractParseTreeVisitor\<Result>, I<file.grammarName>Visitor\<Result> {
<file.visitorNames:{lname |
/// \<summary>
Expand Down Expand Up @@ -238,6 +240,7 @@ Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= <<
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<file.ANTLRVersion>")]
[System.CLSCompliant(false)]
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public <if(parser.abstractRecognizer)>abstract <endif>partial class <csIdentifier.(parser.name)> : <superClass; null="Parser"> {
<if(parser.tokens)>
public const int
Expand Down Expand Up @@ -843,6 +846,7 @@ CaptureNextToken(d) ::= "<d.varName> = _input.Lt(1);"
CaptureNextTokenType(d) ::= "<d.varName> = _input.La(1);"

StructDecl(struct,ctorAttrs,attrs,getters,dispatchMethods,interfaces,extensionMembers) ::= <<
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public partial class <struct.name> : <if(contextSuperClass)><contextSuperClass><else>ParserRuleContext<endif><if(interfaces)>, <interfaces; separator=", "><endif> {
<attrs:{a | public <a>;}; separator="\n">
<getters:{g | <g>}; separator="\n">
Expand All @@ -866,6 +870,7 @@ public partial class <struct.name> : <if(contextSuperClass)><contextSuperClass><
>>

AltLabelStructDecl(struct,attrs,getters,dispatchMethods) ::= <<
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public partial class <struct.name> : <currentRule.name; format="cap">Context {
<attrs:{a | public <a>;}; separator="\n">
<getters:{g | <g>}; separator="\n">
Expand Down Expand Up @@ -961,6 +966,7 @@ using DFA = Antlr4.Runtime.Dfa.DFA;
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "<file.ANTLRVersion>")]
[System.CLSCompliant(false)]
<if(file.IncludeDebuggerNonUserCodeAttribute)>[System.Diagnostics.DebuggerNonUserCode]<endif>
public <if(lexer.abstractRecognizer)>abstract <endif>partial class <csIdentifier.(lexer.name)> : <superClass; null="Lexer"> {
public const int
<lexer.tokens:{k | <tokenType.(k)>=<lexer.tokens.(k)>}; separator=", ", wrap, anchor>;
Expand Down