From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 194E3384690B for ; Tue, 21 Feb 2023 12:03:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 194E3384690B 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-x429.google.com with SMTP id 6so3756262wrb.11 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=LishXGAd9+Z5JB6pmdQngx0JujEc0RI2DOVZXDjQE/7FMlsdpcFRV8Sf18VRFznkzz 3NuNJ/aQ5ZIUTW/KQ8qZURf60+Iy5noUsdvo79kUusXShDsLutxsGZXONtMssMSadxTY 6iH6ePVdBFAbcL4EL3iD3KhHGPhMttmuxtVnwa0E97KmSflicuKfggQDheY9b1PESzTc YSnp1fwahe1h2qx7aZ/mthxya1jxcTvpEXKndJXNivyzE4mZe6MopoZaDHSMqipdyRie FjQ86rx37rZJFk7XDg+E3ce5hjjt9PrNgS4h3t3owWGjxVg0+s5Rh6UTbOJQ+Imit6+3 nBLg== X-Gm-Message-State: AO0yUKXuA9kVR1+cOqvusVYVqB/N+ZgguRFltfZCzlBPPoRYoKJu8mAD dsU8ljue6SnLruTENocXQ+Z1 X-Google-Smtp-Source: AK7set9MydtUFo1PsDUVQLahYmguS4JUnoDjQM2qdO3isQTrrBnaCyTb0NFvKWzq2RR8jYFU1/Y0Ag== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.4 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=unavailable 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: 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) -- 2.39.1