Clang 工具预处理源文件

Clang Tooling Preprocess Source Files

我正在使用 Clang::Tooling 库来解析一些头文件。由于 clang 没有预处理头文件和其他预处理器内容,我似乎无法正确解析。我如何告诉 Clang::Tooling 在解析之前预处理文件。干杯。这是我当前用于调用我的工具的代码。

/*static*/ SAST SAST::Parse( CFile& HeaderFile, const TArray<CString>& CommandLineArgs )
{
    //Our Custom Formated Ast Data Struct
    SAST AST;

    //Parse Command-Line Args.
    clang::tooling::CommandLineArguments CommandArgs;
    for (auto& Item : CommandLineArgs)
        CommandArgs.push_back(Item.GetRaw());

    //Traverse And Collect AST
    auto SourceText = HeaderFile.GetText();
    auto SourceFileName = HeaderFile.GetFullName();
    clang::tooling::runToolOnCodeWithArgs(new CollectASTAction(&AST), SourceText.GetRawConst(), CommandArgs);

    return AST;
}

显然它实际上是在尝试预处理文件。由于没有控制台 window 打开,我看不到任何报告的错误。但是,当我检查带有断点的 llvm::raw_fd_ostream class 的 write() 方法时,我可以看到正在写入错误,例如 "FileXXX.h could not be found"。所以它根本找不到 #include 文件。这就是预处理不是 performed/completed 的原因。感谢大家。这解决了我一天的漫长旅程。