LCOV - code coverage report
Current view: top level - gcc/rust/ast - rust-ast-builder.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 52 52
Test Date: 2024-04-27 14:03:13 Functions: 100.0 % 17 17
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                 :             : #include "rust-ast-builder.h"
      20                 :             : #include "rust-ast-full.h"
      21                 :             : 
      22                 :             : namespace Rust {
      23                 :             : namespace AST {
      24                 :             : 
      25                 :             : std::unique_ptr<Expr>
      26                 :          42 : AstBuilder::call (std::unique_ptr<Expr> &&path,
      27                 :             :                   std::vector<std::unique_ptr<Expr>> &&args)
      28                 :             : {
      29                 :          42 :   return std::unique_ptr<Expr> (
      30                 :          42 :     new CallExpr (std::move (path), std::move (args), {}, loc));
      31                 :             : }
      32                 :             : 
      33                 :             : std::unique_ptr<Expr>
      34                 :          37 : AstBuilder::identifier (std::string name)
      35                 :             : {
      36                 :          74 :   return std::unique_ptr<Expr> (new IdentifierExpr (name, {}, loc));
      37                 :             : }
      38                 :             : 
      39                 :             : std::unique_ptr<Expr>
      40                 :          14 : AstBuilder::tuple_idx (std::string receiver, int idx)
      41                 :             : {
      42                 :          14 :   return std::unique_ptr<Expr> (
      43                 :          14 :     new TupleIndexExpr (identifier (receiver), idx, {}, loc));
      44                 :             : }
      45                 :             : 
      46                 :             : FunctionQualifiers
      47                 :          24 : AstBuilder::fn_qualifiers ()
      48                 :             : {
      49                 :          24 :   return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
      50                 :             : }
      51                 :             : 
      52                 :             : PathExprSegment
      53                 :          92 : AstBuilder::path_segment (std::string seg)
      54                 :             : {
      55                 :          92 :   return PathExprSegment (PathIdentSegment (seg, loc), loc);
      56                 :             : }
      57                 :             : 
      58                 :             : std::unique_ptr<TypePathSegment>
      59                 :          74 : AstBuilder::type_path_segment (std::string seg)
      60                 :             : {
      61                 :          74 :   return std::unique_ptr<TypePathSegment> (
      62                 :          74 :     new TypePathSegment (seg, false, loc));
      63                 :             : }
      64                 :             : 
      65                 :             : std::unique_ptr<Type>
      66                 :          50 : AstBuilder::single_type_path (std::string type)
      67                 :             : {
      68                 :          50 :   auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
      69                 :          50 :   segments.emplace_back (type_path_segment (type));
      70                 :             : 
      71                 :          50 :   return std::unique_ptr<Type> (new TypePath (std::move (segments), loc));
      72                 :          50 : }
      73                 :             : 
      74                 :             : PathInExpression
      75                 :          57 : AstBuilder::path_in_expression (std::vector<std::string> &&segments)
      76                 :             : {
      77                 :          57 :   auto path_segments = std::vector<PathExprSegment> ();
      78                 :         149 :   for (auto &seg : segments)
      79                 :         184 :     path_segments.emplace_back (path_segment (seg));
      80                 :             : 
      81                 :          57 :   return PathInExpression (std::move (path_segments), {}, loc);
      82                 :          57 : }
      83                 :             : 
      84                 :             : std::unique_ptr<Expr>
      85                 :           2 : AstBuilder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
      86                 :             :                    std::unique_ptr<Expr> &&tail_expr)
      87                 :             : {
      88                 :           2 :   return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts),
      89                 :             :                                                std::move (tail_expr), {}, {},
      90                 :           2 :                                                LoopLabel::error (), loc, loc));
      91                 :             : }
      92                 :             : 
      93                 :             : std::unique_ptr<Stmt>
      94                 :           2 : AstBuilder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
      95                 :             :                  std::unique_ptr<Expr> init)
      96                 :             : {
      97                 :           2 :   return std::unique_ptr<Stmt> (new LetStmt (std::move (pattern),
      98                 :             :                                              std::move (init), std::move (type),
      99                 :           2 :                                              {}, loc));
     100                 :             : }
     101                 :             : 
     102                 :             : std::unique_ptr<Expr>
     103                 :          35 : AstBuilder::ref (std::unique_ptr<Expr> &&of, bool mut)
     104                 :             : {
     105                 :          35 :   return std::unique_ptr<Expr> (
     106                 :          35 :     new BorrowExpr (std::move (of), mut, /* is double */ false, {}, loc));
     107                 :             : }
     108                 :             : 
     109                 :             : std::unique_ptr<Expr>
     110                 :           2 : AstBuilder::deref (std::unique_ptr<Expr> &&of)
     111                 :             : {
     112                 :           2 :   return std::unique_ptr<Expr> (new DereferenceExpr (std::move (of), {}, loc));
     113                 :             : }
     114                 :             : 
     115                 :             : std::unique_ptr<Expr>
     116                 :           1 : AstBuilder::struct_expr_struct (std::string struct_name)
     117                 :             : {
     118                 :           1 :   return std::unique_ptr<Expr> (
     119                 :           2 :     new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
     120                 :             : }
     121                 :             : 
     122                 :             : std::unique_ptr<Expr>
     123                 :          14 : AstBuilder::struct_expr (std::string struct_name,
     124                 :             :                          std::vector<std::unique_ptr<StructExprField>> &&fields)
     125                 :             : {
     126                 :          14 :   return std::unique_ptr<Expr> (
     127                 :          42 :     new StructExprStructFields (path_in_expression ({struct_name}),
     128                 :          42 :                                 std::move (fields), loc));
     129                 :             : }
     130                 :             : 
     131                 :             : std::unique_ptr<StructExprField>
     132                 :          21 : AstBuilder::struct_expr_field (std::string field_name,
     133                 :             :                                std::unique_ptr<Expr> &&value)
     134                 :             : {
     135                 :          21 :   return std::unique_ptr<StructExprField> (
     136                 :          21 :     new StructExprFieldIdentifierValue (field_name, std::move (value), loc));
     137                 :             : }
     138                 :             : 
     139                 :             : std::unique_ptr<Expr>
     140                 :          21 : AstBuilder::field_access (std::unique_ptr<Expr> &&instance, std::string field)
     141                 :             : {
     142                 :          21 :   return std::unique_ptr<Expr> (
     143                 :          21 :     new FieldAccessExpr (std::move (instance), field, {}, loc));
     144                 :             : }
     145                 :             : 
     146                 :             : std::unique_ptr<Pattern>
     147                 :           2 : AstBuilder::wildcard ()
     148                 :             : {
     149                 :           2 :   return std::unique_ptr<Pattern> (new WildcardPattern (loc));
     150                 :             : }
     151                 :             : 
     152                 :             : } // namespace AST
     153                 :             : } // 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.