1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H |
14 | #define LLVM_CLANG_SERIALIZATION_ASTREADER_H |
15 | |
16 | #include "clang/AST/DeclCXX.h" |
17 | #include "clang/AST/DeclObjC.h" |
18 | #include "clang/AST/DeclarationName.h" |
19 | #include "clang/AST/NestedNameSpecifier.h" |
20 | #include "clang/AST/OpenMPClause.h" |
21 | #include "clang/AST/TemplateBase.h" |
22 | #include "clang/AST/TemplateName.h" |
23 | #include "clang/AST/Type.h" |
24 | #include "clang/Basic/Diagnostic.h" |
25 | #include "clang/Basic/DiagnosticOptions.h" |
26 | #include "clang/Basic/IdentifierTable.h" |
27 | #include "clang/Basic/Module.h" |
28 | #include "clang/Basic/OpenCLOptions.h" |
29 | #include "clang/Basic/SourceLocation.h" |
30 | #include "clang/Basic/Version.h" |
31 | #include "clang/Lex/ExternalPreprocessorSource.h" |
32 | #include "clang/Lex/HeaderSearch.h" |
33 | #include "clang/Lex/PreprocessingRecord.h" |
34 | #include "clang/Lex/Token.h" |
35 | #include "clang/Sema/ExternalSemaSource.h" |
36 | #include "clang/Sema/IdentifierResolver.h" |
37 | #include "clang/Serialization/ASTBitCodes.h" |
38 | #include "clang/Serialization/ContinuousRangeMap.h" |
39 | #include "clang/Serialization/Module.h" |
40 | #include "clang/Serialization/ModuleFileExtension.h" |
41 | #include "clang/Serialization/ModuleManager.h" |
42 | #include "llvm/ADT/APFloat.h" |
43 | #include "llvm/ADT/APInt.h" |
44 | #include "llvm/ADT/APSInt.h" |
45 | #include "llvm/ADT/ArrayRef.h" |
46 | #include "llvm/ADT/DenseMap.h" |
47 | #include "llvm/ADT/DenseSet.h" |
48 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
49 | #include "llvm/ADT/MapVector.h" |
50 | #include "llvm/ADT/Optional.h" |
51 | #include "llvm/ADT/STLExtras.h" |
52 | #include "llvm/ADT/SetVector.h" |
53 | #include "llvm/ADT/SmallPtrSet.h" |
54 | #include "llvm/ADT/SmallVector.h" |
55 | #include "llvm/ADT/StringMap.h" |
56 | #include "llvm/ADT/StringRef.h" |
57 | #include "llvm/ADT/iterator.h" |
58 | #include "llvm/ADT/iterator_range.h" |
59 | #include "llvm/Bitcode/BitstreamReader.h" |
60 | #include "llvm/Support/Casting.h" |
61 | #include "llvm/Support/Endian.h" |
62 | #include "llvm/Support/MemoryBuffer.h" |
63 | #include "llvm/Support/Timer.h" |
64 | #include "llvm/Support/VersionTuple.h" |
65 | #include <cassert> |
66 | #include <cstddef> |
67 | #include <cstdint> |
68 | #include <ctime> |
69 | #include <deque> |
70 | #include <memory> |
71 | #include <set> |
72 | #include <string> |
73 | #include <utility> |
74 | #include <vector> |
75 | |
76 | namespace clang { |
77 | |
78 | class ASTConsumer; |
79 | class ASTContext; |
80 | class ASTDeserializationListener; |
81 | class ASTReader; |
82 | class ASTRecordReader; |
83 | class CXXTemporary; |
84 | class Decl; |
85 | class DeclaratorDecl; |
86 | class DeclContext; |
87 | class EnumDecl; |
88 | class Expr; |
89 | class FieldDecl; |
90 | class FileEntry; |
91 | class FileManager; |
92 | class FileSystemOptions; |
93 | class FunctionDecl; |
94 | class GlobalModuleIndex; |
95 | struct ; |
96 | class ; |
97 | class LangOptions; |
98 | class LazyASTUnresolvedSet; |
99 | class MacroInfo; |
100 | class InMemoryModuleCache; |
101 | class NamedDecl; |
102 | class NamespaceDecl; |
103 | class ObjCCategoryDecl; |
104 | class ObjCInterfaceDecl; |
105 | class PCHContainerReader; |
106 | class Preprocessor; |
107 | class PreprocessorOptions; |
108 | struct QualifierInfo; |
109 | class Sema; |
110 | class SourceManager; |
111 | class Stmt; |
112 | class SwitchCase; |
113 | class TargetOptions; |
114 | class TemplateParameterList; |
115 | class TypedefNameDecl; |
116 | class TypeSourceInfo; |
117 | class ValueDecl; |
118 | class VarDecl; |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | class ASTReaderListener { |
127 | public: |
128 | virtual ~ASTReaderListener(); |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | virtual bool ReadFullVersionInformation(StringRef FullVersion) { |
135 | return FullVersion != getClangFullRepositoryVersion(); |
136 | } |
137 | |
138 | virtual void ReadModuleName(StringRef ModuleName) {} |
139 | virtual void ReadModuleMapFile(StringRef ModuleMapPath) {} |
140 | |
141 | |
142 | |
143 | |
144 | virtual bool ReadLanguageOptions(const LangOptions &LangOpts, |
145 | bool Complain, |
146 | bool AllowCompatibleDifferences) { |
147 | return false; |
148 | } |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
155 | bool AllowCompatibleDifferences) { |
156 | return false; |
157 | } |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | virtual bool |
164 | ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, |
165 | bool Complain) { |
166 | return false; |
167 | } |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
174 | bool Complain) { |
175 | return false; |
176 | } |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | virtual bool (const HeaderSearchOptions &HSOpts, |
183 | StringRef SpecificModuleCachePath, |
184 | bool Complain) { |
185 | return false; |
186 | } |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
197 | bool Complain, |
198 | std::string &SuggestedPredefines) { |
199 | return false; |
200 | } |
201 | |
202 | |
203 | virtual void ReadCounter(const serialization::ModuleFile &M, |
204 | unsigned Value) {} |
205 | |
206 | |
207 | virtual void visitModuleFile(StringRef Filename, |
208 | serialization::ModuleKind Kind) {} |
209 | |
210 | |
211 | |
212 | virtual bool needsInputFileVisitation() { return false; } |
213 | |
214 | |
215 | |
216 | virtual bool needsSystemInputFileVisitation() { return false; } |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | virtual bool visitInputFile(StringRef Filename, bool isSystem, |
225 | bool isOverridden, bool isExplicitModule) { |
226 | return true; |
227 | } |
228 | |
229 | |
230 | |
231 | virtual bool needsImportVisitation() const { return false; } |
232 | |
233 | |
234 | |
235 | virtual void visitImport(StringRef ModuleName, StringRef Filename) {} |
236 | |
237 | |
238 | virtual void readModuleFileExtension( |
239 | const ModuleFileExtensionMetadata &Metadata) {} |
240 | }; |
241 | |
242 | |
243 | class ChainedASTReaderListener : public ASTReaderListener { |
244 | std::unique_ptr<ASTReaderListener> First; |
245 | std::unique_ptr<ASTReaderListener> Second; |
246 | |
247 | public: |
248 | |
249 | ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First, |
250 | std::unique_ptr<ASTReaderListener> Second) |
251 | : First(std::move(First)), Second(std::move(Second)) {} |
252 | |
253 | std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); } |
254 | std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); } |
255 | |
256 | bool ReadFullVersionInformation(StringRef FullVersion) override; |
257 | void ReadModuleName(StringRef ModuleName) override; |
258 | void ReadModuleMapFile(StringRef ModuleMapPath) override; |
259 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
260 | bool AllowCompatibleDifferences) override; |
261 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
262 | bool AllowCompatibleDifferences) override; |
263 | bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, |
264 | bool Complain) override; |
265 | bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
266 | bool Complain) override; |
267 | |
268 | bool (const HeaderSearchOptions &HSOpts, |
269 | StringRef SpecificModuleCachePath, |
270 | bool Complain) override; |
271 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
272 | bool Complain, |
273 | std::string &SuggestedPredefines) override; |
274 | |
275 | void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; |
276 | bool needsInputFileVisitation() override; |
277 | bool needsSystemInputFileVisitation() override; |
278 | void visitModuleFile(StringRef Filename, |
279 | serialization::ModuleKind Kind) override; |
280 | bool visitInputFile(StringRef Filename, bool isSystem, |
281 | bool isOverridden, bool isExplicitModule) override; |
282 | void readModuleFileExtension( |
283 | const ModuleFileExtensionMetadata &Metadata) override; |
284 | }; |
285 | |
286 | |
287 | |
288 | class PCHValidator : public ASTReaderListener { |
289 | Preprocessor &PP; |
290 | ASTReader &Reader; |
291 | |
292 | public: |
293 | PCHValidator(Preprocessor &PP, ASTReader &Reader) |
294 | : PP(PP), Reader(Reader) {} |
295 | |
296 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
297 | bool AllowCompatibleDifferences) override; |
298 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
299 | bool AllowCompatibleDifferences) override; |
300 | bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, |
301 | bool Complain) override; |
302 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, |
303 | std::string &SuggestedPredefines) override; |
304 | bool (const HeaderSearchOptions &HSOpts, |
305 | StringRef SpecificModuleCachePath, |
306 | bool Complain) override; |
307 | void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override; |
308 | |
309 | private: |
310 | void Error(const char *Msg); |
311 | }; |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | class SimpleASTReaderListener : public ASTReaderListener { |
318 | Preprocessor &PP; |
319 | |
320 | public: |
321 | SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {} |
322 | |
323 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, |
324 | std::string &SuggestedPredefines) override; |
325 | }; |
326 | |
327 | namespace serialization { |
328 | |
329 | class ReadMethodPoolVisitor; |
330 | |
331 | namespace reader { |
332 | |
333 | class ASTIdentifierLookupTrait; |
334 | |
335 | |
336 | struct DeclContextLookupTable; |
337 | |
338 | } |
339 | |
340 | } |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |
353 | |
354 | class ASTReader |
355 | : public ExternalPreprocessorSource, |
356 | public ExternalPreprocessingRecordSource, |
357 | public ExternalHeaderFileInfoSource, |
358 | public ExternalSemaSource, |
359 | public IdentifierInfoLookup, |
360 | public ExternalSLocEntrySource |
361 | { |
362 | public: |
363 | |
364 | friend class ASTDeclReader; |
365 | friend class ASTIdentifierIterator; |
366 | friend class ASTRecordReader; |
367 | friend class ASTStmtReader; |
368 | friend class ASTUnit; |
369 | friend class ASTWriter; |
370 | friend class PCHValidator; |
371 | friend class serialization::reader::ASTIdentifierLookupTrait; |
372 | friend class serialization::ReadMethodPoolVisitor; |
373 | friend class TypeLocReader; |
374 | |
375 | using RecordData = SmallVector<uint64_t, 64>; |
376 | using RecordDataImpl = SmallVectorImpl<uint64_t>; |
377 | |
378 | |
379 | |
380 | enum ASTReadResult { |
381 | |
382 | |
383 | Success, |
384 | |
385 | |
386 | Failure, |
387 | |
388 | |
389 | Missing, |
390 | |
391 | |
392 | |
393 | OutOfDate, |
394 | |
395 | |
396 | VersionMismatch, |
397 | |
398 | |
399 | |
400 | ConfigurationMismatch, |
401 | |
402 | |
403 | HadErrors |
404 | }; |
405 | |
406 | using ModuleFile = serialization::ModuleFile; |
407 | using ModuleKind = serialization::ModuleKind; |
408 | using ModuleManager = serialization::ModuleManager; |
409 | using ModuleIterator = ModuleManager::ModuleIterator; |
410 | using ModuleConstIterator = ModuleManager::ModuleConstIterator; |
411 | using ModuleReverseIterator = ModuleManager::ModuleReverseIterator; |
412 | |
413 | private: |
414 | |
415 | std::unique_ptr<ASTReaderListener> Listener; |
416 | |
417 | |
418 | ASTDeserializationListener *DeserializationListener = nullptr; |
419 | |
420 | bool OwnsDeserializationListener = false; |
421 | |
422 | SourceManager &SourceMgr; |
423 | FileManager &FileMgr; |
424 | const PCHContainerReader &PCHContainerRdr; |
425 | DiagnosticsEngine &Diags; |
426 | |
427 | |
428 | |
429 | Sema *SemaObj = nullptr; |
430 | |
431 | |
432 | Preprocessor &PP; |
433 | |
434 | |
435 | ASTContext *ContextObj = nullptr; |
436 | |
437 | |
438 | ASTConsumer *Consumer = nullptr; |
439 | |
440 | |
441 | ModuleManager ModuleMgr; |
442 | |
443 | |
444 | |
445 | |
446 | IdentifierResolver DummyIdResolver; |
447 | |
448 | |
449 | llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions; |
450 | |
451 | |
452 | std::unique_ptr<llvm::Timer> ReadTimer; |
453 | |
454 | |
455 | |
456 | SourceLocation CurrentImportLoc; |
457 | |
458 | |
459 | std::unique_ptr<GlobalModuleIndex> GlobalIndex; |
460 | |
461 | |
462 | |
463 | ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap; |
464 | |
465 | |
466 | ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap; |
467 | |
468 | using GlobalSLocOffsetMapType = |
469 | ContinuousRangeMap<unsigned, ModuleFile *, 64>; |
470 | |
471 | |
472 | |
473 | GlobalSLocOffsetMapType GlobalSLocOffsetMap; |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | std::vector<QualType> TypesLoaded; |
480 | |
481 | using GlobalTypeMapType = |
482 | ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>; |
483 | |
484 | |
485 | |
486 | |
487 | GlobalTypeMapType GlobalTypeMap; |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | std::vector<Decl *> DeclsLoaded; |
494 | |
495 | using GlobalDeclMapType = |
496 | ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>; |
497 | |
498 | |
499 | |
500 | GlobalDeclMapType GlobalDeclMap; |
501 | |
502 | using FileOffset = std::pair<ModuleFile *, uint64_t>; |
503 | using FileOffsetsTy = SmallVector<FileOffset, 2>; |
504 | using DeclUpdateOffsetsMap = |
505 | llvm::DenseMap<serialization::DeclID, FileOffsetsTy>; |
506 | |
507 | |
508 | |
509 | DeclUpdateOffsetsMap DeclUpdateOffsets; |
510 | |
511 | struct PendingUpdateRecord { |
512 | Decl *D; |
513 | serialization::GlobalDeclID ID; |
514 | |
515 | |
516 | bool JustLoaded; |
517 | |
518 | PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D, |
519 | bool JustLoaded) |
520 | : D(D), ID(ID), JustLoaded(JustLoaded) {} |
521 | }; |
522 | |
523 | |
524 | |
525 | llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords; |
526 | |
527 | enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded }; |
528 | |
529 | |
530 | |
531 | llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData; |
532 | |
533 | |
534 | |
535 | |
536 | |
537 | llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates; |
538 | |
539 | |
540 | |
541 | |
542 | llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates; |
543 | |
544 | |
545 | |
546 | llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *> |
547 | ImportedTypedefNamesForLinkage; |
548 | |
549 | |
550 | |
551 | llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>> |
552 | AnonymousDeclarationsForMerging; |
553 | |
554 | struct FileDeclsInfo { |
555 | ModuleFile *Mod = nullptr; |
556 | ArrayRef<serialization::LocalDeclID> Decls; |
557 | |
558 | FileDeclsInfo() = default; |
559 | FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls) |
560 | : Mod(Mod), Decls(Decls) {} |
561 | }; |
562 | |
563 | |
564 | llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs; |
565 | |
566 | |
567 | |
568 | using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>; |
569 | |
570 | |
571 | llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>> |
572 | LexicalDecls; |
573 | |
574 | |
575 | std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls; |
576 | |
577 | |
578 | llvm::DenseMap<const DeclContext *, |
579 | serialization::reader::DeclContextLookupTable> Lookups; |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | struct PendingVisibleUpdate { |
586 | ModuleFile *Mod; |
587 | const unsigned char *Data; |
588 | }; |
589 | using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>; |
590 | |
591 | |
592 | |
593 | llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates> |
594 | PendingVisibleUpdates; |
595 | |
596 | |
597 | |
598 | llvm::SmallPtrSet<Decl *, 4> PendingDefinitions; |
599 | |
600 | using PendingBodiesMap = |
601 | llvm::MapVector<Decl *, uint64_t, |
602 | llvm::SmallDenseMap<Decl *, unsigned, 4>, |
603 | SmallVector<std::pair<Decl *, uint64_t>, 4>>; |
604 | |
605 | |
606 | PendingBodiesMap PendingBodies; |
607 | |
608 | |
609 | |
610 | llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate; |
611 | |
612 | |
613 | bool ReadLexicalDeclContextStorage(ModuleFile &M, |
614 | llvm::BitstreamCursor &Cursor, |
615 | uint64_t Offset, DeclContext *DC); |
616 | |
617 | |
618 | bool ReadVisibleDeclContextStorage(ModuleFile &M, |
619 | llvm::BitstreamCursor &Cursor, |
620 | uint64_t Offset, serialization::DeclID ID); |
621 | |
622 | |
623 | |
624 | |
625 | |
626 | |
627 | |
628 | std::vector<IdentifierInfo *> IdentifiersLoaded; |
629 | |
630 | using GlobalIdentifierMapType = |
631 | ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>; |
632 | |
633 | |
634 | |
635 | |
636 | GlobalIdentifierMapType GlobalIdentifierMap; |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | |
644 | std::vector<MacroInfo *> MacrosLoaded; |
645 | |
646 | using LoadedMacroInfo = |
647 | std::pair<IdentifierInfo *, serialization::SubmoduleID>; |
648 | |
649 | |
650 | |
651 | |
652 | llvm::DenseSet<LoadedMacroInfo> LoadedUndefs; |
653 | |
654 | using GlobalMacroMapType = |
655 | ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>; |
656 | |
657 | |
658 | |
659 | |
660 | GlobalMacroMapType GlobalMacroMap; |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | SmallVector<Module *, 2> SubmodulesLoaded; |
667 | |
668 | using GlobalSubmoduleMapType = |
669 | ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>; |
670 | |
671 | |
672 | |
673 | |
674 | GlobalSubmoduleMapType GlobalSubmoduleMap; |
675 | |
676 | |
677 | using HiddenNames = SmallVector<Decl *, 2>; |
678 | using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>; |
679 | |
680 | |
681 | |
682 | HiddenNamesMapType HiddenNamesMap; |
683 | |
684 | |
685 | struct UnresolvedModuleRef { |
686 | |
687 | ModuleFile *File; |
688 | |
689 | |
690 | Module *Mod; |
691 | |
692 | |
693 | enum { Import, Export, Conflict } Kind; |
694 | |
695 | |
696 | unsigned ID; |
697 | |
698 | |
699 | unsigned IsWildcard : 1; |
700 | |
701 | |
702 | StringRef String; |
703 | }; |
704 | |
705 | |
706 | |
707 | SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs; |
708 | |
709 | |
710 | |
711 | |
712 | |
713 | |
714 | SmallVector<Selector, 16> SelectorsLoaded; |
715 | |
716 | using GlobalSelectorMapType = |
717 | ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>; |
718 | |
719 | |
720 | |
721 | GlobalSelectorMapType GlobalSelectorMap; |
722 | |
723 | |
724 | |
725 | llvm::DenseMap<Selector, unsigned> SelectorGeneration; |
726 | |
727 | |
728 | |
729 | llvm::DenseMap<Selector, bool> SelectorOutOfDate; |
730 | |
731 | struct PendingMacroInfo { |
732 | ModuleFile *M; |
733 | uint64_t MacroDirectivesOffset; |
734 | |
735 | PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset) |
736 | : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {} |
737 | }; |
738 | |
739 | using PendingMacroIDsMap = |
740 | llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>; |
741 | |
742 | |
743 | |
744 | PendingMacroIDsMap PendingMacroIDs; |
745 | |
746 | using GlobalPreprocessedEntityMapType = |
747 | ContinuousRangeMap<unsigned, ModuleFile *, 4>; |
748 | |
749 | |
750 | |
751 | |
752 | GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap; |
753 | |
754 | using GlobalSkippedRangeMapType = |
755 | ContinuousRangeMap<unsigned, ModuleFile *, 4>; |
756 | |
757 | |
758 | |
759 | GlobalSkippedRangeMapType GlobalSkippedRangeMap; |
760 | |
761 | |
762 | |
763 | |
764 | |
765 | |
766 | |
767 | |
768 | |
769 | |
770 | |
771 | SmallVector<uint64_t, 16> EagerlyDeserializedDecls; |
772 | |
773 | |
774 | |
775 | |
776 | |
777 | |
778 | SmallVector<uint64_t, 16> TentativeDefinitions; |
779 | |
780 | |
781 | |
782 | |
783 | |
784 | |
785 | SmallVector<uint64_t, 64> VTableUses; |
786 | |
787 | |
788 | |
789 | |
790 | |
791 | |
792 | |
793 | SmallVector<uint64_t, 64> PendingInstantiations; |
794 | |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | SmallVector<uint64_t, 16> UnusedFileScopedDecls; |
804 | |
805 | |
806 | |
807 | SmallVector<uint64_t, 4> DelegatingCtorDecls; |
808 | |
809 | |
810 | |
811 | SmallVector<uint64_t, 64> ReferencedSelectorsData; |
812 | |
813 | |
814 | |
815 | SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers; |
816 | |
817 | |
818 | |
819 | |
820 | SmallVector<uint64_t, 4> ExtVectorDecls; |
821 | |
822 | |
823 | |
824 | |
825 | |
826 | |
827 | |
828 | |
829 | |
830 | |
831 | SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates; |
832 | |
833 | |
834 | |
835 | unsigned ForceCUDAHostDeviceDepth = 0; |
836 | |
837 | |
838 | |
839 | |
840 | SmallVector<uint64_t, 4> SemaDeclRefs; |
841 | |
842 | |
843 | |
844 | |
845 | SmallVector<uint64_t, 16> SpecialTypes; |
846 | |
847 | |
848 | |
849 | |
850 | |
851 | SmallVector<uint64_t, 2> CUDASpecialDeclRefs; |
852 | |
853 | |
854 | SmallVector<uint64_t, 1> FPPragmaOptions; |
855 | |
856 | |
857 | SourceLocation OptimizeOffPragmaLocation; |
858 | |
859 | |
860 | int PragmaMSStructState = -1; |
861 | |
862 | |
863 | int = -1; |
864 | SourceLocation PointersToMembersPragmaLocation; |
865 | |
866 | |
867 | Optional<unsigned> PragmaPackCurrentValue; |
868 | SourceLocation PragmaPackCurrentLocation; |
869 | struct PragmaPackStackEntry { |
870 | unsigned Value; |
871 | SourceLocation Location; |
872 | SourceLocation PushLocation; |
873 | StringRef SlotLabel; |
874 | }; |
875 | llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack; |
876 | llvm::SmallVector<std::string, 2> PragmaPackStrings; |
877 | |
878 | |
879 | OpenCLOptions OpenCLExtensions; |
880 | |
881 | |
882 | llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap; |
883 | |
884 | |
885 | llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap; |
886 | |
887 | |
888 | SmallVector<uint64_t, 4> KnownNamespaces; |
889 | |
890 | |
891 | |
892 | SmallVector<uint64_t, 8> UndefinedButUsed; |
893 | |
894 | |
895 | SmallVector<uint64_t, 8> DelayedDeleteExprs; |
896 | |
897 | |
898 | SmallVector<uint64_t, 1> LateParsedTemplates; |
899 | |
900 | public: |
901 | struct ImportedSubmodule { |
902 | serialization::SubmoduleID ID; |
903 | SourceLocation ImportLoc; |
904 | |
905 | ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc) |
906 | : ID(ID), ImportLoc(ImportLoc) {} |
907 | }; |
908 | |
909 | private: |
910 | |
911 | |
912 | SmallVector<ImportedSubmodule, 2> ImportedModules; |
913 | |
914 | |
915 | |
916 | |
917 | std::string isysroot; |
918 | |
919 | |
920 | |
921 | bool DisableValidation; |
922 | |
923 | |
924 | bool AllowASTWithCompilerErrors; |
925 | |
926 | |
927 | |
928 | bool AllowConfigurationMismatch; |
929 | |
930 | |
931 | bool ValidateSystemInputs; |
932 | |
933 | |
934 | bool UseGlobalIndex; |
935 | |
936 | |
937 | bool TriedLoadingGlobalIndex = false; |
938 | |
939 | |
940 | bool ProcessingUpdateRecords = false; |
941 | |
942 | using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>; |
943 | |
944 | |
945 | |
946 | |
947 | |
948 | SwitchCaseMapTy SwitchCaseStmts; |
949 | |
950 | SwitchCaseMapTy *CurrSwitchCaseStmts; |
951 | |
952 | |
953 | |
954 | unsigned NumSLocEntriesRead = 0; |
955 | |
956 | |
957 | unsigned TotalNumSLocEntries = 0; |
958 | |
959 | |
960 | |
961 | unsigned NumStatementsRead = 0; |
962 | |
963 | |
964 | |
965 | unsigned TotalNumStatements = 0; |
966 | |
967 | |
968 | unsigned NumMacrosRead = 0; |
969 | |
970 | |
971 | unsigned TotalNumMacros = 0; |
972 | |
973 | |
974 | unsigned NumIdentifierLookups = 0; |
975 | |
976 | |
977 | unsigned NumIdentifierLookupHits = 0; |
978 | |
979 | |
980 | unsigned NumSelectorsRead = 0; |
981 | |
982 | |
983 | unsigned NumMethodPoolEntriesRead = 0; |
984 | |
985 | |
986 | |
987 | unsigned NumMethodPoolLookups = 0; |
988 | |
989 | |
990 | |
991 | unsigned NumMethodPoolHits = 0; |
992 | |
993 | |
994 | |
995 | unsigned NumMethodPoolTableLookups = 0; |
996 | |
997 | |
998 | |
999 | unsigned NumMethodPoolTableHits = 0; |
1000 | |
1001 | |
1002 | unsigned TotalNumMethodPoolEntries = 0; |
1003 | |
1004 | |
1005 | unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0; |
1006 | |
1007 | |
1008 | unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0; |
1009 | |
1010 | |
1011 | uint64_t TotalModulesSizeInBits = 0; |
1012 | |
1013 | |
1014 | unsigned NumCurrentElementsDeserializing = 0; |
1015 | |
1016 | |
1017 | |
1018 | |
1019 | |
1020 | bool PassingDeclsToConsumer = false; |
1021 | |
1022 | |
1023 | |
1024 | |
1025 | |
1026 | |
1027 | llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>> |
1028 | PendingIdentifierInfos; |
1029 | |
1030 | |
1031 | |
1032 | llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16> |
1033 | PendingFakeLookupResults; |
1034 | |
1035 | |
1036 | |
1037 | llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration; |
1038 | |
1039 | class InterestingDecl { |
1040 | Decl *D; |
1041 | bool DeclHasPendingBody; |
1042 | |
1043 | public: |
1044 | InterestingDecl(Decl *D, bool HasBody) |
1045 | : D(D), DeclHasPendingBody(HasBody) {} |
1046 | |
1047 | Decl *getDecl() { return D; } |
1048 | |
1049 | |
1050 | bool hasPendingBody() { return DeclHasPendingBody; } |
1051 | }; |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | |
1057 | |
1058 | |
1059 | std::deque<InterestingDecl> PotentiallyInterestingDecls; |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16> |
1065 | PendingFunctionTypes; |
1066 | |
1067 | |
1068 | |
1069 | |
1070 | SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains; |
1071 | |
1072 | |
1073 | |
1074 | SmallVector<Decl *, 16> PendingIncompleteDeclChains; |
1075 | |
1076 | |
1077 | |
1078 | struct PendingDeclContextInfo { |
1079 | Decl *D; |
1080 | serialization::GlobalDeclID SemaDC; |
1081 | serialization::GlobalDeclID LexicalDC; |
1082 | }; |
1083 | |
1084 | |
1085 | |
1086 | |
1087 | |
1088 | |
1089 | std::deque<PendingDeclContextInfo> PendingDeclContextInfos; |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks; |
1098 | |
1099 | using DataPointers = |
1100 | std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>; |
1101 | |
1102 | |
1103 | llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2> |
1104 | PendingOdrMergeFailures; |
1105 | |
1106 | |
1107 | llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2> |
1108 | PendingFunctionOdrMergeFailures; |
1109 | |
1110 | |
1111 | llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2> |
1112 | PendingEnumOdrMergeFailures; |
1113 | |
1114 | |
1115 | llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures; |
1116 | |
1117 | |
1118 | |
1119 | llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized; |
1120 | |
1121 | |
1122 | |
1123 | |
1124 | SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded; |
1125 | |
1126 | using KeyDeclsMap = |
1127 | llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>; |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | |
1134 | KeyDeclsMap KeyDecls; |
1135 | |
1136 | |
1137 | |
1138 | |
1139 | llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts; |
1140 | |
1141 | |
1142 | |
1143 | llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions; |
1144 | |
1145 | |
1146 | SmallVector<Stmt *, 16> StmtStack; |
1147 | |
1148 | |
1149 | enum ReadingKind { |
1150 | Read_None, Read_Decl, Read_Type, Read_Stmt |
1151 | }; |
1152 | |
1153 | |
1154 | ReadingKind ReadingKind = Read_None; |
1155 | |
1156 | |
1157 | class ReadingKindTracker { |
1158 | ASTReader &Reader; |
1159 | enum ReadingKind PrevKind; |
1160 | |
1161 | public: |
1162 | ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader) |
1163 | : Reader(reader), PrevKind(Reader.ReadingKind) { |
1164 | Reader.ReadingKind = newKind; |
1165 | } |
1166 | |
1167 | ReadingKindTracker(const ReadingKindTracker &) = delete; |
1168 | ReadingKindTracker &operator=(const ReadingKindTracker &) = delete; |
1169 | ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; } |
1170 | }; |
1171 | |
1172 | |
1173 | class ProcessingUpdatesRAIIObj { |
1174 | ASTReader &Reader; |
1175 | bool PrevState; |
1176 | |
1177 | public: |
1178 | ProcessingUpdatesRAIIObj(ASTReader &reader) |
1179 | : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) { |
1180 | Reader.ProcessingUpdateRecords = true; |
1181 | } |
1182 | |
1183 | ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete; |
1184 | ProcessingUpdatesRAIIObj & |
1185 | operator=(const ProcessingUpdatesRAIIObj &) = delete; |
1186 | ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; } |
1187 | }; |
1188 | |
1189 | |
1190 | |
1191 | |
1192 | |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | std::string SuggestedPredefines; |
1198 | |
1199 | llvm::DenseMap<const Decl *, bool> DefinitionSource; |
1200 | |
1201 | |
1202 | Stmt *ReadStmtFromStream(ModuleFile &F); |
1203 | |
1204 | struct InputFileInfo { |
1205 | std::string Filename; |
1206 | off_t StoredSize; |
1207 | time_t StoredTime; |
1208 | bool Overridden; |
1209 | bool Transient; |
1210 | bool TopLevelModuleMap; |
1211 | }; |
1212 | |
1213 | |
1214 | InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID); |
1215 | |
1216 | |
1217 | |
1218 | serialization::InputFile getInputFile(ModuleFile &F, unsigned ID, |
1219 | bool Complain = true); |
1220 | |
1221 | public: |
1222 | void ResolveImportedPath(ModuleFile &M, std::string &Filename); |
1223 | static void ResolveImportedPath(std::string &Filename, StringRef Prefix); |
1224 | |
1225 | |
1226 | |
1227 | |
1228 | Decl *getKeyDeclaration(Decl *D) { |
1229 | D = D->getCanonicalDecl(); |
1230 | if (D->isFromASTFile()) |
1231 | return D; |
1232 | |
1233 | auto I = KeyDecls.find(D); |
1234 | if (I == KeyDecls.end() || I->second.empty()) |
1235 | return D; |
1236 | return GetExistingDecl(I->second[0]); |
1237 | } |
1238 | const Decl *getKeyDeclaration(const Decl *D) { |
1239 | return getKeyDeclaration(const_cast<Decl*>(D)); |
1240 | } |
1241 | |
1242 | |
1243 | template <typename Fn> |
1244 | void forEachImportedKeyDecl(const Decl *D, Fn Visit) { |
1245 | D = D->getCanonicalDecl(); |
1246 | if (D->isFromASTFile()) |
1247 | Visit(D); |
1248 | |
1249 | auto It = KeyDecls.find(const_cast<Decl*>(D)); |
1250 | if (It != KeyDecls.end()) |
1251 | for (auto ID : It->second) |
1252 | Visit(GetExistingDecl(ID)); |
1253 | } |
1254 | |
1255 | |
1256 | const serialization::reader::DeclContextLookupTable * |
1257 | getLoadedLookupTables(DeclContext *Primary) const; |
1258 | |
1259 | private: |
1260 | struct ImportedModule { |
1261 | ModuleFile *Mod; |
1262 | ModuleFile *ImportedBy; |
1263 | SourceLocation ImportLoc; |
1264 | |
1265 | ImportedModule(ModuleFile *Mod, |
1266 | ModuleFile *ImportedBy, |
1267 | SourceLocation ImportLoc) |
1268 | : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {} |
1269 | }; |
1270 | |
1271 | ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, |
1272 | SourceLocation ImportLoc, ModuleFile *ImportedBy, |
1273 | SmallVectorImpl<ImportedModule> &Loaded, |
1274 | off_t ExpectedSize, time_t ExpectedModTime, |
1275 | ASTFileSignature ExpectedSignature, |
1276 | unsigned ClientLoadCapabilities); |
1277 | ASTReadResult ReadControlBlock(ModuleFile &F, |
1278 | SmallVectorImpl<ImportedModule> &Loaded, |
1279 | const ModuleFile *ImportedBy, |
1280 | unsigned ClientLoadCapabilities); |
1281 | static ASTReadResult ReadOptionsBlock( |
1282 | llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
1283 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
1284 | std::string &SuggestedPredefines); |
1285 | |
1286 | |
1287 | |
1288 | |
1289 | |
1290 | ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
1291 | unsigned ClientLoadCapabilities); |
1292 | |
1293 | static ASTReadResult |
1294 | readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData, |
1295 | unsigned ClientLoadCapabilities, |
1296 | bool AllowCompatibleConfigurationMismatch, |
1297 | ASTReaderListener *Listener, |
1298 | bool ValidateDiagnosticOptions); |
1299 | |
1300 | ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); |
1301 | ASTReadResult ReadExtensionBlock(ModuleFile &F); |
1302 | void ReadModuleOffsetMap(ModuleFile &F) const; |
1303 | bool ParseLineTable(ModuleFile &F, const RecordData &Record); |
1304 | bool ReadSourceManagerBlock(ModuleFile &F); |
1305 | llvm::BitstreamCursor &SLocCursorForID(int ID); |
1306 | SourceLocation getImportLocation(ModuleFile *F); |
1307 | ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
1308 | const ModuleFile *ImportedBy, |
1309 | unsigned ClientLoadCapabilities); |
1310 | ASTReadResult ReadSubmoduleBlock(ModuleFile &F, |
1311 | unsigned ClientLoadCapabilities); |
1312 | static bool ParseLanguageOptions(const RecordData &Record, bool Complain, |
1313 | ASTReaderListener &Listener, |
1314 | bool AllowCompatibleDifferences); |
1315 | static bool ParseTargetOptions(const RecordData &Record, bool Complain, |
1316 | ASTReaderListener &Listener, |
1317 | bool AllowCompatibleDifferences); |
1318 | static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
1319 | ASTReaderListener &Listener); |
1320 | static bool ParseFileSystemOptions(const RecordData &Record, bool Complain, |
1321 | ASTReaderListener &Listener); |
1322 | static bool (const RecordData &Record, bool Complain, |
1323 | ASTReaderListener &Listener); |
1324 | static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain, |
1325 | ASTReaderListener &Listener, |
1326 | std::string &SuggestedPredefines); |
1327 | |
1328 | struct RecordLocation { |
1329 | ModuleFile *F; |
1330 | uint64_t Offset; |
1331 | |
1332 | RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {} |
1333 | }; |
1334 | |
1335 | QualType readTypeRecord(unsigned Index); |
1336 | void readExceptionSpec(ModuleFile &ModuleFile, |
1337 | SmallVectorImpl<QualType> &ExceptionStorage, |
1338 | FunctionProtoType::ExceptionSpecInfo &ESI, |
1339 | const RecordData &Record, unsigned &Index); |
1340 | RecordLocation TypeCursorForIndex(unsigned Index); |
1341 | void LoadedDecl(unsigned Index, Decl *D); |
1342 | Decl *ReadDeclRecord(serialization::DeclID ID); |
1343 | void markIncompleteDeclChain(Decl *Canon); |
1344 | |
1345 | |
1346 | |
1347 | |
1348 | Decl *getMostRecentExistingDecl(Decl *D); |
1349 | |
1350 | RecordLocation DeclCursorForID(serialization::DeclID ID, |
1351 | SourceLocation &Location); |
1352 | void loadDeclUpdateRecords(PendingUpdateRecord &Record); |
1353 | void loadPendingDeclChain(Decl *D, uint64_t LocalOffset); |
1354 | void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D, |
1355 | unsigned PreviousGeneration = 0); |
1356 | |
1357 | RecordLocation getLocalBitOffset(uint64_t GlobalOffset); |
1358 | uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset); |
1359 | |
1360 | |
1361 | |
1362 | serialization::PreprocessedEntityID |
1363 | findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const; |
1364 | |
1365 | |
1366 | |
1367 | |
1368 | |
1369 | |
1370 | |
1371 | serialization::PreprocessedEntityID |
1372 | findNextPreprocessedEntity( |
1373 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const; |
1374 | |
1375 | |
1376 | |
1377 | std::pair<ModuleFile *, unsigned> |
1378 | getModulePreprocessedEntity(unsigned GlobalIndex); |
1379 | |
1380 | |
1381 | |
1382 | llvm::iterator_range<PreprocessingRecord::iterator> |
1383 | getModulePreprocessedEntities(ModuleFile &Mod) const; |
1384 | |
1385 | public: |
1386 | class ModuleDeclIterator |
1387 | : public llvm::iterator_adaptor_base< |
1388 | ModuleDeclIterator, const serialization::LocalDeclID *, |
1389 | std::random_access_iterator_tag, const Decl *, ptrdiff_t, |
1390 | const Decl *, const Decl *> { |
1391 | ASTReader *Reader = nullptr; |
1392 | ModuleFile *Mod = nullptr; |
1393 | |
1394 | public: |
1395 | ModuleDeclIterator() : iterator_adaptor_base(nullptr) {} |
1396 | |
1397 | ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, |
1398 | const serialization::LocalDeclID *Pos) |
1399 | : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {} |
1400 | |
1401 | value_type operator*() const { |
1402 | return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I)); |
1403 | } |
1404 | |
1405 | value_type operator->() const { return **this; } |
1406 | |
1407 | bool operator==(const ModuleDeclIterator &RHS) const { |
1408 | assert(Reader == RHS.Reader && Mod == RHS.Mod); |
1409 | return I == RHS.I; |
1410 | } |
1411 | }; |
1412 | |
1413 | llvm::iterator_range<ModuleDeclIterator> |
1414 | getModuleFileLevelDecls(ModuleFile &Mod); |
1415 | |
1416 | private: |
1417 | void PassInterestingDeclsToConsumer(); |
1418 | void PassInterestingDeclToConsumer(Decl *D); |
1419 | |
1420 | void finishPendingActions(); |
1421 | void diagnoseOdrViolations(); |
1422 | |
1423 | void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); |
1424 | |
1425 | void addPendingDeclContextInfo(Decl *D, |
1426 | serialization::GlobalDeclID SemaDC, |
1427 | serialization::GlobalDeclID LexicalDC) { |
1428 | assert(D); |
1429 | PendingDeclContextInfo Info = { D, SemaDC, LexicalDC }; |
1430 | PendingDeclContextInfos.push_back(Info); |
1431 | } |
1432 | |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | void Error(StringRef Msg) const; |
1438 | void Error(unsigned DiagID, StringRef Arg1 = StringRef(), |
1439 | StringRef Arg2 = StringRef()) const; |
1440 | |
1441 | public: |
1442 | |
1443 | |
1444 | |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | |
1451 | |
1452 | |
1453 | |
1454 | |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | |
1469 | |
1470 | |
1471 | |
1472 | |
1473 | |
1474 | |
1475 | |
1476 | |
1477 | |
1478 | |
1479 | |
1480 | |
1481 | ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, |
1482 | ASTContext *Context, const PCHContainerReader &PCHContainerRdr, |
1483 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
1484 | StringRef isysroot = "", bool DisableValidation = false, |
1485 | bool AllowASTWithCompilerErrors = false, |
1486 | bool AllowConfigurationMismatch = false, |
1487 | bool ValidateSystemInputs = false, bool UseGlobalIndex = true, |
1488 | std::unique_ptr<llvm::Timer> ReadTimer = {}); |
1489 | ASTReader(const ASTReader &) = delete; |
1490 | ASTReader &operator=(const ASTReader &) = delete; |
1491 | ~ASTReader() override; |
1492 | |
1493 | SourceManager &getSourceManager() const { return SourceMgr; } |
1494 | FileManager &getFileManager() const { return FileMgr; } |
1495 | DiagnosticsEngine &getDiags() const { return Diags; } |
1496 | |
1497 | |
1498 | |
1499 | |
1500 | |
1501 | |
1502 | enum LoadFailureCapabilities { |
1503 | |
1504 | ARR_None = 0, |
1505 | |
1506 | |
1507 | |
1508 | ARR_Missing = 0x1, |
1509 | |
1510 | |
1511 | |
1512 | ARR_OutOfDate = 0x2, |
1513 | |
1514 | |
1515 | |
1516 | ARR_VersionMismatch = 0x4, |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | ARR_ConfigurationMismatch = 0x8 |
1522 | }; |
1523 | |
1524 | |
1525 | |
1526 | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, |
1541 | SourceLocation ImportLoc, |
1542 | unsigned ClientLoadCapabilities, |
1543 | SmallVectorImpl<ImportedSubmodule> *Imported = nullptr); |
1544 | |
1545 | |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | |
1552 | |
1553 | |
1554 | void makeModuleVisible(Module *Mod, |
1555 | Module::NameVisibilityKind NameVisibility, |
1556 | SourceLocation ImportLoc); |
1557 | |
1558 | |
1559 | void makeNamesVisible(const HiddenNames &Names, Module *Owner); |
1560 | |
1561 | |
1562 | |
1563 | void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef); |
1564 | |
1565 | |
1566 | std::unique_ptr<ASTReaderListener> takeListener() { |
1567 | return std::move(Listener); |
1568 | } |
1569 | |
1570 | |
1571 | void setListener(std::unique_ptr<ASTReaderListener> Listener) { |
1572 | this->Listener = std::move(Listener); |
1573 | } |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | void addListener(std::unique_ptr<ASTReaderListener> L) { |
1579 | if (Listener) |
1580 | L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), |
1581 | std::move(Listener)); |
1582 | Listener = std::move(L); |
1583 | } |
1584 | |
1585 | |
1586 | class ListenerScope { |
1587 | ASTReader &Reader; |
1588 | bool Chained = false; |
1589 | |
1590 | public: |
1591 | ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L) |
1592 | : Reader(Reader) { |
1593 | auto Old = Reader.takeListener(); |
1594 | if (Old) { |
1595 | Chained = true; |
1596 | L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), |
1597 | std::move(Old)); |
1598 | } |
1599 | Reader.setListener(std::move(L)); |
1600 | } |
1601 | |
1602 | ~ListenerScope() { |
1603 | auto New = Reader.takeListener(); |
1604 | if (Chained) |
1605 | Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get()) |
1606 | ->takeSecond()); |
1607 | } |
1608 | }; |
1609 | |
1610 | |
1611 | void setDeserializationListener(ASTDeserializationListener *Listener, |
1612 | bool TakeOwnership = false); |
1613 | |
1614 | |
1615 | ASTDeserializationListener *getDeserializationListener() { |
1616 | return DeserializationListener; |
1617 | } |
1618 | |
1619 | |
1620 | bool hasGlobalIndex() const { return (bool)GlobalIndex; } |
1621 | |
1622 | |
1623 | GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); } |
1624 | |
1625 | |
1626 | void resetForReload() { TriedLoadingGlobalIndex = false; } |
1627 | |
1628 | |
1629 | |
1630 | |
1631 | bool loadGlobalIndex(); |
1632 | |
1633 | |
1634 | |
1635 | bool isGlobalIndexUnavailable() const; |
1636 | |
1637 | |
1638 | void InitializeContext(); |
1639 | |
1640 | |
1641 | void UpdateSema(); |
1642 | |
1643 | |
1644 | void addInMemoryBuffer(StringRef &FileName, |
1645 | std::unique_ptr<llvm::MemoryBuffer> Buffer) { |
1646 | ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer)); |
1647 | } |
1648 | |
1649 | |
1650 | |
1651 | |
1652 | |
1653 | |
1654 | void finalizeForWriting(); |
1655 | |
1656 | |
1657 | ModuleManager &getModuleManager() { return ModuleMgr; } |
1658 | |
1659 | |
1660 | Preprocessor &getPreprocessor() const { return PP; } |
1661 | |
1662 | |
1663 | |
1664 | StringRef getOriginalSourceFile() { |
1665 | return ModuleMgr.getPrimaryModule().OriginalSourceFileName; |
1666 | } |
1667 | |
1668 | |
1669 | |
1670 | static std::string |
1671 | getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr, |
1672 | const PCHContainerReader &PCHContainerRdr, |
1673 | DiagnosticsEngine &Diags); |
1674 | |
1675 | |
1676 | |
1677 | |
1678 | static bool |
1679 | readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, |
1680 | const PCHContainerReader &PCHContainerRdr, |
1681 | bool FindModuleFileExtensions, |
1682 | ASTReaderListener &Listener, |
1683 | bool ValidateDiagnosticOptions); |
1684 | |
1685 | |
1686 | |
1687 | static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
1688 | const PCHContainerReader &PCHContainerRdr, |
1689 | const LangOptions &LangOpts, |
1690 | const TargetOptions &TargetOpts, |
1691 | const PreprocessorOptions &PPOpts, |
1692 | StringRef ExistingModuleCachePath); |
1693 | |
1694 | |
1695 | |
1696 | |
1697 | const std::string &getSuggestedPredefines() { return SuggestedPredefines; } |
1698 | |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override; |
1704 | |
1705 | |
1706 | |
1707 | std::pair<unsigned, unsigned> |
1708 | findPreprocessedEntitiesInRange(SourceRange Range) override; |
1709 | |
1710 | |
1711 | |
1712 | Optional<bool> isPreprocessedEntityInFileID(unsigned Index, |
1713 | FileID FID) override; |
1714 | |
1715 | |
1716 | SourceRange ReadSkippedRange(unsigned Index) override; |
1717 | |
1718 | |
1719 | HeaderFileInfo (const FileEntry *FE) override; |
1720 | |
1721 | void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag); |
1722 | |
1723 | |
1724 | unsigned getTotalNumSLocs() const { |
1725 | return TotalNumSLocEntries; |
1726 | } |
1727 | |
1728 | |
1729 | unsigned getTotalNumIdentifiers() const { |
1730 | return static_cast<unsigned>(IdentifiersLoaded.size()); |
1731 | } |
1732 | |
1733 | |
1734 | unsigned getTotalNumMacros() const { |
1735 | return static_cast<unsigned>(MacrosLoaded.size()); |
1736 | } |
1737 | |
1738 | |
1739 | unsigned getTotalNumTypes() const { |
1740 | return static_cast<unsigned>(TypesLoaded.size()); |
1741 | } |
1742 | |
1743 | |
1744 | unsigned getTotalNumDecls() const { |
1745 | return static_cast<unsigned>(DeclsLoaded.size()); |
1746 | } |
1747 | |
1748 | |
1749 | unsigned getTotalNumSubmodules() const { |
1750 | return static_cast<unsigned>(SubmodulesLoaded.size()); |
1751 | } |
1752 | |
1753 | |
1754 | unsigned getTotalNumSelectors() const { |
1755 | return static_cast<unsigned>(SelectorsLoaded.size()); |
1756 | } |
1757 | |
1758 | |
1759 | |
1760 | unsigned getTotalNumPreprocessedEntities() const { |
1761 | unsigned Result = 0; |
1762 | for (const auto &M : ModuleMgr) |
1763 | Result += M.NumPreprocessedEntities; |
1764 | return Result; |
1765 | } |
1766 | |
1767 | |
1768 | |
1769 | TemplateArgumentLocInfo |
1770 | GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind, |
1771 | const RecordData &Record, unsigned &Idx); |
1772 | |
1773 | |
1774 | TemplateArgumentLoc |
1775 | ReadTemplateArgumentLoc(ModuleFile &F, |
1776 | const RecordData &Record, unsigned &Idx); |
1777 | |
1778 | const ASTTemplateArgumentListInfo* |
1779 | ReadASTTemplateArgumentListInfo(ModuleFile &F, |
1780 | const RecordData &Record, unsigned &Index); |
1781 | |
1782 | |
1783 | TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F, |
1784 | const RecordData &Record, unsigned &Idx); |
1785 | |
1786 | |
1787 | void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx, |
1788 | TypeLoc TL); |
1789 | |
1790 | |
1791 | |
1792 | QualType GetType(serialization::TypeID ID); |
1793 | |
1794 | |
1795 | QualType getLocalType(ModuleFile &F, unsigned LocalID); |
1796 | |
1797 | |
1798 | serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const; |
1799 | |
1800 | |
1801 | |
1802 | QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) { |
1803 | if (Idx >= Record.size()) |
1804 | return {}; |
1805 | |
1806 | return getLocalType(F, Record[Idx++]); |
1807 | } |
1808 | |
1809 | |
1810 | |
1811 | serialization::DeclID getGlobalDeclID(ModuleFile &F, |
1812 | serialization::LocalDeclID LocalID) const; |
1813 | |
1814 | |
1815 | bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const; |
1816 | |
1817 | |
1818 | |
1819 | ModuleFile *getOwningModuleFile(const Decl *D); |
1820 | |
1821 | |
1822 | |
1823 | std::string getOwningModuleNameForDiagnostic(const Decl *D); |
1824 | |
1825 | |
1826 | SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID); |
1827 | |
1828 | |
1829 | |
1830 | Decl *GetDecl(serialization::DeclID ID); |
1831 | Decl *GetExternalDecl(uint32_t ID) override; |
1832 | |
1833 | |
1834 | |
1835 | Decl *GetExistingDecl(serialization::DeclID ID); |
1836 | |
1837 | |
1838 | Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) { |
1839 | return GetDecl(getGlobalDeclID(F, LocalID)); |
1840 | } |
1841 | |
1842 | |
1843 | |
1844 | |
1845 | template<typename T> |
1846 | T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) { |
1847 | return cast_or_null<T>(GetLocalDecl(F, LocalID)); |
1848 | } |
1849 | |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | serialization::DeclID |
1856 | mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
1857 | serialization::DeclID GlobalID); |
1858 | |
1859 | |
1860 | |
1861 | |
1862 | |
1863 | serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record, |
1864 | unsigned &Idx); |
1865 | |
1866 | |
1867 | |
1868 | Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { |
1869 | return GetDecl(ReadDeclID(F, R, I)); |
1870 | } |
1871 | |
1872 | |
1873 | |
1874 | |
1875 | |
1876 | |
1877 | template<typename T> |
1878 | T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { |
1879 | return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I))); |
1880 | } |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | void CompleteRedeclChain(const Decl *D) override; |
1886 | |
1887 | CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; |
1888 | |
1889 | |
1890 | |
1891 | |
1892 | |
1893 | |
1894 | Stmt *GetExternalDeclStmt(uint64_t Offset) override; |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID); |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | bool FindExternalVisibleDeclsByName(const DeclContext *DC, |
1905 | DeclarationName Name) override; |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | void |
1921 | FindExternalLexicalDecls(const DeclContext *DC, |
1922 | llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
1923 | SmallVectorImpl<Decl *> &Decls) override; |
1924 | |
1925 | |
1926 | |
1927 | |
1928 | void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, |
1929 | SmallVectorImpl<Decl *> &Decls) override; |
1930 | |
1931 | |
1932 | |
1933 | |
1934 | void StartedDeserializing() override; |
1935 | |
1936 | |
1937 | |
1938 | void FinishedDeserializing() override; |
1939 | |
1940 | |
1941 | |
1942 | |
1943 | |
1944 | |
1945 | void StartTranslationUnit(ASTConsumer *Consumer) override; |
1946 | |
1947 | |
1948 | void PrintStats() override; |
1949 | |
1950 | |
1951 | void dump(); |
1952 | |
1953 | |
1954 | |
1955 | void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; |
1956 | |
1957 | |
1958 | |
1959 | |
1960 | void InitializeSema(Sema &S) override; |
1961 | |
1962 | |
1963 | void ForgetSema() override { SemaObj = nullptr; } |
1964 | |
1965 | |
1966 | |
1967 | |
1968 | |
1969 | |
1970 | |
1971 | IdentifierInfo *get(StringRef Name) override; |
1972 | |
1973 | |
1974 | |
1975 | IdentifierIterator *getIdentifiers() override; |
1976 | |
1977 | |
1978 | |
1979 | void ReadMethodPool(Selector Sel) override; |
1980 | |
1981 | |
1982 | |
1983 | void updateOutOfDateSelector(Selector Sel) override; |
1984 | |
1985 | |
1986 | |
1987 | void ReadKnownNamespaces( |
1988 | SmallVectorImpl<NamespaceDecl *> &Namespaces) override; |
1989 | |
1990 | void ReadUndefinedButUsed( |
1991 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override; |
1992 | |
1993 | void ReadMismatchingDeleteExpressions(llvm::MapVector< |
1994 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
1995 | Exprs) override; |
1996 | |
1997 | void ReadTentativeDefinitions( |
1998 | SmallVectorImpl<VarDecl *> &TentativeDefs) override; |
1999 | |
2000 | void ReadUnusedFileScopedDecls( |
2001 | SmallVectorImpl<const DeclaratorDecl *> &Decls) override; |
2002 | |
2003 | void ReadDelegatingConstructors( |
2004 | SmallVectorImpl<CXXConstructorDecl *> &Decls) override; |
2005 | |
2006 | void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override; |
2007 | |
2008 | void ReadUnusedLocalTypedefNameCandidates( |
2009 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; |
2010 | |
2011 | void ReadReferencedSelectors( |
2012 | SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override; |
2013 | |
2014 | void ReadWeakUndeclaredIdentifiers( |
2015 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override; |
2016 | |
2017 | void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; |
2018 | |
2019 | void ReadPendingInstantiations( |
2020 | SmallVectorImpl<std::pair<ValueDecl *, |
2021 | SourceLocation>> &Pending) override; |
2022 | |
2023 | void ReadLateParsedTemplates( |
2024 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
2025 | &LPTMap) override; |
2026 | |
2027 | |
2028 | void LoadSelector(Selector Sel); |
2029 | |
2030 | void SetIdentifierInfo(unsigned ID, IdentifierInfo *II); |
2031 | void SetGloballyVisibleDecls(IdentifierInfo *II, |
2032 | const SmallVectorImpl<uint32_t> &DeclIDs, |
2033 | SmallVectorImpl<Decl *> *Decls = nullptr); |
2034 | |
2035 | |
2036 | DiagnosticBuilder Diag(unsigned DiagID) const; |
2037 | |
2038 | |
2039 | DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const; |
2040 | |
2041 | IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID); |
2042 | |
2043 | IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record, |
2044 | unsigned &Idx) { |
2045 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++])); |
2046 | } |
2047 | |
2048 | IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override { |
2049 | |
2050 | Deserializing AnIdentifier(this); |
2051 | |
2052 | return DecodeIdentifierInfo(ID); |
2053 | } |
2054 | |
2055 | IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID); |
2056 | |
2057 | serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, |
2058 | unsigned LocalID); |
2059 | |
2060 | void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo); |
2061 | |
2062 | |
2063 | MacroInfo *getMacro(serialization::MacroID ID); |
2064 | |
2065 | |
2066 | |
2067 | serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID); |
2068 | |
2069 | |
2070 | bool ReadSLocEntry(int ID) override; |
2071 | |
2072 | |
2073 | |
2074 | std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override; |
2075 | |
2076 | |
2077 | |
2078 | serialization::SubmoduleID |
2079 | getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID); |
2080 | |
2081 | |
2082 | |
2083 | Module *getSubmodule(serialization::SubmoduleID GlobalID); |
2084 | |
2085 | |
2086 | |
2087 | |
2088 | Module *getModule(unsigned ID) override; |
2089 | |
2090 | bool DeclIsFromPCHWithObjectFile(const Decl *D) override; |
2091 | |
2092 | |
2093 | |
2094 | ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID); |
2095 | |
2096 | |
2097 | unsigned getModuleFileID(ModuleFile *M); |
2098 | |
2099 | |
2100 | llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override; |
2101 | |
2102 | ExtKind hasExternalDefinitions(const Decl *D) override; |
2103 | |
2104 | |
2105 | |
2106 | Selector getLocalSelector(ModuleFile &M, unsigned LocalID); |
2107 | |
2108 | Selector DecodeSelector(serialization::SelectorID Idx); |
2109 | |
2110 | Selector GetExternalSelector(serialization::SelectorID ID) override; |
2111 | uint32_t GetNumExternalSelectors() override; |
2112 | |
2113 | Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) { |
2114 | return getLocalSelector(M, Record[Idx++]); |
2115 | } |
2116 | |
2117 | |
2118 | |
2119 | serialization::SelectorID getGlobalSelectorID(ModuleFile &F, |
2120 | unsigned LocalID) const; |
2121 | |
2122 | |
2123 | DeclarationName ReadDeclarationName(ModuleFile &F, |
2124 | const RecordData &Record, unsigned &Idx); |
2125 | void ReadDeclarationNameLoc(ModuleFile &F, |
2126 | DeclarationNameLoc &DNLoc, DeclarationName Name, |
2127 | const RecordData &Record, unsigned &Idx); |
2128 | void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo, |
2129 | const RecordData &Record, unsigned &Idx); |
2130 | |
2131 | void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
2132 | const RecordData &Record, unsigned &Idx); |
2133 | |
2134 | NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F, |
2135 | const RecordData &Record, |
2136 | unsigned &Idx); |
2137 | |
2138 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F, |
2139 | const RecordData &Record, |
2140 | unsigned &Idx); |
2141 | |
2142 | |
2143 | TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record, |
2144 | unsigned &Idx); |
2145 | |
2146 | |
2147 | TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record, |
2148 | unsigned &Idx, |
2149 | bool Canonicalize = false); |
2150 | |
2151 | |
2152 | TemplateParameterList *ReadTemplateParameterList(ModuleFile &F, |
2153 | const RecordData &Record, |
2154 | unsigned &Idx); |
2155 | |
2156 | |
2157 | void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
2158 | ModuleFile &F, const RecordData &Record, |
2159 | unsigned &Idx, bool Canonicalize = false); |
2160 | |
2161 | |
2162 | void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
2163 | const RecordData &Record, unsigned &Idx); |
2164 | |
2165 | |
2166 | CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F, |
2167 | const RecordData &Record,unsigned &Idx); |
2168 | |
2169 | |
2170 | CXXCtorInitializer ** |
2171 | ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
2172 | unsigned &Idx); |
2173 | |
2174 | |
2175 | CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override; |
2176 | |
2177 | |
2178 | |
2179 | SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const { |
2180 | return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31)); |
2181 | } |
2182 | |
2183 | |
2184 | SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const { |
2185 | SourceLocation Loc = ReadUntranslatedSourceLocation(Raw); |
2186 | return TranslateSourceLocation(ModuleFile, Loc); |
2187 | } |
2188 | |
2189 | |
2190 | |
2191 | SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, |
2192 | SourceLocation Loc) const { |
2193 | if (!ModuleFile.ModuleOffsetMap.empty()) |
2194 | ReadModuleOffsetMap(ModuleFile); |
2195 | (0) . __assert_fail ("ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && \"Cannot find offset to remap.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != |
2196 | (0) . __assert_fail ("ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && \"Cannot find offset to remap.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> ModuleFile.SLocRemap.end() && |
2197 | (0) . __assert_fail ("ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() && \"Cannot find offset to remap.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2197, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Cannot find offset to remap."); |
2198 | int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second; |
2199 | return Loc.getLocWithOffset(Remap); |
2200 | } |
2201 | |
2202 | |
2203 | SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, |
2204 | const RecordDataImpl &Record, |
2205 | unsigned &Idx) { |
2206 | return ReadSourceLocation(ModuleFile, Record[Idx++]); |
2207 | } |
2208 | |
2209 | |
2210 | SourceRange ReadSourceRange(ModuleFile &F, |
2211 | const RecordData &Record, unsigned &Idx); |
2212 | |
2213 | |
2214 | llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx); |
2215 | |
2216 | |
2217 | llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx); |
2218 | |
2219 | |
2220 | llvm::APFloat ReadAPFloat(const RecordData &Record, |
2221 | const llvm::fltSemantics &Sem, unsigned &Idx); |
2222 | |
2223 | |
2224 | static std::string ReadString(const RecordData &Record, unsigned &Idx); |
2225 | |
2226 | |
2227 | static void SkipString(const RecordData &Record, unsigned &Idx) { |
2228 | Idx += Record[Idx] + 1; |
2229 | } |
2230 | |
2231 | |
2232 | std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx); |
2233 | |
2234 | |
2235 | std::string ReadPath(StringRef BaseDirectory, const RecordData &Record, |
2236 | unsigned &Idx); |
2237 | |
2238 | |
2239 | static void SkipPath(const RecordData &Record, unsigned &Idx) { |
2240 | SkipString(Record, Idx); |
2241 | } |
2242 | |
2243 | |
2244 | static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); |
2245 | |
2246 | CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record, |
2247 | unsigned &Idx); |
2248 | |
2249 | |
2250 | Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx); |
2251 | |
2252 | |
2253 | void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs); |
2254 | |
2255 | |
2256 | Stmt *ReadStmt(ModuleFile &F); |
2257 | |
2258 | |
2259 | Expr *ReadExpr(ModuleFile &F); |
2260 | |
2261 | |
2262 | Stmt *ReadSubStmt() { |
2263 | (0) . __assert_fail ("ReadingKind == Read_Stmt && \"Should be called only during statement reading!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2264, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ReadingKind == Read_Stmt && |
2264 | (0) . __assert_fail ("ReadingKind == Read_Stmt && \"Should be called only during statement reading!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2264, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Should be called only during statement reading!"); |
2265 | |
2266 | |
2267 | (0) . __assert_fail ("!StmtStack.empty() && \"Read too many sub-statements!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2267, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!StmtStack.empty() && "Read too many sub-statements!"); |
2268 | return StmtStack.pop_back_val(); |
2269 | } |
2270 | |
2271 | |
2272 | Expr *ReadSubExpr(); |
2273 | |
2274 | |
2275 | Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx); |
2276 | |
2277 | |
2278 | MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset); |
2279 | |
2280 | |
2281 | |
2282 | serialization::PreprocessedEntityID |
2283 | getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const; |
2284 | |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | |
2290 | |
2291 | void addPendingMacro(IdentifierInfo *II, ModuleFile *M, |
2292 | uint64_t MacroDirectivesOffset); |
2293 | |
2294 | |
2295 | void ReadDefinedMacros() override; |
2296 | |
2297 | |
2298 | void updateOutOfDateIdentifier(IdentifierInfo &II) override; |
2299 | |
2300 | |
2301 | void markIdentifierUpToDate(IdentifierInfo *II); |
2302 | |
2303 | |
2304 | void completeVisibleDeclsMap(const DeclContext *DC) override; |
2305 | |
2306 | |
2307 | ASTContext &getContext() { |
2308 | (0) . __assert_fail ("ContextObj && \"requested AST context when not loading AST\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Serialization/ASTReader.h", 2308, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ContextObj && "requested AST context when not loading AST"); |
2309 | return *ContextObj; |
2310 | } |
2311 | |
2312 | |
2313 | |
2314 | SmallVector<uint64_t, 16> PreloadedDeclIDs; |
2315 | |
2316 | |
2317 | |
2318 | |
2319 | Sema *getSema() { return SemaObj; } |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | IdentifierResolver &getIdResolver(); |
2325 | |
2326 | |
2327 | |
2328 | IdentifierTable &getIdentifierTable(); |
2329 | |
2330 | |
2331 | |
2332 | void RecordSwitchCaseID(SwitchCase *SC, unsigned ID); |
2333 | |
2334 | |
2335 | SwitchCase *getSwitchCaseWithID(unsigned ID); |
2336 | |
2337 | void ClearSwitchCaseIDs(); |
2338 | |
2339 | |
2340 | SmallVector<std::pair<llvm::BitstreamCursor, |
2341 | serialization::ModuleFile *>, 8> ; |
2342 | |
2343 | |
2344 | void () override; |
2345 | |
2346 | |
2347 | void visitInputFiles(serialization::ModuleFile &MF, |
2348 | bool IncludeSystem, bool Complain, |
2349 | llvm::function_ref<void(const serialization::InputFile &IF, |
2350 | bool isSystem)> Visitor); |
2351 | |
2352 | |
2353 | |
2354 | void visitTopLevelModuleMaps(serialization::ModuleFile &MF, |
2355 | llvm::function_ref< |
2356 | void(const FileEntry *)> Visitor); |
2357 | |
2358 | bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } |
2359 | }; |
2360 | |
2361 | |
2362 | class ASTRecordReader { |
2363 | using ModuleFile = serialization::ModuleFile; |
2364 | |
2365 | ASTReader *Reader; |
2366 | ModuleFile *F; |
2367 | unsigned Idx = 0; |
2368 | ASTReader::RecordData Record; |
2369 | |
2370 | using RecordData = ASTReader::RecordData; |
2371 | using RecordDataImpl = ASTReader::RecordDataImpl; |
2372 | |
2373 | public: |
2374 | |
2375 | ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {} |
2376 | |
2377 | |
2378 | |
2379 | unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID); |
2380 | |
2381 | |
2382 | bool isModule() const { return F->isModule(); } |
2383 | |
2384 | |
2385 | ASTContext &getContext() { return Reader->getContext(); } |
2386 | |
2387 | |
2388 | unsigned getIdx() const { return Idx; } |
2389 | |
2390 | |
2391 | size_t size() const { return Record.size(); } |
2392 | |
2393 | |
2394 | const uint64_t &operator[](size_t N) { return Record[N]; } |
2395 | |
2396 | |
2397 | const uint64_t &back() const { return Record.back(); } |
2398 | |
2399 | |
2400 | |
2401 | const uint64_t &readInt() { return Record[Idx++]; } |
2402 | |
2403 | |
2404 | const uint64_t &peekInt() { return Record[Idx]; } |
2405 | |
2406 | |
2407 | void skipInts(unsigned N) { Idx += N; } |
2408 | |
2409 | |
2410 | serialization::SubmoduleID |
2411 | getGlobalSubmoduleID(unsigned LocalID) { |
2412 | return Reader->getGlobalSubmoduleID(*F, LocalID); |
2413 | } |
2414 | |
2415 | |
2416 | Module *getSubmodule(serialization::SubmoduleID GlobalID) { |
2417 | return Reader->getSubmodule(GlobalID); |
2418 | } |
2419 | |
2420 | |
2421 | bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) { |
2422 | return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset, |
2423 | DC); |
2424 | } |
2425 | |
2426 | |
2427 | bool readVisibleDeclContextStorage(uint64_t Offset, |
2428 | serialization::DeclID ID) { |
2429 | return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset, |
2430 | ID); |
2431 | } |
2432 | |
2433 | void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage, |
2434 | FunctionProtoType::ExceptionSpecInfo &ESI) { |
2435 | return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx); |
2436 | } |
2437 | |
2438 | |
2439 | uint64_t getGlobalBitOffset(uint32_t LocalOffset) { |
2440 | return Reader->getGlobalBitOffset(*F, LocalOffset); |
2441 | } |
2442 | |
2443 | |
2444 | Stmt *readStmt() { return Reader->ReadStmt(*F); } |
2445 | |
2446 | |
2447 | Expr *readExpr() { return Reader->ReadExpr(*F); } |
2448 | |
2449 | |
2450 | Stmt *readSubStmt() { return Reader->ReadSubStmt(); } |
2451 | |
2452 | |
2453 | Expr *readSubExpr() { return Reader->ReadSubExpr(); } |
2454 | |
2455 | |
2456 | |
2457 | |
2458 | template<typename T> |
2459 | T *GetLocalDeclAs(uint32_t LocalID) { |
2460 | return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID)); |
2461 | } |
2462 | |
2463 | |
2464 | |
2465 | TemplateArgumentLocInfo |
2466 | getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) { |
2467 | return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx); |
2468 | } |
2469 | |
2470 | |
2471 | TemplateArgumentLoc |
2472 | readTemplateArgumentLoc() { |
2473 | return Reader->ReadTemplateArgumentLoc(*F, Record, Idx); |
2474 | } |
2475 | |
2476 | const ASTTemplateArgumentListInfo* |
2477 | readASTTemplateArgumentListInfo() { |
2478 | return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx); |
2479 | } |
2480 | |
2481 | |
2482 | TypeSourceInfo *getTypeSourceInfo() { |
2483 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
2484 | } |
2485 | |
2486 | |
2487 | void readTypeLoc(TypeLoc TL) { |
2488 | return Reader->ReadTypeLoc(*F, Record, Idx, TL); |
2489 | } |
2490 | |
2491 | |
2492 | serialization::TypeID getGlobalTypeID(unsigned LocalID) const { |
2493 | return Reader->getGlobalTypeID(*F, LocalID); |
2494 | } |
2495 | |
2496 | |
2497 | QualType readType() { |
2498 | return Reader->readType(*F, Record, Idx); |
2499 | } |
2500 | |
2501 | |
2502 | |
2503 | |
2504 | serialization::DeclID readDeclID() { |
2505 | return Reader->ReadDeclID(*F, Record, Idx); |
2506 | } |
2507 | |
2508 | |
2509 | |
2510 | Decl *readDecl() { |
2511 | return Reader->ReadDecl(*F, Record, Idx); |
2512 | } |
2513 | |
2514 | |
2515 | |
2516 | |
2517 | |
2518 | |
2519 | template<typename T> |
2520 | T *readDeclAs() { |
2521 | return Reader->ReadDeclAs<T>(*F, Record, Idx); |
2522 | } |
2523 | |
2524 | IdentifierInfo *getIdentifierInfo() { |
2525 | return Reader->GetIdentifierInfo(*F, Record, Idx); |
2526 | } |
2527 | |
2528 | |
2529 | Selector readSelector() { |
2530 | return Reader->ReadSelector(*F, Record, Idx); |
2531 | } |
2532 | |
2533 | |
2534 | DeclarationName readDeclarationName() { |
2535 | return Reader->ReadDeclarationName(*F, Record, Idx); |
2536 | } |
2537 | void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { |
2538 | return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx); |
2539 | } |
2540 | void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) { |
2541 | return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx); |
2542 | } |
2543 | |
2544 | void readQualifierInfo(QualifierInfo &Info) { |
2545 | return Reader->ReadQualifierInfo(*F, Info, Record, Idx); |
2546 | } |
2547 | |
2548 | NestedNameSpecifier *readNestedNameSpecifier() { |
2549 | return Reader->ReadNestedNameSpecifier(*F, Record, Idx); |
2550 | } |
2551 | |
2552 | NestedNameSpecifierLoc readNestedNameSpecifierLoc() { |
2553 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
2554 | } |
2555 | |
2556 | |
2557 | TemplateName readTemplateName() { |
2558 | return Reader->ReadTemplateName(*F, Record, Idx); |
2559 | } |
2560 | |
2561 | |
2562 | TemplateArgument readTemplateArgument(bool Canonicalize = false) { |
2563 | return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize); |
2564 | } |
2565 | |
2566 | |
2567 | TemplateParameterList *readTemplateParameterList() { |
2568 | return Reader->ReadTemplateParameterList(*F, Record, Idx); |
2569 | } |
2570 | |
2571 | |
2572 | void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
2573 | bool Canonicalize = false) { |
2574 | return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx, |
2575 | Canonicalize); |
2576 | } |
2577 | |
2578 | |
2579 | void readUnresolvedSet(LazyASTUnresolvedSet &Set) { |
2580 | return Reader->ReadUnresolvedSet(*F, Set, Record, Idx); |
2581 | } |
2582 | |
2583 | |
2584 | CXXBaseSpecifier readCXXBaseSpecifier() { |
2585 | return Reader->ReadCXXBaseSpecifier(*F, Record, Idx); |
2586 | } |
2587 | |
2588 | |
2589 | CXXCtorInitializer **readCXXCtorInitializers() { |
2590 | return Reader->ReadCXXCtorInitializers(*F, Record, Idx); |
2591 | } |
2592 | |
2593 | CXXTemporary *readCXXTemporary() { |
2594 | return Reader->ReadCXXTemporary(*F, Record, Idx); |
2595 | } |
2596 | |
2597 | |
2598 | SourceLocation readSourceLocation() { |
2599 | return Reader->ReadSourceLocation(*F, Record, Idx); |
2600 | } |
2601 | |
2602 | |
2603 | SourceRange readSourceRange() { |
2604 | return Reader->ReadSourceRange(*F, Record, Idx); |
2605 | } |
2606 | |
2607 | |
2608 | llvm::APInt readAPInt() { |
2609 | return Reader->ReadAPInt(Record, Idx); |
2610 | } |
2611 | |
2612 | |
2613 | llvm::APSInt readAPSInt() { |
2614 | return Reader->ReadAPSInt(Record, Idx); |
2615 | } |
2616 | |
2617 | |
2618 | llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) { |
2619 | return Reader->ReadAPFloat(Record, Sem,Idx); |
2620 | } |
2621 | |
2622 | |
2623 | std::string readString() { |
2624 | return Reader->ReadString(Record, Idx); |
2625 | } |
2626 | |
2627 | |
2628 | std::string readPath() { |
2629 | return Reader->ReadPath(*F, Record, Idx); |
2630 | } |
2631 | |
2632 | |
2633 | VersionTuple readVersionTuple() { |
2634 | return ASTReader::ReadVersionTuple(Record, Idx); |
2635 | } |
2636 | |
2637 | |
2638 | Attr *readAttr() { |
2639 | return Reader->ReadAttr(*F, Record, Idx); |
2640 | } |
2641 | |
2642 | |
2643 | void readAttributes(AttrVec &Attrs) { |
2644 | return Reader->ReadAttributes(*this, Attrs); |
2645 | } |
2646 | |
2647 | |
2648 | Token readToken() { |
2649 | return Reader->ReadToken(*F, Record, Idx); |
2650 | } |
2651 | |
2652 | void recordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
2653 | Reader->RecordSwitchCaseID(SC, ID); |
2654 | } |
2655 | |
2656 | |
2657 | SwitchCase *getSwitchCaseWithID(unsigned ID) { |
2658 | return Reader->getSwitchCaseWithID(ID); |
2659 | } |
2660 | }; |
2661 | |
2662 | |
2663 | |
2664 | struct SavedStreamPosition { |
2665 | explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor) |
2666 | : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {} |
2667 | |
2668 | ~SavedStreamPosition() { |
2669 | Cursor.JumpToBit(Offset); |
2670 | } |
2671 | |
2672 | private: |
2673 | llvm::BitstreamCursor &Cursor; |
2674 | uint64_t Offset; |
2675 | }; |
2676 | |
2677 | inline void PCHValidator::Error(const char *Msg) { |
2678 | Reader.Error(Msg); |
2679 | } |
2680 | |
2681 | class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> { |
2682 | ASTRecordReader &Record; |
2683 | ASTContext &Context; |
2684 | |
2685 | public: |
2686 | OMPClauseReader(ASTRecordReader &Record) |
2687 | : Record(Record), Context(Record.getContext()) {} |
2688 | |
2689 | #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C); |
2690 | #include "clang/Basic/OpenMPKinds.def" |
2691 | OMPClause *readClause(); |
2692 | void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); |
2693 | void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); |
2694 | }; |
2695 | |
2696 | } |
2697 | |
2698 | #endif |
2699 | |