Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ast: Add new Expr::Kinds #3385

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,16 @@ class Expr : public Visitable
Identifier,
FormatArgs,
MacroInvocation,
Borrow,
Dereference,
ErrorPropagation,
Negation,
ArithmeticOrLogical,
Comparison,
LazyBoolean,
TypeCast,
Assignment,
CompoundAssignment,
};

virtual Kind get_expr_kind () const = 0;
Expand Down
31 changes: 31 additions & 0 deletions gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ class BorrowExpr : public OperatorExpr
bool get_is_double_borrow () const { return double_borrow; }
bool is_raw_borrow () const { return raw_borrow; }

Expr::Kind get_expr_kind () const override { return Expr::Kind::Borrow; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -437,6 +439,8 @@ class DereferenceExpr : public OperatorExpr
return *main_or_left_expr;
}

Expr::Kind get_expr_kind () const override { return Expr::Kind::Dereference; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -468,6 +472,11 @@ class ErrorPropagationExpr : public OperatorExpr
return *main_or_left_expr;
}

Expr::Kind get_expr_kind () const override
{
return Expr::Kind::ErrorPropagation;
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -511,6 +520,8 @@ class NegationExpr : public OperatorExpr
return *main_or_left_expr;
}

Expr::Kind get_expr_kind () const override { return Expr::Kind::Negation; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -599,6 +610,11 @@ class ArithmeticOrLogicalExpr : public OperatorExpr
void visit_lhs (ASTVisitor &vis) { main_or_left_expr->accept_vis (vis); }
void visit_rhs (ASTVisitor &vis) { right_expr->accept_vis (vis); }

Expr::Kind get_expr_kind () const override
{
return Expr::Kind::ArithmeticOrLogical;
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -686,6 +702,8 @@ class ComparisonExpr : public OperatorExpr

ExprType get_kind () { return expr_type; }

Expr::Kind get_expr_kind () const override { return Expr::Kind::Comparison; }

/* TODO: implement via a function call to std::cmp::PartialEq::eq(&op1, &op2)
* maybe? */
protected:
Expand Down Expand Up @@ -774,6 +792,8 @@ class LazyBooleanExpr : public OperatorExpr

ExprType get_kind () { return expr_type; }

Expr::Kind get_expr_kind () const override { return Expr::Kind::LazyBoolean; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -836,6 +856,8 @@ class TypeCastExpr : public OperatorExpr
return *type_to_convert_to;
}

Expr::Kind get_expr_kind () const override { return Expr::Kind::TypeCast; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -914,6 +936,8 @@ class AssignmentExpr : public OperatorExpr
return *right_expr;
}

Expr::Kind get_expr_kind () const override { return Expr::Kind::Assignment; }

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -1000,6 +1024,11 @@ class CompoundAssignmentExpr : public OperatorExpr
return right_expr;
}

Expr::Kind get_expr_kind () const override
{
return Expr::Kind::CompoundAssignment;
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down Expand Up @@ -2139,6 +2168,8 @@ class CallExpr : public ExprWithoutBlock
return *function;
}

std::unique_ptr<Expr> &get_function_expr_ptr () { return function; }
P-E-P marked this conversation as resolved.
Show resolved Hide resolved

const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }

Expand Down
Loading