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
9
votes
4 answers

Retrieving comments using python libclang

In the following header file I'd like to get the corresponding +reflect comment to the class and member variable: #ifndef __HEADER_FOO #define __HEADER_FOO //+reflect class Foo { public: private: int m_int;…
user408952
  • 882
  • 9
  • 23
9
votes
1 answer

Why isn't libclang returning meaningful completion results?

I'm trying to understand how to do code completion with libclang. I've watched "Thinking beyond the compiler" and I've looked over c-index-test, and I found a simple sample program here I compiled that program and ran it on this sample file that I…
John
  • 548
  • 7
  • 15
9
votes
4 answers

libclang get primitive value

How can I get the value of a primitive literal using libclang? For example, if I have a CXCursor of cursor kind CXCursor_IntegerLiteral, how can I extract the literal value. UPDATE: I've run into so many problems using libclang. I highly recommend…
Thomas Eding
  • 35,312
  • 13
  • 75
  • 106
8
votes
1 answer

get_includes doesn't find standard library headers

I am toying with the Python bindings of libclang. Currently, I am trying to perform some very simple tasks, such as finding all the headers included in a C++ file. The code I use is as follows: from clang.cindex import Index index =…
Morwenn
  • 21,684
  • 12
  • 93
  • 152
8
votes
3 answers

How do I get an enum element's numerical value using libclang?

Suppose I have an enum definition, e.g.: // myenum.h enum MyEnum { First = 1, Second, Third, TwoAgain = Second }; I would like to programmatically generate a map from any given enum definition, where the key is the enum element's…
JKSH
  • 2,658
  • 15
  • 33
8
votes
1 answer

How to retrieve function call argument values using libclang

Is it possible to retrieve the argument values of a clang.cindex.CursorKind.CALL_EXPR cursor? When I dump the AST using the compiler (clang++ -ast-dump source.cpp) I get info about function calls (call expressions) and their arguments. But I'm not…
Raúl Roa
  • 12,061
  • 13
  • 49
  • 64
8
votes
4 answers

How to fix "Xcode quit unexpectedly while using the libclang.dylib plug-in."?

I have this every time in a short while after I start xCode (5.1.1). Removed user data, turned off source control (as some posts suggested), no effect, still crashes (while showing Indexing... that never finishes). Even reinstalled xCode, without…
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
7
votes
2 answers

python libclang bindings on Windows fail to initialize a translation unit from sublime text

Short description: using libclang to autocomplete code does not work with python that comes bundled with Sublime Text 3. Details: A small verifiable example is in the repo on Github In essence, there is a script that uses a slightly changed…
niosus
  • 738
  • 8
  • 22
7
votes
1 answer

libclang: add compiler system include path (Python in Windows)

Following this question and Andrew's suggestions, I am trying to have liblang add the compiler system include paths (in Windows) in order for my Python code import clang.cindex def parse_decl(node): reference_node = node.get_definition() if…
user6167676
7
votes
1 answer

Python clang does not search system include paths

When using libclang from Python, it doesn't seem to automatically search the system's include paths. Is there a reliable way to get these paths? I don't like hardcoding paths as I'm writing code that will run on a variety of UNIX systems. For…
csl
  • 10,937
  • 5
  • 57
  • 89
7
votes
2 answers

libclang returns too much info about function declarations

I have the following code that uses the clang-c API. #include #include #include CXChildVisitResult printVisitor(CXCursor cursor, CXCursor parent, CXClientData client_data) { CXCursor cursor1 =…
user3016814
  • 135
  • 1
  • 8
7
votes
1 answer

clang can't parse my .h file standalone

I'm using python binding of libclang but I think this problem is caused by libclang not by python binding. I have a header object.h #ifndef OBJECT_H #define OBJECT_H class Object { public: int run(); }; #endif And a implementation…
Ray Wu
  • 993
  • 16
  • 34
7
votes
1 answer

Cannot use libclang with Qt

I encountered a strange bug when I tried to use libclang in a Qt application. test.cpp #include #include #include int main (int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow…
silviubogan
  • 3,343
  • 3
  • 31
  • 57
7
votes
2 answers

libclang get class name from cursor

I am trying to extract the class name of a parameter to a method call in objective-C. The code I am parsing is: - (void)testAddConcreteDataModel:(DFDemoDataModelOne*)helpmeh { [self.dataModels addObject:helpmeh]; } And the result I need is the…
Sam
  • 3,659
  • 3
  • 36
  • 49
6
votes
0 answers

Libclang Python Binding: Get ObjC Method Return Value

Background Please see https://github.com/tingraldi/SwiftScripting/issues/18 for a full discussion of this problem. The link above has a long Python script that translates an Objective-C File.h header file into File.swift. To do this, it uses…
Bryan
  • 4,628
  • 3
  • 36
  • 62
1
2
3
15 16