簡體   English   中英

如何將AST用於自定義前端操作和clang靜態分析

[英]How to use AST for both custom front-end action and clang static analysis

我正在開發一個基於libTooling的項目,我通過引用編寫了一個自定義前端動作類。 現在我想在同一個工具中運行clang靜態分析。 目前,我再次運行該工具進行clang靜態分析(修改編譯器選項后)。 但這將解析文件並再次創建AST。

我想創建一次AST並用於自定義前端動作和clang靜態分析。

我怎樣才能做到這一點? MultiplexConsumer在這里有什么幫助嗎?

似乎MultiplexConsumer是要走的路。

在我的前端動作課中,這對我有用:

std::unique_ptr<ASTConsumer> CreateASTConsumer(
    CompilerInstance& compiler, StringRef inFile) override {

    std::unique_ptr<ASTConsumer> consumer1 =
        std::make_unique<MyConsumer1>(compiler);

    std::unique_ptr<ASTConsumer> consumer2 =
        std::make_unique<MyConsumer2>(compiler);

    std::vector<std::unique_ptr<ASTConsumer>> consumers;
    consumers.emplace_back(std::move(consumer1));
    consumers.emplace_back(std::move(consumer2));
    return std::make_unique<MultiplexConsumer>(std::move(consumers));
}

但請注意,如果consumer1返回任何錯誤,那么consumer2將不會運行。 如果consumer1僅返回警告或沒有診斷,那么consumer2將運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM