LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower-enumitem.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 92 92
Test Date: 2026-11-14 16:39:50 Functions: 100.0 % 5 5
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
       2              : 
       3              : // This file is part of GCC.
       4              : 
       5              : // GCC is free software; you can redistribute it and/or modify it under
       6              : // the terms of the GNU General Public License as published by the Free
       7              : // Software Foundation; either version 3, or (at your option) any later
       8              : // version.
       9              : 
      10              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13              : // for more details.
      14              : 
      15              : // You should have received a copy of the GNU General Public License
      16              : // along with GCC; see the file COPYING3.  If not see
      17              : // <http://www.gnu.org/licenses/>.
      18              : 
      19              : #ifndef RUST_AST_LOWER_ENUMITEM
      20              : #define RUST_AST_LOWER_ENUMITEM
      21              : 
      22              : #include "rust-ast-lower.h"
      23              : #include "rust-diagnostics.h"
      24              : 
      25              : #include "rust-ast-lower-base.h"
      26              : #include "rust-ast-lower-type.h"
      27              : #include "rust-ast-lower-expr.h"
      28              : #include "rust-hir-full-decls.h"
      29              : 
      30              : namespace Rust {
      31              : namespace HIR {
      32              : 
      33         2161 : class ASTLoweringEnumItem : public ASTLoweringBase
      34              : {
      35              :   using Rust::HIR::ASTLoweringBase::visit;
      36              : 
      37              : public:
      38         2161 :   static HIR::EnumItem *translate (AST::EnumItem *item)
      39              :   {
      40         4322 :     ASTLoweringEnumItem resolver;
      41         2161 :     item->accept_vis (resolver);
      42              : 
      43         2161 :     rust_assert (resolver.translated != nullptr);
      44              : 
      45         2161 :     auto hirid = resolver.translated->get_mappings ().get_hirid ();
      46         2161 :     auto defid = resolver.translated->get_mappings ().get_defid ();
      47              : 
      48         2161 :     resolver.mappings.insert_defid_mapping (defid, resolver.translated);
      49         2161 :     resolver.mappings.insert_location (hirid,
      50         2161 :                                        resolver.translated->get_locus ());
      51              : 
      52         2161 :     return resolver.translated;
      53         2161 :   }
      54              : 
      55         1004 :   void visit (AST::EnumItem &item) override
      56              :   {
      57         1004 :     auto crate_num = mappings.crate.get_current_crate ();
      58         2008 :     Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
      59         1004 :                                    mappings.get_next_hir_id (crate_num),
      60         1004 :                                    mappings.get_next_localdef_id (crate_num));
      61              : 
      62         1004 :     if (item.has_visibility ())
      63            4 :       rust_error_at (item.get_locus (),
      64              :                      "visibility qualifier %qs not allowed on enum item",
      65            8 :                      item.get_visibility ().as_string ().c_str ());
      66         1004 :     translated = new HIR::EnumItem (mapping, item.get_identifier (),
      67         2008 :                                     item.get_outer_attrs (), item.get_locus ());
      68         1004 :   }
      69              : 
      70          743 :   void visit (AST::EnumItemTuple &item) override
      71              :   {
      72          743 :     auto crate_num = mappings.crate.get_current_crate ();
      73         1486 :     Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
      74          743 :                                    mappings.get_next_hir_id (crate_num),
      75          743 :                                    mappings.get_next_localdef_id (crate_num));
      76              : 
      77          743 :     if (item.has_visibility ())
      78            3 :       rust_error_at (item.get_locus (),
      79              :                      "visibility qualifier %qs not allowed on enum item",
      80            6 :                      item.get_visibility ().as_string ().c_str ());
      81              : 
      82          743 :     std::vector<HIR::TupleField> fields;
      83          743 :     fields.reserve (item.get_tuple_fields ().size ());
      84              : 
      85         1585 :     for (auto &field : item.get_tuple_fields ())
      86              :       {
      87          842 :         HIR::Visibility vis = translate_visibility (field.get_visibility ());
      88          842 :         HIR::Type *type = ASTLoweringType::translate (field.get_field_type ());
      89              : 
      90          842 :         auto crate_num = mappings.crate.get_current_crate ();
      91          842 :         Analysis::NodeMapping field_mapping (
      92          842 :           crate_num, field.get_node_id (), mappings.get_next_hir_id (crate_num),
      93          842 :           mappings.get_next_localdef_id (crate_num));
      94              : 
      95          842 :         fields.emplace_back (field_mapping, std::unique_ptr<HIR::Type> (type),
      96         1684 :                              vis, field.get_locus (), field.get_outer_attrs ());
      97          842 :       }
      98              : 
      99          743 :     translated
     100         1486 :       = new HIR::EnumItemTuple (mapping, item.get_identifier (),
     101          743 :                                 std::move (fields), item.get_outer_attrs (),
     102         1486 :                                 item.get_locus ());
     103          743 :   }
     104              : 
     105           99 :   void visit (AST::EnumItemStruct &item) override
     106              :   {
     107           99 :     auto crate_num = mappings.crate.get_current_crate ();
     108          198 :     Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
     109           99 :                                    mappings.get_next_hir_id (crate_num),
     110           99 :                                    mappings.get_next_localdef_id (crate_num));
     111              : 
     112           99 :     if (item.has_visibility ())
     113            1 :       rust_error_at (item.get_locus (),
     114              :                      "visibility qualifier %qs not allowed on enum item",
     115            2 :                      item.get_visibility ().as_string ().c_str ());
     116              : 
     117           99 :     std::vector<HIR::StructField> fields;
     118          260 :     for (auto &field : item.get_struct_fields ())
     119              :       {
     120          163 :         HIR::Visibility vis = translate_visibility (field.get_visibility ());
     121          163 :         HIR::Type *type = ASTLoweringType::translate (field.get_field_type ());
     122              : 
     123          163 :         auto crate_num = mappings.crate.get_current_crate ();
     124          163 :         Analysis::NodeMapping field_mapping (
     125          163 :           crate_num, field.get_node_id (), mappings.get_next_hir_id (crate_num),
     126          163 :           mappings.get_next_localdef_id (crate_num));
     127              : 
     128          163 :         HIR::StructField translated_field (field_mapping,
     129          326 :                                            field.get_field_name (),
     130          326 :                                            std::unique_ptr<HIR::Type> (type),
     131              :                                            vis, field.get_locus (),
     132          326 :                                            field.get_outer_attrs ());
     133              : 
     134          163 :         if (struct_field_name_exists (fields, translated_field))
     135              :           break;
     136              : 
     137          161 :         fields.push_back (std::move (translated_field));
     138          163 :       }
     139              : 
     140           99 :     translated
     141          198 :       = new HIR::EnumItemStruct (mapping, item.get_identifier (),
     142           99 :                                  std::move (fields), item.get_outer_attrs (),
     143          198 :                                  item.get_locus ());
     144           99 :   }
     145              : 
     146          315 :   void visit (AST::EnumItemDiscriminant &item) override
     147              :   {
     148          315 :     auto crate_num = mappings.crate.get_current_crate ();
     149          630 :     Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
     150          315 :                                    mappings.get_next_hir_id (crate_num),
     151          315 :                                    mappings.get_next_localdef_id (crate_num));
     152              : 
     153          315 :     if (item.has_visibility ())
     154            2 :       rust_error_at (item.get_locus (),
     155              :                      "visibility qualifier %qs not allowed on enum item",
     156            4 :                      item.get_visibility ().as_string ().c_str ());
     157              : 
     158          315 :     HIR::Expr *expr = ASTLoweringExpr::translate (item.get_expr ());
     159          315 :     translated
     160          315 :       = new HIR::EnumItemDiscriminant (mapping, item.get_identifier (),
     161          630 :                                        std::unique_ptr<HIR::Expr> (expr),
     162          315 :                                        item.get_outer_attrs (),
     163          630 :                                        item.get_locus ());
     164          315 :   }
     165              : 
     166              : private:
     167         2161 :   ASTLoweringEnumItem () : translated (nullptr) {}
     168              : 
     169              :   HIR::EnumItem *translated;
     170              : };
     171              : 
     172              : } // namespace HIR
     173              : } // namespace Rust
     174              : 
     175              : #endif // RUST_AST_LOWER_ENUMITEM
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.