libtooling

How to get the macro and its expansion with clang libtooling?

喜你入骨 提交于 2020-03-05 04:07:09
问题 I am working on clang libtooling. So far I am managed to get the macro where it is getting referred in the source file through visitDeclRefExpr(DeclRefExpr *DR) But can I get a list of macros with its name and its expansion as string. exampleprogram.c #define abc ab #define sum 0 int main() { int ab; abc = abc + 0; return 0; } can I get the output like the following abc -- ab sum -- 0 How can I achieve this output with clang libtooling. How can I implement with the clang libtooling? Please

How to get the macro and its expansion with clang libtooling?

故事扮演 提交于 2020-03-05 04:07:06
问题 I am working on clang libtooling. So far I am managed to get the macro where it is getting referred in the source file through visitDeclRefExpr(DeclRefExpr *DR) But can I get a list of macros with its name and its expansion as string. exampleprogram.c #define abc ab #define sum 0 int main() { int ab; abc = abc + 0; return 0; } can I get the output like the following abc -- ab sum -- 0 How can I achieve this output with clang libtooling. How can I implement with the clang libtooling? Please

Clang: How to get the macro name used for size of a constant size array declaration

邮差的信 提交于 2020-01-14 01:38:32
问题 TL;DR; How to get the macro name used for size of a constant size array declaration, from a callExpr -> arg_0 -> DeclRefExpr. Detailed Problem statement: Recently I started working on a challenge which requires source to source transformation tool for modifying specific function calls with an additional argument. Reasearching about the ways i can acheive introduced me to this amazing toolset Clang. I've been learning how to use different tools provided in libtooling to acheive my goal. But

What's the right way to match #includes (or #defines) using Clang's libtooling?

£可爱£侵袭症+ 提交于 2019-12-30 04:31:22
问题 I'm writing a libtooling refactoring tool. I have a class, let's say Foo , defined in a header called foo.h . I want to see if foo.h is included in a file. Currently, to check if bar.cc includes foo.h , I'm just matching using recordDecl(hasName("Foo")) . This works because class Foo { ... }; will exist inside of bar.cc 's AST after preprocessing, if bar.cc includes foo.h . But this doesn't work if, for example, bar.cc includes cat.h which includes foo.h . I want bar.cc to EXPLICITLY include

How to get source location of #includes using clang libtooling?

元气小坏坏 提交于 2019-12-24 06:29:47
问题 Is there any way to get clang::SourceLocation for every #include in file by its clang::FileID or clang::FileEntry or something? 回答1: What about using source manager's GetIncludedLoc function which takes fileid as parameter. SourceManager.GetIncludedLoc(fileid) 回答2: Thank's @Hemant for your answer, you're right I Already found that by myself (in clang 3.8 it is called getIncludeLoc ) but forgot to write here. I used this to find the location after all #includes where i can put my own. Here's

How to print fully qualified Expr in clang?

允我心安 提交于 2019-12-11 11:33:21
问题 I'm working on my reflection tool with clang 8.0.1. And right now I need to print Expr with all names fully qualified. I already tried builtin prettyPrint function with FullyQualifiedName bit set to true. But it still gives incorrect result. For this piece of code: namespace math { struct Transform { float val; [[custom_attr(&Transform::public_val)]] void foo(); }; } It gives me &Transform::public_val instead of &math::Transform::public_val And for static_cast<float (*)(const Transform&)>

Ignore system headers in clang-tidy

我的未来我决定 提交于 2019-12-06 16:59:03
问题 tldr;> How do I hide warnings from system headers in clang-tidy? I have the following minimal example source file, which triggers a clang-tidy warning in the system headers: #include <future> int main() { std::promise<int> p; p.set_value(3); } Calling it with libstdc++ 7.0.1 using clang-tidy 4.0.0 on Ubuntu 17.04: $ clang-tidy main.cpp -extra-arg=-std=c++14 yields Running without flags. 1 warning generated. /usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: warning