LCOV - code coverage report
Current view: top level - gcc/rust/resolve - rust-ast-resolve-toplevel.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 84.8 % 310 263
Test Date: 2024-04-20 14:03:02 Functions: 71.4 % 35 25
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_AST_RESOLVE_TOPLEVEL_H
      20                 :             : #define RUST_AST_RESOLVE_TOPLEVEL_H
      21                 :             : 
      22                 :             : #include "rust-ast-resolve-base.h"
      23                 :             : #include "rust-ast-resolve-implitem.h"
      24                 :             : #include "rust-name-resolver.h"
      25                 :             : 
      26                 :             : namespace Rust {
      27                 :             : namespace Resolver {
      28                 :             : 
      29                 :       16124 : class ResolveTopLevel : public ResolverBase
      30                 :             : {
      31                 :             :   using Rust::Resolver::ResolverBase::visit;
      32                 :             : 
      33                 :             : public:
      34                 :       16124 :   static void go (AST::Item *item, const CanonicalPath &prefix,
      35                 :             :                   const CanonicalPath &canonical_prefix)
      36                 :             :   {
      37                 :       16124 :     if (item->is_marked_for_strip ())
      38                 :           0 :       return;
      39                 :             : 
      40                 :       32248 :     ResolveTopLevel resolver (prefix, canonical_prefix);
      41                 :       16124 :     item->accept_vis (resolver);
      42                 :             : 
      43                 :       16124 :     NodeId current_module = resolver.resolver->peek_current_module_scope ();
      44                 :       16124 :     resolver.mappings->insert_child_item_to_parent_module_mapping (
      45                 :             :       item->get_node_id (), current_module);
      46                 :       16124 :   }
      47                 :             : 
      48                 :         718 :   void visit (AST::Module &module) override
      49                 :             :   {
      50                 :         718 :     auto mod = CanonicalPath::new_seg (module.get_node_id (),
      51                 :         718 :                                        module.get_name ().as_string ());
      52                 :         718 :     auto path = prefix.append (mod);
      53                 :         718 :     auto cpath = canonical_prefix.append (mod);
      54                 :             : 
      55                 :         718 :     resolver->get_name_scope ().insert (
      56                 :             :       path, module.get_node_id (), module.get_locus (), false,
      57                 :             :       Rib::ItemType::Module,
      58                 :         718 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
      59                 :           0 :         rich_location r (line_table, module.get_locus ());
      60                 :           0 :         r.add_range (locus);
      61                 :           0 :         rust_error_at (r, "redefined multiple times");
      62                 :           0 :       });
      63                 :             : 
      64                 :         718 :     NodeId current_module = resolver->peek_current_module_scope ();
      65                 :         718 :     mappings->insert_module_child_item (current_module, mod);
      66                 :         718 :     mappings->insert_module_child (current_module, module.get_node_id ());
      67                 :             : 
      68                 :         718 :     resolver->push_new_module_scope (module.get_node_id ());
      69                 :        1556 :     for (auto &item : module.get_items ())
      70                 :         838 :       ResolveTopLevel::go (item.get (), path, cpath);
      71                 :             : 
      72                 :         718 :     resolver->pop_module_scope ();
      73                 :             : 
      74                 :         718 :     mappings->insert_canonical_path (module.get_node_id (), cpath);
      75                 :         718 :   }
      76                 :             : 
      77                 :          41 :   void visit (AST::TypeAlias &alias) override
      78                 :             :   {
      79                 :          41 :     auto talias
      80                 :             :       = CanonicalPath::new_seg (alias.get_node_id (),
      81                 :          41 :                                 alias.get_new_type_name ().as_string ());
      82                 :          41 :     auto path = prefix.append (talias);
      83                 :          41 :     auto cpath = canonical_prefix.append (talias);
      84                 :             : 
      85                 :          41 :     resolver->get_type_scope ().insert (
      86                 :             :       path, alias.get_node_id (), alias.get_locus (), false,
      87                 :             :       Rib::ItemType::Type,
      88                 :          41 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
      89                 :           0 :         rich_location r (line_table, alias.get_locus ());
      90                 :           0 :         r.add_range (locus);
      91                 :           0 :         rust_error_at (r, "redefined multiple times");
      92                 :           0 :       });
      93                 :             : 
      94                 :          41 :     NodeId current_module = resolver->peek_current_module_scope ();
      95                 :          41 :     mappings->insert_module_child_item (current_module, talias);
      96                 :          41 :     mappings->insert_canonical_path (alias.get_node_id (), cpath);
      97                 :          41 :   }
      98                 :             : 
      99                 :         706 :   void visit (AST::TupleStruct &struct_decl) override
     100                 :             :   {
     101                 :         706 :     auto decl
     102                 :             :       = CanonicalPath::new_seg (struct_decl.get_node_id (),
     103                 :         706 :                                 struct_decl.get_identifier ().as_string ());
     104                 :         706 :     auto path = prefix.append (decl);
     105                 :         706 :     auto cpath = canonical_prefix.append (decl);
     106                 :             : 
     107                 :         706 :     resolver->get_type_scope ().insert (
     108                 :             :       path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
     109                 :             :       Rib::ItemType::Type,
     110                 :         706 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     111                 :           1 :         rich_location r (line_table, struct_decl.get_locus ());
     112                 :           1 :         r.add_range (locus);
     113                 :           1 :         rust_error_at (r, "redefined multiple times");
     114                 :           1 :       });
     115                 :             : 
     116                 :         706 :     NodeId current_module = resolver->peek_current_module_scope ();
     117                 :         706 :     mappings->insert_module_child_item (current_module, decl);
     118                 :         706 :     mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
     119                 :         706 :   }
     120                 :             : 
     121                 :         197 :   void visit (AST::Enum &enum_decl) override
     122                 :             :   {
     123                 :         197 :     auto decl
     124                 :             :       = CanonicalPath::new_seg (enum_decl.get_node_id (),
     125                 :         197 :                                 enum_decl.get_identifier ().as_string ());
     126                 :         197 :     auto path = prefix.append (decl);
     127                 :         197 :     auto cpath = canonical_prefix.append (decl);
     128                 :             : 
     129                 :         197 :     resolver->get_type_scope ().insert (
     130                 :             :       path, enum_decl.get_node_id (), enum_decl.get_locus (), false,
     131                 :             :       Rib::ItemType::Type,
     132                 :         197 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     133                 :           0 :         rich_location r (line_table, enum_decl.get_locus ());
     134                 :           0 :         r.add_range (locus);
     135                 :           0 :         rust_error_at (r, "redefined multiple times");
     136                 :           0 :       });
     137                 :             : 
     138                 :         197 :     resolver->push_new_module_scope (enum_decl.get_node_id ());
     139                 :         670 :     for (auto &variant : enum_decl.get_variants ())
     140                 :         473 :       ResolveTopLevel::go (variant.get (), path, cpath);
     141                 :             : 
     142                 :         197 :     resolver->pop_module_scope ();
     143                 :             : 
     144                 :         197 :     NodeId current_module = resolver->peek_current_module_scope ();
     145                 :         197 :     mappings->insert_module_child_item (current_module, decl);
     146                 :         197 :     mappings->insert_canonical_path (enum_decl.get_node_id (), cpath);
     147                 :         197 :   }
     148                 :             : 
     149                 :         205 :   void visit (AST::EnumItem &item) override
     150                 :             :   {
     151                 :         205 :     auto decl = CanonicalPath::new_seg (item.get_node_id (),
     152                 :         205 :                                         item.get_identifier ().as_string ());
     153                 :         205 :     auto path = prefix.append (decl);
     154                 :         205 :     auto cpath = canonical_prefix.append (decl);
     155                 :             : 
     156                 :         205 :     resolver->get_type_scope ().insert (
     157                 :         205 :       path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type,
     158                 :         205 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     159                 :           1 :         rich_location r (line_table, item.get_locus ());
     160                 :           1 :         r.add_range (locus);
     161                 :           1 :         rust_error_at (r, "redefined multiple times");
     162                 :           1 :       });
     163                 :             : 
     164                 :         205 :     mappings->insert_canonical_path (item.get_node_id (), cpath);
     165                 :             : 
     166                 :         205 :     NodeId current_module = resolver->peek_current_module_scope ();
     167                 :         205 :     mappings->insert_module_child_item (current_module, decl);
     168                 :         205 :     mappings->insert_module_child (current_module, item.get_node_id ());
     169                 :         205 :   }
     170                 :             : 
     171                 :         218 :   void visit (AST::EnumItemTuple &item) override
     172                 :             :   {
     173                 :         218 :     auto decl = CanonicalPath::new_seg (item.get_node_id (),
     174                 :         218 :                                         item.get_identifier ().as_string ());
     175                 :         218 :     auto path = prefix.append (decl);
     176                 :         218 :     auto cpath = canonical_prefix.append (decl);
     177                 :             : 
     178                 :         218 :     resolver->get_type_scope ().insert (
     179                 :         218 :       path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type,
     180                 :         218 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     181                 :           0 :         rich_location r (line_table, item.get_locus ());
     182                 :           0 :         r.add_range (locus);
     183                 :           0 :         rust_error_at (r, "redefined multiple times");
     184                 :           0 :       });
     185                 :             : 
     186                 :         218 :     mappings->insert_canonical_path (item.get_node_id (), cpath);
     187                 :             : 
     188                 :         218 :     NodeId current_module = resolver->peek_current_module_scope ();
     189                 :         218 :     mappings->insert_module_child_item (current_module, decl);
     190                 :         218 :     mappings->insert_module_child (current_module, item.get_node_id ());
     191                 :         218 :   }
     192                 :             : 
     193                 :          45 :   void visit (AST::EnumItemStruct &item) override
     194                 :             :   {
     195                 :          45 :     auto decl = CanonicalPath::new_seg (item.get_node_id (),
     196                 :          45 :                                         item.get_identifier ().as_string ());
     197                 :          45 :     auto path = prefix.append (decl);
     198                 :          45 :     auto cpath = canonical_prefix.append (decl);
     199                 :             : 
     200                 :          45 :     resolver->get_type_scope ().insert (
     201                 :          45 :       path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type,
     202                 :          45 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     203                 :           1 :         rich_location r (line_table, item.get_locus ());
     204                 :           1 :         r.add_range (locus);
     205                 :           1 :         rust_error_at (r, "redefined multiple times");
     206                 :           1 :       });
     207                 :             : 
     208                 :          45 :     mappings->insert_canonical_path (item.get_node_id (), cpath);
     209                 :             : 
     210                 :          45 :     NodeId current_module = resolver->peek_current_module_scope ();
     211                 :          45 :     mappings->insert_module_child_item (current_module, decl);
     212                 :          45 :     mappings->insert_module_child (current_module, item.get_node_id ());
     213                 :          45 :   }
     214                 :             : 
     215                 :           5 :   void visit (AST::EnumItemDiscriminant &item) override
     216                 :             :   {
     217                 :           5 :     auto decl = CanonicalPath::new_seg (item.get_node_id (),
     218                 :           5 :                                         item.get_identifier ().as_string ());
     219                 :           5 :     auto path = prefix.append (decl);
     220                 :           5 :     auto cpath = canonical_prefix.append (decl);
     221                 :             : 
     222                 :           5 :     resolver->get_type_scope ().insert (
     223                 :           5 :       path, item.get_node_id (), item.get_locus (), false, Rib::ItemType::Type,
     224                 :           5 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     225                 :           0 :         rich_location r (line_table, item.get_locus ());
     226                 :           0 :         r.add_range (locus);
     227                 :           0 :         rust_error_at (r, "redefined multiple times");
     228                 :           0 :       });
     229                 :             : 
     230                 :           5 :     mappings->insert_canonical_path (item.get_node_id (), cpath);
     231                 :             : 
     232                 :           5 :     NodeId current_module = resolver->peek_current_module_scope ();
     233                 :           5 :     mappings->insert_module_child_item (current_module, decl);
     234                 :           5 :     mappings->insert_module_child (current_module, item.get_node_id ());
     235                 :           5 :   }
     236                 :             : 
     237                 :        1013 :   void visit (AST::StructStruct &struct_decl) override
     238                 :             :   {
     239                 :        1013 :     auto decl
     240                 :             :       = CanonicalPath::new_seg (struct_decl.get_node_id (),
     241                 :        1013 :                                 struct_decl.get_identifier ().as_string ());
     242                 :        1013 :     auto path = prefix.append (decl);
     243                 :        1013 :     auto cpath = canonical_prefix.append (decl);
     244                 :             : 
     245                 :        1013 :     resolver->get_type_scope ().insert (
     246                 :             :       path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
     247                 :             :       Rib::ItemType::Type,
     248                 :        1013 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     249                 :           1 :         rich_location r (line_table, struct_decl.get_locus ());
     250                 :           1 :         r.add_range (locus);
     251                 :           1 :         rust_error_at (r, "redefined multiple times");
     252                 :           1 :       });
     253                 :             : 
     254                 :        1013 :     NodeId current_module = resolver->peek_current_module_scope ();
     255                 :        1013 :     mappings->insert_module_child_item (current_module, decl);
     256                 :        1013 :     mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
     257                 :        1013 :   }
     258                 :             : 
     259                 :          96 :   void visit (AST::Union &union_decl) override
     260                 :             :   {
     261                 :          96 :     auto decl
     262                 :             :       = CanonicalPath::new_seg (union_decl.get_node_id (),
     263                 :          96 :                                 union_decl.get_identifier ().as_string ());
     264                 :          96 :     auto path = prefix.append (decl);
     265                 :          96 :     auto cpath = canonical_prefix.append (decl);
     266                 :             : 
     267                 :          96 :     resolver->get_type_scope ().insert (
     268                 :             :       path, union_decl.get_node_id (), union_decl.get_locus (), false,
     269                 :             :       Rib::ItemType::Type,
     270                 :          96 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     271                 :           0 :         rich_location r (line_table, union_decl.get_locus ());
     272                 :           0 :         r.add_range (locus);
     273                 :           0 :         rust_error_at (r, "redefined multiple times");
     274                 :           0 :       });
     275                 :             : 
     276                 :          96 :     NodeId current_module = resolver->peek_current_module_scope ();
     277                 :          96 :     mappings->insert_module_child_item (current_module, decl);
     278                 :          96 :     mappings->insert_canonical_path (union_decl.get_node_id (), cpath);
     279                 :          96 :   }
     280                 :             : 
     281                 :          45 :   void visit (AST::StaticItem &var) override
     282                 :             :   {
     283                 :          45 :     auto decl = CanonicalPath::new_seg (var.get_node_id (),
     284                 :          45 :                                         var.get_identifier ().as_string ());
     285                 :          45 :     auto path = prefix.append (decl);
     286                 :          45 :     auto cpath = canonical_prefix.append (decl);
     287                 :             : 
     288                 :          45 :     resolver->get_name_scope ().insert (
     289                 :             :       path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static,
     290                 :          45 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     291                 :           0 :         rich_location r (line_table, var.get_locus ());
     292                 :           0 :         r.add_range (locus);
     293                 :           0 :         rust_error_at (r, "redefined multiple times");
     294                 :           0 :       });
     295                 :             : 
     296                 :          45 :     NodeId current_module = resolver->peek_current_module_scope ();
     297                 :          45 :     mappings->insert_module_child_item (current_module, decl);
     298                 :          45 :     mappings->insert_canonical_path (var.get_node_id (), cpath);
     299                 :          45 :   }
     300                 :             : 
     301                 :         381 :   void visit (AST::ConstantItem &constant) override
     302                 :             :   {
     303                 :         381 :     auto decl = CanonicalPath::new_seg (constant.get_node_id (),
     304                 :         381 :                                         constant.get_identifier ());
     305                 :         381 :     auto path = prefix.append (decl);
     306                 :         381 :     auto cpath = canonical_prefix.append (decl);
     307                 :             : 
     308                 :         381 :     resolver->get_name_scope ().insert (
     309                 :             :       path, constant.get_node_id (), constant.get_locus (), false,
     310                 :             :       Rib::ItemType::Const,
     311                 :         381 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     312                 :           1 :         rich_location r (line_table, constant.get_locus ());
     313                 :           1 :         r.add_range (locus);
     314                 :           1 :         rust_error_at (r, "redefined multiple times");
     315                 :           1 :       });
     316                 :             : 
     317                 :         381 :     NodeId current_module = resolver->peek_current_module_scope ();
     318                 :         381 :     mappings->insert_module_child_item (current_module, decl);
     319                 :         381 :     mappings->insert_canonical_path (constant.get_node_id (), cpath);
     320                 :         381 :   }
     321                 :             : 
     322                 :        5276 :   void visit (AST::Function &function) override
     323                 :             :   {
     324                 :        5276 :     auto decl
     325                 :             :       = CanonicalPath::new_seg (function.get_node_id (),
     326                 :        5276 :                                 function.get_function_name ().as_string ());
     327                 :        5276 :     auto path = prefix.append (decl);
     328                 :        5276 :     auto cpath = canonical_prefix.append (decl);
     329                 :             : 
     330                 :        5276 :     resolver->get_name_scope ().insert (
     331                 :             :       path, function.get_node_id (), function.get_locus (), false,
     332                 :             :       Rib::ItemType::Function,
     333                 :        5276 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     334                 :           1 :         rich_location r (line_table, function.get_locus ());
     335                 :           1 :         r.add_range (locus);
     336                 :           1 :         rust_error_at (r, "redefined multiple times");
     337                 :           1 :       });
     338                 :             : 
     339                 :        5276 :     NodeId current_module = resolver->peek_current_module_scope ();
     340                 :        5276 :     mappings->insert_module_child_item (current_module, decl);
     341                 :        5276 :     mappings->insert_canonical_path (function.get_node_id (), cpath);
     342                 :        5276 :   }
     343                 :             : 
     344                 :         772 :   void visit (AST::InherentImpl &impl_block) override
     345                 :             :   {
     346                 :         772 :     std::string raw_impl_type_path = impl_block.get_type ()->as_string ();
     347                 :         772 :     CanonicalPath impl_type_seg
     348                 :         772 :       = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (),
     349                 :         772 :                                 raw_impl_type_path);
     350                 :             : 
     351                 :         772 :     CanonicalPath impl_type
     352                 :             :       = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (),
     353                 :         772 :                                           impl_type_seg);
     354                 :         772 :     CanonicalPath impl_prefix = prefix.append (impl_type_seg);
     355                 :             : 
     356                 :        2508 :     for (auto &impl_item : impl_block.get_impl_items ())
     357                 :        1736 :       ResolveToplevelImplItem::go (impl_item.get (), impl_prefix);
     358                 :         772 :   }
     359                 :             : 
     360                 :        2351 :   void visit (AST::TraitImpl &impl_block) override
     361                 :             :   {
     362                 :        2351 :     std::string raw_impl_type_path = impl_block.get_type ()->as_string ();
     363                 :        2351 :     CanonicalPath impl_type_seg
     364                 :        2351 :       = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (),
     365                 :        2351 :                                 raw_impl_type_path);
     366                 :             : 
     367                 :        2351 :     std::string raw_trait_type_path = impl_block.get_trait_path ().as_string ();
     368                 :        2351 :     CanonicalPath trait_type_seg
     369                 :        2351 :       = CanonicalPath::new_seg (impl_block.get_trait_path ().get_node_id (),
     370                 :        2351 :                                 raw_trait_type_path);
     371                 :             : 
     372                 :        2351 :     CanonicalPath projection
     373                 :             :       = CanonicalPath::trait_impl_projection_seg (impl_block.get_node_id (),
     374                 :             :                                                   trait_type_seg,
     375                 :        2351 :                                                   impl_type_seg);
     376                 :        2351 :     CanonicalPath impl_prefix = prefix.append (projection);
     377                 :             : 
     378                 :        2351 :     resolver->get_name_scope ().insert (
     379                 :             :       impl_prefix, impl_block.get_node_id (), impl_block.get_locus (), false,
     380                 :             :       Rib::ItemType::TraitImpl,
     381                 :        2351 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     382                 :           0 :         rich_location r (line_table, impl_block.get_locus ());
     383                 :           0 :         r.add_range (locus);
     384                 :           0 :         rust_error_at (r, "redefined multiple times");
     385                 :           0 :       });
     386                 :             : 
     387                 :        4867 :     for (auto &impl_item : impl_block.get_impl_items ())
     388                 :        2516 :       ResolveToplevelImplItem::go (impl_item.get (), impl_prefix);
     389                 :        2351 :   }
     390                 :             : 
     391                 :        2150 :   void visit (AST::Trait &trait) override
     392                 :             :   {
     393                 :        2150 :     auto decl = CanonicalPath::new_seg (trait.get_node_id (),
     394                 :        2150 :                                         trait.get_identifier ().as_string ());
     395                 :        2150 :     auto path = prefix.append (decl);
     396                 :        2150 :     auto cpath = canonical_prefix.append (decl);
     397                 :             : 
     398                 :        2150 :     resolver->get_type_scope ().insert (
     399                 :             :       path, trait.get_node_id (), trait.get_locus (), false,
     400                 :             :       Rib::ItemType::Trait,
     401                 :        2150 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     402                 :           0 :         rich_location r (line_table, trait.get_locus ());
     403                 :           0 :         r.add_range (locus);
     404                 :           0 :         rust_error_at (r, "redefined multiple times");
     405                 :           0 :       });
     406                 :             : 
     407                 :        3784 :     for (auto &item : trait.get_trait_items ())
     408                 :        1634 :       ResolveTopLevelTraitItems::go (item.get (), path, cpath);
     409                 :             : 
     410                 :        2150 :     NodeId current_module = resolver->peek_current_module_scope ();
     411                 :        2150 :     mappings->insert_module_child_item (current_module, decl);
     412                 :        2150 :     mappings->insert_canonical_path (trait.get_node_id (), cpath);
     413                 :        2150 :   }
     414                 :             : 
     415                 :        1138 :   void visit (AST::ExternBlock &extern_block) override
     416                 :             :   {
     417                 :        2988 :     for (auto &item : extern_block.get_extern_items ())
     418                 :             :       {
     419                 :        1850 :         ResolveToplevelExternItem::go (item.get (), prefix);
     420                 :             :       }
     421                 :        1138 :   }
     422                 :             : 
     423                 :          27 :   void visit (AST::ExternCrate &extern_crate) override
     424                 :             :   {
     425                 :          27 :     if (extern_crate.is_marked_for_strip ())
     426                 :          11 :       return;
     427                 :             : 
     428                 :          27 :     NodeId resolved_crate = UNKNOWN_NODEID;
     429                 :          27 :     if (extern_crate.references_self ())
     430                 :             :       {
     431                 :           0 :         CrateNum crate_num = mappings->get_current_crate ();
     432                 :           0 :         bool ok = mappings->crate_num_to_nodeid (crate_num, resolved_crate);
     433                 :           0 :         rust_assert (ok);
     434                 :             :       }
     435                 :             :     else
     436                 :             :       {
     437                 :          27 :         CrateNum found_crate_num = UNKNOWN_CRATENUM;
     438                 :          27 :         bool found
     439                 :          27 :           = mappings->lookup_crate_name (extern_crate.get_referenced_crate (),
     440                 :             :                                          found_crate_num);
     441                 :          27 :         if (!found)
     442                 :             :           {
     443                 :          11 :             rust_error_at (extern_crate.get_locus (), "unknown crate %<%s%>",
     444                 :          11 :                            extern_crate.get_referenced_crate ().c_str ());
     445                 :          11 :             return;
     446                 :             :           }
     447                 :             : 
     448                 :          16 :         bool ok
     449                 :          16 :           = mappings->crate_num_to_nodeid (found_crate_num, resolved_crate);
     450                 :          16 :         if (!ok)
     451                 :             :           {
     452                 :           0 :             rust_internal_error_at (extern_crate.get_locus (),
     453                 :             :                                     "failed to resolve crate to nodeid");
     454                 :             :             return;
     455                 :             :           }
     456                 :             :       }
     457                 :             : 
     458                 :          16 :     if (resolved_crate == UNKNOWN_NODEID)
     459                 :             :       {
     460                 :           0 :         rust_error_at (extern_crate.get_locus (), "failed to resolve crate");
     461                 :           0 :         return;
     462                 :             :       }
     463                 :             : 
     464                 :             :     // mark the node as resolved
     465                 :          16 :     resolver->insert_resolved_name (extern_crate.get_node_id (),
     466                 :             :                                     resolved_crate);
     467                 :          16 :     CanonicalPath decl
     468                 :          16 :       = extern_crate.has_as_clause ()
     469                 :          16 :           ? CanonicalPath::new_seg (extern_crate.get_node_id (),
     470                 :             :                                     extern_crate.get_as_clause ())
     471                 :             :           : CanonicalPath::new_seg (extern_crate.get_node_id (),
     472                 :          16 :                                     extern_crate.get_referenced_crate ());
     473                 :             : 
     474                 :          16 :     resolver->get_type_scope ().insert (
     475                 :             :       decl, resolved_crate, extern_crate.get_locus (), false,
     476                 :             :       Rib::ItemType::ExternCrate,
     477                 :          16 :       [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
     478                 :           0 :         rich_location r (line_table, extern_crate.get_locus ());
     479                 :           0 :         r.add_range (locus);
     480                 :           0 :         rust_error_at (r, "redefined multiple times");
     481                 :           0 :       });
     482                 :          16 :   }
     483                 :             : 
     484                 :             : private:
     485                 :       16124 :   ResolveTopLevel (const CanonicalPath &prefix,
     486                 :             :                    const CanonicalPath &canonical_prefix)
     487                 :       16124 :     : ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix)
     488                 :             :   {}
     489                 :             : 
     490                 :             :   const CanonicalPath &prefix;
     491                 :             :   const CanonicalPath &canonical_prefix;
     492                 :             : };
     493                 :             : 
     494                 :             : } // namespace Resolver
     495                 :             : } // namespace Rust
     496                 :             : 
     497                 :             : #endif // RUST_AST_RESOLVE_TOPLEVEL_H
        

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.