diff options
author | Yizhe <yizhe@pku.edu.cn> | 2021-02-26 08:56:00 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-01 10:42:27 +0000 |
commit | 875bda0637f587ded1a4e8bfab1703b54eee2b2e (patch) | |
tree | c51272f4fab9e605a774d85352af10e3466b1ac8 /gcc | |
parent | 1b857e339dd144e3405a9a5a6f3275a2e56b2f54 (diff) | |
download | gcc-875bda0637f587ded1a4e8bfab1703b54eee2b2e.zip gcc-875bda0637f587ded1a4e8bfab1703b54eee2b2e.tar.gz gcc-875bda0637f587ded1a4e8bfab1703b54eee2b2e.tar.bz2 |
Modify AST and HIR code to use the new enums
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 63 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 17 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 12 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-test.cc | 42 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 26 |
5 files changed, 85 insertions, 75 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 2c196a0..69d1e6e 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "rust-diagnostics.h" #include "rust-ast-visitor.h" #include "rust-session-manager.h" +#include "operator.h" /* Compilation unit used for various AST-related functions that would make * the headers too long if they were defined inline and don't receive any @@ -1602,12 +1603,12 @@ NegationExpr::as_string () const // TODO: rewrite formula to allow outer attributes std::string str; - switch (negation_type) + switch (expr_type) { - case NEGATE: + case NegationOperator::NEGATE: str = "-"; break; - case NOT: + case NegationOperator::NOT: str = "!"; break; default: @@ -1682,22 +1683,22 @@ ComparisonExpr::as_string () const switch (expr_type) { - case EQUAL: + case ComparisonOperator::EQUAL: str += " == "; break; - case NOT_EQUAL: + case ComparisonOperator::NOT_EQUAL: str += " != "; break; - case GREATER_THAN: + case ComparisonOperator::GREATER_THAN: str += " > "; break; - case LESS_THAN: + case ComparisonOperator::LESS_THAN: str += " < "; break; - case GREATER_OR_EQUAL: + case ComparisonOperator::GREATER_OR_EQUAL: str += " >= "; break; - case LESS_OR_EQUAL: + case ComparisonOperator::LESS_OR_EQUAL: str += " <= "; break; default: @@ -1770,10 +1771,10 @@ LazyBooleanExpr::as_string () const switch (expr_type) { - case LOGICAL_OR: + case LazyBooleanOperator::LOGICAL_OR: str += " || "; break; - case LOGICAL_AND: + case LazyBooleanOperator::LOGICAL_AND: str += " && "; break; default: @@ -1944,34 +1945,34 @@ CompoundAssignmentExpr::as_string () const // get operator string switch (expr_type) { - case ADD: + case CompoundAssignmentOperator::ADD: operator_str = "+"; break; - case SUBTRACT: + case CompoundAssignmentOperator::SUBTRACT: operator_str = "-"; break; - case MULTIPLY: + case CompoundAssignmentOperator::MULTIPLY: operator_str = "*"; break; - case DIVIDE: + case CompoundAssignmentOperator::DIVIDE: operator_str = "/"; break; - case MODULUS: + case CompoundAssignmentOperator::MODULUS: operator_str = "%"; break; - case BITWISE_AND: + case CompoundAssignmentOperator::BITWISE_AND: operator_str = "&"; break; - case BITWISE_OR: + case CompoundAssignmentOperator::BITWISE_OR: operator_str = "|"; break; - case BITWISE_XOR: + case CompoundAssignmentOperator::BITWISE_XOR: operator_str = "^"; break; - case LEFT_SHIFT: + case CompoundAssignmentOperator::LEFT_SHIFT: operator_str = "<<"; break; - case RIGHT_SHIFT: + case CompoundAssignmentOperator::RIGHT_SHIFT: operator_str = ">>"; break; default: @@ -2005,34 +2006,34 @@ ArithmeticOrLogicalExpr::as_string () const // get operator string switch (expr_type) { - case ADD: + case ArithmeticOrLogicalOperator::ADD: operator_str = "+"; break; - case SUBTRACT: + case ArithmeticOrLogicalOperator::SUBTRACT: operator_str = "-"; break; - case MULTIPLY: + case ArithmeticOrLogicalOperator::MULTIPLY: operator_str = "*"; break; - case DIVIDE: + case ArithmeticOrLogicalOperator::DIVIDE: operator_str = "/"; break; - case MODULUS: + case ArithmeticOrLogicalOperator::MODULUS: operator_str = "%"; break; - case BITWISE_AND: + case ArithmeticOrLogicalOperator::BITWISE_AND: operator_str = "&"; break; - case BITWISE_OR: + case ArithmeticOrLogicalOperator::BITWISE_OR: operator_str = "|"; break; - case BITWISE_XOR: + case ArithmeticOrLogicalOperator::BITWISE_XOR: operator_str = "^"; break; - case LEFT_SHIFT: + case ArithmeticOrLogicalOperator::LEFT_SHIFT: operator_str = "<<"; break; - case RIGHT_SHIFT: + case ArithmeticOrLogicalOperator::RIGHT_SHIFT: operator_str = ">>"; break; default: diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 9e69998..3de14cc 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -366,9 +366,10 @@ protected: // Unary prefix - or ! negation or NOT operators. class NegationExpr : public OperatorExpr { -private: +public: using ExprType = NegationOperator; +private: /* 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) */ @@ -408,9 +409,10 @@ protected: // Infix binary operators. +, -, *, /, %, &, |, ^, <<, >> class ArithmeticOrLogicalExpr : public OperatorExpr { -private: +public: using ExprType = ArithmeticOrLogicalOperator; +private: // Note: overloading trait specified in comments ExprType expr_type; @@ -483,9 +485,10 @@ protected: // Infix binary comparison operators. ==, !=, <, <=, >, >= class ComparisonExpr : public OperatorExpr { -private: - using ExprType = ComparisionOperator; +public: + using ExprType = ComparisonOperator; +private: // Note: overloading trait specified in comments ExprType expr_type; @@ -559,9 +562,10 @@ protected: // Infix binary lazy boolean logical operators && and ||. class LazyBooleanExpr : public OperatorExpr { -private: +public: using ExprType = LazyBooleanOperator; +private: ExprType expr_type; std::unique_ptr<Expr> right_expr; @@ -760,9 +764,10 @@ protected: * expressions. */ class CompoundAssignmentExpr : public OperatorExpr { -private: +public: using ExprType = CompoundAssignmentOperator; +private: // 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 ad4f7bf..d8f13bf 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -356,9 +356,10 @@ protected: // Unary prefix - or ! negation or NOT operators. class NegationExpr : public OperatorExpr { -private: +public: using ExprType = NegationOperator; +private: /* 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) */ @@ -401,9 +402,10 @@ protected: // Infix binary operators. +, -, *, /, %, &, |, ^, <<, >> class ArithmeticOrLogicalExpr : public OperatorExpr { -private: +public: using ExprType = ArithmeticOrLogicalOperator; +private: // Note: overloading trait specified in comments ExprType expr_type; @@ -474,9 +476,10 @@ protected: // Infix binary comparison operators. ==, !=, <, <=, >, >= class ComparisonExpr : public OperatorExpr { -private: +public: using ExprType = ComparisonOperator; +private: // Note: overloading trait specified in comments ExprType expr_type; @@ -548,9 +551,10 @@ protected: // Infix binary lazy boolean logical operators && and ||. class LazyBooleanExpr : public OperatorExpr { -private: +public: using ExprType = LazyBooleanOperator; +private: ExprType expr_type; std::unique_ptr<Expr> right_expr; diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index e4fa39a..3ced537 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -1685,12 +1685,12 @@ NegationExpr::as_string () const { std::string str; - switch (negation_type) + switch (expr_type) { - case NEGATE: + case NegationOperator::NEGATE: str = "-"; break; - case NOT: + case NegationOperator::NOT: str = "!"; break; default: @@ -1748,22 +1748,22 @@ ComparisonExpr::as_string () const switch (expr_type) { - case EQUAL: + case ComparisonOperator::EQUAL: str += " == "; break; - case NOT_EQUAL: + case ComparisonOperator::NOT_EQUAL: str += " != "; break; - case GREATER_THAN: + case ComparisonOperator::GREATER_THAN: str += " > "; break; - case LESS_THAN: + case ComparisonOperator::LESS_THAN: str += " < "; break; - case GREATER_OR_EQUAL: + case ComparisonOperator::GREATER_OR_EQUAL: str += " >= "; break; - case LESS_OR_EQUAL: + case ComparisonOperator::LESS_OR_EQUAL: str += " <= "; break; default: @@ -1832,10 +1832,10 @@ LazyBooleanExpr::as_string () const switch (expr_type) { - case LOGICAL_OR: + case LazyBooleanOperator::LOGICAL_OR: str += " || "; break; - case LOGICAL_AND: + case LazyBooleanOperator::LOGICAL_AND: str += " && "; break; default: @@ -2000,34 +2000,34 @@ ArithmeticOrLogicalExpr::as_string () const // get operator string switch (expr_type) { - case ADD: + case ArithmeticOrLogicalOperator::ADD: operator_str = "+"; break; - case SUBTRACT: + case ArithmeticOrLogicalOperator::SUBTRACT: operator_str = "-"; break; - case MULTIPLY: + case ArithmeticOrLogicalOperator::MULTIPLY: operator_str = "*"; break; - case DIVIDE: + case ArithmeticOrLogicalOperator::DIVIDE: operator_str = "/"; break; - case MODULUS: + case ArithmeticOrLogicalOperator::MODULUS: operator_str = "%"; break; - case BITWISE_AND: + case ArithmeticOrLogicalOperator::BITWISE_AND: operator_str = "&"; break; - case BITWISE_OR: + case ArithmeticOrLogicalOperator::BITWISE_OR: operator_str = "|"; break; - case BITWISE_XOR: + case ArithmeticOrLogicalOperator::BITWISE_XOR: operator_str = "^"; break; - case LEFT_SHIFT: + case ArithmeticOrLogicalOperator::LEFT_SHIFT: operator_str = "<<"; break; - case RIGHT_SHIFT: + case ArithmeticOrLogicalOperator::RIGHT_SHIFT: operator_str = ">>"; break; default: diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 491d8aa..b72b308 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -524,9 +524,9 @@ public: auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr (), false); // https://doc.rust-lang.org/reference/expressions/operator-expr.html#negation-operators - switch (expr.get_negation_type ()) + switch (expr.get_expr_type ()) { - case HIR::NegationExpr::NegationType::NEGATE: { + case NegationOperator::NEGATE: { bool valid = (negated_expr_ty->get_kind () == TyTy::TypeKind::INT) || (negated_expr_ty->get_kind () == TyTy::TypeKind::UINT) @@ -546,7 +546,7 @@ public: } break; - case HIR::NegationExpr::NegationType::NOT: { + case NegationOperator::NOT: { bool valid = (negated_expr_ty->get_kind () == TyTy::TypeKind::BOOL) || (negated_expr_ty->get_kind () == TyTy::TypeKind::INT) @@ -913,11 +913,11 @@ private: // this will change later when traits are added switch (expr_type) { - case HIR::ArithmeticOrLogicalExpr::ADD: - case HIR::ArithmeticOrLogicalExpr::SUBTRACT: - case HIR::ArithmeticOrLogicalExpr::MULTIPLY: - case HIR::ArithmeticOrLogicalExpr::DIVIDE: - case HIR::ArithmeticOrLogicalExpr::MODULUS: + case ArithmeticOrLogicalOperator::ADD: + case ArithmeticOrLogicalOperator::SUBTRACT: + case ArithmeticOrLogicalOperator::MULTIPLY: + case ArithmeticOrLogicalOperator::DIVIDE: + case ArithmeticOrLogicalOperator::MODULUS: return (type->get_kind () == TyTy::TypeKind::INT) || (type->get_kind () == TyTy::TypeKind::UINT) || (type->get_kind () == TyTy::TypeKind::FLOAT) @@ -929,9 +929,9 @@ private: == TyTy::InferType::FLOAT)); // integers or bools - case HIR::ArithmeticOrLogicalExpr::BITWISE_AND: - case HIR::ArithmeticOrLogicalExpr::BITWISE_OR: - case HIR::ArithmeticOrLogicalExpr::BITWISE_XOR: + case ArithmeticOrLogicalOperator::BITWISE_AND: + case ArithmeticOrLogicalOperator::BITWISE_OR: + case ArithmeticOrLogicalOperator::BITWISE_XOR: return (type->get_kind () == TyTy::TypeKind::INT) || (type->get_kind () == TyTy::TypeKind::UINT) || (type->get_kind () == TyTy::TypeKind::BOOL) @@ -940,8 +940,8 @@ private: == TyTy::InferType::INTEGRAL)); // integers only - case HIR::ArithmeticOrLogicalExpr::LEFT_SHIFT: - case HIR::ArithmeticOrLogicalExpr::RIGHT_SHIFT: + case ArithmeticOrLogicalOperator::LEFT_SHIFT: + case ArithmeticOrLogicalOperator::RIGHT_SHIFT: return (type->get_kind () == TyTy::TypeKind::INT) || (type->get_kind () == TyTy::TypeKind::UINT) || (type->get_kind () == TyTy::TypeKind::INFER |