[cfe-commits] r56692 - in /cfe/trunk: Driver/PrintPreprocessedOutput.cpp include/clang/Basic/SourceManager.h include/clang/Lex/DirectoryLookup.h include/clang/Lex/HeaderSearch.h include/clang/Lex/PPCallbacks.h lib/Basic/SourceManager.cpp lib/Driver/InitHeaderSearch.cpp lib/Lex/PPDirectives.cpp lib/Lex/PPLexerChange.cpp lib/Lex/Pragma.cpp

Chris Lattner sabre at nondot.org
Fri Sep 26 14:18:42 PDT 2008


Author: lattner
Date: Fri Sep 26 16:18:42 2008
New Revision: 56692

URL: http://llvm.org/viewvc/llvm-project?rev=56692&view=rev
Log:
clean up a bunch of fixme's I added, by moving 
DirectoryLookup::DirType into SourceManager.h

Modified:
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/include/clang/Lex/DirectoryLookup.h
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/include/clang/Lex/PPCallbacks.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Driver/InitHeaderSearch.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPLexerChange.cpp
    cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Fri Sep 26 16:18:42 2008
@@ -48,7 +48,7 @@
 private:
   unsigned CurLine;
   bool EmittedTokensOnThisLine;
-  DirectoryLookup::DirType FileType;
+  SrcMgr::Characteristic_t FileType;
   llvm::SmallString<512> CurFilename;
   bool Initialized;
 public:
@@ -57,7 +57,7 @@
     CurLine = 0;
     CurFilename += "<uninit>";
     EmittedTokensOnThisLine = false;
-    FileType = DirectoryLookup::NormalHeaderDir;
+    FileType = SrcMgr::C_User;
     Initialized = false;
   }
   
@@ -65,7 +65,7 @@
   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 @@
   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 @@
 /// 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();

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Sep 26 16:18:42 2008
@@ -32,9 +32,20 @@
 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 @@
     /// 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 @@
   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 @@
     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 @@
   /// 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 @@
                             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 @@
   /// 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 @@
 
   /// 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 @@
   ///  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.

Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Fri Sep 26 16:18:42 2008
@@ -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 DirectoryLookup {
 public:
-  enum DirType {
-    NormalHeaderDir,
-    SystemHeaderDir,
-    ExternCSystemHeaderDir
-  };
-  
   enum LookupType_t {
     LT_NormalDir,
     LT_Framework,
@@ -48,9 +44,8 @@
     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 @@
 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 @@
   
   /// 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 @@
   
   /// 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.
   ///

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Sep 26 16:18:42 2008
@@ -45,10 +45,10 @@
     /// 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 @@
     /// 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 @@
   
   /// 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 @@
   /// 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

Modified: cfe/trunk/include/clang/Lex/PPCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PPCallbacks.h?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PPCallbacks.h (original)
+++ cfe/trunk/include/clang/Lex/PPCallbacks.h Fri Sep 26 16:18:42 2008
@@ -38,7 +38,7 @@
   /// #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.

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri Sep 26 16:18:42 2008
@@ -76,14 +76,14 @@
 /// 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 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);

Modified: cfe/trunk/lib/Driver/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/InitHeaderSearch.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Driver/InitHeaderSearch.cpp Fri Sep 26 16:18:42 2008
@@ -43,13 +43,13 @@
   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 @@
       //
       // 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 @@
         
         // 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;
       }
       

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Sep 26 16:18:42 2008
@@ -675,10 +675,9 @@
   // 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(),

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Fri Sep 26 16:18:42 2008
@@ -95,10 +95,8 @@
   
   // 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 @@
 
     // 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);

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=56692&r1=56691&r2=56692&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Sep 26 16:18:42 2008
@@ -239,8 +239,7 @@
   // 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.





More information about the cfe-commits mailing list