aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree/rust-hir.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir/tree/rust-hir.cc')
-rw-r--r--gcc/rust/hir/tree/rust-hir.cc147
1 files changed, 46 insertions, 101 deletions
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index f05e506..822eaff 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -19,6 +19,7 @@
#include "rust-ast-full.h"
#include "rust-hir-expr.h"
#include "rust-hir-full.h"
+#include "rust-hir-path.h"
#include "rust-hir-visitor.h"
#include "rust-diagnostics.h"
@@ -70,6 +71,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
{
@@ -1183,6 +1211,9 @@ ClosureExpr::as_string () const
std::string
PathPattern::as_string () const
{
+ if (is_lang_item ())
+ return LangItem::PrettyString (*lang_item);
+
std::string str;
for (const auto &segment : segments)
@@ -1572,41 +1603,6 @@ IfExprConseqElse::as_string () const
}
std::string
-IfLetExpr::as_string () const
-{
- std::string str ("IfLetExpr: ");
-
- str += "\n Condition match arm patterns: ";
- if (match_arm_patterns.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto &pattern : match_arm_patterns)
- {
- str += "\n " + pattern->as_string ();
- }
- }
-
- str += "\n Scrutinee expr: " + value->as_string ();
-
- str += "\n If let block expr: " + if_block->as_string ();
-
- return str;
-}
-
-std::string
-IfLetExprConseqElse::as_string () const
-{
- std::string str = IfLetExpr::as_string ();
-
- str += "\n Else expr: " + else_block->as_string ();
-
- return str;
-}
-
-std::string
RangeFromToInclExpr::as_string () const
{
return from->as_string () + "..=" + to->as_string ();
@@ -2186,7 +2182,7 @@ TypeParam::as_string () const
}
else
{
- str += type->as_string ();
+ str += type.value ()->as_string ();
}
return str;
@@ -2195,6 +2191,8 @@ TypeParam::as_string () const
AST::SimplePath
PathPattern::convert_to_simple_path (bool with_opening_scope_resolution) const
{
+ rust_assert (kind == Kind::Segmented);
+
if (!has_segments ())
{
return AST::SimplePath::create_empty ();
@@ -2677,12 +2675,12 @@ LetStmt::as_string () const
if (has_type ())
{
- str += " : " + type->as_string ();
+ str += " : " + get_type ().as_string ();
}
if (has_init_expr ())
{
- str += " = " + init_expr->as_string ();
+ str += " = " + get_init_expr ().as_string ();
}
return str;
@@ -2712,14 +2710,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 std::make_unique<TraitBound> (mappings, std::move (copy),
+ copy.get_locus (), in_parens);
}
std::string
@@ -2868,14 +2866,6 @@ BareFunctionType::as_string () const
}
std::string
-ImplTraitTypeOneBound::as_string () const
-{
- std::string str ("ImplTraitTypeOneBound: \n TraitBound: ");
-
- return str + trait_bound.as_string ();
-}
-
-std::string
TypePathSegmentGeneric::as_string () const
{
return TypePathSegment::as_string () + "<" + generic_args.as_string () + ">";
@@ -3047,7 +3037,7 @@ StructExprStructFields::as_string () const
}
else
{
- str += struct_base->as_string ();
+ str += (*struct_base)->as_string ();
}
return str;
@@ -4030,6 +4020,12 @@ StructExprStructBase::accept_vis (HIRFullVisitor &vis)
}
void
+StructExprStructBase::accept_vis (HIRExpressionVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
CallExpr::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4150,18 +4146,6 @@ IfExprConseqElse::accept_vis (HIRFullVisitor &vis)
}
void
-IfLetExpr::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-IfLetExprConseqElse::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
MatchExpr::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4534,12 +4518,6 @@ ParenthesisedType::accept_vis (HIRFullVisitor &vis)
}
void
-ImplTraitTypeOneBound::accept_vis (HIRFullVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
TupleType::accept_vis (HIRFullVisitor &vis)
{
vis.visit (*this);
@@ -4732,12 +4710,6 @@ ArrayType::accept_vis (HIRTypeVisitor &vis)
}
void
-ImplTraitTypeOneBound::accept_vis (HIRTypeVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
BareFunctionType::accept_vis (HIRTypeVisitor &vis)
{
vis.visit (*this);
@@ -4912,18 +4884,6 @@ RangeFromToInclExpr::accept_vis (HIRExpressionVisitor &vis)
}
void
-IfLetExprConseqElse::accept_vis (HIRExpressionVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
-IfLetExpr::accept_vis (HIRExpressionVisitor &vis)
-{
- vis.visit (*this);
-}
-
-void
IfExprConseqElse::accept_vis (HIRExpressionVisitor &vis)
{
vis.visit (*this);
@@ -5211,20 +5171,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