aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2023-07-02 23:33:02 +0200
committerPhilip Herron <philip.herron@embecosm.com>2023-07-06 10:50:15 +0000
commitf2617325f8794673dadf7737290a71e7a7e4316a (patch)
tree4fc93b19901b3c0c055fd03a5d49249f39fbd89b
parent5406b633a1f5e6e3ae8da02589adf4ea003dec12 (diff)
downloadgcc-f2617325f8794673dadf7737290a71e7a7e4316a.zip
gcc-f2617325f8794673dadf7737290a71e7a7e4316a.tar.gz
gcc-f2617325f8794673dadf7737290a71e7a7e4316a.tar.bz2
gccrs: HIR cleanup
Some more HIR cleanup. gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h (BorrowExpr::is_double_borrow): New. (ArrayElemsCopied::get_elem_to_copy) (ArrayElemsCopied::get_num_copies_expr): Return unique_ptr. (CallExpr::get_fnexpr): Likewise. (ReturnExpr::get_expr): Likewise. (StructExprStructFields::get_struct_base): New. (MethodCallExpr::has_params): New. (ClosureExpr::has_params): New. (BlockExpr::get_inner_attrs): New. (WhileLoopExpr::get_patterns): New. (ForLoopExpr::get_pattern): New. (IfLetExpr::get_if_block): Return ref to unique_ptr. (IfLetExprConseqElse::get_else_block): Likewise. (MatchExpr::get_inner_attrs): New. * hir/tree/rust-hir-item.h (Module::get_module_name): New. (ExternCrate::get_referenced_crate) (ExternCrate::get_as_clause_name): New. (UseTreeGlob::get_glob_type, UseTreeGlob::get_path): New. (UseTreeList::get_path_type, UseTreeList::get_path) (UseTreeList::get_trees): New. (TraitItemKind::get_expr): Remove assert. unique_ptr can be "empty". Must be checked in caller. * hir/tree/rust-hir-pattern.h (IdentifierPattern::get_is_ref) (IdentifierPattern::get_to_bind): New. (RangePatternBoundType::get_has_minus): New. (RangePattern::get_has_ellipsis_syntax): New. (StructPatternField::get_outer_attrs): New. (StructPatternFieldTuplePat::get_index) (StructPatternFieldTuplePat::get_tuple_pattern): New. (StructPatternFieldIdent::get_has_ref): New. * hir/tree/rust-hir-stmt.h (LetStmt::get_outer_attrs): New. (LetStmt::get_type) (LetStmt::get_init_expr, LetStmt::get_pattern): Return unique_ptr. (ExprStmt::get_expr): Likewise. * hir/tree/rust-hir-type.h (TraitBound::get_for_lifetimes): New. (TraitBound::get_in_params): New. (TraitBound::get_opening_question_mark): New. (ImplTraitType::get_type_param_bounds): New. (TraitObjectType::get_has_dyn): New. (TraitBound::get_type_in_parens): New. (ImplTraitTypeOneBound::get_trait_bound): New. (BareFunctionType::get_for_lifetimes) (BareFunctionType::get_is_variadic) (BareFunctionType::get_function_qualifiers): New. * hir/tree/rust-hir.h (class Expr): Virtual inherit from FullVisitable. (class Pattern): Likewise. (ConstGenericParam::get_name): New. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adjust call. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Adjust call. (CompileExpr::array_copied_expr): Likewise. (CompileExpr::generate_possible_fn_trait_call): Likewise. * backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc10
-rw-r--r--gcc/rust/backend/rust-compile-stmt.cc4
-rw-r--r--gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc15
-rw-r--r--gcc/rust/checks/errors/rust-const-checker.cc5
-rw-r--r--gcc/rust/checks/errors/rust-unsafe-checker.cc5
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc12
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h28
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h16
-rw-r--r--gcc/rust/hir/tree/rust-hir-pattern.h11
-rw-r--r--gcc/rust/hir/tree/rust-hir-stmt.h14
-rw-r--r--gcc/rust/hir/tree/rust-hir-type.h19
-rw-r--r--gcc/rust/hir/tree/rust-hir.h5
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc21
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-stmt.cc6
14 files changed, 107 insertions, 64 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 45edd47..a27ba5c 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1633,7 +1633,7 @@ CompileExpr::visit (HIR::CallExpr &expr)
return true;
};
- auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx);
+ auto fn_address = CompileExpr::Compile (expr.get_fnexpr ().get (), ctx);
// is this a closure call?
bool possible_trait_call
@@ -2227,7 +2227,8 @@ CompileExpr::array_copied_expr (Location expr_locus,
}
ctx->push_const_context ();
- tree capacity_expr = CompileExpr::Compile (elems.get_num_copies_expr (), ctx);
+ tree capacity_expr
+ = CompileExpr::Compile (elems.get_num_copies_expr ().get (), ctx);
ctx->pop_const_context ();
if (!TREE_CONSTANT (capacity_expr))
@@ -2237,7 +2238,8 @@ CompileExpr::array_copied_expr (Location expr_locus,
}
// get the compiled value
- tree translated_expr = CompileExpr::Compile (elems.get_elem_to_copy (), ctx);
+ tree translated_expr
+ = CompileExpr::Compile (elems.get_elem_to_copy ().get (), ctx);
tree max_domain = TYPE_MAX_VALUE (domain);
tree min_domain = TYPE_MIN_VALUE (domain);
@@ -2893,7 +2895,7 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
}
// need to apply any autoderef's to the self argument
- HIR::Expr *fnexpr = expr.get_fnexpr ();
+ HIR::Expr *fnexpr = expr.get_fnexpr ().get ();
HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid ();
std::vector<Resolver::Adjustment> *adjustments = nullptr;
bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id,
diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc
index 5bb7b8d..37391fd 100644
--- a/gcc/rust/backend/rust-compile-stmt.cc
+++ b/gcc/rust/backend/rust-compile-stmt.cc
@@ -38,7 +38,7 @@ CompileStmt::Compile (HIR::Stmt *stmt, Context *ctx)
void
CompileStmt::visit (HIR::ExprStmt &stmt)
{
- translated = CompileExpr::Compile (stmt.get_expr (), ctx);
+ translated = CompileExpr::Compile (stmt.get_expr ().get (), ctx);
}
void
@@ -60,7 +60,7 @@ CompileStmt::visit (HIR::LetStmt &stmt)
return;
}
- tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx);
+ tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx);
// FIXME use error_mark_node, check that CompileExpr returns error_mark_node
// on failure and make this an assertion
if (init == nullptr)
diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
index ac7d4e9..c7dde6b 100644
--- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
@@ -493,9 +493,8 @@ PrivacyReporter::visit (HIR::RangeToInclExpr &)
void
PrivacyReporter::visit (HIR::ReturnExpr &expr)
{
- auto return_expr = expr.get_expr ();
- if (return_expr)
- return_expr->accept_vis (*this);
+ if (expr.get_expr ())
+ expr.get_expr ()->accept_vis (*this);
}
void
@@ -707,13 +706,11 @@ PrivacyReporter::visit (HIR::EmptyStmt &)
void
PrivacyReporter::visit (HIR::LetStmt &stmt)
{
- auto type = stmt.get_type ();
- if (type)
- check_type_privacy (type);
+ if (stmt.get_type ())
+ check_type_privacy (stmt.get_type ().get ());
- auto init_expr = stmt.get_init_expr ();
- if (init_expr)
- init_expr->accept_vis (*this);
+ if (stmt.get_init_expr ())
+ stmt.get_init_expr ()->accept_vis (*this);
}
void
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index b8a7889..2ff69be 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -346,11 +346,10 @@ ConstChecker::check_function_call (HirId fn_id, Location locus)
void
ConstChecker::visit (CallExpr &expr)
{
- auto fn = expr.get_fnexpr ();
- if (!fn)
+ if (!expr.get_fnexpr ())
return;
- NodeId ast_node_id = fn->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
NodeId ref_node_id;
HirId definition_id;
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 1866ab7..12c9e86 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -407,11 +407,10 @@ UnsafeChecker::visit (StructExprStructBase &)
void
UnsafeChecker::visit (CallExpr &expr)
{
- auto fn = expr.get_fnexpr ();
- if (!fn)
+ if (!expr.get_fnexpr ())
return;
- NodeId ast_node_id = fn->get_mappings ().get_nodeid ();
+ NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid ();
NodeId ref_node_id;
HirId definition_id;
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index f421f2d..d7a6521 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -622,13 +622,11 @@ Dump::visit (LetStmt &let_stmt)
indentation.increment ();
stream << indentation;
- auto var_pattern = let_stmt.get_pattern ();
- stream << var_pattern->as_string ();
+ stream << let_stmt.get_pattern ()->as_string ();
// return type
if (let_stmt.has_type ())
{
- auto ret_type = let_stmt.get_type ();
- stream << ": " << ret_type->as_string ();
+ stream << ": " << let_stmt.get_type ()->as_string ();
}
// init expr
@@ -637,8 +635,7 @@ Dump::visit (LetStmt &let_stmt)
stream << " = Expr: {\n ";
indentation.increment ();
stream << indentation;
- auto expr = let_stmt.get_init_expr ();
- expr->accept_vis (*this);
+ let_stmt.get_init_expr ()->accept_vis (*this);
stream << "\n";
stream << indentation << "}\n";
indentation.decrement ();
@@ -651,8 +648,7 @@ Dump::visit (LetStmt &let_stmt)
void
Dump::visit (ExprStmt &expr_stmt)
{
- auto expr = expr_stmt.get_expr ();
- expr->accept_vis (*this);
+ expr_stmt.get_expr ()->accept_vis (*this);
}
void
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 3b66230..78b1e83 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -204,6 +204,8 @@ public:
Mutability get_mut () const { return mut; }
bool is_mut () const { return mut == Mutability::Mut; }
+ bool is_double_borrow () const { return double_borrow; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -594,6 +596,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
+ // FIXME: isn't it the same as get_expr() from parent?
std::unique_ptr<Expr> &get_casted_expr ()
{
rust_assert (main_or_left_expr != nullptr);
@@ -962,9 +965,9 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
- Expr *get_elem_to_copy () { return elem_to_copy.get (); }
+ std::unique_ptr<Expr> &get_elem_to_copy () { return elem_to_copy; }
- Expr *get_num_copies_expr () { return num_copies.get (); }
+ std::unique_ptr<Expr> &get_num_copies_expr () { return num_copies; }
ArrayElems::ArrayExprType get_array_expr_type () const override final
{
@@ -1650,6 +1653,8 @@ public:
return fields;
};
+ StructBase *get_struct_base () { return struct_base; }
+
void set_fields_as_owner (
std::vector<std::unique_ptr<StructExprField> > new_fields)
{
@@ -1771,7 +1776,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- Expr *get_fnexpr () { return function.get (); }
+ std::unique_ptr<Expr> &get_fnexpr () { return function; }
size_t num_params () const { return params.size (); }
@@ -1863,6 +1868,7 @@ public:
PathExprSegment &get_method_name () { return method_name; };
const PathExprSegment &get_method_name () const { return method_name; };
+ bool has_params () const { return !params.empty (); }
size_t num_params () const { return params.size (); }
std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; }
@@ -2120,6 +2126,7 @@ public:
};
std::unique_ptr<Expr> &get_expr () { return expr; }
+ bool has_params () const { return !params.empty (); }
std::vector<ClosureParam> &get_params () { return params; }
void accept_vis (HIRFullVisitor &vis) override;
@@ -2154,6 +2161,8 @@ public:
std::string as_string () const override;
+ AST::AttrVec get_inner_attrs () const { return inner_attrs; }
+
// Returns whether the block contains statements.
bool has_statements () const { return !statements.empty (); }
@@ -2772,7 +2781,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- Expr *get_expr () { return return_expr.get (); }
+ std::unique_ptr<Expr> &get_expr () { return return_expr; }
ExprType get_expression_type () const override final
{
@@ -3096,6 +3105,10 @@ public:
void accept_vis (HIRExpressionVisitor &vis) override;
std::unique_ptr<Expr> &get_cond () { return condition; }
+ std::vector<std::unique_ptr<Pattern> > &get_patterns ()
+ {
+ return match_arm_patterns;
+ }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -3162,6 +3175,7 @@ public:
void accept_vis (HIRExpressionVisitor &vis) override;
std::unique_ptr<Expr> &get_iterator_expr () { return iterator_expr; }
+ std::unique_ptr<Pattern> &get_pattern () { return pattern; };
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -3406,7 +3420,7 @@ public:
return match_arm_patterns;
}
- BlockExpr *get_if_block () { return if_block.get (); }
+ std::unique_ptr<BlockExpr> &get_if_block () { return if_block; }
ExprType get_expression_type () const final override
{
@@ -3479,7 +3493,7 @@ public:
void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); }
- ExprWithBlock *get_else_block () { return else_block.get (); }
+ std::unique_ptr<ExprWithBlock> &get_else_block () { return else_block; }
protected:
/* Use covariance to implement clone function as returning this object rather
@@ -3693,7 +3707,7 @@ public:
rust_assert (branch_value != nullptr);
return branch_value;
}
-
+ AST::AttrVec get_inner_attrs () const { return inner_attrs; }
const std::vector<MatchCase> &get_match_cases () const { return match_arms; }
std::vector<MatchCase> &get_match_cases () { return match_arms; }
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 5b8d92c8..22d76ce 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -715,6 +715,7 @@ public:
void accept_vis (HIRStmtVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
+ Identifier get_module_name () const { return module_name; }
std::vector<std::unique_ptr<Item>> &get_items () { return items; };
/* Override that runs the function recursively on all items contained within
@@ -776,6 +777,8 @@ public:
Location get_locus () const override final { return locus; }
ItemKind get_item_kind () const override { return ItemKind::ExternCrate; }
+ std::string get_referenced_crate () { return referenced_crate; }
+ std::string get_as_clause_name () { return as_clause_name; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
@@ -860,6 +863,9 @@ public:
* PATH_PREFIXED. */
bool has_path () const { return !path.is_empty (); }
+ PathType get_glob_type () { return glob_type; }
+ AST::SimplePath get_path () { return path; };
+
std::string as_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
@@ -945,6 +951,10 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
+ PathType get_path_type () { return path_type; }
+ AST::SimplePath get_path () { return path; }
+ std::vector<std::unique_ptr<UseTree>> &get_trees () { return trees; }
+
// TODO: find way to ensure only PATH_PREFIXED path_type has path - factory
// methods?
protected:
@@ -2495,11 +2505,7 @@ public:
std::unique_ptr<Type> &get_type () { return type; }
- std::unique_ptr<Expr> &get_expr ()
- {
- rust_assert (has_expr ());
- return expr;
- }
+ std::unique_ptr<Expr> &get_expr () { return expr; }
const std::string trait_identifier () const override final
{
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h
index 7dfae3f..92be53a 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -131,6 +131,8 @@ public:
Location get_locus () const override { return locus; }
bool is_mut () const { return mut == Mutability::Mut; }
+ bool get_is_ref () const { return is_ref; }
+ std::unique_ptr<Pattern> &get_to_bind () { return to_bind; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRPatternVisitor &vis) override;
@@ -248,6 +250,7 @@ public:
Location get_locus () const { return locus; }
Literal get_literal () const { return literal; }
+ bool get_has_minus () const { return has_minus; }
void accept_vis (HIRFullVisitor &vis) override;
@@ -390,6 +393,8 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRPatternVisitor &vis) override;
+ bool get_has_ellipsis_syntax () { return has_ellipsis_syntax; };
+
Analysis::NodeMapping get_pattern_mappings () const override final
{
return mappings;
@@ -524,6 +529,7 @@ public:
Location get_locus () const { return locus; }
Analysis::NodeMapping get_mappings () const { return mappings; };
+ AST::AttrVec get_outer_attrs () { return outer_attrs; }
protected:
StructPatternField (Analysis::NodeMapping mappings,
@@ -577,6 +583,9 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
+ TupleIndex get_index () { return index; }
+ std::unique_ptr<Pattern> &get_tuple_pattern () { return tuple_pattern; }
+
ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; }
protected:
@@ -666,7 +675,7 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
ItemType get_item_type () const override final { return ItemType::IDENT; }
-
+ bool get_has_ref () const { return has_ref; }
Identifier get_identifier () const { return ident; };
protected:
diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h
index 9d38b03..1446489 100644
--- a/gcc/rust/hir/tree/rust-hir-stmt.h
+++ b/gcc/rust/hir/tree/rust-hir-stmt.h
@@ -138,11 +138,17 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
- HIR::Type *get_type () { return type.get (); }
+ const std::vector<AST::Attribute> &get_outer_attrs () const
+ {
+ return outer_attrs;
+ }
+ std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
+
+ std::unique_ptr<HIR::Type> &get_type () { return type; }
- HIR::Expr *get_init_expr () { return init_expr.get (); }
+ std::unique_ptr<HIR::Expr> &get_init_expr () { return init_expr; }
- HIR::Pattern *get_pattern () { return variables_pattern.get (); }
+ std::unique_ptr<HIR::Pattern> &get_pattern () { return variables_pattern; }
bool is_item () const override final { return false; }
@@ -180,7 +186,7 @@ public:
bool is_item () const override final { return false; }
- Expr *get_expr () { return expr.get (); }
+ std::unique_ptr<Expr> &get_expr () { return expr; }
// Copy constructor with clone
ExprStmt (ExprStmt const &other)
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index 8f09896..3294146 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -64,6 +64,10 @@ public:
return mappings;
}
+ std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
+ bool get_in_parens () { return in_parens; }
+ bool get_opening_question_mark () { return opening_question_mark; }
+
BoundType get_bound_type () const final override { return TRAITBOUND; }
TypePath &get_path () { return type_path; }
@@ -131,7 +135,10 @@ public:
ImplTraitType &operator= (ImplTraitType &&other) = default;
std::string as_string () const override;
-
+ std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
+ {
+ return type_param_bounds;
+ }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
};
@@ -186,7 +193,7 @@ public:
TraitObjectType &operator= (TraitObjectType &&other) = default;
std::string as_string () const override;
-
+ bool get_has_dyn () { return has_dyn; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
@@ -263,7 +270,7 @@ public:
* parenthesised type, it must be in parentheses. */
return type_in_parens->to_trait_bound (true);
}
-
+ std::unique_ptr<Type> &get_type_in_parens () { return type_in_parens; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
};
@@ -295,7 +302,7 @@ public:
{}
std::string as_string () const override;
-
+ TraitBound &get_trait_bound () { return trait_bound; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
};
@@ -811,6 +818,10 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
+ std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
+ bool get_is_variadic () { return is_variadic; }
+ FunctionQualifiers &get_function_qualifiers () { return function_qualifiers; }
+
std::vector<MaybeNamedParam> &get_function_params () { return params; }
const std::vector<MaybeNamedParam> &get_function_params () const
{
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 8a720a1..02ac627 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -260,7 +260,7 @@ protected:
class ExprWithoutBlock;
// Base expression HIR node - abstract
-class Expr : public Node, public FullVisitable
+class Expr : public Node, virtual public FullVisitable
{
public:
using FullVisitable::accept_vis;
@@ -383,7 +383,7 @@ public:
};
// Pattern base HIR node
-class Pattern : public Node, public FullVisitable
+class Pattern : public Node, virtual public FullVisitable
{
public:
using FullVisitable::accept_vis;
@@ -750,6 +750,7 @@ public:
bool has_default_expression () { return default_expression != nullptr; }
+ std::string get_name () { return name; }
std::unique_ptr<Type> &get_type () { return type; }
std::unique_ptr<Expr> &get_default_expression ()
{
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 04bda96..41efede 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -155,7 +155,7 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
: expr.get_locus ();
TyTy::BaseType *expr_ty
= expr.has_return_expr ()
- ? TypeCheckExpr::Resolve (expr.get_expr ())
+ ? TypeCheckExpr::Resolve (expr.get_expr ().get ())
: TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
coercion_site (expr.get_mappings ().get_hirid (),
@@ -168,7 +168,8 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr)
void
TypeCheckExpr::visit (HIR::CallExpr &expr)
{
- TyTy::BaseType *function_tyty = TypeCheckExpr::Resolve (expr.get_fnexpr ());
+ TyTy::BaseType *function_tyty
+ = TypeCheckExpr::Resolve (expr.get_fnexpr ().get ());
rust_debug_loc (expr.get_locus (), "resolved_call_expr to: {%s}",
function_tyty->get_name ().c_str ());
@@ -482,7 +483,7 @@ TypeCheckExpr::visit (HIR::IfLetExpr &expr)
expr.get_locus ());
}
- TypeCheckExpr::Resolve (expr.get_if_block ());
+ TypeCheckExpr::Resolve (expr.get_if_block ().get ());
infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ());
}
@@ -504,8 +505,9 @@ TypeCheckExpr::visit (HIR::IfLetExprConseqElse &expr)
expr.get_locus ());
}
- auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ());
- auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_else_block ());
+ auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ().get ());
+ auto else_blk_resolved
+ = TypeCheckExpr::Resolve (expr.get_else_block ().get ());
if (if_blk_resolved->get_kind () == TyTy::NEVER)
infered = else_blk_resolved;
@@ -886,10 +888,11 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
case HIR::ArrayElems::ArrayExprType::COPIED: {
HIR::ArrayElemsCopied &elems
= static_cast<HIR::ArrayElemsCopied &> (elements);
- element_type = TypeCheckExpr::Resolve (elems.get_elem_to_copy ());
+ element_type
+ = TypeCheckExpr::Resolve (elems.get_elem_to_copy ().get ());
auto capacity_type
- = TypeCheckExpr::Resolve (elems.get_num_copies_expr ());
+ = TypeCheckExpr::Resolve (elems.get_num_copies_expr ().get ());
TyTy::BaseType *expected_ty = nullptr;
bool ok = context->lookup_builtin ("usize", &expected_ty);
@@ -903,7 +906,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr)
elems.get_num_copies_expr ()->get_locus ()),
expr.get_locus ());
- capacity_expr = elems.get_num_copies_expr ();
+ capacity_expr = elems.get_num_copies_expr ().get ();
}
break;
@@ -1910,7 +1913,7 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
// store the adjustments for code-generation to know what to do which must be
// stored onto the receiver to so as we don't trigger duplicate deref mappings
// ICE when an argument is a method call
- HIR::Expr *fnexpr = expr.get_fnexpr ();
+ HIR::Expr *fnexpr = expr.get_fnexpr ().get ();
HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid ();
context->insert_autoderef_mappings (autoderef_mappings_id,
std::move (candidate.adjustments));
diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
index f6af332..5a60380 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
@@ -38,7 +38,7 @@ TypeCheckStmt::Resolve (HIR::Stmt *stmt)
void
TypeCheckStmt::visit (HIR::ExprStmt &stmt)
{
- infered = TypeCheckExpr::Resolve (stmt.get_expr ());
+ infered = TypeCheckExpr::Resolve (stmt.get_expr ().get ());
}
void
@@ -82,7 +82,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
if (stmt.has_init_expr ())
{
init_expr_locus = stmt.get_init_expr ()->get_locus ();
- init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ());
+ init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ().get ());
if (init_expr_ty->get_kind () == TyTy::TypeKind::ERROR)
return;
@@ -94,7 +94,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
Location specified_ty_locus;
if (stmt.has_type ())
{
- specified_ty = TypeCheckType::Resolve (stmt.get_type ());
+ specified_ty = TypeCheckType::Resolve (stmt.get_type ().get ());
specified_ty_locus = stmt.get_type ()->get_locus ();
}