aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-hir-dump.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/hir/rust-hir-dump.cc')
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc151
1 files changed, 76 insertions, 75 deletions
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index b441377..89fcc3d 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -22,9 +22,9 @@
#include "rust-hir-path.h"
#include "rust-hir-type.h"
#include "rust-hir.h"
-#include <string>
#include "rust-attribute-values.h"
#include "tree/rust-hir-expr.h"
+#include "rust-system.h"
namespace Rust {
namespace HIR {
@@ -315,6 +315,14 @@ Dump::do_functionparam (FunctionParam &e)
void
Dump::do_pathpattern (PathPattern &e)
{
+ if (e.get_path_kind () == PathPattern::Kind::LangItem)
+ {
+ put_field ("segments", "#[lang = \""
+ + LangItem::ToString (e.get_lang_item ())
+ + "\"]");
+ return;
+ }
+
std::string str = "";
for (const auto &segment : e.get_segments ())
@@ -359,7 +367,8 @@ Dump::do_matcharm (MatchArm &e)
// FIXME Can't remember how to handle that. Let's see later.
// do_outer_attrs(e);
visit_collection ("match_arm_patterns", e.get_patterns ());
- visit_field ("guard_expr", e.get_guard_expr ());
+ if (e.has_match_arm_guard ())
+ visit_field ("guard_expr", e.get_guard_expr ());
end ("MatchArm");
}
@@ -387,7 +396,10 @@ void
Dump::do_typepathsegment (TypePathSegment &e)
{
do_mappings (e.get_mappings ());
- put_field ("ident_segment", e.get_ident_segment ().as_string ());
+ if (e.is_lang_item ())
+ put_field ("ident_segment", LangItem::PrettyString (e.get_lang_item ()));
+ else
+ put_field ("ident_segment", e.get_ident_segment ().as_string ());
}
void
@@ -401,9 +413,13 @@ void
Dump::do_qualifiedpathtype (QualifiedPathType &e)
{
do_mappings (e.get_mappings ());
- visit_field ("type", e.get_type ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
+ else
+ put_field ("type", "none");
- visit_field ("trait", e.get_trait ());
+ if (e.has_trait ())
+ visit_field ("trait", e.get_trait ());
}
void
@@ -464,17 +480,6 @@ Dump::do_baseloopexpr (BaseLoopExpr &e)
}
void
-Dump::do_ifletexpr (IfLetExpr &e)
-{
- do_expr (e);
-
- visit_collection ("match_arm_patterns", e.get_patterns ());
-
- visit_field ("value", e.get_scrutinee_expr ());
- visit_field ("if_block", e.get_if_block ());
-}
-
-void
Dump::do_struct (Struct &e)
{
do_vis_item (e);
@@ -531,7 +536,10 @@ Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
else
put_field ("function_params", "empty");
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
+ else
+ put_field ("return_type", "none");
if (e.has_where_clause ())
put_field ("where_clause", e.get_where_clause ().as_string ());
@@ -811,7 +819,7 @@ Dump::visit (QualifiedPathInType &e)
end_field ("path_type");
begin_field ("associated_segment");
- do_typepathsegment (*e.get_associated_segment ());
+ do_typepathsegment (e.get_associated_segment ());
end_field ("associated_segment");
visit_collection ("segments", e.get_segments ());
@@ -922,7 +930,7 @@ Dump::visit (ArithmeticOrLogicalExpr &e)
}
put_field ("expr_type", str);
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("ArithmeticOrLogicalExpr");
}
@@ -957,7 +965,7 @@ Dump::visit (ComparisonExpr &e)
}
put_field ("expr_type", str);
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("ComparisonExpr");
}
@@ -980,7 +988,7 @@ Dump::visit (LazyBooleanExpr &e)
}
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("LazyBooleanExpr");
}
@@ -998,7 +1006,7 @@ Dump::visit (AssignmentExpr &e)
{
begin ("AssignmentExpr");
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
end ("AssignmentExpr");
}
@@ -1008,7 +1016,7 @@ Dump::visit (CompoundAssignmentExpr &e)
begin ("CompoundAssignmentExpr");
do_operatorexpr (e);
- visit_field ("right_expr", *e.get_rhs ());
+ visit_field ("right_expr", e.get_rhs ());
std::string str;
@@ -1182,7 +1190,7 @@ Dump::visit (StructExprStructFields &e)
if (!e.has_struct_base ())
put_field ("struct_base", "none");
else
- put_field ("struct_base", e.get_struct_base ()->as_string ());
+ put_field ("struct_base", e.get_struct_base ().as_string ());
end ("StructExprStructFields");
}
@@ -1193,7 +1201,7 @@ Dump::visit (StructExprStructBase &e)
begin ("StructExprStructBase");
do_structexprstruct (e);
- put_field ("struct_base", e.get_struct_base ()->as_string ());
+ put_field ("struct_base", e.get_struct_base ().as_string ());
end ("StructExprStructBase");
}
@@ -1252,13 +1260,17 @@ Dump::visit (ClosureExpr &e)
auto oa = param.get_outer_attrs ();
do_outer_attrs (oa);
visit_field ("pattern", param.get_pattern ());
- visit_field ("type", param.get_type ());
+
+ if (param.has_type_given ())
+ visit_field ("type", param.get_type ());
+
end ("ClosureParam");
}
end_field ("params");
}
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
visit_field ("expr", e.get_expr ());
end ("ClosureExpr");
@@ -1275,7 +1287,8 @@ Dump::visit (BlockExpr &e)
visit_collection ("statements", e.get_statements ());
- visit_field ("expr", e.get_final_expr ());
+ if (e.has_final_expr ())
+ visit_field ("expr", e.get_final_expr ());
end ("BlockExpr");
}
@@ -1304,7 +1317,10 @@ Dump::visit (BreakExpr &e)
else
put_field ("label", "none");
- visit_field ("break_expr ", e.get_expr ());
+ if (e.has_break_expr ())
+ visit_field ("break_expr ", e.get_expr ());
+ else
+ put_field ("break_expr", "none");
end ("BreakExpr");
}
@@ -1374,7 +1390,8 @@ Dump::visit (ReturnExpr &e)
begin ("ReturnExpr");
do_mappings (e.get_mappings ());
- visit_field ("return_expr", e.get_expr ());
+ if (e.has_return_expr ())
+ visit_field ("return_expr", e.get_expr ());
end ("ReturnExpr");
}
@@ -1442,23 +1459,6 @@ Dump::visit (IfExprConseqElse &e)
}
void
-Dump::visit (IfLetExpr &e)
-{
- begin ("IfLetExpr");
- do_ifletexpr (e);
- end ("IfLetExpr");
-}
-
-void
-Dump::visit (IfLetExprConseqElse &e)
-{
- begin ("IfLetExprConseqElse");
- do_ifletexpr (e);
- visit_field ("else_block", e.get_else_block ());
- end ("IfLetExprConseqElse");
-}
-
-void
Dump::visit (MatchExpr &e)
{
begin ("MatchExpr");
@@ -1517,7 +1517,8 @@ Dump::visit (TypeParam &e)
visit_collection ("type_param_bounds", e.get_type_param_bounds ());
- visit_field ("type", e.get_type ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
end ("TypeParam");
}
@@ -1683,7 +1684,8 @@ Dump::visit (Function &e)
put_field ("function_params", "empty");
}
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_function_return_type ())
+ visit_field ("return_type", e.get_return_type ());
if (!e.has_where_clause ())
put_field ("where_clause", "none");
@@ -1712,7 +1714,7 @@ Dump::visit (TypeAlias &e)
else
put_field ("where clause", e.get_where_clause ().as_string ());
- put_field ("type", e.get_type_aliased ()->as_string ());
+ put_field ("type", e.get_type_aliased ().as_string ());
end ("TypeAlias");
}
@@ -1916,7 +1918,8 @@ Dump::visit (TraitItemFunc &e)
do_traitfunctiondecl (e.get_decl ());
- visit_field ("block_expr", e.get_block_expr ());
+ if (e.has_definition ())
+ visit_field ("block_expr", e.get_block_expr ());
end ("TraitItemFunc");
}
@@ -1929,7 +1932,9 @@ Dump::visit (TraitItemConst &e)
put_field ("name", e.get_name ().as_string ());
visit_field ("type", e.get_type ());
- visit_field ("expr", e.get_expr ());
+ if (e.has_expr ())
+ visit_field ("expr", e.get_expr ());
+
end ("TraitItemConst");
}
@@ -2031,7 +2036,8 @@ Dump::visit (ExternalFunctionItem &e)
put_field ("has_variadics", std::to_string (e.is_variadic ()));
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
end ("ExternalFunctionItem");
}
@@ -2078,7 +2084,7 @@ Dump::visit (IdentifierPattern &e)
put_field ("mut", std::to_string (e.is_mut ()));
if (e.has_pattern_to_bind ())
- put_field ("to_bind", e.get_to_bind ()->as_string ());
+ put_field ("to_bind", e.get_to_bind ().as_string ());
else
put_field ("to_bind", "none");
@@ -2122,8 +2128,8 @@ Dump::visit (RangePattern &e)
{
begin ("RangePattern");
do_mappings (e.get_mappings ());
- put_field ("lower", e.get_lower_bound ()->as_string ());
- put_field ("upper", e.get_upper_bound ()->as_string ());
+ put_field ("lower", e.get_lower_bound ().as_string ());
+ put_field ("upper", e.get_upper_bound ().as_string ());
put_field ("has_ellipsis_syntax",
std::to_string (e.get_has_ellipsis_syntax ()));
end ("RangePattern");
@@ -2135,7 +2141,7 @@ Dump::visit (ReferencePattern &e)
begin ("ReferencePattern");
do_mappings (e.get_mappings ());
put_field ("mut", std::to_string (e.is_mut ()));
- put_field ("pattern", e.get_referenced_pattern ()->as_string ());
+ put_field ("pattern", e.get_referenced_pattern ().as_string ());
end ("ReferencePattern");
}
@@ -2147,7 +2153,7 @@ Dump::visit (StructPatternFieldTuplePat &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
put_field ("index", std::to_string (e.get_index ()));
- put_field ("tuple_pattern", e.get_tuple_pattern ()->as_string ());
+ put_field ("tuple_pattern", e.get_tuple_pattern ().as_string ());
end ("StructPatternFieldTuplePat");
}
@@ -2158,7 +2164,7 @@ Dump::visit (StructPatternFieldIdentPat &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
put_field ("ident", e.get_identifier ().as_string ());
- put_field ("ident_pattern", e.get_pattern ()->as_string ());
+ put_field ("ident_pattern", e.get_pattern ().as_string ());
end ("StructPatternFieldIdentPat");
}
@@ -2276,10 +2282,12 @@ Dump::visit (LetStmt &e)
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
- put_field ("variable_pattern", e.get_pattern ()->as_string ());
+ put_field ("variable_pattern", e.get_pattern ().as_string ());
- visit_field ("type", e.get_type ());
- visit_field ("init_expr", e.get_init_expr ());
+ if (e.has_type ())
+ visit_field ("type", e.get_type ());
+ if (e.has_init_expr ())
+ visit_field ("init_expr", e.get_init_expr ());
end ("LetStmt");
}
@@ -2337,20 +2345,11 @@ Dump::visit (ParenthesisedType &e)
{
begin ("ParenthesisedType");
do_type (e);
- put_field ("type_in_parens", e.get_type_in_parens ()->as_string ());
+ put_field ("type_in_parens", e.get_type_in_parens ().as_string ());
end ("ParenthesisedType");
}
void
-Dump::visit (ImplTraitTypeOneBound &e)
-{
- begin ("ImplTraitTypeOneBound");
- do_type (e);
- visit_field ("trait_bound", e.get_trait_bound ());
- end ("ImplTraitTypeOneBound");
-}
-
-void
Dump::visit (TupleType &e)
{
begin ("TupleType");
@@ -2373,7 +2372,7 @@ Dump::visit (RawPointerType &e)
begin ("RawPointerType");
do_type (e);
put_field ("mut", Rust::enum_to_str (e.get_mut ()));
- put_field ("type", e.get_type ()->as_string ());
+ put_field ("type", e.get_type ().as_string ());
end ("RawPointerType");
}
@@ -2384,7 +2383,7 @@ Dump::visit (ReferenceType &e)
do_type (e);
put_field ("lifetime", e.get_lifetime ().as_string ());
put_field ("mut", enum_to_str (e.get_mut ()));
- put_field ("type", e.get_base_type ()->as_string ());
+ put_field ("type", e.get_base_type ().as_string ());
end ("ReferenceType");
}
@@ -2441,7 +2440,9 @@ Dump::visit (BareFunctionType &e)
end_field ("params");
}
- visit_field ("return_type", e.get_return_type ());
+ if (e.has_return_type ())
+ visit_field ("return_type", e.get_return_type ());
+
put_field ("is_variadic", std::to_string (e.get_is_variadic ()));
end ("BareFunctionType");
}