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

Clang function cursor return type

I am trying to get the type of parameters and type of return of a C function. For example I have function: int addTwoIntegers(int a, int b){ return a + b; } What I need is: int (int, int) I am using clang frontend to generate AST. Currently…
Farrukh Nabiyev
  • 346
  • 2
  • 11
2
votes
1 answer

libclang can't find include file despite include path specified

I'm having a problem with libclang. I'm currently writing a C++ parser in C++ using libclang, and apparently, clang does not know where my headers are, despite having specified the include directory. The file I want to parse includes other headers…
Dave
  • 41
  • 8
2
votes
1 answer

LibClang clang_getArgType() returns wrong type

I tried parsing C++ methods using libClang, but when trying to get the parameters/arguments of functions, it gives the wrong types sometimes. Example: I have two separate methods std::string Method::exportMethod(std::map
Bálint
  • 4,009
  • 2
  • 16
  • 27
2
votes
1 answer

Why does libclang mis-parse C++ headers with a .h prefix?

I tried to parse a c++ header with libclang, but the parser only parsed the class name - and show its type as VarDec1. When the file extension changed from .h to .cpp, it just works fine. I couldn't find the answer after days of searching, can…
S.C.
  • 23
  • 4
2
votes
1 answer

How to use compile_commands.json with llvm clang (version 7.0.1) python bindings?

I am attempting to print out all the AST nodes in a given C++ file. And i provide a valid C++ file that has a compile_commands.json file in its parent directory. All steps just like How to use compile_commands.json with clang python bindings? and my…
Abigtree
  • 89
  • 1
  • 1
  • 5
2
votes
1 answer

Is there a way to cross-reference symbols across multiple translation units using libtooling?

I have a Lib and multiple Applications. I want to gather usage statistics about function calls to Lib's API from Apps. Basically my current process is: Parse the Lib for all functions/methods Output the info in a formatted way Use that output to…
2
votes
0 answers

How to get field declaration types other than primitive types in libclang?

I'm trying to get field declaration types other than primitive types in libclang for a C++ AST. Types like {int, float, etc.} can be decoded using clang_getTypeSpelling. CXType is not a CXString, I cannot deduce types like std::string etc because…
bc888
  • 141
  • 14
2
votes
1 answer

libclang give wrong result for type qualifier

Currentlty I'm working on a project to dump class infomation for c++ code with libclang. And there comes some miserable experience with regards to type qualifiers: const, volatile, &, && and their combination. Here are the sample code to dump…
spiritsaway
  • 635
  • 1
  • 7
  • 16
2
votes
1 answer

Parsing source file with libclang - problems with linking include files

I've written a script to parse C/C++ files using the libclang library. The file I was trying to parse: osf_sys.c. The program prints each function/variable etc. in the file. Sample output: ... CURSORKIND: 6; __user at line: 469 CURSORKIND: 43;…
JTJM
  • 255
  • 1
  • 6
  • 18
2
votes
2 answers

Getting the signature of a FunctionDecl

I got the FunctionDecl for the definition of a function. There is no declaration for this function. For example: int foo(char c, double d) { ... } How do I get the signature (qualifier, return type, function name, parametrs) as a valid…
Fee
  • 719
  • 9
  • 24
2
votes
1 answer

Find clang::Type in Clang AST by name

In Clang AST, is it possible to find type by name? For example I have qualified name : nspace::my_type. How can I check if type is present in current translation unit?
random
  • 3,868
  • 3
  • 22
  • 39
2
votes
1 answer

Getting unqualified version of Type in libclang

Is there a way to get "base" type of, well, Type. I see that it's possible to test for const or volatile, but I don't see a way, to get the underlying type. What I am ultimately trying to do is to map member relationships between classes, and…
luk32
  • 15,812
  • 38
  • 62
2
votes
2 answers

LLVM cmake install cannot find DIA SDK

I'm trying to build the LLVM install with cmake but it is giving me an error about the LLVM_ENABLE_DIA_SDK. I managed to build LLVM before without PDB's but I am trying to get started with libclang so I need the PDB. Cmake gives me the following…
Andreas Loanjoe
  • 2,205
  • 10
  • 26
2
votes
1 answer

clang libtooling insert a new header safely

I'm using clang's libtooling to modify some code and I'm trying to find a way to safely insert a header whenever my tool is used on a C file. I've read What's the right way to match #includes (or #defines) using Clang's libtooling? question about…
Marcus Karpoff
  • 451
  • 5
  • 16
2
votes
0 answers

Why is libclang 3.7/8 not able to infer the correct type of an argument (map)?

I am using the Python API for libclang. I have a little test program that prints the AST (node types, names, types) of a parsed file: from clang import cindex def print_ast(node, depth): line = " " * depth + "Node: %s" % node.kind if…
alfa
  • 3,058
  • 3
  • 25
  • 36