Questions tagged [libtooling]

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

152 questions
2
votes
0 answers

matching a @import declaration with ASTMatchers

I'm trying to match objc @import declarations using AST-matchers for a custom tool I'm creating; I'm using Result.Context->local_imports() but although I have @import statements in my source code and I'm passing the fmodules flag, the iterator…
2
votes
1 answer

How to get locations of asm statements with clang frontend

Sample code: int f_i32() { __asm { mov eax, 1 mov edx, 1 } } AST for this code: I get only MSASMStmt in AST and nothing from inside it. I want to extract locations of ASM statements inside __asm block. How can get those with clang…
Hemant
  • 767
  • 6
  • 20
2
votes
2 answers

Getting the signature of a FunctionDecl

I got the FunctionDecl for the definition of a function. There is no declaration for this function. For example: int foo(char c, double d) { ... } How do I get the signature (qualifier, return type, function name, parametrs) as a valid…
Fee
  • 719
  • 9
  • 24
2
votes
1 answer

How to visit a serialized clang abstract syntax tree (AST)

I've been able to implement an ASTFrontendAction to create an ASTConsumer, which uses a RescursiveASTVisitor to traverse a translation unit decl, thereby visiting all the nodes of an AST for a given source file. I do this by implementing a…
JMLoy
  • 121
  • 1
  • 1
  • 6
2
votes
1 answer

Disable looking for pre-compiled header file in clang front-end

I have created a C++ frontend using clang lib-tooling and RecursiveAStVisitor. I use pre-generated compile_commands.json file to load compilation database. Sometimes compile command for a source file contains -include compiler argument. For…
2
votes
1 answer

Clang LibTooling - How to use DependencyCollector

I'm trying to use the DependencyCollector class of Clang in my Tool to list all the dependencies in a file, lets say test.cpp Here is my program: #include "stdafx.h" #include #include "clang/Frontend/FrontendActions.h" #include…
2
votes
0 answers

how can I compare two decls in clang?

Besides simply get and check the decls' name, are there some methods in clang to compare whether two or more decls (clang::Decl) are same or not?
ignorer
  • 327
  • 1
  • 11
2
votes
1 answer

clang libtooling insert a new header safely

I'm using clang's libtooling to modify some code and I'm trying to find a way to safely insert a header whenever my tool is used on a C file. I've read What's the right way to match #includes (or #defines) using Clang's libtooling? question about…
Marcus Karpoff
  • 451
  • 5
  • 16
2
votes
0 answers

Can addToCallGraph do everything for me to generate the call graph?

I want to generate the call graph for a particular function in a .cpp file. I get the function's decl by using AST Matcher. Then, I pass the decl to the addToCallGraph function; clang::CallGraph CG; …
ignorer
  • 327
  • 1
  • 11
2
votes
2 answers

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

Is there any way to get clang::SourceLocation for every #include in file by its clang::FileID or clang::FileEntry or something?
Yuriy
  • 701
  • 4
  • 18
2
votes
0 answers

clang libtooling: How to check if a method is inherited from base class

I am working on a C++ parser using clang compiler front-end with libTooling library. For the following code from LLVM Clang tests // It is deleted if the corresponding constructor [...] is deleted. struct G { G(int) = delete; // expected-note…
Hemant
  • 767
  • 6
  • 20
2
votes
1 answer

Get class information from ObjCPropertyDecl

I having some trouble extracting the class information from a clang ObjCPropertyDecl type. Example Objective-C file: #import @interface Test: NSObject @property (nonatomic, strong, nullable) NSObject *test; @property…
danielbeard
  • 9,120
  • 3
  • 44
  • 58
2
votes
0 answers

How to use clang libtooling to change specific ctor definition

I just want to rewrite specific ctor definition. To find witch on to change I use 'normal' DeclarationMatcher DeclarationMatcher ClassMatcher2 = cxxRecordDecl(isDerivedFrom("X"), has(fieldDecl( …
teZeriusz
  • 81
  • 2
  • 8
2
votes
3 answers

How can I use LibTooling/Clang in Visual Studio?

I'm trying to use LibTooling to replace function and variable names in C-code files. Thus I downloaded llvm and followed the instructions to set it up in windows using GMake and Visual Studio 2015. There are many tutorials (e.g. this one) which I'd…
Alex H.
  • 73
  • 1
  • 8
2
votes
2 answers

CXXRecords getNameAsString, how to get full name?

namespace A { namespace B { class C { class D { }; }; } } CXXRecords for D with getNameAsString would return D. How can I get the fullname ::A::B::C::D ? I tried to recursively call getParent…
KoKuToru
  • 4,055
  • 2
  • 20
  • 21