[cfe-dev] clang reformat

Pardis Pashakhanloo via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 5 13:08:26 PST 2018


Hi all,

I am trying to embed clang-format inside a clang tool I am implementing. As
I learned, there is tooling::format::reformat(...) that can be used in this
case. However, I have not been able to find any good
tutorials, documentation, or examples on it.

Here is the toy code I have currently written:


std::string teststr = "int main() { int i = 0 ;   }";

clang::tooling::Range NewRange(0, teststr.size());

std::vector<clang::tooling::Range> ranges;

ranges.emplace_back(NewRange);

clang::tooling::Replacements Rs = clang::format::reformat(

    clang::format::getLLVMStyle(),

    teststr,

    ranges,

    "ref.c"

);

After compiling, I get the following errors:

error: undefined reference to 'clang::format::getLLVMStyle()'

error: undefined reference to
'clang::format::reformat(clang::format::FormatStyle const&,
llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef,
clang::format::FormattingAttemptStatus*)'

clang: *error: *linker command failed with exit code 1 (use -v to see
invocation)

I have also included "clang/Format/Format.h" and "clang/Lex/Lex.h".

Any ideas?

Thanks,
Pardis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181205/ff068fd7/attachment.html>


More information about the cfe-dev mailing list