diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 110 | ||||
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 12 | ||||
-rw-r--r-- | include/clang/Serialization/ASTDeserializationListener.h | 2 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 41 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 19 | ||||
-rw-r--r-- | include/clang/Serialization/Module.h | 19 |
6 files changed, 75 insertions, 128 deletions
diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index e98a1bad22..0cc6cc5377 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -44,6 +44,9 @@ namespace clang { public: /// \brief The kind of preprocessed entity an object describes. enum EntityKind { + /// \brief Indicates a problem trying to load the preprocessed entity. + InvalidKind, + /// \brief A macro expansion. MacroExpansionKind, @@ -74,7 +77,9 @@ namespace clang { protected: PreprocessedEntity(EntityKind Kind, SourceRange Range) : Kind(Kind), Range(Range) { } - + + friend class PreprocessingRecord; + public: /// \brief Retrieve the kind of preprocessed entity stored in this object. EntityKind getKind() const { return Kind; } @@ -82,7 +87,11 @@ namespace clang { /// \brief Retrieve the source range that covers this entire preprocessed /// entity. SourceRange getSourceRange() const { return Range; } - + + /// \brief Returns true if there was a problem loading the preprocessed + /// entity. + bool isInvalid() const { return Kind == InvalidKind; } + // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *) { return true; } @@ -256,10 +265,12 @@ namespace clang { public: virtual ~ExternalPreprocessingRecordSource(); - /// \brief Read any preallocated preprocessed entities from the external - /// source. - virtual void ReadPreprocessedEntities() = 0; - + /// \brief Read a preallocated preprocessed entity from the external source. + /// + /// \returns null if an error occurred that prevented the preprocessed + /// entity from being loaded. + virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) = 0; + /// \brief Read the preprocessed entity at the given offset. virtual PreprocessedEntity * ReadPreprocessedEntityAtOffset(uint64_t Offset) = 0; @@ -286,17 +297,47 @@ namespace clang { /// The entries in this vector are loaded lazily from the external source, /// and are referenced by the iterator using negative indices. std::vector<PreprocessedEntity *> LoadedPreprocessedEntities; - + + /// \brief Global (loaded or local) ID for a preprocessed entity. + /// Negative values are used to indicate preprocessed entities + /// loaded from the external source while non-negative values are used to + /// indicate preprocessed entities introduced by the current preprocessor. + /// If M is the number of loaded preprocessed entities, value -M + /// corresponds to element 0 in the loaded entities vector, position -M+1 + /// corresponds to element 1 in the loaded entities vector, etc. + typedef int PPEntityID; + + PPEntityID getPPEntityID(unsigned Index, bool isLoaded) const { + return isLoaded ? PPEntityID(Index) - LoadedPreprocessedEntities.size() + : Index; + } + /// \brief Mapping from MacroInfo structures to their definitions. - llvm::DenseMap<const MacroInfo *, MacroDefinition *> MacroDefinitions; + llvm::DenseMap<const MacroInfo *, PPEntityID> MacroDefinitions; /// \brief External source of preprocessed entities. ExternalPreprocessingRecordSource *ExternalSource; + + /// \brief Retrieve the preprocessed entity at the given ID. + PreprocessedEntity *getPreprocessedEntity(PPEntityID PPID); + + /// \brief Retrieve the loaded preprocessed entity at the given index. + PreprocessedEntity *getLoadedPreprocessedEntity(unsigned Index); - /// \brief Whether we have already loaded all of the preallocated entities. - mutable bool LoadedPreallocatedEntities; + /// \brief Determine the number of preprocessed entities that were + /// loaded (or can be loaded) from an external source. + unsigned getNumLoadedPreprocessedEntities() const { + return LoadedPreprocessedEntities.size(); + } - void MaybeLoadPreallocatedEntities() const ; + /// \brief Allocate space for a new set of loaded preprocessed entities. + /// + /// \returns The index into the set of loaded preprocessed entities, which + /// corresponds to the first newly-allocated entity. + unsigned allocateLoadedEntities(unsigned NumEntities); + + /// \brief Register a new macro definition. + void RegisterMacroDefinition(MacroInfo *Macro, PPEntityID PPID); public: /// \brief Construct a new preprocessing record. @@ -328,7 +369,7 @@ namespace clang { /// corresponds to element 0 in the loaded entities vector, position -M+1 /// corresponds to element 1 in the loaded entities vector, etc. This /// gives us a reasonably efficient, source-order walk. - int Position; + PPEntityID Position; public: typedef PreprocessedEntity *value_type; @@ -342,20 +383,11 @@ namespace clang { iterator(PreprocessingRecord *Self, int Position) : Self(Self), Position(Position) { } - reference operator*() const { - if (Position < 0) - return Self->LoadedPreprocessedEntities.end()[Position]; - return Self->PreprocessedEntities[Position]; - } - - pointer operator->() const { - if (Position < 0) - return &Self->LoadedPreprocessedEntities.end()[Position]; - - return &Self->PreprocessedEntities[Position]; + value_type operator*() const { + return Self->getPreprocessedEntity(Position); } - reference operator[](difference_type D) { + value_type operator[](difference_type D) { return *(*this + D); } @@ -450,33 +482,6 @@ namespace clang { return ExternalSource; } - /// \brief Allocate space for a new set of loaded preprocessed entities. - /// - /// \returns The index into the set of loaded preprocessed entities, which - /// corresponds to the first newly-allocated entity. - unsigned allocateLoadedEntities(unsigned NumEntities); - - /// \brief Set the preallocated entry at the given index to the given - /// preprocessed entity, which was loaded from the external source. - void setLoadedPreallocatedEntity(unsigned Index, - PreprocessedEntity *Entity); - - /// \brief Register a new macro definition. - void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinition *MD); - - /// \brief Retrieve the loaded preprocessed entity at the given index. - PreprocessedEntity *getLoadedPreprocessedEntity(unsigned Index) { - assert(Index < LoadedPreprocessedEntities.size() && - "Out-of bounds loaded preprocessed entity"); - return LoadedPreprocessedEntities[Index]; - } - - /// \brief Determine the number of preprocessed entities that were - /// loaded (or can be loaded) from an external source. - unsigned getNumLoadedPreprocessedEntities() const { - return LoadedPreprocessedEntities.size(); - } - /// \brief Retrieve the macro definition that corresponds to the given /// \c MacroInfo. MacroDefinition *findMacroDefinition(const MacroInfo *MI); @@ -493,6 +498,9 @@ namespace clang { SourceLocation EndLoc, StringRef SearchPath, StringRef RelativePath); + + friend class ASTReader; + friend class ASTWriter; }; } // end namespace clang diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 0c3e72c081..f3dd8dc860 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -127,12 +127,6 @@ namespace clang { /// \brief The number of predefined identifier IDs. const unsigned int NUM_PREDEF_IDENT_IDS = 1; - /// \brief An ID number that refers to a macro in an AST file. - typedef uint32_t MacroID; - - /// \brief The number of predefined macro IDs. - const unsigned int NUM_PREDEF_MACRO_IDS = 1; - /// \brief An ID number that refers to an ObjC selctor in an AST file. typedef uint32_t SelectorID; @@ -312,9 +306,9 @@ namespace clang { /// \brief Record code for the array of unused file scoped decls. UNUSED_FILESCOPED_DECLS = 22, - /// \brief Record code for the table of offsets to macro definition - /// entries in the preprocessing record. - MACRO_DEFINITION_OFFSETS = 23, + /// \brief Record code for the table of offsets to entries in the + /// preprocessing record. + PPD_ENTITIES_OFFSETS = 23, /// \brief Record code for the array of VTable uses. VTABLE_USES = 24, diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h index f8cdebe5a9..588fe0e63c 100644 --- a/include/clang/Serialization/ASTDeserializationListener.h +++ b/include/clang/Serialization/ASTDeserializationListener.h @@ -45,7 +45,7 @@ public: /// \brief A selector was read from the AST file. virtual void SelectorRead(serialization::SelectorID iD, Selector Sel) { } /// \brief A macro definition was read from the AST file. - virtual void MacroDefinitionRead(serialization::MacroID, + virtual void MacroDefinitionRead(serialization::PreprocessedEntityID, MacroDefinition *MD) { } }; diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 86bb62ae19..9f3973bc24 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -357,17 +357,6 @@ private: /// global selector ID to produce a local ID. GlobalSelectorMapType GlobalSelectorMap; - /// \brief The macro definitions we have already loaded. - SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded; - - typedef ContinuousRangeMap<serialization::MacroID, Module *, 4> - GlobalMacroDefinitionMapType; - - /// \brief Mapping from global macro definition IDs to the module in which the - /// selector resides along with the offset that should be added to the - /// global selector ID to produce a local ID. - GlobalMacroDefinitionMapType GlobalMacroDefinitionMap; - /// \brief Mapping from identifiers that represent macros whose definitions /// have not yet been deserialized to the global offset where the macro /// record resides. @@ -776,9 +765,12 @@ public: /// which contains a (typically-empty) subset of the predefines /// build prior to including the precompiled header. const std::string &getSuggestedPredefines() { return SuggestedPredefines; } - - /// \brief Read preprocessed entities into the preprocessing record. - virtual void ReadPreprocessedEntities(); + + /// \brief Read a preallocated preprocessed entity from the external source. + /// + /// \returns null if an error occurred that prevented the preprocessed + /// entity from being loaded. + virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index); /// \brief Read the preprocessed entity at the given offset. virtual PreprocessedEntity *ReadPreprocessedEntityAtOffset(uint64_t Offset); @@ -819,16 +811,11 @@ public: unsigned Result = 0; for (ModuleConstIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { - Result += (*I)->NumPreallocatedPreprocessingEntities; + Result += (*I)->NumPreprocessedEntities; } return Result; } - - /// \brief Returns the number of macro definitions found in the chain. - unsigned getTotalNumMacroDefinitions() const { - return static_cast<unsigned>(MacroDefinitionsLoaded.size()); - } /// \brief Returns the number of C++ base specifiers found in the chain. unsigned getTotalNumCXXBaseSpecifiers() const { @@ -1245,20 +1232,6 @@ public: /// into the unread macro record offsets table. void LoadMacroDefinition( llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos); - - /// \brief Retrieve the macro definition with the given ID. - MacroDefinition *getMacroDefinition(serialization::MacroID ID); - - /// \brief Retrieve the global macro definition ID that corresponds to the - /// local macro definition ID within a given module. - serialization::MacroID getGlobalMacroDefinitionID(Module &M, - unsigned LocalID); - - /// \brief Deserialize a macro definition that is local to the given - /// module. - MacroDefinition *getLocalMacroDefinition(Module &M, unsigned LocalID) { - return getMacroDefinition(getGlobalMacroDefinitionID(M, LocalID)); - } /// \brief Retrieve the AST context that this AST reader supplements. ASTContext &getContext() { return Context; } diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index d872ce260b..1ecab72afa 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -205,21 +205,11 @@ private: /// \brief The set of identifiers that had macro definitions at some point. std::vector<const IdentifierInfo *> DeserializedMacroNames; - - /// \brief The first ID number we can use for our own macro definitions. - serialization::MacroID FirstMacroID; - - /// \brief The decl ID that will be assigned to the next new macro definition. - serialization::MacroID NextMacroID; /// \brief Mapping from macro definitions (as they occur in the preprocessing /// record) to the macro IDs. - llvm::DenseMap<const MacroDefinition *, serialization::MacroID> + llvm::DenseMap<const MacroDefinition *, serialization::PreprocessedEntityID> MacroDefinitions; - - /// \brief Mapping from the macro definition indices in \c MacroDefinitions - /// to the corresponding offsets within the preprocessor block. - std::vector<uint32_t> MacroDefinitionOffsets; typedef SmallVector<uint64_t, 2> UpdateRecord; typedef llvm::DenseMap<const Decl *, UpdateRecord> DeclUpdateMap; @@ -461,10 +451,6 @@ public: "Identifier does not name a macro"); return MacroOffsets[II]; } - - /// \brief Retrieve the ID number corresponding to the given macro - /// definition. - serialization::MacroID getMacroDefinitionID(MacroDefinition *MD); /// \brief Emit a reference to a type. void AddTypeRef(QualType T, RecordDataImpl &Record); @@ -626,7 +612,8 @@ public: void TypeRead(serialization::TypeIdx Idx, QualType T); void DeclRead(serialization::DeclID ID, const Decl *D); void SelectorRead(serialization::SelectorID ID, Selector Sel); - void MacroDefinitionRead(serialization::MacroID ID, MacroDefinition *MD); + void MacroDefinitionRead(serialization::PreprocessedEntityID ID, + MacroDefinition *MD); // ASTMutationListener implementation. virtual void CompletedTagDefinition(const TagDecl *D); diff --git a/include/clang/Serialization/Module.h b/include/clang/Serialization/Module.h index c35a4f0096..9f063316c1 100644 --- a/include/clang/Serialization/Module.h +++ b/include/clang/Serialization/Module.h @@ -177,19 +177,8 @@ public: /// \brief Remapping table for preprocessed entity IDs in this module. ContinuousRangeMap<uint32_t, int, 2> PreprocessedEntityRemap; - /// \brief The number of macro definitions in this file. - unsigned LocalNumMacroDefinitions; - - /// \brief Offsets of all of the macro definitions in the preprocessing - /// record in the AST file. - const uint32_t *MacroDefinitionOffsets; - - /// \brief Base macro definition ID for macro definitions local to this - /// module. - serialization::MacroID BaseMacroDefinitionID; - - /// \brief Remapping table for macro definition IDs in this module. - ContinuousRangeMap<uint32_t, int, 2> MacroDefinitionRemap; + const uint32_t *PreprocessedEntityOffsets; + unsigned NumPreprocessedEntities; // === Header search information === @@ -309,10 +298,6 @@ public: /// The dynamic type of this stat cache is always ASTStatCache void *StatCache; - /// \brief The number of preallocated preprocessing entities in the - /// preprocessing record. - unsigned NumPreallocatedPreprocessingEntities; - /// \brief List of modules which depend on this module llvm::SetVector<Module *> ImportedBy; |