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
0 answers

Get variable definition as string using Clang

What way would you recommend of getting the definition of (global) variable var as it is in the source code snippet int var = MACRO(5) + 5; using Clang/Libclang if I have var's definition cursor? One way would be to use the cursor's extents to…
PhantomR
  • 605
  • 4
  • 16
1
vote
0 answers

Get definition without comments in (lib)clang

Suppose I have the variable definition int x = MACRO(5) /* HOHO */ + 25; and have access to x's CXCursor in libclang. I want to get the definition without the additional spaces and without the comment. I know how to get the extents of the…
PhantomR
  • 605
  • 4
  • 16
1
vote
1 answer

Cannot link to libclang in OSX High Sierra

I have installed llvm and clang through brew. When I compile a program with the header file "clang-c/Index.h", I get Undefined symbols for architecture x86_64: "_clang_createIndex", referenced from: _main in t-c9baef.o .... Here is the command I…
user2232305
  • 319
  • 2
  • 11
1
vote
0 answers

libclang getting original struct parameter types

This appears to be a duplicate question (I found someone asking the same thing yesterday but I can't find it now), except that the other copy of this question provided an alternative answer that doesn't really address the problem. I'm working on a…
xanderflood
  • 826
  • 2
  • 12
  • 22
1
vote
0 answers

Make clang just parse ast without bothering about includes

I'm writing a tool that uses clang CompilerInstance and ParseAST to parse and rewrite a source file. What I find quite annoying is that if include paths are missing then the tool outputs an error that it can not find some include file, however the…
Martin
  • 3,509
  • 3
  • 26
  • 31
1
vote
1 answer

Reparse an ASTUnit with relative header include paths fails

I'm using libclang's LibTooling to get code completion data from C++ source files. The ASTUnits are generated from a compile_commands.json file created via CMake with Ninja as the generator. In the compiler invocation commands, there are relative…
1
vote
1 answer

Find a function definition for a specific function call with Clang

I'm trying to build a small program with libclang which retrieves the definition of a function/method for a specific function call. For instance, I have the following main.cpp: int add(int x, int y) { return x + y; } int main() { int a =…
filaton
  • 2,257
  • 17
  • 27
1
vote
1 answer

python + libclang; iterating back and forth: binding field comments to the field

I struggling for a while now to find a decent way to bind a field in C++ structure to its comments, using libclang 3.9.1, and python 3.5.2. So far, I got this setup up and running: Assuming that I have file Foo.h: typedef int arbType; struct Foo { …
Bak Itzik
  • 466
  • 1
  • 5
  • 17
1
vote
0 answers

Why is libclang (libclang.so.3.9) so large(124 MB) in CentOS 6.5 after compiling from source?

I have downloaded and compiled libclang following this link on CentOS 6.5: https://www.vultr.com/docs/how-to-install-llvm-and-clang-on-centos-6 I did just till make as I only need libclang.so and not the clang compiler installed. libclang.so.3.9 is…
safe_malloc
  • 824
  • 2
  • 12
  • 29
1
vote
0 answers

get_field_offsetof in libclang 3.9 python binding doesn't work for uint64_t

What I am doing is I want to use libclang to parse a c++ head file then get AST to find structs and describe their formats as, struct 0 name,field 0 name,field 0 offset,field 1 name,field 1 offset, ... struct 1 name,field 0 name,field 0…
DAG
  • 417
  • 4
  • 7
1
vote
1 answer

Get function declaration type with AST visitor clang

I have implemented an AST visitor using Clang. With this piece of code and I can retrieve the function call name correclty. virtual bool VisitFunctionDecl(FunctionDecl *func) { numFunctions++; string funcName =…
Andreas Geo
  • 365
  • 2
  • 15
1
vote
0 answers

Clang Tutorial Compilation Error

Like every new guy am trying to build something with Clang, using the tutorials found here: Ioarabia Clang Tutorials I can build the 1st and 2nd tutorial using this command: export CLANG_LIBS="-lclangTooling -lclangFrontendTool -lclangFrontend…
1
vote
1 answer

Libclang tokenKinds

Where can I find the token kinds in libclang? for example I know these token kinds exists: eof, r_paren, l_paren, r_brace, l_brace Where can I find the rest of the token kinds? Thank you.
Andreas Geo
  • 365
  • 2
  • 15
1
vote
2 answers

Get actual spelling of lib clang cursor/type

I writing a script to detect formatting errors in my C++ code. (for example making sure all member variables are prefixed with m_). One of things I want to do is make sure types that are pointers have the asterix attached to the type (int* num, not…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
1
vote
1 answer

LibClang Python binding function "getOverridden"

LibClang exposes a function to "determine the set of methods that are overridden by the given method" (explained here). However this function does not seem to be exposed in the python bindings. Could someone explain how to add this function to the…
cwde
  • 214
  • 1
  • 10