为了分析 AST,我们需要遍历语法树。Clang 提供了两种方式:RecursiveASTVisitor 和 ASTMatcher。RecursiveASTVisitor 能够让我们以深度优先的方式遍历 Clang AST 节点。我们可以通过扩展类并实现所需的 VisitXXX 方法来访问特定节点。 ASTMatcher API 提供了一种域特定语言(DSL)来构建基于 Clang AST 的谓词,它能高效地匹...
ASTMatchFinder::BindKind Bind) : Matcher(Matcher), Finder(Finder), Builder(Builder), CurrentDepth(0), MaxDepth(MaxDepth), IgnoreImplicitChildren(IgnoreImplicitChildren), Bind(Bind), Matches(false) {} MaxDepth(MaxDepth), Bind(Bind), Matches(false) { ShouldVisitTemplateInstantiations = true; Sho...
通过FrontendPluginRegistry注册插件,需要关联插件名与自定义的ASTAction类 【第二步】扫描配置完毕 HandleTopLevelDecl:解析完一个顶级的声明,就回调一次 HandleTranslationUnit:整个文件都解析完成的回调,将文件解析完毕后的上下文context(即AST语法树) 给 matcher 继承自ASTConsumer类,实现自定义的子类CJLASTConsumer,有两...
class="name" onclick="toggle('forEachTemplateArgument0')">forEachTemplateArgumentclang::ast_matchers::Matcher<TemplateArgument> InnerMatcher Matches classTemplateSpecialization, templateSpecializationType and functionDecl nodes where the template argument matches the inner matcher. This matcher may ...
libclangDynamicASTMatchers.dll.a libclangEdit.dll.a libclangExtractAPI.dll.a libclangFormat.dll.a libclangFrontend.dll.a libclangFrontendTool.dll.a libclangHandleCXX.dll.a libclangHandleLLVM.dll.a libclangIndex.dll.a libclangIndexSerialization.dll.a ...
ast_matchers;//命名空间,和插件同名namespace CJLPlugin {//第三步:扫描完毕的回调函数//4、自定义回调类,继承自MatchCallbackclass CJLMatchCallback: public MatchFinder::MatchCallback {private://CI传递路径:CJLASTAction类中的CreateASTConsumer方法参数 - CJLConsumer的构造函数 - CJLMatchCallback的私有...
ast_matchers;namespace QTPlugin{classQTMatchHandler:publicMatchFinder::MatchCallback{private:CompilerInstance&CI;boolisUserSourceCode(conststring filename){if(filename.empty())returnfalse;// 非Xcode中的源码都认为是用户源码if(filename.find("/Applications/Xcode.app/")==0)returnfalse;returntrue;}...
http://clang.llvm.org/docs/LibASTMatchers.html 静态检查的一些库以及使用方法 FauxPas_document_translation/README.md at master · DeveloperLx/FauxPas_document_translation · GitHub CodeGen 生成 IR 代码 将语法树翻译成 LLVM IR 中间代码,做为 LLVM Backend 输入的桥接语言。这样做的好处在前言里也提到...
其中CreateConsumer 创建我们自定义的 consumer 来获取语法树信息,执行ExecuteAction 函数进入 ParseAST 分析流程,调用我们自定义的 ASTConsumer 去handle,通过 RecursiveASTVisitor 或 ASTMatcher 来匹配想检查操作的AST Notes。 如果不符合规范的话,创建一个diagnosis 来警告或报错,并且可以创建一个 FixHint 来提供修复能...
clangASTMatchers ) 2020-08-13 回复喜欢 超自然祈祷 请问,添加的代码是在clang中添加吗?所以最后编译出是一个添加了自定义功能的clang而不是单独的可执行文件? 2020-03-18 回复喜欢 钟浩贤 我也在学习写c编译器,但是没用llvm·· 2020-01-22 回复喜欢 买个冰棍不爱冰 我尝试按...