diff options
-rw-r--r-- | clang/Driver/PrintPreprocessedOutput.cpp | 12 | ||||
-rw-r--r-- | clang/include/clang/Basic/SourceManager.h | 48 | ||||
-rw-r--r-- | clang/include/clang/Lex/DirectoryLookup.h | 24 | ||||
-rw-r--r-- | clang/include/clang/Lex/HeaderSearch.h | 12 | ||||
-rw-r--r-- | clang/include/clang/Lex/PPCallbacks.h | 2 | ||||
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Driver/InitHeaderSearch.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Lex/Pragma.cpp | 3 |
10 files changed, 71 insertions, 71 deletions
diff --git a/clang/Driver/PrintPreprocessedOutput.cpp b/clang/Driver/PrintPreprocessedOutput.cpp index 7edfc374837..570b36b6942 100644 --- a/clang/Driver/PrintPreprocessedOutput.cpp +++ b/clang/Driver/PrintPreprocessedOutput.cpp @@ -48,7 +48,7 @@ public: private: unsigned CurLine; bool EmittedTokensOnThisLine; - DirectoryLookup::DirType FileType; + SrcMgr::Characteristic_t FileType; llvm::SmallString<512> CurFilename; bool Initialized; public: @@ -57,7 +57,7 @@ public: CurLine = 0; CurFilename += "<uninit>"; EmittedTokensOnThisLine = false; - FileType = DirectoryLookup::NormalHeaderDir; + FileType = SrcMgr::C_User; Initialized = false; } @@ -65,7 +65,7 @@ public: bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; } virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, - DirectoryLookup::DirType FileType); + SrcMgr::Characteristic_t FileType); virtual void Ident(SourceLocation Loc, const std::string &str); @@ -91,9 +91,9 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo, if (ExtraLen) OS.write(Extra, ExtraLen); - if (FileType == DirectoryLookup::SystemHeaderDir) + if (FileType == SrcMgr::C_System) OS.write(" 3", 2); - else if (FileType == DirectoryLookup::ExternCSystemHeaderDir) + else if (FileType == SrcMgr::C_ExternCSystem) OS.write(" 3 4", 4); OS << '\n'; } @@ -143,7 +143,7 @@ bool PrintPPOutputPPCallbacks::MoveToLine(SourceLocation Loc) { /// position. void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, - DirectoryLookup::DirType NewFileType) { + SrcMgr::Characteristic_t NewFileType) { // Unless we are exiting a #include, make sure to skip ahead to the line the // #include directive was at. SourceManager &SourceMgr = PP.getSourceManager(); diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index c8a0b490d71..7d28db20e58 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -32,9 +32,20 @@ class FileManager; class FileEntry; class IdentifierTokenInfo; -/// SrcMgr - Private classes that are part of the SourceManager implementation. +/// SrcMgr - Public enums and private classes that are part of the +/// SourceManager implementation. /// namespace SrcMgr { + /// Characteristic_t - This is used to represent whether a file or directory + /// holds normal user code, system code, or system code which is implicitly + /// 'extern "C"' in C++ mode. Entire directories can be tagged with this + /// (this is maintained by DirectoryLookup and friends) as can specific + /// FileIDInfos when a #pragma system_header is seen or various other cases. + /// + enum Characteristic_t { + C_User, C_System, C_ExternCSystem + }; + /// ContentCache - Once instance of this struct is kept for every file /// loaded or used. This object owns the MemoryBuffer object. struct ContentCache { @@ -114,9 +125,9 @@ namespace SrcMgr { /// chunk number of this FileID. unsigned ChunkNo : 30; - /// DirCharacteristic - This is an instance of DirectoryLookup::DirType, + /// FileCharacteristic - This is an instance of Characteristic_t, /// indicating whether this is a system header dir or not. - unsigned DirCharacteristic : 2; + unsigned FileCharacteristic : 2; /// Content - Information about the source buffer itself. const ContentCache* Content; @@ -124,12 +135,13 @@ namespace SrcMgr { public: /// get - Return a FileIDInfo object. static FileIDInfo get(SourceLocation IL, unsigned CN, - const ContentCache *Con, unsigned DirCharacter) { + const ContentCache *Con, + Characteristic_t FileCharacter) { FileIDInfo X; X.IncludeLoc = IL; X.ChunkNo = CN; X.Content = Con; - X.DirCharacteristic = DirCharacter; + X.FileCharacteristic = FileCharacter; return X; } @@ -137,9 +149,10 @@ namespace SrcMgr { unsigned getChunkNo() const { return ChunkNo; } const ContentCache* getContentCache() const { return Content; } - /// getDirCharacteristic - Return whether this is a system header or not. - /// FIXME: rename from dir to file? - unsigned getDirCharacteristic() const { return DirCharacteristic; } + /// getCharacteristic - Return whether this is a system header or not. + Characteristic_t getFileCharacteristic() const { + return (Characteristic_t)FileCharacteristic; + } /// Emit - Emit this FileIDInfo to Bitcode. void Emit(llvm::Serializer& S) const; @@ -254,10 +267,10 @@ public: /// being #included from the specified IncludePosition. This returns 0 on /// error and translates NULL into standard input. unsigned createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, - unsigned DirCharacter) { + SrcMgr::Characteristic_t FileCharacter) { const SrcMgr::ContentCache *IR = getContentCache(SourceFile); if (IR == 0) return 0; // Error opening file? - return createFileID(IR, IncludePos, DirCharacter); + return createFileID(IR, IncludePos, FileCharacter); } /// createMainFileID - Create the FileID for the main source file. @@ -265,7 +278,7 @@ public: SourceLocation IncludePos) { assert (MainFileID == 0 && "MainFileID already set!"); - MainFileID = createFileID(SourceFile, IncludePos, 0); + MainFileID = createFileID(SourceFile, IncludePos, SrcMgr::C_User); return MainFileID; } @@ -274,8 +287,7 @@ public: /// ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once. unsigned createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) { return createFileID(createMemBufferContentCache(Buffer), SourceLocation(), - // FIXME: USE ENUM - 0/*normal header*/); + SrcMgr::C_User); } /// createMainFileIDForMembuffer - Create the FileID for a memory buffer @@ -436,11 +448,10 @@ public: /// isInSystemHeader - Returns if a SourceLocation is in a system header. bool isInSystemHeader(SourceLocation Loc) const { - // FIXME: Use proper enum here! - return getDirCharacteristic(Loc) != 0; + return getFileCharacteristic(Loc) != SrcMgr::C_User; } - unsigned getDirCharacteristic(SourceLocation Loc) const { - return getFIDInfo(getPhysicalLoc(Loc).getFileID())->getDirCharacteristic(); + SrcMgr::Characteristic_t getFileCharacteristic(SourceLocation Loc) const { + return getFIDInfo(getPhysicalLoc(Loc).getFileID())->getFileCharacteristic(); } @@ -462,7 +473,8 @@ private: /// include position. This works regardless of whether the ContentCache /// corresponds to a file or some other input source. unsigned createFileID(const SrcMgr::ContentCache* File, - SourceLocation IncludePos, unsigned DirCharacter); + SourceLocation IncludePos, + SrcMgr::Characteristic_t DirCharacter); /// getContentCache - Create or return a cached ContentCache for the specified /// file. This returns null on failure. diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h index eb9bf5dbbb2..e5171cd7fe8 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -14,6 +14,8 @@ #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H +#include "clang/Basic/SourceManager.h" + namespace clang { class HeaderMap; class DirectoryEntry; @@ -26,12 +28,6 @@ class HeaderSearch; /// class DirectoryLookup { public: - enum DirType { - NormalHeaderDir, - SystemHeaderDir, - ExternCSystemHeaderDir - }; - enum LookupType_t { LT_NormalDir, LT_Framework, @@ -48,9 +44,8 @@ private: const HeaderMap *Map; } u; - // NOTE: VC++ treats enums as signed, avoid using the DirType enum - /// DirCharacteristic - The type of directory this is, one of the DirType enum - /// values. + /// DirCharacteristic - The type of directory this is: this is an instance of + /// SrcMgr::Characteristic_t. unsigned DirCharacteristic : 2; /// UserSupplied - True if this is a user-supplied directory. @@ -63,8 +58,8 @@ private: public: /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of /// 'dir'. - DirectoryLookup(const DirectoryEntry *dir, DirType DT, bool isUser, - bool isFramework) + DirectoryLookup(const DirectoryEntry *dir, SrcMgr::Characteristic_t DT, + bool isUser, bool isFramework) : DirCharacteristic(DT), UserSupplied(isUser), LookupType(isFramework ? LT_Framework : LT_NormalDir) { u.Dir = dir; @@ -72,7 +67,8 @@ public: /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of /// 'map'. - DirectoryLookup(const HeaderMap *map, DirType DT, bool isUser) + DirectoryLookup(const HeaderMap *map, SrcMgr::Characteristic_t DT, + bool isUser) : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) { u.Map = map; } @@ -111,7 +107,9 @@ public: /// DirCharacteristic - The type of directory this is, one of the DirType enum /// values. - DirType getDirCharacteristic() const { return DirType(DirCharacteristic); } + SrcMgr::Characteristic_t getDirCharacteristic() const { + return (SrcMgr::Characteristic_t)DirCharacteristic; + } /// isUserSupplied - True if this is a user-supplied directory. /// diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 9981b7137a8..fc0321b3aa0 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -45,10 +45,10 @@ class HeaderSearch { /// isImport - True if this is a #import'd or #pragma once file. bool isImport : 1; - // NOTE: VC++ treats enums as signed, avoid using DirectoryLookup::DirType /// DirInfo - Keep track of whether this is a system header, and if so, /// whether it is C++ clean or not. This can be set by the include paths or - /// by #pragma gcc system_header. + /// by #pragma gcc system_header. This is an instance of + /// SrcMgr::Characteristic_t. unsigned DirInfo : 2; /// NumIncludes - This is the number of times the file has been included @@ -60,7 +60,7 @@ class HeaderSearch { /// for the macro that controls whether or not it has any effect. const IdentifierInfo *ControllingMacro; - PerFileInfo() : isImport(false), DirInfo(DirectoryLookup::NormalHeaderDir), + PerFileInfo() : isImport(false), DirInfo(SrcMgr::C_User), NumIncludes(0), ControllingMacro(0) {} }; @@ -155,8 +155,8 @@ public: /// getFileDirFlavor - Return whether the specified file is a normal header, /// a system header, or a C++ friendly system header. - DirectoryLookup::DirType getFileDirFlavor(const FileEntry *File) { - return DirectoryLookup::DirType(getFileInfo(File).DirInfo); + SrcMgr::Characteristic_t getFileDirFlavor(const FileEntry *File) { + return (SrcMgr::Characteristic_t)getFileInfo(File).DirInfo; } /// MarkFileIncludeOnce - Mark the specified file as a "once only" file, e.g. @@ -168,7 +168,7 @@ public: /// MarkFileSystemHeader - Mark the specified file as a system header, e.g. /// due to #pragma GCC system_header. void MarkFileSystemHeader(const FileEntry *File) { - getFileInfo(File).DirInfo = DirectoryLookup::SystemHeaderDir; + getFileInfo(File).DirInfo = SrcMgr::C_System; } /// IncrementIncludeCount - Increment the count for the number of times the diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index ccaf5a7123a..d8bcdeb0982 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -38,7 +38,7 @@ public: /// #include'd file (when true) or whether we're exiting one because we ran /// off the end (when false). virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, - DirectoryLookup::DirType FileType) { + SrcMgr::Characteristic_t FileType) { } /// Ident - This callback is invoked when a #ident or #sccs directive is read. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 66a85146a10..1a072fccaa0 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -76,14 +76,14 @@ SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) { /// corresponds to a file or some other input source. unsigned SourceManager::createFileID(const ContentCache *File, SourceLocation IncludePos, - unsigned DirCharacter) { + SrcMgr::Characteristic_t FileCharacter) { // If FileEnt is really large (e.g. it's a large .i file), we may not be able // to fit an arbitrary position in the file in the FilePos field. To handle // this, we create one FileID for each chunk of the file that fits in a // FilePos field. unsigned FileSize = File->Buffer->getBufferSize(); if (FileSize+1 < (1 << SourceLocation::FilePosBits)) { - FileIDs.push_back(FileIDInfo::get(IncludePos, 0, File, DirCharacter)); + FileIDs.push_back(FileIDInfo::get(IncludePos, 0, File, FileCharacter)); assert(FileIDs.size() < (1 << SourceLocation::FileIDBits) && "Ran out of file ID's!"); return FileIDs.size(); @@ -95,7 +95,7 @@ unsigned SourceManager::createFileID(const ContentCache *File, unsigned ChunkNo = 0; while (1) { FileIDs.push_back(FileIDInfo::get(IncludePos, ChunkNo++, File, - DirCharacter)); + FileCharacter)); if (FileSize+1 < (1 << SourceLocation::FilePosBits)) break; FileSize -= (1 << SourceLocation::FilePosBits); diff --git a/clang/lib/Driver/InitHeaderSearch.cpp b/clang/lib/Driver/InitHeaderSearch.cpp index 5c23808b3ba..3ebca8e175b 100644 --- a/clang/lib/Driver/InitHeaderSearch.cpp +++ b/clang/lib/Driver/InitHeaderSearch.cpp @@ -43,13 +43,13 @@ void InitHeaderSearch::AddPath(const std::string &Path, IncludeDirGroup Group, MappedPath.append(Path.begin(), Path.end()); // Compute the DirectoryLookup type. - DirectoryLookup::DirType Type; + SrcMgr::Characteristic_t Type; if (Group == Quoted || Group == Angled) - Type = DirectoryLookup::NormalHeaderDir; + Type = SrcMgr::C_User; else if (isCXXAware) - Type = DirectoryLookup::SystemHeaderDir; + Type = SrcMgr::C_System; else - Type = DirectoryLookup::ExternCSystemHeaderDir; + Type = SrcMgr::C_ExternCSystem; // If the directory exists, add it. @@ -267,10 +267,7 @@ static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, // // Since dupes of system dirs are rare, just rescan to find the original // that we're nuking instead of using a DenseMap. - if (SearchList[i].getDirCharacteristic() == - DirectoryLookup::SystemHeaderDir || - SearchList[i].getDirCharacteristic() == - DirectoryLookup::ExternCSystemHeaderDir) { + if (SearchList[i].getDirCharacteristic() != SrcMgr::C_User) { // Find the dir that this is the same of. unsigned FirstDir; for (FirstDir = 0; ; ++FirstDir) { @@ -281,8 +278,7 @@ static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, // If the first dir in the search path is a non-system dir, zap it // instead of the system one. - if (SearchList[FirstDir].getDirCharacteristic() == - DirectoryLookup::NormalHeaderDir) + if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) DirToRemove = FirstDir; } diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 504bc45dca4..a3aaabd298d 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -675,10 +675,9 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, // The #included file will be considered to be a system header if either it is // in a system include directory, or if the #includer is a system include // header. - unsigned FileCharacter = - // FIXME: Casts - std::max((unsigned)HeaderInfo.getFileDirFlavor(File), - SourceMgr.getDirCharacteristic(getCurrentFileLexer()->getFileLoc())); + SrcMgr::Characteristic_t FileCharacter = + std::max(HeaderInfo.getFileDirFlavor(File), + SourceMgr.getFileCharacteristic(getCurrentFileLexer()->getFileLoc())); // Look up the file, create a File ID for it. unsigned FileID = SourceMgr.createFileID(File, FilenameTok.getLocation(), diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 1522bf5e8ca..ccaddf52ed5 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -95,10 +95,8 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer, // Notify the client, if desired, that we are in a new source file. if (Callbacks && !CurLexer->Is_PragmaLexer) { - DirectoryLookup::DirType FileType = - // FIXME: - (DirectoryLookup::DirType) - SourceMgr.getDirCharacteristic(CurLexer->getFileLoc()); + SrcMgr::Characteristic_t FileType = + SourceMgr.getFileCharacteristic(CurLexer->getFileLoc()); Callbacks->FileChanged(CurLexer->getFileLoc(), PPCallbacks::EnterFile, FileType); @@ -180,10 +178,8 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { // Notify the client, if desired, that we are in a new source file. if (Callbacks && !isEndOfMacro && CurLexer) { - DirectoryLookup::DirType FileType = - // FIXME: - (DirectoryLookup::DirType) - SourceMgr.getDirCharacteristic(CurLexer->getFileLoc()); + SrcMgr::Characteristic_t FileType = + SourceMgr.getFileCharacteristic(CurLexer->getFileLoc()); Callbacks->FileChanged(CurLexer->getSourceLocation(CurLexer->BufferPtr), PPCallbacks::ExitFile, FileType); diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index e6955d762fa..b6f5ac49360 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -239,8 +239,7 @@ void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) { // Notify the client, if desired, that we are in a new source file. if (Callbacks) Callbacks->FileChanged(TheLexer->getSourceLocation(TheLexer->BufferPtr), - PPCallbacks::SystemHeaderPragma, - DirectoryLookup::SystemHeaderDir); + PPCallbacks::SystemHeaderPragma, SrcMgr::C_System); } /// HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah. |