From patchwork Tue Feb 21 12:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1827824wrn; Tue, 21 Feb 2023 04:14:57 -0800 (PST) X-Google-Smtp-Source: AK7set99iltsJi5Zonj0cD0t2Nr5ZE3z9w/wdNSc6ahrIXRwwBjlm5P2t5itYTzaySqdtKCK/IV5 X-Received: by 2002:a17:906:af10:b0:8aa:c038:974c with SMTP id lx16-20020a170906af1000b008aac038974cmr11919857ejb.54.1676981697080; Tue, 21 Feb 2023 04:14:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981697; cv=none; d=google.com; s=arc-20160816; b=hrXaA/e5hggQOq3vSYuVJmw1OXLtWHJ0ZY7NS4glC8LSQXoB5Y06wwBh2QPiW+gon1 sHcJhkS/U0AoIGZmJ1kCHjUKH23p8AG6g42AhcH2dFBFx5R9ctCMr0WXwe71pwtHWu90 aEOBpnhgvqOMQVfzMscCmR4QIaTyrwxqr5VRcctUIJ7wkKiI/P7F+taQEfUpOBrq/5wQ XMM+SlKLaw2T5utbEYNryKAhLNnDaLFQFeGgdDbSWmlcQjaswlkxFjIJzfPy63OEHO95 Ha7wXuIJc82KnT1FsrDiaHu0v1OJ5Q+subQvmUUckZQdMpR/CXHZISYVmLkSrHdlTgJG 5A2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=df/2K0/KtqGB6JuvmZot7P42Hj6u3lxezEsu0jNdp7Mg2nj/bCO/TmtMpzm9JYxCbo NG86uNiHGjvi7WjG5kKWLATBu1OCGKWgvb2KWoX/wLZr4m8QEY2YGQkt5IZJKP9af9KE q37RKLidy0pawY5rrretVP9XR17Y8eNg+ZvhVK/A6OWzHYrBSj2/uoJZz8nqZXe/uDmn ZwoEbsGX02pF9BmXiaBOO+nYfiuNqu3KZr/w1AsduMQWzXLlYy2ENWiwfHYdmj5JT2MP CpCqcbxkAp4RPvGYzSb/vJc1kxA1enhHt3kBnIEzSME1M0Vz64JoUQDsCKrnSv1QyooI H41w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=FKywTj1Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h12-20020a170906530c00b008c3baa1f86asi11843913ejo.851.2023.02.21.04.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:14:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=FKywTj1Q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11D11395A43A for ; Tue, 21 Feb 2023 12:07:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 57C3D384F4AF for ; Tue, 21 Feb 2023 12:03:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57C3D384F4AF 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-x42e.google.com with SMTP id j2so3981375wrh.9 for ; Tue, 21 Feb 2023 04:03:36 -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=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=FKywTj1Q6/Iy3g43h49UDGw73doDc5cSaT4Q2V32WZQ4fOadD962koLffyGarofgMd wSrhnfCQZTnmY9BBwcu+LFnJVXq+gMa//EqHIolPLc6YkDYxlVix2kHX5Y9BLdZx4Orr 4uhqYX8aAp5CGZD8juRtKnmg6euwG3ygFamliEJdg4h8dzXn0xJC9M5pkKn61XiojyoV qrE4v/8RAbt4nPO8QYJJQelYymfKWCvoccyol8eHHK44vhYI+uGlcJRQ5M192hgzOe4m Aw1xxfwJiMafzahfrEt0UUaoY06nV/ACQTxRtcweJOfQpsfIyPEGP4yWOMvDrTqQkscq p+Eg== 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=VPoZB0P7NXPdmRarj5QWxhLM4hB1pT7x7XSIrJO7pmc=; b=rp28jLw0q8MVF4xi0Bs94nbrX5w8e9sd+QdL71a9sM7yA+cyjuLBjDBnvGvNBBu/bL taD9cqRlmnKVe++ZTNhVEiHdM6haHFAE0rTvVLCxvNM51iM6H+shRJ3Y/6WUXvvZAgod wBCLLRlB69WMWsgqFRO9uz+K4CIPtRQPJc5NjAdd6O284ktMy9ujk4cOfeba949Z95H0 Y5RQCUvCb/bh1QmC1RQTR9bV+xGyUkiG2PpHK3iPW05LjaBTiulMROPQJhLgrpJW/Sql iShGKfn3ZMDVK0iDidO6QTT641tWv08LyLZyxYI4eSB1B5UP6//jxyC5iyrPRdmLkXD2 gzFg== X-Gm-Message-State: AO0yUKWDkF5rQ824cXT/7i++O+ptxREkzfBS79VKYOmsDVt19FNqkUN7 fjNSahsG6meqpYvkfKJN3T6FNlkb4DogMQ+jSQ== X-Received: by 2002:a5d:404d:0:b0:2c5:a07e:55e1 with SMTP id w13-20020a5d404d000000b002c5a07e55e1mr4353134wrp.17.1676981014875; Tue, 21 Feb 2023 04:03:34 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, David Faust Subject: [committed 014/103] gccrs: ast: dump structs, enums and unions Date: Tue, 21 Feb 2023 13:01:04 +0100 Message-Id: <20230221120230.596966-15-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> MIME-Version: 1.0 X-Spam-Status: No, score=-14.9 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758442760138762513?= X-GMAIL-MSGID: =?utf-8?q?1758442760138762513?= From: David Faust gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Fill empty functions for structs, enums and unions. --- gcc/rust/ast/rust-ast-dump.cc | 135 ++++++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 8 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 6f2f81630b0..7cbdfa21fcb 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -750,35 +750,154 @@ Dump::visit (TypeAlias &type_alias) void Dump::visit (StructStruct &struct_item) -{} +{ + stream << "struct " << struct_item.get_identifier (); + if (struct_item.has_generics ()) + emit_generic_params (struct_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + + auto &fields = struct_item.get_fields (); + + indentation.increment (); + for (auto &field : fields) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + if (fields.size () > 0) + stream << '\n' << indentation; + stream << "}\n"; +} void Dump::visit (TupleStruct &tuple_struct) -{} +{ + stream << "struct " << tuple_struct.get_identifier (); + if (tuple_struct.has_generics ()) + emit_generic_params (tuple_struct.get_generic_params ()); + + // FIXME: where-clause + + stream << '('; + + auto &fields = tuple_struct.get_fields (); + if (fields.size () >= 1) + { + format_tuple_field (fields[0]); + for (size_t i = 1; i < fields.size (); i++) + { + stream << ", "; + format_tuple_field (fields[i]); + } + } + stream << ");\n"; +} void Dump::visit (EnumItem &item) -{} +{ + stream << item.get_identifier (); +} void Dump::visit (EnumItemTuple &item) -{} +{ + stream << item.get_identifier () << '('; + auto &fields = item.get_tuple_fields (); + if (fields.size () >= 1) + { + format_tuple_field (fields[0]); + for (size_t i = 1; i < fields.size (); i++) + { + stream << ", "; + format_tuple_field (fields[i]); + } + } + stream << ')'; +} void Dump::visit (EnumItemStruct &item) -{} +{ + stream << item.get_identifier () << " {"; + + auto &fields = item.get_struct_fields (); + + indentation.increment (); + for (auto &field : fields) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + if (fields.size () > 0) + stream << '\n' << indentation; + stream << '}'; +} void Dump::visit (EnumItemDiscriminant &item) -{} +{ + stream << item.get_identifier () << " = "; + item.get_expr ()->accept_vis (*this); +} void Dump::visit (Enum &enum_item) -{} +{ + stream << "enum " << enum_item.get_identifier (); + if (enum_item.has_generics ()) + emit_generic_params (enum_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + auto &variants = enum_item.get_variants (); + if (variants.size () >= 1) + { + stream << '\n'; + indentation.increment (); + for (auto &var : variants) + { + stream << indentation; + var->accept_vis (*this); + stream << ",\n"; + } + indentation.decrement (); + } + + stream << "}\n"; +} void Dump::visit (Union &union_item) -{} +{ + stream << "union " << union_item.get_identifier (); + if (union_item.has_generics ()) + emit_generic_params (union_item.get_generic_params ()); + + // FIXME: where-clause + + stream << " {"; + indentation.increment (); + for (auto &field : union_item.get_variants ()) + { + stream << '\n' << indentation; + format_struct_field (field); + stream << ','; + } + indentation.decrement (); + + stream << '\n' << indentation << "}\n"; +} void Dump::visit (ConstantItem &const_item)