summaryrefslogtreecommitdiffstats
path: root/include/clang/Serialization/ASTReader.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Serialization/ASTReader.h')
-rw-r--r--include/clang/Serialization/ASTReader.h167
1 files changed, 97 insertions, 70 deletions
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index 840655e..588a6a9 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -30,6 +30,7 @@
#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/APFloat.h"
#include "llvm/ADT/APInt.h"
@@ -38,6 +39,7 @@
#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/Bitcode/BitstreamReader.h"
@@ -179,7 +181,8 @@ public:
unsigned Value) {}
/// This is called for each AST file loaded.
- virtual void visitModuleFile(StringRef Filename) {}
+ 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.
@@ -194,7 +197,7 @@ public:
///
/// \returns true to continue receiving the next input file, false to stop.
virtual bool visitInputFile(StringRef Filename, bool isSystem,
- bool isOverridden) {
+ bool isOverridden, bool isExplicitModule) {
return true;
}
@@ -204,6 +207,10 @@ public:
/// \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.
@@ -242,9 +249,12 @@ public:
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
bool needsInputFileVisitation() override;
bool needsSystemInputFileVisitation() override;
- void visitModuleFile(StringRef Filename) override;
+ void visitModuleFile(StringRef Filename,
+ serialization::ModuleKind Kind) override;
bool visitInputFile(StringRef Filename, bool isSystem,
- bool isOverridden) override;
+ bool isOverridden, bool isExplicitModule) override;
+ void readModuleFileExtension(
+ const ModuleFileExtensionMetadata &Metadata) override;
};
/// \brief ASTReaderListener implementation to validate the information of
@@ -280,9 +290,8 @@ class ReadMethodPoolVisitor;
namespace reader {
class ASTIdentifierLookupTrait;
- /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
- typedef llvm::OnDiskIterableChainedHashTable<ASTDeclContextNameLookupTrait>
- ASTDeclContextNameLookupTable;
+ /// \brief The on-disk hash table(s) used for DeclContext name lookup.
+ struct DeclContextLookupTable;
}
} // end namespace serialization
@@ -381,6 +390,9 @@ private:
/// \brief The module manager which manages modules and their dependencies
ModuleManager ModuleMgr;
+ /// A mapping from extension block names to module file extensions.
+ llvm::StringMap<IntrusiveRefCntPtr<ModuleFileExtension>> ModuleFileExtensions;
+
/// \brief A timer used to track the time spent deserializing.
std::unique_ptr<llvm::Timer> ReadTimer;
@@ -494,20 +506,36 @@ private:
/// \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 will not
- // be available yet (unless it's the TU), so have this pending map using the
- // ID as a key. It will be realized when the context is actually loaded.
- typedef
- SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
- ModuleFile*>, 1> DeclContextVisibleUpdates;
- typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
- DeclContextVisibleUpdatesPending;
+ // 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.
- DeclContextVisibleUpdatesPending PendingVisibleUpdates;
-
+ 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;
@@ -524,11 +552,14 @@ private:
/// performed deduplication.
llvm::SetVector<NamedDecl*> PendingMergedDefinitionsToDeduplicate;
- /// \brief Read the records that describe the contents of declcontexts.
- bool ReadDeclContextStorage(ModuleFile &M,
- llvm::BitstreamCursor &Cursor,
- const std::pair<uint64_t, uint64_t> &Offsets,
- serialization::DeclContextInfo &Info);
+ /// \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.
@@ -914,20 +945,10 @@ private:
/// Objective-C protocols.
std::deque<Decl *> InterestingDecls;
- /// \brief The set of redeclarable declarations that have been deserialized
- /// since the last time the declaration chains were linked.
- llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
-
/// \brief The list of redeclaration chains that still need to be
- /// reconstructed.
- ///
- /// Each element is the canonical declaration of the chain.
- /// Elements in this vector should be unique; use
- /// PendingDeclChainsKnown to ensure uniqueness.
- SmallVector<Decl *, 16> PendingDeclChains;
-
- /// \brief Keeps track of the elements added to PendingDeclChains.
- llvm::SmallSet<Decl *, 16> PendingDeclChainsKnown;
+ /// reconstructed, and the local offset to the corresponding list
+ /// of redeclarations.
+ SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
/// \brief The list of canonical declarations whose redeclaration chains
/// need to be marked as incomplete once we're done deserializing things.
@@ -972,13 +993,6 @@ private:
/// module is loaded.
SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
- /// \brief A mapping from a primary context for a declaration chain to the
- /// other declarations of that entity that also have name lookup tables.
- /// Used when we merge together two class definitions that have different
- /// sets of declared special member functions.
- llvm::DenseMap<const DeclContext*, SmallVector<const DeclContext*, 2>>
- MergedLookups;
-
typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
KeyDeclsMap;
@@ -1044,12 +1058,11 @@ private:
off_t StoredSize;
time_t StoredTime;
bool Overridden;
+ bool Transient;
};
/// \brief Reads the stored information about an input file.
InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
- /// \brief A convenience method to read the filename from an input file.
- std::string getInputFileName(ModuleFile &F, unsigned ID);
/// \brief Retrieve the file entry and 'overridden' bit for an input
/// file in the given module file.
@@ -1090,6 +1103,10 @@ public:
Visit(GetExistingDecl(ID));
}
+ /// \brief Get the loaded lookup tables for \p Primary, if any.
+ const serialization::reader::DeclContextLookupTable *
+ getLoadedLookupTables(DeclContext *Primary) const;
+
private:
struct ImportedModule {
ModuleFile *Mod;
@@ -1112,7 +1129,12 @@ private:
SmallVectorImpl<ImportedModule> &Loaded,
const ModuleFile *ImportedBy,
unsigned ClientLoadCapabilities);
+ static ASTReadResult ReadOptionsBlock(
+ llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
+ bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
+ std::string &SuggestedPredefines);
ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
+ ASTReadResult ReadExtensionBlock(ModuleFile &F);
bool ParseLineTable(ModuleFile &F, const RecordData &Record);
bool ReadSourceManagerBlock(ModuleFile &F);
llvm::BitstreamCursor &SLocCursorForID(int ID);
@@ -1163,7 +1185,7 @@ private:
RecordLocation DeclCursorForID(serialization::DeclID ID,
unsigned &RawLocation);
void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
- void loadPendingDeclChain(Decl *D);
+ void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
unsigned PreviousGeneration = 0);
@@ -1261,9 +1283,12 @@ public:
/// \param Context the AST context that this precompiled header will be
/// loaded into.
///
- /// \param PCHContainerOps the PCHContainerOperations to use for loading and
+ /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
/// creating modules.
///
+ /// \param Extensions the list of module file extensions that can be loaded
+ /// from the AST files.
+ ///
/// \param isysroot If non-NULL, the system include path specified by the
/// user. This is only used with relocatable PCH files. If non-NULL,
/// a relocatable PCH file will use the default path "/".
@@ -1290,6 +1315,7 @@ public:
/// deserializing.
ASTReader(Preprocessor &PP, ASTContext &Context,
const PCHContainerReader &PCHContainerRdr,
+ ArrayRef<IntrusiveRefCntPtr<ModuleFileExtension>> Extensions,
StringRef isysroot = "", bool DisableValidation = false,
bool AllowASTWithCompilerErrors = false,
bool AllowConfigurationMismatch = false,
@@ -1300,6 +1326,7 @@ public:
SourceManager &getSourceManager() const { return SourceMgr; }
FileManager &getFileManager() const { return FileMgr; }
+ DiagnosticsEngine &getDiags() const { return Diags; }
/// \brief Flags that indicate what kind of AST loading failures the client
/// of the AST reader can directly handle.
@@ -1467,6 +1494,7 @@ public:
static bool
readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
const PCHContainerReader &PCHContainerRdr,
+ bool FindModuleFileExtensions,
ASTReaderListener &Listener);
/// \brief Determine whether the given AST file is acceptable to load into a
@@ -1684,7 +1712,7 @@ public:
/// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
/// specified cursor. Read the abbreviations that are at the top of the block
/// and then leave the cursor pointing into the block.
- bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
+ static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
/// \brief Finds all the visible declarations with a given name.
/// The current implementation of this method just loads the entire
@@ -1698,16 +1726,17 @@ public:
/// \param DC The declaration context whose declarations will be
/// read.
///
+ /// \param IsKindWeWant A predicate indicating which declaration kinds
+ /// we are interested in.
+ ///
/// \param Decls Vector that will contain the declarations loaded
/// from the external source. The caller is responsible for merging
/// these declarations with any declarations already stored in the
/// declaration context.
- ///
- /// \returns true if there was an error while reading the
- /// declarations for this declaration context.
- ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
- bool (*isKindWeWant)(Decl::Kind),
- SmallVectorImpl<Decl*> &Decls) override;
+ void
+ FindExternalLexicalDecls(const DeclContext *DC,
+ llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
+ SmallVectorImpl<Decl *> &Decls) override;
/// \brief Get the decls that are contained in a file in the Offset/Length
/// range. \p Length can be 0 to indicate a point at \p Offset instead of
@@ -1755,10 +1784,7 @@ public:
/// declarations with this name are visible from translation unit scope, their
/// declarations will be deserialized and introduced into the declaration
/// chain of the identifier.
- virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
- IdentifierInfo *get(StringRef Name) override {
- return get(Name.begin(), Name.end());
- }
+ IdentifierInfo *get(StringRef Name) override;
/// \brief Retrieve an iterator into the set of all identifiers
/// in all loaded AST files.
@@ -1873,10 +1899,15 @@ public:
/// Note: overrides method in ExternalASTSource
Module *getModule(unsigned ID) override;
+ /// \brief Retrieve the module file with a given local ID within the specified
+ /// ModuleFile.
+ ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
+
+ /// \brief Get an ID for the given module file.
+ unsigned getModuleFileID(ModuleFile *M);
+
/// \brief Return a descriptor for the corresponding module.
llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
- /// \brief Return a descriptor for the module.
- ASTSourceDescriptor getSourceDescriptor(const Module &M) override;
/// \brief Retrieve a selector from the given module with its local ID
/// number.
@@ -1921,8 +1952,9 @@ public:
unsigned &Idx);
/// \brief Read a template argument.
- TemplateArgument ReadTemplateArgument(ModuleFile &F,
- const RecordData &Record,unsigned &Idx);
+ TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
+ unsigned &Idx,
+ bool Canonicalize = false);
/// \brief Read a template parameter list.
TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
@@ -1930,10 +1962,9 @@ public:
unsigned &Idx);
/// \brief Read a template argument array.
- void
- ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
- ModuleFile &F, const RecordData &Record,
- unsigned &Idx);
+ void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
+ ModuleFile &F, const RecordData &Record,
+ unsigned &Idx, bool Canonicalize = false);
/// \brief Read a UnresolvedSet structure.
void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
@@ -2082,12 +2113,8 @@ public:
SmallVector<std::pair<llvm::BitstreamCursor,
serialization::ModuleFile *>, 8> CommentsCursors;
- //RIDErief Loads comments ranges.
+ /// \brief Loads comments ranges.
void ReadComments() override;
-
- /// Return all input files for the given module file.
- void getInputFiles(ModuleFile &F,
- SmallVectorImpl<serialization::InputFile> &Files);
};
/// \brief Helper class that saves the current stream position and
OpenPOWER on IntegriCloud