clang reformat

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

clang reformat

Oleg Smolsky via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang reformat

Oleg Smolsky via cfe-dev
Hi!

I suspect the problem will be in you CMakeLists.txt file. Can you copy it here?

Cheers,
Kristóf Umann


On 5 Dec 2018 22:08, "Pardis Pashakhanloo via cfe-dev" <[hidden email]> wrote:
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang reformat

Oleg Smolsky via cfe-dev

Thanks. You are right. It was solved by adding clangToolingInclusions and clangFormat to the cmake module.

Best,
Pardis

On Wed, Dec 5, 2018 at 4:28 PM Kristóf Umann <[hidden email]> wrote:
Hi!

I suspect the problem will be in you CMakeLists.txt file. Can you copy it here?

Cheers,
Kristóf Umann


On 5 Dec 2018 22:08, "Pardis Pashakhanloo via cfe-dev" <[hidden email]> wrote:
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev