LCOV - code coverage report
Current view: top level - gcc/rust/parse - rust-parse-error.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 72.6 % 62 45
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2025-2026 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_PARSE_ERROR_H
      20              : #define RUST_PARSE_ERROR_H
      21              : 
      22              : #include "expected.h"
      23              : #include "rust-ast.h"
      24              : #include "rust-parse-utils.h"
      25              : 
      26              : namespace Rust {
      27              : namespace Parse {
      28              : namespace Error {
      29              : 
      30              : struct Attribute
      31              : {
      32            0 :   static tl::expected<AST::Attribute, Attribute> make_malformed ()
      33              :   {
      34            0 :     return tl::unexpected<Attribute> (Attribute (Kind::MALFORMED));
      35              :   }
      36              : 
      37            7 :   static tl::expected<AST::Attribute, Attribute> make_malformed_body ()
      38              :   {
      39            7 :     return tl::unexpected<Attribute> (Attribute (Kind::MALFORMED_BODY));
      40              :   }
      41              : 
      42            2 :   static tl::expected<AST::Attribute, Attribute> make_unexpected_inner ()
      43              :   {
      44            2 :     return tl::unexpected<Attribute> (Attribute (Kind::UNEXPECTED_INNER));
      45              :   }
      46              : 
      47              :   enum class Kind
      48              :   {
      49              :     MALFORMED,
      50              :     MALFORMED_BODY,
      51              :     UNEXPECTED_INNER,
      52              :   } kind;
      53              : 
      54              : private:
      55            9 :   Attribute (Kind kind) : kind (kind) {}
      56              : };
      57              : 
      58              : struct AttributeBody
      59              : {
      60            0 :   static tl::expected<Parse::AttributeBody, AttributeBody> make_invalid_path ()
      61              :   {
      62            0 :     return tl::unexpected<AttributeBody> (AttributeBody (Kind::INVALID_PATH));
      63              :   }
      64              : 
      65              :   static tl::expected<Parse::AttributeBody, AttributeBody>
      66            7 :   make_invalid_attrinput ()
      67              :   {
      68            7 :     return tl::unexpected<AttributeBody> (
      69            7 :       AttributeBody (Kind::INVALID_ATTRINPUT));
      70              :   }
      71              : 
      72              :   enum class Kind
      73              :   {
      74              :     INVALID_PATH,
      75              :     INVALID_ATTRINPUT,
      76              :   } kind;
      77              : 
      78              : private:
      79            7 :   AttributeBody (Kind kind) : kind (kind) {}
      80              : };
      81              : 
      82              : struct SimplePathSegment
      83              : {
      84              :   static tl::expected<AST::SimplePathSegment, SimplePathSegment>
      85          220 :   make_invalid_token_or_path_end ()
      86              :   {
      87          220 :     return tl::unexpected<SimplePathSegment> (
      88          220 :       SimplePathSegment (Kind::INVALID_SIMPLE_PATH_TOKEN));
      89              :   }
      90              : 
      91              :   enum class Kind
      92              :   {
      93              :     /* Invalid token found whilst parsing a simple path segment, could be an
      94              :        error or the end of the path */
      95              :     INVALID_SIMPLE_PATH_TOKEN,
      96              :   } kind;
      97              : 
      98              : private:
      99          220 :   SimplePathSegment (Kind kind) : kind (kind) {}
     100              : };
     101              : 
     102              : struct PathIdentSegment
     103              : {
     104              :   static tl::expected<AST::PathIdentSegment, PathIdentSegment>
     105          211 :   make_invalid_token ()
     106              :   {
     107          211 :     return tl::unexpected<PathIdentSegment> (
     108          211 :       PathIdentSegment (Kind::INVALID_PATH_IDENT_TOKEN));
     109              :   }
     110              : 
     111              :   enum class Kind
     112              :   {
     113              :     INVALID_PATH_IDENT_TOKEN,
     114              :   } kind;
     115              : 
     116              : private:
     117          211 :   PathIdentSegment (Kind kind) : kind (kind) {}
     118              : };
     119              : 
     120              : struct AttrInput
     121              : {
     122              :   static tl::expected<std::unique_ptr<AST::AttrInput>, AttrInput>
     123            0 :   make_malformed ()
     124              :   {
     125            0 :     return tl::unexpected<AttrInput> (AttrInput (Kind::MALFORMED));
     126              :   }
     127              : 
     128              :   static tl::expected<std::unique_ptr<AST::AttrInput>, AttrInput>
     129            0 :   make_bad_macro_invocation ()
     130              :   {
     131            0 :     return tl::unexpected<AttrInput> (AttrInput (Kind::BAD_MACRO_INVOCATION));
     132              :   }
     133              : 
     134              :   static tl::expected<std::unique_ptr<AST::AttrInput>, AttrInput>
     135         6372 :   make_missing_attrinput ()
     136              :   {
     137         6372 :     return tl::unexpected<AttrInput> (AttrInput (Kind::MISSING));
     138              :   }
     139              : 
     140              :   static tl::expected<std::unique_ptr<AST::AttrInput>, AttrInput>
     141            7 :   make_bad_token_tree ()
     142              :   {
     143            7 :     return tl::unexpected<AttrInput> (AttrInput (Kind::BAD_TOKEN_TREE));
     144              :   }
     145              : 
     146              :   enum class Kind
     147              :   {
     148              :     MALFORMED,
     149              :     BAD_MACRO_INVOCATION,
     150              :     BAD_TOKEN_TREE,
     151              :     // Not an hard error in some context
     152              :     MISSING,
     153              :   } kind;
     154              : 
     155              : private:
     156         6379 :   AttrInput (Kind kind) : kind (kind) {}
     157              : };
     158              : 
     159              : struct Item
     160              : {
     161            7 :   static tl::expected<std::unique_ptr<AST::Item>, Item> make_end_of_file ()
     162              :   {
     163            7 :     return tl::unexpected<Item> (Item (Kind::END_OF_FILE));
     164              :   }
     165              : 
     166           68 :   static tl::expected<std::unique_ptr<AST::Item>, Item> make_malformed ()
     167              :   {
     168           68 :     return tl::unexpected<Item> (Item (Kind::MALFORMED));
     169              :   }
     170              : 
     171              :   enum class Kind
     172              :   {
     173              :     END_OF_FILE,
     174              :     MALFORMED,
     175              :   } kind;
     176              : 
     177              : private:
     178           75 :   Item (Kind kind) : kind (kind) {}
     179              : };
     180              : 
     181          148 : struct Items
     182              : {
     183              :   static tl::expected<std::vector<std::unique_ptr<AST::Item>>, Items>
     184           74 :   make_malformed (std::vector<std::unique_ptr<AST::Item>> items)
     185              :   {
     186           74 :     return tl::unexpected<Items> (Items (Kind::MALFORMED, std::move (items)));
     187              :   }
     188              : 
     189              :   enum class Kind
     190              :   {
     191              :     MALFORMED,
     192              :   } kind;
     193              : 
     194              :   Items (Items const &) = delete;
     195              :   Items &operator= (Items const &) = delete;
     196              : 
     197           74 :   Items (Items &&items) = default;
     198              :   Items &operator= (Items &&) = default;
     199              : 
     200              :   // Should we do anything with valid items ?
     201              :   std::vector<std::unique_ptr<AST::Item>> items;
     202              : 
     203              : private:
     204           74 :   Items (Kind kind, std::vector<std::unique_ptr<AST::Item>> items)
     205           74 :     : kind (kind), items (std::move (items))
     206              :   {}
     207              : };
     208              : 
     209              : struct Visibility
     210              : {
     211            0 :   static tl::expected<AST::Visibility, Visibility> make_malformed ()
     212              :   {
     213            0 :     return tl::unexpected<Visibility> (Visibility (Kind::MALFORMED));
     214              :   }
     215              : 
     216            0 :   static tl::expected<AST::Visibility, Visibility> make_missing_path ()
     217              :   {
     218            0 :     return tl::unexpected<Visibility> (Visibility (Kind::MISSING_PATH));
     219              :   }
     220              : 
     221              :   enum class Kind
     222              :   {
     223              :     MISSING_PATH,
     224              :     MALFORMED,
     225              :   } kind;
     226              : 
     227              : private:
     228            0 :   Visibility (Kind kind) : kind (kind) {}
     229              : };
     230              : 
     231              : struct LifetimeParam
     232              : {
     233              :   static tl::expected<AST::LifetimeParam, LifetimeParam>
     234            2 :   make_not_a_lifetime_param ()
     235              :   {
     236            2 :     return tl::unexpected<LifetimeParam> (
     237            2 :       LifetimeParam (Kind::NOT_A_LIFETIME_PARAM));
     238              :   }
     239              : 
     240              :   enum class Kind
     241              :   {
     242              :     NOT_A_LIFETIME_PARAM,
     243              :   } kind;
     244              : 
     245              : private:
     246            2 :   LifetimeParam (Kind kind) : kind (kind) {}
     247              : };
     248              : 
     249              : class Lifetime
     250              : {
     251              : };
     252              : 
     253              : struct LoopLabel
     254              : {
     255            0 :   static tl::expected<AST::LoopLabel, LoopLabel> make_not_loop_label ()
     256              :   {
     257            0 :     return tl::unexpected<LoopLabel> (LoopLabel (Kind::NOT_LOOP_LABEL));
     258              :   }
     259              : 
     260           40 :   static tl::expected<AST::LoopLabel, LoopLabel> make_missing_colon ()
     261              :   {
     262           40 :     return tl::unexpected<LoopLabel> (LoopLabel (Kind::MISSING_COLON));
     263              :   }
     264              : 
     265              :   enum class Kind
     266              :   {
     267              :     // Not an hard error
     268              :     NOT_LOOP_LABEL,
     269              :     // Hard error
     270              :     MISSING_COLON,
     271              :   } kind;
     272              : 
     273              : private:
     274           40 :   LoopLabel (Kind kind) : kind (kind) {}
     275              : };
     276              : 
     277              : struct Self
     278              : {
     279              :   static tl::expected<std::unique_ptr<AST::Param>, Self>
     280            3 :   make_self_raw_pointer ()
     281              :   {
     282            3 :     return tl::unexpected<Self> (Self (Kind::SELF_RAW_PTR));
     283              :   }
     284              : 
     285        10338 :   static tl::expected<std::unique_ptr<AST::Param>, Self> make_not_self ()
     286              :   {
     287        10338 :     return tl::unexpected<Self> (Self (Kind::NOT_SELF));
     288              :   }
     289              : 
     290            0 :   static tl::expected<std::unique_ptr<AST::Param>, Self> make_parsing_error ()
     291              :   {
     292            0 :     return tl::unexpected<Self> (Self (Kind::PARSING));
     293              :   }
     294              : 
     295              :   enum class Kind
     296              :   {
     297              :     SELF_RAW_PTR,
     298              :     PARSING,
     299              :     NOT_SELF,
     300              :   } kind;
     301              : 
     302              : private:
     303        10341 :   Self (Kind kind) : kind (kind) {}
     304              : };
     305              : 
     306              : enum class Expr
     307              : {
     308              :   MALFORMED,
     309              :   CHILD_ERROR,
     310              :   NULL_EXPR,
     311              :   NULL_DENOTATION,
     312              :   LEFT_DENOTATION,
     313              : };
     314              : 
     315              : enum class StructExprField
     316              : {
     317              :   MALFORMED,
     318              :   CHILD_ERROR,
     319              :   // Not a hard error
     320              :   STRUCT_BASE,
     321              : };
     322              : 
     323              : // Generic intermediate AST node error used when the errors need no special
     324              : // handling
     325              : enum class Node
     326              : {
     327              :   // Unexpected or missing token whilst parsing the node
     328              :   MALFORMED,
     329              :   // Error whilst parsing a child construct for the current node
     330              :   CHILD_ERROR,
     331              : };
     332              : 
     333              : } // namespace Error
     334              : } // namespace Parse
     335              : } // namespace Rust
     336              : 
     337              : #endif /* !RUST_PARSE_ERROR_H */
        

Generated by: LCOV version 2.4-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.