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

libclang not finding headers in <> brackets on Mac with Xcode

Edit: This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode. I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following…
bc888
  • 141
  • 14
0
votes
1 answer

How can I specify the target platform when using libclang to analyse C code?

I am using a source code analysis tool using Clang (version 6.0.1). The source code I want to analyse was written for an ARM processor and will be compiled using arm-none-eabi-gcc. My tool is running on Linux or Windows. How can I tell libclang to…
ygramoel
  • 669
  • 1
  • 6
  • 18
0
votes
0 answers

libclang with Visual C++

I'm new to working with Visual C++ and I would like to add libclang as a dependency to my project. I have downloaded LLVM and compiled libclang successfully with cmake in a separate directory outside my Visual C++ solution. I would like copy the…
Sienna
  • 1,570
  • 3
  • 24
  • 48
0
votes
0 answers

Get all functions called (even if called by another function) libclang python

I'm trying to use libclang/python 3.7 to gather every function called in a program by parsing it into a translation unit. I parse the main.cpp file in order to gather the data. Testhead.cpp: #include void a() { std::cout<<5; …
magic_HAT
  • 19
  • 2
0
votes
2 answers

pass a member function as argument in libclang visitor

I am using LibClang to traverse AST in a C++ program as below: CXChildVisitResult visitor(CXCursor cursor, CXCursor parent, CXClientData data) { // some code } int main() { // some code clang_visitChildren(rootCursor, visitor, 0); } I do not…
Sida
  • 23
  • 3
0
votes
1 answer

how to auto refactor C for loops

I have a very large old code base I am slowly updating. Throughout large parts of the code there are for loops preforming basic math routines that I would like to call back to a function ie to change for(int i=0;i< NUM_EL; i++) { x[i] = a[i] *…
Sam P
  • 681
  • 5
  • 19
0
votes
0 answers

Getting template spelling without arguments, from a type, in libclang

I can't find a way to get a "fully qualified name" for a template type without it's arguments, just plain name. I.e. for a type which spells NS::NS::TemplatedType just NS::NS::TemplatedType. I know it's possible to do for a cursor in a…
luk32
  • 15,812
  • 38
  • 62
0
votes
1 answer

Generate an optimized AST using clang and libclang

I want to apply clang optimizations to a source file then generate its AST. I tried passing -O3 flag but it seems that it is ignored. For example I assume that for this snipped of program: #include int main(void) { int a = 5 + 5; for…
user2232305
  • 319
  • 2
  • 11
0
votes
1 answer

How to build libclang release 6.0

I'm trying to build libclang for the latest release 6.0. As I understand I need to clone llvm repository and then to clone clang repository under tools/clang directory, run cmake command and then build libclang with make liblcang during the build I…
sagi
  • 523
  • 3
  • 15
0
votes
0 answers

Undefined reference compiling with g++

I am trying to create a C/C++ parser using libclang in Windows. I am using MinGW 6.3.0. This is the line of code that I am using to compile the file. g++ -I../clang/include/ main.cpp -L../clang/lib -llibclang -o cdeep Folder Structure: -clang …
0
votes
1 answer

libclang python how to get number of arguments for function with default values

I'm using libclang with it's python binding and I'm trying to get the number of arguments for CallExpr, I found that if a member function has default value and being called with this argument missing, libclang returns the number of arguments in the…
sagi
  • 523
  • 3
  • 15
0
votes
1 answer

Howto inject code using libclang (in C++)

I would like to know how to insert an argument to a function call using libclang? I have to following code that just prints the arguments: class CASTVisitor : public RecursiveASTVisitor { public: CASTVisitor(Rewriter &R) :…
0
votes
0 answers

C++: How to write a program that finds all instances where function X, variable Y, or object Z are called?

Here's some background of what I'm trying to achieve. I'm in need of parsing C++ source code to find all instances where function X is called. This seems doable in libclang as mentioned in this post: Find all references of specific function…
marumaru
  • 55
  • 5
0
votes
1 answer

Use clang to extract documentation comments as XML

I've seen this presentation from 2012 on clang features to handle C++ documentation comments (eg. for doxygen). Slide 20 mentions a new feature to export comments as XML as being part of libclang. I'd like to try that feature out. More…
m8mble
  • 1,513
  • 1
  • 22
  • 30
0
votes
1 answer

Clang Tooling Preprocess Source Files

I am using the Clang::Tooling library to parse some header files. I can't seem to parse properly due to clang not pre-processing header files and other pre-processor stuff. How can I tell Clang::Tooling to pre-process files before parsing. Cheers.…
Richmar1
  • 191
  • 10