Questions tagged [libclang]

LibClang is a stable high level C interface to the clang compiler.

LibClang is a stable high level C interface to clang.

When in doubt, LibClang is probably the best clang interface to use, since it:

  • can be called from any language interfaced with C (python bindings come out of the box),
  • is stable,
  • provides high enough abstraction over clang's implementation details.

LibClang provides the following features:

  • C/C++/ObjC/ObjC++ code parsing and syntax checking,
  • AST indexing and cross-referencing,
  • source code tokenization (e.g. for syntax highlighting),
  • code completion.

Useful links

Related tags

230 questions
1
vote
0 answers

libclang skips function return type for C

I have been trying to parse C headers using libclang's c++ API. I am able to parse functions, however, clang skips their return types. Here is simplified version of what my code looks like; #include #include using namespace…
memoks
  • 11
  • 3
1
vote
1 answer

Confusion about clang.cindex Token int_data

I hope this is not seen as an ignorant question, but I am a compiler noob. I could not find any answer to this question by myself, but that might be because I lack the proper search terms. I am trying to automatically find a pre-processor directive…
meetaig
  • 913
  • 10
  • 26
1
vote
0 answers

clang tools: how to find the physical end of an expression?

I’m building a source-to-source tool with clang. What I want to do is instrument stores made with the binary = operator. Currently, I’m running into problems with rewriting expressions that contain macro invocations. I’ve done some digging around,…
M. Taylor
  • 71
  • 1
  • 5
1
vote
0 answers

Clang indexing doesn't detect C++20 ConceptDecls

I'm having trouble getting Clang's IndexingAction to detect clang::ConceptDecls. I have a minimum working example that initializes an IndexingAction and runs it over some test code that contains two ConceptDecls. I've verified that the frontend…
John V.
  • 21
  • 1
1
vote
0 answers

Parse C++ macro lines (with comments) using python libclang

I am having a problem. I had a python script that was setup using the (ancient) clang-3.4, which was taking in header files (.h), parsed them and got all the macros (#define) together with comments after the define on the same line. E.g. the full…
w0wy
  • 21
  • 3
1
vote
0 answers

python libclang, not finding template definition

I have a header file I am trying to parse using python and libclang. I made the following method: def FindDeclaration(path, function_name): idx = clang.cindex.Index.create() tu = idx.parse(path) location = None for f in…
Makogan
  • 8,208
  • 7
  • 44
  • 112
1
vote
0 answers

libclang: How to distinguish project and system includes?

I am using libclang (Python bindings) to parse some C++ code. I need to distinguish includes that resolve to system headers, e.g., #include , from includes that resolve to project-local headers, e.g., #include "my_header.h". The problem…
Gileos
  • 113
  • 6
1
vote
1 answer

libclang: how to get compiler macro definitions

With clang LibTooling API one can get a list of compiler predefines simply using clang::Preprocessor::getPredefines(), but I cannot find any equivalent in libclang API. Is it possible to get a list of compiler predefines with libclang API?
Victor K
  • 529
  • 2
  • 16
1
vote
0 answers

Building a dynamic/shared library for a libclang project (LLVM) using CMake

I am trying to generate a dynamic(shared) library for a single C file, which uses LibClang (LLVM) Here's are the imports of that file. #include #include #include I am struggling with building a dynamic library…
Prerak Mann
  • 661
  • 7
  • 15
1
vote
0 answers

libclang CXCursors hiding body of openmp directives?

I'm trying to write a linter for openmp code, but libclang hides the body of openmp directives. My problem is essentially the same as this unanswered issue from the llvm mailing list. I took a look at clang's textual ast-dump, and the information I…
D. Tastet
  • 11
  • 2
1
vote
1 answer

YouCompleteMe throwing (35) SSL connect error when installing libclang on Mac Mojave

I have been using YouCompleteMe for a while, but now I want to have also C++ code completion and I can't get it to work. I followed the build instructions, on the Github page. This is what I did: ./install.py --clang-completer I get an error…
Moshe Rabaev
  • 1,892
  • 16
  • 31
1
vote
0 answers

What is the easiest way to rename all occurrences of a variable name using clang libtooling and having a namedDecl handle?

I want to make a program that makes abstract names for all function,variable,namespace ... and replaces the current ones.To this purpose i have used the clang libtooling documentation as well as their AST visitor example. I have found other useful…
1
vote
1 answer

cmake: LIBCLANG_PATH not found on windows

I am trying to write a simple clang AST cursor traveler. https://github.com/dyhe83/clang-AST-cursor-traveler This following cmake code works fine on Linux. PROJECT(traveler) FIND_LIBRARY(LIBCLANG_PATH clang HINTS…
someone
  • 122
  • 2
  • 9
1
vote
0 answers

Why does libclang not generate cursor for cross-file reference?

When I parse a C++ code file using libclang's Python bindings, I found the cursor of the cross-file reference is missing. Example C++ code: #include "controller/LocalController.h" int addition(int a, int b) { return a + b; } auto c =…
1
vote
0 answers

Why does libclang's clang_getEnumDeclIntegerType return different results on Linux and Windows?

Consider this simple C file, file.c: enum X { A, B } Let's detect the underlying type of the enum using libclang: #include #include enum CXChildVisitResult visitor(CXCursor cursor, CXCursor parent, CXClientData…
Solal Pirelli
  • 1,199
  • 9
  • 21