From 2d7d5c241bce687a4c7018a023efb7b22769ca9d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Jun 2017 02:19:42 +0000 Subject: Track the set of module maps read while building a .pcm file and reload those when preprocessing from that .pcm file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306628 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 50 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'include/clang/Basic/SourceManager.h') diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 5e01f64167..e658af742e 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -80,9 +80,19 @@ namespace SrcMgr { /// system_header is seen or in various other cases. /// enum CharacteristicKind { - C_User, C_System, C_ExternCSystem + C_User, C_System, C_ExternCSystem, C_User_ModuleMap, C_System_ModuleMap }; + /// Determine whether a file / directory characteristic is for system code. + inline bool isSystem(CharacteristicKind CK) { + return CK != C_User && CK != C_User_ModuleMap; + } + + /// Determine whether a file characteristic is for a module map. + inline bool isModuleMap(CharacteristicKind CK) { + return CK == C_User_ModuleMap || CK == C_System_ModuleMap; + } + /// \brief One instance of this struct is kept for every file loaded or used. /// /// This object owns the MemoryBuffer object. @@ -251,12 +261,14 @@ namespace SrcMgr { /// preprocessing of this \#include, including this SLocEntry. /// /// Zero means the preprocessor didn't provide such info for this SLocEntry. - unsigned NumCreatedFIDs; + unsigned NumCreatedFIDs : 31; + + /// \brief Whether this FileInfo has any \#line directives. + unsigned HasLineDirectives : 1; - /// \brief Contains the ContentCache* and the bits indicating the - /// characteristic of the file and whether it has \#line info, all - /// bitmangled together. - uintptr_t Data; + /// \brief The content cache and the characteristic of the file. + llvm::PointerIntPair + ContentAndKind; friend class clang::SourceManager; friend class clang::ASTWriter; @@ -269,10 +281,9 @@ namespace SrcMgr { FileInfo X; X.IncludeLoc = IL.getRawEncoding(); X.NumCreatedFIDs = 0; - X.Data = (uintptr_t)Con; - assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned"); - assert((unsigned)FileCharacter < 4 && "invalid file character"); - X.Data |= (unsigned)FileCharacter; + X.HasLineDirectives = false; + X.ContentAndKind.setPointer(Con); + X.ContentAndKind.setInt(FileCharacter); return X; } @@ -280,22 +291,22 @@ namespace SrcMgr { return SourceLocation::getFromRawEncoding(IncludeLoc); } - const ContentCache* getContentCache() const { - return reinterpret_cast(Data & ~uintptr_t(7)); + const ContentCache *getContentCache() const { + return ContentAndKind.getPointer(); } /// \brief Return whether this is a system header or not. CharacteristicKind getFileCharacteristic() const { - return (CharacteristicKind)(Data & 3); + return ContentAndKind.getInt(); } /// \brief Return true if this FileID has \#line directives in it. - bool hasLineDirectives() const { return (Data & 4) != 0; } + bool hasLineDirectives() const { return HasLineDirectives; } /// \brief Set the flag that indicates that this FileID has /// line table entries associated with it. void setHasLineDirectives() { - Data |= 4; + HasLineDirectives = true; } }; @@ -407,6 +418,8 @@ namespace SrcMgr { }; public: + SLocEntry() : Offset(), IsExpansion(), File() {} + unsigned getOffset() const { return Offset; } bool isExpansion() const { return IsExpansion; } @@ -789,9 +802,8 @@ public: FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID = 0, unsigned LoadedOffset = 0) { - const SrcMgr::ContentCache * - IR = getOrCreateContentCache(SourceFile, - /*isSystemFile=*/FileCharacter != SrcMgr::C_User); + const SrcMgr::ContentCache *IR = + getOrCreateContentCache(SourceFile, isSystem(FileCharacter)); assert(IR && "getOrCreateContentCache() cannot return NULL"); return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset); } @@ -1360,7 +1372,7 @@ public: /// \brief Returns if a SourceLocation is in a system header. bool isInSystemHeader(SourceLocation Loc) const { - return getFileCharacteristic(Loc) != SrcMgr::C_User; + return isSystem(getFileCharacteristic(Loc)); } /// \brief Returns if a SourceLocation is in an "extern C" system header. -- cgit v1.2.3