aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir/tree')
-rw-r--r--gcc/rust/hir/tree/rust-hir-bound.h12
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr-abstract.h6
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.cc148
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h331
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-decls.h6
-rw-r--r--gcc/rust/hir/tree/rust-hir-generic-param.h7
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.cc37
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h83
-rw-r--r--gcc/rust/hir/tree/rust-hir-path.cc20
-rw-r--r--gcc/rust/hir/tree/rust-hir-path.h111
-rw-r--r--gcc/rust/hir/tree/rust-hir-pattern.h18
-rw-r--r--gcc/rust/hir/tree/rust-hir-stmt.cc12
-rw-r--r--gcc/rust/hir/tree/rust-hir-stmt.h16
-rw-r--r--gcc/rust/hir/tree/rust-hir-type.cc5
-rw-r--r--gcc/rust/hir/tree/rust-hir-type.h41
-rw-r--r--gcc/rust/hir/tree/rust-hir-visibility.h2
-rw-r--r--gcc/rust/hir/tree/rust-hir-visitor.cc1187
-rw-r--r--gcc/rust/hir/tree/rust-hir-visitor.h322
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc207
19 files changed, 2275 insertions, 296 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-bound.h b/gcc/rust/hir/tree/rust-hir-bound.h
index 78bb133..8fa6a22 100644
--- a/gcc/rust/hir/tree/rust-hir-bound.h
+++ b/gcc/rust/hir/tree/rust-hir-bound.h
@@ -44,18 +44,6 @@ public:
{}
// Returns true if the lifetime is in an error state.
- bool is_error () const
- {
- return lifetime_type == AST::Lifetime::LifetimeType::NAMED
- && lifetime_name.empty ();
- }
-
- static Lifetime error ()
- {
- return Lifetime (Analysis::NodeMapping::get_error (),
- AST::Lifetime::LifetimeType::NAMED, "", UNDEF_LOCATION);
- }
-
std::string as_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
diff --git a/gcc/rust/hir/tree/rust-hir-expr-abstract.h b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
index ecf9bd1..371daa8 100644
--- a/gcc/rust/hir/tree/rust-hir-expr-abstract.h
+++ b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
@@ -43,7 +43,7 @@ public:
WITHOUT_BLOCK,
};
- enum ExprType
+ enum class ExprType
{
Lit,
Operator,
@@ -58,6 +58,8 @@ public:
FieldAccess,
Closure,
Block,
+ AnonConst,
+ ConstBlock,
Continue,
Break,
Range,
@@ -71,6 +73,8 @@ public:
AsyncBlock,
Path,
InlineAsm,
+ LlvmInlineAsm,
+ OffsetOf,
};
BaseKind get_hir_kind () override final { return Node::BaseKind::EXPR; }
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
index 2ded789..14786ad 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.cc
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -17,6 +17,8 @@
// <http://www.gnu.org/licenses/>.
#include "rust-hir-expr.h"
+#include "rust-hir-map.h"
+#include "optional.h"
#include "rust-operators.h"
#include "rust-hir-stmt.h"
@@ -81,10 +83,10 @@ OperatorExpr::operator= (OperatorExpr const &other)
BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
- AST::AttrVec outer_attribs, location_t locus)
+ bool raw, AST::AttrVec outer_attribs, location_t locus)
: OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
std::move (outer_attribs), locus),
- mut (mut)
+ mut (mut), raw (raw)
{}
DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
@@ -749,7 +751,7 @@ BlockExpr::BlockExpr (Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<Stmt>> block_statements,
std::unique_ptr<Expr> block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- LoopLabel label, location_t start_locus,
+ tl::optional<LoopLabel> label, location_t start_locus,
location_t end_locus)
: ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
WithInnerAttrs (std::move (inner_attribs)),
@@ -790,14 +792,71 @@ BlockExpr::operator= (BlockExpr const &other)
return *this;
}
+AnonConst::AnonConst (Analysis::NodeMapping mappings,
+ std::unique_ptr<Expr> &&expr, location_t locus)
+ : ExprWithBlock (std::move (mappings), {}), locus (locus),
+ kind (Kind::Explicit), expr (std::move (expr))
+{
+ rust_assert (this->expr.value ());
+}
+
+AnonConst::AnonConst (Analysis::NodeMapping mappings, location_t locus)
+ : ExprWithBlock (std::move (mappings), {}), locus (locus),
+ kind (Kind::DeferredInference), expr (tl::nullopt)
+{}
+
+AnonConst::AnonConst (const AnonConst &other)
+ : ExprWithBlock (other), locus (other.locus), kind (other.kind)
+{
+ if (other.expr)
+ expr = other.expr.value ()->clone_expr ();
+}
+
+AnonConst
+AnonConst::operator= (const AnonConst &other)
+{
+ ExprWithBlock::operator= (other);
+
+ locus = other.locus;
+ kind = other.kind;
+
+ if (other.expr)
+ expr = other.expr.value ()->clone_expr ();
+
+ return *this;
+}
+
+ConstBlock::ConstBlock (Analysis::NodeMapping mappings, AnonConst &&expr,
+ location_t locus, AST::AttrVec outer_attrs)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
+ expr (std::move (expr)), locus (locus)
+{}
+
+ConstBlock::ConstBlock (const ConstBlock &other)
+ : ExprWithBlock (other), expr (other.expr), locus (other.locus)
+{}
+
+ConstBlock
+ConstBlock::operator= (const ConstBlock &other)
+{
+ ExprWithBlock::operator= (other);
+
+ expr = other.expr;
+ locus = other.locus;
+
+ return *this;
+}
+
ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime label, AST::AttrVec outer_attribs)
+ tl::optional<Lifetime> label,
+ AST::AttrVec outer_attribs)
: ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
label (std::move (label)), locus (locus)
{}
BreakExpr::BreakExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime break_label, std::unique_ptr<Expr> expr_in_break,
+ tl::optional<Lifetime> break_label,
+ std::unique_ptr<Expr> expr_in_break,
AST::AttrVec outer_attribs)
: ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
label (std::move (break_label)), break_expr (std::move (expr_in_break)),
@@ -985,7 +1044,8 @@ UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block,
- location_t locus, LoopLabel loop_label,
+ location_t locus,
+ tl::optional<LoopLabel> loop_label,
AST::AttrVec outer_attribs)
: ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
@@ -1011,7 +1071,8 @@ BaseLoopExpr::operator= (BaseLoopExpr const &other)
LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label, AST::AttrVec outer_attribs)
+ tl::optional<LoopLabel> loop_label,
+ AST::AttrVec outer_attribs)
: BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
std::move (loop_label), std::move (outer_attribs))
{}
@@ -1019,7 +1080,8 @@ LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> loop_condition,
std::unique_ptr<BlockExpr> loop_block,
- location_t locus, LoopLabel loop_label,
+ location_t locus,
+ tl::optional<LoopLabel> loop_label,
AST::AttrVec outer_attribs)
: BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
std::move (loop_label), std::move (outer_attribs)),
@@ -1046,7 +1108,8 @@ WhileLetLoopExpr::WhileLetLoopExpr (
Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
std::unique_ptr<Expr> condition, std::unique_ptr<BlockExpr> loop_block,
- location_t locus, LoopLabel loop_label, AST::AttrVec outer_attribs)
+ location_t locus, tl::optional<LoopLabel> loop_label,
+ AST::AttrVec outer_attribs)
: BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
std::move (loop_label), std::move (outer_attribs)),
match_arm_patterns (std::move (match_arm_patterns)),
@@ -1271,59 +1334,42 @@ AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
+ rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
{}
OperatorExprMeta::OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
+ rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
{}
OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_expr ().get_mappings ()),
+ rvalue_mappings (Analysis::NodeMapping::get_error ()),
locus (expr.get_locus ())
{}
OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_expr ().get_mappings ()),
+ rvalue_mappings (Analysis::NodeMapping::get_error ()),
locus (expr.get_locus ())
{}
OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_array_expr ().get_mappings ()),
+ rvalue_mappings (expr.get_index_expr ().get_mappings ()),
locus (expr.get_locus ())
{}
OperatorExprMeta::OperatorExprMeta (HIR::ComparisonExpr &expr)
: node_mappings (expr.get_mappings ()),
lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
+ rvalue_mappings (expr.get_rhs ().get_mappings ()), locus (expr.get_locus ())
{}
-AnonConst::AnonConst (NodeId id, std::unique_ptr<Expr> expr)
- : id (id), expr (std::move (expr))
-{
- rust_assert (this->expr != nullptr);
-}
-
-AnonConst::AnonConst (const AnonConst &other)
-{
- id = other.id;
- expr = other.expr->clone_expr ();
-}
-
-AnonConst
-AnonConst::operator= (const AnonConst &other)
-{
- id = other.id;
- expr = other.expr->clone_expr ();
- return *this;
-}
-
InlineAsmOperand::In::In (
const tl::optional<struct AST::InlineAsmRegOrRegClass> &reg,
std::unique_ptr<Expr> expr)
@@ -1470,7 +1516,7 @@ InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
std::vector<AST::TupleTemplateStr> template_strs,
std::vector<HIR::InlineAsmOperand> operands,
std::vector<AST::TupleClobber> clobber_abi,
- std::set<AST::InlineAsmOption> options,
+ std::set<AST::InlineAsm::Option> options,
Analysis::NodeMapping mappings,
AST::AttrVec outer_attribs)
: ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
@@ -1480,5 +1526,41 @@ InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
clobber_abi (std::move (clobber_abi)), options (std::move (options))
{}
+OffsetOf &
+OffsetOf::operator= (const OffsetOf &other)
+{
+ ExprWithoutBlock::operator= (other);
+
+ type = other.type->clone_type ();
+ field = other.field;
+ loc = other.loc;
+
+ return *this;
+}
+
+ExprWithoutBlock *
+OffsetOf::clone_expr_without_block_impl () const
+{
+ return new OffsetOf (*this);
+}
+
+std::string
+OffsetOf::as_string () const
+{
+ return "OffsetOf(" + type->as_string () + ", " + field.as_string () + ")";
+}
+
+void
+OffsetOf::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+OffsetOf::accept_vis (HIRFullVisitor &vis)
+{
+ vis.visit (*this);
+}
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index f8f2128..61e3590 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -19,12 +19,15 @@
#ifndef RUST_HIR_EXPR_H
#define RUST_HIR_EXPR_H
+#include "rust-ast.h"
#include "rust-hir-expr-abstract.h"
#include "rust-hir-literal.h"
#include "rust-common.h"
#include "rust-hir-bound.h"
#include "rust-hir-attrs.h"
#include "rust-expr.h"
+#include "rust-hir-map.h"
+#include "rust-mapping-common.h"
namespace Rust {
namespace HIR {
@@ -45,9 +48,6 @@ public:
LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
location_t locus);
- // Returns whether the LoopLabel is in an error state.
- bool is_error () const { return label.is_error (); }
-
location_t get_locus () const { return locus; }
Analysis::NodeMapping &get_mappings () { return mappings; }
@@ -199,12 +199,13 @@ public:
class BorrowExpr : public OperatorExpr
{
Mutability mut;
+ bool raw;
public:
std::string as_string () const override;
BorrowExpr (Analysis::NodeMapping mappings,
- std::unique_ptr<Expr> borrow_lvalue, Mutability mut,
+ std::unique_ptr<Expr> borrow_lvalue, Mutability mut, bool raw,
AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
@@ -212,6 +213,7 @@ public:
Mutability get_mut () const { return mut; }
bool is_mut () const { return mut == Mutability::Mut; }
+ bool is_raw_borrow () const { return raw; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -1715,7 +1717,7 @@ public:
std::vector<std::unique_ptr<Stmt>> statements;
std::unique_ptr<Expr> expr;
bool tail_reachable;
- LoopLabel label;
+ tl::optional<LoopLabel> label;
location_t start_locus;
location_t end_locus;
@@ -1735,7 +1737,8 @@ public:
std::vector<std::unique_ptr<Stmt>> block_statements,
std::unique_ptr<Expr> block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- LoopLabel label, location_t start_locus, location_t end_locus);
+ tl::optional<LoopLabel> label, location_t start_locus,
+ location_t end_locus);
// Copy constructor with clone
BlockExpr (BlockExpr const &other);
@@ -1774,8 +1777,8 @@ public:
return ExprType::Block;
}
- bool has_label () const { return !label.is_error (); }
- LoopLabel &get_label () { return label; }
+ bool has_label () const { return label.has_value (); }
+ LoopLabel &get_label () { return label.value (); }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -1800,28 +1803,116 @@ protected:
}
};
+class AnonConst : public ExprWithBlock
+{
+public:
+ enum class Kind
+ {
+ Explicit,
+ DeferredInference
+ };
+
+ AnonConst (Analysis::NodeMapping mappings, std::unique_ptr<Expr> &&expr,
+ location_t locus = UNKNOWN_LOCATION);
+ AnonConst (Analysis::NodeMapping mappings,
+ location_t locus = UNKNOWN_LOCATION);
+ AnonConst (const AnonConst &other);
+ AnonConst operator= (const AnonConst &other);
+
+ std::string as_string () const override;
+
+ void accept_vis (HIRFullVisitor &vis) override;
+ void accept_vis (HIRExpressionVisitor &vis) override;
+
+ ExprType get_expression_type () const final override
+ {
+ return ExprType::AnonConst;
+ }
+
+ location_t get_locus () const override { return locus; }
+
+ Expr &get_inner_expr ()
+ {
+ rust_assert (kind == Kind::Explicit);
+ return *expr.value ();
+ }
+
+ const Expr &get_inner_expr () const
+ {
+ rust_assert (kind == Kind::Explicit);
+ return *expr.value ();
+ }
+
+ bool is_deferred () const { return kind == Kind::DeferredInference; }
+
+private:
+ location_t locus;
+ Kind kind;
+ tl::optional<std::unique_ptr<Expr>> expr;
+
+ AnonConst *clone_expr_with_block_impl () const override
+ {
+ return new AnonConst (*this);
+ }
+};
+
+class ConstBlock : public ExprWithBlock
+{
+public:
+ ConstBlock (Analysis::NodeMapping mappings, AnonConst &&expr,
+ location_t locus = UNKNOWN_LOCATION,
+ AST::AttrVec outer_attrs = {});
+ ConstBlock (const ConstBlock &other);
+ ConstBlock operator= (const ConstBlock &other);
+
+ void accept_vis (HIRFullVisitor &vis) override;
+ void accept_vis (HIRExpressionVisitor &vis) override;
+
+ std::string as_string () const override;
+
+ ExprType get_expression_type () const final override
+ {
+ return ExprType::ConstBlock;
+ }
+
+ location_t get_locus () const override { return locus; }
+ AnonConst &get_const_expr () { return expr; }
+ const AnonConst &get_const_expr () const { return expr; }
+
+private:
+ AnonConst expr;
+ location_t locus;
+
+ ConstBlock *clone_expr_with_block_impl () const override
+ {
+ return new ConstBlock (*this);
+ }
+};
+
// HIR node representing continue expression within loops
class ContinueExpr : public ExprWithoutBlock
{
- Lifetime label;
+ tl::optional<Lifetime> label;
location_t locus;
public:
std::string as_string () const override;
// Returns true if the continue expr has a label.
- bool has_label () const { return !label.is_error (); }
+ bool has_label () const { return label.has_value (); }
// Constructor for a ContinueExpr with a label.
ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime label, AST::AttrVec outer_attribs = AST::AttrVec ());
+ tl::optional<Lifetime> label,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
location_t get_locus () const override final { return locus; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- Lifetime &get_label () { return label; }
+ Lifetime &get_label () { return label.value (); }
+ const Lifetime &get_label () const { return label.value (); }
ExprType get_expression_type () const final override
{
@@ -1848,7 +1939,7 @@ protected:
class BreakExpr : public ExprWithoutBlock
{
// bool has_label;
- Lifetime label;
+ tl::optional<Lifetime> label;
// bool has_break_expr;
std::unique_ptr<Expr> break_expr;
@@ -1859,7 +1950,7 @@ public:
std::string as_string () const override;
// Returns whether the break expression has a label or not.
- bool has_label () const { return !label.is_error (); }
+ bool has_label () const { return label.has_value (); }
/* Returns whether the break expression has an expression used in the break or
* not. */
@@ -1867,7 +1958,7 @@ public:
// Constructor for a break expression
BreakExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime break_label,
+ tl::optional<Lifetime> break_label,
std::unique_ptr<Expr> expr_in_break = nullptr,
AST::AttrVec outer_attribs = AST::AttrVec ());
@@ -1886,7 +1977,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- Lifetime &get_label () { return label; }
+ Lifetime &get_label () { return label.value (); }
+ const Lifetime &get_label () const { return label.value (); }
Expr &get_expr () { return *break_expr; }
@@ -2293,7 +2385,7 @@ protected:
class BaseLoopExpr : public ExprWithBlock
{
protected:
- LoopLabel loop_label;
+ tl::optional<LoopLabel> loop_label;
std::unique_ptr<BlockExpr> loop_block;
private:
@@ -2303,7 +2395,7 @@ protected:
// Constructor for BaseLoopExpr
BaseLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label,
+ tl::optional<LoopLabel> loop_label,
AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor for BaseLoopExpr with clone
@@ -2322,13 +2414,14 @@ protected:
}
public:
- bool has_loop_label () const { return !loop_label.is_error (); }
+ bool has_loop_label () const { return loop_label.has_value (); }
location_t get_locus () const override final { return locus; }
HIR::BlockExpr &get_loop_block () { return *loop_block; };
- LoopLabel &get_loop_label () { return loop_label; }
+ LoopLabel &get_loop_label () { return loop_label.value (); }
+ const LoopLabel &get_loop_label () const { return loop_label.value (); }
};
// 'Loop' expression (i.e. the infinite loop) HIR node
@@ -2340,7 +2433,8 @@ public:
// Constructor for LoopExpr
LoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label, AST::AttrVec outer_attribs = AST::AttrVec ());
+ tl::optional<LoopLabel> loop_label,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -2370,7 +2464,7 @@ public:
WhileLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> loop_condition,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label,
+ tl::optional<LoopLabel> loop_label,
AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
@@ -2419,7 +2513,7 @@ public:
std::vector<std::unique_ptr<Pattern>> match_arm_patterns,
std::unique_ptr<Expr> condition,
std::unique_ptr<BlockExpr> loop_block, location_t locus,
- LoopLabel loop_label,
+ tl::optional<LoopLabel> loop_label,
AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
@@ -2626,6 +2720,8 @@ public:
Expr &get_guard_expr () { return *guard_expr; }
location_t get_locus () const { return locus; }
+
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
};
/* A "match case" - a correlated match arm and resulting expression. Not
@@ -2818,6 +2914,22 @@ public:
OperatorExprMeta (HIR::ComparisonExpr &expr);
+ OperatorExprMeta (const OperatorExprMeta &other)
+ : node_mappings (other.node_mappings),
+ lvalue_mappings (other.lvalue_mappings),
+ rvalue_mappings (other.rvalue_mappings), locus (other.locus)
+ {}
+
+ OperatorExprMeta &operator= (const OperatorExprMeta &other)
+ {
+ node_mappings = other.node_mappings;
+ lvalue_mappings = other.lvalue_mappings;
+ rvalue_mappings = other.rvalue_mappings;
+ locus = other.locus;
+
+ return *this;
+ }
+
const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
const Analysis::NodeMapping &get_lvalue_mappings () const
@@ -2825,11 +2937,22 @@ public:
return lvalue_mappings;
}
+ const Analysis::NodeMapping &get_rvalue_mappings () const
+ {
+ return rvalue_mappings;
+ }
+
+ bool has_rvalue_mappings () const
+ {
+ return rvalue_mappings.get_hirid () != UNKNOWN_HIRID;
+ }
+
location_t get_locus () const { return locus; }
private:
- const Analysis::NodeMapping node_mappings;
- const Analysis::NodeMapping lvalue_mappings;
+ Analysis::NodeMapping node_mappings;
+ Analysis::NodeMapping lvalue_mappings;
+ Analysis::NodeMapping rvalue_mappings;
location_t locus;
};
@@ -2887,18 +3010,6 @@ class InlineAsmRegClass
std::string placeholder;
};
-struct AnonConst
-{
- NodeId id;
- std::unique_ptr<Expr> expr;
-
- AnonConst (NodeId id, std::unique_ptr<Expr> expr);
-
- AnonConst (const AnonConst &other);
-
- AnonConst operator= (const AnonConst &other);
-};
-
class InlineAsmOperand
{
public:
@@ -2987,8 +3098,9 @@ public:
Label operator= (const struct Label &other);
};
-private:
using RegisterType = AST::InlineAsmOperand::RegisterType;
+
+private:
AST::InlineAsmOperand::RegisterType register_type;
tl::optional<struct In> in;
@@ -3032,13 +3144,24 @@ public:
RegisterType get_register_type () const { return register_type; }
// Potentially unsafe without get_register_type() check
- struct In get_in () const { return in.value (); }
- struct Out get_out () const { return out.value (); }
- struct InOut get_in_out () const { return in_out.value (); }
- struct SplitInOut get_split_in_out () const { return split_in_out.value (); }
- struct Const get_const () const { return cnst.value (); }
- struct Sym get_sym () const { return sym.value (); }
- struct Label get_label () const { return label.value (); }
+ const struct In &get_in () const { return in.value (); }
+ const struct Out &get_out () const { return out.value (); }
+ const struct InOut &get_in_out () const { return in_out.value (); }
+ const struct SplitInOut &get_split_in_out () const
+ {
+ return split_in_out.value ();
+ }
+ const struct Const &get_const () const { return cnst.value (); }
+ const struct Sym &get_sym () const { return sym.value (); }
+ const struct Label &get_label () const { return label.value (); }
+
+ struct In &get_in () { return in.value (); }
+ struct Out &get_out () { return out.value (); }
+ struct InOut &get_in_out () { return in_out.value (); }
+ struct SplitInOut &get_split_in_out () { return split_in_out.value (); }
+ struct Const &get_const () { return cnst.value (); }
+ struct Sym &get_sym () { return sym.value (); }
+ struct Label &get_label () { return label.value (); }
};
// Inline Assembly Node
@@ -3054,7 +3177,7 @@ public:
std::vector<AST::TupleTemplateStr> template_strs;
std::vector<HIR::InlineAsmOperand> operands;
std::vector<AST::TupleClobber> clobber_abi;
- std::set<AST::InlineAsmOption> options;
+ std::set<AST::InlineAsm::Option> options;
std::vector<location_t> line_spans;
@@ -3085,11 +3208,11 @@ public:
return template_strs;
}
- std::vector<HIR::InlineAsmOperand> get_operands () { return operands; }
+ std::vector<HIR::InlineAsmOperand> &get_operands () { return operands; }
std::vector<AST::TupleClobber> get_clobber_abi () { return clobber_abi; }
- std::set<AST::InlineAsmOption> get_options () { return options; }
+ std::set<AST::InlineAsm::Option> get_options () { return options; }
bool is_simple_asm ()
{
@@ -3108,11 +3231,121 @@ public:
std::vector<AST::TupleTemplateStr> template_strs,
std::vector<HIR::InlineAsmOperand> operands,
std::vector<AST::TupleClobber> clobber_abi,
- std::set<AST::InlineAsmOption> options,
+ std::set<AST::InlineAsm::Option> options,
Analysis::NodeMapping mappings,
AST::AttrVec outer_attribs = AST::AttrVec ());
};
+class OffsetOf : public ExprWithoutBlock
+{
+public:
+ OffsetOf (std::unique_ptr<Type> &&type, Identifier field,
+ Analysis::NodeMapping mappings, location_t loc)
+ : ExprWithoutBlock (mappings), type (std::move (type)), field (field),
+ loc (loc)
+ {}
+
+ OffsetOf (const OffsetOf &other)
+ : ExprWithoutBlock (other), type (other.type->clone_type ()),
+ field (other.field), loc (other.loc)
+ {}
+
+ OffsetOf &operator= (const OffsetOf &other);
+
+ ExprWithoutBlock *clone_expr_without_block_impl () const override;
+ std::string as_string () const override;
+
+ void accept_vis (HIRExpressionVisitor &vis) override;
+ void accept_vis (HIRFullVisitor &vis) override;
+
+ ExprType get_expression_type () const override { return ExprType::OffsetOf; }
+
+ location_t get_locus () const override { return loc; }
+
+ Type &get_type () { return *type; }
+ const Type &get_type () const { return *type; }
+ const Identifier &get_field () const { return field; }
+
+private:
+ std::unique_ptr<Type> type;
+ Identifier field;
+ location_t loc;
+};
+
+struct LlvmOperand
+{
+ std::string constraint;
+ std::unique_ptr<Expr> expr;
+
+ LlvmOperand (std::string constraint, std::unique_ptr<Expr> &&expr)
+ : constraint (constraint), expr (std::move (expr))
+ {}
+
+ LlvmOperand (const LlvmOperand &other)
+ : constraint (other.constraint), expr (other.expr->clone_expr ())
+ {}
+ LlvmOperand &operator= (const LlvmOperand &other)
+ {
+ constraint = other.constraint;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+ }
+};
+
+class LlvmInlineAsm : public ExprWithoutBlock
+{
+public:
+ struct Options
+ {
+ bool is_volatile;
+ bool align_stack;
+ AST::LlvmInlineAsm::Dialect dialect;
+ };
+
+ location_t locus;
+ AST::AttrVec outer_attrs;
+ std::vector<LlvmOperand> inputs;
+ std::vector<LlvmOperand> outputs;
+ std::vector<AST::TupleTemplateStr> templates;
+ std::vector<AST::TupleClobber> clobbers;
+ Options options;
+
+ LlvmInlineAsm (location_t locus, std::vector<LlvmOperand> inputs,
+ std::vector<LlvmOperand> outputs,
+ std::vector<AST::TupleTemplateStr> templates,
+ std::vector<AST::TupleClobber> clobbers, Options options,
+ AST::AttrVec outer_attrs, Analysis::NodeMapping mappings)
+ : ExprWithoutBlock (mappings, std::move (outer_attrs)), locus (locus),
+ inputs (std::move (inputs)), outputs (std::move (outputs)),
+ templates (std::move (templates)), clobbers (std::move (clobbers)),
+ options (options)
+ {}
+
+ AST::LlvmInlineAsm::Dialect get_dialect () { return options.dialect; }
+
+ location_t get_locus () const override { return locus; }
+
+ std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ void accept_vis (HIRFullVisitor &vis) override;
+ void accept_vis (HIRExpressionVisitor &vis) override;
+
+ LlvmInlineAsm *clone_expr_without_block_impl () const override
+ {
+ return new LlvmInlineAsm (*this);
+ }
+
+ std::vector<AST::TupleTemplateStr> &get_templates () { return templates; }
+
+ Expr::ExprType get_expression_type () const override
+ {
+ return Expr::ExprType::LlvmInlineAsm;
+ }
+
+ std::vector<AST::TupleClobber> get_clobbers () { return clobbers; }
+};
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h
index c64c8bf..57b3a4d 100644
--- a/gcc/rust/hir/tree/rust-hir-full-decls.h
+++ b/gcc/rust/hir/tree/rust-hir-full-decls.h
@@ -95,6 +95,8 @@ class FieldAccessExpr;
struct ClosureParam;
class ClosureExpr;
class BlockExpr;
+class AnonConst;
+class ConstBlock;
class ContinueExpr;
class BreakExpr;
class RangeExpr;
@@ -123,9 +125,10 @@ class AwaitExpr;
class AsyncBlockExpr;
class InlineAsmReg;
class InlineAsmRegClass;
-struct AnonConst;
class InlineAsmOperand;
class InlineAsm;
+class LlvmInlineAsm;
+class OffsetOf;
// rust-stmt.h
class EmptyStmt;
@@ -211,7 +214,6 @@ class TraitBound;
class ImplTraitType;
class TraitObjectType;
class ParenthesisedType;
-class ImplTraitTypeOneBound;
class TupleType;
class NeverType;
class RawPointerType;
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.h b/gcc/rust/hir/tree/rust-hir-generic-param.h
index a1c59bf..340b5c6 100644
--- a/gcc/rust/hir/tree/rust-hir-generic-param.h
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.h
@@ -97,9 +97,6 @@ public:
AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
- // Returns whether the lifetime param is in an error state.
- bool is_error () const { return lifetime.is_error (); }
-
// Constructor
LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
location_t locus = UNDEF_LOCATION,
@@ -153,7 +150,7 @@ public:
location_t get_locus () const override final { return locus; };
- bool has_default_expression () { return default_expression != nullptr; }
+ bool has_default_expression () const { return default_expression != nullptr; }
std::string get_name () { return name; }
Type &get_type ()
@@ -163,6 +160,8 @@ public:
}
Expr &get_default_expression () { return *default_expression; }
+ const Expr &get_default_expression () const { return *default_expression; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc b/gcc/rust/hir/tree/rust-hir-item.cc
index cff06d3..1406e7a 100644
--- a/gcc/rust/hir/tree/rust-hir-item.cc
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -26,16 +26,18 @@ TypeParam::TypeParam (
Analysis::NodeMapping mappings, Identifier type_representation,
location_t locus,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
- tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs)
+ tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs,
+ bool was_impl_trait)
: GenericParam (mappings), outer_attrs (std::move (outer_attrs)),
type_representation (std::move (type_representation)),
type_param_bounds (std::move (type_param_bounds)), type (std::move (type)),
- locus (locus)
+ locus (locus), was_impl_trait (was_impl_trait)
{}
TypeParam::TypeParam (TypeParam const &other)
: GenericParam (other.mappings), outer_attrs (other.outer_attrs),
- type_representation (other.type_representation), locus (other.locus)
+ type_representation (other.type_representation), locus (other.locus),
+ was_impl_trait (other.was_impl_trait)
{
// guard to prevent null pointer dereference
if (other.has_type ())
@@ -55,6 +57,7 @@ TypeParam::operator= (TypeParam const &other)
outer_attrs = other.outer_attrs;
locus = other.locus;
mappings = other.mappings;
+ was_impl_trait = other.was_impl_trait;
// guard to prevent null pointer dereference
if (other.has_type ())
@@ -123,7 +126,8 @@ TypeBoundWhereClauseItem::get_type_param_bounds ()
}
SelfParam::SelfParam (Analysis::NodeMapping mappings,
- ImplicitSelfKind self_kind, Lifetime lifetime, Type *type)
+ ImplicitSelfKind self_kind,
+ tl::optional<Lifetime> lifetime, Type *type)
: self_kind (self_kind), lifetime (std::move (lifetime)), type (type),
mappings (mappings)
{}
@@ -131,13 +135,13 @@ SelfParam::SelfParam (Analysis::NodeMapping mappings,
SelfParam::SelfParam (Analysis::NodeMapping mappings,
std::unique_ptr<Type> type, bool is_mut, location_t locus)
: self_kind (is_mut ? ImplicitSelfKind::MUT : ImplicitSelfKind::IMM),
- lifetime (
- Lifetime (mappings, AST::Lifetime::LifetimeType::NAMED, "", locus)),
- type (std::move (type)), locus (locus), mappings (mappings)
+ lifetime (tl::nullopt), type (std::move (type)), locus (locus),
+ mappings (mappings)
{}
-SelfParam::SelfParam (Analysis::NodeMapping mappings, Lifetime lifetime,
- bool is_mut, location_t locus)
+SelfParam::SelfParam (Analysis::NodeMapping mappings,
+ tl::optional<Lifetime> lifetime, bool is_mut,
+ location_t locus)
: self_kind (is_mut ? ImplicitSelfKind::MUT_REF : ImplicitSelfKind::IMM_REF),
lifetime (std::move (lifetime)), locus (locus), mappings (mappings)
{}
@@ -263,7 +267,8 @@ Function::Function (Analysis::NodeMapping mappings, Identifier function_name,
std::vector<FunctionParam> function_params,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::unique_ptr<BlockExpr> function_body, Visibility vis,
- AST::AttrVec outer_attrs, SelfParam self, location_t locus)
+ AST::AttrVec outer_attrs, tl::optional<SelfParam> self,
+ Defaultness defaultness, location_t locus)
: VisItem (std::move (mappings), std::move (vis), std::move (outer_attrs)),
qualifiers (std::move (qualifiers)),
function_name (std::move (function_name)),
@@ -272,7 +277,7 @@ Function::Function (Analysis::NodeMapping mappings, Identifier function_name,
return_type (std::move (return_type)),
where_clause (std::move (where_clause)),
function_body (std::move (function_body)), self (std::move (self)),
- locus (locus)
+ locus (locus), defaultness (defaultness)
{}
Function::Function (Function const &other)
@@ -280,7 +285,7 @@ Function::Function (Function const &other)
function_name (other.function_name),
function_params (other.function_params), where_clause (other.where_clause),
function_body (other.function_body->clone_block_expr ()), self (other.self),
- locus (other.locus)
+ locus (other.locus), defaultness (other.defaultness)
{
// guard to prevent null dereference (always required)
if (other.return_type != nullptr)
@@ -312,6 +317,8 @@ Function::operator= (Function const &other)
locus = other.locus;
self = other.self;
+ defaultness = other.defaultness;
+
generic_params.reserve (other.generic_params.size ());
for (const auto &e : other.generic_params)
generic_params.push_back (e->clone_generic_param ());
@@ -609,9 +616,9 @@ StaticItem::operator= (StaticItem const &other)
TraitFunctionDecl::TraitFunctionDecl (
Identifier function_name, FunctionQualifiers qualifiers,
- std::vector<std::unique_ptr<GenericParam>> generic_params, SelfParam self,
- std::vector<FunctionParam> function_params, std::unique_ptr<Type> return_type,
- WhereClause where_clause)
+ std::vector<std::unique_ptr<GenericParam>> generic_params,
+ tl::optional<SelfParam> self, std::vector<FunctionParam> function_params,
+ std::unique_ptr<Type> return_type, WhereClause where_clause)
: qualifiers (std::move (qualifiers)),
function_name (std::move (function_name)),
generic_params (std::move (generic_params)),
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 4744717..d9df602 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -95,17 +95,11 @@ protected:
class TypeParam : public GenericParam
{
AST::AttrVec outer_attrs;
-
Identifier type_representation;
-
- // bool has_type_param_bounds;
- // TypeParamBounds type_param_bounds;
- std::vector<std::unique_ptr<TypeParamBound>>
- type_param_bounds; // inlined form
-
+ std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
tl::optional<std::unique_ptr<Type>> type;
-
location_t locus;
+ bool was_impl_trait;
public:
// Returns whether the type of the type param has been specified.
@@ -121,9 +115,9 @@ public:
TypeParam (Analysis::NodeMapping mappings, Identifier type_representation,
location_t locus = UNDEF_LOCATION,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
- = std::vector<std::unique_ptr<TypeParamBound>> (),
+ = {},
tl::optional<std::unique_ptr<Type>> type = tl::nullopt,
- AST::AttrVec outer_attrs = std::vector<AST::Attribute> ());
+ AST::AttrVec outer_attrs = {}, bool was_impl_trait = false);
// Copy constructor uses clone
TypeParam (TypeParam const &other);
@@ -154,6 +148,8 @@ public:
std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ();
+ bool from_impl_trait () const { return was_impl_trait; }
+
protected:
// Clone function implementation as (not pure) virtual method
TypeParam *clone_generic_param_impl () const override
@@ -213,6 +209,8 @@ public:
std::string as_string () const override;
+ location_t get_locus () const { return locus; }
+
void accept_vis (HIRFullVisitor &vis) override;
Lifetime &get_lifetime () { return lifetime; }
@@ -371,13 +369,13 @@ public:
private:
ImplicitSelfKind self_kind;
- Lifetime lifetime;
+ tl::optional<Lifetime> lifetime;
std::unique_ptr<Type> type;
location_t locus;
Analysis::NodeMapping mappings;
SelfParam (Analysis::NodeMapping mappings, ImplicitSelfKind self_kind,
- Lifetime lifetime, Type *type);
+ tl::optional<Lifetime> lifetime, Type *type);
public:
// Type-based self parameter (not ref, no lifetime)
@@ -385,8 +383,8 @@ public:
bool is_mut, location_t locus);
// Lifetime-based self parameter (is ref, no type)
- SelfParam (Analysis::NodeMapping mappings, Lifetime lifetime, bool is_mut,
- location_t locus);
+ SelfParam (Analysis::NodeMapping mappings, tl::optional<Lifetime> lifetime,
+ bool is_mut, location_t locus);
// Copy constructor requires clone
SelfParam (SelfParam const &other);
@@ -398,22 +396,15 @@ public:
SelfParam (SelfParam &&other) = default;
SelfParam &operator= (SelfParam &&other) = default;
- static SelfParam error ()
- {
- return SelfParam (Analysis::NodeMapping::get_error (),
- ImplicitSelfKind::NONE, Lifetime::error (), nullptr);
- }
-
// Returns whether the self-param has a type field.
bool has_type () const { return type != nullptr; }
// Returns whether the self-param has a valid lifetime.
- bool has_lifetime () const { return !lifetime.is_error (); }
+ bool has_lifetime () const { return lifetime.has_value (); }
- const Lifetime &get_lifetime () const { return lifetime; }
+ const Lifetime &get_lifetime () const { return lifetime.value (); }
- // Returns whether the self-param is in an error state.
- bool is_error () const { return self_kind == ImplicitSelfKind::NONE; }
+ Lifetime &get_lifetime () { return lifetime.value (); }
std::string as_string () const;
@@ -945,6 +936,12 @@ protected:
class LetStmt;
+enum class Defaultness
+{
+ Default,
+ Final,
+};
+
// Rust function declaration HIR node
class Function : public VisItem, public ImplItem
{
@@ -955,9 +952,14 @@ class Function : public VisItem, public ImplItem
std::unique_ptr<Type> return_type;
WhereClause where_clause;
std::unique_ptr<BlockExpr> function_body;
- SelfParam self;
+ tl::optional<SelfParam> self;
location_t locus;
+ // NOTE: This should be moved to the trait item base class once we start
+ // implementing specialization for real, instead of just stubbing out the
+ // feature
+ Defaultness defaultness;
+
public:
std::string as_string () const override;
@@ -973,6 +975,9 @@ public:
// Returns whether function has a where clause.
bool has_where_clause () const { return !where_clause.is_empty (); }
+ // Returns whether function has a default qualifier
+ bool is_default () const { return defaultness == Defaultness::Default; }
+
ImplItemType get_impl_item_type () const override final
{
return ImplItem::ImplItemType::FUNCTION;
@@ -987,7 +992,8 @@ public:
std::vector<FunctionParam> function_params,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::unique_ptr<BlockExpr> function_body, Visibility vis,
- AST::AttrVec outer_attrs, SelfParam self, location_t locus);
+ AST::AttrVec outer_attrs, tl::optional<SelfParam> self,
+ Defaultness defaultness, location_t locus);
// Copy constructor with clone
Function (Function const &other);
@@ -1041,9 +1047,13 @@ public:
// TODO: is this better? Or is a "vis_block" better?
Type &get_return_type () { return *return_type; }
- bool is_method () const { return !self.is_error (); }
+ bool is_method () const { return self.has_value (); }
+
+ tl::optional<SelfParam> &get_self_param () { return self; }
+ const tl::optional<SelfParam> &get_self_param () const { return self; }
- SelfParam &get_self_param () { return self; }
+ SelfParam &get_self_param_unchecked () { return self.value (); }
+ const SelfParam &get_self_param_unchecked () const { return self.value (); }
std::string get_impl_item_name () const override final
{
@@ -1791,6 +1801,8 @@ public:
return *type;
}
+ bool has_expr () const { return const_expr != nullptr; }
+
Expr &get_expr () { return *const_expr; }
Identifier get_identifier () const { return identifier; }
@@ -1898,13 +1910,14 @@ private:
std::vector<FunctionParam> function_params;
std::unique_ptr<Type> return_type;
WhereClause where_clause;
- SelfParam self;
+ tl::optional<SelfParam> self;
public:
// Mega-constructor
TraitFunctionDecl (Identifier function_name, FunctionQualifiers qualifiers,
std::vector<std::unique_ptr<GenericParam>> generic_params,
- SelfParam self, std::vector<FunctionParam> function_params,
+ tl::optional<SelfParam> self,
+ std::vector<FunctionParam> function_params,
std::unique_ptr<Type> return_type,
WhereClause where_clause);
@@ -1936,9 +1949,13 @@ public:
WhereClause &get_where_clause () { return where_clause; }
- bool is_method () const { return !self.is_error (); }
+ bool is_method () const { return self.has_value (); }
+
+ SelfParam &get_self_unchecked () { return self.value (); }
+ const SelfParam &get_self_unchecked () const { return self.value (); }
- SelfParam &get_self () { return self; }
+ tl::optional<SelfParam> &get_self () { return self; }
+ const tl::optional<SelfParam> &get_self () const { return self; }
Identifier get_function_name () const { return function_name; }
@@ -2055,6 +2072,8 @@ public:
Identifier get_name () const { return name; }
+ bool has_type () const { return expr != nullptr; }
+
bool has_expr () const { return expr != nullptr; }
Type &get_type ()
diff --git a/gcc/rust/hir/tree/rust-hir-path.cc b/gcc/rust/hir/tree/rust-hir-path.cc
index 7db2b25..ee4a572 100644
--- a/gcc/rust/hir/tree/rust-hir-path.cc
+++ b/gcc/rust/hir/tree/rust-hir-path.cc
@@ -133,6 +133,8 @@ PathExprSegment::operator= (PathExprSegment const &other)
void
PathPattern::iterate_path_segments (std::function<bool (PathExprSegment &)> cb)
{
+ rust_assert (kind == Kind::Segmented);
+
for (auto it = segments.begin (); it != segments.end (); it++)
{
if (!cb (*it))
@@ -150,6 +152,15 @@ PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
{}
+PathInExpression::PathInExpression (Analysis::NodeMapping mappings,
+ LangItem::Kind lang_item, location_t locus,
+ bool has_opening_scope_resolution,
+ std::vector<AST::Attribute> outer_attrs)
+ : PathPattern (lang_item),
+ PathExpr (std::move (mappings), std::move (outer_attrs)),
+ has_opening_scope_resolution (has_opening_scope_resolution), locus (locus)
+{}
+
bool
PathInExpression::is_self () const
@@ -358,6 +369,15 @@ QualifiedPathInExpression::QualifiedPathInExpression (
path_type (std::move (qual_path_type)), locus (locus)
{}
+QualifiedPathInExpression::QualifiedPathInExpression (
+ Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
+ LangItem::Kind lang_item, location_t locus,
+ std::vector<AST::Attribute> outer_attrs)
+ : PathPattern (lang_item),
+ PathExpr (std::move (mappings), std::move (outer_attrs)),
+ path_type (std::move (qual_path_type)), locus (locus)
+{}
+
QualifiedPathInType::QualifiedPathInType (
Analysis::NodeMapping mappings, QualifiedPathType qual_path_type,
std::unique_ptr<TypePathSegment> associated_segment,
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index bbb9c2d..4f296d8 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -19,6 +19,7 @@
#ifndef RUST_HIR_PATH_H
#define RUST_HIR_PATH_H
+#include "rust-hir-map.h"
#include "rust-hir-simple-path.h"
#include "rust-hir-type-no-bounds.h"
#include "rust-hir-pattern-abstract.h"
@@ -40,11 +41,15 @@ public:
: segment_name (std::move (segment_name))
{}
- /* TODO: insert check in constructor for this? Or is this a semantic error
- * best handled then? */
+ PathIdentSegment (const PathIdentSegment &other)
+ : segment_name (other.segment_name)
+ {}
- /* TODO: does this require visitor? pretty sure this isn't polymorphic, but
- * not entirely sure */
+ PathIdentSegment &operator= (PathIdentSegment const &other)
+ {
+ segment_name = other.segment_name;
+ return *this;
+ }
// Creates an error PathIdentSegment.
static PathIdentSegment create_error () { return PathIdentSegment (""); }
@@ -127,6 +132,8 @@ public:
std::unique_ptr<Expr> &get_expression () { return expression; }
+ location_t get_locus () const { return locus; }
+
private:
std::unique_ptr<Expr> expression;
location_t locus;
@@ -145,7 +152,7 @@ public:
bool has_generic_args () const
{
return !(lifetime_args.empty () && type_args.empty ()
- && binding_args.empty ());
+ && binding_args.empty () && const_args.empty ());
}
GenericArgs (std::vector<Lifetime> lifetime_args,
@@ -230,15 +237,34 @@ public:
// HIR node representing a pattern that involves a "path" - abstract base class
class PathPattern : public Pattern
{
+public:
+ enum class Kind
+ {
+ Segmented,
+ LangItem
+ };
+
+private:
std::vector<PathExprSegment> segments;
+ tl::optional<LangItem::Kind> lang_item;
+ Kind kind;
protected:
PathPattern (std::vector<PathExprSegment> segments)
- : segments (std::move (segments))
+ : segments (std::move (segments)), lang_item (tl::nullopt),
+ kind (Kind::Segmented)
+ {}
+
+ PathPattern (LangItem::Kind lang_item)
+ : segments ({}), lang_item (lang_item), kind (Kind::LangItem)
{}
// Returns whether path has segments.
- bool has_segments () const { return !segments.empty (); }
+ bool has_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return !segments.empty ();
+ }
/* Converts path segments to their equivalent SimplePath segments if possible,
* and creates a SimplePath from them. */
@@ -248,26 +274,61 @@ protected:
public:
/* Returns whether the path is a single segment (excluding qualified path
* initial as segment). */
- bool is_single_segment () const { return segments.size () == 1; }
+ bool is_single_segment () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.size () == 1;
+ }
std::string as_string () const override;
void iterate_path_segments (std::function<bool (PathExprSegment &)> cb);
- size_t get_num_segments () const { return segments.size (); }
+ size_t get_num_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.size ();
+ }
- std::vector<PathExprSegment> &get_segments () { return segments; }
+ std::vector<PathExprSegment> &get_segments ()
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments;
+ }
- const std::vector<PathExprSegment> &get_segments () const { return segments; }
+ const std::vector<PathExprSegment> &get_segments () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments;
+ }
- PathExprSegment &get_root_seg () { return segments.at (0); }
+ PathExprSegment &get_root_seg ()
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.at (0);
+ }
- const PathExprSegment &get_final_segment () const { return segments.back (); }
+ const PathExprSegment &get_final_segment () const
+ {
+ rust_assert (kind == Kind::Segmented);
+ return segments.back ();
+ }
+
+ LangItem::Kind get_lang_item () const
+ {
+ rust_assert (kind == Kind::LangItem);
+
+ return *lang_item;
+ }
PatternType get_pattern_type () const override final
{
return PatternType::PATH;
}
+
+ bool is_lang_item () const { return kind == Kind::LangItem; }
+
+ Kind get_path_kind () const { return kind; }
};
/* HIR node representing a path-in-expression pattern (path that allows generic
@@ -288,6 +349,13 @@ public:
std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> ());
+ // lang-item Constructor
+ PathInExpression (Analysis::NodeMapping mappings, LangItem::Kind kind,
+ location_t locus = UNDEF_LOCATION,
+ bool has_opening_scope_resolution = false,
+ std::vector<AST::Attribute> outer_attrs
+ = std::vector<AST::Attribute> ());
+
// Creates an error state path in expression.
static PathInExpression create_error ()
{
@@ -671,13 +739,20 @@ public:
Analysis::NodeMapping get_mappings () const { return mappings; }
+ bool has_type () { return type != nullptr; }
+ bool has_trait () { return trait != nullptr; }
+
Type &get_type ()
{
rust_assert (type);
return *type;
}
- TypePath &get_trait () { return *trait; }
+ TypePath &get_trait ()
+ {
+ rust_assert (trait);
+ return *trait;
+ }
bool trait_has_generic_args () const;
@@ -701,6 +776,14 @@ public:
std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> ());
+ // lang-item constructor
+ QualifiedPathInExpression (Analysis::NodeMapping mappings,
+ QualifiedPathType qual_path_type,
+ LangItem::Kind lang_item,
+ location_t locus = UNDEF_LOCATION,
+ std::vector<AST::Attribute> outer_attrs
+ = std::vector<AST::Attribute> ());
+
location_t get_locus () const override final { return locus; }
void accept_vis (HIRFullVisitor &vis) override;
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index 5cc5c95..9c636ca 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -80,7 +80,7 @@ class IdentifierPattern : public Pattern
Identifier variable_ident;
bool is_ref;
Mutability mut;
- std::unique_ptr<Pattern> to_bind;
+ std::unique_ptr<Pattern> subpattern;
location_t locus;
Analysis::NodeMapping mappings;
@@ -88,15 +88,15 @@ public:
std::string as_string () const override;
// Returns whether the IdentifierPattern has a pattern to bind.
- bool has_pattern_to_bind () const { return to_bind != nullptr; }
+ bool has_subpattern () const { return subpattern != nullptr; }
// Constructor
IdentifierPattern (Analysis::NodeMapping mappings, Identifier ident,
location_t locus, bool is_ref = false,
Mutability mut = Mutability::Imm,
- std::unique_ptr<Pattern> to_bind = nullptr)
+ std::unique_ptr<Pattern> subpattern = nullptr)
: variable_ident (std::move (ident)), is_ref (is_ref), mut (mut),
- to_bind (std::move (to_bind)), locus (locus), mappings (mappings)
+ subpattern (std::move (subpattern)), locus (locus), mappings (mappings)
{}
// Copy constructor with clone
@@ -105,8 +105,8 @@ public:
mut (other.mut), locus (other.locus), mappings (other.mappings)
{
// fix to get prevent null pointer dereference
- if (other.to_bind != nullptr)
- to_bind = other.to_bind->clone_pattern ();
+ if (other.subpattern != nullptr)
+ subpattern = other.subpattern->clone_pattern ();
}
// Overload assignment operator to use clone
@@ -119,8 +119,8 @@ public:
mappings = other.mappings;
// fix to get prevent null pointer dereference
- if (other.to_bind != nullptr)
- to_bind = other.to_bind->clone_pattern ();
+ if (other.subpattern != nullptr)
+ subpattern = other.subpattern->clone_pattern ();
return *this;
}
@@ -133,7 +133,7 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
bool get_is_ref () const { return is_ref; }
- Pattern &get_to_bind () { return *to_bind; }
+ Pattern &get_subpattern () { return *subpattern; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRPatternVisitor &vis) override;
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.cc b/gcc/rust/hir/tree/rust-hir-stmt.cc
index 025f67e..fd58e29 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.cc
+++ b/gcc/rust/hir/tree/rust-hir-stmt.cc
@@ -26,11 +26,13 @@ namespace HIR {
LetStmt::LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
tl::optional<std::unique_ptr<Expr>> init_expr,
+ tl::optional<std::unique_ptr<Expr>> else_expr,
tl::optional<std::unique_ptr<Type>> type,
AST::AttrVec outer_attrs, location_t locus)
: Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
variables_pattern (std::move (variables_pattern)), type (std::move (type)),
- init_expr (std::move (init_expr)), locus (locus)
+ init_expr (std::move (init_expr)), else_expr (std::move (else_expr)),
+ locus (locus)
{}
LetStmt::LetStmt (LetStmt const &other)
@@ -43,6 +45,8 @@ LetStmt::LetStmt (LetStmt const &other)
// guard to prevent null dereference (always required)
if (other.has_init_expr ())
init_expr = other.get_init_expr ().clone_expr ();
+ if (other.has_else_expr ())
+ else_expr = other.get_else_expr ().clone_expr ();
if (other.has_type ())
type = other.get_type ().clone_type ();
@@ -67,6 +71,12 @@ LetStmt::operator= (LetStmt const &other)
init_expr = other.get_init_expr ().clone_expr ();
else
init_expr = nullptr;
+
+ if (other.has_else_expr ())
+ else_expr = other.get_else_expr ().clone_expr ();
+ else
+ else_expr = tl::nullopt;
+
if (other.has_type ())
type = other.get_type ().clone_type ();
else
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index 3db1728..9c1a9ec 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -101,6 +101,7 @@ class LetStmt : public Stmt
tl::optional<std::unique_ptr<Type>> type;
tl::optional<std::unique_ptr<Expr>> init_expr;
+ tl::optional<std::unique_ptr<Expr>> else_expr;
location_t locus;
@@ -113,12 +114,15 @@ public:
// Returns whether let statement has an initialisation expression.
bool has_init_expr () const { return init_expr.has_value (); }
+ // Returns whether let statement has a diverging else expression.
+ bool has_else_expr () const { return else_expr.has_value (); }
std::string as_string () const override;
LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
tl::optional<std::unique_ptr<Expr>> init_expr,
+ tl::optional<std::unique_ptr<Expr>> else_expr,
tl::optional<std::unique_ptr<Type>> type, AST::AttrVec outer_attrs,
location_t locus);
@@ -167,6 +171,18 @@ public:
return *init_expr.value ();
}
+ HIR::Expr &get_else_expr ()
+ {
+ rust_assert (*else_expr);
+ return *else_expr.value ();
+ }
+
+ const HIR::Expr &get_else_expr () const
+ {
+ rust_assert (*else_expr);
+ return *else_expr.value ();
+ }
+
HIR::Pattern &get_pattern () { return *variables_pattern; }
bool is_item () const override final { return false; }
diff --git a/gcc/rust/hir/tree/rust-hir-type.cc b/gcc/rust/hir/tree/rust-hir-type.cc
index 689d86b..ec48425 100644
--- a/gcc/rust/hir/tree/rust-hir-type.cc
+++ b/gcc/rust/hir/tree/rust-hir-type.cc
@@ -162,7 +162,7 @@ RawPointerType::operator= (RawPointerType const &other)
ReferenceType::ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
std::unique_ptr<Type> type_no_bounds,
- location_t locus, Lifetime lifetime)
+ location_t locus, tl::optional<Lifetime> lifetime)
: TypeNoBounds (mappings, locus), lifetime (std::move (lifetime)), mut (mut),
type (std::move (type_no_bounds))
{}
@@ -268,7 +268,8 @@ BareFunctionType::BareFunctionType (BareFunctionType const &other)
for_lifetimes (other.for_lifetimes),
function_qualifiers (other.function_qualifiers), params (other.params),
is_variadic (other.is_variadic),
- return_type (other.return_type->clone_type ())
+ return_type (other.has_return_type () ? other.return_type->clone_type ()
+ : nullptr)
{}
BareFunctionType &
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index e231d78..cbc20ff 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -164,38 +164,6 @@ public:
void accept_vis (HIRTypeVisitor &vis) override;
};
-// Impl trait with a single bound? Poor reference material here.
-class ImplTraitTypeOneBound : public TypeNoBounds
-{
- TraitBound trait_bound;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- ImplTraitTypeOneBound *clone_type_impl () const override
- {
- return new ImplTraitTypeOneBound (*this);
- }
-
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- ImplTraitTypeOneBound *clone_type_no_bounds_impl () const override
- {
- return new ImplTraitTypeOneBound (*this);
- }
-
-public:
- ImplTraitTypeOneBound (Analysis::NodeMapping mappings, TraitBound trait_bound,
- location_t locus)
- : TypeNoBounds (mappings, locus), trait_bound (std::move (trait_bound))
- {}
-
- std::string as_string () const override;
- TraitBound &get_trait_bound () { return trait_bound; }
- void accept_vis (HIRFullVisitor &vis) override;
- void accept_vis (HIRTypeVisitor &vis) override;
-};
-
/* A type consisting of the "product" of others (the tuple's elements) in a
* specific order */
class TupleType : public TypeNoBounds
@@ -323,7 +291,7 @@ protected:
class ReferenceType : public TypeNoBounds
{
// bool has_lifetime; // TODO: handle in lifetime or something?
- Lifetime lifetime;
+ tl::optional<Lifetime> lifetime;
Mutability mut;
std::unique_ptr<Type> type;
@@ -333,12 +301,12 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
// Returns whether the reference has a lifetime.
- bool has_lifetime () const { return !lifetime.is_error (); }
+ bool has_lifetime () const { return lifetime.has_value (); }
// Constructor
ReferenceType (Analysis::NodeMapping mappings, Mutability mut,
std::unique_ptr<Type> type_no_bounds, location_t locus,
- Lifetime lifetime);
+ tl::optional<Lifetime> lifetime);
// Copy constructor with custom clone method
ReferenceType (ReferenceType const &other);
@@ -355,7 +323,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
- Lifetime &get_lifetime () { return lifetime; }
+ Lifetime &get_lifetime () { return lifetime.value (); }
+ const Lifetime &get_lifetime () const { return lifetime.value (); }
Mutability get_mut () const { return mut; }
diff --git a/gcc/rust/hir/tree/rust-hir-visibility.h b/gcc/rust/hir/tree/rust-hir-visibility.h
index a750d88..9dd6ff2 100644
--- a/gcc/rust/hir/tree/rust-hir-visibility.h
+++ b/gcc/rust/hir/tree/rust-hir-visibility.h
@@ -73,6 +73,8 @@ public:
}
std::string as_string () const;
+
+ location_t get_locus () const { return locus; }
};
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.cc b/gcc/rust/hir/tree/rust-hir-visitor.cc
new file mode 100644
index 0000000..58c1e1a
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-visitor.cc
@@ -0,0 +1,1187 @@
+// Copyright (C) 2021-2025 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-expr.h"
+#include "rust-hir-full-decls.h"
+#include "rust-hir-visitor.h"
+#include "rust-hir-full.h"
+#include "rust-system.h"
+
+namespace Rust {
+namespace HIR {
+
+void
+DefaultHIRVisitor::walk (Lifetime &)
+{}
+
+void
+DefaultHIRVisitor::walk (LifetimeParam &lifetime_param)
+{
+ visit_outer_attrs (lifetime_param);
+ lifetime_param.get_lifetime ().accept_vis (*this);
+ for (Lifetime &lifetime_bound : lifetime_param.get_lifetime_bounds ())
+ lifetime_bound.accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_generic_args (GenericArgs &generic_args)
+{
+ for (auto &lifetime : generic_args.get_lifetime_args ())
+ lifetime.accept_vis (*this);
+ for (auto &type : generic_args.get_type_args ())
+ type->accept_vis (*this);
+ for (auto &binding : generic_args.get_binding_args ())
+ binding.get_type ().accept_vis (*this);
+ for (auto &const_arg : generic_args.get_const_args ())
+ const_arg.get_expression ()->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (PathInExpression &path_in_expr)
+{
+ visit_outer_attrs (path_in_expr);
+ if (!path_in_expr.is_lang_item ())
+ for (auto &segment : path_in_expr.get_segments ())
+ visit_path_expr_segment (segment);
+}
+
+void
+DefaultHIRVisitor::walk (TypePathSegment &)
+{}
+
+void
+DefaultHIRVisitor::walk (TypePathSegmentFunction &segment_function)
+{
+ TypePathFunction &function_path = segment_function.get_function_path ();
+ if (function_path.has_inputs ())
+ for (auto &param : function_path.get_params ())
+ param->accept_vis (*this);
+ if (function_path.has_return_type ())
+ function_path.get_return_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TypePathSegmentGeneric &segment_generic)
+{
+ if (segment_generic.has_generic_args ())
+ visit_generic_args (segment_generic.get_generic_args ());
+}
+
+void
+DefaultHIRVisitor::walk (TypePath &type_path)
+{
+ for (auto &segment : type_path.get_segments ())
+ segment->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_qualified_path_type (QualifiedPathType &path)
+{
+ path.get_type ().accept_vis (*this);
+ if (path.has_as_clause ())
+ path.get_trait ().accept_vis (*this);
+}
+
+// TODO: Implement visit_path_expr_segment
+void
+DefaultHIRVisitor::visit_path_expr_segment (PathExprSegment &segment)
+{
+ if (segment.has_generic_args ())
+ visit_generic_args (segment.get_generic_args ());
+}
+
+void
+DefaultHIRVisitor::walk (QualifiedPathInExpression &path_in_expr)
+{
+ visit_outer_attrs (path_in_expr);
+ visit_qualified_path_type (path_in_expr.get_path_type ());
+ for (auto &segment : path_in_expr.get_segments ())
+ visit_path_expr_segment (segment);
+}
+
+void
+DefaultHIRVisitor::walk (QualifiedPathInType &path_in_type)
+{
+ visit_qualified_path_type (path_in_type.get_path_type ());
+ path_in_type.get_associated_segment ().accept_vis (*this);
+ for (auto &segment : path_in_type.get_segments ())
+ segment->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (LiteralExpr &expr)
+{
+ visit_outer_attrs (expr);
+}
+
+void
+DefaultHIRVisitor::walk (BorrowExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (DereferenceExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ErrorPropagationExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (NegationExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArithmeticOrLogicalExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ComparisonExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (LazyBooleanExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TypeCastExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_expr ().accept_vis (*this);
+ expr.get_type_to_convert_to ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (AssignmentExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (CompoundAssignmentExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_lhs ().accept_vis (*this);
+ expr.get_rhs ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (GroupedExpr &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_expr_in_parens ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArrayElemsValues &elems)
+{
+ for (auto &elem : elems.get_values ())
+ elem->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArrayElemsCopied &elems)
+{
+ elems.get_elem_to_copy ().accept_vis (*this);
+ elems.get_num_copies_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArrayExpr &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_internal_elements ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArrayIndexExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_array_expr ().accept_vis (*this);
+ expr.get_index_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleExpr &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ for (auto &elem : expr.get_tuple_elems ())
+ elem->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleIndexExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_tuple_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructExprStruct &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_struct_name ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructExprFieldIdentifier &)
+{}
+
+void
+DefaultHIRVisitor::walk (StructExprFieldIdentifierValue &field)
+{
+ field.get_value ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructExprFieldIndexValue &field)
+{
+ field.get_value ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructExprStructFields &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_struct_name ().accept_vis (*this);
+ if (expr.has_struct_base ())
+ {
+ StructBase &base = expr.get_struct_base ();
+ base.get_base ().accept_vis (*this);
+ }
+ for (auto &field : expr.get_fields ())
+ field->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructExprStructBase &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_struct_name ().accept_vis (*this);
+ StructBase &base = expr.get_struct_base ();
+ base.get_base ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (CallExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_fnexpr ().accept_vis (*this);
+ for (auto &arg : expr.get_arguments ())
+ arg->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (MethodCallExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_receiver ().accept_vis (*this);
+ visit_path_expr_segment (expr.get_method_name ());
+ for (auto &arg : expr.get_arguments ())
+ arg->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (FieldAccessExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_receiver_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_closure_param (ClosureParam &param)
+{
+ visit_outer_attrs (param);
+ param.get_pattern ().accept_vis (*this);
+ if (param.has_type_given ())
+ {
+ param.get_type ().accept_vis (*this);
+ }
+}
+
+void
+DefaultHIRVisitor::walk (ClosureExpr &expr)
+{
+ visit_outer_attrs (expr);
+ for (auto &param : expr.get_params ())
+ visit_closure_param (param);
+ if (expr.has_return_type ())
+ expr.get_return_type ().accept_vis (*this);
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (BlockExpr &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ for (auto &stmt : expr.get_statements ())
+ stmt->accept_vis (*this);
+ if (expr.has_expr ())
+ expr.get_final_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (AnonConst &expr)
+{
+ if (!expr.is_deferred ())
+ expr.get_inner_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ConstBlock &expr)
+{
+ expr.get_const_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ContinueExpr &expr)
+{
+ visit_outer_attrs (expr);
+ if (expr.has_label ())
+ expr.get_label ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (BreakExpr &expr)
+{
+ visit_outer_attrs (expr);
+ if (expr.has_label ())
+ expr.get_label ().accept_vis (*this);
+
+ if (expr.has_break_expr ())
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangeFromToExpr &expr)
+{
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangeFromExpr &expr)
+{
+ expr.get_from_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangeToExpr &expr)
+{
+ expr.get_to_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangeFullExpr &)
+{}
+
+void
+DefaultHIRVisitor::walk (RangeFromToInclExpr &expr)
+{
+ expr.get_from_expr ().accept_vis (*this);
+ expr.get_to_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangeToInclExpr &expr)
+{
+ expr.get_to_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ReturnExpr &expr)
+{
+ visit_outer_attrs (expr);
+ if (expr.has_return_expr ())
+ expr.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (UnsafeBlockExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_block_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_loop_label (LoopLabel &label)
+{
+ label.get_lifetime ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (LoopExpr &expr)
+{
+ visit_outer_attrs (expr);
+ if (expr.has_loop_label ())
+ visit_loop_label (expr.get_loop_label ());
+ expr.get_loop_block ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (WhileLoopExpr &expr)
+{
+ visit_outer_attrs (expr);
+ if (expr.has_loop_label ())
+ visit_loop_label (expr.get_loop_label ());
+ expr.get_predicate_expr ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (WhileLetLoopExpr &expr)
+{
+ visit_outer_attrs (expr);
+ for (auto &pattern : expr.get_patterns ())
+ pattern->accept_vis (*this);
+ if (expr.has_loop_label ())
+ visit_loop_label (expr.get_loop_label ());
+ expr.get_cond ().accept_vis (*this);
+ expr.get_loop_block ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (IfExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_if_condition ().accept_vis (*this);
+ expr.get_if_block ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (IfExprConseqElse &expr)
+{
+ expr.IfExpr::accept_vis (*this);
+ expr.get_else_block ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_match_arm (MatchArm &arm)
+{
+ // visit_outer_attrs (arm);
+ for (auto &pattern : arm.get_patterns ())
+ pattern->accept_vis (*this);
+ if (arm.has_match_arm_guard ())
+ arm.get_guard_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_match_case (MatchCase &arm)
+{
+ visit_match_arm (arm.get_arm ());
+ arm.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (MatchExpr &expr)
+{
+ visit_outer_attrs (expr);
+ visit_inner_attrs (expr);
+ expr.get_scrutinee_expr ().accept_vis (*this);
+ for (auto &arm : expr.get_match_cases ())
+ visit_match_case (arm);
+}
+
+void
+DefaultHIRVisitor::walk (AwaitExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_awaited_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (AsyncBlockExpr &expr)
+{
+ visit_outer_attrs (expr);
+ expr.get_block_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (InlineAsm &expr)
+{
+ visit_outer_attrs (expr);
+ auto &operands = expr.get_operands ();
+ using RegisterType = AST::InlineAsmOperand::RegisterType;
+ for (auto &operand : operands)
+ {
+ switch (operand.get_register_type ())
+ {
+ case RegisterType::In:
+ {
+ operand.get_in ().expr->accept_vis (*this);
+ break;
+ }
+ case RegisterType::Out:
+ {
+ operand.get_out ().expr->accept_vis (*this);
+ break;
+ }
+ case RegisterType::InOut:
+ {
+ operand.get_in_out ().expr->accept_vis (*this);
+ break;
+ }
+ case RegisterType::SplitInOut:
+ {
+ operand.get_split_in_out ().in_expr->accept_vis (*this);
+ operand.get_split_in_out ().out_expr->accept_vis (*this);
+ break;
+ }
+ case RegisterType::Const:
+ {
+ operand.get_const ().anon_const.get_inner_expr ().accept_vis (
+ *this);
+ break;
+ }
+ case RegisterType::Sym:
+ {
+ operand.get_sym ().expr->accept_vis (*this);
+ break;
+ }
+ case RegisterType::Label:
+ {
+ operand.get_label ().expr->accept_vis (*this);
+ break;
+ }
+ }
+ }
+}
+
+void
+DefaultHIRVisitor::walk (LlvmInlineAsm &expr)
+{
+ for (auto &output : expr.outputs)
+ output.expr->accept_vis (*this);
+ for (auto &input : expr.inputs)
+ input.expr->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (OffsetOf &expr)
+{
+ expr.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TypeParam &param)
+{
+ visit_outer_attrs (param);
+ for (auto &bounds : param.get_type_param_bounds ())
+ bounds->accept_vis (*this);
+ if (param.has_type ())
+ param.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ConstGenericParam &const_param)
+{
+ visit_outer_attrs (const_param);
+ const_param.get_type ().accept_vis (*this);
+ if (const_param.has_default_expression ())
+ const_param.get_default_expression ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (LifetimeWhereClauseItem &item)
+{
+ item.get_lifetime ().accept_vis (*this);
+ for (auto &bound : item.get_lifetime_bounds ())
+ bound.accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TypeBoundWhereClauseItem &item)
+{
+ for (auto &lifetime : item.get_for_lifetimes ())
+ lifetime.accept_vis (*this);
+ item.get_bound_type ().accept_vis (*this);
+ for (auto &param : item.get_type_param_bounds ())
+ param->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (Module &module)
+{
+ visit_outer_attrs (module);
+ visit_inner_attrs (module);
+ for (auto &item : module.get_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ExternCrate &crate)
+{
+ visit_outer_attrs (crate);
+}
+
+void
+DefaultHIRVisitor::walk (UseTreeGlob &)
+{}
+
+void
+DefaultHIRVisitor::walk (UseTreeList &)
+{}
+
+void
+DefaultHIRVisitor::walk (UseTreeRebind &)
+{}
+
+void
+DefaultHIRVisitor::walk (UseDeclaration &)
+{}
+
+void
+DefaultHIRVisitor::visit_function_param (FunctionParam &param)
+{
+ param.get_param_name ().accept_vis (*this);
+ param.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (Function &function)
+{
+ visit_outer_attrs (function);
+ for (auto &generic : function.get_generic_params ())
+ generic->accept_vis (*this);
+ for (auto &param : function.get_function_params ())
+ visit_function_param (param);
+ if (function.has_return_type ())
+ function.get_return_type ().accept_vis (*this);
+ if (function.has_where_clause ())
+ visit_where_clause (function.get_where_clause ());
+ function.get_definition ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TypeAlias &type_alias)
+{
+ visit_outer_attrs (type_alias);
+ for (auto &generic : type_alias.get_generic_params ())
+ generic->accept_vis (*this);
+ if (type_alias.has_where_clause ())
+ visit_where_clause (type_alias.get_where_clause ());
+ type_alias.get_type_aliased ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_struct_field (StructField &field)
+{
+ field.get_field_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructStruct &struct_item)
+{
+ visit_outer_attrs (struct_item);
+ for (auto &generic : struct_item.get_generic_params ())
+ generic->accept_vis (*this);
+ if (struct_item.has_where_clause ())
+ visit_where_clause (struct_item.get_where_clause ());
+ for (auto &field : struct_item.get_fields ())
+ visit_struct_field (field);
+}
+
+void
+DefaultHIRVisitor::walk (TupleStruct &tuple_struct)
+{
+ visit_outer_attrs (tuple_struct);
+ for (auto &generic : tuple_struct.get_generic_params ())
+ generic->accept_vis (*this);
+ if (tuple_struct.has_where_clause ())
+ visit_where_clause (tuple_struct.get_where_clause ());
+ for (auto &field : tuple_struct.get_fields ())
+ field.get_field_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (EnumItem &item)
+{
+ visit_outer_attrs (item);
+}
+
+void
+DefaultHIRVisitor::walk (EnumItemTuple &item_tuple)
+{
+ item_tuple.EnumItem::accept_vis (*this);
+ for (auto &field : item_tuple.get_tuple_fields ())
+ field.get_field_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (EnumItemStruct &item_struct)
+{
+ item_struct.EnumItem::accept_vis (*this);
+ for (auto &field : item_struct.get_struct_fields ())
+ field.get_field_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (EnumItemDiscriminant &item)
+{
+ item.EnumItem::accept_vis (*this);
+ item.get_discriminant_expression ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (Enum &enum_item)
+{
+ visit_outer_attrs (enum_item);
+ for (auto &generic : enum_item.get_generic_params ())
+ generic->accept_vis (*this);
+ if (enum_item.has_where_clause ())
+ visit_where_clause (enum_item.get_where_clause ());
+ for (auto &item : enum_item.get_variants ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (Union &union_item)
+{
+ visit_outer_attrs (union_item);
+ for (auto &generic : union_item.get_generic_params ())
+ generic->accept_vis (*this);
+ if (union_item.has_where_clause ())
+ visit_where_clause (union_item.get_where_clause ());
+ for (auto &variant : union_item.get_variants ())
+ visit_struct_field (variant);
+}
+
+void
+DefaultHIRVisitor::walk (ConstantItem &const_item)
+{
+ visit_outer_attrs (const_item);
+ const_item.get_type ().accept_vis (*this);
+ const_item.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StaticItem &static_item)
+{
+ visit_outer_attrs (static_item);
+ static_item.get_type ().accept_vis (*this);
+ static_item.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_self_param (SelfParam &self_param)
+{
+ if (self_param.has_lifetime ())
+ {
+ Lifetime lifetime = self_param.get_lifetime ();
+ lifetime.accept_vis (*this);
+ }
+ if (self_param.has_type ())
+ self_param.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TraitItemFunc &item)
+{
+ visit_outer_attrs (item);
+ TraitFunctionDecl &decl = item.get_decl ();
+ for (auto &generic : decl.get_generic_params ())
+ generic->accept_vis (*this);
+ if (decl.get_self ().has_value ())
+ visit_self_param (decl.get_self ().value ());
+ for (auto &param : decl.get_function_params ())
+ visit_function_param (param);
+ if (decl.has_return_type ())
+ decl.get_return_type ().accept_vis (*this);
+ if (decl.has_where_clause ())
+ visit_where_clause (decl.get_where_clause ());
+ if (item.has_definition ())
+ item.get_block_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TraitItemConst &item)
+{
+ visit_outer_attrs (item);
+ item.get_type ().accept_vis (*this);
+ if (item.has_expr ())
+ item.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TraitItemType &item)
+{
+ visit_outer_attrs (item);
+ for (auto &bound : item.get_type_param_bounds ())
+ bound->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_where_clause (const WhereClause &where_clause)
+{
+ for (auto &item : where_clause.get_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_where_clause (WhereClause &where_clause)
+{
+ for (auto &item : where_clause.get_items ())
+ {
+ item->accept_vis (*this);
+ }
+}
+
+void
+DefaultHIRVisitor::walk (WhereClauseItem &node)
+{}
+
+void
+DefaultHIRVisitor::walk (Trait &trait)
+{
+ visit_outer_attrs (trait);
+ for (auto &generic : trait.get_generic_params ())
+ generic->accept_vis (*this);
+ if (trait.has_where_clause ())
+ visit_where_clause (trait.get_where_clause ());
+ for (auto &bound : trait.get_type_param_bounds ())
+ bound->accept_vis (*this);
+ for (auto &item : trait.get_trait_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ImplBlock &impl)
+{
+ visit_outer_attrs (impl);
+ for (auto &generic : impl.get_generic_params ())
+ generic->accept_vis (*this);
+ if (impl.has_trait_ref ())
+ impl.get_trait_ref ().accept_vis (*this);
+ impl.get_type ().accept_vis (*this);
+ if (impl.has_where_clause ())
+ visit_where_clause (impl.get_where_clause ());
+ visit_inner_attrs (impl);
+ for (auto &item : impl.get_impl_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ExternalStaticItem &item)
+{
+ visit_outer_attrs (item);
+ item.get_item_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::visit_named_function_param (NamedFunctionParam &param)
+{
+ param.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ExternalFunctionItem &item)
+{
+ visit_outer_attrs (item);
+ for (auto &generic : item.get_generic_params ())
+ generic->accept_vis (*this);
+ for (auto &param : item.get_function_params ())
+ visit_named_function_param (param);
+ if (item.has_return_type ())
+ item.get_return_type ().accept_vis (*this);
+ if (item.has_where_clause ())
+ visit_where_clause (item.get_where_clause ());
+}
+
+void
+DefaultHIRVisitor::walk (ExternalTypeItem &item)
+{
+ visit_outer_attrs (item);
+}
+
+void
+DefaultHIRVisitor::walk (ExternBlock &block)
+{
+ visit_outer_attrs (block);
+ visit_inner_attrs (block);
+ for (auto &item : block.get_extern_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (LiteralPattern &)
+{}
+
+void
+DefaultHIRVisitor::walk (IdentifierPattern &pattern)
+{
+ if (pattern.has_subpattern ())
+ pattern.get_subpattern ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (WildcardPattern &)
+{}
+
+void
+DefaultHIRVisitor::walk (RangePatternBoundLiteral &)
+{}
+
+void
+DefaultHIRVisitor::walk (RangePatternBoundPath &bound)
+{
+ bound.get_path ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangePatternBoundQualPath &bound)
+{
+ bound.get_qualified_path ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (RangePattern &pattern)
+{
+ pattern.get_lower_bound ().accept_vis (*this);
+ pattern.get_upper_bound ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ReferencePattern &pattern)
+{
+ pattern.get_referenced_pattern ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructPatternFieldTuplePat &field)
+{
+ visit_outer_attrs (field);
+ field.get_tuple_pattern ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructPatternFieldIdentPat &field)
+{
+ visit_outer_attrs (field);
+ field.get_pattern ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (StructPatternFieldIdent &field)
+{
+ visit_outer_attrs (field);
+}
+
+void
+DefaultHIRVisitor::walk (StructPattern &pattern)
+{
+ pattern.get_path ().accept_vis (*this);
+ StructPatternElements &elements = pattern.get_struct_pattern_elems ();
+ for (auto &field : elements.get_struct_pattern_fields ())
+ field->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleStructItemsNoRange &tuple_items)
+{
+ for (auto &item : tuple_items.get_patterns ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleStructItemsRange &tuple_items)
+{
+ for (auto &lower : tuple_items.get_lower_patterns ())
+ lower->accept_vis (*this);
+ for (auto &upper : tuple_items.get_upper_patterns ())
+ upper->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleStructPattern &pattern)
+{
+ pattern.get_path ().accept_vis (*this);
+ pattern.get_items ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TuplePatternItemsMultiple &tuple_items)
+{
+ for (auto &pattern : tuple_items.get_patterns ())
+ pattern->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TuplePatternItemsRanged &tuple_items)
+{
+ for (auto &lower : tuple_items.get_lower_patterns ())
+ lower->accept_vis (*this);
+ for (auto &upper : tuple_items.get_upper_patterns ())
+ upper->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TuplePattern &pattern)
+{
+ pattern.get_items ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (SlicePattern &pattern)
+{
+ for (auto &item : pattern.get_items ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (AltPattern &pattern)
+{
+ for (auto &item : pattern.get_alts ())
+ item->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (EmptyStmt &stmt)
+{}
+
+void
+DefaultHIRVisitor::walk (LetStmt &stmt)
+{
+ visit_outer_attrs (stmt);
+ stmt.get_pattern ().accept_vis (*this);
+ if (stmt.has_type ())
+ stmt.get_type ().accept_vis (*this);
+ if (stmt.has_init_expr ())
+ stmt.get_init_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ExprStmt &stmt)
+{
+ stmt.get_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TraitBound &bound)
+{
+ for (auto &lifetime : bound.get_for_lifetimes ())
+ lifetime.accept_vis (*this);
+ bound.get_path ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ImplTraitType &type)
+{
+ for (auto &bound : type.get_type_param_bounds ())
+ bound->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TraitObjectType &type)
+{
+ for (auto &bound : type.get_type_param_bounds ())
+ bound->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ParenthesisedType &type)
+{
+ type.get_type_in_parens ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (TupleType &type)
+{
+ for (auto &elem : type.get_elems ())
+ elem->accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (NeverType &type)
+{}
+
+void
+DefaultHIRVisitor::walk (RawPointerType &type)
+{
+ type.get_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ReferenceType &type)
+{
+ if (type.has_lifetime ())
+ type.get_lifetime ().accept_vis (*this);
+ type.get_base_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (ArrayType &type)
+{
+ type.get_element_type ().accept_vis (*this);
+ type.get_size_expr ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (SliceType &type)
+{
+ type.get_element_type ().accept_vis (*this);
+}
+
+void
+DefaultHIRVisitor::walk (InferredType &type)
+{}
+
+void
+DefaultHIRVisitor::walk (BareFunctionType &type)
+{
+ for (auto &lifetime : type.get_for_lifetimes ())
+ lifetime.accept_vis (*this);
+ for (auto &param : type.get_function_params ())
+ param.get_type ().accept_vis (*this);
+ if (type.has_return_type ())
+ type.get_return_type ().accept_vis (*this);
+}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h
index 33e6b7b..7996260 100644
--- a/gcc/rust/hir/tree/rust-hir-visitor.h
+++ b/gcc/rust/hir/tree/rust-hir-visitor.h
@@ -20,6 +20,7 @@
#define RUST_HIR_VISITOR_H
#include "rust-hir-full-decls.h"
+#include "rust-ast.h"
namespace Rust {
namespace HIR {
@@ -64,6 +65,8 @@ public:
virtual void visit (MethodCallExpr &expr) = 0;
virtual void visit (FieldAccessExpr &expr) = 0;
virtual void visit (BlockExpr &expr) = 0;
+ virtual void visit (AnonConst &expr) = 0;
+ virtual void visit (ConstBlock &expr) = 0;
virtual void visit (ClosureExpr &expr) = 0;
virtual void visit (ContinueExpr &expr) = 0;
virtual void visit (BreakExpr &expr) = 0;
@@ -84,6 +87,8 @@ public:
virtual void visit (AwaitExpr &expr) = 0;
virtual void visit (AsyncBlockExpr &expr) = 0;
virtual void visit (InlineAsm &expr) = 0;
+ virtual void visit (LlvmInlineAsm &expr) = 0;
+ virtual void visit (OffsetOf &expr) = 0;
virtual void visit (TypeParam &param) = 0;
virtual void visit (ConstGenericParam &param) = 0;
virtual void visit (LifetimeWhereClauseItem &item) = 0;
@@ -142,7 +147,6 @@ public:
virtual void visit (ImplTraitType &type) = 0;
virtual void visit (TraitObjectType &type) = 0;
virtual void visit (ParenthesisedType &type) = 0;
- virtual void visit (ImplTraitTypeOneBound &type) = 0;
virtual void visit (TupleType &type) = 0;
virtual void visit (NeverType &type) = 0;
virtual void visit (RawPointerType &type) = 0;
@@ -153,6 +157,312 @@ public:
virtual void visit (BareFunctionType &type) = 0;
};
+class DefaultHIRVisitor : public HIRFullVisitor
+{
+public:
+ virtual void visit_where_clause (WhereClause &);
+ virtual void visit_where_clause (const WhereClause &);
+ virtual void visit_named_function_param (NamedFunctionParam &param);
+ virtual void visit_function_param (FunctionParam &param);
+ virtual void visit_self_param (SelfParam &param);
+ virtual void visit_match_arm (MatchArm &arm);
+ virtual void visit_match_case (MatchCase &);
+ virtual void visit_struct_field (StructField &field);
+ virtual void visit_generic_args (GenericArgs &args);
+ virtual void visit_qualified_path_type (QualifiedPathType &);
+ virtual void visit_path_expr_segment (PathExprSegment &segment);
+ virtual void visit_closure_param (ClosureParam &param);
+ virtual void visit_loop_label (LoopLabel &);
+
+ virtual void visit_attribute (AST::Attribute &attr)
+ {
+ visit_attribute (static_cast<const AST::Attribute &> (attr));
+ }
+ virtual void visit_attribute (const AST::Attribute &attr) {}
+ template <typename T> void visit_outer_attrs (T &node)
+ {
+ for (auto &attr : node.get_outer_attrs ())
+ visit_attribute (attr);
+ }
+ template <typename T> void visit_inner_attrs (T &node)
+ {
+ for (auto &attr : node.get_inner_attrs ())
+ visit_attribute (attr);
+ }
+
+ virtual void visit (WhereClauseItem &node) { walk (node); }
+
+ virtual void visit (Lifetime &node) override { walk (node); }
+ virtual void visit (LifetimeParam &node) override { walk (node); }
+ virtual void visit (PathInExpression &node) override { walk (node); }
+ virtual void visit (TypePathSegment &node) override { walk (node); }
+ virtual void visit (TypePathSegmentGeneric &node) override { walk (node); }
+ virtual void visit (TypePathSegmentFunction &node) override { walk (node); }
+ virtual void visit (TypePath &node) override { walk (node); }
+ virtual void visit (QualifiedPathInExpression &node) override { walk (node); }
+ virtual void visit (QualifiedPathInType &node) override { walk (node); }
+ virtual void visit (LiteralExpr &node) override { walk (node); }
+ virtual void visit (BorrowExpr &node) override { walk (node); }
+ virtual void visit (DereferenceExpr &node) override { walk (node); }
+ virtual void visit (ErrorPropagationExpr &node) override { walk (node); }
+ virtual void visit (NegationExpr &node) override { walk (node); }
+ virtual void visit (ArithmeticOrLogicalExpr &node) override { walk (node); }
+ virtual void visit (ComparisonExpr &node) override { walk (node); }
+ virtual void visit (LazyBooleanExpr &node) override { walk (node); }
+ virtual void visit (TypeCastExpr &node) override { walk (node); }
+ virtual void visit (AssignmentExpr &node) override { walk (node); }
+ virtual void visit (CompoundAssignmentExpr &node) override { walk (node); }
+ virtual void visit (GroupedExpr &node) override { walk (node); }
+ virtual void visit (ArrayElemsValues &node) override { walk (node); }
+ virtual void visit (ArrayElemsCopied &node) override { walk (node); }
+ virtual void visit (ArrayExpr &node) override { walk (node); }
+ virtual void visit (ArrayIndexExpr &node) override { walk (node); }
+ virtual void visit (TupleExpr &node) override { walk (node); }
+ virtual void visit (TupleIndexExpr &node) override { walk (node); }
+ virtual void visit (StructExprStruct &node) override { walk (node); }
+ virtual void visit (StructExprFieldIdentifier &node) override { walk (node); }
+ virtual void visit (StructExprFieldIdentifierValue &node) override
+ {
+ walk (node);
+ }
+ virtual void visit (StructExprFieldIndexValue &node) override { walk (node); }
+ virtual void visit (StructExprStructFields &node) override { walk (node); }
+ virtual void visit (StructExprStructBase &node) override { walk (node); }
+ virtual void visit (CallExpr &node) override { walk (node); }
+ virtual void visit (MethodCallExpr &node) override { walk (node); }
+ virtual void visit (FieldAccessExpr &node) override { walk (node); }
+ virtual void visit (ClosureExpr &node) override { walk (node); }
+ virtual void visit (BlockExpr &node) override { walk (node); }
+ virtual void visit (AnonConst &node) override { walk (node); }
+ virtual void visit (ConstBlock &node) override { walk (node); }
+ virtual void visit (ContinueExpr &node) override { walk (node); }
+ virtual void visit (BreakExpr &node) override { walk (node); }
+ virtual void visit (RangeFromToExpr &node) override { walk (node); }
+ virtual void visit (RangeFromExpr &node) override { walk (node); }
+ virtual void visit (RangeToExpr &node) override { walk (node); }
+ virtual void visit (RangeFullExpr &node) override { walk (node); }
+ virtual void visit (RangeFromToInclExpr &node) override { walk (node); }
+ virtual void visit (RangeToInclExpr &node) override { walk (node); }
+ virtual void visit (ReturnExpr &node) override { walk (node); }
+ virtual void visit (UnsafeBlockExpr &node) override { walk (node); }
+ virtual void visit (LoopExpr &node) override { walk (node); }
+ virtual void visit (WhileLoopExpr &node) override { walk (node); }
+ virtual void visit (WhileLetLoopExpr &node) override { walk (node); }
+ virtual void visit (IfExpr &node) override { walk (node); }
+ virtual void visit (IfExprConseqElse &node) override { walk (node); }
+ virtual void visit (MatchExpr &node) override { walk (node); }
+ virtual void visit (AwaitExpr &node) override { walk (node); }
+ virtual void visit (AsyncBlockExpr &node) override { walk (node); }
+ virtual void visit (InlineAsm &node) override { walk (node); }
+ virtual void visit (LlvmInlineAsm &node) override { walk (node); }
+ virtual void visit (OffsetOf &node) override { walk (node); }
+ virtual void visit (TypeParam &node) override { walk (node); }
+ virtual void visit (ConstGenericParam &node) override { walk (node); }
+ virtual void visit (LifetimeWhereClauseItem &node) override { walk (node); }
+ virtual void visit (TypeBoundWhereClauseItem &node) override { walk (node); }
+ virtual void visit (Module &node) override { walk (node); }
+ virtual void visit (ExternCrate &node) override { walk (node); }
+ virtual void visit (UseTreeGlob &node) override { walk (node); }
+ virtual void visit (UseTreeList &node) override { walk (node); }
+ virtual void visit (UseTreeRebind &node) override { walk (node); }
+ virtual void visit (UseDeclaration &node) override { walk (node); }
+ virtual void visit (Function &node) override { walk (node); }
+ virtual void visit (TypeAlias &node) override { walk (node); }
+ virtual void visit (StructStruct &node) override { walk (node); }
+ virtual void visit (TupleStruct &node) override { walk (node); }
+ virtual void visit (EnumItem &node) override { walk (node); }
+ virtual void visit (EnumItemTuple &node) override { walk (node); }
+ virtual void visit (EnumItemStruct &node) override { walk (node); }
+ virtual void visit (EnumItemDiscriminant &node) override { walk (node); }
+ virtual void visit (Enum &node) override { walk (node); }
+ virtual void visit (Union &node) override { walk (node); }
+ virtual void visit (ConstantItem &node) override { walk (node); }
+ virtual void visit (StaticItem &node) override { walk (node); }
+ virtual void visit (TraitItemFunc &node) override { walk (node); }
+ virtual void visit (TraitItemConst &node) override { walk (node); }
+ virtual void visit (TraitItemType &node) override { walk (node); }
+ virtual void visit (Trait &node) override { walk (node); }
+ virtual void visit (ImplBlock &node) override { walk (node); }
+ virtual void visit (ExternalStaticItem &node) override { walk (node); }
+ virtual void visit (ExternalFunctionItem &node) override { walk (node); }
+ virtual void visit (ExternalTypeItem &node) override { walk (node); }
+ virtual void visit (ExternBlock &node) override { walk (node); }
+ virtual void visit (LiteralPattern &node) override { walk (node); }
+ virtual void visit (IdentifierPattern &node) override { walk (node); }
+ virtual void visit (WildcardPattern &node) override { walk (node); }
+ virtual void visit (RangePatternBoundLiteral &node) override { walk (node); }
+ virtual void visit (RangePatternBoundPath &node) override { walk (node); }
+ virtual void visit (RangePatternBoundQualPath &node) override { walk (node); }
+ virtual void visit (RangePattern &node) override { walk (node); }
+ virtual void visit (ReferencePattern &node) override { walk (node); }
+ virtual void visit (StructPatternFieldTuplePat &node) override
+ {
+ walk (node);
+ }
+ virtual void visit (StructPatternFieldIdentPat &node) override
+ {
+ walk (node);
+ }
+ virtual void visit (StructPatternFieldIdent &node) override { walk (node); }
+ virtual void visit (StructPattern &node) override { walk (node); }
+ virtual void visit (TupleStructItemsNoRange &node) override { walk (node); }
+ virtual void visit (TupleStructItemsRange &node) override { walk (node); }
+ virtual void visit (TupleStructPattern &node) override { walk (node); }
+ virtual void visit (TuplePatternItemsMultiple &node) override { walk (node); }
+ virtual void visit (TuplePatternItemsRanged &node) override { walk (node); }
+ virtual void visit (TuplePattern &node) override { walk (node); }
+ virtual void visit (SlicePattern &node) override { walk (node); }
+ virtual void visit (AltPattern &node) override { walk (node); }
+ virtual void visit (EmptyStmt &node) override { walk (node); }
+ virtual void visit (LetStmt &node) override { walk (node); }
+ virtual void visit (ExprStmt &node) override { walk (node); }
+ virtual void visit (TraitBound &node) override { walk (node); }
+ virtual void visit (ImplTraitType &node) override { walk (node); }
+ virtual void visit (TraitObjectType &node) override { walk (node); }
+ virtual void visit (ParenthesisedType &node) override { walk (node); }
+ virtual void visit (TupleType &node) override { walk (node); }
+ virtual void visit (NeverType &node) override { walk (node); }
+ virtual void visit (RawPointerType &node) override { walk (node); }
+ virtual void visit (ReferenceType &node) override { walk (node); }
+ virtual void visit (ArrayType &node) override { walk (node); }
+ virtual void visit (SliceType &node) override { walk (node); }
+ virtual void visit (InferredType &node) override { walk (node); }
+ virtual void visit (BareFunctionType &node) override { walk (node); }
+
+protected:
+ virtual void walk (WhereClauseItem &) final;
+
+ virtual void walk (Lifetime &) final;
+ virtual void walk (LifetimeParam &) final;
+ virtual void walk (PathInExpression &) final;
+ virtual void walk (TypePathSegment &) final;
+ virtual void walk (TypePathSegmentGeneric &) final;
+ virtual void walk (TypePathSegmentFunction &) final;
+ virtual void walk (TypePath &) final;
+ virtual void walk (QualifiedPathInExpression &) final;
+ virtual void walk (QualifiedPathInType &) final;
+
+ virtual void walk (LiteralExpr &) final;
+ virtual void walk (BorrowExpr &) final;
+ virtual void walk (DereferenceExpr &) final;
+ virtual void walk (ErrorPropagationExpr &) final;
+ virtual void walk (NegationExpr &) final;
+ virtual void walk (ArithmeticOrLogicalExpr &) final;
+ virtual void walk (ComparisonExpr &) final;
+ virtual void walk (LazyBooleanExpr &) final;
+ virtual void walk (TypeCastExpr &) final;
+ virtual void walk (AssignmentExpr &) final;
+ virtual void walk (CompoundAssignmentExpr &) final;
+ virtual void walk (GroupedExpr &) final;
+
+ virtual void walk (ArrayElemsValues &) final;
+ virtual void walk (ArrayElemsCopied &) final;
+ virtual void walk (ArrayExpr &) final;
+ virtual void walk (ArrayIndexExpr &) final;
+ virtual void walk (TupleExpr &) final;
+ virtual void walk (TupleIndexExpr &) final;
+ virtual void walk (StructExprStruct &) final;
+ virtual void walk (StructExprFieldIdentifier &) final;
+ virtual void walk (StructExprFieldIdentifierValue &) final;
+ virtual void walk (StructExprFieldIndexValue &) final;
+ virtual void walk (StructExprStructFields &) final;
+ virtual void walk (StructExprStructBase &) final;
+ virtual void walk (CallExpr &) final;
+ virtual void walk (MethodCallExpr &) final;
+ virtual void walk (FieldAccessExpr &) final;
+ virtual void walk (ClosureExpr &) final;
+ virtual void walk (BlockExpr &) final;
+ virtual void walk (AnonConst &) final;
+ virtual void walk (ConstBlock &) final;
+ virtual void walk (ContinueExpr &) final;
+ virtual void walk (BreakExpr &) final;
+ virtual void walk (RangeFromToExpr &) final;
+ virtual void walk (RangeFromExpr &) final;
+ virtual void walk (RangeToExpr &) final;
+ virtual void walk (RangeFullExpr &) final;
+ virtual void walk (RangeFromToInclExpr &) final;
+ virtual void walk (RangeToInclExpr &) final;
+ virtual void walk (ReturnExpr &) final;
+ virtual void walk (UnsafeBlockExpr &) final;
+ virtual void walk (LoopExpr &) final;
+ virtual void walk (WhileLoopExpr &) final;
+ virtual void walk (WhileLetLoopExpr &) final;
+ virtual void walk (IfExpr &) final;
+ virtual void walk (IfExprConseqElse &) final;
+ virtual void walk (MatchExpr &) final;
+ virtual void walk (AwaitExpr &) final;
+ virtual void walk (AsyncBlockExpr &) final;
+ virtual void walk (InlineAsm &) final;
+ virtual void walk (LlvmInlineAsm &) final;
+ virtual void walk (OffsetOf &) final;
+ virtual void walk (TypeParam &) final;
+ virtual void walk (ConstGenericParam &) final;
+ virtual void walk (LifetimeWhereClauseItem &) final;
+ virtual void walk (TypeBoundWhereClauseItem &) final;
+ virtual void walk (Module &) final;
+ virtual void walk (ExternCrate &) final;
+ virtual void walk (UseTreeGlob &) final;
+ virtual void walk (UseTreeList &) final;
+ virtual void walk (UseTreeRebind &) final;
+ virtual void walk (UseDeclaration &) final;
+ virtual void walk (Function &) final;
+ virtual void walk (TypeAlias &) final;
+ virtual void walk (StructStruct &) final;
+ virtual void walk (TupleStruct &) final;
+ virtual void walk (EnumItem &) final;
+ virtual void walk (EnumItemTuple &) final;
+ virtual void walk (EnumItemStruct &) final;
+ virtual void walk (EnumItemDiscriminant &) final;
+ virtual void walk (Enum &) final;
+ virtual void walk (Union &) final;
+ virtual void walk (ConstantItem &) final;
+ virtual void walk (StaticItem &) final;
+ virtual void walk (TraitItemFunc &) final;
+ virtual void walk (TraitItemConst &) final;
+ virtual void walk (TraitItemType &) final;
+ virtual void walk (Trait &) final;
+ virtual void walk (ImplBlock &) final;
+ virtual void walk (ExternalStaticItem &) final;
+ virtual void walk (ExternalFunctionItem &) final;
+ virtual void walk (ExternalTypeItem &) final;
+ virtual void walk (ExternBlock &) final;
+ virtual void walk (LiteralPattern &) final;
+ virtual void walk (IdentifierPattern &) final;
+ virtual void walk (WildcardPattern &) final;
+ virtual void walk (RangePatternBoundLiteral &) final;
+ virtual void walk (RangePatternBoundPath &) final;
+ virtual void walk (RangePatternBoundQualPath &) final;
+ virtual void walk (RangePattern &) final;
+ virtual void walk (ReferencePattern &) final;
+ virtual void walk (StructPatternFieldTuplePat &) final;
+ virtual void walk (StructPatternFieldIdentPat &) final;
+ virtual void walk (StructPatternFieldIdent &) final;
+ virtual void walk (StructPattern &) final;
+ virtual void walk (TupleStructItemsNoRange &) final;
+ virtual void walk (TupleStructItemsRange &) final;
+ virtual void walk (TupleStructPattern &) final;
+ virtual void walk (TuplePatternItemsMultiple &) final;
+ virtual void walk (TuplePatternItemsRanged &) final;
+ virtual void walk (TuplePattern &) final;
+ virtual void walk (SlicePattern &) final;
+ virtual void walk (AltPattern &) final;
+ virtual void walk (EmptyStmt &) final;
+ virtual void walk (LetStmt &) final;
+ virtual void walk (ExprStmt &) final;
+ virtual void walk (TraitBound &) final;
+ virtual void walk (ImplTraitType &) final;
+ virtual void walk (TraitObjectType &) final;
+ virtual void walk (ParenthesisedType &) final;
+ virtual void walk (TupleType &) final;
+ virtual void walk (NeverType &) final;
+ virtual void walk (RawPointerType &) final;
+ virtual void walk (ReferenceType &) final;
+ virtual void walk (ArrayType &) final;
+ virtual void walk (SliceType &) final;
+ virtual void walk (InferredType &) final;
+ virtual void walk (BareFunctionType &) final;
+};
+
class HIRFullVisitorBase : public HIRFullVisitor
{
public:
@@ -201,6 +511,8 @@ public:
virtual void visit (FieldAccessExpr &) override {}
virtual void visit (ClosureExpr &) override {}
virtual void visit (BlockExpr &) override {}
+ virtual void visit (AnonConst &) override {}
+ virtual void visit (ConstBlock &) override {}
virtual void visit (ContinueExpr &) override {}
virtual void visit (BreakExpr &) override {}
virtual void visit (RangeFromToExpr &) override {}
@@ -221,6 +533,8 @@ public:
virtual void visit (AwaitExpr &) override {}
virtual void visit (AsyncBlockExpr &) override {}
virtual void visit (InlineAsm &) override {}
+ virtual void visit (LlvmInlineAsm &) override {}
+ virtual void visit (OffsetOf &) override {}
virtual void visit (TypeParam &) override {}
virtual void visit (ConstGenericParam &) override {}
@@ -290,7 +604,6 @@ public:
virtual void visit (ImplTraitType &) override {}
virtual void visit (TraitObjectType &) override {}
virtual void visit (ParenthesisedType &) override {}
- virtual void visit (ImplTraitTypeOneBound &) override {}
virtual void visit (TupleType &) override {}
virtual void visit (NeverType &) override {}
virtual void visit (RawPointerType &) override {}
@@ -354,7 +667,6 @@ public:
virtual void visit (ImplTraitType &type) = 0;
virtual void visit (TraitObjectType &type) = 0;
virtual void visit (ParenthesisedType &type) = 0;
- virtual void visit (ImplTraitTypeOneBound &type) = 0;
virtual void visit (TupleType &type) = 0;
virtual void visit (NeverType &type) = 0;
virtual void visit (RawPointerType &type) = 0;
@@ -428,6 +740,8 @@ public:
virtual void visit (MethodCallExpr &expr) = 0;
virtual void visit (FieldAccessExpr &expr) = 0;
virtual void visit (BlockExpr &expr) = 0;
+ virtual void visit (AnonConst &expr) = 0;
+ virtual void visit (ConstBlock &expr) = 0;
virtual void visit (ContinueExpr &expr) = 0;
virtual void visit (BreakExpr &expr) = 0;
virtual void visit (RangeFromToExpr &expr) = 0;
@@ -444,6 +758,8 @@ public:
virtual void visit (IfExpr &expr) = 0;
virtual void visit (IfExprConseqElse &expr) = 0;
virtual void visit (InlineAsm &expr) = 0;
+ virtual void visit (OffsetOf &expr) = 0;
+ virtual void visit (LlvmInlineAsm &expr) = 0;
virtual void visit (MatchExpr &expr) = 0;
virtual void visit (AwaitExpr &expr) = 0;
virtual void visit (AsyncBlockExpr &expr) = 0;
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index da1c8b9..a802e8c 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -19,6 +19,7 @@
#include "rust-ast-full.h"
#include "rust-hir-expr.h"
#include "rust-hir-full.h"
+#include "rust-hir-path.h"
#include "rust-hir-visitor.h"
#include "rust-diagnostics.h"
@@ -576,7 +577,8 @@ UseTreeGlob::as_string () const
return "*";
case GLOBAL:
return "::*";
- case PATH_PREFIXED: {
+ case PATH_PREFIXED:
+ {
std::string path_str = path.as_string ();
return path_str + "::*";
}
@@ -599,7 +601,8 @@ UseTreeList::as_string () const
case GLOBAL:
path_str = "::{";
break;
- case PATH_PREFIXED: {
+ case PATH_PREFIXED:
+ {
path_str = path.as_string () + "::{";
break;
}
@@ -1047,6 +1050,36 @@ BlockExpr::as_string () const
}
std::string
+AnonConst::as_string () const
+{
+ std::string istr = indent_spaces (enter);
+ std::string str = istr + "AnonConst:\n" + istr;
+
+ if (expr.has_value ())
+ str += get_inner_expr ().as_string ();
+ else
+ str += "_";
+
+ str += "\n" + indent_spaces (out);
+
+ return str;
+}
+
+std::string
+ConstBlock::as_string () const
+{
+ std::string istr = indent_spaces (enter);
+
+ std::string str = istr + "ConstBlock:\n" + istr;
+
+ str += get_const_expr ().as_string ();
+
+ str += "\n" + indent_spaces (out);
+
+ return str;
+}
+
+std::string
TypeAlias::as_string () const
{
std::string str = VisItem::as_string ();
@@ -1210,6 +1243,9 @@ ClosureExpr::as_string () const
std::string
PathPattern::as_string () const
{
+ if (is_lang_item ())
+ return LangItem::PrettyString (*lang_item);
+
std::string str;
for (const auto &segment : segments)
@@ -1310,7 +1346,7 @@ ContinueExpr::as_string () const
if (has_label ())
{
- str += label.as_string ();
+ str += get_label ().as_string ();
}
return str;
@@ -1700,7 +1736,7 @@ WhileLoopExpr::as_string () const
}
else
{
- str += loop_label.as_string ();
+ str += get_loop_label ().as_string ();
}
str += "\n Conditional expr: " + condition->as_string ();
@@ -1722,7 +1758,7 @@ WhileLetLoopExpr::as_string () const
}
else
{
- str += loop_label.as_string ();
+ str += get_loop_label ().as_string ();
}
str += "\n Match arm patterns: ";
@@ -1757,7 +1793,7 @@ LoopExpr::as_string () const
}
else
{
- str += loop_label.as_string ();
+ str += get_loop_label ().as_string ();
}
str += "\n Loop block: " + loop_block->as_string ();
@@ -1812,7 +1848,7 @@ BreakExpr::as_string () const
if (has_label ())
{
- str += label.as_string () + " ";
+ str += get_label ().as_string () + " ";
}
if (has_break_expr ())
@@ -2097,11 +2133,6 @@ QualifiedPathInType::as_string () const
std::string
Lifetime::as_string () const
{
- if (is_error ())
- {
- return "error lifetime";
- }
-
switch (lifetime_type)
{
case AST::Lifetime::LifetimeType::NAMED:
@@ -2187,6 +2218,8 @@ TypeParam::as_string () const
AST::SimplePath
PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
{
+ rust_assert (kind == Kind::Segmented);
+
if (!has_segments ())
{
return AST::SimplePath::create_empty ();
@@ -2578,9 +2611,9 @@ IdentifierPattern::as_string () const
str += variable_ident.as_string ();
- if (has_pattern_to_bind ())
+ if (has_subpattern ())
{
- str += " @ " + to_bind->as_string ();
+ str += " @ " + subpattern->as_string ();
}
return str;
@@ -2754,7 +2787,7 @@ ReferenceType::as_string () const
if (has_lifetime ())
{
- str += lifetime.as_string () + " ";
+ str += get_lifetime ().as_string () + " ";
}
if (is_mut ())
@@ -2860,14 +2893,6 @@ BareFunctionType::as_string () const
}
std::string
-ImplTraitTypeOneBound::as_string () const
-{
- std::string str ("ImplTraitTypeOneBound: \n TraitBound: ");
-
- return str + trait_bound.as_string ();
-}
-
-std::string
TypePathSegmentGeneric::as_string () const
{
return TypePathSegment::as_string () + "<" + generic_args.as_string () + ">";
@@ -3413,7 +3438,7 @@ TraitFunctionDecl::as_string () const
str += "\n Function params: ";
if (is_method ())
{
- str += self.as_string () + (has_params () ? ", " : "");
+ str += get_self_unchecked ().as_string () + (has_params () ? ", " : "");
}
if (has_params ())
@@ -3527,70 +3552,63 @@ TraitItemType::as_string () const
std::string
SelfParam::as_string () const
{
- if (is_error ())
- {
- return "error";
- }
- else
+ if (has_type ())
{
- if (has_type ())
+ // type (i.e. not ref, no lifetime)
+ std::string str;
+
+ if (is_mut ())
{
- // type (i.e. not ref, no lifetime)
- std::string str;
+ str += "mut ";
+ }
- if (is_mut ())
- {
- str += "mut ";
- }
+ str += "self : ";
- str += "self : ";
+ str += type->as_string ();
- str += type->as_string ();
+ return str;
+ }
+ else if (has_lifetime ())
+ {
+ // ref and lifetime
+ std::string str = "&" + get_lifetime ().as_string () + " ";
- return str;
- }
- else if (has_lifetime ())
+ if (is_mut ())
{
- // ref and lifetime
- std::string str = "&" + lifetime.as_string () + " ";
+ str += "mut ";
+ }
- if (is_mut ())
- {
- str += "mut ";
- }
+ str += "self";
- str += "self";
+ return str;
+ }
+ else if (is_ref ())
+ {
+ // ref with no lifetime
+ std::string str = "&";
- return str;
- }
- else if (is_ref ())
+ if (is_mut ())
{
- // ref with no lifetime
- std::string str = "&";
+ str += " mut ";
+ }
- if (is_mut ())
- {
- str += " mut ";
- }
+ str += "self";
- str += "self";
+ return str;
+ }
+ else
+ {
+ // no ref, no type
+ std::string str;
- return str;
- }
- else
+ if (is_mut ())
{
- // no ref, no type
- std::string str;
-
- if (is_mut ())
- {
- str += "mut ";
- }
+ str += "mut ";
+ }
- str += "self";
+ str += "self";
- return str;
- }
+ return str;
}
}
@@ -3836,6 +3854,17 @@ InlineAsm::accept_vis (HIRFullVisitor &vis)
}
void
+LlvmInlineAsm::accept_vis (HIRFullVisitor &vis)
+{
+ vis.visit (*this);
+}
+void
+LlvmInlineAsm::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
BorrowExpr::accept_vis (HIRExpressionVisitor &vis)
{
vis.visit (*this);
@@ -4058,6 +4087,18 @@ BlockExpr::accept_vis (HIRFullVisitor &vis)
}
void
+AnonConst::accept_vis (HIRFullVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+ConstBlock::accept_vis (HIRFullVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
ContinueExpr::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4520,12 +4561,6 @@ ParenthesisedType::accept_vis (HIRFullVisitor &vis)
}
void
-ImplTraitTypeOneBound::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
TupleType::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4718,12 +4753,6 @@ ArrayType::accept_vis (HIRTypeVisitor &vis)
}
void
-ImplTraitTypeOneBound::accept_vis (HIRTypeVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
BareFunctionType::accept_vis (HIRTypeVisitor &vis)
{
vis.visit (*this);
@@ -5042,6 +5071,18 @@ BlockExpr::accept_vis (HIRExpressionVisitor &vis)
}
void
+AnonConst::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+ConstBlock::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
Function::accept_vis (HIRStmtVisitor &vis)
{
vis.visit (*this);