[antlr-interest] [CSharp3] TraceIn/TraceOut and ANTLR_TRACE conditional
Peter Kooiman
peter at crispu.com
Sat Apr 2 09:42:05 PDT 2011
After struggling a bit to get tracing working in my parser by defining ANTLR_TRACE and getting nowhere, I realized the following, which may or may not be intended:
Both the Parser and Lexer classes inherit from BaseRecognizer and override (well, hide) the BaseRecognizer TraceIn and TraceOut methods. These overrides call base.Traceout / base.TraceIn, BUT, since during library compilation ANTLR_TRACE is not defined, these base method calls become no-ops. The result is, that while BaseRecognizer has usable TraceIn and TraceOut methods, the TraceIn and TraceOut methods of both Parser and Lexer become essentially no-ops.
This is the MSIL for Parser::TraceIn in Antlr3.Runtime.dll:
.method public hidebysig newslot virtual
instance void TraceIn(string ruleName,
int32 ruleIndex) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.ConditionalAttribute::.ctor(string) = ( 01 00 0B 41 4E 54 4C 52 5F 54 52 41 43 45 00 00 ) // ...ANTLR_TRACE..
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method Parser::TraceIn
Fixed easily enough by overriding TraceIn/TraceOut in my parser, but a bit of a pain to figure out, so I thought I'd at least document it here.
Regards
Peter
More information about the antlr-interest
mailing list