aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-mapping-common.h
diff options
context:
space:
mode:
authorNirmal Patel <npate012@gmail.com>2021-11-02 21:01:13 -0400
committerNirmal Patel <npate012@gmail.com>2021-11-07 11:13:29 -0500
commita7c31383def5c499864d61c5d00a1575d1cbff81 (patch)
tree82d8bd640e581df5f58e2db8b5512e7cad38267a /gcc/rust/util/rust-mapping-common.h
parent5f0df4812c37fc428b5508e019e9fb7f8a7b77b1 (diff)
downloadgcc-a7c31383def5c499864d61c5d00a1575d1cbff81.zip
gcc-a7c31383def5c499864d61c5d00a1575d1cbff81.tar.gz
gcc-a7c31383def5c499864d61c5d00a1575d1cbff81.tar.bz2
Changed DefId type from uint64_t to be struct
DefId was uint64_t previously but it has been changed to be a struct. In order to reduce code breakage, ==, !=, and < operators have been implemented for DefId. Since DefId is now a proper struct, bit manipulation code has been removed with member accesses. Fixes #439 Signed-off-by: Nirmal Patel <npate012@gmail.com>
Diffstat (limited to 'gcc/rust/util/rust-mapping-common.h')
-rw-r--r--gcc/rust/util/rust-mapping-common.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/gcc/rust/util/rust-mapping-common.h b/gcc/rust/util/rust-mapping-common.h
index 1309a8d..0665779 100644
--- a/gcc/rust/util/rust-mapping-common.h
+++ b/gcc/rust/util/rust-mapping-common.h
@@ -31,17 +31,32 @@ typedef uint32_t NodeId;
typedef uint32_t HirId;
// refers to any top-level decl in HIR
typedef uint32_t LocalDefId;
-// refers to <Crate><DefId>
-typedef uint64_t DefId;
-#define DEF_ID_CRATE_MASK 0xFFFFFFFF00000000
-#define DEF_ID_LOCAL_DEF_MASK 0x00000000FFFFFFFF
+struct DefId
+{
+ CrateNum crateNum;
+ LocalDefId localDefId;
+
+ bool operator== (const DefId &other) const
+ {
+ return this->crateNum == other.crateNum
+ && this->localDefId == other.localDefId;
+ }
+
+ bool operator!= (const DefId &other) const { return !(*this == other); }
+
+ bool operator< (const DefId &other) const
+ {
+ return ((uint64_t) this->crateNum << 32 | this->localDefId)
+ < ((uint64_t) other.crateNum << 32 | other.localDefId);
+ }
+};
#define UNKNOWN_CREATENUM ((uint32_t) (0))
#define UNKNOWN_NODEID ((uint32_t) (0))
#define UNKNOWN_HIRID ((uint32_t) (0))
#define UNKNOWN_LOCAL_DEFID ((uint32_t) (0))
-#define UNKNOWN_DEFID ((uint64_t) (0))
+#define UNKNOWN_DEFID (DefId{0, 0})
} // namespace Rust