[antlr-interest] ASTPair handling in C# runtime for 2.7.6 (and _saveIndex bugs in 2.7.5)

Micheal J open.zone at virgin.net
Sat Oct 29 05:42:15 PDT 2005


Luis,

> Hi,
> 
> I haven't experienced the problem you described in the other 
> message. I guess a struct makes more sense at this point then.

Noted. 

> The _saveIndex optimization only declares _saveIndex when needed. 
> 
> The trouble is that the C# standard does not allow local 
> variable redeclarations in nested blocks (even if the 
> definition of local variable in the outer block occurs after 
> the declaration in the nested block): 

<snip>

What version of ANTLR/C# are you using?. IIRC, Kunle and I fixed this for
the 2.7.5 release.

If you are using 2.7.5, send me a small grammar that demonstrates the
problem.

> So _saveIndex should only be declared once in the outer block 
> and then used in the inner block. I don't think it's possible 
> to predict in the code generator that _saveIndex will be used 
> in a nested block? Personally I'm not sure this is worth all 
> the effort. Perhaps we should just stick to the way the Java 
> generator does it - once at the beginning of the method?

C# [unlike Java] generates warning for unused variables. We aim for codegen
output to be "warning-free".

> The 
> optimization has the side-effect that many _saveIndex 
> variables are declared that take up more memory than just 
> declaring it once at the beginning.

Nope. The C# compiler/CLR Jit system are smart enough (or should be smart
enough for CLRs on non-MS platforms) to reuse a single memory slot.

Micheal



More information about the antlr-interest mailing list