LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-hir-type-check-stmt.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 79.5 % 88 70
Test Date: 2024-04-13 14:00:49 Functions: 66.7 % 18 12
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2024 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-hir-type-check-stmt.h"
      20                 :             : #include "rust-hir-type-check-type.h"
      21                 :             : #include "rust-hir-type-check-expr.h"
      22                 :             : #include "rust-hir-type-check-implitem.h"
      23                 :             : #include "rust-hir-type-check-item.h"
      24                 :             : #include "rust-hir-type-check-pattern.h"
      25                 :             : #include "rust-type-util.h"
      26                 :             : 
      27                 :             : namespace Rust {
      28                 :             : namespace Resolver {
      29                 :             : 
      30                 :             : TyTy::BaseType *
      31                 :       16118 : TypeCheckStmt::Resolve (HIR::Stmt *stmt)
      32                 :             : {
      33                 :       16118 :   TypeCheckStmt resolver;
      34                 :       16118 :   stmt->accept_vis (resolver);
      35                 :       16117 :   return resolver.infered;
      36                 :       16117 : }
      37                 :             : 
      38                 :             : void
      39                 :        5871 : TypeCheckStmt::visit (HIR::ExprStmt &stmt)
      40                 :             : {
      41                 :        5871 :   infered = TypeCheckExpr::Resolve (stmt.get_expr ().get ());
      42                 :        5871 : }
      43                 :             : 
      44                 :             : void
      45                 :          45 : TypeCheckStmt::visit (HIR::EmptyStmt &stmt)
      46                 :             : {
      47                 :          45 :   infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ());
      48                 :          45 : }
      49                 :             : 
      50                 :             : void
      51                 :           8 : TypeCheckStmt::visit (HIR::ExternBlock &extern_block)
      52                 :             : {
      53                 :          16 :   for (auto &item : extern_block.get_extern_items ())
      54                 :             :     {
      55                 :           8 :       TypeCheckTopLevelExternItem::Resolve (item.get (), extern_block);
      56                 :             :     }
      57                 :           8 : }
      58                 :             : 
      59                 :             : void
      60                 :          51 : TypeCheckStmt::visit (HIR::ConstantItem &constant)
      61                 :             : {
      62                 :          51 :   TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ());
      63                 :          51 :   TyTy::BaseType *expr_type
      64                 :          51 :     = TypeCheckExpr::Resolve (constant.get_expr ().get ());
      65                 :             : 
      66                 :          51 :   infered = coercion_site (
      67                 :          51 :     constant.get_mappings ().get_hirid (),
      68                 :          51 :     TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()),
      69                 :          51 :     TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()),
      70                 :             :     constant.get_locus ());
      71                 :          51 :   context->insert_type (constant.get_mappings (), infered);
      72                 :          51 : }
      73                 :             : 
      74                 :             : void
      75                 :        9924 : TypeCheckStmt::visit (HIR::LetStmt &stmt)
      76                 :             : {
      77                 :        9924 :   infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ());
      78                 :             : 
      79                 :        9924 :   HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
      80                 :        9924 :   TyTy::BaseType *init_expr_ty = nullptr;
      81                 :        9924 :   location_t init_expr_locus = UNKNOWN_LOCATION;
      82                 :        9924 :   if (stmt.has_init_expr ())
      83                 :             :     {
      84                 :        8899 :       init_expr_locus = stmt.get_init_expr ()->get_locus ();
      85                 :        8899 :       init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ().get ());
      86                 :        8898 :       if (init_expr_ty->get_kind () == TyTy::TypeKind::ERROR)
      87                 :             :         return;
      88                 :             : 
      89                 :        8881 :       init_expr_ty->append_reference (
      90                 :        8881 :         stmt_pattern.get_mappings ().get_hirid ());
      91                 :             :     }
      92                 :             : 
      93                 :        9906 :   TyTy::BaseType *specified_ty = nullptr;
      94                 :        9906 :   location_t specified_ty_locus;
      95                 :        9906 :   if (stmt.has_type ())
      96                 :             :     {
      97                 :        1679 :       specified_ty = TypeCheckType::Resolve (stmt.get_type ().get ());
      98                 :        1679 :       specified_ty_locus = stmt.get_type ()->get_locus ();
      99                 :             :     }
     100                 :             : 
     101                 :             :   // let x:i32 = 123;
     102                 :        9906 :   if (specified_ty != nullptr && init_expr_ty != nullptr)
     103                 :             :     {
     104                 :        1497 :       coercion_site (stmt.get_mappings ().get_hirid (),
     105                 :             :                      TyTy::TyWithLocation (specified_ty, specified_ty_locus),
     106                 :             :                      TyTy::TyWithLocation (init_expr_ty, init_expr_locus),
     107                 :             :                      stmt.get_locus ());
     108                 :        1497 :       TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
     109                 :             :     }
     110                 :             :   else
     111                 :             :     {
     112                 :             :       // let x:i32;
     113                 :        8409 :       if (specified_ty != nullptr)
     114                 :             :         {
     115                 :         182 :           TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
     116                 :             :         }
     117                 :             :       // let x = 123;
     118                 :        8227 :       else if (init_expr_ty != nullptr)
     119                 :             :         {
     120                 :        7384 :           TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty);
     121                 :             :         }
     122                 :             :       // let x;
     123                 :             :       else
     124                 :             :         {
     125                 :         843 :           auto infer
     126                 :         843 :             = new TyTy::InferType (stmt_pattern.get_mappings ().get_hirid (),
     127                 :             :                                    TyTy::InferType::InferTypeKind::GENERAL,
     128                 :             :                                    TyTy::InferType::TypeHint::Default (),
     129                 :         843 :                                    stmt.get_locus ());
     130                 :         843 :           TypeCheckPattern::Resolve (&stmt_pattern, infer);
     131                 :             :         }
     132                 :             :     }
     133                 :             : }
     134                 :             : 
     135                 :             : void
     136                 :           0 : TypeCheckStmt::visit (HIR::TypePath &path)
     137                 :             : {
     138                 :           0 :   infered = TypeCheckType::Resolve (&path);
     139                 :           0 : }
     140                 :             : void
     141                 :           0 : TypeCheckStmt::visit (HIR::QualifiedPathInType &path)
     142                 :             : {
     143                 :           0 :   infered = TypeCheckType::Resolve (&path);
     144                 :           0 : }
     145                 :             : 
     146                 :             : void
     147                 :          79 : TypeCheckStmt::visit (HIR::TupleStruct &struct_decl)
     148                 :             : {
     149                 :          79 :   infered = TypeCheckItem::Resolve (struct_decl);
     150                 :          79 : }
     151                 :             : 
     152                 :             : void
     153                 :           3 : TypeCheckStmt::visit (HIR::Enum &enum_decl)
     154                 :             : {
     155                 :           3 :   infered = TypeCheckItem::Resolve (enum_decl);
     156                 :           3 : }
     157                 :             : 
     158                 :             : void
     159                 :          70 : TypeCheckStmt::visit (HIR::StructStruct &struct_decl)
     160                 :             : {
     161                 :          70 :   infered = TypeCheckItem::Resolve (struct_decl);
     162                 :          70 : }
     163                 :             : 
     164                 :             : void
     165                 :           0 : TypeCheckStmt::visit (HIR::Union &union_decl)
     166                 :             : {
     167                 :           0 :   infered = TypeCheckItem::Resolve (union_decl);
     168                 :           0 : }
     169                 :             : 
     170                 :             : void
     171                 :          60 : TypeCheckStmt::visit (HIR::Function &function)
     172                 :             : {
     173                 :          60 :   infered = TypeCheckItem::Resolve (function);
     174                 :          60 : }
     175                 :             : 
     176                 :             : void
     177                 :           0 : TypeCheckStmt::visit (HIR::Module &module)
     178                 :             : {
     179                 :           0 :   infered = TypeCheckItem::Resolve (module);
     180                 :           0 : }
     181                 :             : 
     182                 :             : void
     183                 :           0 : TypeCheckStmt::visit (HIR::TypeAlias &type_alias)
     184                 :             : {
     185                 :           0 :   infered = TypeCheckItem::Resolve (type_alias);
     186                 :           0 : }
     187                 :             : 
     188                 :             : void
     189                 :           0 : TypeCheckStmt::visit (HIR::StaticItem &static_item)
     190                 :             : {
     191                 :           0 :   infered = TypeCheckItem::Resolve (static_item);
     192                 :           0 : }
     193                 :             : 
     194                 :             : void
     195                 :           3 : TypeCheckStmt::visit (HIR::Trait &trait)
     196                 :             : {
     197                 :           3 :   infered = TypeCheckItem::Resolve (trait);
     198                 :           3 : }
     199                 :             : 
     200                 :             : void
     201                 :           4 : TypeCheckStmt::visit (HIR::ImplBlock &impl)
     202                 :             : {
     203                 :           4 :   infered = TypeCheckItem::Resolve (impl);
     204                 :           4 : }
     205                 :             : 
     206                 :             : } // namespace Resolver
     207                 :             : } // namespace Rust
        

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