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

In python-clang, how do I figure out if a struct member is bool or _Bool?

I'm using python-clang to parse C code. I want to distinguish between bool and _Bool. defines bool as a macro, not a typedef. For variables, it works to look at the tokens of the cursor. For members in struct declarations, it does not…
Jani
  • 853
  • 8
  • 20
0
votes
0 answers

How to get information about macro implementation in c++ using libclang and python?

I need to get information about macro instantiations in my cpp files. Here is example of what I need to do: #define TEST_PARAM_MACRO( Type ) \ static Type var; #define TEST_NAMESPACE_MACRO( Name ) \ void Name() {} namespace…
Crazy Sage
  • 414
  • 2
  • 14
0
votes
0 answers

How to print out the IF_STMT and RETURN_STMT in libclang, using python

I would like to print out the if/switch statement in c++ source code, currently I'm using the libclang python API. I figured that the .spelling is not the correct way to print out the statement, any idea how to solve it? python scripts: def…
Crystal
  • 85
  • 9
0
votes
0 answers

Extracting the call graph with the accessed variables and called functions from C Source Code or C binary

I would like to know a reliable and convinient way (preexisting libraries, C-compilers) to extract the specific information from a C Source Code or C binary code - the format does not really matter, but rather the result is what matters…
SimpleThings
  • 147
  • 2
  • 12
0
votes
1 answer

libclang.dll cannot be found

I have installed the clang python library on windows. When I'm executing a script that uses it, It gives me this: Could not find module 'path\to\clang\libclang.dll' (or one of its dependencies). Try using the full path with constructor syntax.. To…
Shaheen
  • 31
  • 6
0
votes
1 answer

rust libclang, why am I parsing only c functions from a cpp file?

I am trying to write a rust script that parses a C++ file, finds all extern C declared functions and prints them out. To that effect I have this first attempt: use clang::*; use clap::{Arg, App}; fn main() { let matches = App::new("Shared C++…
Makogan
  • 8,208
  • 7
  • 44
  • 112
0
votes
1 answer

How do I retrieve all function calls from C++ source files with libclang?

I'm learning to parse some C++ source file with python-libclang, so far I have a script that can partially achieve what I hope: import clang.cindex idx = clang.cindex.Index.create() tu = idx.parse('example.cpp', args='-xc++…
Rahn
  • 4,787
  • 4
  • 31
  • 57
0
votes
1 answer

How to identify all C++ standard library calls in source code?

I want to get the information about how many kind of C++ standard library features are used in my application source code, e.g., whether vector is used or some STL algorithm is used? For C library, I know that I can use objdump -T | grep GLIBC on…
Simon Zhu
  • 7
  • 2
0
votes
0 answers

Incomplete TranslationUnit with libclang CXTranslationUnit_SingleFileParse

I'm trying to parse a single C++ file that looks as follows: #include #include #include "foo.h" std::unique_ptr FooBar::baz(std::wstring const& text) { auto result = std::make_unique(text.length() + 1); …
DEls
  • 241
  • 3
  • 14
0
votes
1 answer

Decide a template declaration is a struct or a class using AST parsed with libclang

template struct TBox2 { } typedef TBox2 FBox2f; So the template declaration in AST is a CursorKind.CLASS_TEMPLATE. How can I tell the template is a struct or class ? > tpl.kind CursorKind.CLASS_TEMPLATE > tpl.spelling 'TBox2' >…
Joey.Z
  • 4,492
  • 4
  • 38
  • 63
0
votes
1 answer

How to include libclang as a dependency using meson?

I am trying to use libclang for some source parsing on linux. I have libclang-dev installed and it appears under the list of packages for apt on my system. However when i try to add it as a dependency through any…
Makogan
  • 8,208
  • 7
  • 44
  • 112
0
votes
1 answer

`clang::PluginASTAction` with `clang::tooling::runToolOnCode` produce string output (for tests)?

With clang::tooling::runToolOnCode I can provide std::string input but I only get a bool output. static const char *const from = "#include \n" "int main(void) {\n" " for(int i=0; i
Samuel Marks
  • 1,611
  • 1
  • 20
  • 25
0
votes
1 answer

OSError: libclangFrontend.so.5: cannot open shared object file: No such file or directory

I am running bcc-tools on cent os 7. I have taken all the steps available on google: set LD_LIBRARY_PATH the one available here: https://blogs.oracle.com/linux/post/intro-to-bcc-2 llvmtoolset is already installed I just want to run bcc-tools on…
user248396
  • 25
  • 4
0
votes
1 answer

Python libclang how do you use a compilation database?

This has been asked twice already one answer seems very popular: How to use compile_commands.json with clang python bindings? This other one not as much: How to use compile_commands.json with llvm clang (version 7.0.1) python bindings? However…
Makogan
  • 8,208
  • 7
  • 44
  • 112
0
votes
1 answer

How do I get AST as string using libclang?

I need to transverse AST using libclang. All solutions I have found tell me to dump the AST in a .ast file and then create translationUnit with that file for transversing. It would be great to be able to do the following: Generate AST for some code…