@@ -5107,69 +5107,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
5107
5107
for (auto *D : SemaRef.DeclsToCheckForDeferredDiags )
5108
5108
DeclsToCheckForDeferredDiags.push_back (GetDeclRef (D));
5109
5109
5110
- {
5111
- auto Abv = std::make_shared<BitCodeAbbrev>();
5112
- Abv->Add (llvm::BitCodeAbbrevOp (UPDATE_VISIBLE));
5113
- Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::VBR, 6 ));
5114
- Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::Blob));
5115
- UpdateVisibleAbbrev = Stream.EmitAbbrev (std::move (Abv));
5116
- }
5117
-
5118
- RecordData DeclUpdatesOffsetsRecord;
5119
-
5120
- // Keep writing types, declarations, and declaration update records
5121
- // until we've emitted all of them.
5122
- Stream.EnterSubblock (DECLTYPES_BLOCK_ID, /* bits for abbreviations*/ 5 );
5123
- DeclTypesBlockStartOffset = Stream.GetCurrentBitNo ();
5124
- WriteTypeAbbrevs ();
5125
- WriteDeclAbbrevs ();
5126
- do {
5127
- WriteDeclUpdatesBlocks (DeclUpdatesOffsetsRecord);
5128
- while (!DeclTypesToEmit.empty ()) {
5129
- DeclOrType DOT = DeclTypesToEmit.front ();
5130
- DeclTypesToEmit.pop ();
5131
- if (DOT.isType ())
5132
- WriteType (DOT.getType ());
5133
- else
5134
- WriteDecl (Context, DOT.getDecl ());
5135
- }
5136
- } while (!DeclUpdates.empty ());
5137
- Stream.ExitBlock ();
5138
-
5139
- DoneWritingDeclsAndTypes = true ;
5140
-
5141
- // These things can only be done once we've written out decls and types.
5142
- WriteTypeDeclOffsets ();
5143
- if (!DeclUpdatesOffsetsRecord.empty ())
5144
- Stream.EmitRecord (DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
5145
-
5146
- // Create a lexical update block containing all of the declarations in the
5147
- // translation unit that do not come from other AST files.
5148
- {
5149
- SmallVector<uint32_t , 128 > NewGlobalKindDeclPairs;
5150
- for (const auto *D : TU->noload_decls ()) {
5151
- if (!D->isFromASTFile ()) {
5152
- NewGlobalKindDeclPairs.push_back (D->getKind ());
5153
- NewGlobalKindDeclPairs.push_back (GetDeclRef (D));
5154
- }
5155
- }
5156
-
5157
- auto Abv = std::make_shared<BitCodeAbbrev>();
5158
- Abv->Add (llvm::BitCodeAbbrevOp (TU_UPDATE_LEXICAL));
5159
- Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::Blob));
5160
- unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev (std::move (Abv));
5161
-
5162
- RecordData::value_type Record[] = {TU_UPDATE_LEXICAL};
5163
- Stream.EmitRecordWithBlob (TuUpdateLexicalAbbrev, Record,
5164
- bytes (NewGlobalKindDeclPairs));
5165
- }
5166
-
5167
- // And a visible updates block for the translation unit.
5168
- WriteDeclContextVisibleUpdate (TU);
5169
-
5170
- // If we have any extern "C" names, write out a visible update for them.
5171
- if (Context.ExternCContext )
5172
- WriteDeclContextVisibleUpdate (Context.ExternCContext );
5110
+ WriteDeclAndTypes (Context);
5173
5111
5174
5112
WriteFileDeclIDsMap ();
5175
5113
WriteSourceManagerBlock (Context.getSourceManager (), PP);
@@ -5255,10 +5193,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
5255
5193
if (!DeleteExprsToAnalyze.empty ())
5256
5194
Stream.EmitRecord (DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze);
5257
5195
5258
- // Write the visible updates to DeclContexts.
5259
- for (auto *DC : UpdatedDeclContexts)
5260
- WriteDeclContextVisibleUpdate (DC);
5261
-
5262
5196
if (!WritingModule) {
5263
5197
// Write the submodules that were imported, if any.
5264
5198
struct ModuleInfo {
@@ -5323,6 +5257,72 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
5323
5257
return backpatchSignature ();
5324
5258
}
5325
5259
5260
+ void ASTWriter::WriteDeclAndTypes (ASTContext &Context) {
5261
+ // Keep writing types, declarations, and declaration update records
5262
+ // until we've emitted all of them.
5263
+ RecordData DeclUpdatesOffsetsRecord;
5264
+ Stream.EnterSubblock (DECLTYPES_BLOCK_ID, /* bits for abbreviations*/ 5 );
5265
+ DeclTypesBlockStartOffset = Stream.GetCurrentBitNo ();
5266
+ WriteTypeAbbrevs ();
5267
+ WriteDeclAbbrevs ();
5268
+ do {
5269
+ WriteDeclUpdatesBlocks (DeclUpdatesOffsetsRecord);
5270
+ while (!DeclTypesToEmit.empty ()) {
5271
+ DeclOrType DOT = DeclTypesToEmit.front ();
5272
+ DeclTypesToEmit.pop ();
5273
+ if (DOT.isType ())
5274
+ WriteType (DOT.getType ());
5275
+ else
5276
+ WriteDecl (Context, DOT.getDecl ());
5277
+ }
5278
+ } while (!DeclUpdates.empty ());
5279
+ Stream.ExitBlock ();
5280
+
5281
+ DoneWritingDeclsAndTypes = true ;
5282
+
5283
+ // These things can only be done once we've written out decls and types.
5284
+ WriteTypeDeclOffsets ();
5285
+ if (!DeclUpdatesOffsetsRecord.empty ())
5286
+ Stream.EmitRecord (DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord);
5287
+
5288
+ const TranslationUnitDecl *TU = Context.getTranslationUnitDecl ();
5289
+ // Create a lexical update block containing all of the declarations in the
5290
+ // translation unit that do not come from other AST files.
5291
+ SmallVector<uint32_t , 128 > NewGlobalKindDeclPairs;
5292
+ for (const auto *D : TU->noload_decls ()) {
5293
+ if (!D->isFromASTFile ()) {
5294
+ NewGlobalKindDeclPairs.push_back (D->getKind ());
5295
+ NewGlobalKindDeclPairs.push_back (GetDeclRef (D));
5296
+ }
5297
+ }
5298
+
5299
+ auto Abv = std::make_shared<llvm::BitCodeAbbrev>();
5300
+ Abv->Add (llvm::BitCodeAbbrevOp (TU_UPDATE_LEXICAL));
5301
+ Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::Blob));
5302
+ unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev (std::move (Abv));
5303
+
5304
+ RecordData::value_type Record[] = {TU_UPDATE_LEXICAL};
5305
+ Stream.EmitRecordWithBlob (TuUpdateLexicalAbbrev, Record,
5306
+ bytes (NewGlobalKindDeclPairs));
5307
+
5308
+ Abv = std::make_shared<llvm::BitCodeAbbrev>();
5309
+ Abv->Add (llvm::BitCodeAbbrevOp (UPDATE_VISIBLE));
5310
+ Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::VBR, 6 ));
5311
+ Abv->Add (llvm::BitCodeAbbrevOp (llvm::BitCodeAbbrevOp::Blob));
5312
+ UpdateVisibleAbbrev = Stream.EmitAbbrev (std::move (Abv));
5313
+
5314
+ // And a visible updates block for the translation unit.
5315
+ WriteDeclContextVisibleUpdate (TU);
5316
+
5317
+ // If we have any extern "C" names, write out a visible update for them.
5318
+ if (Context.ExternCContext )
5319
+ WriteDeclContextVisibleUpdate (Context.ExternCContext );
5320
+
5321
+ // Write the visible updates to DeclContexts.
5322
+ for (auto *DC : UpdatedDeclContexts)
5323
+ WriteDeclContextVisibleUpdate (DC);
5324
+ }
5325
+
5326
5326
void ASTWriter::WriteDeclUpdatesBlocks (RecordDataImpl &OffsetsRecord) {
5327
5327
if (DeclUpdates.empty ())
5328
5328
return ;
0 commit comments