diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 7f04136fe63..6de0a20b6a0 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -178,6 +178,13 @@ GRS_OBJS = \
rust/rust-polonius.o\
rust/rust-hir-dot-operator.o \
rust/rust-hir-path-probe.o \
+ rust/rust-hir-path.o \
+ rust/rust-hir-type.o \
+ rust/rust-hir-expr.o \
+ rust/rust-hir-type-abstract.o \
+ rust/rust-hir-item.o \
+ rust/rust-hir-stmt.o \
+ rust/rust-hir-generic-param.o \
rust/rust-type-util.o \
rust/rust-coercion.o \
rust/rust-casts.o \
diff --git a/gcc/rust/hir/tree/rust-hir-attrs.h b/gcc/rust/hir/tree/rust-hir-attrs.h
new file mode 100644
index 00000000000..3e2b1d87cf8
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-attrs.h
@@ -0,0 +1,56 @@
+
+// Copyright (C) 2020-2024 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
+// .
+
+#ifndef RUST_HIR_ATTRS_H
+#define RUST_HIR_ATTRS_H
+
+#include "rust-ast.h"
+
+namespace Rust {
+namespace HIR {
+
+class WithOuterAttrs
+{
+protected:
+ AST::AttrVec outer_attrs;
+
+public:
+ AST::AttrVec &get_outer_attrs () { return outer_attrs; }
+ const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
+
+ WithOuterAttrs (AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)){};
+};
+
+class WithInnerAttrs
+{
+protected:
+ AST::AttrVec inner_attrs;
+
+public:
+ AST::AttrVec get_inner_attrs () const { return inner_attrs; }
+
+ WithInnerAttrs (AST::AttrVec inner_attrs)
+ : inner_attrs (std::move (inner_attrs)){};
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-bound-abstract.h b/gcc/rust/hir/tree/rust-hir-bound-abstract.h
new file mode 100644
index 00000000000..ffc915be919
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-bound-abstract.h
@@ -0,0 +1,65 @@
+// Copyright (C) 2020-2024 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
+// .
+
+#ifndef RUST_HIR_BOUND_ABSTRACT_H
+#define RUST_HIR_BOUND_ABSTRACT_H
+
+#include "rust-hir-visitable.h"
+#include "rust-system.h"
+#include "rust-hir-map.h"
+
+namespace Rust {
+namespace HIR {
+
+/* Abstract base class representing a type param bound - Lifetime and TraitBound
+ * extends it */
+class TypeParamBound : public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+ enum BoundType
+ {
+ LIFETIME,
+ TRAITBOUND
+ };
+
+ virtual ~TypeParamBound () {}
+
+ // Unique pointer custom clone function
+ std::unique_ptr clone_type_param_bound () const
+ {
+ return std::unique_ptr (clone_type_param_bound_impl ());
+ }
+
+ virtual std::string as_string () const = 0;
+
+ virtual Analysis::NodeMapping get_mappings () const = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ virtual BoundType get_bound_type () const = 0;
+
+protected:
+ // Clone function implementation as pure virtual method
+ virtual TypeParamBound *clone_type_param_bound_impl () const = 0;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-bound.h b/gcc/rust/hir/tree/rust-hir-bound.h
new file mode 100644
index 00000000000..78bb133f6d4
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-bound.h
@@ -0,0 +1,94 @@
+// Copyright (C) 2020-2024 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
+// .
+
+#ifndef RUST_HIR_BOUND_H
+#define RUST_HIR_BOUND_H
+
+#include "rust-hir-bound-abstract.h"
+#include "rust-common.h"
+#include "rust-hir-path.h"
+
+namespace Rust {
+namespace HIR {
+
+// Represents a lifetime (and is also a kind of type param bound)
+class Lifetime : public TypeParamBound
+{
+private:
+ AST::Lifetime::LifetimeType lifetime_type;
+ std::string lifetime_name;
+ location_t locus;
+ Analysis::NodeMapping mappings;
+
+public:
+ // Constructor
+ Lifetime (Analysis::NodeMapping mapping, AST::Lifetime::LifetimeType type,
+ std::string name, location_t locus)
+ : lifetime_type (type), lifetime_name (std::move (name)), locus (locus),
+ mappings (mapping)
+ {}
+
+ // 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;
+
+ WARN_UNUSED_RESULT const std::string &get_name () const
+ {
+ return lifetime_name;
+ }
+
+ AST::Lifetime::LifetimeType get_lifetime_type () const
+ {
+ return lifetime_type;
+ }
+
+ location_t get_locus () const override final { return locus; }
+
+ Analysis::NodeMapping get_mappings () const override final
+ {
+ return mappings;
+ }
+
+ BoundType get_bound_type () const final override { return LIFETIME; }
+
+protected:
+ /* Use covariance to implement clone function as returning this object rather
+ * than base */
+ Lifetime *clone_type_param_bound_impl () const override
+ {
+ return new Lifetime (*this);
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-expr-abstract.h b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
new file mode 100644
index 00000000000..ecf9bd1af5d
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-expr-abstract.h
@@ -0,0 +1,174 @@
+// Copyright (C) 2020-2024 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
+// .
+
+#ifndef RUST_HIR_EXPR_ABSTRACT_H
+#define RUST_HIR_EXPR_ABSTRACT_H
+
+#include "rust-ast.h"
+#include "rust-hir-visitable.h"
+#include "rust-hir-node.h"
+
+namespace Rust {
+namespace HIR {
+
+// Base expression HIR node - abstract
+class Expr : public Node, virtual public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+protected:
+ AST::AttrVec outer_attrs;
+ Analysis::NodeMapping mappings;
+
+public:
+ enum BlockType
+ {
+ WITH_BLOCK,
+ WITHOUT_BLOCK,
+ };
+
+ enum ExprType
+ {
+ Lit,
+ Operator,
+ Grouped,
+ Array,
+ ArrayIndex,
+ Tuple,
+ TupleIdx,
+ Struct,
+ Call,
+ MethodCall,
+ FieldAccess,
+ Closure,
+ Block,
+ Continue,
+ Break,
+ Range,
+ Return,
+ UnsafeBlock,
+ BaseLoop,
+ If,
+ IfLet,
+ Match,
+ Await,
+ AsyncBlock,
+ Path,
+ InlineAsm,
+ };
+
+ BaseKind get_hir_kind () override final { return Node::BaseKind::EXPR; }
+
+ const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
+
+ // Unique pointer custom clone function
+ std::unique_ptr clone_expr () const
+ {
+ return std::unique_ptr (clone_expr_impl ());
+ }
+
+ // TODO: make pure virtual if move out outer attributes to derived classes
+ virtual std::string as_string () const;
+
+ virtual ~Expr () {}
+
+ virtual location_t get_locus () const = 0;
+
+ const Analysis::NodeMapping &get_mappings () const { return mappings; }
+
+ // Clone function implementation as pure virtual method
+ virtual Expr *clone_expr_impl () const = 0;
+
+ virtual BlockType get_block_expr_type () const = 0;
+
+ virtual ExprType get_expression_type () const = 0;
+
+ virtual void accept_vis (HIRExpressionVisitor &vis) = 0;
+
+protected:
+ // Constructor
+ Expr (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
+
+ // TODO: think of less hacky way to implement this kind of thing
+ // Sets outer attributes.
+ void set_outer_attrs (AST::AttrVec outer_attrs_to_set)
+ {
+ outer_attrs = std::move (outer_attrs_to_set);
+ }
+};
+
+// HIR node for an expression without an accompanying block - abstract
+class ExprWithoutBlock : public Expr
+{
+protected:
+ // Constructor
+ ExprWithoutBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs = AST::AttrVec ());
+
+ // pure virtual clone implementation
+ virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
+
+ /* Save having to specify two clone methods in derived classes by making expr
+ * clone return exprwithoutblock clone. Hopefully won't affect performance too
+ * much. */
+ ExprWithoutBlock *clone_expr_impl () const override
+ {
+ return clone_expr_without_block_impl ();
+ }
+
+public:
+ // Unique pointer custom clone function
+ std::unique_ptr clone_expr_without_block () const
+ {
+ return std::unique_ptr (clone_expr_without_block_impl ());
+ }
+
+ BlockType get_block_expr_type () const final override
+ {
+ return BlockType::WITHOUT_BLOCK;
+ };
+};
+
+// Base path expression HIR node - abstract
+class PathExpr : public ExprWithoutBlock
+{
+protected:
+ PathExpr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs))
+ {}
+
+public:
+ /* Replaces the outer attributes of this path expression with the given outer
+ * attributes. */
+ void replace_outer_attrs (AST::AttrVec outer_attrs)
+ {
+ set_outer_attrs (std::move (outer_attrs));
+ }
+
+ ExprType get_expression_type () const final override
+ {
+ return ExprType::Path;
+ }
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
new file mode 100644
index 00000000000..9962ecbb187
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -0,0 +1,1541 @@
+// Copyright (C) 2020-2024 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
+// .
+
+#include "rust-hir-expr.h"
+#include "rust-operators.h"
+#include "rust-hir-stmt.h"
+
+namespace Rust {
+namespace HIR {
+
+Expr::Expr (Analysis::NodeMapping mappings, AST::AttrVec outer_attribs)
+ : outer_attrs (std::move (outer_attribs)), mappings (std::move (mappings))
+{}
+
+ExprWithoutBlock::ExprWithoutBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs)
+ : Expr (std::move (mappings), std::move (outer_attribs))
+{}
+
+LoopLabel::LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
+ location_t locus)
+ : label (std::move (loop_label)), locus (locus), mappings (mapping)
+{}
+
+ExprWithBlock::ExprWithBlock (Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attrs)
+ : Expr (std::move (mappings), std::move (outer_attrs))
+{}
+
+LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings,
+ std::string value_as_string, Literal::LitType type,
+ PrimitiveCoreType type_hint, location_t locus,
+ AST::AttrVec outer_attrs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ literal (std::move (value_as_string), type, type_hint), locus (locus)
+{}
+
+LiteralExpr::LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
+ location_t locus, AST::AttrVec outer_attrs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ literal (std::move (literal)), locus (locus)
+{}
+
+OperatorExpr::OperatorExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr main_or_left_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ locus (locus), main_or_left_expr (std::move (main_or_left_expr))
+{}
+
+OperatorExpr::OperatorExpr (OperatorExpr const &other)
+ : ExprWithoutBlock (other), locus (other.locus),
+ main_or_left_expr (other.main_or_left_expr->clone_expr ())
+{}
+
+OperatorExpr &
+OperatorExpr::operator= (OperatorExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ main_or_left_expr = other.main_or_left_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr borrow_lvalue, Mutability mut,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
+ std::move (outer_attribs), locus),
+ mut (mut)
+{}
+
+DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr deref_lvalue,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
+ std::move (outer_attribs), locus)
+{}
+
+ErrorPropagationExpr::ErrorPropagationExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr potential_error_value,
+ AST::AttrVec outer_attribs, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (potential_error_value),
+ std::move (outer_attribs), locus)
+{}
+
+NegationExpr::NegationExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr negated_value,
+ ExprType expr_kind, AST::AttrVec outer_attribs,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (negated_value),
+ std::move (outer_attribs), locus),
+ expr_type (expr_kind)
+{}
+
+ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr left_value,
+ std::unique_ptr right_value, ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
+ locus),
+ expr_type (expr_kind), right_expr (std::move (right_value))
+{}
+
+ArithmeticOrLogicalExpr::ArithmeticOrLogicalExpr (
+ ArithmeticOrLogicalExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+ArithmeticOrLogicalExpr &
+ArithmeticOrLogicalExpr::operator= (ArithmeticOrLogicalExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+
+ return *this;
+}
+
+ComparisonExpr::ComparisonExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr left_value,
+ std::unique_ptr right_value,
+ ExprType comparison_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_value), AST::AttrVec (),
+ locus),
+ expr_type (comparison_kind), right_expr (std::move (right_value))
+{}
+
+ComparisonExpr::ComparisonExpr (ComparisonExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+ComparisonExpr &
+ComparisonExpr::operator= (ComparisonExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+LazyBooleanExpr::LazyBooleanExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr left_bool_expr,
+ std::unique_ptr right_bool_expr,
+ ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
+ AST::AttrVec (), locus),
+ expr_type (expr_kind), right_expr (std::move (right_bool_expr))
+{}
+
+LazyBooleanExpr::LazyBooleanExpr (LazyBooleanExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+LazyBooleanExpr &
+LazyBooleanExpr::operator= (LazyBooleanExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+
+ return *this;
+}
+
+TypeCastExpr::TypeCastExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr expr_to_cast,
+ std::unique_ptr type_to_cast_to,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
+ AST::AttrVec (), locus),
+ type_to_convert_to (std::move (type_to_cast_to))
+{}
+
+TypeCastExpr::TypeCastExpr (TypeCastExpr const &other)
+ : OperatorExpr (other),
+ type_to_convert_to (other.type_to_convert_to->clone_type ())
+{}
+
+TypeCastExpr &
+TypeCastExpr::operator= (TypeCastExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ type_to_convert_to = other.type_to_convert_to->clone_type ();
+
+ return *this;
+}
+
+AssignmentExpr::AssignmentExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr value_to_assign_to,
+ std::unique_ptr value_to_assign,
+ location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
+ AST::AttrVec (), locus),
+ right_expr (std::move (value_to_assign))
+{}
+
+AssignmentExpr::AssignmentExpr (AssignmentExpr const &other)
+ : OperatorExpr (other), right_expr (other.right_expr->clone_expr ())
+{}
+
+AssignmentExpr &
+AssignmentExpr::operator= (AssignmentExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+CompoundAssignmentExpr::CompoundAssignmentExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr value_to_assign_to,
+ std::unique_ptr value_to_assign, ExprType expr_kind, location_t locus)
+ : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
+ AST::AttrVec (), locus),
+ expr_type (expr_kind), right_expr (std::move (value_to_assign))
+{}
+
+CompoundAssignmentExpr::CompoundAssignmentExpr (
+ CompoundAssignmentExpr const &other)
+ : OperatorExpr (other), expr_type (other.expr_type),
+ right_expr (other.right_expr->clone_expr ())
+{}
+
+CompoundAssignmentExpr &
+CompoundAssignmentExpr::operator= (CompoundAssignmentExpr const &other)
+{
+ OperatorExpr::operator= (other);
+ // main_or_left_expr = other.main_or_left_expr->clone_expr();
+ right_expr = other.right_expr->clone_expr ();
+ expr_type = other.expr_type;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+GroupedExpr::GroupedExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr parenthesised_expr,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ expr_in_parens (std::move (parenthesised_expr)), locus (locus)
+{}
+
+GroupedExpr::GroupedExpr (GroupedExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
+{}
+
+GroupedExpr &
+GroupedExpr::operator= (GroupedExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ expr_in_parens = other.expr_in_parens->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ArrayElemsValues::ArrayElemsValues (Analysis::NodeMapping mappings,
+ std::vector> elems)
+ : ArrayElems (mappings), values (std::move (elems))
+{}
+
+ArrayElemsValues::ArrayElemsValues (ArrayElemsValues const &other)
+ : ArrayElems (other)
+{
+ values.reserve (other.values.size ());
+ for (const auto &e : other.values)
+ values.push_back (e->clone_expr ());
+}
+
+ArrayElemsValues &
+ArrayElemsValues::operator= (ArrayElemsValues const &other)
+{
+ values.reserve (other.values.size ());
+ for (const auto &e : other.values)
+ values.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+ArrayElemsCopied::ArrayElemsCopied (Analysis::NodeMapping mappings,
+ std::unique_ptr copied_elem,
+ std::unique_ptr copy_amount)
+ : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
+ num_copies (std::move (copy_amount))
+{}
+
+ArrayElemsCopied::ArrayElemsCopied (ArrayElemsCopied const &other)
+ : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
+ num_copies (other.num_copies->clone_expr ())
+{}
+
+ArrayElemsCopied &
+ArrayElemsCopied::operator= (ArrayElemsCopied const &other)
+{
+ elem_to_copy = other.elem_to_copy->clone_expr ();
+ num_copies = other.num_copies->clone_expr ();
+
+ return *this;
+}
+
+ArrayExpr::ArrayExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr array_elems,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ internal_elements (std::move (array_elems)), locus (locus)
+{}
+
+ArrayExpr::ArrayExpr (ArrayExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ locus (other.locus)
+{
+ if (other.has_array_elems ())
+ internal_elements = other.internal_elements->clone_array_elems ();
+}
+
+ArrayExpr &
+ArrayExpr::operator= (ArrayExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ if (other.has_array_elems ())
+ internal_elements = other.internal_elements->clone_array_elems ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ArrayIndexExpr::ArrayIndexExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr array_expr,
+ std::unique_ptr array_index_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ array_expr (std::move (array_expr)),
+ index_expr (std::move (array_index_expr)), locus (locus)
+{}
+
+ArrayIndexExpr::ArrayIndexExpr (ArrayIndexExpr const &other)
+ : ExprWithoutBlock (other), array_expr (other.array_expr->clone_expr ()),
+ index_expr (other.index_expr->clone_expr ()), locus (other.locus)
+{}
+
+ArrayIndexExpr &
+ArrayIndexExpr::operator= (ArrayIndexExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ array_expr = other.array_expr->clone_expr ();
+ index_expr = other.index_expr->clone_expr ();
+ // outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ return *this;
+}
+
+TupleExpr::TupleExpr (Analysis::NodeMapping mappings,
+ std::vector> tuple_elements,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ tuple_elems (std::move (tuple_elements)), locus (locus)
+{}
+
+TupleExpr::TupleExpr (TupleExpr const &other)
+ : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
+ locus (other.locus)
+{
+ tuple_elems.reserve (other.tuple_elems.size ());
+ for (const auto &e : other.tuple_elems)
+ tuple_elems.push_back (e->clone_expr ());
+}
+
+TupleExpr &
+TupleExpr::operator= (TupleExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ inner_attrs = other.inner_attrs;
+ locus = other.locus;
+
+ tuple_elems.reserve (other.tuple_elems.size ());
+ for (const auto &e : other.tuple_elems)
+ tuple_elems.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+TupleIndexExpr::TupleIndexExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr tuple_expr,
+ TupleIndex index, AST::AttrVec outer_attribs,
+ location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
+{}
+
+TupleIndexExpr::TupleIndexExpr (TupleIndexExpr const &other)
+ : ExprWithoutBlock (other), tuple_expr (other.tuple_expr->clone_expr ()),
+ tuple_index (other.tuple_index), locus (other.locus)
+{}
+
+TupleIndexExpr &
+TupleIndexExpr::operator= (TupleIndexExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ tuple_expr = other.tuple_expr->clone_expr ();
+ tuple_index = other.tuple_index;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+StructExpr::StructExpr (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ struct_name (std::move (struct_path))
+{}
+
+StructExprStruct::StructExprStruct (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs,
+ location_t locus)
+ : StructExpr (std::move (mappings), std::move (struct_path),
+ std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)), locus (locus)
+{}
+
+StructBase::StructBase (std::unique_ptr base_struct_ptr)
+ : base_struct (std::move (base_struct_ptr))
+{}
+
+StructBase::StructBase (StructBase const &other)
+{
+ /* HACK: gets around base_struct pointer being null (e.g. if no struct base
+ * exists) */
+ if (other.base_struct != nullptr)
+ other.base_struct->clone_expr ();
+}
+
+StructBase &
+StructBase::operator= (StructBase const &other)
+{
+ base_struct = other.base_struct->clone_expr ();
+
+ return *this;
+}
+
+StructExprField::StructExprField (Analysis::NodeMapping mapping,
+ location_t locus)
+ : mappings (mapping), locus (locus)
+{}
+
+StructExprFieldIdentifier::StructExprFieldIdentifier (
+ Analysis::NodeMapping mapping, Identifier field_identifier, location_t locus)
+ : StructExprField (mapping, locus), field_name (std::move (field_identifier))
+{}
+
+StructExprFieldWithVal::StructExprFieldWithVal (
+ Analysis::NodeMapping mapping, std::unique_ptr field_value,
+ location_t locus)
+ : StructExprField (mapping, locus), value (std::move (field_value))
+{}
+
+StructExprFieldWithVal::StructExprFieldWithVal (
+ StructExprFieldWithVal const &other)
+ : StructExprField (other.mappings, other.locus),
+ value (other.value->clone_expr ())
+{}
+
+StructExprFieldWithVal &
+StructExprFieldWithVal::operator= (StructExprFieldWithVal const &other)
+{
+ value = other.value->clone_expr ();
+ mappings = other.mappings;
+ locus = other.locus;
+
+ return *this;
+}
+
+StructExprFieldIdentifierValue::StructExprFieldIdentifierValue (
+ Analysis::NodeMapping mapping, Identifier field_identifier,
+ std::unique_ptr field_value, location_t locus)
+ : StructExprFieldWithVal (mapping, std::move (field_value), locus),
+ field_name (std::move (field_identifier))
+{}
+
+StructExprFieldIndexValue::StructExprFieldIndexValue (
+ Analysis::NodeMapping mapping, TupleIndex tuple_index,
+ std::unique_ptr field_value, location_t locus)
+ : StructExprFieldWithVal (mapping, std::move (field_value), locus),
+ index (tuple_index)
+{}
+
+StructExprStructFields::StructExprStructFields (
+ Analysis::NodeMapping mappings, PathInExpression struct_path,
+ std::vector> expr_fields, location_t locus,
+ tl::optional> base_struct,
+ AST::AttrVec inner_attribs = AST::AttrVec (),
+ AST::AttrVec outer_attribs = AST::AttrVec ())
+ : StructExprStruct (std::move (mappings), std::move (struct_path),
+ std::move (inner_attribs), std::move (outer_attribs),
+ locus),
+ fields (std::move (expr_fields)), struct_base (std::move (base_struct))
+{}
+
+StructExprStructFields::StructExprStructFields (
+ StructExprStructFields const &other)
+ : StructExprStruct (other),
+ struct_base (
+ other.has_struct_base () ? tl::optional> (
+ Rust::make_unique (*other.struct_base.value ()))
+ : tl::nullopt),
+ union_index (other.union_index)
+{
+ fields.reserve (other.fields.size ());
+ for (const auto &e : other.fields)
+ fields.push_back (e->clone_struct_expr_field ());
+}
+
+StructExprStructFields &
+StructExprStructFields::operator= (StructExprStructFields const &other)
+{
+ StructExprStruct::operator= (other);
+ struct_base = other.has_struct_base ()
+ ? tl::optional> (
+ Rust::make_unique (*other.struct_base.value ()))
+ : tl::nullopt;
+ union_index = other.union_index;
+
+ fields.reserve (other.fields.size ());
+ for (const auto &e : other.fields)
+ fields.push_back (e->clone_struct_expr_field ());
+
+ return *this;
+}
+
+StructExprStructBase::StructExprStructBase (Analysis::NodeMapping mappings,
+ PathInExpression struct_path,
+ StructBase base_struct,
+ AST::AttrVec inner_attribs,
+ AST::AttrVec outer_attribs,
+ location_t locus)
+ : StructExprStruct (std::move (mappings), std::move (struct_path),
+ std::move (inner_attribs), std::move (outer_attribs),
+ locus),
+ struct_base (std::move (base_struct))
+{}
+
+CallExpr::CallExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr function_expr,
+ std::vector> function_params,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ function (std::move (function_expr)), params (std::move (function_params)),
+ locus (locus)
+{}
+
+CallExpr::CallExpr (CallExpr const &other)
+ : ExprWithoutBlock (other), function (other.function->clone_expr ()),
+ locus (other.locus)
+/*, params(other.params),*/ {
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+}
+
+CallExpr &
+CallExpr::operator= (CallExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ function = other.function->clone_expr ();
+ locus = other.locus;
+ // params = other.params;
+ // outer_attrs = other.outer_attrs;
+
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+MethodCallExpr::MethodCallExpr (
+ Analysis::NodeMapping mappings, std::unique_ptr call_receiver,
+ PathExprSegment method_path, std::vector> method_params,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ receiver (std::move (call_receiver)), method_name (std::move (method_path)),
+ params (std::move (method_params)), locus (locus)
+{}
+
+MethodCallExpr::MethodCallExpr (MethodCallExpr const &other)
+ : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
+ method_name (other.method_name), locus (other.locus)
+/*, params(other.params),*/ {
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+}
+
+MethodCallExpr &
+MethodCallExpr::operator= (MethodCallExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ receiver = other.receiver->clone_expr ();
+ method_name = other.method_name;
+ locus = other.locus;
+ // params = other.params;
+ // outer_attrs = other.outer_attrs;
+
+ params.reserve (other.params.size ());
+ for (const auto &e : other.params)
+ params.push_back (e->clone_expr ());
+
+ return *this;
+}
+
+FieldAccessExpr::FieldAccessExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr field_access_receiver,
+ Identifier field_name,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ receiver (std::move (field_access_receiver)),
+ field (std::move (field_name)), locus (locus)
+{}
+
+FieldAccessExpr::FieldAccessExpr (FieldAccessExpr const &other)
+ : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
+ field (other.field), locus (other.locus)
+{}
+
+FieldAccessExpr &
+FieldAccessExpr::operator= (FieldAccessExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ receiver = other.receiver->clone_expr ();
+ field = other.field;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+ClosureParam::ClosureParam (std::unique_ptr param_pattern,
+ location_t locus, std::unique_ptr param_type,
+ std::vector outer_attrs)
+ : outer_attrs (std::move (outer_attrs)), pattern (std::move (param_pattern)),
+ type (std::move (param_type)), locus (locus)
+{}
+
+ClosureParam::ClosureParam (ClosureParam const &other)
+ : pattern (other.pattern->clone_pattern ())
+{
+ // guard to protect from null pointer dereference
+ if (other.pattern != nullptr)
+ pattern = other.pattern->clone_pattern ();
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+}
+
+ClosureParam &
+ClosureParam::operator= (ClosureParam const &other)
+{
+ outer_attrs = other.outer_attrs;
+
+ // guard to protect from null pointer dereference
+ if (other.pattern != nullptr)
+ pattern = other.pattern->clone_pattern ();
+ else
+ pattern = nullptr;
+ if (other.type != nullptr)
+ type = other.type->clone_type ();
+ else
+ type = nullptr;
+
+ return *this;
+}
+
+ClosureExpr::ClosureExpr (Analysis::NodeMapping mappings,
+ std::vector closure_params,
+ std::unique_ptr closure_return_type,
+ std::unique_ptr closure_expr, bool has_move,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ has_move (has_move), params (std::move (closure_params)), locus (locus),
+ return_type (std::move (closure_return_type)),
+ expr (std::move (closure_expr))
+{}
+
+ClosureExpr::ClosureExpr (ClosureExpr const &other)
+ : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
+{
+ return_type
+ = other.has_return_type () ? other.return_type->clone_type () : nullptr;
+ expr = other.expr->clone_expr ();
+ params = other.params;
+ has_move = other.has_move;
+}
+
+ClosureExpr &
+ClosureExpr::operator= (ClosureExpr const &other)
+{
+ mappings = other.mappings;
+ return_type
+ = other.has_return_type () ? other.return_type->clone_type () : nullptr;
+ expr = other.expr->clone_expr ();
+ params = other.params;
+ has_move = other.has_move;
+
+ return *this;
+}
+
+BlockExpr::BlockExpr (Analysis::NodeMapping mappings,
+ std::vector> block_statements,
+ std::unique_ptr block_expr, bool tail_reachable,
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
+ LoopLabel label, location_t start_locus,
+ location_t end_locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
+ WithInnerAttrs (std::move (inner_attribs)),
+ statements (std::move (block_statements)), expr (std::move (block_expr)),
+ tail_reachable (tail_reachable), label (std::move (label)),
+ start_locus (start_locus), end_locus (end_locus)
+{}
+
+BlockExpr::BlockExpr (BlockExpr const &other)
+ : ExprWithBlock (other), /*statements(other.statements),*/
+ WithInnerAttrs (other.inner_attrs), label (other.label),
+ start_locus (other.start_locus), end_locus (other.end_locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.expr != nullptr)
+ expr = other.expr->clone_expr ();
+
+ statements.reserve (other.statements.size ());
+ for (const auto &e : other.statements)
+ statements.push_back (e->clone_stmt ());
+}
+
+BlockExpr &
+BlockExpr::operator= (BlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ // statements = other.statements;
+ expr = other.expr->clone_expr ();
+ inner_attrs = other.inner_attrs;
+ start_locus = other.end_locus;
+ end_locus = other.end_locus;
+ // outer_attrs = other.outer_attrs;
+
+ statements.reserve (other.statements.size ());
+ for (const auto &e : other.statements)
+ statements.push_back (e->clone_stmt ());
+
+ return *this;
+}
+
+ContinueExpr::ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
+ 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_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)),
+ locus (locus)
+{}
+
+BreakExpr::BreakExpr (BreakExpr const &other)
+ : ExprWithoutBlock (other), label (other.label), locus (other.locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.break_expr != nullptr)
+ break_expr = other.break_expr->clone_expr ();
+}
+
+BreakExpr &
+BreakExpr::operator= (BreakExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ label = other.label;
+ break_expr = other.break_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+RangeExpr::RangeExpr (Analysis::NodeMapping mappings, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
+{}
+
+RangeFromToExpr::RangeFromToExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr range_from,
+ std::unique_ptr range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
+ to (std::move (range_to))
+{}
+
+RangeFromToExpr::RangeFromToExpr (RangeFromToExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ()),
+ to (other.to->clone_expr ())
+{}
+
+RangeFromToExpr &
+RangeFromToExpr::operator= (RangeFromToExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeFromExpr::RangeFromExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr range_from,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
+{}
+
+RangeFromExpr::RangeFromExpr (RangeFromExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ())
+{}
+
+RangeFromExpr &
+RangeFromExpr::operator= (RangeFromExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+
+ return *this;
+}
+
+RangeToExpr::RangeToExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr range_to, location_t locus)
+ : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
+{}
+
+RangeToExpr::RangeToExpr (RangeToExpr const &other)
+ : RangeExpr (other), to (other.to->clone_expr ())
+{}
+
+RangeToExpr &
+RangeToExpr::operator= (RangeToExpr const &other)
+{
+ RangeExpr::operator= (other);
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeFullExpr::RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
+ : RangeExpr (std::move (mappings), locus)
+{}
+
+RangeFromToInclExpr::RangeFromToInclExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr range_from,
+ std::unique_ptr range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
+ to (std::move (range_to))
+{}
+
+RangeFromToInclExpr::RangeFromToInclExpr (RangeFromToInclExpr const &other)
+ : RangeExpr (other), from (other.from->clone_expr ()),
+ to (other.to->clone_expr ())
+{}
+
+RangeFromToInclExpr &
+RangeFromToInclExpr::operator= (RangeFromToInclExpr const &other)
+{
+ RangeExpr::operator= (other);
+ from = other.from->clone_expr ();
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+RangeToInclExpr::RangeToInclExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr range_to,
+ location_t locus)
+ : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
+{}
+
+RangeToInclExpr::RangeToInclExpr (RangeToInclExpr const &other)
+ : RangeExpr (other), to (other.to->clone_expr ())
+{}
+
+RangeToInclExpr &
+RangeToInclExpr::operator= (RangeToInclExpr const &other)
+{
+ RangeExpr::operator= (other);
+ to = other.to->clone_expr ();
+
+ return *this;
+}
+
+ReturnExpr::ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
+ std::unique_ptr returned_expr,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ return_expr (std::move (returned_expr)), locus (locus)
+{}
+
+ReturnExpr::ReturnExpr (ReturnExpr const &other)
+ : ExprWithoutBlock (other), locus (other.locus)
+{
+ // guard to protect from null pointer dereference
+ if (other.return_expr != nullptr)
+ return_expr = other.return_expr->clone_expr ();
+}
+
+ReturnExpr &
+ReturnExpr::operator= (ReturnExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ return_expr = other.return_expr->clone_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+UnsafeBlockExpr::UnsafeBlockExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr block_expr,
+ AST::AttrVec outer_attribs, location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
+ expr (std::move (block_expr)), locus (locus)
+{}
+
+UnsafeBlockExpr::UnsafeBlockExpr (UnsafeBlockExpr const &other)
+ : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
+ locus (other.locus)
+{}
+
+UnsafeBlockExpr &
+UnsafeBlockExpr::operator= (UnsafeBlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ expr = other.expr->clone_block_expr ();
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+BaseLoopExpr::BaseLoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr loop_block,
+ location_t locus, 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)),
+ locus (locus)
+{}
+
+BaseLoopExpr::BaseLoopExpr (BaseLoopExpr const &other)
+ : ExprWithBlock (other), loop_label (other.loop_label),
+ loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
+{}
+
+BaseLoopExpr &
+BaseLoopExpr::operator= (BaseLoopExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ loop_block = other.loop_block->clone_block_expr ();
+ loop_label = other.loop_label;
+ locus = other.locus;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+LoopExpr::LoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr loop_block, location_t locus,
+ LoopLabel loop_label, AST::AttrVec outer_attribs)
+ : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
+ std::move (loop_label), std::move (outer_attribs))
+{}
+
+WhileLoopExpr::WhileLoopExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr loop_condition,
+ std::unique_ptr loop_block,
+ location_t locus, LoopLabel loop_label,
+ AST::AttrVec outer_attribs)
+ : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
+ std::move (loop_label), std::move (outer_attribs)),
+ condition (std::move (loop_condition))
+{}
+
+WhileLoopExpr::WhileLoopExpr (WhileLoopExpr const &other)
+ : BaseLoopExpr (other), condition (other.condition->clone_expr ())
+{}
+
+WhileLoopExpr &
+WhileLoopExpr::operator= (WhileLoopExpr const &other)
+{
+ BaseLoopExpr::operator= (other);
+ condition = other.condition->clone_expr ();
+ // loop_block = other.loop_block->clone_block_expr();
+ // loop_label = other.loop_label;
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+WhileLetLoopExpr::WhileLetLoopExpr (
+ Analysis::NodeMapping mappings,
+ std::vector> match_arm_patterns,
+ std::unique_ptr condition, std::unique_ptr loop_block,
+ location_t locus, 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)),
+ condition (std::move (condition))
+{}
+
+WhileLetLoopExpr::WhileLetLoopExpr (WhileLetLoopExpr const &other)
+ : BaseLoopExpr (other),
+ /*match_arm_patterns(other.match_arm_patterns),*/ condition (
+ other.condition->clone_expr ())
+{
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+}
+
+WhileLetLoopExpr &
+WhileLetLoopExpr::operator= (WhileLetLoopExpr const &other)
+{
+ BaseLoopExpr::operator= (other);
+ // match_arm_patterns = other.match_arm_patterns;
+ condition = other.condition->clone_expr ();
+ // loop_block = other.loop_block->clone_block_expr();
+ // loop_label = other.loop_label;
+ // outer_attrs = other.outer_attrs;
+
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ return *this;
+}
+
+IfExpr::IfExpr (Analysis::NodeMapping mappings, std::unique_ptr condition,
+ std::unique_ptr if_block, location_t locus)
+ : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
+ condition (std::move (condition)), if_block (std::move (if_block)),
+ locus (locus)
+{}
+
+IfExpr::IfExpr (IfExpr const &other)
+ : ExprWithBlock (other), condition (other.condition->clone_expr ()),
+ if_block (other.if_block->clone_block_expr ()), locus (other.locus)
+{}
+
+IfExpr &
+IfExpr::operator= (IfExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ condition = other.condition->clone_expr ();
+ if_block = other.if_block->clone_block_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+IfExprConseqElse::IfExprConseqElse (Analysis::NodeMapping mappings,
+ std::unique_ptr condition,
+ std::unique_ptr if_block,
+ std::unique_ptr else_block,
+ location_t locus)
+ : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
+ locus),
+ else_block (std::move (else_block))
+{}
+
+IfExprConseqElse::IfExprConseqElse (IfExprConseqElse const &other)
+ : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
+{}
+
+IfExprConseqElse &
+IfExprConseqElse::operator= (IfExprConseqElse const &other)
+{
+ IfExpr::operator= (other);
+ // condition = other.condition->clone_expr();
+ // if_block = other.if_block->clone_block_expr();
+ else_block = other.else_block->clone_expr_with_block ();
+
+ return *this;
+}
+
+IfLetExpr::IfLetExpr (Analysis::NodeMapping mappings,
+ std::vector> match_arm_patterns,
+ std::unique_ptr value,
+ std::unique_ptr if_block, location_t locus)
+ : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
+ match_arm_patterns (std::move (match_arm_patterns)),
+ value (std::move (value)), if_block (std::move (if_block)), locus (locus)
+{}
+
+IfLetExpr::IfLetExpr (IfLetExpr const &other)
+ : ExprWithBlock (other),
+ /*match_arm_patterns(other.match_arm_patterns),*/ value (
+ other.value->clone_expr ()),
+ if_block (other.if_block->clone_block_expr ()), locus (other.locus)
+{
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+}
+
+IfLetExpr &
+IfLetExpr::operator= (IfLetExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ // match_arm_patterns = other.match_arm_patterns;
+ value = other.value->clone_expr ();
+ if_block = other.if_block->clone_block_expr ();
+ locus = other.locus;
+
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ return *this;
+}
+
+IfLetExprConseqElse::IfLetExprConseqElse (
+ Analysis::NodeMapping mappings,
+ std::vector> match_arm_patterns,
+ std::unique_ptr value, std::unique_ptr if_block,
+ std::unique_ptr else_block, location_t locus)
+ : IfLetExpr (std::move (mappings), std::move (match_arm_patterns),
+ std::move (value), std::move (if_block), locus),
+ else_block (std::move (else_block))
+{}
+
+IfLetExprConseqElse::IfLetExprConseqElse (IfLetExprConseqElse const &other)
+ : IfLetExpr (other), else_block (other.else_block->clone_expr_with_block ())
+{}
+
+IfLetExprConseqElse &
+IfLetExprConseqElse::operator= (IfLetExprConseqElse const &other)
+{
+ IfLetExpr::operator= (other);
+ // match_arm_patterns = other.match_arm_patterns;
+ // value = other.value->clone_expr();
+ // if_block = other.if_block->clone_block_expr();
+ else_block = other.else_block->clone_expr_with_block ();
+ // outer_attrs = other.outer_attrs;
+
+ return *this;
+}
+
+MatchArm::MatchArm (std::vector> match_arm_patterns,
+ location_t locus, std::unique_ptr guard_expr,
+ AST::AttrVec outer_attrs)
+ : outer_attrs (std::move (outer_attrs)),
+ match_arm_patterns (std::move (match_arm_patterns)),
+ guard_expr (std::move (guard_expr)), locus (locus)
+{}
+
+MatchArm::MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
+{
+ // guard to protect from null pointer dereference
+ if (other.guard_expr != nullptr)
+ guard_expr = other.guard_expr->clone_expr ();
+
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ locus = other.locus;
+}
+
+MatchArm &
+MatchArm::operator= (MatchArm const &other)
+{
+ outer_attrs = other.outer_attrs;
+
+ if (other.guard_expr != nullptr)
+ guard_expr = other.guard_expr->clone_expr ();
+
+ match_arm_patterns.clear ();
+ match_arm_patterns.reserve (other.match_arm_patterns.size ());
+ for (const auto &e : other.match_arm_patterns)
+ match_arm_patterns.push_back (e->clone_pattern ());
+
+ return *this;
+}
+
+MatchCase::MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
+ std::unique_ptr expr)
+ : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
+{}
+
+MatchCase::MatchCase (const MatchCase &other)
+ : mappings (other.mappings), arm (other.arm), expr (other.expr->clone_expr ())
+{}
+
+MatchCase &
+MatchCase::operator= (const MatchCase &other)
+{
+ mappings = other.mappings;
+ arm = other.arm;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+MatchExpr::MatchExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr branch_value,
+ std::vector match_arms,
+ AST::AttrVec inner_attrs, AST::AttrVec outer_attrs,
+ location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
+ WithInnerAttrs (std::move (inner_attrs)),
+ branch_value (std::move (branch_value)),
+ match_arms (std::move (match_arms)), locus (locus)
+{}
+
+MatchExpr::MatchExpr (MatchExpr const &other)
+ : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
+ branch_value (other.branch_value->clone_expr ()),
+ match_arms (other.match_arms), locus (other.locus)
+{
+ /*match_arms.reserve (other.match_arms.size ());
+ for (const auto &e : other.match_arms)
+ match_arms.push_back (e->clone_match_case ());*/
+}
+
+MatchExpr &
+MatchExpr::operator= (MatchExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ branch_value = other.branch_value->clone_expr ();
+ inner_attrs = other.inner_attrs;
+ match_arms = other.match_arms;
+ // outer_attrs = other.outer_attrs;
+ locus = other.locus;
+
+ /*match_arms.reserve (other.match_arms.size ());
+ for (const auto &e : other.match_arms)
+ match_arms.push_back (e->clone_match_case ());*/
+
+ return *this;
+}
+
+AwaitExpr::AwaitExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr awaited_expr,
+ AST::AttrVec outer_attrs, location_t locus)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
+ awaited_expr (std::move (awaited_expr)), locus (locus)
+{}
+
+AwaitExpr::AwaitExpr (AwaitExpr const &other)
+ : ExprWithoutBlock (other), awaited_expr (other.awaited_expr->clone_expr ()),
+ locus (other.locus)
+{}
+
+AwaitExpr &
+AwaitExpr::operator= (AwaitExpr const &other)
+{
+ ExprWithoutBlock::operator= (other);
+ awaited_expr = other.awaited_expr->clone_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+AsyncBlockExpr::AsyncBlockExpr (Analysis::NodeMapping mappings,
+ std::unique_ptr block_expr,
+ bool has_move, AST::AttrVec outer_attrs,
+ location_t locus)
+ : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
+ has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
+{}
+
+AsyncBlockExpr::AsyncBlockExpr (AsyncBlockExpr const &other)
+ : ExprWithBlock (other), has_move (other.has_move),
+ block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
+{}
+
+AsyncBlockExpr &
+AsyncBlockExpr::operator= (AsyncBlockExpr const &other)
+{
+ ExprWithBlock::operator= (other);
+ has_move = other.has_move;
+ block_expr = other.block_expr->clone_block_expr ();
+ locus = other.locus;
+
+ return *this;
+}
+
+OperatorExprMeta::OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().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 ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::NegationExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::DereferenceExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+OperatorExprMeta::OperatorExprMeta (HIR::ArrayIndexExpr &expr)
+ : node_mappings (expr.get_mappings ()),
+ lvalue_mappings (expr.get_array_expr ().get_mappings ()),
+ locus (expr.get_locus ())
+{}
+
+AnonConst::AnonConst (NodeId id, std::unique_ptr 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 ®,
+ std::unique_ptr expr)
+ : reg (reg), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::In::In (const struct In &other)
+{
+ reg = other.reg;
+
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::In
+InlineAsmOperand::In::operator= (const struct In &other)
+{
+ reg = other.reg;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::Out::Out (
+ tl::optional ®, bool late,
+ std::unique_ptr expr)
+ : reg (reg), late (late), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::Out::Out (const struct Out &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::Out
+InlineAsmOperand::Out::operator= (const struct Out &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+ return *this;
+}
+
+InlineAsmOperand::InOut::InOut (
+ tl::optional ®, bool late,
+ std::unique_ptr expr)
+ : reg (reg), late (late), expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::InOut::InOut (const struct InOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+}
+
+InlineAsmOperand::InOut
+InlineAsmOperand::InOut::operator= (const struct InOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ expr = other.expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::SplitInOut::SplitInOut (
+ tl::optional ®, bool late,
+ std::unique_ptr in_expr, std::unique_ptr out_expr)
+ : reg (reg), late (late), in_expr (std::move (in_expr)),
+ out_expr (std::move (out_expr))
+{
+ rust_assert (this->in_expr != nullptr);
+ rust_assert (this->out_expr != nullptr);
+}
+
+InlineAsmOperand::SplitInOut::SplitInOut (const struct SplitInOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr->clone_expr ();
+ out_expr = other.out_expr->clone_expr ();
+}
+
+InlineAsmOperand::SplitInOut
+InlineAsmOperand::SplitInOut::operator= (const struct SplitInOut &other)
+{
+ reg = other.reg;
+ late = other.late;
+ in_expr = other.in_expr->clone_expr ();
+ out_expr = other.out_expr->clone_expr ();
+
+ return *this;
+}
+
+InlineAsmOperand::Sym::Sym (std::unique_ptr expr)
+ : expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+}
+
+InlineAsmOperand::Sym::Sym (const struct Sym &other)
+{
+ expr = std::unique_ptr (other.expr->clone_expr ());
+}
+
+InlineAsmOperand::Sym
+InlineAsmOperand::Sym::operator= (const struct Sym &other)
+{
+ expr = std::unique_ptr (other.expr->clone_expr ());
+ return *this;
+}
+
+InlineAsmOperand::Label::Label (tl::optional label_name,
+ std::unique_ptr expr)
+ : expr (std::move (expr))
+{
+ rust_assert (this->expr != nullptr);
+ if (label_name.has_value ())
+ this->label_name = label_name.value ();
+}
+
+InlineAsmOperand::Label::Label (const struct Label &other)
+{
+ expr = std::unique_ptr (other.expr->clone_expr ());
+}
+
+InlineAsmOperand::Label
+InlineAsmOperand::Label::operator= (const struct Label &other)
+{
+ expr = std::unique_ptr (other.expr->clone_expr ());
+ return *this;
+}
+
+InlineAsm::InlineAsm (location_t locus, bool is_global_asm,
+ std::vector template_,
+ std::vector template_strs,
+ std::vector operands,
+ std::vector clobber_abi,
+ std::set options,
+ Analysis::NodeMapping mappings,
+ AST::AttrVec outer_attribs)
+ : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+ locus (locus), is_global_asm (is_global_asm),
+ template_ (std::move (template_)),
+ template_strs (std::move (template_strs)), operands (std::move (operands)),
+ clobber_abi (std::move (clobber_abi)), options (std::move (options))
+{}
+
+} // 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 7f2de644519..934ff4806e3 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -19,14 +19,13 @@
#ifndef RUST_HIR_EXPR_H
#define RUST_HIR_EXPR_H
-#include "optional.h"
+#include "rust-hir-expr-abstract.h"
+#include "rust-hir-literal.h"
#include "rust-common.h"
-#include "rust-ast-full-decls.h"
-#include "rust-hir.h"
-#include "rust-hir-path.h"
-#include "rust-operators.h"
+#include "rust-hir-bound.h"
+#include "rust-hir-attrs.h"
#include "rust-expr.h"
-#include "rust-system.h"
+
namespace Rust {
namespace HIR {
@@ -44,9 +43,7 @@ class LoopLabel /*: public Node*/
std::string as_string () const;
LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
- location_t locus)
- : label (std::move (loop_label)), locus (locus), mappings (mapping)
- {}
+ location_t locus);
// Returns whether the LoopLabel is in an error state.
bool is_error () const { return label.is_error (); }
@@ -64,9 +61,7 @@ class ExprWithBlock : public Expr
// TODO: should this mean that a BlockExpr should be a member variable?
protected:
ExprWithBlock (Analysis::NodeMapping mappings,
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : Expr (std::move (mappings), std::move (outer_attrs))
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// pure virtual clone implementation
virtual ExprWithBlock *clone_expr_with_block_impl () const = 0;
@@ -108,16 +103,10 @@ class LiteralExpr : public ExprWithoutBlock
LiteralExpr (Analysis::NodeMapping mappings, std::string value_as_string,
Literal::LitType type, PrimitiveCoreType type_hint,
- location_t locus, AST::AttrVec outer_attrs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- literal (std::move (value_as_string), type, type_hint), locus (locus)
- {}
+ location_t locus, AST::AttrVec outer_attrs);
LiteralExpr (Analysis::NodeMapping mappings, Literal literal,
- location_t locus, AST::AttrVec outer_attrs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- literal (std::move (literal)), locus (locus)
- {}
+ location_t locus, AST::AttrVec outer_attrs);
// Unique pointer custom clone function
std::unique_ptr clone_literal_expr () const
@@ -182,27 +171,13 @@ class OperatorExpr : public ExprWithoutBlock
// Constructor (only for initialisation of expr purposes)
OperatorExpr (Analysis::NodeMapping mappings,
std::unique_ptr main_or_left_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- locus (locus), main_or_left_expr (std::move (main_or_left_expr))
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor (only for initialisation of expr purposes)
- OperatorExpr (OperatorExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus),
- main_or_left_expr (other.main_or_left_expr->clone_expr ())
- {}
+ OperatorExpr (OperatorExpr const &other);
// Overload assignment operator to deep copy expr
- OperatorExpr &operator= (OperatorExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- main_or_left_expr = other.main_or_left_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ OperatorExpr &operator= (OperatorExpr const &other);
// move constructors
OperatorExpr (OperatorExpr &&other) = default;
@@ -230,11 +205,7 @@ class BorrowExpr : public OperatorExpr
BorrowExpr (Analysis::NodeMapping mappings,
std::unique_ptr borrow_lvalue, Mutability mut,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (borrow_lvalue),
- std::move (outer_attribs), locus),
- mut (mut)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -267,10 +238,7 @@ class DereferenceExpr : public OperatorExpr
// Constructor calls OperatorExpr's protected constructor
DereferenceExpr (Analysis::NodeMapping mappings,
std::unique_ptr deref_lvalue,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (deref_lvalue),
- std::move (outer_attribs), locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -300,10 +268,7 @@ class ErrorPropagationExpr : public OperatorExpr
// Constructor calls OperatorExpr's protected constructor
ErrorPropagationExpr (Analysis::NodeMapping mappings,
std::unique_ptr potential_error_value,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (potential_error_value),
- std::move (outer_attribs), locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -344,11 +309,7 @@ class NegationExpr : public OperatorExpr
// Constructor calls OperatorExpr's protected constructor
NegationExpr (Analysis::NodeMapping mappings,
std::unique_ptr negated_value, ExprType expr_kind,
- AST::AttrVec outer_attribs, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (negated_value),
- std::move (outer_attribs), locus),
- expr_type (expr_kind)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -390,29 +351,14 @@ class ArithmeticOrLogicalExpr : public OperatorExpr
ArithmeticOrLogicalExpr (Analysis::NodeMapping mappings,
std::unique_ptr left_value,
std::unique_ptr right_value,
- ExprType expr_kind, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_value),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (right_value))
- {}
+ ExprType expr_kind, location_t locus);
// outer attributes not allowed
// Copy constructor - probably required due to unique pointer
- ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr const &other);
// Overload assignment operator
- ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
-
- return *this;
- }
+ ArithmeticOrLogicalExpr &operator= (ArithmeticOrLogicalExpr const &other);
// move constructors
ArithmeticOrLogicalExpr (ArithmeticOrLogicalExpr &&other) = default;
@@ -467,30 +413,14 @@ class ComparisonExpr : public OperatorExpr
ComparisonExpr (Analysis::NodeMapping mappings,
std::unique_ptr left_value,
std::unique_ptr right_value, ExprType comparison_kind,
- location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_value),
- AST::AttrVec (), locus),
- expr_type (comparison_kind), right_expr (std::move (right_value))
- {}
+ location_t locus);
// outer attributes not allowed
// Copy constructor also calls OperatorExpr's protected constructor
- ComparisonExpr (ComparisonExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ ComparisonExpr (ComparisonExpr const &other);
// Overload assignment operator to deep copy
- ComparisonExpr &operator= (ComparisonExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ComparisonExpr &operator= (ComparisonExpr const &other);
// move constructors
ComparisonExpr (ComparisonExpr &&other) = default;
@@ -538,29 +468,14 @@ class LazyBooleanExpr : public OperatorExpr
LazyBooleanExpr (Analysis::NodeMapping mappings,
std::unique_ptr left_bool_expr,
std::unique_ptr right_bool_expr, ExprType expr_kind,
- location_t locus)
- : OperatorExpr (std::move (mappings), std::move (left_bool_expr),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (right_bool_expr))
- {}
+ location_t locus);
// outer attributes not allowed
// Copy constructor also calls OperatorExpr's protected constructor
- LazyBooleanExpr (LazyBooleanExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ LazyBooleanExpr (LazyBooleanExpr const &other);
// Overload assignment operator to deep copy
- LazyBooleanExpr &operator= (LazyBooleanExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
-
- return *this;
- }
+ LazyBooleanExpr &operator= (LazyBooleanExpr const &other);
// move constructors
LazyBooleanExpr (LazyBooleanExpr &&other) = default;
@@ -604,28 +519,14 @@ class TypeCastExpr : public OperatorExpr
// Constructor requires calling protected constructor of OperatorExpr
TypeCastExpr (Analysis::NodeMapping mappings,
std::unique_ptr expr_to_cast,
- std::unique_ptr type_to_cast_to, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (expr_to_cast),
- AST::AttrVec (), locus),
- type_to_convert_to (std::move (type_to_cast_to))
- {}
+ std::unique_ptr type_to_cast_to, location_t locus);
// outer attributes not allowed
// Copy constructor also requires calling protected constructor
- TypeCastExpr (TypeCastExpr const &other)
- : OperatorExpr (other),
- type_to_convert_to (other.type_to_convert_to->clone_type ())
- {}
+ TypeCastExpr (TypeCastExpr const &other);
// Overload assignment operator to deep copy
- TypeCastExpr &operator= (TypeCastExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- type_to_convert_to = other.type_to_convert_to->clone_type ();
-
- return *this;
- }
+ TypeCastExpr &operator= (TypeCastExpr const &other);
// move constructors as not supported in c++03
TypeCastExpr (TypeCastExpr &&other) = default;
@@ -666,28 +567,14 @@ class AssignmentExpr : public OperatorExpr
// Call OperatorExpr constructor to initialise left_expr
AssignmentExpr (Analysis::NodeMapping mappings,
std::unique_ptr value_to_assign_to,
- std::unique_ptr value_to_assign, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
- AST::AttrVec (), locus),
- right_expr (std::move (value_to_assign))
- {}
+ std::unique_ptr value_to_assign, location_t locus);
// outer attributes not allowed
// Call OperatorExpr constructor in copy constructor, as well as clone
- AssignmentExpr (AssignmentExpr const &other)
- : OperatorExpr (other), right_expr (other.right_expr->clone_expr ())
- {}
+ AssignmentExpr (AssignmentExpr const &other);
// Overload assignment operator to clone unique_ptr right_expr
- AssignmentExpr &operator= (AssignmentExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ AssignmentExpr &operator= (AssignmentExpr const &other);
// move constructors
AssignmentExpr (AssignmentExpr &&other) = default;
@@ -737,30 +624,14 @@ class CompoundAssignmentExpr : public OperatorExpr
CompoundAssignmentExpr (Analysis::NodeMapping mappings,
std::unique_ptr value_to_assign_to,
std::unique_ptr value_to_assign,
- ExprType expr_kind, location_t locus)
- : OperatorExpr (std::move (mappings), std::move (value_to_assign_to),
- AST::AttrVec (), locus),
- expr_type (expr_kind), right_expr (std::move (value_to_assign))
- {}
+ ExprType expr_kind, location_t locus);
// outer attributes not allowed
// Have clone in copy constructor
- CompoundAssignmentExpr (CompoundAssignmentExpr const &other)
- : OperatorExpr (other), expr_type (other.expr_type),
- right_expr (other.right_expr->clone_expr ())
- {}
+ CompoundAssignmentExpr (CompoundAssignmentExpr const &other);
// Overload assignment operator to clone
- CompoundAssignmentExpr &operator= (CompoundAssignmentExpr const &other)
- {
- OperatorExpr::operator= (other);
- // main_or_left_expr = other.main_or_left_expr->clone_expr();
- right_expr = other.right_expr->clone_expr ();
- expr_type = other.expr_type;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ CompoundAssignmentExpr &operator= (CompoundAssignmentExpr const &other);
// move constructors
CompoundAssignmentExpr (CompoundAssignmentExpr &&other) = default;
@@ -800,29 +671,13 @@ class GroupedExpr : public ExprWithoutBlock, public WithInnerAttrs
GroupedExpr (Analysis::NodeMapping mappings,
std::unique_ptr parenthesised_expr,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- expr_in_parens (std::move (parenthesised_expr)), locus (locus)
- {}
+ location_t locus);
// Copy constructor includes clone for expr_in_parens
- GroupedExpr (GroupedExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- expr_in_parens (other.expr_in_parens->clone_expr ()), locus (other.locus)
- {}
+ GroupedExpr (GroupedExpr const &other);
// Overloaded assignment operator to clone expr_in_parens
- GroupedExpr &operator= (GroupedExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- expr_in_parens = other.expr_in_parens->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ GroupedExpr &operator= (GroupedExpr const &other);
// move constructors
GroupedExpr (GroupedExpr &&other) = default;
@@ -901,27 +756,13 @@ class ArrayElemsValues : public ArrayElems
public:
ArrayElemsValues (Analysis::NodeMapping mappings,
- std::vector> elems)
- : ArrayElems (mappings), values (std::move (elems))
- {}
+ std::vector> elems);
// copy constructor with vector clone
- ArrayElemsValues (ArrayElemsValues const &other) : ArrayElems (other)
- {
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
- }
+ ArrayElemsValues (ArrayElemsValues const &other);
// overloaded assignment operator with vector clone
- ArrayElemsValues &operator= (ArrayElemsValues const &other)
- {
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
-
- return *this;
- }
+ ArrayElemsValues &operator= (ArrayElemsValues const &other);
// move constructors
ArrayElemsValues (ArrayElemsValues &&other) = default;
@@ -957,25 +798,13 @@ class ArrayElemsCopied : public ArrayElems
// Constructor requires pointers for polymorphism
ArrayElemsCopied (Analysis::NodeMapping mappings,
std::unique_ptr copied_elem,
- std::unique_ptr copy_amount)
- : ArrayElems (mappings), elem_to_copy (std::move (copied_elem)),
- num_copies (std::move (copy_amount))
- {}
+ std::unique_ptr copy_amount);
// Copy constructor required due to unique_ptr - uses custom clone
- ArrayElemsCopied (ArrayElemsCopied const &other)
- : ArrayElems (other), elem_to_copy (other.elem_to_copy->clone_expr ()),
- num_copies (other.num_copies->clone_expr ())
- {}
+ ArrayElemsCopied (ArrayElemsCopied const &other);
// Overloaded assignment operator for deep copying
- ArrayElemsCopied &operator= (ArrayElemsCopied const &other)
- {
- elem_to_copy = other.elem_to_copy->clone_expr ();
- num_copies = other.num_copies->clone_expr ();
-
- return *this;
- }
+ ArrayElemsCopied &operator= (ArrayElemsCopied const &other);
// move constructors
ArrayElemsCopied (ArrayElemsCopied &&other) = default;
@@ -1018,33 +847,13 @@ class ArrayExpr : public ExprWithoutBlock, public WithInnerAttrs
ArrayExpr (Analysis::NodeMapping mappings,
std::unique_ptr array_elems,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- internal_elements (std::move (array_elems)), locus (locus)
- {}
+ location_t locus);
// Copy constructor requires cloning ArrayElems for polymorphism to hold
- ArrayExpr (ArrayExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- locus (other.locus)
- {
- if (other.has_array_elems ())
- internal_elements = other.internal_elements->clone_array_elems ();
- }
+ ArrayExpr (ArrayExpr const &other);
// Overload assignment operator to clone internal_elements
- ArrayExpr &operator= (ArrayExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- if (other.has_array_elems ())
- internal_elements = other.internal_elements->clone_array_elems ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ArrayExpr &operator= (ArrayExpr const &other);
// move constructors
ArrayExpr (ArrayExpr &&other) = default;
@@ -1088,29 +897,13 @@ class ArrayIndexExpr : public ExprWithoutBlock
ArrayIndexExpr (Analysis::NodeMapping mappings,
std::unique_ptr array_expr,
std::unique_ptr array_index_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- array_expr (std::move (array_expr)),
- index_expr (std::move (array_index_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires special cloning due to unique_ptr
- ArrayIndexExpr (ArrayIndexExpr const &other)
- : ExprWithoutBlock (other), array_expr (other.array_expr->clone_expr ()),
- index_expr (other.index_expr->clone_expr ()), locus (other.locus)
- {}
+ ArrayIndexExpr (ArrayIndexExpr const &other);
// Overload assignment operator to clone unique_ptrs
- ArrayIndexExpr &operator= (ArrayIndexExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- array_expr = other.array_expr->clone_expr ();
- index_expr = other.index_expr->clone_expr ();
- // outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- return *this;
- }
+ ArrayIndexExpr &operator= (ArrayIndexExpr const &other);
// move constructors
ArrayIndexExpr (ArrayIndexExpr &&other) = default;
@@ -1159,35 +952,13 @@ class TupleExpr : public ExprWithoutBlock, public WithInnerAttrs
TupleExpr (Analysis::NodeMapping mappings,
std::vector> tuple_elements,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- tuple_elems (std::move (tuple_elements)), locus (locus)
- {}
+ location_t locus);
// copy constructor with vector clone
- TupleExpr (TupleExpr const &other)
- : ExprWithoutBlock (other), WithInnerAttrs (other.inner_attrs),
- locus (other.locus)
- {
- tuple_elems.reserve (other.tuple_elems.size ());
- for (const auto &e : other.tuple_elems)
- tuple_elems.push_back (e->clone_expr ());
- }
+ TupleExpr (TupleExpr const &other);
// overloaded assignment operator to vector clone
- TupleExpr &operator= (TupleExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- inner_attrs = other.inner_attrs;
- locus = other.locus;
-
- tuple_elems.reserve (other.tuple_elems.size ());
- for (const auto &e : other.tuple_elems)
- tuple_elems.push_back (e->clone_expr ());
-
- return *this;
- }
+ TupleExpr &operator= (TupleExpr const &other);
// move constructors
TupleExpr (TupleExpr &&other) = default;
@@ -1240,28 +1011,13 @@ class TupleIndexExpr : public ExprWithoutBlock
TupleIndexExpr (Analysis::NodeMapping mappings,
std::unique_ptr tuple_expr, TupleIndex index,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- tuple_expr (std::move (tuple_expr)), tuple_index (index), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires a clone for tuple_expr
- TupleIndexExpr (TupleIndexExpr const &other)
- : ExprWithoutBlock (other), tuple_expr (other.tuple_expr->clone_expr ()),
- tuple_index (other.tuple_index), locus (other.locus)
- {}
+ TupleIndexExpr (TupleIndexExpr const &other);
// Overload assignment operator in order to clone
- TupleIndexExpr &operator= (TupleIndexExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- tuple_expr = other.tuple_expr->clone_expr ();
- tuple_index = other.tuple_index;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ TupleIndexExpr &operator= (TupleIndexExpr const &other);
// move constructors
TupleIndexExpr (TupleIndexExpr &&other) = default;
@@ -1303,10 +1059,7 @@ class StructExpr : public ExprWithoutBlock
// Protected constructor to allow initialising struct_name
StructExpr (Analysis::NodeMapping mappings, PathInExpression struct_path,
- AST::AttrVec outer_attribs)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- struct_name (std::move (struct_path))
- {}
+ AST::AttrVec outer_attribs);
public:
PathInExpression &get_struct_name () { return struct_name; }
@@ -1330,11 +1083,7 @@ class StructExprStruct : public StructExpr, public WithInnerAttrs
// Constructor has to call protected constructor of base class
StructExprStruct (Analysis::NodeMapping mappings,
PathInExpression struct_path, AST::AttrVec inner_attribs,
- AST::AttrVec outer_attribs, location_t locus)
- : StructExpr (std::move (mappings), std::move (struct_path),
- std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
location_t get_locus () const override final { return locus; }
@@ -1366,29 +1115,16 @@ struct StructBase
public:
// TODO: should this store location data?
- StructBase (std::unique_ptr base_struct_ptr)
- : base_struct (std::move (base_struct_ptr))
- {}
+ StructBase (std::unique_ptr base_struct_ptr);
// Copy constructor requires clone
- StructBase (StructBase const &other)
- {
- /* HACK: gets around base_struct pointer being null (e.g. if no struct base
- * exists) */
- if (other.base_struct != nullptr)
- other.base_struct->clone_expr ();
- }
+ StructBase (StructBase const &other);
// Destructor
~StructBase () = default;
// Overload assignment operator to clone base_struct
- StructBase &operator= (StructBase const &other)
- {
- base_struct = other.base_struct->clone_expr ();
-
- return *this;
- }
+ StructBase &operator= (StructBase const &other);
// move constructors
StructBase (StructBase &&other) = default;
@@ -1440,9 +1176,7 @@ class StructExprField : public FullVisitable
// pure virtual clone implementation
virtual StructExprField *clone_struct_expr_field_impl () const = 0;
- StructExprField (Analysis::NodeMapping mapping, location_t locus)
- : mappings (mapping), locus (locus)
- {}
+ StructExprField (Analysis::NodeMapping mapping, location_t locus);
Analysis::NodeMapping mappings;
location_t locus;
@@ -1457,10 +1191,7 @@ class StructExprFieldIdentifier : public StructExprField
// TODO: should this store location data?
public:
StructExprFieldIdentifier (Analysis::NodeMapping mapping,
- Identifier field_identifier, location_t locus)
- : StructExprField (mapping, locus),
- field_name (std::move (field_identifier))
- {}
+ Identifier field_identifier, location_t locus);
std::string as_string () const override { return field_name.as_string (); }
@@ -1491,25 +1222,13 @@ class StructExprFieldWithVal : public StructExprField
protected:
StructExprFieldWithVal (Analysis::NodeMapping mapping,
- std::unique_ptr field_value, location_t locus)
- : StructExprField (mapping, locus), value (std::move (field_value))
- {}
+ std::unique_ptr field_value, location_t locus);
// Copy constructor requires clone
- StructExprFieldWithVal (StructExprFieldWithVal const &other)
- : StructExprField (other.mappings, other.locus),
- value (other.value->clone_expr ())
- {}
+ StructExprFieldWithVal (StructExprFieldWithVal const &other);
// Overload assignment operator to clone unique_ptr
- StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other)
- {
- value = other.value->clone_expr ();
- mappings = other.mappings;
- locus = other.locus;
-
- return *this;
- }
+ StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other);
// move constructors
StructExprFieldWithVal (StructExprFieldWithVal &&other) = default;
@@ -1532,10 +1251,7 @@ class StructExprFieldIdentifierValue : public StructExprFieldWithVal
StructExprFieldIdentifierValue (Analysis::NodeMapping mapping,
Identifier field_identifier,
std::unique_ptr field_value,
- location_t locus)
- : StructExprFieldWithVal (mapping, std::move (field_value), locus),
- field_name (std::move (field_identifier))
- {}
+ location_t locus);
std::string as_string () const override;
@@ -1569,10 +1285,7 @@ class StructExprFieldIndexValue : public StructExprFieldWithVal
StructExprFieldIndexValue (Analysis::NodeMapping mapping,
TupleIndex tuple_index,
std::unique_ptr field_value,
- location_t locus)
- : StructExprFieldWithVal (mapping, std::move (field_value), locus),
- index (tuple_index)
- {}
+ location_t locus);
std::string as_string () const override;
@@ -1616,44 +1329,13 @@ class StructExprStructFields : public StructExprStruct
Analysis::NodeMapping mappings, PathInExpression struct_path,
std::vector> expr_fields, location_t locus,
tl::optional> base_struct,
- AST::AttrVec inner_attribs = AST::AttrVec (),
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : StructExprStruct (std::move (mappings), std::move (struct_path),
- std::move (inner_attribs), std::move (outer_attribs),
- locus),
- fields (std::move (expr_fields)), struct_base (std::move (base_struct))
- {}
+ AST::AttrVec inner_attribs, AST::AttrVec outer_attribs);
// copy constructor with vector clone
- StructExprStructFields (StructExprStructFields const &other)
- : StructExprStruct (other),
- struct_base (
- other.has_struct_base () ? tl::optional> (
- Rust::make_unique (*other.struct_base.value ()))
- : tl::nullopt),
- union_index (other.union_index)
- {
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_struct_expr_field ());
- }
+ StructExprStructFields (StructExprStructFields const &other);
// overloaded assignment operator with vector clone
- StructExprStructFields &operator= (StructExprStructFields const &other)
- {
- StructExprStruct::operator= (other);
- struct_base
- = other.has_struct_base () ? tl::optional> (
- Rust::make_unique (*other.struct_base.value ()))
- : tl::nullopt;
- union_index = other.union_index;
-
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_struct_expr_field ());
-
- return *this;
- }
+ StructExprStructFields &operator= (StructExprStructFields const &other);
// move constructors
StructExprStructFields (StructExprStructFields &&other) = default;
@@ -1702,21 +1384,10 @@ class StructExprStructBase : public StructExprStruct
StructBase struct_base;
public:
- std::string as_string () const override;
-
- /*inline StructBase get_struct_base() const {
- return struct_base;
- }*/
-
StructExprStructBase (Analysis::NodeMapping mappings,
PathInExpression struct_path, StructBase base_struct,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- location_t locus)
- : StructExprStruct (std::move (mappings), std::move (struct_path),
- std::move (inner_attribs), std::move (outer_attribs),
- locus),
- struct_base (std::move (base_struct))
- {}
+ location_t locus);
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -1751,37 +1422,13 @@ class CallExpr : public ExprWithoutBlock
CallExpr (Analysis::NodeMapping mappings, std::unique_ptr function_expr,
std::vector> function_params,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- function (std::move (function_expr)),
- params (std::move (function_params)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// copy constructor requires clone
- CallExpr (CallExpr const &other)
- : ExprWithoutBlock (other), function (other.function->clone_expr ()),
- locus (other.locus)
- /*, params(other.params),*/ {
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
- }
+ CallExpr (CallExpr const &other);
// Overload assignment operator to clone
- CallExpr &operator= (CallExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- function = other.function->clone_expr ();
- locus = other.locus;
- // params = other.params;
- // outer_attrs = other.outer_attrs;
-
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
-
- return *this;
- }
+ CallExpr &operator= (CallExpr const &other);
// move constructors
CallExpr (CallExpr &&other) = default;
@@ -1840,39 +1487,13 @@ class MethodCallExpr : public ExprWithoutBlock
std::unique_ptr call_receiver,
PathExprSegment method_path,
std::vector> method_params,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- receiver (std::move (call_receiver)),
- method_name (std::move (method_path)), params (std::move (method_params)),
- locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// copy constructor required due to cloning
- MethodCallExpr (MethodCallExpr const &other)
- : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
- method_name (other.method_name), locus (other.locus)
- /*, params(other.params),*/ {
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
- }
+ MethodCallExpr (MethodCallExpr const &other);
// Overload assignment operator to clone receiver object
- MethodCallExpr &operator= (MethodCallExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- receiver = other.receiver->clone_expr ();
- method_name = other.method_name;
- locus = other.locus;
- // params = other.params;
- // outer_attrs = other.outer_attrs;
-
- params.reserve (other.params.size ());
- for (const auto &e : other.params)
- params.push_back (e->clone_expr ());
-
- return *this;
- }
+ MethodCallExpr &operator= (MethodCallExpr const &other);
// move constructors
MethodCallExpr (MethodCallExpr &&other) = default;
@@ -1934,29 +1555,13 @@ class FieldAccessExpr : public ExprWithoutBlock
FieldAccessExpr (Analysis::NodeMapping mappings,
std::unique_ptr field_access_receiver,
Identifier field_name, AST::AttrVec outer_attribs,
- location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- receiver (std::move (field_access_receiver)),
- field (std::move (field_name)), locus (locus)
- {}
+ location_t locus);
// Copy constructor required due to unique_ptr cloning
- FieldAccessExpr (FieldAccessExpr const &other)
- : ExprWithoutBlock (other), receiver (other.receiver->clone_expr ()),
- field (other.field), locus (other.locus)
- {}
+ FieldAccessExpr (FieldAccessExpr const &other);
// Overload assignment operator to clone unique_ptr
- FieldAccessExpr &operator= (FieldAccessExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- receiver = other.receiver->clone_expr ();
- field = other.field;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ FieldAccessExpr &operator= (FieldAccessExpr const &other);
// move constructors
FieldAccessExpr (FieldAccessExpr &&other) = default;
@@ -2008,42 +1613,15 @@ struct ClosureParam
// Constructor for closure parameter
ClosureParam (std::unique_ptr param_pattern, location_t locus,
std::unique_ptr param_type = nullptr,
- std::vector outer_attrs = {})
- : outer_attrs (std::move (outer_attrs)),
- pattern (std::move (param_pattern)), type (std::move (param_type)),
- locus (locus)
- {}
+ std::vector outer_attrs = {});
// Copy constructor required due to cloning as a result of unique_ptrs
- ClosureParam (ClosureParam const &other)
- : pattern (other.pattern->clone_pattern ())
- {
- // guard to protect from null pointer dereference
- if (other.pattern != nullptr)
- pattern = other.pattern->clone_pattern ();
- if (other.type != nullptr)
- type = other.type->clone_type ();
- }
+ ClosureParam (ClosureParam const &other);
~ClosureParam () = default;
// Assignment operator must be overloaded to clone as well
- ClosureParam &operator= (ClosureParam const &other)
- {
- outer_attrs = other.outer_attrs;
-
- // guard to protect from null pointer dereference
- if (other.pattern != nullptr)
- pattern = other.pattern->clone_pattern ();
- else
- pattern = nullptr;
- if (other.type != nullptr)
- type = other.type->clone_type ();
- else
- type = nullptr;
-
- return *this;
- }
+ ClosureParam &operator= (ClosureParam const &other);
// move constructors
ClosureParam (ClosureParam &&other) = default;
@@ -2079,36 +1657,13 @@ class ClosureExpr : public ExprWithoutBlock
std::vector closure_params,
std::unique_ptr closure_return_type,
std::unique_ptr closure_expr, bool has_move,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- has_move (has_move), params (std::move (closure_params)), locus (locus),
- return_type (std::move (closure_return_type)),
- expr (std::move (closure_expr))
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor requires cloning
- ClosureExpr (ClosureExpr const &other)
- : ExprWithoutBlock (other.get_mappings (), other.get_outer_attrs ())
- {
- return_type
- = other.has_return_type () ? other.return_type->clone_type () : nullptr;
- expr = other.expr->clone_expr ();
- params = other.params;
- has_move = other.has_move;
- }
+ ClosureExpr (ClosureExpr const &other);
// Overload assignment operator to clone unique_ptrs
- ClosureExpr &operator= (ClosureExpr const &other)
- {
- mappings = other.mappings;
- return_type
- = other.has_return_type () ? other.return_type->clone_type () : nullptr;
- expr = other.expr->clone_expr ();
- params = other.params;
- has_move = other.has_move;
-
- return *this;
- }
+ ClosureExpr &operator= (ClosureExpr const &other);
// move constructors
ClosureExpr (ClosureExpr &&other) = default;
@@ -2180,46 +1735,13 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs
std::vector> block_statements,
std::unique_ptr block_expr, bool tail_reachable,
AST::AttrVec inner_attribs, AST::AttrVec outer_attribs,
- LoopLabel label, location_t start_locus, location_t end_locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- WithInnerAttrs (std::move (inner_attribs)),
- statements (std::move (block_statements)), expr (std::move (block_expr)),
- tail_reachable (tail_reachable), label (std::move (label)),
- start_locus (start_locus), end_locus (end_locus)
- {}
+ LoopLabel label, location_t start_locus, location_t end_locus);
// Copy constructor with clone
- BlockExpr (BlockExpr const &other)
- : ExprWithBlock (other), /*statements(other.statements),*/
- WithInnerAttrs (other.inner_attrs), label (other.label),
- start_locus (other.start_locus), end_locus (other.end_locus)
- {
- // guard to protect from null pointer dereference
- if (other.expr != nullptr)
- expr = other.expr->clone_expr ();
-
- statements.reserve (other.statements.size ());
- for (const auto &e : other.statements)
- statements.push_back (e->clone_stmt ());
- }
+ BlockExpr (BlockExpr const &other);
// Overloaded assignment operator to clone pointer
- BlockExpr &operator= (BlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- // statements = other.statements;
- expr = other.expr->clone_expr ();
- inner_attrs = other.inner_attrs;
- start_locus = other.end_locus;
- end_locus = other.end_locus;
- // outer_attrs = other.outer_attrs;
-
- statements.reserve (other.statements.size ());
- for (const auto &e : other.statements)
- statements.push_back (e->clone_stmt ());
-
- return *this;
- }
+ BlockExpr &operator= (BlockExpr const &other);
// move constructors
BlockExpr (BlockExpr &&other) = default;
@@ -2292,10 +1814,7 @@ class ContinueExpr : public ExprWithoutBlock
// Constructor for a ContinueExpr with a label.
ContinueExpr (Analysis::NodeMapping mappings, location_t locus,
- Lifetime label, AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- label (std::move (label)), locus (locus)
- {}
+ Lifetime label, AST::AttrVec outer_attribs = AST::AttrVec ());
location_t get_locus () const override final { return locus; }
@@ -2350,32 +1869,13 @@ class BreakExpr : public ExprWithoutBlock
BreakExpr (Analysis::NodeMapping mappings, location_t locus,
Lifetime break_label,
std::unique_ptr expr_in_break = nullptr,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- label (std::move (break_label)), break_expr (std::move (expr_in_break)),
- locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor defined to use clone for unique pointer
- BreakExpr (BreakExpr const &other)
- : ExprWithoutBlock (other), label (other.label), locus (other.locus)
- {
- // guard to protect from null pointer dereference
- if (other.break_expr != nullptr)
- break_expr = other.break_expr->clone_expr ();
- }
+ BreakExpr (BreakExpr const &other);
// Overload assignment operator to clone unique pointer
- BreakExpr &operator= (BreakExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- label = other.label;
- break_expr = other.break_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ BreakExpr &operator= (BreakExpr const &other);
// move constructors
BreakExpr (BreakExpr &&other) = default;
@@ -2415,9 +1915,7 @@ class RangeExpr : public ExprWithoutBlock
protected:
// outer attributes not allowed before range expressions
- RangeExpr (Analysis::NodeMapping mappings, location_t locus)
- : ExprWithoutBlock (std::move (mappings), AST::AttrVec ()), locus (locus)
- {}
+ RangeExpr (Analysis::NodeMapping mappings, location_t locus);
public:
location_t get_locus () const override final { return locus; }
@@ -2440,26 +1938,13 @@ class RangeFromToExpr : public RangeExpr
RangeFromToExpr (Analysis::NodeMapping mappings,
std::unique_ptr range_from,
- std::unique_ptr range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
- to (std::move (range_to))
- {}
+ std::unique_ptr range_to, location_t locus);
// Copy constructor with cloning
- RangeFromToExpr (RangeFromToExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ()),
- to (other.to->clone_expr ())
- {}
+ RangeFromToExpr (RangeFromToExpr const &other);
// Overload assignment operator to clone unique pointers
- RangeFromToExpr &operator= (RangeFromToExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeFromToExpr &operator= (RangeFromToExpr const &other);
// move constructors
RangeFromToExpr (RangeFromToExpr &&other) = default;
@@ -2497,23 +1982,13 @@ class RangeFromExpr : public RangeExpr
std::string as_string () const override;
RangeFromExpr (Analysis::NodeMapping mappings,
- std::unique_ptr range_from, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from))
- {}
+ std::unique_ptr range_from, location_t locus);
// Copy constructor with clone
- RangeFromExpr (RangeFromExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ())
- {}
+ RangeFromExpr (RangeFromExpr const &other);
// Overload assignment operator to clone unique_ptr
- RangeFromExpr &operator= (RangeFromExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
-
- return *this;
- }
+ RangeFromExpr &operator= (RangeFromExpr const &other);
// move constructors
RangeFromExpr (RangeFromExpr &&other) = default;
@@ -2551,23 +2026,13 @@ class RangeToExpr : public RangeExpr
// outer attributes not allowed
RangeToExpr (Analysis::NodeMapping mappings, std::unique_ptr range_to,
- location_t locus)
- : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
- {}
+ location_t locus);
// Copy constructor with clone
- RangeToExpr (RangeToExpr const &other)
- : RangeExpr (other), to (other.to->clone_expr ())
- {}
+ RangeToExpr (RangeToExpr const &other);
// Overload assignment operator to clone unique_ptr
- RangeToExpr &operator= (RangeToExpr const &other)
- {
- RangeExpr::operator= (other);
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeToExpr &operator= (RangeToExpr const &other);
// move constructors
RangeToExpr (RangeToExpr &&other) = default;
@@ -2601,9 +2066,7 @@ class RangeFullExpr : public RangeExpr
public:
std::string as_string () const override;
- RangeFullExpr (Analysis::NodeMapping mappings, location_t locus)
- : RangeExpr (std::move (mappings), locus)
- {}
+ RangeFullExpr (Analysis::NodeMapping mappings, location_t locus);
// outer attributes not allowed
void accept_vis (HIRFullVisitor &vis) override;
@@ -2637,27 +2100,14 @@ class RangeFromToInclExpr : public RangeExpr
RangeFromToInclExpr (Analysis::NodeMapping mappings,
std::unique_ptr range_from,
- std::unique_ptr range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), from (std::move (range_from)),
- to (std::move (range_to))
- {}
+ std::unique_ptr range_to, location_t locus);
// outer attributes not allowed
// Copy constructor with clone
- RangeFromToInclExpr (RangeFromToInclExpr const &other)
- : RangeExpr (other), from (other.from->clone_expr ()),
- to (other.to->clone_expr ())
- {}
+ RangeFromToInclExpr (RangeFromToInclExpr const &other);
// Overload assignment operator to use clone
- RangeFromToInclExpr &operator= (RangeFromToInclExpr const &other)
- {
- RangeExpr::operator= (other);
- from = other.from->clone_expr ();
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeFromToInclExpr &operator= (RangeFromToInclExpr const &other);
// move constructors
RangeFromToInclExpr (RangeFromToInclExpr &&other) = default;
@@ -2695,24 +2145,14 @@ class RangeToInclExpr : public RangeExpr
std::string as_string () const override;
RangeToInclExpr (Analysis::NodeMapping mappings,
- std::unique_ptr range_to, location_t locus)
- : RangeExpr (std::move (mappings), locus), to (std::move (range_to))
- {}
+ std::unique_ptr range_to, location_t locus);
// outer attributes not allowed
// Copy constructor with clone
- RangeToInclExpr (RangeToInclExpr const &other)
- : RangeExpr (other), to (other.to->clone_expr ())
- {}
+ RangeToInclExpr (RangeToInclExpr const &other);
// Overload assignment operator to clone pointer
- RangeToInclExpr &operator= (RangeToInclExpr const &other)
- {
- RangeExpr::operator= (other);
- to = other.to->clone_expr ();
-
- return *this;
- }
+ RangeToInclExpr &operator= (RangeToInclExpr const &other);
// move constructors
RangeToInclExpr (RangeToInclExpr &&other) = default;
@@ -2756,30 +2196,13 @@ class ReturnExpr : public ExprWithoutBlock
// Constructor for ReturnExpr.
ReturnExpr (Analysis::NodeMapping mappings, location_t locus,
std::unique_ptr returned_expr = nullptr,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- return_expr (std::move (returned_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- ReturnExpr (ReturnExpr const &other)
- : ExprWithoutBlock (other), locus (other.locus)
- {
- // guard to protect from null pointer dereference
- if (other.return_expr != nullptr)
- return_expr = other.return_expr->clone_expr ();
- }
+ ReturnExpr (ReturnExpr const &other);
// Overloaded assignment operator to clone return_expr pointer
- ReturnExpr &operator= (ReturnExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- return_expr = other.return_expr->clone_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ ReturnExpr &operator= (ReturnExpr const &other);
// move constructors
ReturnExpr (ReturnExpr &&other) = default;
@@ -2826,27 +2249,13 @@ class UnsafeBlockExpr : public ExprWithBlock
UnsafeBlockExpr (Analysis::NodeMapping mappings,
std::unique_ptr block_expr,
- AST::AttrVec outer_attribs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- expr (std::move (block_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attribs, location_t locus);
// Copy constructor with clone
- UnsafeBlockExpr (UnsafeBlockExpr const &other)
- : ExprWithBlock (other), expr (other.expr->clone_block_expr ()),
- locus (other.locus)
- {}
+ UnsafeBlockExpr (UnsafeBlockExpr const &other);
// Overloaded assignment operator to clone
- UnsafeBlockExpr &operator= (UnsafeBlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- expr = other.expr->clone_block_expr ();
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ UnsafeBlockExpr &operator= (UnsafeBlockExpr const &other);
// move constructors
UnsafeBlockExpr (UnsafeBlockExpr &&other) = default;
@@ -2895,29 +2304,13 @@ class BaseLoopExpr : public ExprWithBlock
BaseLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithBlock (std::move (mappings), std::move (outer_attribs)),
- loop_label (std::move (loop_label)), loop_block (std::move (loop_block)),
- locus (locus)
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor for BaseLoopExpr with clone
- BaseLoopExpr (BaseLoopExpr const &other)
- : ExprWithBlock (other), loop_label (other.loop_label),
- loop_block (other.loop_block->clone_block_expr ()), locus (other.locus)
- {}
+ BaseLoopExpr (BaseLoopExpr const &other);
// Overloaded assignment operator to clone
- BaseLoopExpr &operator= (BaseLoopExpr const &other)
- {
- ExprWithBlock::operator= (other);
- loop_block = other.loop_block->clone_block_expr ();
- loop_label = other.loop_label;
- locus = other.locus;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ BaseLoopExpr &operator= (BaseLoopExpr const &other);
// move constructors
BaseLoopExpr (BaseLoopExpr &&other) = default;
@@ -2947,10 +2340,7 @@ class LoopExpr : public BaseLoopExpr
// Constructor for LoopExpr
LoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr loop_block, location_t locus,
- LoopLabel loop_label, AST::AttrVec outer_attribs = AST::AttrVec ())
- : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
- std::move (loop_label), std::move (outer_attribs))
- {}
+ LoopLabel loop_label, AST::AttrVec outer_attribs = AST::AttrVec ());
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
@@ -2981,28 +2371,13 @@ class WhileLoopExpr : public BaseLoopExpr
std::unique_ptr loop_condition,
std::unique_ptr loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : BaseLoopExpr (std::move (mappings), std::move (loop_block), locus,
- std::move (loop_label), std::move (outer_attribs)),
- condition (std::move (loop_condition))
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- WhileLoopExpr (WhileLoopExpr const &other)
- : BaseLoopExpr (other), condition (other.condition->clone_expr ())
- {}
+ WhileLoopExpr (WhileLoopExpr const &other);
// Overloaded assignment operator to clone
- WhileLoopExpr &operator= (WhileLoopExpr const &other)
- {
- BaseLoopExpr::operator= (other);
- condition = other.condition->clone_expr ();
- // loop_block = other.loop_block->clone_block_expr();
- // loop_label = other.loop_label;
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ WhileLoopExpr &operator= (WhileLoopExpr const &other);
// move constructors
WhileLoopExpr (WhileLoopExpr &&other) = default;
@@ -3045,40 +2420,13 @@ class WhileLetLoopExpr : public BaseLoopExpr
std::unique_ptr condition,
std::unique_ptr loop_block, location_t locus,
LoopLabel loop_label,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : 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)),
- condition (std::move (condition))
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
// Copy constructor with clone
- WhileLetLoopExpr (WhileLetLoopExpr const &other)
- : BaseLoopExpr (other),
- /*match_arm_patterns(other.match_arm_patterns),*/ condition (
- other.condition->clone_expr ())
- {
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
- }
+ WhileLetLoopExpr (WhileLetLoopExpr const &other);
// Overloaded assignment operator to clone pointers
- WhileLetLoopExpr &operator= (WhileLetLoopExpr const &other)
- {
- BaseLoopExpr::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- condition = other.condition->clone_expr ();
- // loop_block = other.loop_block->clone_block_expr();
- // loop_label = other.loop_label;
- // outer_attrs = other.outer_attrs;
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
+ WhileLetLoopExpr &operator= (WhileLetLoopExpr const &other);
// move constructors
WhileLetLoopExpr (WhileLetLoopExpr &&other) = default;
@@ -3124,29 +2472,14 @@ class IfExpr : public ExprWithBlock
std::string as_string () const override;
IfExpr (Analysis::NodeMapping mappings, std::unique_ptr condition,
- std::unique_ptr if_block, location_t locus)
- : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
- condition (std::move (condition)), if_block (std::move (if_block)),
- locus (locus)
- {}
+ std::unique_ptr if_block, location_t locus);
// outer attributes are never allowed on IfExprs
// Copy constructor with clone
- IfExpr (IfExpr const &other)
- : ExprWithBlock (other), condition (other.condition->clone_expr ()),
- if_block (other.if_block->clone_block_expr ()), locus (other.locus)
- {}
+ IfExpr (IfExpr const &other);
// Overloaded assignment operator to clone expressions
- IfExpr &operator= (IfExpr const &other)
- {
- ExprWithBlock::operator= (other);
- condition = other.condition->clone_expr ();
- if_block = other.if_block->clone_block_expr ();
- locus = other.locus;
-
- return *this;
- }
+ IfExpr &operator= (IfExpr const &other);
// move constructors
IfExpr (IfExpr &&other) = default;
@@ -3202,28 +2535,15 @@ class IfExprConseqElse : public IfExpr
IfExprConseqElse (Analysis::NodeMapping mappings,
std::unique_ptr condition,
std::unique_ptr if_block,
- std::unique_ptr else_block, location_t locus)
- : IfExpr (std::move (mappings), std::move (condition), std::move (if_block),
- locus),
- else_block (std::move (else_block))
- {}
+ std::unique_ptr else_block,
+ location_t locus);
// again, outer attributes not allowed
// Copy constructor with clone
- IfExprConseqElse (IfExprConseqElse const &other)
- : IfExpr (other), else_block (other.else_block->clone_expr_with_block ())
- {}
+ IfExprConseqElse (IfExprConseqElse const &other);
// Overloaded assignment operator with cloning
- IfExprConseqElse &operator= (IfExprConseqElse const &other)
- {
- IfExpr::operator= (other);
- // condition = other.condition->clone_expr();
- // if_block = other.if_block->clone_block_expr();
- else_block = other.else_block->clone_expr_with_block ();
-
- return *this;
- }
+ IfExprConseqElse &operator= (IfExprConseqElse const &other);
// move constructors
IfExprConseqElse (IfExprConseqElse &&other) = default;
@@ -3275,40 +2595,14 @@ class IfLetExpr : public ExprWithBlock
IfLetExpr (Analysis::NodeMapping mappings,
std::vector> match_arm_patterns,
std::unique_ptr value, std::unique_ptr if_block,
- location_t locus)
- : ExprWithBlock (std::move (mappings), AST::AttrVec ()),
- match_arm_patterns (std::move (match_arm_patterns)),
- value (std::move (value)), if_block (std::move (if_block)), locus (locus)
- {}
+ location_t locus);
// outer attributes not allowed on if let exprs either
// copy constructor with clone
- IfLetExpr (IfLetExpr const &other)
- : ExprWithBlock (other),
- /*match_arm_patterns(other.match_arm_patterns),*/ value (
- other.value->clone_expr ()),
- if_block (other.if_block->clone_block_expr ()), locus (other.locus)
- {
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
- }
+ IfLetExpr (IfLetExpr const &other);
// overload assignment operator to clone
- IfLetExpr &operator= (IfLetExpr const &other)
- {
- ExprWithBlock::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- value = other.value->clone_expr ();
- if_block = other.if_block->clone_block_expr ();
- locus = other.locus;
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
+ IfLetExpr &operator= (IfLetExpr const &other);
// move constructors
IfLetExpr (IfLetExpr &&other) = default;
@@ -3372,30 +2666,14 @@ class IfLetExprConseqElse : public IfLetExpr
std::unique_ptr value,
std::unique_ptr if_block,
std::unique_ptr else_block,
- location_t locus)
- : IfLetExpr (std::move (mappings), std::move (match_arm_patterns),
- std::move (value), std::move (if_block), locus),
- else_block (std::move (else_block))
- {}
+ location_t locus);
// outer attributes not allowed
// copy constructor with clone
- IfLetExprConseqElse (IfLetExprConseqElse const &other)
- : IfLetExpr (other), else_block (other.else_block->clone_expr_with_block ())
- {}
+ IfLetExprConseqElse (IfLetExprConseqElse const &other);
// overload assignment operator to clone
- IfLetExprConseqElse &operator= (IfLetExprConseqElse const &other)
- {
- IfLetExpr::operator= (other);
- // match_arm_patterns = other.match_arm_patterns;
- // value = other.value->clone_expr();
- // if_block = other.if_block->clone_block_expr();
- else_block = other.else_block->clone_expr_with_block ();
- // outer_attrs = other.outer_attrs;
-
- return *this;
- }
+ IfLetExprConseqElse &operator= (IfLetExprConseqElse const &other);
// move constructors
IfLetExprConseqElse (IfLetExprConseqElse &&other) = default;
@@ -3447,43 +2725,15 @@ struct MatchArm
// Constructor for match arm with a guard expression
MatchArm (std::vector> match_arm_patterns,
location_t locus, std::unique_ptr guard_expr = nullptr,
- AST::AttrVec outer_attrs = AST::AttrVec ())
- : outer_attrs (std::move (outer_attrs)),
- match_arm_patterns (std::move (match_arm_patterns)),
- guard_expr (std::move (guard_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs = AST::AttrVec ());
// Copy constructor with clone
- MatchArm (MatchArm const &other) : outer_attrs (other.outer_attrs)
- {
- // guard to protect from null pointer dereference
- if (other.guard_expr != nullptr)
- guard_expr = other.guard_expr->clone_expr ();
-
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- locus = other.locus;
- }
+ MatchArm (MatchArm const &other);
~MatchArm () = default;
// Overload assignment operator to clone
- MatchArm &operator= (MatchArm const &other)
- {
- outer_attrs = other.outer_attrs;
-
- if (other.guard_expr != nullptr)
- guard_expr = other.guard_expr->clone_expr ();
-
- match_arm_patterns.clear ();
- match_arm_patterns.reserve (other.match_arm_patterns.size ());
- for (const auto &e : other.match_arm_patterns)
- match_arm_patterns.push_back (e->clone_pattern ());
-
- return *this;
- }
+ MatchArm &operator= (MatchArm const &other);
// move constructors
MatchArm (MatchArm &&other) = default;
@@ -3522,23 +2772,11 @@ struct MatchCase
public:
MatchCase (Analysis::NodeMapping mappings, MatchArm arm,
- std::unique_ptr expr)
- : mappings (mappings), arm (std::move (arm)), expr (std::move (expr))
- {}
+ std::unique_ptr expr);
- MatchCase (const MatchCase &other)
- : mappings (other.mappings), arm (other.arm),
- expr (other.expr->clone_expr ())
- {}
+ MatchCase (const MatchCase &other);
- MatchCase &operator= (const MatchCase &other)
- {
- mappings = other.mappings;
- arm = other.arm;
- expr = other.expr->clone_expr ();
-
- return *this;
- }
+ MatchCase &operator= (const MatchCase &other);
MatchCase (MatchCase &&other) = default;
MatchCase &operator= (MatchCase &&other) = default;
@@ -3567,40 +2805,13 @@ class MatchExpr : public ExprWithBlock, public WithInnerAttrs
MatchExpr (Analysis::NodeMapping mappings, std::unique_ptr branch_value,
std::vector match_arms, AST::AttrVec inner_attrs,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
- WithInnerAttrs (std::move (inner_attrs)),
- branch_value (std::move (branch_value)),
- match_arms (std::move (match_arms)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// Copy constructor requires clone due to unique_ptr
- MatchExpr (MatchExpr const &other)
- : ExprWithBlock (other), WithInnerAttrs (other.inner_attrs),
- branch_value (other.branch_value->clone_expr ()),
- match_arms (other.match_arms), locus (other.locus)
- {
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
- }
+ MatchExpr (MatchExpr const &other);
// Overloaded assignment operator to clone due to unique_ptr
- MatchExpr &operator= (MatchExpr const &other)
- {
- ExprWithBlock::operator= (other);
- branch_value = other.branch_value->clone_expr ();
- inner_attrs = other.inner_attrs;
- match_arms = other.match_arms;
- // outer_attrs = other.outer_attrs;
- locus = other.locus;
-
- /*match_arms.reserve (other.match_arms.size ());
- for (const auto &e : other.match_arms)
- match_arms.push_back (e->clone_match_case ());*/
-
- return *this;
- }
+ MatchExpr &operator= (MatchExpr const &other);
// move constructors
MatchExpr (MatchExpr &&other) = default;
@@ -3643,26 +2854,13 @@ class AwaitExpr : public ExprWithoutBlock
public:
// TODO: ensure outer attributes are actually allowed
AwaitExpr (Analysis::NodeMapping mappings, std::unique_ptr awaited_expr,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attrs)),
- awaited_expr (std::move (awaited_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// copy constructor with clone
- AwaitExpr (AwaitExpr const &other)
- : ExprWithoutBlock (other),
- awaited_expr (other.awaited_expr->clone_expr ()), locus (other.locus)
- {}
+ AwaitExpr (AwaitExpr const &other);
// overloaded assignment operator with clone
- AwaitExpr &operator= (AwaitExpr const &other)
- {
- ExprWithoutBlock::operator= (other);
- awaited_expr = other.awaited_expr->clone_expr ();
- locus = other.locus;
-
- return *this;
- }
+ AwaitExpr &operator= (AwaitExpr const &other);
// move constructors
AwaitExpr (AwaitExpr &&other) = default;
@@ -3701,27 +2899,13 @@ class AsyncBlockExpr : public ExprWithBlock
public:
AsyncBlockExpr (Analysis::NodeMapping mappings,
std::unique_ptr block_expr, bool has_move,
- AST::AttrVec outer_attrs, location_t locus)
- : ExprWithBlock (std::move (mappings), std::move (outer_attrs)),
- has_move (has_move), block_expr (std::move (block_expr)), locus (locus)
- {}
+ AST::AttrVec outer_attrs, location_t locus);
// copy constructor with clone
- AsyncBlockExpr (AsyncBlockExpr const &other)
- : ExprWithBlock (other), has_move (other.has_move),
- block_expr (other.block_expr->clone_block_expr ()), locus (other.locus)
- {}
+ AsyncBlockExpr (AsyncBlockExpr const &other);
// overloaded assignment operator to clone
- AsyncBlockExpr &operator= (AsyncBlockExpr const &other)
- {
- ExprWithBlock::operator= (other);
- has_move = other.has_move;
- block_expr = other.block_expr->clone_block_expr ();
- locus = other.locus;
-
- return *this;
- }
+ AsyncBlockExpr &operator= (AsyncBlockExpr const &other);
// move constructors
AsyncBlockExpr (AsyncBlockExpr &&other) = default;
@@ -3755,35 +2939,15 @@ class AsyncBlockExpr : public ExprWithBlock
class OperatorExprMeta
{
public:
- OperatorExprMeta (HIR::CompoundAssignmentExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::CompoundAssignmentExpr &expr);
- OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr);
- OperatorExprMeta (HIR::NegationExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::NegationExpr &expr);
- OperatorExprMeta (HIR::DereferenceExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::DereferenceExpr &expr);
- OperatorExprMeta (HIR::ArrayIndexExpr &expr)
- : node_mappings (expr.get_mappings ()),
- lvalue_mappings (expr.get_array_expr ().get_mappings ()),
- locus (expr.get_locus ())
- {}
+ OperatorExprMeta (HIR::ArrayIndexExpr &expr);
const Analysis::NodeMapping &get_mappings () const { return node_mappings; }
@@ -3858,23 +3022,12 @@ struct AnonConst
{
NodeId id;
std::unique_ptr expr;
- AnonConst (NodeId id, std::unique_ptr expr)
- : id (id), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
- AnonConst (const AnonConst &other)
- {
- id = other.id;
- expr = other.expr->clone_expr ();
- }
- AnonConst operator= (const AnonConst &other)
- {
- id = other.id;
- expr = other.expr->clone_expr ();
- return *this;
- }
+ AnonConst (NodeId id, std::unique_ptr expr);
+
+ AnonConst (const AnonConst &other);
+
+ AnonConst operator= (const AnonConst &other);
};
class InlineAsmOperand
@@ -3886,26 +3039,11 @@ class InlineAsmOperand
std::unique_ptr expr;
In (const tl::optional ®,
- std::unique_ptr expr)
- : reg (reg), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- In (const struct In &other)
- {
- reg = other.reg;
-
- expr = other.expr->clone_expr ();
- }
-
- In operator= (const struct In &other)
- {
- reg = other.reg;
- expr = other.expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr expr);
+
+ In (const struct In &other);
+
+ In operator= (const struct In &other);
};
struct Out
@@ -3915,26 +3053,11 @@ class InlineAsmOperand
std::unique_ptr expr; // can be null
Out (tl::optional ®, bool late,
- std::unique_ptr expr)
- : reg (reg), late (late), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- Out (const struct Out &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- }
-
- Out operator= (const struct Out &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- return *this;
- }
+ std::unique_ptr expr);
+
+ Out (const struct Out &other);
+
+ Out operator= (const struct Out &other);
};
struct InOut
@@ -3944,27 +3067,11 @@ class InlineAsmOperand
std::unique_ptr expr; // this can't be null
InOut (tl::optional ®, bool late,
- std::unique_ptr expr)
- : reg (reg), late (late), expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
-
- InOut (const struct InOut &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
- }
-
- InOut operator= (const struct InOut &other)
- {
- reg = other.reg;
- late = other.late;
- expr = other.expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr expr);
+
+ InOut (const struct InOut &other);
+
+ InOut operator= (const struct InOut &other);
};
struct SplitInOut
@@ -3976,31 +3083,11 @@ class InlineAsmOperand
SplitInOut (tl::optional ®,
bool late, std::unique_ptr in_expr,
- std::unique_ptr out_expr)
- : reg (reg), late (late), in_expr (std::move (in_expr)),
- out_expr (std::move (out_expr))
- {
- rust_assert (this->in_expr != nullptr);
- rust_assert (this->out_expr != nullptr);
- }
-
- SplitInOut (const struct SplitInOut &other)
- {
- reg = other.reg;
- late = other.late;
- in_expr = other.in_expr->clone_expr ();
- out_expr = other.out_expr->clone_expr ();
- }
-
- SplitInOut operator= (const struct SplitInOut &other)
- {
- reg = other.reg;
- late = other.late;
- in_expr = other.in_expr->clone_expr ();
- out_expr = other.out_expr->clone_expr ();
-
- return *this;
- }
+ std::unique_ptr out_expr);
+
+ SplitInOut (const struct SplitInOut &other);
+
+ SplitInOut operator= (const struct SplitInOut &other);
};
struct Const
@@ -4012,20 +3099,11 @@ class InlineAsmOperand
{
std::unique_ptr expr;
- Sym (std::unique_ptr expr) : expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- }
- Sym (const struct Sym &other)
- {
- expr = std::unique_ptr (other.expr->clone_expr ());
- }
-
- Sym operator= (const struct Sym &other)
- {
- expr = std::unique_ptr (other.expr->clone_expr ());
- return *this;
- }
+ Sym (std::unique_ptr expr);
+
+ Sym (const struct Sym &other);
+
+ Sym operator= (const struct Sym &other);
};
struct Label
@@ -4033,23 +3111,11 @@ class InlineAsmOperand
std::string label_name;
std::unique_ptr expr;
- Label (tl::optional label_name, std::unique_ptr expr)
- : expr (std::move (expr))
- {
- rust_assert (this->expr != nullptr);
- if (label_name.has_value ())
- this->label_name = label_name.value ();
- }
- Label (const struct Label &other)
- {
- expr = std::unique_ptr (other.expr->clone_expr ());
- }
-
- Label operator= (const struct Label &other)
- {
- expr = std::unique_ptr (other.expr->clone_expr ());
- return *this;
- }
+ Label (tl::optional label_name, std::unique_ptr expr);
+
+ Label (const struct Label &other);
+
+ Label operator= (const struct Label &other);
};
private:
@@ -4169,6 +3235,7 @@ class InlineAsm : public ExprWithoutBlock
// INFO: An inline asm is asm!, which is the opposite of a global_asm()
return !this->is_global_asm;
}
+
InlineAsm (location_t locus, bool is_global_asm,
std::vector template_,
std::vector template_strs,
@@ -4176,16 +3243,9 @@ class InlineAsm : public ExprWithoutBlock
std::vector clobber_abi,
std::set options,
Analysis::NodeMapping mappings,
- AST::AttrVec outer_attribs = AST::AttrVec ())
- : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
- locus (locus), is_global_asm (is_global_asm),
- template_ (std::move (template_)),
- template_strs (std::move (template_strs)),
- operands (std::move (operands)), clobber_abi (std::move (clobber_abi)),
- options (std::move (options))
-
- {}
+ AST::AttrVec outer_attribs = AST::AttrVec ());
};
+
} // namespace HIR
} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.cc b/gcc/rust/hir/tree/rust-hir-generic-param.cc
new file mode 100644
index 00000000000..e5afa8ee08f
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.cc
@@ -0,0 +1,95 @@
+// Copyright (C) 2020-2024 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
+// .
+
+#include "rust-hir-generic-param.h"
+
+namespace Rust {
+namespace HIR {
+
+GenericParam::GenericParam (Analysis::NodeMapping mapping,
+ enum GenericKind kind)
+ : mappings (mapping), kind (kind)
+{}
+
+LifetimeParam::LifetimeParam (Analysis::NodeMapping mappings, Lifetime lifetime,
+ location_t locus,
+ std::vector lifetime_bounds,
+ AST::AttrVec outer_attrs)
+ : GenericParam (mappings, GenericKind::LIFETIME),
+ lifetime (std::move (lifetime)),
+ lifetime_bounds (std::move (lifetime_bounds)),
+ outer_attrs (std::move (outer_attrs)), locus (locus)
+{}
+
+LifetimeParam::LifetimeParam (LifetimeParam const &other)
+ : GenericParam (other.mappings, GenericKind::LIFETIME),
+ lifetime (other.lifetime), lifetime_bounds (other.lifetime_bounds),
+ outer_attrs (other.outer_attrs), locus (other.locus)
+{}
+
+LifetimeParam &
+LifetimeParam::operator= (LifetimeParam const &other)
+{
+ lifetime = other.lifetime;
+ lifetime_bounds = other.lifetime_bounds;
+ outer_attrs = other.outer_attrs;
+ locus = other.locus;
+ mappings = other.mappings;
+
+ return *this;
+}
+
+ConstGenericParam::ConstGenericParam (std::string name,
+ std::unique_ptr type,
+ std::unique_ptr default_expression,
+ Analysis::NodeMapping mapping,
+ location_t locus)
+ : GenericParam (mapping, GenericKind::CONST), name (std::move (name)),
+ type (std::move (type)),
+ default_expression (std::move (default_expression)), locus (locus)
+{}
+
+ConstGenericParam::ConstGenericParam (const ConstGenericParam &other)
+ : GenericParam (other)
+{
+ name = other.name;
+ locus = other.locus;
+
+ if (other.type)
+ type = other.type->clone_type ();
+ if (other.default_expression)
+ default_expression = other.default_expression->clone_expr ();
+}
+
+std::string
+ConstGenericParam::as_string () const
+{
+ auto result = "ConstGenericParam: " + name + " : " + type->as_string ();
+
+ if (default_expression)
+ result += " = " + default_expression->as_string ();
+
+ return result;
+}
+
+void
+ConstGenericParam::accept_vis (HIRFullVisitor &)
+{}
+
+} // namespace HIR
+} // namespace Rust
diff --git a/gcc/rust/hir/tree/rust-hir-generic-param.h b/gcc/rust/hir/tree/rust-hir-generic-param.h
new file mode 100644
index 00000000000..73b93d48a49
--- /dev/null
+++ b/gcc/rust/hir/tree/rust-hir-generic-param.h
@@ -0,0 +1,186 @@
+
+// Copyright (C) 2020-2024 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
+// .
+
+#ifndef RUST_HIR_GENERIC_PARAM_H
+#define RUST_HIR_GENERIC_PARAM_H
+
+#include "rust-hir-visitable.h"
+#include "rust-hir-bound.h"
+
+namespace Rust {
+namespace HIR {
+
+/* Base generic parameter in HIR. Abstract - can be represented by a Lifetime or
+ * Type param */
+class GenericParam : public FullVisitable
+{
+public:
+ using FullVisitable::accept_vis;
+
+ virtual ~GenericParam () {}
+
+ enum class GenericKind
+ {
+ TYPE,
+ LIFETIME,
+ CONST,
+ };
+
+ virtual AST::AttrVec &get_outer_attrs () = 0;
+ virtual bool has_outer_attribute () const = 0;
+
+ // Unique pointer custom clone function
+ std::unique_ptr clone_generic_param () const
+ {
+ return std::unique_ptr (clone_generic_param_impl ());
+ }
+
+ virtual std::string as_string () const = 0;
+
+ virtual location_t get_locus () const = 0;
+
+ Analysis::NodeMapping get_mappings () const { return mappings; }
+
+ enum GenericKind get_kind () const { return kind; }
+
+protected:
+ // Clone function implementation as pure virtual method
+ virtual GenericParam *clone_generic_param_impl () const = 0;
+
+ Analysis::NodeMapping mappings;
+
+ enum GenericKind kind;
+
+ GenericParam (Analysis::NodeMapping mapping,
+ enum GenericKind kind = GenericKind::TYPE);
+};
+
+// A lifetime generic parameter (as opposed to a type generic parameter)
+class LifetimeParam : public GenericParam
+{
+ Lifetime lifetime;
+
+ // bool has_lifetime_bounds;
+ // LifetimeBounds lifetime_bounds;
+ std::vector lifetime_bounds; // inlined LifetimeBounds
+
+ AST::AttrVec outer_attrs;
+
+ location_t locus;
+
+public:
+ Lifetime get_lifetime () { return lifetime; }
+
+ // Returns whether the lifetime param has any lifetime bounds.
+ bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }
+
+ std::vector &get_lifetime_bounds () { return lifetime_bounds; }
+
+ // Returns whether the lifetime param has an outer attribute.
+ bool has_outer_attribute () const override { return outer_attrs.size () > 1; }
+
+ 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,
+ std::vector lifetime_bounds
+ = std::vector