LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-struct-field-expr.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 33 33
Test Date: 2026-02-28 14:20:25 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              : #include "rust-compile-struct-field-expr.h"
      20              : #include "rust-compile-expr.h"
      21              : 
      22              : namespace Rust {
      23              : namespace Compile {
      24              : 
      25         2860 : CompileStructExprField::CompileStructExprField (Context *ctx)
      26         2860 :   : HIRCompileBase (ctx), translated (error_mark_node)
      27         2860 : {}
      28              : 
      29              : tree
      30         2860 : CompileStructExprField::Compile (HIR::StructExprField &field, Context *ctx)
      31              : {
      32         2860 :   CompileStructExprField compiler (ctx);
      33         2860 :   switch (field.get_kind ())
      34              :     {
      35          197 :     case HIR::StructExprField::StructExprFieldKind::IDENTIFIER:
      36          197 :       compiler.visit (static_cast<HIR::StructExprFieldIdentifier &> (field));
      37          197 :       break;
      38              : 
      39         2621 :     case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE:
      40         2621 :       compiler.visit (
      41              :         static_cast<HIR::StructExprFieldIdentifierValue &> (field));
      42         2621 :       break;
      43              : 
      44           42 :     case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE:
      45           42 :       compiler.visit (static_cast<HIR::StructExprFieldIndexValue &> (field));
      46           42 :       break;
      47              :     }
      48         2860 :   return compiler.translated;
      49         2860 : }
      50              : 
      51              : void
      52         2621 : CompileStructExprField::visit (HIR::StructExprFieldIdentifierValue &field)
      53              : {
      54         2621 :   translated = CompileExpr::Compile (field.get_value (), ctx);
      55         2621 : }
      56              : 
      57              : void
      58           42 : CompileStructExprField::visit (HIR::StructExprFieldIndexValue &field)
      59              : {
      60           42 :   translated = CompileExpr::Compile (field.get_value (), ctx);
      61           42 : }
      62              : 
      63              : void
      64          197 : CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
      65              : {
      66              :   // we can make the field look like a path expr to take advantage of existing
      67              :   // code
      68              : 
      69          197 :   Analysis::NodeMapping mappings_copy1 = field.get_mappings ();
      70          197 :   Analysis::NodeMapping mappings_copy2 = field.get_mappings ();
      71              : 
      72          394 :   HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ());
      73          197 :   HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (),
      74          394 :                             HIR::GenericArgs::create_empty ());
      75          197 :   HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
      76          394 :                               {});
      77          197 :   translated = CompileExpr::Compile (expr, ctx);
      78          394 : }
      79              : 
      80              : } // namespace Compile
      81              : } // namespace Rust
        

Generated by: LCOV version 2.4-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.