libclang


C++ libclang: Retrieving cursor from CXSourceLocation returning wrong cursor?

泄露秘密 提交于 2020-01-13 03:56:50
问题 I am currently writing a simple clone detector using libclang with C++. The program stores cursors using a struct, containing a pointer to the translation unit and the CXSourceLocation gained from calling clang_getCursorLocation(cursor). typedef struct { CXTranslationUnit* tu; CXSourceLocation srcLoc; } t_cursorLocation; For the sake of this error, the child visitor function visits each node and creates a struct from each cursor. With a struct of type t_cursorLocation, I wrote this function

libclang: missing some statements in the AST?

☆樱花仙子☆ 提交于 2020-01-03 17:09:13
问题 I've wrote a test program (parse_ast.c) to parse a c source file (tt.c) to see how libclang works, the output is the hierarchical structure of the AST: Here is the test file: /* tt.c */ // line 1 #include <unistd.h> #include <stdio.h> typedef ssize_t (*write_fn_t)(int, const void *, size_t); void indirect_write(write_fn_t write_fn) { // line 7 (*write_fn)(1, "indirect call\n", 14); } void direct_write() { // line 11 write(1, "direct call\n", 12); // line 12 mising in the ast? } int main() { /

How to extract comments and match to declaration with RecursiveASTVisitor in libclang c++?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 02:17:07
问题 I am writing a utility which is supposed to parse C++ (and C) header files, extract the structs, enums, fields etc. and generate code in other languages based on the extracted information. I decided to use libclang for this. I'm using a RecursiveASTVisitor and it seems I'm able to extract all the information I need, except for comments. I want to have the comment which appears right above every declaration (field, struct, class, enum) read, and add its text when I generate the code in other

How can I parse a typedef for a function pointer using clang API to get the function pointer name?

徘徊边缘 提交于 2019-12-24 11:29:05
问题 I am currently building a parser for C++ code using the clang C API. The parser will process a header file and generate a list of defined and missing symbols for it (it ignores include directives, so it will parse strictly the contents of the header). My problem is, if I have a typedef for a function pointer which takes an argument of an undefined type, such as: typedef SOME_TYPE (* funcPtrName)(SOME_UNDEF_TYPE x); the AST parses SOME_TYPE as the typedef instead of funcPtrName . If I replace

How can I retrieve fully-qualified function names with libclang?

这一生的挚爱 提交于 2019-12-24 08:32:51
问题 I need to parse a C++ code file and find all the function calls in it with fully-qualified names. I'm using libclang's Python bindings because it seems easier than writing my own C++ parser, even if the documentation is sparse. Example C++ code: namespace a { namespace b { class Thing { public: Thing(); void DoSomething(); int DoAnotherThing(); private: int thisThing; }; } } int main() { a::b::Thing *thing = new a::b::Thing(); thing->DoSomething(); return 0; } Python script: import clang

Why can't this python script find the libclang dll?

自闭症网瘾萝莉.ら 提交于 2019-12-23 22:45:07
问题 I would like to get started with using libclang with Python . I am trying to get a sample code (http://www.altdevblogaday.com/2014/03/05/implementing-a-code-generator-with-libclang/) to work on Windows , here is a part of the code I'm trying to run: #!/usr/bin/python # vim: set fileencoding=utf-8 import sys import os import clang.cindex import itertools ... print("Setting clang path") # I tried multiple variations. Libclang is correctly installed in the specified location. #clang.cindex

How to get function definition/signature as a string in Clang?

和自甴很熟 提交于 2019-12-23 18:04:25
问题 How can I get a function's signature (or at least the entire definition?) as a string using Clang/Libclang, assuming I have its CXCursor or so? I think that the definition may be somehow obtainable by using the cursor's extents, but I don't really know how (what function to use). 回答1: You can use this simple code to get prototype of a function ( name, return type, count of arguments and arguments[name,data type]). string Convert(const CXString& s) { string result = clang_getCString(s); clang

python libclang bindings on Windows fail to initialize a translation unit from sublime text

空扰寡人 提交于 2019-12-23 13:32:59
问题 Short description : using libclang to autocomplete code does not work with python that comes bundled with Sublime Text 3. Details : A small verifiable example is in the repo on Github In essence, there is a script that uses a slightly changed cindex.py (compatible with python 3 and clang 3.8) and builds a Translation Unit from a test source file. It then reparses it and tries to complete. The script works as expected on using Python 3.3.5 from Powershell. When put into Packages folder on

libclang get primitive value

社会主义新天地 提交于 2019-12-21 01:06:19
问题 How can I get the value of a primitive literal using libclang? For example, if I have a CXCursor of cursor kind CXCursor_IntegerLiteral, how can I extract the literal value. UPDATE: I've run into so many problems using libclang. I highly recommend avoiding it entirely and instead use the C++ interface clang provides. The C++ interface is highly useable and very well documented: http://clang.llvm.org/doxygen/annotated.html The only purpose I see of libclang now is to generate the ASTUnit

possible to share work when parsing multiple files with libclang?

拈花ヽ惹草 提交于 2019-12-19 04:01:46
问题 If I have multiple files in a large project, all of which share a large number of included header files, is there any way to share the work of parsing the header files? I had hoped that creating one Index and then adding multiple translationUnits to it could cause some work to be shared - however even code along the lines of (pseudocode) index = clang_createIndex(); clang_parseTranslationUnit(index, "myfile"); clang_parseTranslationUnit(index, "myfile"); seems to take the full amount of time

工具导航Map