- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Quick compiler internals query
Thu, 2009-12-03, 20:33
Do we have a mechanism in the compiler to view a Tree node as it existed before being transformed by a previous phase?I've browsed the source, but nothing obvious stands out
Sat, 2009-12-05, 21:47
#2
an easy way to compare AST trees across compilation phases
I've settled on the following procedure, which involves writing zero lines
of code.
1) run the compiler to get a textual representation of the AST just before
the transformation of interest, e.g.
-Xprint:explicitouter -Yshow-trees
2) ditto for the phase afterwards
3) let the IDE compare both text files
Before noticing NodePrinters, I even considered visiting the AST using
reflection and Integer.toHexString(System.identityHashCode(object))
Good that I didn't get carried away with that :-)
Sat, 2009-12-05, 22:07
#3
Re: an easy way to compare AST trees across compilation phases
Useful stuff :)
Do we have a summary anywhere of all the -X and -Y options?Unfortunately, the descriptions in Settings.scala aren't always as helpful as perhaps they could be.
On Sat, Dec 5, 2009 at 8:39 PM, Miguel Garcia <miguel.garcia@tuhh.de> wrote:
Do we have a summary anywhere of all the -X and -Y options?Unfortunately, the descriptions in Settings.scala aren't always as helpful as perhaps they could be.
On Sat, Dec 5, 2009 at 8:39 PM, Miguel Garcia <miguel.garcia@tuhh.de> wrote:
I've settled on the following procedure, which involves writing zero lines of code.
1) run the compiler to get a textual representation of the AST just before the transformation of interest, e.g.
-Xprint:explicitouter -Yshow-trees
2) ditto for the phase afterwards
3) let the IDE compare both text files
Before noticing NodePrinters, I even considered visiting the AST using reflection and Integer.toHexString(System.identityHashCode(object))
Good that I didn't get carried away with that :-)
Miguel
http://www.sts.tu-harburg.de/people/mi.garcia
Sat, 2009-12-05, 22:17
#4
Re: an easy way to compare AST trees across compilation phases
> Do we have a summary anywhere of all the -X and -Y options?
> Unfortunately, the descriptions in Settings.scala aren't always as helpful
> as perhaps they could be.
Hmmm, besides:
- placing the cursor on a setting in Settings.scala and letting the IDE
find usages for it
- browsing the changesets involving some setting
No, I guess that's all there is :-)
Kevin,
Sometimes one needs to compare the pre and the post versions of a Tree after
a transformation. Not sure if that's what you're asking about. I never
streamlined a workflow for that, but some unpolished ideas are:
1) subclass LazyTreeCopier to trace where updates occurred. As a reminder
:-) the typical AST-node-handler in LazyTreeCopier looks as follows:
def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams:
List[TypeDef], impl: Template) = tree match {
case t @ ClassDef(mods0, name0, tparams0, impl0)
if (mods0 == mods) && (name0 == name) && (tparams0 == tparams) &&
(impl0 == impl) => t
case _ => treeCopy.ClassDef(tree, mods, name, tparams, impl)
}
2) serialize the ASTs pre and post transformation into XML, then use an XML
diff tool
3) the Model-Driven community shares utilities for comparing objects graphs,
for example
http://www.eclipsecon.org/2008/sub/attachments/Comparing_and_Merging_Mod...
Miguel
http://www.sts.tu-harburg.de/people/mi.garcia