我正在尝试使用libclang解析一个库,但我遇到了一个可能非常简单的问题:如何使用STL配置它?目前,它无法解析翻译单元,因为找不到.这是我尝试过的:char*args[]={"-x","c++","-Ic:/my/library/includes","-IG:/Prog/libcxx-3.4/include"};clang_parseTranslationUnit(index,"c:/my/library/test.cpp",args,4,0,0,0);我在Windows上,使用从llvm.org下载的预编译clang二进制文件,我尝试了各种STL实现:VisualStudio铭文
我目前正在使用libclang和C++编写一个简单的克隆检测器。程序使用结构存储游标,包含指向翻译单元的指针和通过调用clang_getCursorLocation(cursor)获得的CXSourceLocation。typedefstruct{CXTranslationUnit*tu;CXSourceLocationsrcLoc;}t_cursorLocation;为了这个错误,子访问者函数访问每个节点并从每个游标创建一个结构。使用t_cursorLocation类型的结构,我编写了这个函数来检索相应的光标:CXCursorgetCursor(t_cursorLocation*lo
当从Python使用libclang时,它似乎不会自动搜索系统的包含路径。是否有可靠的方法来获取这些路径?我不喜欢硬编码路径,因为我编写的代码将在各种UNIX系统上运行。例如给定test.cpp#includeintmain(){puts("Hello,world!");}和测试.pyfromclang.cindeximportIndextu=Index.create().parse(None,["test.cpp"])print(list(tu.diagnostics))运行pythontest.py将打印:[,spelling"'stdio.h'filenotfound">]当然可
我在我的.clang-format文件中使用了BreakBeforeBraces:Allman,但在控制语句(例如if、for,while,...)没有放在它们自己的行上。//Currently:voidfoo(){while(true){bar();}}//WhatIwant:voidfoo(){while(true){bar();}}I'vereadthat您可以在BraceWrapping中为大括号设置嵌套配置类,但我无法找出正确的YAML语法(以及sublimetext插件的JSON语法),也找不到任何现有示例。有什么办法吗? 最佳答案
如何使用libclang获取原始文字的值?例如,如果我有一个游标类型为CXCursor_IntegerLiteral的CXCursor,我该如何提取文字值。更新:我在使用libclang时遇到了很多问题。我强烈建议完全避免使用它,而是使用clang提供的C++接口(interface)。C++接口(interface)非常有用并且有很好的文档记录:http://clang.llvm.org/doxygen/annotated.html我现在看到libclang的唯一目的是为您生成ASTUnit对象,就像下面的代码一样(否则并不容易):ASTUnit*astUnit;{index=cla
当我尝试在Qt应用程序中使用libclang时遇到了一个奇怪的错误。测试.cpp#include#include#includeintmain(intargc,char*argv[]){QApplicationa(argc,argv);QMainWindoww;w.show();CXIndexindex=clang_createIndex(0,0);Q_UNUSED(index)returna.exec();}test.proQT+=corewidgetsTARGET=testTEMPLATE=appSOURCES+=test.cppLIBS+=-lclangShell命令和输出:$l
我刚刚构建了LLVM/Clangcompiler-rt并尝试了-fsanitize选项。但奇怪的是链接失败了,因为它找不到libclang_rt.san-x86_64.a。/usr/bin/ld:cannotfind/home/hongxu/RESEARCH/llvm-git/obj/bin/../lib/clang/3.7.0/lib/linux/libclang_rt.san-x86_64.a:Nosuchfileordirectoryclang-3.7:error:linkercommandfailedwithexitcode1(use-vtoseeinvocation)当我进入
libclang只定义了5种类型的标记:CXToken_PunctuationCXToken_KeywordCXToken_IdentifierCXToken_LiteralCXToken_Comment是否可以获得有关token的更详细信息?例如,对于以下源代码:structType;voidfoo(Typeparam);我希望输出是这样的:结构-关键字类型-类型名称>;-标点符号void-类型/关键字foo-函数名(-标点符号Type-函数参数的类型param-函数参数名)-标点符号>;-标点符号我还需要将这些实体映射到文件位置。 最佳答案
我最近开始使用libclang来解析C文件。我遇到的问题显然是,libclang在生成AST之前启动了预处理器。我想禁止预处理器运行,而是提供预处理器指令在文件中的信息...我使用以下python脚本(cindex.py和libclang)importcodecsfromclang.cindeximport*classSourceFile(object):def__init__(self,path):withcodecs.open(path,'r','utf-8')asfile:self.file_content=file.read()index=Index.create()root_
关注此question和Andrew's建议,我正在尝试让liblang添加编译器系统包含路径(在Windows中)以便我的Python代码importclang.cindexdefparse_decl(node):reference_node=node.get_definition()ifnode.kind.is_declaration():print(node.kind,node.kind.name,node.location.line,',',node.location.column,reference_node.displayname)forchinnode.get_child