diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 74 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 53 | ||||
-rw-r--r-- | gcc/rust/operator.h | 107 |
3 files changed, 75 insertions, 159 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; diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index c5c80ad..15c89eb 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -21,6 +21,7 @@ #include "rust-hir.h" #include "rust-hir-path.h" +#include "operator.h" namespace Rust { namespace HIR { @@ -355,30 +356,26 @@ 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 (Analysis::NodeMapping mappings, - std::unique_ptr<Expr> negated_value, NegationType negation_kind, + std::unique_ptr<Expr> negated_value, ExprType expr_kind, std::vector<Attribute> outer_attribs, Location locus) : OperatorExpr (std::move (mappings), std::move (negated_value), std::move (outer_attribs), locus), - negation_type (negation_kind) + expr_type (expr_kind) {} void accept_vis (HIRVisitor &vis) override; @@ -404,20 +401,8 @@ 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; @@ -489,16 +474,8 @@ 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; @@ -571,12 +548,8 @@ 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; diff --git a/gcc/rust/operator.h b/gcc/rust/operator.h index e2bcf3b..2dd161f 100644 --- a/gcc/rust/operator.h +++ b/gcc/rust/operator.h @@ -1,69 +1,56 @@ -// operator.h -- Go frontend operators. -*- C++ -*- +#ifndef OPERATOR_H +#define OPERATOR_H -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +enum Operator {}; -#ifndef GO_OPERATOR_H -#define GO_OPERATOR_H - -// The operators. +enum class NegationOperator +{ + NEGATE, + NOT +}; -// TODO: Will have to be significantly modified to work with Rust and current -// setup of gccrs +enum class ArithmeticOrLogicalOperator +{ + 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 +}; -enum Operator +enum class ComparisionOperator { - OPERATOR_INVALID, - OPERATOR_OROR, // || - OPERATOR_ANDAND, // && - OPERATOR_EQEQ, // == - OPERATOR_NOTEQ, // != - OPERATOR_LT, // < - OPERATOR_LE, // <= - OPERATOR_GT, // > - OPERATOR_GE, // >= - OPERATOR_PLUS, // + - OPERATOR_MINUS, // - - OPERATOR_OR, // | - OPERATOR_XOR, // ^ - OPERATOR_MULT, // * - OPERATOR_DIV, // / - OPERATOR_MOD, // % - OPERATOR_LSHIFT, // << - OPERATOR_RSHIFT, // >> - OPERATOR_AND, // & - OPERATOR_NOT, // ! - OPERATOR_BITCLEAR, // &^ - OPERATOR_CHANOP, // <- + 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 +}; - OPERATOR_EQ, // = - OPERATOR_PLUSEQ, // += - OPERATOR_MINUSEQ, // -= - OPERATOR_OREQ, // |= - OPERATOR_XOREQ, // ^= - OPERATOR_MULTEQ, // *= - OPERATOR_DIVEQ, // /= - OPERATOR_MODEQ, // %= - OPERATOR_LSHIFTEQ, // <<= - OPERATOR_RSHIFTEQ, // >>= - OPERATOR_ANDEQ, // &= - OPERATOR_BITCLEAREQ, // &^= - OPERATOR_PLUSPLUS, // ++ - OPERATOR_MINUSMINUS, // -- +enum class LazyBooleanOperator +{ + LOGICAL_OR, + LOGICAL_AND +}; - OPERATOR_COLON, // : - OPERATOR_COLONEQ, // := - OPERATOR_SEMICOLON, // ; - OPERATOR_DOT, // . - OPERATOR_ELLIPSIS, // ... - OPERATOR_COMMA, // , - OPERATOR_LPAREN, // ( - OPERATOR_RPAREN, // ) - OPERATOR_LCURLY, // { - OPERATOR_RCURLY, // } - OPERATOR_LSQUARE, // [ - OPERATOR_RSQUARE // ] +enum class CompoundAssignmentOperator +{ + 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 }; -#endif // !defined(GO_OPERATOR_H) +#endif |