[cfe-commits] r43968 - in /cfe/trunk: Basic/SourceManager.cpp clang.xcodeproj/project.pbxproj include/clang/Basic/SourceLocation.h include/clang/Basic/SourceManager.h

Chris Lattner sabre at nondot.org
Fri Nov 9 15:52:17 PST 2007


Author: lattner
Date: Fri Nov  9 17:52:16 2007
New Revision: 43968

URL: http://llvm.org/viewvc/llvm-project?rev=43968&view=rev
Log:
change source location to have two bits for macros, tracking
whether the location is the start and/or end of an expansion.
These are currently not set or used by anything.

Modified:
    cfe/trunk/Basic/SourceManager.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/include/clang/Basic/SourceManager.h

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

==============================================================================
--- cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/trunk/Basic/SourceManager.cpp Fri Nov  9 17:52:16 2007
@@ -193,12 +193,12 @@
     int PhysDelta = PhysLoc.getRawFilePos() -
                     LastOne.getPhysicalLoc().getRawFilePos();
     if (SourceLocation::isValidMacroPhysOffs(PhysDelta))
-      return SourceLocation::getMacroLoc(i, PhysDelta, 0);
+      return SourceLocation::getMacroLoc(i, PhysDelta, false, false);
   }
   
  
   MacroIDs.push_back(MacroIDInfo::get(InstantLoc, PhysLoc));
-  return SourceLocation::getMacroLoc(MacroIDs.size()-1, 0, 0);
+  return SourceLocation::getMacroLoc(MacroIDs.size()-1, 0, false, false);
 }
 
 /// getBufferData - Return a pointer to the start and end of the character

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43968&r1=43967&r2=43968&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Nov  9 17:52:16 2007
@@ -764,7 +764,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Fri Nov  9 17:52:16 2007
@@ -26,13 +26,27 @@
   unsigned ID;
 public:
   enum {
+    // FileID Layout:
+    // bit 31: 0 -> FileID, 1 -> MacroID (invalid for FileID)
+    //     30...17 -> FileID of source location, index into SourceManager table.
     FileIDBits  = 14,
+    //      0...16 -> Index into the chunk of the specified FileID.
     FilePosBits = 32-1-FileIDBits,
     
+    // MacroID Layout:
+    // bit 31: 1 -> MacroID, 0 -> FileID (invalid for MacroID)
+
+    // bit 30: 1 -> Start of macro expansion marker.
+    MacroStartOfExpansionBit = 30,
+    // bit 29: 1 -> End of macro expansion marker.
+    MacroEndOfExpansionBit = 29,
+    // bits 28...9 -> MacroID number.
     MacroIDBits       = 20,
+    // bits 8...0  -> Macro Physical offset
     MacroPhysOffsBits = 9,
-    MacroLogOffBits   = 2,
     
+    
+    // Useful constants.
     ChunkSize = (1 << FilePosBits)
   };
 
@@ -41,6 +55,13 @@
   bool isFileID() const { return (ID >> 31) == 0; }
   bool isMacroID() const { return (ID >> 31) != 0; }
   
+  /// isValid - Return true if this is a valid SourceLocation object.  Invalid
+  /// SourceLocations are often used when events have no corresponding location
+  /// in the source (e.g. a diagnostic is required for a command line option).
+  ///
+  bool isValid() const { return ID != 0; }
+  bool isInvalid() const { return ID == 0; }
+  
   static SourceLocation getFileLoc(unsigned FileID, unsigned FilePos) {
     SourceLocation L;
     // If a FilePos is larger than (1<<FilePosBits), the SourceManager makes
@@ -65,28 +86,23 @@
   }
   
   static SourceLocation getMacroLoc(unsigned MacroID, int PhysOffs,
-                                    unsigned LogOffs) {
+                                    bool isExpansionStart, bool isExpansionEnd){
     assert(MacroID < (1 << MacroIDBits) && "Too many macros!");
     assert(isValidMacroPhysOffs(PhysOffs) && "Physoffs too large!");
-    assert(LogOffs  < (1 << MacroLogOffBits) && "Logical offs too large!");
     
+    // Mask off sign bits.
     PhysOffs &= (1 << MacroPhysOffsBits)-1;
     
     SourceLocation L;
-    L.ID = (1 << 31) | (MacroID << (MacroPhysOffsBits+MacroLogOffBits)) |
-           (PhysOffs << MacroLogOffBits) |
-           LogOffs;
+    L.ID = (1 << 31) |
+           (isExpansionStart << MacroStartOfExpansionBit) |
+           (isExpansionEnd << MacroEndOfExpansionBit) |
+           (MacroID << MacroPhysOffsBits) |
+           PhysOffs;
     return L;
   }
   
   
-  /// isValid - Return true if this is a valid SourceLocation object.  Invalid
-  /// SourceLocations are often used when events have no corresponding location
-  /// in the source (e.g. a diagnostic is required for a command line option).
-  ///
-  bool isValid() const { return ID != 0; }
-  bool isInvalid() const { return ID == 0; }
-  
   /// getFileID - Return the file identifier for this SourceLocation.  This
   /// FileID can be used with the SourceManager object to obtain an entire
   /// include stack for a file position reference.
@@ -106,22 +122,17 @@
 
   unsigned getMacroID() const {
     assert(isMacroID() && "Is not a macro id!");
-    return (ID >> (MacroPhysOffsBits+MacroLogOffBits)) & ((1 << MacroIDBits)-1);
+    return (ID >> MacroPhysOffsBits) & ((1 << MacroIDBits)-1);
   }
   
   int getMacroPhysOffs() const {
     assert(isMacroID() && "Is not a macro id!");
-    int Val = (ID >> MacroLogOffBits) & ((1 << MacroPhysOffsBits)-1);
+    int Val = ID & ((1 << MacroPhysOffsBits)-1);
     // Sign extend it properly.
     unsigned ShAmt = sizeof(int)*8 - MacroPhysOffsBits;
     return (Val << ShAmt) >> ShAmt;
   }
   
-  unsigned getMacroLogOffs() const {
-    assert(isMacroID() && "Is not a macro id!");
-    return ID & ((1 << MacroLogOffBits)-1);
-  }
-  
   /// getFileLocWithOffset - Return a source location with the specified offset
   /// from this file SourceLocation.
   SourceLocation getFileLocWithOffset(int Offset) const {

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

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Nov  9 17:52:16 2007
@@ -291,8 +291,7 @@
     // File locations are both physical and logical.
     if (Loc.isFileID()) return Loc;
 
-    SourceLocation ILoc = MacroIDs[Loc.getMacroID()].getInstantiationLoc();
-    return ILoc.getFileLocWithOffset(Loc.getMacroLogOffs());
+    return MacroIDs[Loc.getMacroID()].getInstantiationLoc();
   }
   
   /// getPhysicalLoc - Given a SourceLocation object, return the physical





More information about the cfe-commits mailing list