Questions tagged [libtooling]

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

152 questions
44
votes
3 answers

Ignore system headers in clang-tidy

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 int main() { std::promise p; …
Heinzi
  • 5,793
  • 4
  • 40
  • 69
14
votes
4 answers

How to use standard library with Clang and LibTooling

I want to use Clang and LibTooling to create some C++ source analysis and transformation tools. I've built Clang and LibTooling following this tutorial, and I've been able to run and create some analysis tools and compile C++ programs using the…
Jonathan Sharman
  • 636
  • 6
  • 16
13
votes
1 answer

clang: custom attributes not visible in AST

i implemented a custom attribute in clang as described in the official manual: http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute So i added the following Code to Attr.td: def MyAttr: InheritableAttr { let Spellings =…
Jimbei
  • 395
  • 3
  • 11
10
votes
1 answer

OCLint ASTMatcher rule. Matching NS_ENUM

I am trying to create an OCLint rule that matches both typedef enum and typedef NS_ENUM declarations, with little success. I have an Objective-C file (TestClass.m) with the following enum declarations in it: typedef NS_ENUM(NSInteger, TestEnum) { …
danielbeard
  • 9,120
  • 3
  • 44
  • 58
9
votes
2 answers

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

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…
sagargp
  • 1,030
  • 11
  • 24
7
votes
2 answers

How to find implicitly deleted default constructors in clang's AST?

Consider the following struct definition in foo.cc: struct Foo { int &bar; }; Because bar has reference type, the implicit trivial default constructor Foo::Foo() is implicitly deleted. However, this fact does not seem to be reflected in the AST…
Peter
  • 2,919
  • 1
  • 16
  • 35
7
votes
0 answers

How to get actual name of invalid/unresolved type in clang AST

Consider the following code int function() { unknownType variable; } In the above code snippet, "unknownType" is not resolved at compile time, so clang will put default type as int in the AST and mark the declaration as invalid. Now the question…
Hemant
  • 767
  • 6
  • 20
6
votes
2 answers

clang libTooling: How to find which header an AST item came out of?

Examples found on the web for clang tools are always run on toy examples, which are usually all really trivial C programs. I am building a tool which performs source-to-source transformations on C++ code, which is obviously a very, very challenging…
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
5
votes
3 answers

How to use Clang LibTooling multiple times

Minimul source that use Clang LibTooling which is a very common way: #include "pch.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" #include…
jw_
  • 1,663
  • 18
  • 32
5
votes
1 answer

Clang - how to retrieve "Expr" as string?

I am using Clang/libtooling (ASTComsumer with a Matcher) to visit ALL return statements (ReturnStmt). I need to extract the expression that comes after the keyword return in a string form so that I can put that in a macro that I am replacing return…
DLight
  • 51
  • 1
  • 2
5
votes
2 answers

Clang using LibTooling Rewriter to generate new file?

I'm using LibTooling to do some analysis. I know how to traverse the AST and insert some text into somewhere. For example, Rewriter mywriter; mywriter.InsertTextAfter(func->getLocEnd(),"Hello"); Now I'm wondering if there are any way to save the…
link5555
  • 63
  • 1
  • 6
5
votes
1 answer

Get fully qualified template template argument name using libtooling

I am trying to use libtooling to print a CXXRecordDecl of the substantiation of a template class with a template template parameter. Unfortunately, the string representation of the template template parameter is not fully qualified (e.g. it's…
Michael Koval
  • 8,207
  • 5
  • 42
  • 53
5
votes
2 answers

How to build clang LibTooling on Mac OS?

I want to use clang's LibTooling on Mac OS X Yosemite. Clang's docs only shows how to build clang and llvm, but what I need is LibTooling, not whole clang (xcode has already provided clang and llvm). How to build LibTooling without building another…
wing
  • 141
  • 1
  • 5
5
votes
4 answers

getting parameter information from FunctionDecl class in clang

How to get parameter information as a string from FunctionDecl class in clang . I'm trying but getting confused by so many inheritances. Also they compiler is saying that getReturnType() is not a member of FunctionDecl but doxygen documentation says…
Sourav Mukherjee
  • 299
  • 7
  • 13
4
votes
1 answer

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

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…
1
2 3
10 11