Help needed: ANTLR-like API on top of clang AST

Hi there,

total clang/llvm n00b here. I’m building a multilingual static analysis tool which has parsers for individual languages export an appropriately tagged language-agnostic AST for a single analyser binary to process. So far I’ve been using native parsers for Ruby and Go and ANTLR-based one for Swift.

ANTLR in particular won my heart because of it’s Listener API where 3 generic methods are provided:

void enterEveryRule(ParserRuleContext ctx)
void exitEveryRule(ParserRuleContext ctx)
void visitTerminal(TerminalNode node)

You can also subscribe to ‘enter’ and ‘exit’ events for particular rules that you find particularly interesting. So for a given rule you’d have four callbacks triggered - enterEveryRule, enterParticularRule, exitParticularRule, exitEveryRule - in this particular order. There is also concept of TerminalNodes which are things like literals etc.

Since this sort an API what feels most natural for the task at hand I would kindly like to solicit your advice on how to go about replicating it in clang.

Thanks in advance!