Questions tagged [libtooling]

LibTooling is a library to support writing standalone tools based on Clang.

152 questions
2
votes
1 answer

How to convert a cpp file's source code to IR by using libtooling (clang C++ API)?

We know that the IR file can be obtained from foo.cpp through the clang driver: clang++ -emit-llvm -S foo.cpp -o foo.ll Now I want to do this by using the libTooling's API without clang driver. But I don't know how these APIs are used, I would like…
2
votes
1 answer

clang DeclContext::getParent() not returning parent RecordDecl for nested structs

I'm using the following code get parent struct of a nested struct using clang libtooling. bool VisitRecordDecl(clang::RecordDecl *RD) { llvm::outs() <<"\n\tTrying to get parents of "<getNameAsString()<<"\n\n"; clang::RecordDecl *Parent…
Mah35h
  • 1,127
  • 1
  • 7
  • 18
2
votes
1 answer

How to use custom C++ attributes with Clang libTooling without modifying Clang code?

I'm writing some kind of tool that extracts the interface definitions of C++ code. In process of writing, I decided to restrict the parser to process only the code that was explicitly marked for processing, and I thought that C++ attributes are the…
k.meinkopf
  • 158
  • 6
2
votes
1 answer

Clang AST: access member function templates from CXXRecordDecl

Say I have a dummy class like this: class Stack { public: template void push(T val) { (void)val; } template T pop() { return 0; } bool empty() const { return true; } }; The AST dump of which looks like: …
Peter
  • 2,919
  • 1
  • 16
  • 35
2
votes
1 answer

How to tell that class/struct is copyable using python bindings for clang tooling

Our project is using clang python api to generate python bindings for C++ classes. Right now we have a limitation that the copy will only be exposed if a type has an explicitly defined copy constructor. I would like to change it to also declare a…
Denis Yaroshevskiy
  • 1,218
  • 11
  • 24
2
votes
0 answers

Using clang libtooling to rewrite C++ source code to include implicitly defined constructors, operators and destructors

According to the C++ standard: [Note:In some circumstances, C++implementations implicitly define the default constructor (12.1), copyconstructor (12.8), move constructor (12.8), copy assignment operator (12.8), move assignment opera-tor (12.8), or…
2
votes
0 answers

How do I run my Clang Tool on a CMake based build system?

I am working on a tool, using clang's LibTooling library, and I want it to parse the entire build system. Code I've been trying to call clang with: int main(int argc, const char** argv) { clang::tooling::CommonOptionParser parser(argc, argv,…
Bako
  • 313
  • 1
  • 15
2
votes
1 answer

How to obtain the compilation command in a tool based on libtooling

I have built a custom tool (based on libtooling) for transforming source code. I used clang's own tutorial and managed to run my own custom FrontendAction. I now need to parse the compile flags that were provided to the tool (on the command line) to…
Ethan
  • 57
  • 4
2
votes
3 answers

VS2017 Debugger : has no address, possibly due to compiler optimizations

Seems not relevant to some questions with similar titles. //some other code std::string s = Lookup->getName().str(); -> break here //some other code Note: "Lookup" is clang::DirectoryLookup…
jw_
  • 1,663
  • 18
  • 32
2
votes
1 answer

How to get information about call to destructors in Clang LibTooling?

In C++, the compiler should implicitly insert calls to destructors at places such as delete keyword/end of scope, etc. In C++ the call to destructors should be fixed at compilation time (though the callee may be decided at runtime with vtables). (Is…
jw_
  • 1,663
  • 18
  • 32
2
votes
1 answer

How to let RecursiveASTVisitor abort current subtree

While using Clang LibTooling's RecursiveASTVisitor, how to tell the library to abort the scan of the subtree under the currently visited AST node? RecursiveASTVisitor uses depth-first traversal on the AST, it could be easy to abort some subtree and…
jw_
  • 1,663
  • 18
  • 32
2
votes
0 answers

Developed clangtool does not find headers outside source tree (runtime)

I'm developing a clang based tool with which I process the AST generated by clang. Right now I'm developing inside the llvm-project tree (I cloned the whole repository) as mentioned in this tutorial. I've created the CMakeLists.txt as mentioned and…
Minee
  • 408
  • 5
  • 12
2
votes
0 answers

Add deprecated tag to declaration using a Clang Plugin

I have a sample file with a function declaration that I want to deprecate. I want to add this C++ tag to make the compiler emit warnings when this function is being called like this one: ...simple_test.cpp:45:5: warning: 'free_fun' is deprecated…
2
votes
1 answer

Is there a way to cross-reference symbols across multiple translation units using libtooling?

I have a Lib and multiple Applications. I want to gather usage statistics about function calls to Lib's API from Apps. Basically my current process is: Parse the Lib for all functions/methods Output the info in a formatted way Use that output to…
2
votes
2 answers

How to get the actual type of a template typed class member with Clang?

For example, I have the following class: template class Foo { public: T getBar(); private: T bar_; }; It is instantiated as: Foo foo; I extract the clang::CXXRecordDecl node of class Foo, and iterate through its…
Eric
  • 730
  • 4
  • 16
1 2
3
10 11