| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/Lex/HeaderSearch.h" |
| 16 | #include "clang/Lex/Preprocessor.h" |
| 17 | #include "clang/Sema/SemaConsumer.h" |
| 18 | #include "clang/Serialization/ASTWriter.h" |
| 19 | #include "llvm/Bitcode/BitstreamWriter.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | |
| 23 | PCHGenerator::PCHGenerator( |
| 24 | const Preprocessor &PP, InMemoryModuleCache &ModuleCache, |
| 25 | StringRef OutputFile, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, |
| 26 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 27 | bool AllowASTWithErrors, bool IncludeTimestamps, |
| 28 | bool ShouldCacheASTInMemory) |
| 29 | : PP(PP), OutputFile(OutputFile), isysroot(isysroot.str()), |
| 30 | SemaPtr(nullptr), Buffer(std::move(Buffer)), Stream(this->Buffer->Data), |
| 31 | Writer(Stream, this->Buffer->Data, ModuleCache, Extensions, |
| 32 | IncludeTimestamps), |
| 33 | AllowASTWithErrors(AllowASTWithErrors), |
| 34 | ShouldCacheASTInMemory(ShouldCacheASTInMemory) { |
| 35 | this->Buffer->IsComplete = false; |
| 36 | } |
| 37 | |
| 38 | PCHGenerator::~PCHGenerator() { |
| 39 | } |
| 40 | |
| 41 | void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { |
| 42 | |
| 43 | if (PP.getModuleLoader().HadFatalFailure) |
| 44 | return; |
| 45 | |
| 46 | bool hasErrors = PP.getDiagnostics().hasErrorOccurred(); |
| 47 | if (hasErrors && !AllowASTWithErrors) |
| 48 | return; |
| 49 | |
| 50 | Module *Module = nullptr; |
| 51 | if (PP.getLangOpts().isCompilingModule()) { |
| 52 | Module = PP.getHeaderSearchInfo().lookupModule( |
| 53 | PP.getLangOpts().CurrentModule, false); |
| 54 | if (!Module) { |
| 55 | (0) . __assert_fail ("hasErrors && \"emitting module but current module doesn't exist\"", "/home/seafit/code_projects/clang_source/clang/lib/Serialization/GeneratePCH.cpp", 55, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(hasErrors && "emitting module but current module doesn't exist"); |
| 56 | return; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | (0) . __assert_fail ("SemaPtr && \"No Sema?\"", "/home/seafit/code_projects/clang_source/clang/lib/Serialization/GeneratePCH.cpp", 61, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SemaPtr && "No Sema?"); |
| 62 | Buffer->Signature = |
| 63 | Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, |
| 64 | |
| 65 | |
| 66 | PP.getDiagnostics().hasUncompilableErrorOccurred(), |
| 67 | ShouldCacheASTInMemory); |
| 68 | |
| 69 | Buffer->IsComplete = true; |
| 70 | } |
| 71 | |
| 72 | ASTMutationListener *PCHGenerator::GetASTMutationListener() { |
| 73 | return &Writer; |
| 74 | } |
| 75 | |
| 76 | ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() { |
| 77 | return &Writer; |
| 78 | } |
| 79 | |