[llvm-dev] libclang - forcing of the ClangTool using the C++ mode
Ing. Ondřej Stárek via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 23 11:57:41 PDT 2018
Hi all,
I'm not sure whether this is the right mail list for my question but I'll try.
I work on a simple framework for automated testing (can be seen at
https://github.com/Staon/otest2). The framework describes tests as
a valid C++ files but there is a need for some preprocessing. And this
is the job for the libclang. Everything worked fine until I decided
to change suffix of the test files (different suffix is more easy
for build tools like (auto)make). Since, the ClangTool supposes
the input file as a linker input. I have tried the '-xc++' switch,
but with no success. How can I force the tool to handle my sources as C++?
I use the libLLVM and libclang 5.0
There is a simplified code here:
/* -- prepare compiler options */
std::vector<std::string> opts_;
opts_.push_back("otest2");
opts_.push_back("--extra-arg=-xc++");
opts_.push_back("--extra-arg=--std=c++11");
opts_.push_back("--extra-arg=-DOTEST2_PARSER_ACTIVE");
opts_.push_back("mytestfile.ot2");
/* -- parse the file */
std::vector<const char*> argv_;
for(const auto& arg_ : opts_)
argv_.push_back(arg_.c_str());
int argc_(argv_.size());
clang::tooling::CommonOptionsParser parseropts_(
argc_, argv_.data(), ParserOptCategory);
clang::tooling::ClangTool tool_(
parseropts_.getCompilations(),
parseropts_.getSourcePathList());
int retval_(tool_.run(new FrontendFactory));
Thank you for your help.
Staon
stareko at email.cz
More information about the llvm-dev
mailing list