Automating Clang Tool (with CommonOptionsParser)

Hello All,

We want to create a tool (in C# .NET, EXE) which invokes the clang tool (C++, DLL). While implementing we realized that the CommonOptionsParser only expects the call to the Clang tool to be in the form of command line options. Is there a way around this issue that someone has encountered earlier?

On the other hand, if I pass the c code as a string buffer to the tooling, the included .h files are not recognized by clang tooling. So somehow Common Options Parser was the choice.

int main(int argc, const char **argv) {

CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);

ClangTool Tool(OptionsParser.getCompilations(),OptionsParser.getSourcePathList());

int result = Tool.run(newFrontendActionFactory().get());

return result;

}

Any help would be greatly appreciated J

Regards,

Sunny. R. Billava

Hello All,

We want to create a tool (in C# .NET, EXE) which invokes the clang tool
(C++, DLL). While implementing we realized that the CommonOptionsParser
only expects the call to the Clang tool to be in the form of command line
options. Is there a way around this issue that someone has encountered
earlier?

On the other hand, if I pass the c code as a string buffer to the tooling,
the included .h files are not recognized by clang tooling. So somehow
Common Options Parser was the choice.

int main(int argc, const char **argv) {

CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);

       ClangTool Tool(OptionsParser.getCompilations(),OptionsParser.
getSourcePathList());

       int result = Tool.run(newFrontendActionFactory<DFAMainClassAction
>().get());

return result;

}

Any help would be greatly appreciated J

I think that you can use pass the arguments as an array of strings to your
DLL and create the tool using the FixedCompilationDatabase, like in the
example below:

   std::vector<std::string> CommandLineArguments = { "-I", "includes" }; //
Get the arguments
   // Create the tool
   std::unique_ptr<CompilationDatabase> Compilations(new
FixedCompilationDatabase(".", CommandLineArguments));
   ClangTool Tool(*Compilations, Filename);

Thanks Alex!!

This worked! : ) Awesome.

Regards,

Sunny. R. Billava