From f4d78133368ff453eaf60413c697cf848ad1e17e Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 20:49:17 +0100 Subject: ast: Dump slice type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 8e2a8c6..3f5dada 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1606,7 +1606,12 @@ Dump::visit (ArrayType &type) void Dump::visit (SliceType &type) { + // Syntax: + // [ Type ] + + stream << '['; visit (type.get_elem_type ()); + stream << ']'; } void -- cgit v1.1 From 0eaaeb4b3592075fe30d3a8aa57941dd40c6f256 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 20:54:40 +0100 Subject: ast: Dump array type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 3f5dada..273a510 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1600,7 +1600,14 @@ Dump::visit (ReferenceType &type) void Dump::visit (ArrayType &type) { + // Syntax: + // [ Type ; Expression ] + + stream << '['; visit (type.get_elem_type ()); + stream << "; "; + visit(type.get_size_expr()); + stream << ']'; } void -- cgit v1.1 From 20bf6802ba7b964ec1e570dd4fec971fa3d678f6 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 21:21:34 +0100 Subject: ast: Dump raw pointer type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 273a510..e6d6e07 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1588,12 +1588,36 @@ Dump::visit (NeverType &) {} void -Dump::visit (RawPointerType &) -{} +Dump::visit (RawPointerType &type) +{ + // Syntax: + // * ( mut | const ) TypeNoBounds + + if (type.get_pointer_type () == RawPointerType::MUT) + stream << "*mut "; + else /* RawPointerType::CONST */ + stream << "*const "; + + visit (type.get_type_pointed_to ()); +} void Dump::visit (ReferenceType &type) { + // Syntax: + // & Lifetime? mut? TypeNoBounds + + stream << '&'; + + if (type.has_lifetime ()) + { + visit (type.get_lifetime ()); + stream << ' '; + } + + if (type.get_has_mut ()) + stream << "mut "; + visit (type.get_type_referenced ()); } @@ -1606,7 +1630,7 @@ Dump::visit (ArrayType &type) stream << '['; visit (type.get_elem_type ()); stream << "; "; - visit(type.get_size_expr()); + visit (type.get_size_expr ()); stream << ']'; } -- cgit v1.1 From 496ed46e0ab377d89c39ff85c104fd26f8e987bb Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 21:23:12 +0100 Subject: ast: Dump never type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index e6d6e07..3af4895 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1585,7 +1585,12 @@ Dump::visit (TupleType &) void Dump::visit (NeverType &) -{} +{ + // Syntax: + // ! + + stream << '!'; +} void Dump::visit (RawPointerType &type) -- cgit v1.1 From 9b6d82061208796389e064cbe6707a3787a264fe Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 21:27:49 +0100 Subject: ast: Dump tuple type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 3af4895..9393f95 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1580,16 +1580,24 @@ Dump::visit (TraitObjectTypeOneBound &) {} void -Dump::visit (TupleType &) -{} +Dump::visit (TupleType &type) +{ + // Syntax: + // ( ) + // | ( ( Type , )+ Type? ) + + stream << '('; + visit_items_joined_by_separator (type.get_elems (), ", "); + stream << ')'; +} void Dump::visit (NeverType &) { - // Syntax: - // ! + // Syntax: + // ! - stream << '!'; + stream << '!'; } void -- cgit v1.1 From 8c239b1428ee4a36530ecbbd5bf36eb9333e9697 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Sun, 6 Nov 2022 21:29:56 +0100 Subject: ast: Dump inferred type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9393f95..a37d5ad 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1661,6 +1661,9 @@ Dump::visit (SliceType &type) void Dump::visit (InferredType &) { + // Syntax: + // _ + stream << "_"; } -- cgit v1.1 From 0ebbd2a451145cedeaec99e8a31372befecf85f6 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Mon, 7 Nov 2022 17:09:33 +0100 Subject: ast: Dump bare function type + Return FunctionQualifiers as ref to work in ast dump Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 94 +++++++++++++++++++++++++++++++++++++- gcc/rust/ast/rust-ast-dump.h | 2 + gcc/rust/ast/rust-ast-full-test.cc | 2 +- gcc/rust/ast/rust-type.h | 22 ++++++--- 4 files changed, 111 insertions(+), 9 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index a37d5ad..5dae38c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -250,6 +250,56 @@ Dump::visit (std::vector &for_lifetimes) } void +Dump::visit (FunctionQualifiers &qualifiers) +{ + // Syntax: + // `const`? `async`? `unsafe`? (`extern` Abi?)? + // unsafe? (extern Abi?)? + + switch (qualifiers.get_const_status ()) + { + case NONE: + break; + case CONST_FN: + stream << "const "; + break; + case ASYNC_FN: + stream << "async "; + break; + } + + if (qualifiers.is_unsafe ()) + stream << "unsafe "; + if (qualifiers.is_extern ()) + { + stream << "extern "; + if (qualifiers.has_abi ()) + stream << "\"" << qualifiers.get_extern_abi () << "\" "; + } +} // namespace AST + +void +Dump::visit (MaybeNamedParam ¶m) +{ + // Syntax: + // OuterAttribute* ( ( IDENTIFIER | _ ) : )? Type + + visit_items_joined_by_separator (param.get_outer_attrs (), " "); + switch (param.get_param_kind ()) + { + case MaybeNamedParam::UNNAMED: + break; + case MaybeNamedParam::IDENTIFIER: + stream << " " << param.get_name () << ": "; + break; + case MaybeNamedParam::WILDCARD: + stream << " _: "; + break; + } + visit (param.get_type ()); +} + +void Dump::visit (Token &tok) { stream << tok.as_string (); @@ -1668,8 +1718,48 @@ Dump::visit (InferredType &) } void -Dump::visit (BareFunctionType &) -{} +Dump::visit (BareFunctionType &type) +{ + // Syntax: + // ForLifetimes? FunctionTypeQualifiers fn + // ( FunctionParametersMaybeNamedVariadic? ) BareFunctionReturnType? + // + // BareFunctionReturnType: + // -> TypeNoBounds + // + // FunctionParametersMaybeNamedVariadic : + // MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic + // + // MaybeNamedFunctionParameters : + // MaybeNamedParam ( , MaybeNamedParam )* ,? + // + // MaybeNamedFunctionParametersVariadic : + // ( MaybeNamedParam , )* MaybeNamedParam , OuterAttribute* ... + + if (type.has_for_lifetimes ()) + visit (type.get_for_lifetimes ()); + + visit (type.get_function_qualifiers ()); + + stream << "fn ("; + + visit_items_joined_by_separator (type.get_function_params (), ", "); + + if (type.is_variadic ()) + { + stream << ", "; + visit_items_joined_by_separator (type.get_variadic_attr (), " "); + stream << "..."; + } + + stream << ')'; + + if (type.has_return_type ()) + { + stream << " -> "; + visit (type.get_return_type ()); + } +} } // namespace AST } // namespace Rust diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 2bd3b31..6c2f13c 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -137,6 +137,8 @@ private: void visit (MacroRule &rule); void visit (WhereClause &rule); void visit (std::vector &for_lifetimes); + void visit (FunctionQualifiers &qualifiers); + void visit (MaybeNamedParam ¶m); // rust-ast.h void visit (Token &tok); diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 1e8a93d..c4df730 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -3071,7 +3071,7 @@ BareFunctionType::as_string () const } str += "\n Is variadic: "; - if (is_variadic) + if (_is_variadic) str += "true"; else str += "false"; diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 8fc3d31..4d435cf 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -835,7 +835,7 @@ public: }; /* A function pointer type - can be created via coercion from function items and - * non- capturing closures. */ + * non-capturing closures. */ class BareFunctionType : public TypeNoBounds { // bool has_for_lifetimes; @@ -844,7 +844,7 @@ class BareFunctionType : public TypeNoBounds FunctionQualifiers function_qualifiers; std::vector params; - bool is_variadic; + bool _is_variadic; std::vector variadic_attrs; // bool has_return_type; @@ -860,6 +860,16 @@ public: // Whether the function has ForLifetimes. bool has_for_lifetimes () const { return !for_lifetimes.empty (); } + std::vector &get_for_lifetimes () { return for_lifetimes; } + + bool is_variadic () const { return _is_variadic; } + + std::vector &get_variadic_attr () { return variadic_attrs; }; + const std::vector &get_variadic_attr () const + { + return variadic_attrs; + }; + BareFunctionType (std::vector lifetime_params, FunctionQualifiers qualifiers, std::vector named_params, bool is_variadic, @@ -867,7 +877,7 @@ public: std::unique_ptr type, Location locus) : for_lifetimes (std::move (lifetime_params)), function_qualifiers (std::move (qualifiers)), - params (std::move (named_params)), is_variadic (is_variadic), + params (std::move (named_params)), _is_variadic (is_variadic), variadic_attrs (std::move (variadic_attrs)), return_type (std::move (type)), locus (locus) { @@ -879,7 +889,7 @@ public: BareFunctionType (BareFunctionType const &other) : for_lifetimes (other.for_lifetimes), function_qualifiers (other.function_qualifiers), params (other.params), - is_variadic (other.is_variadic), variadic_attrs (other.variadic_attrs), + _is_variadic (other._is_variadic), variadic_attrs (other.variadic_attrs), locus (other.locus) { // guard to prevent null dereference @@ -893,7 +903,7 @@ public: for_lifetimes = other.for_lifetimes; function_qualifiers = other.function_qualifiers; params = other.params; - is_variadic = other.is_variadic; + _is_variadic = other._is_variadic; variadic_attrs = other.variadic_attrs; locus = other.locus; @@ -930,7 +940,7 @@ public: return return_type; } - FunctionQualifiers get_function_qualifiers () { return function_qualifiers; } + FunctionQualifiers &get_function_qualifiers () { return function_qualifiers; } protected: /* Use covariance to implement clone function as returning this object rather -- cgit v1.1 From 6c432d6ca2f767f5afe3006e6aa8d5123e4f4636 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 15:42:08 +0100 Subject: ast: Dump impl trait type one bound Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 5dae38c..2f01c72 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1622,8 +1622,14 @@ Dump::visit (ParenthesisedType &) {} void -Dump::visit (ImplTraitTypeOneBound &) -{} +Dump::visit (ImplTraitTypeOneBound &type) +{ + // Syntax: + // impl TraitBound + + stream << "impl "; + visit (type.get_trait_bound()); +} void Dump::visit (TraitObjectTypeOneBound &) -- cgit v1.1 From 9147e08003b935e312437ec61e83120c8eceb74b Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 15:44:48 +0100 Subject: ast: Dump impl trait type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 2f01c72..1d593d4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1610,8 +1610,16 @@ Dump::visit (TraitBound &bound) } void -Dump::visit (ImplTraitType &) -{} +Dump::visit (ImplTraitType &type) +{ + // Syntax: + // impl TypeParamBounds + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + stream << "impl "; + visit_items_joined_by_separator(type.get_type_param_bounds (), " + "); +} void Dump::visit (TraitObjectType &) -- cgit v1.1 From 0e026b6c33d20a7d1b8714df73e9157ede98af70 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 15:49:05 +0100 Subject: ast: Dump trait object type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 1d593d4..0ae57fd 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1618,12 +1618,21 @@ Dump::visit (ImplTraitType &type) // TypeParamBound ( + TypeParamBound )* +? stream << "impl "; - visit_items_joined_by_separator(type.get_type_param_bounds (), " + "); + visit_items_joined_by_separator (type.get_type_param_bounds (), " + "); } void -Dump::visit (TraitObjectType &) -{} +Dump::visit (TraitObjectType &type) +{ + // Syntax: + // dyn? TypeParamBounds + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + if (type.is_dyn ()) + stream << "dyn "; + visit_items_joined_by_separator (type.get_type_param_bounds (), " + "); +} void Dump::visit (ParenthesisedType &) @@ -1636,7 +1645,7 @@ Dump::visit (ImplTraitTypeOneBound &type) // impl TraitBound stream << "impl "; - visit (type.get_trait_bound()); + visit (type.get_trait_bound ()); } void -- cgit v1.1 From 4c69451b3d46db438a5c2cc436f7b02dbf4bbab2 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 15:52:34 +0100 Subject: ast: Dump parenthesised type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 0ae57fd..8e06bf3 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1635,8 +1635,15 @@ Dump::visit (TraitObjectType &type) } void -Dump::visit (ParenthesisedType &) -{} +Dump::visit (ParenthesisedType &type) +{ + // Syntax: + // ( Type ) + + stream << "("; + visit (type.get_type_in_parens ()); + stream << ")"; +} void Dump::visit (ImplTraitTypeOneBound &type) -- cgit v1.1 From 5c943bf43888f9dd1a5934f678de8b8435f1199a Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 17:02:00 +0100 Subject: ast: Dump trait object type one bound Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 8e06bf3..7d62571 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1656,8 +1656,15 @@ Dump::visit (ImplTraitTypeOneBound &type) } void -Dump::visit (TraitObjectTypeOneBound &) -{} +Dump::visit (TraitObjectTypeOneBound &type) +{ + // Syntax: + // dyn? TraitBound + + if (type.is_dyn ()) + stream << "dyn "; + visit(type.get_trait_bound()); +} void Dump::visit (TupleType &type) -- cgit v1.1 From a3dfe962eb96380d0382dfb5fa243e36591ff6fc Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Tue, 15 Nov 2022 18:39:41 +0100 Subject: ast: Dump type param type Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 7d62571..216f0a4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -892,7 +892,19 @@ Dump::visit (AsyncBlockExpr &) void Dump::visit (TypeParam ¶m) { + // Syntax: + // IDENTIFIER( : TypeParamBounds? )? ( = Type )? + // TypeParamBounds : + // TypeParamBound ( + TypeParamBound )* +? + + // FIXME this outputs things like "Ambiguous: String" - this comes from + // Token::str stream << param.get_type_representation (); + if (param.has_type_param_bounds ()) + { + stream << ": "; + visit_items_joined_by_separator (param.get_type_param_bounds (), " + "); + } if (param.has_type ()) { stream << " = "; @@ -1663,7 +1675,7 @@ Dump::visit (TraitObjectTypeOneBound &type) if (type.is_dyn ()) stream << "dyn "; - visit(type.get_trait_bound()); + visit (type.get_trait_bound ()); } void -- cgit v1.1 From 78df522226ecc92f167f6d177c098847c1267c10 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Wed, 16 Nov 2022 13:58:50 +0100 Subject: ast: Dump generic parameters Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 129 +++++++++++++++++++++++++++++++++++++++--- gcc/rust/ast/rust-ast-dump.h | 3 + 2 files changed, 123 insertions(+), 9 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 216f0a4..03a57d4 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -372,21 +372,134 @@ Dump::visit (PathInExpression &path) } void -Dump::visit (TypePathSegment &) -{} +Dump::visit (TypePathSegment &segment) +{ + // Syntax: + // PathIdentSegment + + stream << segment.get_ident_segment ().as_string (); +} void -Dump::visit (TypePathSegmentGeneric &) -{} +Dump::visit (TypePathSegmentGeneric &segment) +{ + // Syntax: + // PathIdentSegment `::`? (GenericArgs)? + // GenericArgs : + // `<` `>` + // | `<` ( GenericArg `,` )* GenericArg `,`? `>` + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + stream << "<"; + + { + // Here we join 3 lists (each possibly empty) with a separator. + + auto &lifetime_args = segment.get_generic_args ().get_lifetime_args (); + auto &generic_args = segment.get_generic_args ().get_generic_args (); + auto &binding_args = segment.get_generic_args ().get_binding_args (); + + visit_items_joined_by_separator (lifetime_args, ", "); + if (!lifetime_args.empty () + && (!generic_args.empty () || !binding_args.empty ())) + { + // Insert separator if some items have been already emitted and some + // more are to be emitted from any of the following collections. + stream << ", "; + } + visit_items_joined_by_separator (generic_args, ", "); + if (!generic_args.empty () && !binding_args.empty ()) + { + // Insert separator if some item vas emitted from the previous + // collection and more are to be emitted from the last. + stream << ", "; + } + visit_items_joined_by_separator (binding_args, ", "); + } + + stream << ">"; +} void -Dump::visit (TypePathSegmentFunction &) -{} +Dump::visit (GenericArgsBinding &binding) +{ + // Syntax: + // IDENTIFIER `=` Type + + stream << binding.get_identifier () << " << "; + visit (binding.get_type ()); +} + +void +Dump::visit (GenericArg &arg) +{ + // `GenericArg` implements `accept_vis` but it is not useful for this case as + // it ignores unresolved cases (`Kind::Either`). + + switch (arg.get_kind ()) + { + case GenericArg::Kind::Const: + visit (arg.get_expression ()); + break; + case GenericArg::Kind::Type: + visit (arg.get_type ()); + break; + case GenericArg::Kind::Either: + stream << arg.get_path (); + break; + case GenericArg::Kind::Error: + gcc_unreachable (); + } +} // namespace AST + +void +Dump::visit (TypePathSegmentFunction &segment) +{ + // Syntax: + // PathIdentSegment `::`? (TypePathFn)? + + stream << segment.get_ident_segment ().as_string (); + + if (segment.get_separating_scope_resolution ()) + stream << "::"; + + if (!segment.is_ident_only ()) + visit (segment.get_type_path_function ()); +} + +void +Dump::visit (TypePathFunction &type_path_fn) +{ + // Syntax: + // `(` TypePathFnInputs? `)` (`->` Type)? + // TypePathFnInputs : + // Type (`,` Type)* `,`? + + stream << '('; + if (type_path_fn.has_inputs ()) + visit_items_joined_by_separator (type_path_fn.get_params (), ", "); + stream << ')'; + + if (type_path_fn.has_return_type ()) + { + stream << "->"; + visit (type_path_fn.get_return_type ()); + } +} void Dump::visit (TypePath &path) { - stream << path.as_string (); + // Syntax: + // `::`? TypePathSegment (`::` TypePathSegment)* + + if (path.has_opening_scope_resolution_op ()) + stream << "::"; + visit_items_joined_by_separator (path.get_segments (), "::"); } void @@ -897,8 +1010,6 @@ Dump::visit (TypeParam ¶m) // TypeParamBounds : // TypeParamBound ( + TypeParamBound )* +? - // FIXME this outputs things like "Ambiguous: String" - this comes from - // Token::str stream << param.get_type_representation (); if (param.has_type_param_bounds ()) { diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 6c2f13c..4bc322c 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -139,6 +139,9 @@ private: void visit (std::vector &for_lifetimes); void visit (FunctionQualifiers &qualifiers); void visit (MaybeNamedParam ¶m); + void visit (TypePathFunction &type_path_fn); + void visit (GenericArgsBinding &binding); + void visit (GenericArg &arg); // rust-ast.h void visit (Token &tok); -- cgit v1.1 From fc944a02419c633a04390d1c8df0684587f87fb7 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Wed, 16 Nov 2022 13:59:16 +0100 Subject: ast: Remove unused include in rust-ast-dump.cc Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 03a57d4..477805f 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -17,7 +17,6 @@ // . #include "rust-ast-dump.h" -#include "rust-diagnostics.h" namespace Rust { namespace AST { -- cgit v1.1 From b0ec92f7d4b577ff483e3d8992d4ea43f59dbfeb Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Wed, 16 Nov 2022 14:03:07 +0100 Subject: ast: Dump remove /* stmp */ comment to not clutter the dump Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 477805f..9ec847c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -848,7 +848,7 @@ Dump::visit (BlockExpr &expr) stream << "{\n"; indentation.increment (); - visit_items_as_lines (expr.get_statements (), "; /* stmt */"); + visit_items_as_lines (expr.get_statements (), ";"); if (expr.has_tail_expr ()) visit_as_line (expr.get_tail_expr (), " /* tail expr */\n"); @@ -1205,7 +1205,6 @@ Dump::visit (TypeAlias &type_alias) visit (type_alias.get_where_clause ()); stream << " = "; visit (type_alias.get_type_aliased ()); - stream << ";\n"; } void -- cgit v1.1 From 9527e9985890e30c7687c9482b669e3f5338f9fe Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Wed, 16 Nov 2022 14:16:51 +0100 Subject: ast: Dump no comma after self in fn params if it is the last one Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 9ec847c..131e23e 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -1077,8 +1077,12 @@ Dump::visit (Method &method) visit (method.get_visibility ()); stream << "fn " << method.get_method_name () << '('; - stream << method.get_self_param ().as_string () << ", "; - visit_items_joined_by_separator (method.get_function_params (), ", "); + stream << method.get_self_param ().as_string (); + if (!method.get_function_params ().empty ()) + { + stream << ", "; + visit_items_joined_by_separator (method.get_function_params (), ", "); + } stream << ") "; @@ -1343,9 +1347,13 @@ Dump::visit (TraitItemMethod &item) // emit_visibility (method.get_visibility ()); stream << "fn " << method.get_identifier () << '('; - stream << method.get_self_param ().as_string () << ", "; + stream << method.get_self_param ().as_string (); - visit_items_joined_by_separator (method.get_function_params (), ", "); + if (!method.get_function_params ().empty ()) + { + stream << ", "; + visit_items_joined_by_separator (method.get_function_params (), ", "); + } stream << ") "; -- cgit v1.1