LCOV - code coverage report
Current view: top level - gcc/rust/ast - rust-ast-dump.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 26 24
Test Date: 2024-04-27 14:03:13 Functions: 33.3 % 3 1
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                 :             : #ifndef RUST_AST_DUMP_H
      19                 :             : #define RUST_AST_DUMP_H
      20                 :             : 
      21                 :             : #include "rust-ast-visitor.h"
      22                 :             : #include "rust-ast.h"
      23                 :             : #include "rust-ast-full.h"
      24                 :             : #include "rust-dump.h"
      25                 :             : 
      26                 :             : #include "rust-ast-collector.h"
      27                 :             : 
      28                 :             : namespace Rust {
      29                 :             : namespace AST {
      30                 :             : 
      31                 :             : class Dump
      32                 :             : {
      33                 :             : public:
      34                 :             :   Dump (std::ostream &stream);
      35                 :             : 
      36                 :             :   /**
      37                 :             :    * Run the visitor on an entire crate and its items
      38                 :             :    */
      39                 :             :   void go (AST::Crate &crate);
      40                 :             :   void go (AST::Item &item);
      41                 :             : 
      42                 :        2052 :   template <typename T> void process (T &v)
      43                 :             :   {
      44                 :        2052 :     TokenCollector collector;
      45                 :        2052 :     collector.visit (v);
      46                 :             : 
      47                 :        2052 :     TokenPtr previous = nullptr;
      48                 :       49423 :     for (auto item : collector.collect ())
      49                 :             :       {
      50                 :       47371 :         switch (item.get_kind ())
      51                 :             :           {
      52                 :       36539 :             case AST::CollectItem::Kind::Token: {
      53                 :       36539 :               TokenPtr current = item.get_token ();
      54                 :      134504 :               if (require_spacing (previous, current))
      55                 :       18742 :                 stream << " ";
      56                 :       36539 :               stream << current->as_string ();
      57                 :       36539 :               previous = current;
      58                 :       36539 :             }
      59                 :       36539 :             break;
      60                 :          63 :           case AST::CollectItem::Kind::Comment:
      61                 :          63 :             stream << " /* " << item.get_comment () << " */ ";
      62                 :          63 :             break;
      63                 :             :           case AST::CollectItem::Kind::Indentation:
      64                 :        5885 :             for (size_t i = 0; i < item.get_indent_level (); i++)
      65                 :             :               {
      66                 :        1824 :                 stream << "    ";
      67                 :             :               }
      68                 :             :             break;
      69                 :        6708 :           case AST::CollectItem::Kind::Newline:
      70                 :        6708 :             stream << "\n";
      71                 :        6708 :             previous = nullptr;
      72                 :        6708 :             break;
      73                 :           0 :           default:
      74                 :           0 :             rust_unreachable ();
      75                 :             :           }
      76                 :             :       }
      77                 :        2052 :   }
      78                 :             : 
      79                 :             :   // Helper method to get a quick debug dump to standard error output
      80                 :             :   static void debug (Visitable &v);
      81                 :             : 
      82                 :             : private:
      83                 :             :   std::ostream &stream;
      84                 :             :   Indent indentation;
      85                 :             : 
      86                 :             :   static bool require_spacing (TokenPtr previous, TokenPtr current);
      87                 :             : };
      88                 :             : 
      89                 :             : } // namespace AST
      90                 :             : } // namespace Rust
      91                 :             : 
      92                 :             : // In the global namespace to make it easier to call from debugger
      93                 :             : void
      94                 :             : debug (Rust::AST::Visitable &v);
      95                 :             : 
      96                 :             : #endif // !RUST_AST_DUMP_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.