|
27 | 27 | #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
|
28 | 28 | #include "clang/Frontend/ASTConsumers.h"
|
29 | 29 | #include "clang/Frontend/CompilerInstance.h"
|
| 30 | +#include "clang/Frontend/FrontendOptions.h" |
| 31 | +#include "llvm/ADT/SmallVector.h" |
| 32 | +#include "llvm/Support/MemoryBuffer.h" |
30 | 33 | #include "llvm/Support/raw_ostream.h"
|
31 | 34 |
|
32 | 35 | using namespace clang;
|
@@ -339,6 +342,35 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
339 | 342 | std::move(OS));
|
340 | 343 | }
|
341 | 344 |
|
| 345 | +bool ExtractAPIAction::PrepareToExecuteAction(CompilerInstance &CI) { |
| 346 | + auto &Inputs = CI.getFrontendOpts().Inputs; |
| 347 | + if (Inputs.empty()) |
| 348 | + return true; |
| 349 | + |
| 350 | + auto Kind = Inputs[0].getKind(); |
| 351 | + |
| 352 | + // Convert the header file inputs into a single input buffer. |
| 353 | + SmallString<256> HeaderContents; |
| 354 | + for (const FrontendInputFile &FIF : Inputs) { |
| 355 | + if (Kind.isObjectiveC()) |
| 356 | + HeaderContents += "#import"; |
| 357 | + else |
| 358 | + HeaderContents += "#include"; |
| 359 | + HeaderContents += " \""; |
| 360 | + HeaderContents += FIF.getFile(); |
| 361 | + HeaderContents += "\"\n"; |
| 362 | + } |
| 363 | + |
| 364 | + Buffer = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents, |
| 365 | + getInputBufferName()); |
| 366 | + |
| 367 | + // Set that buffer up as our "real" input in the CompilerInstance. |
| 368 | + Inputs.clear(); |
| 369 | + Inputs.emplace_back(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false); |
| 370 | + |
| 371 | + return true; |
| 372 | +} |
| 373 | + |
342 | 374 | std::unique_ptr<raw_pwrite_stream>
|
343 | 375 | ExtractAPIAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) {
|
344 | 376 | std::unique_ptr<raw_pwrite_stream> OS =
|
|
0 commit comments