Re: [Codenarc-user] can I change the compiler phase my rule runs in?
Brought to you by:
chrismair
From: Hamlet D'A. <ham...@gm...> - 2010-10-24 14:01:15
|
Hi Chris, Concerning a CompilePhase, here is what I tell people: if you want to write new AST do it in an early phase. If you want to read AST then do it in a later phase. More information is available in later phases so you have better information like resolved types when possible. The "tree is more dense" later on and more sparse earlier on. I would say just run everything in CLASS_GENERATION. The downside is that it might break any custom rules implemented, but honestly how likely is that... -- Hamlet D'Arcy ham...@gm... On Sun, Oct 24, 2010 at 8:17 AM, Chris Mair <chr...@ea...> wrote: > Hamlet, > > As I'm sure you saw in the code, that compiler phase is used in the > AbstractSourceCode class. And the AST for a SourceCode instance for a file > is only built once and then cached. So, to support different compiler > phases, I would lean toward having the SourceCode instance maintain a Map of > AST objects, keyed by the compiler phase, and pass the desired phase from > the Rule into the SourceCode object. I can work on that. > > That being said, what is the downside of having all of the rules use the > later compiler phase (CLASS_GENERATION)? I just tried to change the default > to CLASS_GENERATION, and it broke a bunch of code/tests. But, at least for a > few of the failures, I was able to adjust the AST manipulation in the code > and fix the tests. It might be a lot of work, but if I could do that > everywhere, would that be the "right" thing to do? > > Chris > > -----Original Message----- > *From:* Hamlet D'Arcy [mailto:ham...@gm...] > *Sent:* Friday, October 22, 2010 2:39 PM > *To:* chr...@wa... > *Cc:* Cod...@li... > *Subject:* Re: [Codenarc-user] can I change the compiler phase my rule > runs in? > > I am quite sure it is hardcoded as well. That's what I saw in the code :) > > Can we make it an optional property on AbstractAstVisitorRule, like this: > > class CouldReturnZeroLengthArrayRule extends AbstractAstVisitorRule { > String name = 'CouldReturnZeroLengthArray' > int priority = 2 > Class astVisitorClass = CouldReturnZeroLengthArrayAstVisitor > CompilePhase phase = CompilePhase.CLASS_GENERATION > } > > I could take a look at adding this feature if you want, but I'd rather > concentrate on writing new rules. Can you handle this? > > -- > Hamlet D'Arcy > ham...@gm... > > > > On Fri, Oct 22, 2010 at 1:24 PM, <chr...@wa...> wrote: > >> >> Hmmm. Not currently. That is hard-coded right now, I think. I'll take a >> look. >> >> >> >> *"Hamlet D'Arcy" <ham...@gm...>* >> >> 10/22/2010 02:11 PM >> To >> Cod...@li... >> cc >> Subject >> [Codenarc-user] can I change the compiler phase my rule runs in? >> >> >> >> >> can I change the compiler phase my rule runs in? >> >> I need to see ReturnStatement objects and those are only present in >> the Class Generation phase. >> >> Can I make my rule run in that phase? >> >> -- >> Hamlet D'Arcy >> ham...@gm... >> >> >> ------------------------------------------------------------------------------ >> Nokia and AT&T present the 2010 Calling All Innovators-North America >> contest >> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada >> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in >> marketing >> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store >> http://p.sf.net/sfu/nokia-dev2dev >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> >> ForwardSourceID:NT000CCCDE >> > > > > |