aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree/rust-hir.cc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-10-15 15:22:56 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:32:57 +0100
commit417f4bd3e0bb82e74664417a6c9a7a878e4df462 (patch)
treebc19e9c0131237710c05338da6996e545a50fb6c /gcc/rust/hir/tree/rust-hir.cc
parentd123f43e42f623dfd7dbe63f484197a99ea7f9ed (diff)
downloadgcc-417f4bd3e0bb82e74664417a6c9a7a878e4df462.zip
gcc-417f4bd3e0bb82e74664417a6c9a7a878e4df462.tar.gz
gcc-417f4bd3e0bb82e74664417a6c9a7a878e4df462.tar.bz2
gccrs: Refactor hir to avoid raw pointers and unneeded fwd
Refactor the hir tree files to remove raw pointer usage and most forward declarations. Move implementation out of headers and split headers into smaller and more manageable units. gcc/rust/ChangeLog: * Make-lang.in: Add new files. * hir/tree/rust-hir-item.h: Move Item definition and remove implementations to their corresponding cc file. * hir/tree/rust-hir-expr.h: Move implementation to the corresponding cc file. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * hir/tree/rust-hir.h: Likewise. * hir/tree/rust-hir.cc (Crate::Crate): Add implementations from Crate and remove ConstGenericParam implementations to move them to their own file. * hir/tree/rust-hir-attrs.h: New file. * hir/tree/rust-hir-bound-abstract.h: New file. * hir/tree/rust-hir-bound.h: New file. * hir/tree/rust-hir-expr-abstract.h: New file. * hir/tree/rust-hir-expr.cc: New file. * hir/tree/rust-hir-generic-param.cc: New file. * hir/tree/rust-hir-generic-param.h: New file. * hir/tree/rust-hir-item.cc: New file. * hir/tree/rust-hir-literal.h: New file. * hir/tree/rust-hir-node.h: New file. * hir/tree/rust-hir-path.cc: New file. * hir/tree/rust-hir-pattern-abstract.h: New file. * hir/tree/rust-hir-simple-path.h: New file. * hir/tree/rust-hir-stmt.cc: New file. * hir/tree/rust-hir-trait-bound.h: New file. * hir/tree/rust-hir-type-abstract.cc: New file. * hir/tree/rust-hir-type-abstract.h: New file. * hir/tree/rust-hir-type-no-bounds.h: New file. * hir/tree/rust-hir-type.cc: New file. * hir/tree/rust-hir-visibility.h: New file. * hir/tree/rust-hir-visitable.h: New file. * checks/lints/rust-lint-marklive.h: Use References. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Reformat vectors. * hir/rust-hir-dump.cc (Dump::visit): Use reference. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Use references. * typecheck/rust-tyty-bounds.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/hir/tree/rust-hir.cc')
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc56
1 files changed, 37 insertions, 19 deletions
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index 9de881f..ea09111 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -70,6 +70,33 @@ get_string_in_delims (std::string str_input, AST::DelimType delim_type)
rust_unreachable ();
}
+Crate::Crate (std::vector<std::unique_ptr<Item>> items,
+ AST::AttrVec inner_attrs, Analysis::NodeMapping mappings)
+ : WithInnerAttrs (std::move (inner_attrs)), items (std::move (items)),
+ mappings (mappings)
+{}
+
+Crate::Crate (Crate const &other)
+ : WithInnerAttrs (other.inner_attrs), mappings (other.mappings)
+{
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+}
+
+Crate &
+Crate::operator= (Crate const &other)
+{
+ inner_attrs = other.inner_attrs;
+ mappings = other.mappings;
+
+ items.reserve (other.items.size ());
+ for (const auto &e : other.items)
+ items.push_back (e->clone_item ());
+
+ return *this;
+}
+
std::string
Crate::as_string () const
{
@@ -2677,14 +2704,14 @@ Expr::as_string () const
}
// hopefully definition here will prevent circular dependency issue
-TraitBound *
+std::unique_ptr<TraitBound>
TypePath::to_trait_bound (bool in_parens) const
{
// create clone FIXME is this required? or is copy constructor automatically
// called?
TypePath copy (*this);
- return new TraitBound (mappings, std::move (copy), copy.get_locus (),
- in_parens);
+ return Rust::make_unique<TraitBound> (mappings, std::move (copy),
+ copy.get_locus (), in_parens);
}
std::string
@@ -3012,7 +3039,7 @@ StructExprStructFields::as_string () const
}
else
{
- str += struct_base->as_string ();
+ str += (*struct_base)->as_string ();
}
return str;
@@ -3995,6 +4022,12 @@ StructExprStructBase::accept_vis (HIRFullVisitor &vis)
}
void
+StructExprStructBase::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
CallExpr::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -5152,20 +5185,5 @@ StaticItem::accept_vis (HIRVisItemVisitor &vis)
vis.visit (*this);
}
-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