diff options
author | Chris Lattner <sabre@nondot.org> | 2007-11-09 23:52:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-11-09 23:52:16 +0000 |
commit | b7489d8129136437953d412e2a6cf0ef87f4a461 (patch) | |
tree | d9ac35c154357f87ae8134c4fceb424d8475dd83 | |
parent | 360300ca2ee298d585d29baf006519507d968812 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43968 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Basic/SourceManager.cpp | 4 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | include/clang/Basic/SourceLocation.h | 51 | ||||
-rw-r--r-- | include/clang/Basic/SourceManager.h | 3 |
4 files changed, 34 insertions, 25 deletions
diff --git a/Basic/SourceManager.cpp b/Basic/SourceManager.cpp index 0482d4c705..74e88c18dc 100644 --- a/Basic/SourceManager.cpp +++ b/Basic/SourceManager.cpp @@ -193,12 +193,12 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc, 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 diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index b9eb859d85..ffe6580cb2 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -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 = ""; diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 7e64e3ebbf..c25528b7e9 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -26,13 +26,27 @@ class SourceLocation { 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 @@ public: 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 @@ public: } 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 @@ public: 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 { diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 6392e899e3..b08886efa5 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -291,8 +291,7 @@ public: // 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 |