0

With clang::tooling::runToolOnCode I can provide std::string input but I only get a bool output.

static const char
  *const from = "#include <string.h>\n"
                "int main(void) {\n"
                "    for(int i=0; i<strlen(\"FOO\"); i++) {}\n"
                "}\n",
  *const want = "#include <string.h>\n"
                "int main(void) {\n"
                "    for(size_t i=0; i<strlen(\"FOO\"); i++) {}\n"
                "}\n";

clang::tooling::runToolOnCode(std::make_unique<TypeCorrectPluginAction>(), from));

How do I get the modified source-code, without outputting to disk and reading from disk?

Samuel Marks
  • 1,611
  • 1
  • 20
  • 25
  • I'm not sure about how to achieve this, but if this helps a little, you can check the unittests in clang-tools, specifically: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp#L34 . – jmmartinez Mar 11 '22 at 11:02
  • 1
    @JuanManuel If you can write that up into an answer I can give you the bounty – Samuel Marks Mar 18 '22 at 13:17

1 Answers1

0

I'm not sure about how to achieve this specifically, but I have a pointer.

You can check how it's done in the unittests in clang-tools, more specifically: here

jmmartinez
  • 333
  • 1
  • 9