Turn on PPCallBacks

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Turn on PPCallBacks

Neil Nelson via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev