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

libclang not emitting certain AST nodes

I'm using the go-clang library to parse the following C file: aac.c. For some reason when I run the file through clang and dump the AST, I don't get AST output for certain functions. For example, the C file contains a forward declaration of…
Lander
  • 3,369
  • 2
  • 37
  • 53
1
vote
1 answer

c++ bindings for libclang

I'm aware of python bindings as well as original c lang written libclang, but I'm trying to use it in classrooms, and we teach c++. So if anyone is aware of c++ bindings, getting hands on it would be very helpful. Ref -…
user964843
1
vote
1 answer

Parsing C in python with libclang but generated the wrong AST

I want to use the libclang binding python to generate a C code's AST. OK, the source code is portrayed below . #include #include "adlist.h" #include "zmalloc.h" list *listCreate(void) { struct list *list; if ((list =…
Ham Xue
  • 11
  • 4
1
vote
2 answers

Parse C Array Size with Python & LibClang

I am currently using Python to parse a C file using LibClang. I've encountered a problem while reading a C-array which size is defined by a define-directive-variable. With node.get_children i can perfectly read the following array: int…
Feras Wilson
  • 380
  • 1
  • 3
  • 13
1
vote
3 answers

vim youcompleteme can't find cstdint

I've encountered a problem trying to set up a C++ project on my Mac (Yosemite with Xcode 6) using CMake with Unix style Makefiles and vim with the youcompleteme plugin (I'm a Linux veteran and Mac newbie so I prefer this setup to Xcode). The code…
realh
  • 962
  • 2
  • 7
  • 22
1
vote
1 answer

AST generated by Libclang’s python binding unable to parse certain tokens in C++ source codes

I am using Libclang’s python binding. I have basically two queries: I want to know how can we parse library function which are neither defined by user nor for which a library has been included..   For e.g. when I have the following source code – …
1
vote
1 answer

How can I parse a typedef for a function pointer using clang API to get the function pointer name?

I am currently building a parser for C++ code using the clang C API. The parser will process a header file and generate a list of defined and missing symbols for it (it ignores include directives, so it will parse strictly the contents of the…
tatones
  • 81
  • 4
1
vote
1 answer

Tutorial on embedding libclang in a Cocoa app

Does anybody have a good tutorial handy on embedding libclang in a Cocoa app? In particular I get issues with the rpath at launch saying the dylib couldn't be found. Error was the lovely dyld: Library not loaded: @rpath/libclang.dylib
uchuugaka
  • 12,679
  • 6
  • 37
  • 55
1
vote
0 answers

Reusing AST for different translation units in libclang (python bindings)

I am using python bindings for libclang. When parsing a cpp file I parse every header included in the cpp (or rather the cpp after the preprocessor step). I am trying to find all references to certain artefacts, however browsing the same headers…
thatsme
  • 325
  • 1
  • 2
  • 10
1
vote
1 answer

libclang: get interface cursor from implementation cursor

world! I am trying to use libclang to determine the superclass that an Objective-C method belongs to. I have a cursor representing an instance method (CXCursor_ObjCInstanceMethodDecl). When I get the cursor's parent, I get a cursor of kind…
EJV
  • 1,009
  • 1
  • 10
  • 17
1
vote
2 answers

libclang/libtooling handle or turn off all error outputs

I think every thing is in the title^^ in fact, I'm developping a tool using libtooling, but I'd like to suppress every errors (the tool is aimed to be used only on correct source, so error output polutes stderr...).
hl037_
  • 3,520
  • 1
  • 27
  • 58
1
vote
1 answer

Using libclang/libtooling

I have to retrieve all the structures and type defined in a project (as described in my previous question "https://stackoverflow.com/questions/23154414/c-project-get-all-global-variables-and-all-types" ). I chose the clang solution because it seems…
hl037_
  • 3,520
  • 1
  • 27
  • 58
1
vote
1 answer

libclang python binding don't return any of fixits

I want to dump diagnostics and fixits from translation unit (tu). But below code don't works. def dump_fixits(): """Return diagnostics with fixits of translation unit.""" result = [] for diag in tu.diagnostics: diag_fixits =…
kumar8600
  • 133
  • 1
  • 6
1
vote
1 answer

In libclang how to exclude functions from stdio.h

When using libclang, how to exclude function from stdio.h ? When I use the below source to collect only function definitions, then I end up getting all the functions from stdio.h as well. I read we can pass '-x c-header' kind of arguments while…
pankaj
  • 55
  • 1
  • 6
1
vote
1 answer

using libclang, callback function does not traverse recursively and does not visit all functions

I am following an example which shows limitation of python bindings, from site http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/ It uses "libclang visitation API directly". import sys import clang.cindex def…
pankaj
  • 55
  • 1
  • 6