diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-15 18:13:32 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-16 15:09:53 +0000 |
commit | 04a49acfa3caa7a85a1a9edd24d69da0ad575ad5 (patch) | |
tree | d6bf4186cb815ff8b0bdf691c9659cf14bca8efd /gcc/rust/util/rust-hir-map.h | |
parent | 0f74fe23c6d602c257ba94b2522bd9d6a594609e (diff) | |
download | gcc-04a49acfa3caa7a85a1a9edd24d69da0ad575ad5.zip gcc-04a49acfa3caa7a85a1a9edd24d69da0ad575ad5.tar.gz gcc-04a49acfa3caa7a85a1a9edd24d69da0ad575ad5.tar.bz2 |
Add negation operator overload support
Unary operator expressions can be treated as simply having a nullptr
rvalue. This patch updates the shared operator overloading code to allow
for a nullptr rhs to canonicalize the code path for all operator overloads.
Fixes #249
Diffstat (limited to 'gcc/rust/util/rust-hir-map.h')
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index bcbd582..4f8c389 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -43,6 +43,7 @@ public: REMAINDER, NEGATION, + NOT, ADD_ASSIGN, SUB_ASSIGN, @@ -79,6 +80,10 @@ public: { return ItemType::NEGATION; } + else if (item.compare ("not") == 0) + { + return ItemType::NOT; + } else if (item.compare ("add_assign") == 0) { return ItemType::ADD_ASSIGN; @@ -119,6 +124,8 @@ public: return "rem"; case NEGATION: return "neg"; + case NOT: + return "not"; case ADD_ASSIGN: return "add_assign"; case SUB_ASSIGN: @@ -151,11 +158,7 @@ public: case ArithmeticOrLogicalOperator::MODULUS: return ItemType::REMAINDER; - case ArithmeticOrLogicalOperator::BITWISE_AND: - case ArithmeticOrLogicalOperator::BITWISE_OR: - case ArithmeticOrLogicalOperator::BITWISE_XOR: - case ArithmeticOrLogicalOperator::LEFT_SHIFT: - case ArithmeticOrLogicalOperator::RIGHT_SHIFT: + default: return ItemType::UNKNOWN; } return ItemType::UNKNOWN; @@ -177,11 +180,22 @@ public: case ArithmeticOrLogicalOperator::MODULUS: return ItemType::REM_ASSIGN; - case ArithmeticOrLogicalOperator::BITWISE_AND: - case ArithmeticOrLogicalOperator::BITWISE_OR: - case ArithmeticOrLogicalOperator::BITWISE_XOR: - case ArithmeticOrLogicalOperator::LEFT_SHIFT: - case ArithmeticOrLogicalOperator::RIGHT_SHIFT: + default: + return ItemType::UNKNOWN; + } + return ItemType::UNKNOWN; + } + + static ItemType NegationOperatorToLangItem (NegationOperator op) + { + switch (op) + { + case NegationOperator::NEGATE: + return ItemType::NEGATION; + case NegationOperator::NOT: + return ItemType::NOT; + + default: return ItemType::UNKNOWN; } return ItemType::UNKNOWN; |