LCOV - code coverage report
Current view: top level - gcc/rust/ast - rust-pattern.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 30.8 % 198 61
Test Date: 2024-04-27 14:03:13 Functions: 44.2 % 43 19
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* General AST-related method implementations for Rust frontend.
       2                 :             :    Copyright (C) 2009-2024 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "rust-system.h"
      21                 :             : #include "rust-ast-full.h"
      22                 :             : #include "rust-diagnostics.h"
      23                 :             : #include "rust-ast-visitor.h"
      24                 :             : #include "rust-macro.h"
      25                 :             : #include "rust-session-manager.h"
      26                 :             : #include "rust-lex.h"
      27                 :             : #include "rust-parse.h"
      28                 :             : #include "rust-operators.h"
      29                 :             : 
      30                 :             : namespace Rust {
      31                 :             : namespace AST {
      32                 :             : 
      33                 :             : std::string
      34                 :           0 : LiteralPattern::as_string () const
      35                 :             : {
      36                 :           0 :   return lit.as_string ();
      37                 :             : }
      38                 :             : 
      39                 :             : std::string
      40                 :          34 : IdentifierPattern::as_string () const
      41                 :             : {
      42                 :             :   // TODO: maybe rewrite to work with non-linearisable patterns
      43                 :          34 :   std::string str;
      44                 :             : 
      45                 :          34 :   if (is_ref)
      46                 :           0 :     str += "ref ";
      47                 :             : 
      48                 :          34 :   if (is_mut)
      49                 :           0 :     str += "mut ";
      50                 :             : 
      51                 :          34 :   str += variable_ident.as_string ();
      52                 :             : 
      53                 :          34 :   if (has_pattern_to_bind ())
      54                 :           0 :     str += " @ " + to_bind->as_string ();
      55                 :             : 
      56                 :          34 :   return str;
      57                 :             : }
      58                 :             : 
      59                 :             : std::string
      60                 :           0 : RangePatternBoundLiteral::as_string () const
      61                 :             : {
      62                 :           0 :   std::string str;
      63                 :             : 
      64                 :           0 :   if (has_minus)
      65                 :           0 :     str += "-";
      66                 :             : 
      67                 :           0 :   str += literal.as_string ();
      68                 :             : 
      69                 :           0 :   return str;
      70                 :             : }
      71                 :             : 
      72                 :             : std::string
      73                 :           0 : RangePattern::as_string () const
      74                 :             : {
      75                 :             :   // TODO: maybe rewrite to work with non-linearisable bounds
      76                 :           0 :   if (has_ellipsis_syntax)
      77                 :           0 :     return lower->as_string () + "..." + upper->as_string ();
      78                 :             :   else
      79                 :           0 :     return lower->as_string () + "..=" + upper->as_string ();
      80                 :             : }
      81                 :             : 
      82                 :             : std::string
      83                 :           0 : ReferencePattern::as_string () const
      84                 :             : {
      85                 :             :   // TODO: maybe rewrite to work with non-linearisable patterns
      86                 :           0 :   std::string str ("&");
      87                 :             : 
      88                 :           0 :   if (has_two_amps)
      89                 :           0 :     str += "&";
      90                 :             : 
      91                 :           0 :   if (is_mut)
      92                 :           0 :     str += "mut ";
      93                 :             : 
      94                 :           0 :   str += pattern->as_string ();
      95                 :             : 
      96                 :           0 :   return str;
      97                 :             : }
      98                 :             : 
      99                 :             : std::string
     100                 :           0 : StructPatternField::as_string () const
     101                 :             : {
     102                 :             :   // outer attributes
     103                 :           0 :   std::string str = append_attributes (outer_attrs, OUTER);
     104                 :             : 
     105                 :           0 :   return str;
     106                 :             : }
     107                 :             : 
     108                 :             : std::string
     109                 :           0 : StructPatternFieldTuplePat::as_string () const
     110                 :             : {
     111                 :             :   // TODO: maybe rewrite to work with non-linearisable patterns
     112                 :           0 :   std::string str = StructPatternField::as_string ();
     113                 :             : 
     114                 :           0 :   str += "\n";
     115                 :             : 
     116                 :           0 :   str += std::to_string (index) + " : " + tuple_pattern->as_string ();
     117                 :             : 
     118                 :           0 :   return str;
     119                 :             : }
     120                 :             : 
     121                 :             : std::string
     122                 :           0 : StructPatternFieldIdentPat::as_string () const
     123                 :             : {
     124                 :             :   // TODO: maybe rewrite to work with non-linearisable patterns
     125                 :           0 :   std::string str = StructPatternField::as_string ();
     126                 :             : 
     127                 :           0 :   str += "\n";
     128                 :             : 
     129                 :           0 :   str += ident.as_string () + " : " + ident_pattern->as_string ();
     130                 :             : 
     131                 :           0 :   return str;
     132                 :             : }
     133                 :             : 
     134                 :             : std::string
     135                 :           0 : StructPatternFieldIdent::as_string () const
     136                 :             : {
     137                 :           0 :   std::string str = StructPatternField::as_string ();
     138                 :             : 
     139                 :           0 :   str += "\n";
     140                 :             : 
     141                 :           0 :   if (has_ref)
     142                 :           0 :     str += "ref ";
     143                 :             : 
     144                 :           0 :   if (has_mut)
     145                 :           0 :     str += "mut ";
     146                 :             : 
     147                 :           0 :   str += ident.as_string ();
     148                 :             : 
     149                 :           0 :   return str;
     150                 :             : }
     151                 :             : 
     152                 :             : std::string
     153                 :           0 : StructPatternElements::as_string () const
     154                 :             : {
     155                 :           0 :   std::string str ("\n  Fields: ");
     156                 :             : 
     157                 :           0 :   if (!has_struct_pattern_fields ())
     158                 :             :     {
     159                 :           0 :       str += "none";
     160                 :             :     }
     161                 :             :   else
     162                 :             :     {
     163                 :           0 :       for (const auto &field : fields)
     164                 :           0 :         str += "\n   " + field->as_string ();
     165                 :             :     }
     166                 :             : 
     167                 :           0 :   str += "\n  Etc: ";
     168                 :           0 :   if (has_struct_pattern_etc)
     169                 :           0 :     str += "true";
     170                 :             :   else
     171                 :           0 :     str += "false";
     172                 :             : 
     173                 :           0 :   return str;
     174                 :             : }
     175                 :             : 
     176                 :             : std::string
     177                 :           0 : StructPattern::as_string () const
     178                 :             : {
     179                 :           0 :   std::string str ("StructPattern: \n Path: ");
     180                 :             : 
     181                 :           0 :   str += path.as_string ();
     182                 :             : 
     183                 :           0 :   str += "\n Struct pattern elems: ";
     184                 :           0 :   if (!has_struct_pattern_elems ())
     185                 :           0 :     str += "none";
     186                 :             :   else
     187                 :           0 :     str += elems.as_string ();
     188                 :             : 
     189                 :           0 :   return str;
     190                 :             : }
     191                 :             : 
     192                 :             : std::string
     193                 :           0 : TupleStructItemsNoRange::as_string () const
     194                 :             : {
     195                 :           0 :   std::string str;
     196                 :             : 
     197                 :           0 :   for (const auto &pattern : patterns)
     198                 :           0 :     str += "\n  " + pattern->as_string ();
     199                 :             : 
     200                 :           0 :   return str;
     201                 :             : }
     202                 :             : 
     203                 :             : std::string
     204                 :           0 : TupleStructItemsRange::as_string () const
     205                 :             : {
     206                 :           0 :   std::string str ("\n  Lower patterns: ");
     207                 :             : 
     208                 :           0 :   if (lower_patterns.empty ())
     209                 :             :     {
     210                 :           0 :       str += "none";
     211                 :             :     }
     212                 :             :   else
     213                 :             :     {
     214                 :           0 :       for (const auto &lower : lower_patterns)
     215                 :           0 :         str += "\n   " + lower->as_string ();
     216                 :             :     }
     217                 :             : 
     218                 :           0 :   str += "\n  Upper patterns: ";
     219                 :           0 :   if (upper_patterns.empty ())
     220                 :             :     {
     221                 :           0 :       str += "none";
     222                 :             :     }
     223                 :             :   else
     224                 :             :     {
     225                 :           0 :       for (const auto &upper : upper_patterns)
     226                 :           0 :         str += "\n   " + upper->as_string ();
     227                 :             :     }
     228                 :             : 
     229                 :           0 :   return str;
     230                 :             : }
     231                 :             : 
     232                 :             : std::string
     233                 :           0 : TupleStructPattern::as_string () const
     234                 :             : {
     235                 :           0 :   std::string str ("TupleStructPattern: \n Path: ");
     236                 :             : 
     237                 :           0 :   str += path.as_string ();
     238                 :             : 
     239                 :           0 :   str += "\n Tuple struct items: " + items->as_string ();
     240                 :             : 
     241                 :           0 :   return str;
     242                 :             : }
     243                 :             : 
     244                 :             : std::string
     245                 :           0 : TuplePatternItemsMultiple::as_string () const
     246                 :             : {
     247                 :           0 :   std::string str;
     248                 :             : 
     249                 :           0 :   for (const auto &pattern : patterns)
     250                 :           0 :     str += "\n " + pattern->as_string ();
     251                 :             : 
     252                 :           0 :   return str;
     253                 :             : }
     254                 :             : 
     255                 :             : std::string
     256                 :           0 : TuplePatternItemsRanged::as_string () const
     257                 :             : {
     258                 :           0 :   std::string str;
     259                 :             : 
     260                 :           0 :   str += "\n Lower patterns: ";
     261                 :           0 :   if (lower_patterns.empty ())
     262                 :             :     {
     263                 :           0 :       str += "none";
     264                 :             :     }
     265                 :             :   else
     266                 :             :     {
     267                 :           0 :       for (const auto &lower : lower_patterns)
     268                 :           0 :         str += "\n  " + lower->as_string ();
     269                 :             :     }
     270                 :             : 
     271                 :           0 :   str += "\n Upper patterns: ";
     272                 :           0 :   if (upper_patterns.empty ())
     273                 :             :     {
     274                 :           0 :       str += "none";
     275                 :             :     }
     276                 :             :   else
     277                 :             :     {
     278                 :           0 :       for (const auto &upper : upper_patterns)
     279                 :           0 :         str += "\n  " + upper->as_string ();
     280                 :             :     }
     281                 :             : 
     282                 :           0 :   return str;
     283                 :             : }
     284                 :             : 
     285                 :             : std::string
     286                 :           0 : TuplePattern::as_string () const
     287                 :             : {
     288                 :           0 :   return "TuplePattern: " + items->as_string ();
     289                 :             : }
     290                 :             : 
     291                 :             : std::string
     292                 :           0 : GroupedExpr::as_string () const
     293                 :             : {
     294                 :           0 :   std::string str ("Grouped expr:");
     295                 :             : 
     296                 :             :   // outer attrs
     297                 :           0 :   str += append_attributes (outer_attrs, OUTER);
     298                 :             : 
     299                 :             :   // inner attributes
     300                 :           0 :   str += append_attributes (inner_attrs, INNER);
     301                 :             : 
     302                 :           0 :   str += "\n Expr in parens: " + expr_in_parens->as_string ();
     303                 :             : 
     304                 :           0 :   return str;
     305                 :             : }
     306                 :             : 
     307                 :             : std::string
     308                 :           0 : SlicePattern::as_string () const
     309                 :             : {
     310                 :           0 :   std::string str ("SlicePattern: ");
     311                 :             : 
     312                 :           0 :   for (const auto &pattern : items)
     313                 :           0 :     str += "\n " + pattern->as_string ();
     314                 :             : 
     315                 :           0 :   return str;
     316                 :             : }
     317                 :             : 
     318                 :             : std::string
     319                 :           0 : AltPattern::as_string () const
     320                 :             : {
     321                 :           0 :   std::string str ("AltPattern: ");
     322                 :             : 
     323                 :           0 :   for (const auto &pattern : alts)
     324                 :           0 :     str += "\n " + pattern->as_string ();
     325                 :             : 
     326                 :           0 :   return str;
     327                 :             : }
     328                 :             : 
     329                 :             : void
     330                 :         223 : AltPattern::accept_vis (ASTVisitor &vis)
     331                 :             : {
     332                 :         223 :   vis.visit (*this);
     333                 :         223 : }
     334                 :             : 
     335                 :             : void
     336                 :         210 : GroupedPattern::accept_vis (ASTVisitor &vis)
     337                 :             : {
     338                 :         210 :   vis.visit (*this);
     339                 :         210 : }
     340                 :             : 
     341                 :             : void
     342                 :        1267 : GroupedExpr::accept_vis (ASTVisitor &vis)
     343                 :             : {
     344                 :        1267 :   vis.visit (*this);
     345                 :        1267 : }
     346                 :             : 
     347                 :             : void
     348                 :           0 : SlicePattern::accept_vis (ASTVisitor &vis)
     349                 :             : {
     350                 :           0 :   vis.visit (*this);
     351                 :           0 : }
     352                 :             : 
     353                 :             : void
     354                 :           0 : TuplePatternItemsRanged::accept_vis (ASTVisitor &vis)
     355                 :             : {
     356                 :           0 :   vis.visit (*this);
     357                 :           0 : }
     358                 :             : 
     359                 :             : void
     360                 :        1812 : TuplePattern::accept_vis (ASTVisitor &vis)
     361                 :             : {
     362                 :        1812 :   vis.visit (*this);
     363                 :        1812 : }
     364                 :             : 
     365                 :             : void
     366                 :        1501 : TuplePatternItemsMultiple::accept_vis (ASTVisitor &vis)
     367                 :             : {
     368                 :        1501 :   vis.visit (*this);
     369                 :        1501 : }
     370                 :             : 
     371                 :             : void
     372                 :         876 : LiteralPattern::accept_vis (ASTVisitor &vis)
     373                 :             : {
     374                 :         876 :   vis.visit (*this);
     375                 :         876 : }
     376                 :             : 
     377                 :             : void
     378                 :      120026 : IdentifierPattern::accept_vis (ASTVisitor &vis)
     379                 :             : {
     380                 :      120026 :   vis.visit (*this);
     381                 :      120026 : }
     382                 :             : 
     383                 :             : void
     384                 :        1761 : WildcardPattern::accept_vis (ASTVisitor &vis)
     385                 :             : {
     386                 :        1761 :   vis.visit (*this);
     387                 :        1761 : }
     388                 :             : 
     389                 :             : void
     390                 :           0 : RestPattern::accept_vis (ASTVisitor &vis)
     391                 :             : {
     392                 :           0 :   vis.visit (*this);
     393                 :           0 : }
     394                 :             : 
     395                 :             : void
     396                 :          84 : RangePatternBoundLiteral::accept_vis (ASTVisitor &vis)
     397                 :             : {
     398                 :          84 :   vis.visit (*this);
     399                 :          84 : }
     400                 :             : 
     401                 :             : void
     402                 :          84 : RangePatternBoundPath::accept_vis (ASTVisitor &vis)
     403                 :             : {
     404                 :          84 :   vis.visit (*this);
     405                 :          84 : }
     406                 :             : 
     407                 :             : void
     408                 :           0 : RangePatternBoundQualPath::accept_vis (ASTVisitor &vis)
     409                 :             : {
     410                 :           0 :   vis.visit (*this);
     411                 :           0 : }
     412                 :             : 
     413                 :             : void
     414                 :         126 : RangePattern::accept_vis (ASTVisitor &vis)
     415                 :             : {
     416                 :         126 :   vis.visit (*this);
     417                 :         126 : }
     418                 :             : 
     419                 :             : void
     420                 :         201 : ReferencePattern::accept_vis (ASTVisitor &vis)
     421                 :             : {
     422                 :         201 :   vis.visit (*this);
     423                 :         201 : }
     424                 :             : 
     425                 :             : void
     426                 :           3 : StructPatternFieldTuplePat::accept_vis (ASTVisitor &vis)
     427                 :             : {
     428                 :           3 :   vis.visit (*this);
     429                 :           3 : }
     430                 :             : 
     431                 :             : void
     432                 :           5 : StructPatternFieldIdentPat::accept_vis (ASTVisitor &vis)
     433                 :             : {
     434                 :           5 :   vis.visit (*this);
     435                 :           5 : }
     436                 :             : 
     437                 :             : void
     438                 :         189 : StructPatternFieldIdent::accept_vis (ASTVisitor &vis)
     439                 :             : {
     440                 :         189 :   vis.visit (*this);
     441                 :         189 : }
     442                 :             : 
     443                 :             : void
     444                 :         212 : StructPattern::accept_vis (ASTVisitor &vis)
     445                 :             : {
     446                 :         212 :   vis.visit (*this);
     447                 :         212 : }
     448                 :             : 
     449                 :             : void
     450                 :        1018 : TupleStructItemsNoRange::accept_vis (ASTVisitor &vis)
     451                 :             : {
     452                 :        1018 :   vis.visit (*this);
     453                 :        1018 : }
     454                 :             : 
     455                 :             : void
     456                 :           0 : TupleStructItemsRange::accept_vis (ASTVisitor &vis)
     457                 :             : {
     458                 :           0 :   vis.visit (*this);
     459                 :           0 : }
     460                 :             : 
     461                 :             : void
     462                 :        1319 : TupleStructPattern::accept_vis (ASTVisitor &vis)
     463                 :             : {
     464                 :        1319 :   vis.visit (*this);
     465                 :        1319 : }
     466                 :             : 
     467                 :             : } // namespace AST
     468                 :             : } // 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.