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
1 answer

lib clang.dylib: change installation path

I have a problem using libclang: I built libclang locally. It resides somewhere like clang-llvm/…/libclang.3.4.dylib. Then I developed a foundation tool using that dylib. (exactly: I copied a version to my project folder and linked against this.)…
Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50
1
vote
1 answer

Libclang API to get function definitions defined in a different file

Suppose I have two files main.c and func.c func.c is called from main.c's main function. Normally, I would generate main.o and func.o and linker would find definition of func and tie it up to it's call in main .c Now, I want to do same thing through…
user763410
  • 502
  • 6
  • 22
1
vote
1 answer

Is there any api in libclang to simpilfy BinaryOperator

I want to do a transform on my code, it simplifies the binary operator e.g. "1+ a+ 2" to "a+3", so is there any api in libclang can do such things?
WhatisThat
  • 267
  • 4
  • 10
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
1 answer

Cannot configure QDoc when configuring Qt 6.2.4 because of missing libclang

I am trying to build Qt 6.2.4 from source on Windows 10. I run into the following WARNINGs when configuring. WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt…
0
votes
0 answers

Make libclang correctly parse headers of a Bazel project included with a relative path

Suppose I have a Bazel project with this structure: WORKSPACE - includes - a.h - BUILD - includes_b - b.h - BUILD with the following files: includes/BUILD cc_library( name = "a", srcs = [], hdrs = [ "a.h", …
roschach
  • 8,390
  • 14
  • 74
  • 124
0
votes
1 answer

positive values ​instead negative values of integer_literals

In the source code, I have a negative int literal. When I parse the source code through libclang, the integer_leteral functions clang_Cursor_Evaluate and clang_EvalResult_getAsInt return a positive value for this. For example, I had int a = -555 in…
Jurddox
  • 21
  • 1
  • 4
0
votes
0 answers

Python libclang and get_includes() returning duplicate entries

For a simple C++ file: #include int main() { int a = 1; int b = 2; return 0; } Calling tu.get_includes(), returns a lot of header files and more especially redundant entries. Do you have any…
Tom B.
  • 21
  • 3
0
votes
1 answer

How I can I parse comments from macro expansion using libclang?

Given the following C++ program: #define SOME_MACRO \ (void) x; /* some comment in macro */ \ int main() { int x = 0; /* some comment in main */ SOME_MACRO SOME_MACRO return 0; } I would like libclang to call me back on the comments…
Dorian
  • 490
  • 2
  • 10
0
votes
0 answers

How to parse FieldDecl with libclang?

Using the example Clang lambda, I'm trying to parse a c++ header file. The problem is, I'm unsure how to parse a CXCursor_FieldDecl for the type and name of a member field of a class. clang_visitChildren(cursor, …
Ender
  • 1,652
  • 2
  • 25
  • 50
0
votes
1 answer

Cppyy cmake build cannot find libclang

I am trying to build cppyy via cmake but I keep getting this error: CPYY_MODULE_PATH: /usr/local/anaconda3/envs/bwcpp_env/lib/python3.10/site-packages/cppyy_backend/cmake CMake Error at…
shouriha
  • 79
  • 6
0
votes
0 answers

Libclang many (relevant) AST nodes are left out when parsing

I'm working on a project that relies on parsing .cpp files using into the clang AST. I've noticed that (at least the python bindings) leave out a lot of relevant nodes that appear when using -clang -Xclang -ast-dump Python parser: def…
0
votes
0 answers

libclang fails to parse the classes with :: in name

I'm using libclang+python binding to parse the cpp files, but it fails to parse the following class: class ReadableStreamBytesConsumer::OnFulfilled final : public ScriptFunction { static v8::Local CreateFunction(){} } libclang…
Crystal
  • 85
  • 9
0
votes
1 answer

libclang: distinguish typedeffed struct declaration from typedeffed struct definition

Consider two typedefs struct A { int member; }; typedef struct A TA; typedef struct B { int b; } TB; One can ask libclang for the type underlying the typedef (using clang_getTypedefDeclUnderlyingType(CXCursor)) for both examples. In both cases we…
A.J.Rouvoet
  • 1,203
  • 1
  • 14
  • 29
0
votes
0 answers

Libclang cannot parse c++ macro if there is an iostream include

I have very strange problem. I have simple python c++ parser that looks for certain macro instantiations in my c++ code. And I have very strange problem I have two files, test.cpp and macro.hpp, I'm parsing test.cpp //macro.hpp #define…
Crazy Sage
  • 414
  • 2
  • 14