Questions tagged [libtooling]

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

152 questions
4
votes
1 answer

Clang tooling. Type name without keyword

I'm working on some clang tool, and I need to generate source code with types, that aren't specified explicitly. The strings with types I get from clang::QualType is something like: class std::initializer_list. The issue is to get type without…
Yuriy
  • 701
  • 4
  • 18
4
votes
0 answers

Uninstantiated function/class template ast is not generated by clang

I am working on a C/C++ parser based on clang libtooling. I use the AST generated by clang to parse the code. Recently what I observed is that for a template class or function which is not instantiated clang does not generate AST for that class or…
Hemant
  • 767
  • 6
  • 20
3
votes
1 answer

How VisitNamedDecl and VisitCXXRecordDecl are called by RecursiveASTVisitor?

In RecursiveASTVisitors doc, there is are no virtual methods of name VisitNamedDecl, VisitCXXRecordDecl ..etc. So how they are called automatically called ?
LightSith
  • 795
  • 12
  • 27
3
votes
0 answers

Getting file not found error using clang LibASTMatchers

I am experiencing an issue with CLang's libastmatchers while working with Postgres sources: it can't find include file. This error is reproduced only when CLangTool is created from two files. If it is created for a separate file, there is no error…
Vadim Volodin
  • 377
  • 1
  • 2
  • 14
3
votes
1 answer

When will a Clang AST node have multiple parents?

The class clang::ASTContext has a method: DynTypedNodeList getParents(const NodeT &Node) which returns a list of parent nodes of a given AST node. Commonly AST as a tree will be a tree structure, but for some reasons (perhaps performance reasons)…
jw_
  • 1,663
  • 18
  • 32
3
votes
2 answers

How do you obtain the instantiated CXXRecordDecl of a templated class in Clang?

For example, I have a class: template class Foo { public: T getBar(); private: T bar_; }; It is instantiated with: using FooBarT = Foo; How do I get the CXXRecordDecl with resolved fields and methods for Foo? I…
Eric
  • 730
  • 4
  • 16
3
votes
1 answer

How to get function pointer arguments names using clang LibTooling?

Say I analyze a code like this: struct Foo { void(*setParam)(const char* name, int value); }; I use clang LibTooling and get FieldDecl on a setParam. I figured I can get argument types like so: auto ft =…
Shens
  • 43
  • 5
3
votes
1 answer

How to use AST for both custom front-end action and clang static analysis

I am working on a libTooling based project where I have written a custom frontend action class by referring this. Now I want to run clang static analysis in the same tool. Currently, I am running the tool again for clang static analysis (after…
Hemant
  • 767
  • 6
  • 20
3
votes
1 answer

Add memory file to clang CompilerInstance

I am trying to create a tool with clang and was wondering if it is possible to inject a include file from memory to the CompilerInstance preprocessor. My goal is to add a #include to my files and dynamically include this file with…
mkaes
  • 13,781
  • 10
  • 52
  • 72
3
votes
1 answer

Clang: write a function's AST from original file to a new file

I'm a novice for Clang who is trying to analyze AST via libtooling. I want to find a particular function, and move its AST from original source file to a new file. I've known how to find the function by MatchFinder. Now, I was wondering how to…
ignorer
  • 327
  • 1
  • 11
3
votes
1 answer

Replacements returning empty map in clang RefactoringTool

I have a MatchFinder defined as: MatchFinder Finder; Finder.addMatcher(FunctionCallMatcher, &printer); And the DeclarationMatcher, and the MatchCallback are as below: DeclarationMatcher FunctionCallMatcher =…
yaman
  • 759
  • 3
  • 17
3
votes
1 answer

Why does clang create these implicit methods when a class contains a virtual method?

I'm working on a tool based on clang's AST, and I'm curious to know why clang works this way. Here's my input. I have a very simple class that is defined like this: class Foo { int foo(); }; Then in my RecursiveASTVisitor, I have code that…
Chris
  • 1,657
  • 1
  • 13
  • 20
3
votes
1 answer

Clang libtooling: determine macro expansion location

I have a header header.h with a macro definition which expands into a class definition and a source file test.cpp which includes header.h and uses this macro. Then I use RecursiveASTVisitor to visit all CXXRecordDecl's. When I visit the…
LVK
  • 288
  • 4
  • 13
3
votes
0 answers

Function call extraction in a c code using Clang

I want to write a program which decomposes expressions (in a C code) in which they have function calls and extract each function call to variable. For example: x = A() + B(); should be changed to : a = A(); b = B(); x = a + b; I'm writing it using…
NEO
  • 2,145
  • 2
  • 26
  • 34
2
votes
1 answer

How to find the clang::SourceRange of a deleted function?

I am working on a Clang AST generated from the following source code: struct has_deleted_function_member { void deleted_function1() = delete; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ col:33 }; void deleted_function2() = delete; //~~~~~~~~~~~~~~~~~~~~~^…
1
2
3
10 11