-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
ASTReader.h
2573 lines (2084 loc) · 97.8 KB
/
ASTReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the ASTReader class, which reads AST files.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/TemplateBase.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/Version.h"
#include "clang/Lex/ExternalPreprocessorSource.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Sema/ExternalSemaSource.h"
#include "clang/Sema/IdentifierResolver.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "clang/Serialization/ContinuousRangeMap.h"
#include "clang/Serialization/Module.h"
#include "clang/Serialization/ModuleFileExtension.h"
#include "clang/Serialization/ModuleManager.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Timer.h"
#include <deque>
#include <memory>
#include <string>
#include <utility>
#include <vector>
namespace llvm {
class BitstreamCursor;
class MemoryBuffer;
class APInt;
class APSInt;
class APFloat;
}
namespace clang {
class SourceManager;
class HeaderSearchOptions;
class FileManager;
class AddrLabelExpr;
class ASTConsumer;
class ASTContext;
class ASTIdentifierIterator;
class ASTUnit; // FIXME: Layering violation and egregious hack.
class Attr;
class Decl;
class DeclContext;
class DefMacroDirective;
class DiagnosticOptions;
class NestedNameSpecifier;
class CXXBaseSpecifier;
class CXXConstructorDecl;
class CXXCtorInitializer;
class GlobalModuleIndex;
class GotoStmt;
class MacroDefinition;
class MacroDirective;
class ModuleMacro;
class NamedDecl;
class OpaqueValueExpr;
class Preprocessor;
class PreprocessorOptions;
class Sema;
class SwitchCase;
class ASTDeserializationListener;
class ASTWriter;
class ASTReader;
class ASTDeclReader;
class ASTStmtReader;
class ASTRecordReader;
class TypeLocReader;
struct HeaderFileInfo;
class VersionTuple;
class TargetOptions;
class LazyASTUnresolvedSet;
/// \brief Abstract interface for callback invocations by the ASTReader.
///
/// While reading an AST file, the ASTReader will call the methods of the
/// listener to pass on specific information. Some of the listener methods can
/// return true to indicate to the ASTReader that the information (and
/// consequently the AST file) is invalid.
class ASTReaderListener {
public:
virtual ~ASTReaderListener();
/// \brief Receives the full Clang version information.
///
/// \returns true to indicate that the version is invalid. Subclasses should
/// generally defer to this implementation.
virtual bool ReadFullVersionInformation(StringRef FullVersion) {
return FullVersion != getClangFullRepositoryVersion();
}
virtual void ReadModuleName(StringRef ModuleName) {}
virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
/// \brief Receives the language options.
///
/// \returns true to indicate the options are invalid or false otherwise.
virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
bool Complain,
bool AllowCompatibleDifferences) {
return false;
}
/// \brief Receives the target options.
///
/// \returns true to indicate the target options are invalid, or false
/// otherwise.
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool AllowCompatibleDifferences) {
return false;
}
/// \brief Receives the diagnostic options.
///
/// \returns true to indicate the diagnostic options are invalid, or false
/// otherwise.
virtual bool
ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
bool Complain) {
return false;
}
/// \brief Receives the file system options.
///
/// \returns true to indicate the file system options are invalid, or false
/// otherwise.
virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
bool Complain) {
return false;
}
/// \brief Receives the header search options.
///
/// \returns true to indicate the header search options are invalid, or false
/// otherwise.
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef SpecificModuleCachePath,
bool Complain) {
return false;
}
/// \brief Receives the preprocessor options.
///
/// \param SuggestedPredefines Can be filled in with the set of predefines
/// that are suggested by the preprocessor options. Typically only used when
/// loading a precompiled header.
///
/// \returns true to indicate the preprocessor options are invalid, or false
/// otherwise.
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
bool Complain,
std::string &SuggestedPredefines) {
return false;
}
/// \brief Receives __COUNTER__ value.
virtual void ReadCounter(const serialization::ModuleFile &M,
unsigned Value) {}
/// This is called for each AST file loaded.
virtual void visitModuleFile(StringRef Filename,
serialization::ModuleKind Kind) {}
/// \brief Returns true if this \c ASTReaderListener wants to receive the
/// input files of the AST file via \c visitInputFile, false otherwise.
virtual bool needsInputFileVisitation() { return false; }
/// \brief Returns true if this \c ASTReaderListener wants to receive the
/// system input files of the AST file via \c visitInputFile, false otherwise.
virtual bool needsSystemInputFileVisitation() { return false; }
/// \brief if \c needsInputFileVisitation returns true, this is called for
/// each non-system input file of the AST File. If
/// \c needsSystemInputFileVisitation is true, then it is called for all
/// system input files as well.
///
/// \returns true to continue receiving the next input file, false to stop.
virtual bool visitInputFile(StringRef Filename, bool isSystem,
bool isOverridden, bool isExplicitModule) {
return true;
}
/// \brief Returns true if this \c ASTReaderListener wants to receive the
/// imports of the AST file via \c visitImport, false otherwise.
virtual bool needsImportVisitation() const { return false; }
/// \brief If needsImportVisitation returns \c true, this is called for each
/// AST file imported by this AST file.
virtual void visitImport(StringRef Filename) {}
/// Indicates that a particular module file extension has been read.
virtual void readModuleFileExtension(
const ModuleFileExtensionMetadata &Metadata) {}
};
/// \brief Simple wrapper class for chaining listeners.
class ChainedASTReaderListener : public ASTReaderListener {
std::unique_ptr<ASTReaderListener> First;
std::unique_ptr<ASTReaderListener> Second;
public:
/// Takes ownership of \p First and \p Second.
ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
std::unique_ptr<ASTReaderListener> Second)
: First(std::move(First)), Second(std::move(Second)) {}
std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
bool ReadFullVersionInformation(StringRef FullVersion) override;
void ReadModuleName(StringRef ModuleName) override;
void ReadModuleMapFile(StringRef ModuleMapPath) override;
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
bool Complain) override;
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
bool Complain) override;
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef SpecificModuleCachePath,
bool Complain) override;
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
bool Complain,
std::string &SuggestedPredefines) override;
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
bool needsInputFileVisitation() override;
bool needsSystemInputFileVisitation() override;
void visitModuleFile(StringRef Filename,
serialization::ModuleKind Kind) override;
bool visitInputFile(StringRef Filename, bool isSystem,
bool isOverridden, bool isExplicitModule) override;
void readModuleFileExtension(
const ModuleFileExtensionMetadata &Metadata) override;
};
/// \brief ASTReaderListener implementation to validate the information of
/// the PCH file against an initialized Preprocessor.
class PCHValidator : public ASTReaderListener {
Preprocessor &PP;
ASTReader &Reader;
public:
PCHValidator(Preprocessor &PP, ASTReader &Reader)
: PP(PP), Reader(Reader) {}
bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
bool AllowCompatibleDifferences) override;
bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
bool Complain) override;
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
std::string &SuggestedPredefines) override;
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef SpecificModuleCachePath,
bool Complain) override;
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
private:
void Error(const char *Msg);
};
/// \brief ASTReaderListenter implementation to set SuggestedPredefines of
/// ASTReader which is required to use a pch file. This is the replacement
/// of PCHValidator or SimplePCHValidator when using a pch file without
/// validating it.
class SimpleASTReaderListener : public ASTReaderListener {
Preprocessor &PP;
public:
SimpleASTReaderListener(Preprocessor &PP)
: PP(PP) {}
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
std::string &SuggestedPredefines) override;
};
namespace serialization {
class ReadMethodPoolVisitor;
namespace reader {
class ASTIdentifierLookupTrait;
/// \brief The on-disk hash table(s) used for DeclContext name lookup.
struct DeclContextLookupTable;
}
} // end namespace serialization
/// \brief Reads an AST files chain containing the contents of a translation
/// unit.
///
/// The ASTReader class reads bitstreams (produced by the ASTWriter
/// class) containing the serialized representation of a given
/// abstract syntax tree and its supporting data structures. An
/// instance of the ASTReader can be attached to an ASTContext object,
/// which will provide access to the contents of the AST files.
///
/// The AST reader provides lazy de-serialization of declarations, as
/// required when traversing the AST. Only those AST nodes that are
/// actually required will be de-serialized.
class ASTReader
: public ExternalPreprocessorSource,
public ExternalPreprocessingRecordSource,
public ExternalHeaderFileInfoSource,
public ExternalSemaSource,
public IdentifierInfoLookup,
public ExternalSLocEntrySource
{
public:
typedef SmallVector<uint64_t, 64> RecordData;
typedef SmallVectorImpl<uint64_t> RecordDataImpl;
/// \brief The result of reading the control block of an AST file, which
/// can fail for various reasons.
enum ASTReadResult {
/// \brief The control block was read successfully. Aside from failures,
/// the AST file is safe to read into the current context.
Success,
/// \brief The AST file itself appears corrupted.
Failure,
/// \brief The AST file was missing.
Missing,
/// \brief The AST file is out-of-date relative to its input files,
/// and needs to be regenerated.
OutOfDate,
/// \brief The AST file was written by a different version of Clang.
VersionMismatch,
/// \brief The AST file was writtten with a different language/target
/// configuration.
ConfigurationMismatch,
/// \brief The AST file has errors.
HadErrors
};
/// \brief Types of AST files.
friend class PCHValidator;
friend class ASTDeclReader;
friend class ASTStmtReader;
friend class ASTIdentifierIterator;
friend class serialization::reader::ASTIdentifierLookupTrait;
friend class TypeLocReader;
friend class ASTRecordReader;
friend class ASTWriter;
friend class ASTUnit; // ASTUnit needs to remap source locations.
friend class serialization::ReadMethodPoolVisitor;
typedef serialization::ModuleFile ModuleFile;
typedef serialization::ModuleKind ModuleKind;
typedef serialization::ModuleManager ModuleManager;
typedef ModuleManager::ModuleIterator ModuleIterator;
typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
private:
/// \brief The receiver of some callbacks invoked by ASTReader.
std::unique_ptr<ASTReaderListener> Listener;
/// \brief The receiver of deserialization events.
ASTDeserializationListener *DeserializationListener = nullptr;
bool OwnsDeserializationListener = false;
SourceManager &SourceMgr;
FileManager &FileMgr;
const PCHContainerReader &PCHContainerRdr;
DiagnosticsEngine &Diags;
/// \brief The semantic analysis object that will be processing the
/// AST files and the translation unit that uses it.
Sema *SemaObj = nullptr;
/// \brief The preprocessor that will be loading the source file.
Preprocessor &PP;
/// \brief The AST context into which we'll read the AST files.
ASTContext *ContextObj = nullptr;
/// \brief The AST consumer.
ASTConsumer *Consumer = nullptr;
/// \brief The module manager which manages modules and their dependencies
ModuleManager ModuleMgr;
/// The cache that manages memory buffers for PCM files.
MemoryBufferCache &PCMCache;
/// \brief A dummy identifier resolver used to merge TU-scope declarations in
/// C, for the cases where we don't have a Sema object to provide a real
/// identifier resolver.
IdentifierResolver DummyIdResolver;
/// A mapping from extension block names to module file extensions.
llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
/// \brief A timer used to track the time spent deserializing.
std::unique_ptr<llvm::Timer> ReadTimer;
/// \brief The location where the module file will be considered as
/// imported from. For non-module AST types it should be invalid.
SourceLocation CurrentImportLoc;
/// \brief The global module index, if loaded.
std::unique_ptr<GlobalModuleIndex> GlobalIndex;
/// \brief A map of global bit offsets to the module that stores entities
/// at those bit offsets.
ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
/// \brief A map of negated SLocEntryIDs to the modules containing them.
ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
/// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
/// SourceLocation offsets to the modules containing them.
GlobalSLocOffsetMapType GlobalSLocOffsetMap;
/// \brief Types that have already been loaded from the chain.
///
/// When the pointer at index I is non-NULL, the type with
/// ID = (I + 1) << FastQual::Width has already been loaded
std::vector<QualType> TypesLoaded;
typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
GlobalTypeMapType;
/// \brief Mapping from global type IDs to the module in which the
/// type resides along with the offset that should be added to the
/// global type ID to produce a local ID.
GlobalTypeMapType GlobalTypeMap;
/// \brief Declarations that have already been loaded from the chain.
///
/// When the pointer at index I is non-NULL, the declaration with ID
/// = I + 1 has already been loaded.
std::vector<Decl *> DeclsLoaded;
typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
GlobalDeclMapType;
/// \brief Mapping from global declaration IDs to the module in which the
/// declaration resides.
GlobalDeclMapType GlobalDeclMap;
typedef std::pair<ModuleFile *, uint64_t> FileOffset;
typedef SmallVector<FileOffset, 2> FileOffsetsTy;
typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
DeclUpdateOffsetsMap;
/// \brief Declarations that have modifications residing in a later file
/// in the chain.
DeclUpdateOffsetsMap DeclUpdateOffsets;
struct PendingUpdateRecord {
Decl *D;
serialization::GlobalDeclID ID;
// Whether the declaration was just deserialized.
bool JustLoaded;
PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
bool JustLoaded)
: D(D), ID(ID), JustLoaded(JustLoaded) {}
};
/// \brief Declaration updates for already-loaded declarations that we need
/// to apply once we finish processing an import.
llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
/// \brief The DefinitionData pointers that we faked up for class definitions
/// that we needed but hadn't loaded yet.
llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
/// \brief Exception specification updates that have been loaded but not yet
/// propagated across the relevant redeclaration chain. The map key is the
/// canonical declaration (used only for deduplication) and the value is a
/// declaration that has an exception specification.
llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
/// \brief Declarations that have been imported and have typedef names for
/// linkage purposes.
llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*>
ImportedTypedefNamesForLinkage;
/// \brief Mergeable declaration contexts that have anonymous declarations
/// within them, and those anonymous declarations.
llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>>
AnonymousDeclarationsForMerging;
struct FileDeclsInfo {
ModuleFile *Mod;
ArrayRef<serialization::LocalDeclID> Decls;
FileDeclsInfo() : Mod(nullptr) {}
FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
: Mod(Mod), Decls(Decls) {}
};
/// \brief Map from a FileID to the file-level declarations that it contains.
llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
/// \brief An array of lexical contents of a declaration context, as a sequence of
/// Decl::Kind, DeclID pairs.
typedef ArrayRef<llvm::support::unaligned_uint32_t> LexicalContents;
/// \brief Map from a DeclContext to its lexical contents.
llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
LexicalDecls;
/// \brief Map from the TU to its lexical contents from each module file.
std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
/// \brief Map from a DeclContext to its lookup tables.
llvm::DenseMap<const DeclContext *,
serialization::reader::DeclContextLookupTable> Lookups;
// Updates for visible decls can occur for other contexts than just the
// TU, and when we read those update records, the actual context may not
// be available yet, so have this pending map using the ID as a key. It
// will be realized when the context is actually loaded.
struct PendingVisibleUpdate {
ModuleFile *Mod;
const unsigned char *Data;
};
typedef SmallVector<PendingVisibleUpdate, 1> DeclContextVisibleUpdates;
/// \brief Updates to the visible declarations of declaration contexts that
/// haven't been loaded yet.
llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
PendingVisibleUpdates;
/// \brief The set of C++ or Objective-C classes that have forward
/// declarations that have not yet been linked to their definitions.
llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
typedef llvm::MapVector<Decl *, uint64_t,
llvm::SmallDenseMap<Decl *, unsigned, 4>,
SmallVector<std::pair<Decl *, uint64_t>, 4> >
PendingBodiesMap;
/// \brief Functions or methods that have bodies that will be attached.
PendingBodiesMap PendingBodies;
/// \brief Definitions for which we have added merged definitions but not yet
/// performed deduplication.
llvm::SetVector<NamedDecl*> PendingMergedDefinitionsToDeduplicate;
/// \brief Read the record that describes the lexical contents of a DC.
bool ReadLexicalDeclContextStorage(ModuleFile &M,
llvm::BitstreamCursor &Cursor,
uint64_t Offset, DeclContext *DC);
/// \brief Read the record that describes the visible contents of a DC.
bool ReadVisibleDeclContextStorage(ModuleFile &M,
llvm::BitstreamCursor &Cursor,
uint64_t Offset, serialization::DeclID ID);
/// \brief A vector containing identifiers that have already been
/// loaded.
///
/// If the pointer at index I is non-NULL, then it refers to the
/// IdentifierInfo for the identifier with ID=I+1 that has already
/// been loaded.
std::vector<IdentifierInfo *> IdentifiersLoaded;
typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
GlobalIdentifierMapType;
/// \brief Mapping from global identifier IDs to the module in which the
/// identifier resides along with the offset that should be added to the
/// global identifier ID to produce a local ID.
GlobalIdentifierMapType GlobalIdentifierMap;
/// \brief A vector containing macros that have already been
/// loaded.
///
/// If the pointer at index I is non-NULL, then it refers to the
/// MacroInfo for the identifier with ID=I+1 that has already
/// been loaded.
std::vector<MacroInfo *> MacrosLoaded;
typedef std::pair<IdentifierInfo *, serialization::SubmoduleID>
LoadedMacroInfo;
/// \brief A set of #undef directives that we have loaded; used to
/// deduplicate the same #undef information coming from multiple module
/// files.
llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
GlobalMacroMapType;
/// \brief Mapping from global macro IDs to the module in which the
/// macro resides along with the offset that should be added to the
/// global macro ID to produce a local ID.
GlobalMacroMapType GlobalMacroMap;
/// \brief A vector containing submodules that have already been loaded.
///
/// This vector is indexed by the Submodule ID (-1). NULL submodule entries
/// indicate that the particular submodule ID has not yet been loaded.
SmallVector<Module *, 2> SubmodulesLoaded;
typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
GlobalSubmoduleMapType;
/// \brief Mapping from global submodule IDs to the module file in which the
/// submodule resides along with the offset that should be added to the
/// global submodule ID to produce a local ID.
GlobalSubmoduleMapType GlobalSubmoduleMap;
/// \brief A set of hidden declarations.
typedef SmallVector<Decl*, 2> HiddenNames;
typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
/// \brief A mapping from each of the hidden submodules to the deserialized
/// declarations in that submodule that could be made visible.
HiddenNamesMapType HiddenNamesMap;
/// \brief A module import, export, or conflict that hasn't yet been resolved.
struct UnresolvedModuleRef {
/// \brief The file in which this module resides.
ModuleFile *File;
/// \brief The module that is importing or exporting.
Module *Mod;
/// \brief The kind of module reference.
enum { Import, Export, Conflict } Kind;
/// \brief The local ID of the module that is being exported.
unsigned ID;
/// \brief Whether this is a wildcard export.
unsigned IsWildcard : 1;
/// \brief String data.
StringRef String;
};
/// \brief The set of module imports and exports that still need to be
/// resolved.
SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
/// \brief A vector containing selectors that have already been loaded.
///
/// This vector is indexed by the Selector ID (-1). NULL selector
/// entries indicate that the particular selector ID has not yet
/// been loaded.
SmallVector<Selector, 16> SelectorsLoaded;
typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
GlobalSelectorMapType;
/// \brief Mapping from global selector IDs to the module in which the
/// global selector ID to produce a local ID.
GlobalSelectorMapType GlobalSelectorMap;
/// \brief The generation number of the last time we loaded data from the
/// global method pool for this selector.
llvm::DenseMap<Selector, unsigned> SelectorGeneration;
/// Whether a selector is out of date. We mark a selector as out of date
/// if we load another module after the method pool entry was pulled in.
llvm::DenseMap<Selector, bool> SelectorOutOfDate;
struct PendingMacroInfo {
ModuleFile *M;
uint64_t MacroDirectivesOffset;
PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
: M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
};
typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> >
PendingMacroIDsMap;
/// \brief Mapping from identifiers that have a macro history to the global
/// IDs have not yet been deserialized to the global IDs of those macros.
PendingMacroIDsMap PendingMacroIDs;
typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
GlobalPreprocessedEntityMapType;
/// \brief Mapping from global preprocessing entity IDs to the module in
/// which the preprocessed entity resides along with the offset that should be
/// added to the global preprocessing entity ID to produce a local ID.
GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
/// \name CodeGen-relevant special data
/// \brief Fields containing data that is relevant to CodeGen.
//@{
/// \brief The IDs of all declarations that fulfill the criteria of
/// "interesting" decls.
///
/// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
/// in the chain. The referenced declarations are deserialized and passed to
/// the consumer eagerly.
SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
/// \brief The IDs of all tentative definitions stored in the chain.
///
/// Sema keeps track of all tentative definitions in a TU because it has to
/// complete them and pass them on to CodeGen. Thus, tentative definitions in
/// the PCH chain must be eagerly deserialized.
SmallVector<uint64_t, 16> TentativeDefinitions;
/// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
/// used.
///
/// CodeGen has to emit VTables for these records, so they have to be eagerly
/// deserialized.
SmallVector<uint64_t, 64> VTableUses;
/// \brief A snapshot of the pending instantiations in the chain.
///
/// This record tracks the instantiations that Sema has to perform at the
/// end of the TU. It consists of a pair of values for every pending
/// instantiation where the first value is the ID of the decl and the second
/// is the instantiation location.
SmallVector<uint64_t, 64> PendingInstantiations;
//@}
/// \name DiagnosticsEngine-relevant special data
/// \brief Fields containing data that is used for generating diagnostics
//@{
/// \brief A snapshot of Sema's unused file-scoped variable tracking, for
/// generating warnings.
SmallVector<uint64_t, 16> UnusedFileScopedDecls;
/// \brief A list of all the delegating constructors we've seen, to diagnose
/// cycles.
SmallVector<uint64_t, 4> DelegatingCtorDecls;
/// \brief Method selectors used in a @selector expression. Used for
/// implementation of -Wselector.
SmallVector<uint64_t, 64> ReferencedSelectorsData;
/// \brief A snapshot of Sema's weak undeclared identifier tracking, for
/// generating warnings.
SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
/// \brief The IDs of type aliases for ext_vectors that exist in the chain.
///
/// Used by Sema for finding sugared names for ext_vectors in diagnostics.
SmallVector<uint64_t, 4> ExtVectorDecls;
//@}
/// \name Sema-relevant special data
/// \brief Fields containing data that is used for semantic analysis
//@{
/// \brief The IDs of all potentially unused typedef names in the chain.
///
/// Sema tracks these to emit warnings.
SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
/// \brief Our current depth in #pragma cuda force_host_device begin/end
/// macros.
unsigned ForceCUDAHostDeviceDepth = 0;
/// \brief The IDs of the declarations Sema stores directly.
///
/// Sema tracks a few important decls, such as namespace std, directly.
SmallVector<uint64_t, 4> SemaDeclRefs;
/// \brief The IDs of the types ASTContext stores directly.
///
/// The AST context tracks a few important types, such as va_list, directly.
SmallVector<uint64_t, 16> SpecialTypes;
/// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
///
/// The AST context tracks a few important decls, currently cudaConfigureCall,
/// directly.
SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
/// \brief The floating point pragma option settings.
SmallVector<uint64_t, 1> FPPragmaOptions;
/// \brief The pragma clang optimize location (if the pragma state is "off").
SourceLocation OptimizeOffPragmaLocation;
/// \brief The PragmaMSStructKind pragma ms_struct state if set, or -1.
int PragmaMSStructState = -1;
/// \brief The PragmaMSPointersToMembersKind pragma pointers_to_members state.
int PragmaMSPointersToMembersState = -1;
SourceLocation PointersToMembersPragmaLocation;
/// \brief The pragma pack state.
Optional<unsigned> PragmaPackCurrentValue;
SourceLocation PragmaPackCurrentLocation;
struct PragmaPackStackEntry {
unsigned Value;
SourceLocation Location;
SourceLocation PushLocation;
StringRef SlotLabel;
};
llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
llvm::SmallVector<std::string, 2> PragmaPackStrings;
/// \brief The OpenCL extension settings.
OpenCLOptions OpenCLExtensions;
/// \brief Extensions required by an OpenCL type.
llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
/// \brief Extensions required by an OpenCL declaration.
llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
/// \brief A list of the namespaces we've seen.
SmallVector<uint64_t, 4> KnownNamespaces;
/// \brief A list of undefined decls with internal linkage followed by the
/// SourceLocation of a matching ODR-use.
SmallVector<uint64_t, 8> UndefinedButUsed;
/// \brief Delete expressions to analyze at the end of translation unit.
SmallVector<uint64_t, 8> DelayedDeleteExprs;
// \brief A list of late parsed template function data.
SmallVector<uint64_t, 1> LateParsedTemplates;
public:
struct ImportedSubmodule {
serialization::SubmoduleID ID;
SourceLocation ImportLoc;
ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
: ID(ID), ImportLoc(ImportLoc) {}
};
private:
/// \brief A list of modules that were imported by precompiled headers or
/// any other non-module AST file.
SmallVector<ImportedSubmodule, 2> ImportedModules;
//@}
/// \brief The system include root to be used when loading the
/// precompiled header.
std::string isysroot;
/// \brief Whether to disable the normal validation performed on precompiled
/// headers when they are loaded.
bool DisableValidation;
/// \brief Whether to accept an AST file with compiler errors.
bool AllowASTWithCompilerErrors;
/// \brief Whether to accept an AST file that has a different configuration
/// from the current compiler instance.
bool AllowConfigurationMismatch;
/// \brief Whether validate system input files.
bool ValidateSystemInputs;
/// \brief Whether we are allowed to use the global module index.
bool UseGlobalIndex;
/// \brief Whether we have tried loading the global module index yet.
bool TriedLoadingGlobalIndex = false;
///\brief Whether we are currently processing update records.
bool ProcessingUpdateRecords = false;
typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
/// \brief Mapping from switch-case IDs in the chain to switch-case statements
///
/// Statements usually don't have IDs, but switch cases need them, so that the
/// switch statement can refer to them.
SwitchCaseMapTy SwitchCaseStmts;
SwitchCaseMapTy *CurrSwitchCaseStmts;
/// \brief The number of source location entries de-serialized from
/// the PCH file.
unsigned NumSLocEntriesRead = 0;
/// \brief The number of source location entries in the chain.
unsigned TotalNumSLocEntries = 0;
/// \brief The number of statements (and expressions) de-serialized
/// from the chain.
unsigned NumStatementsRead = 0;
/// \brief The total number of statements (and expressions) stored
/// in the chain.
unsigned TotalNumStatements = 0;
/// \brief The number of macros de-serialized from the chain.
unsigned NumMacrosRead = 0;
/// \brief The total number of macros stored in the chain.
unsigned TotalNumMacros = 0;
/// \brief The number of lookups into identifier tables.
unsigned NumIdentifierLookups = 0;
/// \brief The number of lookups into identifier tables that succeed.
unsigned NumIdentifierLookupHits = 0;
/// \brief The number of selectors that have been read.
unsigned NumSelectorsRead = 0;
/// \brief The number of method pool entries that have been read.
unsigned NumMethodPoolEntriesRead = 0;
/// \brief The number of times we have looked up a selector in the method
/// pool.
unsigned NumMethodPoolLookups = 0;
/// \brief The number of times we have looked up a selector in the method
/// pool and found something.
unsigned NumMethodPoolHits = 0;
/// \brief The number of times we have looked up a selector in the method
/// pool within a specific module.
unsigned NumMethodPoolTableLookups = 0;
/// \brief The number of times we have looked up a selector in the method
/// pool within a specific module and found something.
unsigned NumMethodPoolTableHits = 0;
/// \brief The total number of method pool entries in the selector table.
unsigned TotalNumMethodPoolEntries = 0;
/// Number of lexical decl contexts read/total.
unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
/// Number of visible decl contexts read/total.
unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
/// Total size of modules, in bits, currently loaded
uint64_t TotalModulesSizeInBits = 0;
/// \brief Number of Decl/types that are currently deserializing.
unsigned NumCurrentElementsDeserializing = 0;
/// \brief Set true while we are in the process of passing deserialized
/// "interesting" decls to consumer inside FinishedDeserializing().
/// This is used as a guard to avoid recursively repeating the process of
/// passing decls to consumer.
bool PassingDeclsToConsumer = false;
/// \brief The set of identifiers that were read while the AST reader was
/// (recursively) loading declarations.
///
/// The declarations on the identifier chain for these identifiers will be
/// loaded once the recursive loading has completed.
llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> >
PendingIdentifierInfos;
/// \brief The set of lookup results that we have faked in order to support
/// merging of partially deserialized decls but that we have not yet removed.
llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
PendingFakeLookupResults;
/// \brief The generation number of each identifier, which keeps track of
/// the last time we loaded information about this identifier.
llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
class InterestingDecl {
Decl *D;
bool DeclHasPendingBody;
public:
InterestingDecl(Decl *D, bool HasBody)
: D(D), DeclHasPendingBody(HasBody) {}