LCOV - code coverage report
Current view: top level - gcc/rust/hir/tree - rust-hir-stmt.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 53.7 % 41 22
Test Date: 2024-04-13 14:00:49 Functions: 53.8 % 13 7
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                 :             : #ifndef RUST_HIR_STATEMENT_H
      20                 :             : #define RUST_HIR_STATEMENT_H
      21                 :             : 
      22                 :             : #include "rust-hir.h"
      23                 :             : #include "rust-hir-path.h"
      24                 :             : #include "rust-hir-expr.h"
      25                 :             : 
      26                 :             : namespace Rust {
      27                 :             : namespace HIR {
      28                 :             : // Just a semi-colon, which apparently is a statement.
      29                 :           0 : class EmptyStmt : public Stmt
      30                 :             : {
      31                 :             :   location_t locus;
      32                 :             : 
      33                 :             : public:
      34                 :           0 :   std::string as_string () const override { return std::string (1, ';'); }
      35                 :             : 
      36                 :          45 :   EmptyStmt (Analysis::NodeMapping mappings, location_t locus)
      37                 :          45 :     : Stmt (std::move (mappings)), locus (locus)
      38                 :             :   {}
      39                 :             : 
      40                 :          45 :   location_t get_locus () const override final { return locus; }
      41                 :             : 
      42                 :             :   void accept_vis (HIRFullVisitor &vis) override;
      43                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
      44                 :             : 
      45                 :          90 :   bool is_item () const override final { return false; }
      46                 :             : 
      47                 :             : protected:
      48                 :             :   /* Use covariance to implement clone function as returning this object rather
      49                 :             :    * than base */
      50                 :           0 :   EmptyStmt *clone_stmt_impl () const override { return new EmptyStmt (*this); }
      51                 :             : };
      52                 :             : 
      53                 :             : /* Variable assignment let statement - type of "declaration statement" as it
      54                 :             :  * introduces new name into scope */
      55                 :             : class LetStmt : public Stmt
      56                 :             : {
      57                 :             :   // bool has_outer_attrs;
      58                 :             :   AST::AttrVec outer_attrs;
      59                 :             : 
      60                 :             :   std::unique_ptr<Pattern> variables_pattern;
      61                 :             : 
      62                 :             :   // bool has_type;
      63                 :             :   std::unique_ptr<Type> type;
      64                 :             : 
      65                 :             :   // bool has_init_expr;
      66                 :             :   std::unique_ptr<Expr> init_expr;
      67                 :             : 
      68                 :             :   location_t locus;
      69                 :             : 
      70                 :             : public:
      71                 :             :   // Returns whether let statement has outer attributes.
      72                 :             :   bool has_outer_attrs () const { return !outer_attrs.empty (); }
      73                 :             : 
      74                 :             :   // Returns whether let statement has a given return type.
      75                 :        9906 :   bool has_type () const { return type != nullptr; }
      76                 :             : 
      77                 :             :   // Returns whether let statement has an initialisation expression.
      78                 :       52512 :   bool has_init_expr () const { return init_expr != nullptr; }
      79                 :             : 
      80                 :             :   std::string as_string () const override;
      81                 :             : 
      82                 :        9928 :   LetStmt (Analysis::NodeMapping mappings,
      83                 :             :            std::unique_ptr<Pattern> variables_pattern,
      84                 :             :            std::unique_ptr<Expr> init_expr, std::unique_ptr<Type> type,
      85                 :             :            AST::AttrVec outer_attrs, location_t locus)
      86                 :        9928 :     : Stmt (std::move (mappings)), outer_attrs (std::move (outer_attrs)),
      87                 :        9928 :       variables_pattern (std::move (variables_pattern)),
      88                 :        9928 :       type (std::move (type)), init_expr (std::move (init_expr)), locus (locus)
      89                 :             :   {}
      90                 :             : 
      91                 :             :   // Copy constructor with clone
      92                 :           0 :   LetStmt (LetStmt const &other)
      93                 :           0 :     : Stmt (other.mappings), outer_attrs (other.outer_attrs),
      94                 :           0 :       locus (other.locus)
      95                 :             :   {
      96                 :             :     // guard to prevent null dereference (only required if error state)
      97                 :           0 :     if (other.variables_pattern != nullptr)
      98                 :           0 :       variables_pattern = other.variables_pattern->clone_pattern ();
      99                 :             : 
     100                 :             :     // guard to prevent null dereference (always required)
     101                 :           0 :     if (other.init_expr != nullptr)
     102                 :           0 :       init_expr = other.init_expr->clone_expr ();
     103                 :           0 :     if (other.type != nullptr)
     104                 :           0 :       type = other.type->clone_type ();
     105                 :           0 :   }
     106                 :             : 
     107                 :             :   // Overloaded assignment operator to clone
     108                 :             :   LetStmt &operator= (LetStmt const &other)
     109                 :             :   {
     110                 :             :     outer_attrs = other.outer_attrs;
     111                 :             :     locus = other.locus;
     112                 :             : 
     113                 :             :     // guard to prevent null dereference (only required if error state)
     114                 :             :     if (other.variables_pattern != nullptr)
     115                 :             :       variables_pattern = other.variables_pattern->clone_pattern ();
     116                 :             :     else
     117                 :             :       variables_pattern = nullptr;
     118                 :             : 
     119                 :             :     // guard to prevent null dereference (always required)
     120                 :             :     if (other.init_expr != nullptr)
     121                 :             :       init_expr = other.init_expr->clone_expr ();
     122                 :             :     else
     123                 :             :       init_expr = nullptr;
     124                 :             :     if (other.type != nullptr)
     125                 :             :       type = other.type->clone_type ();
     126                 :             :     else
     127                 :             :       type = nullptr;
     128                 :             : 
     129                 :             :     return *this;
     130                 :             :   }
     131                 :             : 
     132                 :             :   // move constructors
     133                 :             :   LetStmt (LetStmt &&other) = default;
     134                 :             :   LetStmt &operator= (LetStmt &&other) = default;
     135                 :             : 
     136                 :       12268 :   location_t get_locus () const override final { return locus; }
     137                 :             : 
     138                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     139                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
     140                 :             : 
     141                 :             :   const std::vector<AST::Attribute> &get_outer_attrs () const
     142                 :             :   {
     143                 :             :     return outer_attrs;
     144                 :             :   }
     145                 :           0 :   std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; }
     146                 :             : 
     147                 :       10568 :   std::unique_ptr<HIR::Type> &get_type () { return type; }
     148                 :             : 
     149                 :       73313 :   std::unique_ptr<HIR::Expr> &get_init_expr () { return init_expr; }
     150                 :             : 
     151                 :       27952 :   std::unique_ptr<HIR::Pattern> &get_pattern () { return variables_pattern; }
     152                 :             : 
     153                 :       19848 :   bool is_item () const override final { return false; }
     154                 :             : 
     155                 :             : protected:
     156                 :             :   /* Use covariance to implement clone function as returning this object rather
     157                 :             :    * than base */
     158                 :           0 :   LetStmt *clone_stmt_impl () const override { return new LetStmt (*this); }
     159                 :             : };
     160                 :             : 
     161                 :             : /* class for expression statements (statements containing an expression) */
     162                 :             : class ExprStmt : public Stmt
     163                 :             : {
     164                 :             :   std::unique_ptr<Expr> expr;
     165                 :             :   location_t locus;
     166                 :             :   bool must_be_unit;
     167                 :             : 
     168                 :             : public:
     169                 :        5872 :   ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
     170                 :             :             location_t locus, bool must_be_unit)
     171                 :        5872 :     : Stmt (std::move (mappings)), expr (std::move (expr)), locus (locus),
     172                 :        5872 :       must_be_unit (must_be_unit)
     173                 :             :   {}
     174                 :             : 
     175                 :             :   ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
     176                 :             :             location_t locus)
     177                 :             :     : ExprStmt (std::move (mappings), std::move (expr), locus, false)
     178                 :             :   {}
     179                 :             : 
     180                 :             :   std::string as_string () const override;
     181                 :             : 
     182                 :        5875 :   location_t get_locus () const override final { return locus; }
     183                 :             : 
     184                 :             :   void accept_vis (HIRFullVisitor &vis) override;
     185                 :             :   void accept_vis (HIRStmtVisitor &vis) override;
     186                 :             : 
     187                 :       11742 :   bool is_item () const override final { return false; }
     188                 :             : 
     189                 :       37266 :   std::unique_ptr<Expr> &get_expr () { return expr; }
     190                 :             : 
     191                 :             :   // Copy constructor with clone
     192                 :           0 :   ExprStmt (ExprStmt const &other)
     193                 :           0 :     : Stmt (other), expr (other.expr->clone_expr ()), locus (other.locus)
     194                 :           0 :   {}
     195                 :             : 
     196                 :             :   // Overloaded assignment operator to clone
     197                 :             :   ExprStmt &operator= (ExprStmt const &other)
     198                 :             :   {
     199                 :             :     Stmt::operator= (other);
     200                 :             :     expr = other.expr->clone_expr ();
     201                 :             :     locus = other.locus;
     202                 :             : 
     203                 :             :     return *this;
     204                 :             :   }
     205                 :             : 
     206                 :             :   // move constructors
     207                 :             :   ExprStmt (ExprStmt &&other) = default;
     208                 :             :   ExprStmt &operator= (ExprStmt &&other) = default;
     209                 :             : 
     210                 :        5871 :   bool is_unit_check_needed () const override { return must_be_unit; }
     211                 :             : 
     212                 :             : protected:
     213                 :             :   /* Use covariance to implement clone function as returning this object rather
     214                 :             :    * than base */
     215                 :           0 :   ExprStmt *clone_stmt_impl () const override { return new ExprStmt (*this); }
     216                 :             : };
     217                 :             : 
     218                 :             : } // namespace HIR
     219                 :             : } // namespace Rust
     220                 :             : 
     221                 :             : #endif
        

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.