[cfe-dev] Turn on PPCallBacks

Timur Iskhakov via cfe-dev cfe-dev at lists.llvm.org
Mon May 23 16:08:28 PDT 2016


Hi all,

Can someone tell how to turn on PPCallBacks? I get no Callback functions
calls.

I have very simple code:

class MacroDefinitionCallback : public PPCallbacks {
public:
    MacroDefinitionCallback() {}
    void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) {
        cerr << "MacroDefined" << endl;
    }
}

int main() {
    ...

    MacroDefinitionCallback MDC;

ci.getPreprocessor().addPPCallbacks(llvm::make_unique<PPCallbacks>(MDC));

    do {
        ci.getPreprocessor().Lex(tok); // or LexUnexpandedToken
        // ci.getPreprocessor().DumpToken(tok); // All tokens are printed,
it is OK
    } while ( tok.isNot(clang::tok::eof));

    ...
}

Preprocessed file source:
#define sum(a, b) (a) + (b)

int main() {
    int s = sum(1, 2);
}

This program doesn't print anything, so what is the way to turn on the
callback?


Timur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160524/fcba116f/attachment.html>


More information about the cfe-dev mailing list