From b7489d8129136437953d412e2a6cf0ef87f4a461 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 9 Nov 2007 23:52:16 +0000 Subject: [PATCH] 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 --- Basic/SourceManager.cpp | 4 +-- clang.xcodeproj/project.pbxproj | 1 - include/clang/Basic/SourceLocation.h | 51 +++++++++++++++++----------- 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<> (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 -- 2.40.0