Questions tagged [clang-query]

clang-query is a tool that allows you to quickly iterate and develop the difficult part of a matcher. Once the design of the matcher is completed, it can be transferred to a C++ clang-tidy plugin.

20 questions
5
votes
1 answer

Clang AST matcher for variables compared to different variable types

I am new to clang-tidy and the following is practice so I can move to more complex matchers and tools. Lets say we have typedef int my_type; void foo() { int x = 0;//this should be identified as need to be fixed my_type z = 0; …
warz
  • 73
  • 4
3
votes
0 answers

How do I find string literals containing a given substring with clang-query?

I am doing some automated refactoring and I want to understand if some name is used in strings. E.g. in the code below I want to find all string literals containing substring "hello", which will yield me the first string. int hello; const char* str…
Mikhail
  • 20,685
  • 7
  • 70
  • 146
3
votes
1 answer

Writing AST matcher to find all case statements having no break statement

I want to find all the case statement having no break statement. I using clang-query to build my matcher. My matcher is failing in some of the test cases. I wrote simple matcher as match caseStmt(unless(has(breakStmt()))) it works with follwing…
sunil sarode
  • 154
  • 1
  • 13
2
votes
0 answers

How to see all UnresolvedLookupExpr node in Clang AST

I am looking into various scenarios where UnresolvedLookupExpr node occurs. I notice that the output of -ast-dump and clang-query don't match. Here is an example code in c++/9/bits/range_access.h. template inline constexpr…
2
votes
0 answers

clang-tidy isolate multiple field declarations

In clang-tidy there is the readability-isolate-declaration check. I am trying to do something similar for field declarations. Let us say that we have the following typedef struct s{ int x,y; }s; If we check the above example in clang-query we…
warz
  • 73
  • 4
2
votes
1 answer

Running Clang-query on objective-c files that import Foundation

I am trying to use clang-query to run matches against obj-c files that import Foundation but its not working, After building clang-query by moving it to the tools/extra folder, I run it using this command: ./clang-query MyClass.m -- …
Andrespch
  • 370
  • 3
  • 16
1
vote
0 answers

use clang-query to match specified string

how should I use clang-query to match specified string souece code: int main() { __asm__ __volatile__("pause"); } I want to substituted "yield" for "pause" what I have tried in clang-query, I can only match the stringLiteral and I cant match…
1
vote
1 answer

Running clang-query only on input files

I'm running clang-query on a specific file using a compilation database as follows: clang-query -p build foo/bar.cpp This works, but when I run a simple query (e.g. match ifStmt()) it returns thousands of results, including matches from imported…
MattDs17
  • 401
  • 1
  • 4
  • 20
1
vote
1 answer

locate constructor line number in cpp source with clang-query

I'm looking to get the line number for the last line of the constructor with clang-query, does anyone know how to get there? i have a lot of source files to go through, and needing to update the constructors. i spent time trying to parse the source…
huynle
  • 53
  • 1
  • 7
1
vote
2 answers

how to find symbols that should be exported

If you compile with -fvisibility=hidden or with msvc you have to export your shared library symbols manually. As an experiment, how could you find them automatically with AST matchers (clang-query)? It's not that easy as a minimal set of export…
Trass3r
  • 5,858
  • 2
  • 30
  • 45
0
votes
0 answers

using libClang or libTooling to list function declarations

I am developing a windows C++ tool to analyze and mutate C code. I need help to use libClang or preferably libTooling get a list of C function declarations from a source tree of C files (translation units) with their headers. Eventually, I would…
johnco3
  • 2,401
  • 4
  • 35
  • 67
0
votes
0 answers

Can I find #define with clang-query?

I know that #defines are processed by the preprocessor and not the compiler that creates the AST. But anyways, the LLVM/clang toolchain could somehow retain that information internally. Can I query for #define with clang-query? If so, how?
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
0
votes
1 answer

Writing AST Matcher expressions using an AST tree dump as a guide

I am new to clang-query and I need help to understand how to build ASTMatcher expressions for a code profiling tool I am trying to create. Eventually I would like to combine these AST matchers with a libTooling application to rewrite the source…
johnco3
  • 2,401
  • 4
  • 35
  • 67
0
votes
1 answer

How do I get clang-query or AST to recognize the underlying pair / type inside a map?

I'd like to create an AST matcher for the following code snippet #include int main() { int a = 3333, b = 4444, c = 5555; std::unordered_map unorderedMapPtr = {{&a, b}, {&b, c}}; for (auto mapIter : unorderedMapPtr)…
0
votes
0 answers

How can I match a CXXTypeidExpr with clang-query?

Minimum "working" example on compiler explorer: https://godbolt.org/z/r6jebPWMe I have this C++ code: #include namespace { struct Base { virtual ~Base() {} }; struct Derived : Base { virtual void name() {} }; } //…
1
2