From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 8C30A382E69D for ; Tue, 21 Feb 2023 12:04:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C30A382E69D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id c12so4165085wrw.1 for ; Tue, 21 Feb 2023 04:04:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=Ab23yKxHbZ+wd7dUuVAYJgm8UQA5Fm909Cyj5qth6UFHyDJfvGViDLD7X3FiPCsL2D gjwtyd9b2miICMxGIv5RomNgY3uuNfy1Wz5vriXngXsIQbu8QhrhQsOaiBzmlB+Hy5fY stPawowJnbOTck8NqwDzSoh0TzztMmiOpcVk0cbY3Exql0P1Y5D8Yp0OUQ/xd4RWon6v hlg0ZT61yJ6Nw0FUs3Jme+lePueyx04RqudNTPBpc+O28TNpOd0yR59dx0cIUkajtwN3 L9MtVN3J5eaKW6ogXVgdfMch3+DitRFOyrQPesHLaU3L90rgmUzA5vHujNIaVyvga8VG QY7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=80461fre8+hQ0zMopblsV380dH0N+AStk+XMfdir8cY=; b=6vWBjXobJQh0JOWlMOh2hmcVRUh3sQ/VU1EdFrmU+HA3CdxjmNFlAC7J88ml3yb59H TEfGPNfjCOBMkxvnznd7dGo/os4a0QgjdXKliXtdiZb8TM57UISh0uyyl0AFvwtiawOH Pe2wqWakp8vAvLIRZTcmJr2P5/MD7JFb/uht3KLE8apPnxNZz2Q9gGS3iev6MWBNOTZS +LzP/D+W5wFl+o+TfmT+G+2CgK65JEZ8Qe7nwonwp69OqNhVm3dz9JXt3FkjxlNzdUfw ynLaCK2mFzMNw4UhRfBrUbfquVGfbM4kTmrv9ilfRvata8E/qJTu7Ch+NEZ5wYvNFbz8 bl/Q== X-Gm-Message-State: AO0yUKWzMbO2jNb8v2poe167668T1IgJcVJR7yeBY7nvOFlrifwLJ4TD kKoSdfHktYX2Qrnbt0ISIdGF X-Google-Smtp-Source: AK7set+hKN/wAnd6jcoQHe7XAkFdbxxA7IIoavlNuzaHrlVMMKQRHxjFh33AmRVx67sHbSBlerR0/A== X-Received: by 2002:adf:fdce:0:b0:2c5:5ff8:6b01 with SMTP id i14-20020adffdce000000b002c55ff86b01mr4996763wrs.1.1676981073168; Tue, 21 Feb 2023 04:04:33 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 087/103] gccrs: ast: Dump generic parameters Date: Tue, 21 Feb 2023 13:02:17 +0100 Message-Id: <20230221120230.596966-88-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add missing visitor. * ast/rust-ast-dump.h: Likewise. 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(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 216f0a43dc3..03a57d416c4 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 6c2f13c8c01..4bc322cda98 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); -- 2.39.1