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

can libclang parse the CRTP pattern?

I am trying to use libclang for parsing C++, but it seems to have problem with the CRTP pattern, i.e when a class inherits from a template that is instantiated with the derived class: // The Curiously Recurring Template Pattern (CRTP) template
user2479653
  • 509
  • 5
  • 14
3
votes
1 answer

How can I retrieve fully-qualified function names with libclang?

I need to parse a C++ code file and find all the function calls in it with fully-qualified names. I'm using libclang's Python bindings because it seems easier than writing my own C++ parser, even if the documentation is sparse. Example C++…
DarkMorford
  • 505
  • 1
  • 4
  • 12
3
votes
1 answer

set -D macro compiler flag globally for libclang

I am trying to generate mutants for a code (with an AST based mutant generator) which in order to compile uses -D macros. I am able to use clang to generate an AST dump using this command clang -Xclang -ast-dump -fsyntax-only -DFLAG=0 -DOTHER_FLAG…
Nishant Sharma
  • 683
  • 9
  • 16
3
votes
1 answer

A templated constructor cursor and a templated member cursor have kind FUNCTION_TEMPLATE in libclang

Some context I am not that familiar with libclang. I am just modifying a vim plugin which uses the python bindings to libclang. There is a python function which receives a cursor parameter. This is called for almost every node in the AST of the…
bolov
  • 72,283
  • 15
  • 145
  • 224
3
votes
2 answers

Libclang returning incorrect cursor types (stdlib and namespaced types)

I am using libclang to do some basic reflection of C++. I am creating a translation unit for a header and then visiting all the tree elements using the cursors, in some cases I fall back onto the qualtypes to get the necessary information out. The…
3
votes
1 answer

libclang getting the member declaration

class aclass{ public: int num; }; int main() { aclass *ok; ok->num = 4; return 0; } now when I do clang_getCursorDefinition(cur_cursor); on the cursor right at the beginning of the o at ok->num = 4; it gives the cursor for int…
Vans S
  • 1,743
  • 3
  • 21
  • 36
3
votes
0 answers

How to use libclang in Xcode

I want to use the libclang library included with Xcode to do some simple source code parsing. This is how I do it. Figure out the libclang.dylib using echoxcode-select --print-path/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib Copy the…
khanhlvg
  • 781
  • 7
  • 9
3
votes
1 answer

How to use libclang with STL?

I'm trying to parse a library using libclang, and I'm stuck with what could be a very simple issue: how to configure it with STL? At the moment, it fails to parse a translation unit because it can't find . Here's what I tried : char *args[]…
Mikarnage
  • 893
  • 1
  • 9
  • 24
3
votes
1 answer

how to retrieve class:function with clang

I have a CXCursor that marks the place where the declaration of a function in C++. I know how to get the method name, or the USR... but how can I get the Class Name (that the method is a part of) The code that I am parsing with libclang…
ekeren
  • 3,408
  • 3
  • 35
  • 55
3
votes
1 answer

LibClang: parse a header file with definitions from another header file?

I am using the latest LibClang to parse some C header files. The code I process comes from CXUnsavedFile's (it is all generated dynamically and nothing lives on disk). For Example: FileA.h contains: struct STRUCT_A { int a; struct STRUCT_B…
QAZ
  • 4,870
  • 6
  • 36
  • 50
3
votes
0 answers

Evaluate function macros and expressions with libclang

Is it possible to evaluate expressions and function macros with libclang? Something like this (expression): #define SOMETHING 1 | 2 | 4 | 0x10 Or something with a function macro: #define ADD(a,b) a+b #define THING ADD(10,5) I can tokenize the…
sciencectn
  • 1,405
  • 1
  • 16
  • 25
3
votes
2 answers

Install libc++ on mac 10.6.8

I'm currently trying to install the lib++.1.dylib on my mac. I followed the instructions here http://libcxx.llvm.org/ and downloaded the source. When I tried to ./buildit I encountered a clang++: command not found error. So I went here…
rwolst
  • 12,904
  • 16
  • 54
  • 75
3
votes
1 answer

how to Generate code from clang::ASTContext

I need a sample code to learn how to Generate C++ Code from clang::ASTContext. I created ast from c++ code and I made some changes in AST and now I want to Generate Code again.
Saman Parser
  • 148
  • 14
3
votes
0 answers

List of type names visible at a given position

I need a way to programatically retrieve a list of all type names that are visible at a given position in a C++ source, even when the source is incomplete (eg. being edited). I understand LibClang is probably already creating such a list under the…
xcvii
  • 450
  • 3
  • 17
2
votes
1 answer

How to reuse a clang AST matcher?

I'm using AST matchers from lib clang to ensures that some code is present in the body of a foo function. So all my matchers starts like this: auto matcher1 = functiondecl(hasname("foo"), hasdescendant(...)))); auto matcher2 =…
Dorian
  • 490
  • 2
  • 10