LCOV - code coverage report
Current view: top level - gcc/rust/resolve - rust-ast-resolve.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 42 42
Test Date: 2024-04-13 14:00:49 Functions: 100.0 % 4 4
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-ast-resolve.h"
      20                 :             : #include "rust-ast-full.h"
      21                 :             : #include "rust-tyty.h"
      22                 :             : #include "rust-ast-resolve-toplevel.h"
      23                 :             : #include "rust-ast-resolve-item.h"
      24                 :             : #include "rust-ast-resolve-expr.h"
      25                 :             : #include "rust-ast-resolve-struct-expr-field.h"
      26                 :             : 
      27                 :             : extern bool
      28                 :             : saw_errors (void);
      29                 :             : 
      30                 :             : namespace Rust {
      31                 :             : namespace Resolver {
      32                 :             : 
      33                 :             : // NameResolution
      34                 :             : 
      35                 :             : NameResolution *
      36                 :        3613 : NameResolution::get ()
      37                 :             : {
      38                 :        3613 :   static NameResolution *instance;
      39                 :        3613 :   if (instance == nullptr)
      40                 :        3597 :     instance = new NameResolution ();
      41                 :             : 
      42                 :        3613 :   return instance;
      43                 :             : }
      44                 :             : 
      45                 :        3597 : NameResolution::NameResolution ()
      46                 :        3597 :   : resolver (Resolver::get ()), mappings (Analysis::Mappings::get ())
      47                 :             : {
      48                 :             :   // these are global
      49                 :        3597 :   resolver->get_type_scope ().push (mappings->get_next_node_id ());
      50                 :        3597 :   resolver->insert_builtin_types (resolver->get_type_scope ().peek ());
      51                 :        3597 :   resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
      52                 :        3597 : }
      53                 :             : 
      54                 :             : void
      55                 :        3613 : NameResolution::Resolve (AST::Crate &crate)
      56                 :             : {
      57                 :        3613 :   auto resolver = get ();
      58                 :        3613 :   resolver->go (crate);
      59                 :        3612 : }
      60                 :             : 
      61                 :             : void
      62                 :        3613 : NameResolution::go (AST::Crate &crate)
      63                 :             : {
      64                 :             :   // lookup current crate name
      65                 :        3613 :   CrateNum cnum = mappings->get_current_crate ();
      66                 :        3613 :   std::string crate_name;
      67                 :        3613 :   bool ok = mappings->get_crate_name (cnum, crate_name);
      68                 :        3613 :   rust_assert (ok);
      69                 :             : 
      70                 :             :   // setup the ribs
      71                 :        3613 :   NodeId scope_node_id = crate.get_node_id ();
      72                 :        3613 :   resolver->get_name_scope ().push (scope_node_id);
      73                 :        3613 :   resolver->get_type_scope ().push (scope_node_id);
      74                 :        3613 :   resolver->get_label_scope ().push (scope_node_id);
      75                 :        3613 :   resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
      76                 :        3613 :   resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
      77                 :        3613 :   resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
      78                 :             : 
      79                 :             :   // get the root segment
      80                 :        3613 :   CanonicalPath crate_prefix
      81                 :        3613 :     = CanonicalPath::new_seg (scope_node_id, crate_name);
      82                 :        3613 :   crate_prefix.set_crate_num (cnum);
      83                 :             : 
      84                 :             :   // setup a dummy crate node
      85                 :        7226 :   resolver->get_name_scope ().insert (
      86                 :        7226 :     CanonicalPath::new_seg (crate.get_node_id (), "__$$crate__"),
      87                 :             :     crate.get_node_id (), UNDEF_LOCATION);
      88                 :             : 
      89                 :             :   // setup the root scope
      90                 :        3613 :   resolver->push_new_module_scope (scope_node_id);
      91                 :             : 
      92                 :             :   // first gather the top-level namespace names then we drill down so this
      93                 :             :   // allows for resolving forward declarations since an impl block might have
      94                 :             :   // a Self type Foo which is defined after the impl block for example.
      95                 :       17840 :   for (auto it = crate.items.begin (); it != crate.items.end (); it++)
      96                 :       14227 :     ResolveTopLevel::go (it->get (), CanonicalPath::create_empty (),
      97                 :             :                          crate_prefix);
      98                 :             : 
      99                 :             :   // FIXME remove this
     100                 :        3613 :   if (saw_errors ())
     101                 :             :     {
     102                 :         115 :       resolver->pop_module_scope ();
     103                 :         115 :       return;
     104                 :             :     }
     105                 :             : 
     106                 :             :   // next we can drill down into the items and their scopes
     107                 :       17360 :   for (auto it = crate.items.begin (); it != crate.items.end (); it++)
     108                 :       13863 :     ResolveItem::go (it->get (), CanonicalPath::create_empty (), crate_prefix);
     109                 :             : 
     110                 :             :   // done
     111                 :        3497 :   resolver->pop_module_scope ();
     112                 :        3612 : }
     113                 :             : 
     114                 :             : } // namespace Resolver
     115                 :             : } // 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.