[cfe-dev] clang Find the last #include

于 秋沣 via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 8 01:24:51 PST 2017


Hi All,

I'm working on a project which given a C/C++ source code, I need to find the last #include and insert one additional #include right after that. For example, suppose I have a file called Test.c which looks like this:

#include <stdio.h>
#include <stdlib.h>
int main(){
    // some code here...
}

I want to get the location of the #include <stdlib.h> and insert one extra #include, then the code should be like this:

#include <stdio.h>
#include <stdlib.h>
#include "extraInclude.h"
int main(){
    // some code here....
}

I feel like the right class I need to use is clang::Preprocessor and clang::PPCallbacks, but I haven't figured out a way to implement this.

Any help would be appreciated.

Patrick

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


More information about the cfe-dev mailing list