AST equality test that ignores NodeInfo
Gregory Crosswhite
gcross at u.washington.edu
Thu Feb 26 12:59:31 EST 2009
In my own code when I want to test that two ASTs are equivalent
ignoring nodeInfos, I first run them through a function which converts
all nodeInfos to internalNode and all idents to internalIdent. It
makes use of Data.Generics to accomplish this:
convertToInternal :: GenericT
convertToInternal = everywhere ((mkT convertToInternalNode) `extT`
convertToInternalIdent)
where
convertToInternalNode :: NodeInfo -> NodeInfo
convertToInternalNode _ = internalNode
convertToInternalIdent :: Ident -> Ident
convertToInternalIdent ident = internalIdent (identToString
ident)
If you're not familiar with the "Scrap-Your-Boilerplate" style, what
this code basically does is create a transformer which has specific
behaviours for the two explicitly given types and acts as the identity
on all other types, and the "everywhere" function goes through the
data structure and applies the transformer to all of the terms/
subterms in the AST.
Cheers,
Greg
On Feb 26, 2009, at 8:40 AM, Bueno, Denis wrote:
> Hi all,
>
> Is there a better way than implementing my own equality operator that
> explicitly ignores NodeInfo, which is almost all boilerplate and
> will take a
> lot of time? Is there a way to (ab)use Data.Typeable for this?
>
> If I have an AST for a C file, I would like to be able to read
> expressions
> from another file, to see if any of those expressions match any part
> of the
> AST while I'm traversing the AST.
> Denis
>
>
>
> _______________________________________________
> Language-c mailing list
> Language-c at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/language-c
More information about the Language-c
mailing list