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

How to completely parse cpp file by clang?

I'm using clang in python to parse c++ code file, here's my code: def traverse(node, depth): print("%s%s %s" % ("| " * depth, str(node.kind), node.spelling)) for n in node.get_children(): traverse(n, depth + 1) if __name__ ==…
0
votes
1 answer

Get AST of MACRO statements usinc libclang

There are quite a few defined macros in my code that I would like to be able to get the AST of. A statement might look like this: #define maskout_different_softening_flag(x) (x & (1 << BITFLAG_MIXED_SOFTENINGS_IN_NODE)) So if…
dearn44
  • 3,198
  • 4
  • 30
  • 63
0
votes
0 answers

Is there a way to get a meaningfull error message when compiling code through libclang?

I am trying to compile code at runtime using libclang. I am giving ti deliberately malformed code to try to see how to print error messages. To this effect I am calling clang_parseTranslationUnit2 on my faulty string. And sure enough it returns an…
Makogan
  • 8,208
  • 7
  • 44
  • 112
0
votes
1 answer

Cannot install any R package

I'm on Ubuntu 20.04. R version 4.0.2. I've been using R for a long time and everything worked fine. Today, when trying to install new packages i get this error: ** checking absolute paths in shared objects and dynamic libraries readelf: symbol…
Willinki
  • 1
  • 1
0
votes
0 answers

Generate header amalgamation from multiple header and source files?

I've been using a header-only library, but it has actually separated it out into header (*.h) and source (*.c) files. SQLite creates a single file—primarily for other reasons related to optimisation—so I was wondering if there's an automated way of…
Samuel Marks
  • 1,611
  • 1
  • 20
  • 25
0
votes
1 answer

Libclang: Get Symbol (e.g. function) at SourceLocation

I want to write a refactor tool, where I want to move the function at the cursor(cursor is in the function name) to the source file. I found the FunctionMover.cc in https://github.com/lanl/CoARCT which is a good starting point to move the…
veio
  • 507
  • 4
  • 16
0
votes
1 answer

How would I get the depth of a function using libclang?

I'm currently using libclang to do static code analysis for a school project. I've got it set up and working, and have so far managed to get the file location and physical length (number of lines) of a function, but the next thing I want to get is…
AgentPaper
  • 109
  • 4
0
votes
0 answers

Libclang does not detect function calls defined in headers

I am using libclang to parse .cpp and get all function calls in the file. However , the only returned function calls are the one defined at the parsed .h / .cpp file not all the ones from the include files. for example I am parsing example.cpp…
Hazem Abaza
  • 331
  • 4
  • 21
0
votes
1 answer

How to speed up parsing C++ code using libclang?

I have a project that must be parsed before original compilation. It's needed for reflection purposes. In short I want to check edited .h files for some attributes in the code and gather info about it to generate specific include files. For example…
Artem Selivanov
  • 1,867
  • 1
  • 27
  • 45
0
votes
1 answer

Definition data of ClassTemplateSpecializationDecl is null

I recieve a class alt::VectorLayout for example, as a ClassTemplateSpecializationDecl and I'm trying to process the field and methods of the class, but it fails on an assertion where the definition data is null. I have the presumption that…
7Hazard
  • 23
  • 2
  • 6
0
votes
0 answers

How to handle if init statement (c++17) with libclang

I use libclang for creating syntax colorizing tool for c/c++ files. All works fine, but I has a problem with handling init statement in if statement (c++17 feature). For example struct alpha {}; int main() { if (alpha a; 1 < 10) { } } So when…
0
votes
0 answers

How to specify directory for compilation

I wrote some tool, based on libclang, which get some file and create translation unit from it and parse ast tree, but the tool needs compile flags, so I must specify all needed flags for compilation the file. So, here is a small problem: I can not…
0
votes
0 answers

How to check if a c++ function is asynchronous using Libclang?

I am parsing c++ codes using Libclang. I want to check for every function/method if it is asynchronous. For example: void returnN(std::function handler){ auto t = std::thread([handler](){ handler(10); }); …
Jahnvi
  • 43
  • 1
  • 2
0
votes
0 answers

How to fix "no matching function for call to 'wprintf'" in libclang on windows' visual studio 2015

I'm using libclang to analyse code, because my project has too many files, so I need clang's precompiled headers to speed up. First I save the pch file in disk, but when using it, libclang give errors. const char* custom_args[] = { …
Roland Yim
  • 36
  • 6
0
votes
1 answer

Unable to link libclang with cmake on VS2017

A while ago I wrote a code generation program to use in my 3D game engine. I added a target to my cmake files, linked libclang with it as I'm using that for parsing the code, and it all worked fine. Recently I added another dependency to my project,…
MivVG
  • 679
  • 4
  • 16