LCOV - code coverage report
Current view: top level - gcc/text-art - theme.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.2 % 41 37
Test Date: 2024-05-11 15:19:56 Functions: 100.0 % 5 5
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Classes for abstracting ascii vs unicode output.
       2                 :             :    Copyright (C) 2023-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #define INCLUDE_VECTOR
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "pretty-print.h"
      26                 :             : #include "selftest.h"
      27                 :             : #include "text-art/selftests.h"
      28                 :             : #include "text-art/ruler.h"
      29                 :             : #include "text-art/theme.h"
      30                 :             : 
      31                 :             : using namespace text_art;
      32                 :             : 
      33                 :             : /* class theme.  */
      34                 :             : 
      35                 :             : void
      36                 :         300 : theme::paint_y_arrow (canvas &canvas,
      37                 :             :                       int canvas_x,
      38                 :             :                       canvas::range_t y_range,
      39                 :             :                       y_arrow_dir dir,
      40                 :             :                       style::id_t style_id) const
      41                 :             : {
      42                 :         300 :   int canvas_y;
      43                 :         300 :   int delta_y;
      44                 :         300 :   const canvas::cell_t head (get_cppchar (dir == y_arrow_dir::UP
      45                 :             :                                           ? cell_kind::Y_ARROW_UP_HEAD
      46                 :             :                                           : cell_kind::Y_ARROW_DOWN_HEAD),
      47                 :         556 :                              false, style_id);
      48                 :         300 :   const canvas::cell_t tail (get_cppchar (dir == y_arrow_dir::UP
      49                 :             :                                           ? cell_kind::Y_ARROW_UP_TAIL
      50                 :             :                                           : cell_kind::Y_ARROW_DOWN_TAIL),
      51                 :         556 :                              false, style_id);
      52                 :         300 :   if (dir == y_arrow_dir::UP)
      53                 :             :     {
      54                 :          44 :       canvas_y = y_range.get_max ();
      55                 :          44 :       delta_y = -1;
      56                 :             :     }
      57                 :             :   else
      58                 :             :     {
      59                 :             :       canvas_y = y_range.get_min ();
      60                 :             :       delta_y = 1;
      61                 :             :     }
      62                 :        1200 :   for (int len = y_range.get_size (); len; len--)
      63                 :             :     {
      64                 :         900 :       const canvas::cell_t cell = (len > 1) ? tail : head;
      65                 :         900 :       canvas.paint (canvas::coord_t (canvas_x, canvas_y), cell);
      66                 :         900 :       canvas_y += delta_y;
      67                 :         900 :     }
      68                 :         300 : }
      69                 :             : 
      70                 :             : /* class ascii_theme : public theme.  */
      71                 :             : 
      72                 :             : canvas::cell_t
      73                 :        6395 : ascii_theme::get_line_art (directions line_dirs) const
      74                 :             : {
      75                 :        6395 :   if (line_dirs.m_up
      76                 :        1532 :       && line_dirs.m_down
      77                 :        1031 :       && !(line_dirs.m_left || line_dirs.m_right))
      78                 :         436 :     return canvas::cell_t ('|');
      79                 :        5959 :   if (line_dirs.m_left
      80                 :        4765 :       && line_dirs.m_right
      81                 :        4462 :       && !(line_dirs.m_up || line_dirs.m_down))
      82                 :        3471 :     return canvas::cell_t ('-');
      83                 :        2488 :   if (line_dirs.m_up
      84                 :        1392 :       || line_dirs.m_down
      85                 :         891 :       || line_dirs.m_left
      86                 :         891 :       || line_dirs.m_right)
      87                 :        1597 :     return canvas::cell_t ('+');
      88                 :         891 :   return canvas::cell_t (' ');
      89                 :             : }
      90                 :             : 
      91                 :             : cppchar_t
      92                 :        1485 : ascii_theme::get_cppchar (enum cell_kind kind) const
      93                 :             : {
      94                 :        1485 :   switch (kind)
      95                 :             :     {
      96                 :           0 :     default:
      97                 :           0 :       gcc_unreachable ();
      98                 :             :     case cell_kind::X_RULER_LEFT_EDGE:
      99                 :             :       return '|';
     100                 :             :     case cell_kind::X_RULER_MIDDLE:
     101                 :             :       return '~';
     102                 :             :     case cell_kind::X_RULER_INTERNAL_EDGE:
     103                 :             :       return '|';
     104                 :             :     case cell_kind::X_RULER_CONNECTOR_TO_LABEL_BELOW:
     105                 :             :     case cell_kind::X_RULER_CONNECTOR_TO_LABEL_ABOVE:
     106                 :             :       return '+';
     107                 :             :     case cell_kind::X_RULER_RIGHT_EDGE:
     108                 :             :       return '|';
     109                 :             :     case cell_kind::X_RULER_VERTICAL_CONNECTOR:
     110                 :             :       return '|';
     111                 :             : 
     112                 :             :     case cell_kind::TEXT_BORDER_HORIZONTAL:
     113                 :             :       return '-';
     114                 :             :     case cell_kind::TEXT_BORDER_VERTICAL:
     115                 :             :       return '|';
     116                 :             :     case cell_kind::TEXT_BORDER_TOP_LEFT:
     117                 :             :     case cell_kind::TEXT_BORDER_TOP_RIGHT:
     118                 :             :     case cell_kind::TEXT_BORDER_BOTTOM_LEFT:
     119                 :             :     case cell_kind::TEXT_BORDER_BOTTOM_RIGHT:
     120                 :             :       return '+';
     121                 :             : 
     122                 :             :     case cell_kind::Y_ARROW_UP_HEAD: return '^';
     123                 :             :     case cell_kind::Y_ARROW_DOWN_HEAD: return 'v';
     124                 :             : 
     125                 :             :     case cell_kind::Y_ARROW_UP_TAIL:
     126                 :             :     case cell_kind::Y_ARROW_DOWN_TAIL:
     127                 :             :       return '|';
     128                 :             :     }
     129                 :             : }
     130                 :             : 
     131                 :             : /* class unicode_theme : public theme.  */
     132                 :             : 
     133                 :             : canvas::cell_t
     134                 :       16766 : unicode_theme::get_line_art (directions line_dirs) const
     135                 :             : {
     136                 :       16766 :   return canvas::cell_t (get_box_drawing_char (line_dirs));
     137                 :             : }
     138                 :             : 
     139                 :             : cppchar_t
     140                 :        7377 : unicode_theme::get_cppchar (enum cell_kind kind) const
     141                 :             : {
     142                 :        7377 :   switch (kind)
     143                 :             :     {
     144                 :           0 :     default:
     145                 :           0 :       gcc_unreachable ();
     146                 :             :     case cell_kind::X_RULER_LEFT_EDGE:
     147                 :             :       return 0x251C; /* "├": U+251C: BOX DRAWINGS LIGHT VERTICAL AND RIGHT */
     148                 :             :     case cell_kind::X_RULER_MIDDLE:
     149                 :             :       return 0x2500; /* "─": U+2500: BOX DRAWINGS LIGHT HORIZONTAL */
     150                 :             :     case cell_kind::X_RULER_INTERNAL_EDGE:
     151                 :             :       return 0x253C; /* "┼": U+253C: BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
     152                 :             :     case cell_kind::X_RULER_CONNECTOR_TO_LABEL_BELOW:
     153                 :             :       return 0x252C; /* "┬": U+252C: BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */
     154                 :             :     case cell_kind::X_RULER_CONNECTOR_TO_LABEL_ABOVE:
     155                 :             :       return 0x2534; /* "┴": U+2534: BOX DRAWINGS LIGHT UP AND HORIZONTAL */
     156                 :             :     case cell_kind::X_RULER_RIGHT_EDGE:
     157                 :             :       return 0x2524; /* "┤": U+2524: BOX DRAWINGS LIGHT VERTICAL AND LEFT */
     158                 :             :     case cell_kind::X_RULER_VERTICAL_CONNECTOR:
     159                 :             :       return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */
     160                 :             : 
     161                 :             :     case cell_kind::TEXT_BORDER_HORIZONTAL:
     162                 :             :       return 0x2500; /* "─": U+2500: BOX DRAWINGS LIGHT HORIZONTAL */
     163                 :             :     case cell_kind::TEXT_BORDER_VERTICAL:
     164                 :             :       return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */
     165                 :             : 
     166                 :             :     /* Round corners.  */
     167                 :             :     case cell_kind::TEXT_BORDER_TOP_LEFT:
     168                 :             :       return 0x256D; /* "╭": U+256D BOX DRAWINGS LIGHT ARC DOWN AND RIGHT.  */
     169                 :             :     case cell_kind::TEXT_BORDER_TOP_RIGHT:
     170                 :             :       return 0x256E; /* "╮": U+256E BOX DRAWINGS LIGHT ARC DOWN AND LEFT.  */
     171                 :             :     case cell_kind::TEXT_BORDER_BOTTOM_LEFT:
     172                 :             :       return 0x2570; /* "╰": U+2570 BOX DRAWINGS LIGHT ARC UP AND RIGHT.  */
     173                 :             :     case cell_kind::TEXT_BORDER_BOTTOM_RIGHT:
     174                 :             :       return 0x256F; /* "╯": U+256F BOX DRAWINGS LIGHT ARC UP AND LEFT.  */
     175                 :             : 
     176                 :             :     case cell_kind::Y_ARROW_UP_HEAD:
     177                 :             :       return '^';
     178                 :             :     case cell_kind::Y_ARROW_DOWN_HEAD:
     179                 :             :       return 'v';
     180                 :             :     case cell_kind::Y_ARROW_UP_TAIL:
     181                 :             :     case cell_kind::Y_ARROW_DOWN_TAIL:
     182                 :             :       return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */
     183                 :             :     }
     184                 :             : }
        

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.