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
108
votes
2 answers

Faster code-completion with clang

I am investigating potential code-completion speedups while using clang's code-completion mechanism. The flow described below is what I found in rtags, by Anders Bakken. Translation units are parsed by a daemon monitoring files for changes. This is…
Pradhan
  • 16,391
  • 3
  • 44
  • 59
19
votes
1 answer

Finding anonymous enums with libclang

Is there a way to detect anonymous enumerations using libclang without relying on the text in the spelling name? The python bindings to libclang include functionality to detect whether C/C++ structs or unions are anonymous using…
Andrew Walker
  • 40,984
  • 8
  • 62
  • 84
17
votes
1 answer

C-family Semantic Autocompletion Plugins for Vim (C/C++ completion) using Clang (clang_complete, YouCompleteMe)

I am using 64-bit Vim on windows, this version by Haroogan: +python27 +python33 +huge I am trying to use clang_complete, so I took the libclang.dll library here and I set up my vimrc correctly. libclang.dll is found. However when I open a *.cpp…
statquant
  • 13,672
  • 21
  • 91
  • 162
16
votes
2 answers

How to extract comments and match to declaration with RecursiveASTVisitor in libclang c++?

I am writing a utility which is supposed to parse C++ (and C) header files, extract the structs, enums, fields etc. and generate code in other languages based on the extracted information. I decided to use libclang for this. I'm using a…
Asaf
  • 4,317
  • 28
  • 48
14
votes
1 answer

Obtain original (unexpanded) macro text using libclang

Using libclang, I have a cursor into a AST, which corresponds to the statement resulting from a macro expansion. I want to retrieve the original, unexpanded macro text. I've looked for a libclang API to do this, and can't find one. Am I missing…
Jeremy
  • 5,055
  • 1
  • 28
  • 44
13
votes
2 answers

How to find out whether a member function is const or volatile with libclang?

I have an instance of CXCursor of kind CXCursor_CXXMethod. I want to find out if the function is const or volatile, for example: class Foo { public: void bar() const; void baz() volatile; void qux() const volatile; }; I could not find…
user1203803
12
votes
3 answers

Retrieve information about pre-processor directives

I've recently started using libclang to parse C files. The problem I'm having is that apparently, libclang initiates the preprocessor before generating AST. I would like to prohibit the preprocessor from running, and instead be given information…
Robin Heggelund Hansen
  • 4,906
  • 6
  • 37
  • 54
11
votes
1 answer

Remove CV type qualifiers from libclang's CXType

I use libclang to parse source file and get reference to some type as CXType, say it is "const std::__1::basic_string" (as reported by clang_getTypeSpelling). How can I get reference to same type but without const qualifier?
kriomant
  • 2,216
  • 1
  • 16
  • 21
11
votes
2 answers

Inspecting generalized attributes with libclang

I would like to parse generalized attributes of class member functions in the following example: class Foo { public: void foo [[interesting]] (); void bar (); }; Using the libclang C API, I would like to distinguish between foo and bar (and…
Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
11
votes
1 answer

Any tutorial on libclang?

I've been looking for some easy to understand guide into libclang. I've seen some threads either here or other forums but the only recommended sources of information were libclang source/doxygen doc, clang complete plugin for vim or Thinking Beyond…
user1307957
  • 541
  • 3
  • 8
  • 19
10
votes
1 answer

Find all references of specific function declaration in libclang (Python)

I am trying to find (line and column position) all the references of a specific function declaration when parsing a C++ source file via libclang in Python. For example: #include using namespace std; int addition (int a, int b) { int…
user6003691
10
votes
2 answers

libclang: how to get token semantics

libclang defines only 5 types of tokens: CXToken_Punctuation CXToken_Keyword CXToken_Identifier CXToken_Literal CXToken_Comment Is it possible to get a more detailed information about tokens? For example, for the following source code: struct…
piotrekg2
  • 1,237
  • 11
  • 21
10
votes
4 answers

Where is libclang.so?

I am using Linux Mint and I installed clang_complete using the makefile from Clang Complete, but it does not work. When I open a cpp file, there is an error message: Loading libclang failed, completion won't be available. Consider setting…
user3476184
  • 101
  • 1
  • 1
  • 6
9
votes
2 answers

Unable to install RStudio, cannot install 'libclang-dev'

I use ubuntu 20.04.2. I had some problems with rStudio so I unistalled completelly from my computer. I already have installed r, but now I want to install rStudio but when I try to I get that 'libclang-dev' is uninstallable. $ sudo gdebi…
IgnacioNC
  • 311
  • 2
  • 7
9
votes
1 answer

How do you detect the difference between an enum and a scoped enum using libclang?

I have been writing a C++ AST parser using the excellent C interface libclang (http://clang.llvm.org/doxygen/group__CINDEX.html). Unfortunately there appears to be no disambiguation between C++ 11 scoped enums and old fashioned enums: both have a…
Niall Douglas
  • 9,212
  • 2
  • 44
  • 54
1
2 3
15 16