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

python-clang: Getting Template Arguments

I'm trying to extract the template arguments from class instantiations in C++ using python-clang, ie. the Python bindings for libclang (with clang 3.9). For example, for template class X {}; X x; I'd like to be able to figure out…
rainer
  • 6,769
  • 3
  • 23
  • 37
2
votes
2 answers

Unable to import clang bindings in Anaconda/Python3

I just pip installed clang to my Anaconda Python 3 installation and I'm unable to import the clang python bindings... C:\Temp>python -m pip install clang --proxy="xxxxx" Collecting clang Downloading clang-3.8.tar.gz Building wheels for collected…
jxramos
  • 7,356
  • 6
  • 57
  • 105
2
votes
2 answers

Expand macros & retrieve macro values

I am trying to use libclang python bindings to parse my c++ source files. I am unable to get the value of macro or expand a macro. Here is my sample c++ code #define FOO 6001 #define EXPAND_MACR \ int \ foo = 61 int main() { …
Ganesh kudva
  • 990
  • 3
  • 13
  • 34
2
votes
1 answer

Is there any way to "restart matching" with libclang matchers after already having matched something?

class __attribute__((annotate("some_important_string"))) Foo { public: void do_something(); }; I want to find all the public methods in a class with a specific annotation. I have a matcher set up to get classes with…
xaxxon
  • 19,189
  • 5
  • 50
  • 80
2
votes
0 answers

How to use clang libtooling to change specific ctor definition

I just want to rewrite specific ctor definition. To find witch on to change I use 'normal' DeclarationMatcher DeclarationMatcher ClassMatcher2 = cxxRecordDecl(isDerivedFrom("X"), has(fieldDecl( …
teZeriusz
  • 81
  • 2
  • 8
2
votes
1 answer

libclang ,clang_Cursor_isAnonymous what is an anonymous declaration?

I have some difficulties to understand what are anonymous structures declaration (or union) . From this link: http://clang.llvm.org/doxygen/classclang_1_1RecordDecl.html#ad2dd151523eecb8d15149cc0937c3dff this is an anonymous declaration union {…
cedlemo
  • 3,205
  • 3
  • 32
  • 50
2
votes
0 answers

How to get tokens for a declaration using Clang C++ API?

I have my own recursive AST visitor class with the clang::ASTContext object inside: class Visitor : public clang::RecursiveASTVisitor { public: Visitor(const clang::ASTContext& context) : context_(context) {} private: const…
abyss.7
  • 13,882
  • 11
  • 56
  • 100
2
votes
0 answers

pip package: proper way of compiling code that depends on libclang

I am building a python library, that I want to be installable via pip. The installation process requires a cpp file to be compiled, and that cpp file depends on libclang (in particular, it includes some of clang-c header files, and needs to be…
Ishamael
  • 12,583
  • 4
  • 34
  • 52
2
votes
0 answers

Embedding clang Compiler into OS X Cocoa App

As part of development for an application of mine that generates C source code, I need to be able to embed a compiler into my application so that it can generate executable object code. Since this is a sandboxed app intended for the Mac App Store, I…
SevenBits
  • 2,836
  • 1
  • 20
  • 33
2
votes
1 answer

Find conditional evaluation in for loop using libclang

I'm using clang (via libclang via the Python bindings) to put together a code-review bot. I've been making the assumption that all FOR_STMT cursors will have 4 children; INIT, EVAL, INC, and BODY.. for( INIT; EVAL; INC ) BODY; which would imply…
bgutt3r
  • 558
  • 3
  • 10
2
votes
0 answers

Can't get CXCursor at some offsets within an include statement

Given this source file as test.cpp #include If I parse it with clang_parseTranslationUnit() using the CXTranslationUnit_DetailedPreprocessingRecord option I find there is a single CXCursor located in my source file with kind…
2
votes
1 answer

CLang Libtooling: fetching datatype of a variable inside clang::VarDecl, clang::FieldDecl or clang::ParmVarDecl

I am working on CLang 3.5. I am trying to fetch info about variables declared in a C++ project. How can I fetch datatype or qualified class name of a variable in a clang::VarDecl, clang::FieldDecl or clang::ParmVarDecl object? I tried to find a…
Prakhar Mishra
  • 1,586
  • 4
  • 28
  • 52
2
votes
1 answer

how to refresh AST in libclang

my code visit the AST generated by libclang, and insert some code into it. I want to get the new AST, at the same time I want to avoid writing code to file, Is there any api in libclang to do this?
WhatisThat
  • 267
  • 4
  • 10
2
votes
0 answers

"linker' input unused when '-fsyntax-only' is present" on libClang

Has anyone experienced this sort of problem while attempting to running a executable generated by clang on a code using libclang (it occurs if I compile using gcc too)? Using few prints I noticed that it occurs on the following function call:…
1
vote
0 answers

libclang: how to get non-type template arguments from a CXType?

Given the following code to parse: template class Base {}; using BaseFloat1 = Base; I can get the TypeAliasDecl from the last line, get the CXType from that, and the use clang_Type_getNumTemplateArguments() to see…
user1832047
  • 155
  • 9