diff options
author | Yizhe <yizhe@pku.edu.cn> | 2021-02-26 08:53:19 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-01 10:42:27 +0000 |
commit | 1b857e339dd144e3405a9a5a6f3275a2e56b2f54 (patch) | |
tree | 775d0739bf14633fa9fad182bf3c6ef3da609353 /gcc/rust | |
parent | 5625e07187567025cdc5aeac576dd9fca7579af1 (diff) | |
download | gcc-1b857e339dd144e3405a9a5a6f3275a2e56b2f54.zip gcc-1b857e339dd144e3405a9a5a6f3275a2e56b2f54.tar.gz gcc-1b857e339dd144e3405a9a5a6f3275a2e56b2f54.tar.bz2 |
Cleanup AST-to-HIR lowering
With AST and HIR using the same operator enum, we no longer need to
perform conversions. Except for CompoundAssignmentExpr, which gets
compiled away and therefore still needs conversion.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.h | 136 |
1 files changed, 28 insertions, 108 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index b46861e..6247be0 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -388,42 +388,6 @@ public: void visit (AST::ArithmeticOrLogicalExpr &expr) { - HIR::ArithmeticOrLogicalExpr::ExprType kind - = HIR::ArithmeticOrLogicalExpr::ExprType::ADD; - switch (expr.get_expr_type ()) - { - case AST::ArithmeticOrLogicalExpr::ExprType::ADD: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::ADD; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::SUBTRACT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::SUBTRACT; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::MULTIPLY: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::MULTIPLY; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::DIVIDE: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::DIVIDE; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::MODULUS: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::MODULUS; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::BITWISE_AND: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_AND; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::BITWISE_OR: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_OR; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::BITWISE_XOR: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_XOR; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::LEFT_SHIFT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::LEFT_SHIFT; - break; - case AST::ArithmeticOrLogicalExpr::ExprType::RIGHT_SHIFT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::RIGHT_SHIFT; - break; - } - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); rust_assert (lhs != nullptr); HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); @@ -438,34 +402,11 @@ public: = new HIR::ArithmeticOrLogicalExpr (mapping, std::unique_ptr<HIR::Expr> (lhs), std::unique_ptr<HIR::Expr> (rhs), - kind, expr.get_locus ()); + expr.get_expr_type(), expr.get_locus ()); } void visit (AST::ComparisonExpr &expr) { - HIR::ComparisonExpr::ExprType kind; - switch (expr.get_kind ()) - { - case AST::ComparisonExpr::ExprType::EQUAL: - kind = HIR::ComparisonExpr::ExprType::EQUAL; - break; - case AST::ComparisonExpr::ExprType::NOT_EQUAL: - kind = HIR::ComparisonExpr::ExprType::NOT_EQUAL; - break; - case AST::ComparisonExpr::ExprType::GREATER_THAN: - kind = HIR::ComparisonExpr::ExprType::GREATER_THAN; - break; - case AST::ComparisonExpr::ExprType::LESS_THAN: - kind = HIR::ComparisonExpr::ExprType::LESS_THAN; - break; - case AST::ComparisonExpr::ExprType::GREATER_OR_EQUAL: - kind = HIR::ComparisonExpr::ExprType::GREATER_OR_EQUAL; - break; - case AST::ComparisonExpr::ExprType::LESS_OR_EQUAL: - kind = HIR::ComparisonExpr::ExprType::LESS_OR_EQUAL; - break; - } - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); rust_assert (lhs != nullptr); HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); @@ -478,23 +419,12 @@ public: translated = new HIR::ComparisonExpr (mapping, std::unique_ptr<HIR::Expr> (lhs), - std::unique_ptr<HIR::Expr> (rhs), kind, + std::unique_ptr<HIR::Expr> (rhs), expr.get_expr_type(), expr.get_locus ()); } void visit (AST::LazyBooleanExpr &expr) { - HIR::LazyBooleanExpr::ExprType kind; - switch (expr.get_kind ()) - { - case AST::LazyBooleanExpr::ExprType::LOGICAL_AND: - kind = HIR::LazyBooleanExpr::ExprType::LOGICAL_AND; - break; - case AST::LazyBooleanExpr::ExprType::LOGICAL_OR: - kind = HIR::LazyBooleanExpr::ExprType::LOGICAL_OR; - break; - } - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); rust_assert (lhs != nullptr); HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); @@ -507,7 +437,7 @@ public: translated = new HIR::LazyBooleanExpr (mapping, std::unique_ptr<HIR::Expr> (lhs), - std::unique_ptr<HIR::Expr> (rhs), kind, + std::unique_ptr<HIR::Expr> (rhs), expr.get_expr_type(), expr.get_locus ()); } @@ -515,17 +445,6 @@ public: { std::vector<HIR::Attribute> outer_attribs; - HIR::NegationExpr::NegationType type; - switch (expr.get_negation_type ()) - { - case AST::NegationExpr::NegationType::NEGATE: - type = HIR::NegationExpr::NegationType::NEGATE; - break; - case AST::NegationExpr::NegationType::NOT: - type = HIR::NegationExpr::NegationType::NOT; - break; - } - HIR::Expr *negated_value = ASTLoweringExpr::translate (expr.get_negated_expr ().get ()); @@ -535,45 +454,46 @@ public: UNKNOWN_LOCAL_DEFID); translated = new HIR::NegationExpr (mapping, - std::unique_ptr<HIR::Expr> (negated_value), type, + std::unique_ptr<HIR::Expr> (negated_value), expr.get_expr_type(), std::move (outer_attribs), expr.get_locus ()); } + /* Compound assignment expression is compiled away. */ void visit (AST::CompoundAssignmentExpr &expr) { - HIR::ArithmeticOrLogicalExpr::ExprType kind - = HIR::ArithmeticOrLogicalExpr::ExprType::ADD; + /* First we need to find the corresponding arithmetic or logical operator. */ + ArithmeticOrLogicalOperator op; switch (expr.get_expr_type ()) { - case AST::CompoundAssignmentExpr::ExprType::ADD: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::ADD; + case CompoundAssignmentOperator::ADD: + op = ArithmeticOrLogicalOperator::ADD; break; - case AST::CompoundAssignmentExpr::ExprType::SUBTRACT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::SUBTRACT; + case CompoundAssignmentOperator::SUBTRACT: + op = ArithmeticOrLogicalOperator::SUBTRACT; break; - case AST::CompoundAssignmentExpr::ExprType::MULTIPLY: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::MULTIPLY; + case CompoundAssignmentOperator::MULTIPLY: + op = ArithmeticOrLogicalOperator::MULTIPLY; break; - case AST::CompoundAssignmentExpr::ExprType::DIVIDE: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::DIVIDE; + case CompoundAssignmentOperator::DIVIDE: + op = ArithmeticOrLogicalOperator::DIVIDE; break; - case AST::CompoundAssignmentExpr::ExprType::MODULUS: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::MODULUS; + case CompoundAssignmentOperator::MODULUS: + op = ArithmeticOrLogicalOperator::MODULUS; break; - case AST::CompoundAssignmentExpr::ExprType::BITWISE_AND: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_AND; + case CompoundAssignmentOperator::BITWISE_AND: + op = ArithmeticOrLogicalOperator::BITWISE_AND; break; - case AST::CompoundAssignmentExpr::ExprType::BITWISE_OR: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_OR; + case CompoundAssignmentOperator::BITWISE_OR: + op = ArithmeticOrLogicalOperator::BITWISE_OR; break; - case AST::CompoundAssignmentExpr::ExprType::BITWISE_XOR: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::BITWISE_XOR; + case CompoundAssignmentOperator::BITWISE_XOR: + op = ArithmeticOrLogicalOperator::BITWISE_XOR; break; - case AST::CompoundAssignmentExpr::ExprType::LEFT_SHIFT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::LEFT_SHIFT; + case CompoundAssignmentOperator::LEFT_SHIFT: + op = ArithmeticOrLogicalOperator::LEFT_SHIFT; break; - case AST::CompoundAssignmentExpr::ExprType::RIGHT_SHIFT: - kind = HIR::ArithmeticOrLogicalExpr::ExprType::RIGHT_SHIFT; + case CompoundAssignmentOperator::RIGHT_SHIFT: + op = ArithmeticOrLogicalOperator::RIGHT_SHIFT; break; } @@ -589,7 +509,7 @@ public: HIR::Expr *operator_expr = new HIR::ArithmeticOrLogicalExpr (mapping, asignee_expr->clone_expr (), std::unique_ptr<HIR::Expr> (value), - kind, expr.get_locus ()); + op, expr.get_locus ()); translated = new HIR::AssignmentExpr (mapping, std::unique_ptr<HIR::Expr> (asignee_expr), |