[antlr-interest] CSharp GeneratedCode attribute

Sam Harwell sharwell at pixelminegames.com
Sun Jun 14 05:31:34 PDT 2009


FxCop freaks out on ANTLR generated code right now and slows down so much it's effectively unusable. I've been meaning to address this issue in the CSharp3 target, but haven't yet. I'm curious how you're supposed to handle partial classes with the GeneratedCode attribute - I assume I have to mark the generated methods and fields instead of the whole class, and the generated code has an enormous number of fields (tokens and follow sets). It makes me wonder if the GeneratedCodeAttribute is conditional like the SuppressMessageAttribute, and if not, how much with the compiled code increase in size with them all marked. I'm guessing not much considering how large the compiled grammar already is.

I'll take a look at this when I get the chance, but it could take a few weeks right now.

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Johannes Luber
Sent: Saturday, June 13, 2009 6:08 PM
To: packadal; antlr-interest at antlr.org
Subject: Re: [antlr-interest] CSharp GeneratedCode attribute

> Hi,
> 
> For the current project I am working on, we need to use a parser.
> I convinced everybody here that writing your own parser is evil, because
> it
> takes much longer to write than using a tool conceived for this exact
> purpose.
> 
> Now we use C# and have some strict coding conventions, enforced using the
> Microsoft tools (FxCop and StyleCop).
> The problem being the antlr-generated code does not comply with these
> rules.
> 
> But Microsoft thought about the possibility of using generated code with
> these tools, and the [GeneratedCode(name, version)] attribute is here for
> this purpose. Hurray !
> The only problem remaining now is that this attribute cannot be placed
> correctly using the C# 2 template.
> 
> So I added a line in the C# 2 template (dunno if I done it "The Right Way"
> though) :
> 
> ...
> 
> 75  <docComment>
> *76  <if(actions.(actionScope).generatedVersion)>
> 77  [GeneratedCode("antlr", @"<actions.(actionScope).generatedVersion>")]
> 78
> 79  <endif>
> *80  <recognizer>
> ...

Hi!

>From what I can gather it seems to be the right place, though I wonder what other way you tried first. Regarding the CSharp3 target: Unlike CSharp2 it is/on the way to be completely .NET-compliant regarding the coding standards. I can't change it for CSharp2 yet because I have to worry about backwards-compatibility, but I plan parity for 3.2.

So the question remains, if including this attribute there makes sense if FxCop won't find anything. Sam, any comments?

Johannes

> Obviously in bold is what I added.
> >>From what I have seen this can also be added in the C# 3 template.
> 
> BTW, when will there be a release of antlrworks including version 3.1.3 of
> antlr ?
> I have tried it by myself but must have done something wrong as I get
> loads
> of errors when trying to compile.
> 
> Keep up the good work,
> Regards.
> 
> -- 
> - Always keep in mind that you may be wrong -

-- 
GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und Telefonanschluss
für nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list