libclang

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

Function boundary identification using libclang

有些话、适合烂在心里 提交于 2019-12-14 03:52:48
问题 I am learning to parse C++ files using Python + libclang with the help of this very informative (but slightly outdated) tutorial by Eli Bendersky. My objective is to parse C++ files and identify the function boundaries for functions present in those file. I am expecting to build a python dictionary of this form: {<func_name>:(<func_start_loc>, <func_end_loc>), ...} To this end, I am able to get the function name (using cursor.spelling for AST nodes that are of CursorKind.FUNCTION_DECL or

LLVM cmake install cannot find DIA SDK

ε祈祈猫儿з 提交于 2019-12-14 02:13:35
问题 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 error: CMake Error at cmake/config-ix.cmake:482 (message): DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards. Call Stack (most recent call first): CMakeLists.txt

How to fix “Xcode quit unexpectedly while using the libclang.dylib plug-in.”?

走远了吗. 提交于 2019-12-10 03:51:06
问题 I have this every time in a short while after I start xCode ( 5.1.1 ). Removed user data, turned off source control (as some posts suggested), no effect, still crashes (while showing Indexing... that never finishes). Even reinstalled xCode, without any effect, still says the same. Did anybody fixed such an xCode? Here's the crashing thread: Thread 7 Crashed:: Dispatch queue: IDEIndex PCH Creation Lock 0 libclang.dylib 0x00000001080c60d9 void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl

libclang: add compiler system include path (Python in Windows)

℡╲_俬逩灬. 提交于 2019-12-08 19:36:09
问题 Following this question and Andrew's suggestions, I am trying to have liblang add the compiler system include paths (in Windows) in order for my Python code import clang.cindex def parse_decl(node): reference_node = node.get_definition() if node.kind.is_declaration(): print(node.kind, node.kind.name, node.location.line, ',', node.location.column, reference_node.displayname) for ch in node.get_children(): parse_decl(ch) # configure path clang.cindex.Config.set_library_file('C:/Program Files

Using libclang to parse in C++ in Python

一世执手 提交于 2019-12-07 19:03:56
问题 After some research and a few questions, I ended up exploring libclang library in order to parse C++ source files in Python. Given a C++ source int fac(int n) { return (n>1) ? n∗fac(n−1) : 1; } for (int i = 0; i < linecount; i++) { sum += array[i]; } double mean = sum/linecount; I am trying to identify the tokens fac as a function name, n as variable name, i as a variable name, mean as variable name, along with each ones position. I interested in eventually tokenizing them. I have read some

Python clang does not search system include paths

▼魔方 西西 提交于 2019-12-07 10:03:18
问题 When using libclang from Python, it doesn't seem to automatically search the system's include paths. Is there a reliable way to get these paths? I don't like hardcoding paths as I'm writing code that will run on a variety of UNIX systems. For example, given test.cpp #include <stdio.h> int main() { puts("Hello, world!"); } and test.py from clang.cindex import Index tu = Index.create().parse(None, ["test.cpp"]) print(list(tu.diagnostics)) running python test.py will print: [<Diagnostic severity

How to skip subtrees in AST traversal using python bindings for libclang

被刻印的时光 ゝ 提交于 2019-12-07 08:01:14
问题 I have just started using libclang via python bindings. I understand that I can traverse the entire syntax tree (AST) using get_children , but I have not been able to find a get_next_sibling() (or whatever it might be called) function so that I can skip subtrees that are not of interest. Does such a function exist? 回答1: I don't think a get_next_sibling function exists in the Python API, but I also don't see why you should need it. In the python API, each node in the AST knows about all its

Libclang API to get function definitions defined in a different file

被刻印的时光 ゝ 提交于 2019-12-06 16:03:12
问题 Suppose I have two files main.c and func.c func.c is called from main.c's main function. Normally, I would generate main.o and func.o and linker would find definition of func and tie it up to it's call in main .c Now, I want to do same thing through libclang APIs. This is for a Doxygen type code browsing utility I am making. I am able to parse the two files. From here, I don't know how to proceed. Should I generate *.o files and make clang link them? Thanks, I hope I am clear in asking the

Using libclang to parse in C++ in Python

試著忘記壹切 提交于 2019-12-06 09:20:40
After some research and a few questions, I ended up exploring libclang library in order to parse C++ source files in Python. Given a C++ source int fac(int n) { return (n>1) ? n∗fac(n−1) : 1; } for (int i = 0; i < linecount; i++) { sum += array[i]; } double mean = sum/linecount; I am trying to identify the tokens fac as a function name, n as variable name, i as a variable name, mean as variable name, along with each ones position. I interested in eventually tokenizing them. I have read some very useful articles ( eli's , Gaetan's ) as well as some stack overflow questions 35113197 , 13236500 .