How to get the definition of a name in a transformation
In a transformation, how can I get the referrenced AST? For example:
foo : Import(m) -> ...body... where Module(mname, imps, body) := <?> m
The binding rules for modules and imports:
Asked by Sebastian Erdweg on 7 May 2014 at 13:12Module(m, _, _): defines unique Module m Import(m): refers to Module m
1 Answer
Currently you can’t. You have to store the AST itself in the index with a property.
properties ast of Module : Term binding rules a@Module(m, _, _): defines unique Module m of ast a
I’m however not sure what the performance implications of that are.
I would argue however that it is desirable to be able to get the ast, based on the parent-node of a name.
Answered by Daco Harkes on 7 May 2014 at 13:34
This would enable model -> target language AST transformations, instead of the source language AST -> target language AST transformations.