diff options
author | Daniel Grumberg <dgrumberg@apple.com> | 2022-03-21 19:41:29 +0000 |
---|---|---|
committer | Daniel Grumberg <dgrumberg@apple.com> | 2022-03-23 19:05:19 +0000 |
commit | f833aab0d0bf1bd9e9903a1398e429f431532f5f (patch) | |
tree | c32dd0011f745d744bb202cdd1e29e899a9f40a5 /clang/lib/ExtractAPI/ExtractAPIConsumer.cpp | |
parent | ebc8466481f938d799d0170e0caf1c7e64f52c53 (diff) | |
download | llvm-f833aab0d0bf1bd9e9903a1398e429f431532f5f.zip llvm-f833aab0d0bf1bd9e9903a1398e429f431532f5f.tar.gz llvm-f833aab0d0bf1bd9e9903a1398e429f431532f5f.tar.bz2 |
[clang][extract-api] Enable processing of multiple headers
Before actually executing the ExtractAPIAction, clear the
CompilationInstance's input list and replace it with a single
synthesized file that just includes (or imports in ObjC) all the inputs.
Depends on D122141
Differential Revision: https://reviews.llvm.org/D122175
Diffstat (limited to 'clang/lib/ExtractAPI/ExtractAPIConsumer.cpp')
-rw-r--r-- | clang/lib/ExtractAPI/ExtractAPIConsumer.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp index 7007d08..0636e6d 100644 --- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -27,6 +27,9 @@ #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendOptions.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -339,6 +342,35 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::move(OS)); } +bool ExtractAPIAction::PrepareToExecuteAction(CompilerInstance &CI) { + auto &Inputs = CI.getFrontendOpts().Inputs; + if (Inputs.empty()) + return true; + + auto Kind = Inputs[0].getKind(); + + // Convert the header file inputs into a single input buffer. + SmallString<256> HeaderContents; + for (const FrontendInputFile &FIF : Inputs) { + if (Kind.isObjectiveC()) + HeaderContents += "#import"; + else + HeaderContents += "#include"; + HeaderContents += " \""; + HeaderContents += FIF.getFile(); + HeaderContents += "\"\n"; + } + + Buffer = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents, + getInputBufferName()); + + // Set that buffer up as our "real" input in the CompilerInstance. + Inputs.clear(); + Inputs.emplace_back(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false); + + return true; +} + std::unique_ptr<raw_pwrite_stream> ExtractAPIAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) { std::unique_ptr<raw_pwrite_stream> OS = |