aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-expr.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r--gcc/rust/ast/rust-expr.h74
1 files changed, 15 insertions, 59 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 0afa46b..9e69998 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -3,6 +3,7 @@
#include "rust-ast.h"
#include "rust-path.h"
+#include "operator.h"
namespace Rust {
namespace AST {
@@ -365,30 +366,25 @@ protected:
// Unary prefix - or ! negation or NOT operators.
class NegationExpr : public OperatorExpr
{
-public:
- enum NegationType
- {
- NEGATE,
- NOT
- };
-
private:
+ using ExprType = NegationOperator;
+
/* Note: overload negation via std::ops::Neg and not via std::ops::Not
* Negation only works for signed integer and floating-point types, NOT only
* works for boolean and integer types (via bitwise NOT) */
- NegationType negation_type;
+ ExprType expr_type;
public:
std::string as_string () const override;
- NegationType get_negation_type () const { return negation_type; }
+ ExprType get_expr_type () const { return expr_type; }
// Constructor calls OperatorExpr's protected constructor
- NegationExpr (std::unique_ptr<Expr> negated_value, NegationType negation_kind,
+ NegationExpr (std::unique_ptr<Expr> negated_value, ExprType expr_kind,
std::vector<Attribute> outer_attribs, Location locus)
: OperatorExpr (std::move (negated_value), std::move (outer_attribs),
locus),
- negation_type (negation_kind)
+ expr_type (expr_kind)
{}
void accept_vis (ASTVisitor &vis) override;
@@ -412,22 +408,9 @@ protected:
// Infix binary operators. +, -, *, /, %, &, |, ^, <<, >>
class ArithmeticOrLogicalExpr : public OperatorExpr
{
-public:
- enum ExprType
- {
- ADD, // std::ops::Add
- SUBTRACT, // std::ops::Sub
- MULTIPLY, // std::ops::Mul
- DIVIDE, // std::ops::Div
- MODULUS, // std::ops::Rem
- BITWISE_AND, // std::ops::BitAnd
- BITWISE_OR, // std::ops::BitOr
- BITWISE_XOR, // std::ops::BitXor
- LEFT_SHIFT, // std::ops::Shl
- RIGHT_SHIFT // std::ops::Shr
- };
-
private:
+ using ExprType = ArithmeticOrLogicalOperator;
+
// Note: overloading trait specified in comments
ExprType expr_type;
@@ -500,18 +483,9 @@ protected:
// Infix binary comparison operators. ==, !=, <, <=, >, >=
class ComparisonExpr : public OperatorExpr
{
-public:
- enum ExprType
- {
- EQUAL, // std::cmp::PartialEq::eq
- NOT_EQUAL, // std::cmp::PartialEq::ne
- GREATER_THAN, // std::cmp::PartialEq::gt
- LESS_THAN, // std::cmp::PartialEq::lt
- GREATER_OR_EQUAL, // std::cmp::PartialEq::ge
- LESS_OR_EQUAL // std::cmp::PartialEq::le
- };
-
private:
+ using ExprType = ComparisionOperator;
+
// Note: overloading trait specified in comments
ExprType expr_type;
@@ -585,14 +559,9 @@ protected:
// Infix binary lazy boolean logical operators && and ||.
class LazyBooleanExpr : public OperatorExpr
{
-public:
- enum ExprType
- {
- LOGICAL_OR,
- LOGICAL_AND
- };
-
private:
+ using ExprType = LazyBooleanOperator;
+
ExprType expr_type;
std::unique_ptr<Expr> right_expr;
@@ -791,22 +760,9 @@ protected:
* expressions. */
class CompoundAssignmentExpr : public OperatorExpr
{
-public:
- enum ExprType
- {
- ADD, // std::ops::AddAssign
- SUBTRACT, // std::ops::SubAssign
- MULTIPLY, // std::ops::MulAssign
- DIVIDE, // std::ops::DivAssign
- MODULUS, // std::ops::RemAssign
- BITWISE_AND, // std::ops::BitAndAssign
- BITWISE_OR, // std::ops::BitOrAssign
- BITWISE_XOR, // std::ops::BitXorAssign
- LEFT_SHIFT, // std::ops::ShlAssign
- RIGHT_SHIFT // std::ops::ShrAssign
- };
-
private:
+ using ExprType = CompoundAssignmentOperator;
+
// Note: overloading trait specified in comments
ExprType expr_type;
std::unique_ptr<Expr> right_expr;