r253177 - [Basic] Use a bitfield in SLocEntry for clarity. NFC.
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 15 16:11:59 PST 2015
Author: vedantk
Date: Sun Nov 15 18:11:58 2015
New Revision: 253177
URL: http://llvm.org/viewvc/llvm-project?rev=253177&view=rev
Log:
[Basic] Use a bitfield in SLocEntry for clarity. NFC.
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=253177&r1=253176&r2=253177&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Sun Nov 15 18:11:58 2015
@@ -388,15 +388,16 @@ namespace SrcMgr {
/// SourceManager keeps an array of these objects, and they are uniquely
/// identified by the FileID datatype.
class SLocEntry {
- unsigned Offset; // low bit is set for expansion info.
+ unsigned Offset : 31;
+ unsigned IsExpansion : 1;
union {
FileInfo File;
ExpansionInfo Expansion;
};
public:
- unsigned getOffset() const { return Offset >> 1; }
+ unsigned getOffset() const { return Offset; }
- bool isExpansion() const { return Offset & 1; }
+ bool isExpansion() const { return IsExpansion; }
bool isFile() const { return !isExpansion(); }
const FileInfo &getFile() const {
@@ -410,15 +411,19 @@ namespace SrcMgr {
}
static SLocEntry get(unsigned Offset, const FileInfo &FI) {
+ assert(!(Offset & (1 << 31)) && "Offset is too large");
SLocEntry E;
- E.Offset = Offset << 1;
+ E.Offset = Offset;
+ E.IsExpansion = false;
E.File = FI;
return E;
}
static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) {
+ assert(!(Offset & (1 << 31)) && "Offset is too large");
SLocEntry E;
- E.Offset = (Offset << 1) | 1;
+ E.Offset = Offset;
+ E.IsExpansion = true;
E.Expansion = Expansion;
return E;
}
More information about the cfe-commits
mailing list