LCOV - code coverage report
Current view: top level - gcc/rust/hir - rust-ast-lower-base.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 14 14
Test Date: 2024-12-21 13:15:12 Functions: 50.0 % 4 2
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                 :             : #ifndef RUST_AST_LOWER_BASE
      20                 :             : #define RUST_AST_LOWER_BASE
      21                 :             : 
      22                 :             : #include "rust-ast.h"
      23                 :             : #include "rust-system.h"
      24                 :             : #include "rust-ast-full.h"
      25                 :             : #include "rust-ast-visitor.h"
      26                 :             : #include "rust-hir-map.h"
      27                 :             : #include "rust-hir-full.h"
      28                 :             : #include "rust-attributes.h"
      29                 :             : 
      30                 :             : namespace Rust {
      31                 :             : namespace HIR {
      32                 :             : 
      33                 :             : // proxy class so we can do attribute checking on items and trait items
      34                 :             : class ItemWrapper
      35                 :             : {
      36                 :             : public:
      37                 :       18116 :   ItemWrapper (const HIR::Item &item)
      38                 :       18116 :     : mappings (item.get_mappings ()), locus (item.get_locus ()),
      39                 :       18116 :       outer_attrs (item.get_outer_attrs ())
      40                 :             :   {}
      41                 :             : 
      42                 :        1523 :   ItemWrapper (const HIR::TraitItem &item)
      43                 :        1523 :     : mappings (item.get_mappings ()), locus (item.get_trait_locus ()),
      44                 :        1523 :       outer_attrs (item.get_outer_attrs ())
      45                 :        1523 :   {}
      46                 :             : 
      47                 :        1780 :   const Analysis::NodeMapping &get_mappings () const { return mappings; }
      48                 :             :   location_t get_locus () const { return locus; }
      49                 :       19639 :   const AST::AttrVec &get_outer_attrs () const { return outer_attrs; }
      50                 :             : 
      51                 :             : private:
      52                 :             :   const Analysis::NodeMapping &mappings;
      53                 :             :   location_t locus;
      54                 :             :   const AST::AttrVec &outer_attrs;
      55                 :             : };
      56                 :             : 
      57                 :             : // base class to allow derivatives to overload as needed
      58                 :             : class ASTLoweringBase : public AST::ASTVisitor
      59                 :             : {
      60                 :             : public:
      61                 :      176995 :   virtual ~ASTLoweringBase () {}
      62                 :             : 
      63                 :             :   // visitor impl
      64                 :             :   // rust-ast.h
      65                 :             :   //  virtual void visit(AttrInput& attr_input);
      66                 :             :   //  virtual void visit(TokenTree& token_tree);
      67                 :             :   //  virtual void visit(MacroMatch& macro_match);
      68                 :             :   virtual void visit (AST::Token &tok);
      69                 :             :   virtual void visit (AST::DelimTokenTree &delim_tok_tree);
      70                 :             :   virtual void visit (AST::AttrInputMetaItemContainer &input);
      71                 :             :   //  virtual void visit(MetaItem& meta_item);
      72                 :             :   //  void vsit(Stmt& stmt);
      73                 :             :   //  virtual void visit(Expr& expr);
      74                 :             :   virtual void visit (AST::IdentifierExpr &ident_expr);
      75                 :             :   //  virtual void visit(Pattern& pattern);
      76                 :             :   //  virtual void visit(Type& type);
      77                 :             :   //  virtual void visit(TypeParamBound& type_param_bound);
      78                 :             :   virtual void visit (AST::Lifetime &lifetime);
      79                 :             :   //  virtual void visit(GenericParam& generic_param);
      80                 :             :   virtual void visit (AST::LifetimeParam &lifetime_param);
      81                 :             :   virtual void visit (AST::ConstGenericParam &const_param);
      82                 :             :   //  virtual void visit(TraitItem& trait_item);
      83                 :             :   //  virtual void visit(InherentImplItem& inherent_impl_item);
      84                 :             :   //  virtual void visit(TraitImplItem& trait_impl_item);
      85                 :             : 
      86                 :             :   // rust-path.h
      87                 :             :   virtual void visit (AST::PathInExpression &path);
      88                 :             :   virtual void visit (AST::TypePathSegment &segment);
      89                 :             :   virtual void visit (AST::TypePathSegmentGeneric &segment);
      90                 :             :   virtual void visit (AST::TypePathSegmentFunction &segment);
      91                 :             :   virtual void visit (AST::TypePath &path);
      92                 :             :   virtual void visit (AST::QualifiedPathInExpression &path);
      93                 :             :   virtual void visit (AST::QualifiedPathInType &path);
      94                 :             : 
      95                 :             :   // rust-expr.h
      96                 :             :   virtual void visit (AST::LiteralExpr &expr);
      97                 :             :   virtual void visit (AST::AttrInputLiteral &attr_input);
      98                 :             :   virtual void visit (AST::AttrInputMacro &attr_input);
      99                 :             :   virtual void visit (AST::MetaItemLitExpr &meta_item);
     100                 :             :   virtual void visit (AST::MetaItemPathLit &meta_item);
     101                 :             :   virtual void visit (AST::BorrowExpr &expr);
     102                 :             :   virtual void visit (AST::DereferenceExpr &expr);
     103                 :             :   virtual void visit (AST::ErrorPropagationExpr &expr);
     104                 :             :   virtual void visit (AST::NegationExpr &expr);
     105                 :             :   virtual void visit (AST::ArithmeticOrLogicalExpr &expr);
     106                 :             :   virtual void visit (AST::ComparisonExpr &expr);
     107                 :             :   virtual void visit (AST::LazyBooleanExpr &expr);
     108                 :             :   virtual void visit (AST::TypeCastExpr &expr);
     109                 :             :   virtual void visit (AST::AssignmentExpr &expr);
     110                 :             :   virtual void visit (AST::CompoundAssignmentExpr &expr);
     111                 :             :   virtual void visit (AST::GroupedExpr &expr);
     112                 :             :   //  virtual void visit(ArrayElems& elems);
     113                 :             :   virtual void visit (AST::ArrayElemsValues &elems);
     114                 :             :   virtual void visit (AST::ArrayElemsCopied &elems);
     115                 :             :   virtual void visit (AST::ArrayExpr &expr);
     116                 :             :   virtual void visit (AST::ArrayIndexExpr &expr);
     117                 :             :   virtual void visit (AST::TupleExpr &expr);
     118                 :             :   virtual void visit (AST::TupleIndexExpr &expr);
     119                 :             :   virtual void visit (AST::StructExprStruct &expr);
     120                 :             :   //  virtual void visit(StructExprField& field);
     121                 :             :   virtual void visit (AST::StructExprFieldIdentifier &field);
     122                 :             :   virtual void visit (AST::StructExprFieldIdentifierValue &field);
     123                 :             :   virtual void visit (AST::StructExprFieldIndexValue &field);
     124                 :             :   virtual void visit (AST::StructExprStructFields &expr);
     125                 :             :   virtual void visit (AST::StructExprStructBase &expr);
     126                 :             :   virtual void visit (AST::CallExpr &expr);
     127                 :             :   virtual void visit (AST::MethodCallExpr &expr);
     128                 :             :   virtual void visit (AST::FieldAccessExpr &expr);
     129                 :             :   virtual void visit (AST::ClosureExprInner &expr);
     130                 :             :   virtual void visit (AST::BlockExpr &expr);
     131                 :             :   virtual void visit (AST::ClosureExprInnerTyped &expr);
     132                 :             :   virtual void visit (AST::ContinueExpr &expr);
     133                 :             :   virtual void visit (AST::BreakExpr &expr);
     134                 :             :   virtual void visit (AST::RangeFromToExpr &expr);
     135                 :             :   virtual void visit (AST::RangeFromExpr &expr);
     136                 :             :   virtual void visit (AST::RangeToExpr &expr);
     137                 :             :   virtual void visit (AST::RangeFullExpr &expr);
     138                 :             :   virtual void visit (AST::RangeFromToInclExpr &expr);
     139                 :             :   virtual void visit (AST::RangeToInclExpr &expr);
     140                 :             :   virtual void visit (AST::ReturnExpr &expr);
     141                 :             :   virtual void visit (AST::UnsafeBlockExpr &expr);
     142                 :             :   virtual void visit (AST::LoopExpr &expr);
     143                 :             :   virtual void visit (AST::WhileLoopExpr &expr);
     144                 :             :   virtual void visit (AST::WhileLetLoopExpr &expr);
     145                 :             :   virtual void visit (AST::ForLoopExpr &expr);
     146                 :             :   virtual void visit (AST::IfExpr &expr);
     147                 :             :   virtual void visit (AST::IfExprConseqElse &expr);
     148                 :             :   virtual void visit (AST::IfLetExpr &expr);
     149                 :             :   virtual void visit (AST::IfLetExprConseqElse &expr);
     150                 :             :   //  virtual void visit(MatchCase& match_case);
     151                 :             :   // virtual void visit (AST::MatchCaseBlockExpr &match_case);
     152                 :             :   // virtual void visit (AST::MatchCaseExpr &match_case);
     153                 :             :   virtual void visit (AST::MatchExpr &expr);
     154                 :             :   virtual void visit (AST::AwaitExpr &expr);
     155                 :             :   virtual void visit (AST::AsyncBlockExpr &expr);
     156                 :             : 
     157                 :             :   // rust-item.h
     158                 :             :   virtual void visit (AST::TypeParam &param);
     159                 :             :   //  virtual void visit(WhereClauseItem& item);
     160                 :             :   virtual void visit (AST::LifetimeWhereClauseItem &item);
     161                 :             :   virtual void visit (AST::TypeBoundWhereClauseItem &item);
     162                 :             :   virtual void visit (AST::Module &module);
     163                 :             :   virtual void visit (AST::ExternCrate &crate);
     164                 :             :   //  virtual void visit(UseTree& use_tree);
     165                 :             :   virtual void visit (AST::UseTreeGlob &use_tree);
     166                 :             :   virtual void visit (AST::UseTreeList &use_tree);
     167                 :             :   virtual void visit (AST::UseTreeRebind &use_tree);
     168                 :             :   virtual void visit (AST::UseDeclaration &use_decl);
     169                 :             :   virtual void visit (AST::Function &function);
     170                 :             :   virtual void visit (AST::TypeAlias &type_alias);
     171                 :             :   virtual void visit (AST::StructStruct &struct_item);
     172                 :             :   virtual void visit (AST::TupleStruct &tuple_struct);
     173                 :             :   virtual void visit (AST::EnumItem &item);
     174                 :             :   virtual void visit (AST::EnumItemTuple &item);
     175                 :             :   virtual void visit (AST::EnumItemStruct &item);
     176                 :             :   virtual void visit (AST::EnumItemDiscriminant &item);
     177                 :             :   virtual void visit (AST::Enum &enum_item);
     178                 :             :   virtual void visit (AST::Union &union_item);
     179                 :             :   virtual void visit (AST::ConstantItem &const_item);
     180                 :             :   virtual void visit (AST::StaticItem &static_item);
     181                 :             :   virtual void visit (AST::TraitItemConst &item);
     182                 :             :   virtual void visit (AST::TraitItemType &item);
     183                 :             :   virtual void visit (AST::Trait &trait);
     184                 :             :   virtual void visit (AST::InherentImpl &impl);
     185                 :             :   virtual void visit (AST::TraitImpl &impl);
     186                 :             :   //  virtual void visit(ExternalItem& item);
     187                 :             :   virtual void visit (AST::ExternalTypeItem &item);
     188                 :             :   virtual void visit (AST::ExternalStaticItem &item);
     189                 :             :   virtual void visit (AST::ExternBlock &block);
     190                 :             : 
     191                 :             :   // rust-macro.h
     192                 :             :   virtual void visit (AST::MacroMatchFragment &match);
     193                 :             :   virtual void visit (AST::MacroMatchRepetition &match);
     194                 :             :   virtual void visit (AST::MacroMatcher &matcher);
     195                 :             :   virtual void visit (AST::MacroRulesDefinition &rules_def);
     196                 :             :   virtual void visit (AST::MacroInvocation &macro_invoc);
     197                 :             :   virtual void visit (AST::MetaItemPath &meta_item);
     198                 :             :   virtual void visit (AST::MetaItemSeq &meta_item);
     199                 :             :   virtual void visit (AST::MetaWord &meta_item);
     200                 :             :   virtual void visit (AST::MetaNameValueStr &meta_item);
     201                 :             :   virtual void visit (AST::MetaListPaths &meta_item);
     202                 :             :   virtual void visit (AST::MetaListNameValueStr &meta_item);
     203                 :             : 
     204                 :             :   // rust-pattern.h
     205                 :             :   virtual void visit (AST::LiteralPattern &pattern);
     206                 :             :   virtual void visit (AST::IdentifierPattern &pattern);
     207                 :             :   virtual void visit (AST::WildcardPattern &pattern);
     208                 :             :   virtual void visit (AST::RestPattern &pattern);
     209                 :             :   //  virtual void visit(RangePatternBound& bound);
     210                 :             :   virtual void visit (AST::RangePatternBoundLiteral &bound);
     211                 :             :   virtual void visit (AST::RangePatternBoundPath &bound);
     212                 :             :   virtual void visit (AST::RangePatternBoundQualPath &bound);
     213                 :             :   virtual void visit (AST::RangePattern &pattern);
     214                 :             :   virtual void visit (AST::ReferencePattern &pattern);
     215                 :             :   //  virtual void visit(StructPatternField& field);
     216                 :             :   virtual void visit (AST::StructPatternFieldTuplePat &field);
     217                 :             :   virtual void visit (AST::StructPatternFieldIdentPat &field);
     218                 :             :   virtual void visit (AST::StructPatternFieldIdent &field);
     219                 :             :   virtual void visit (AST::StructPattern &pattern);
     220                 :             :   //  virtual void visit(TupleStructItems& tuple_items);
     221                 :             :   virtual void visit (AST::TupleStructItemsNoRange &tuple_items);
     222                 :             :   virtual void visit (AST::TupleStructItemsRange &tuple_items);
     223                 :             :   virtual void visit (AST::TupleStructPattern &pattern);
     224                 :             :   //  virtual void visit(TuplePatternItems& tuple_items);
     225                 :             :   virtual void visit (AST::TuplePatternItemsMultiple &tuple_items);
     226                 :             :   virtual void visit (AST::TuplePatternItemsRanged &tuple_items);
     227                 :             :   virtual void visit (AST::TuplePattern &pattern);
     228                 :             :   virtual void visit (AST::GroupedPattern &pattern);
     229                 :             :   virtual void visit (AST::SlicePattern &pattern);
     230                 :             :   virtual void visit (AST::AltPattern &pattern);
     231                 :             : 
     232                 :             :   // rust-stmt.h
     233                 :             :   virtual void visit (AST::EmptyStmt &stmt);
     234                 :             :   virtual void visit (AST::LetStmt &stmt);
     235                 :             :   virtual void visit (AST::ExprStmt &stmt);
     236                 :             : 
     237                 :             :   // rust-type.h
     238                 :             :   virtual void visit (AST::TraitBound &bound);
     239                 :             :   virtual void visit (AST::ImplTraitType &type);
     240                 :             :   virtual void visit (AST::TraitObjectType &type);
     241                 :             :   virtual void visit (AST::ParenthesisedType &type);
     242                 :             :   virtual void visit (AST::ImplTraitTypeOneBound &type);
     243                 :             :   virtual void visit (AST::TraitObjectTypeOneBound &type);
     244                 :             :   virtual void visit (AST::TupleType &type);
     245                 :             :   virtual void visit (AST::NeverType &type);
     246                 :             :   virtual void visit (AST::RawPointerType &type);
     247                 :             :   virtual void visit (AST::ReferenceType &type);
     248                 :             :   virtual void visit (AST::ArrayType &type);
     249                 :             :   virtual void visit (AST::SliceType &type);
     250                 :             :   virtual void visit (AST::InferredType &type);
     251                 :             :   virtual void visit (AST::BareFunctionType &type);
     252                 :             :   virtual void visit (AST::FunctionParam &param);
     253                 :             :   virtual void visit (AST::VariadicParam &param);
     254                 :             :   virtual void visit (AST::SelfParam &param);
     255                 :             : 
     256                 :             :   virtual void visit (AST::FormatArgs &fmt);
     257                 :             : 
     258                 :             : protected:
     259                 :      218870 :   ASTLoweringBase ()
     260                 :      437740 :     : mappings (Analysis::Mappings::get ()),
     261                 :      218870 :       attr_mappings (Analysis::BuiltinAttributeMappings::get ())
     262                 :      218870 :   {}
     263                 :             : 
     264                 :             :   Analysis::Mappings *mappings;
     265                 :             :   Analysis::BuiltinAttributeMappings *attr_mappings;
     266                 :             : 
     267                 :             :   HIR::Lifetime lower_lifetime (AST::Lifetime &lifetime,
     268                 :             :                                 bool default_to_static_lifetime = false);
     269                 :             : 
     270                 :             :   HIR::LoopLabel lower_loop_label (AST::LoopLabel &loop_label);
     271                 :             : 
     272                 :             :   std::vector<std::unique_ptr<HIR::GenericParam> > lower_generic_params (
     273                 :             :     std::vector<std::unique_ptr<AST::GenericParam> > &params);
     274                 :             : 
     275                 :             :   HIR::PathExprSegment lower_path_expr_seg (AST::PathExprSegment &s);
     276                 :             : 
     277                 :             :   HIR::GenericArgs lower_generic_args (AST::GenericArgs &args);
     278                 :             : 
     279                 :             :   HIR::GenericArgsBinding lower_binding (AST::GenericArgsBinding &binding);
     280                 :             : 
     281                 :             :   HIR::SelfParam lower_self (AST::Param &self);
     282                 :             : 
     283                 :             :   HIR::Type *lower_type_no_bounds (AST::TypeNoBounds &type);
     284                 :             : 
     285                 :             :   HIR::TypeParamBound *lower_bound (AST::TypeParamBound &bound);
     286                 :             : 
     287                 :             :   HIR::QualifiedPathType
     288                 :             :   lower_qual_path_type (AST::QualifiedPathType &qual_path_type);
     289                 :             : 
     290                 :             :   HIR::FunctionQualifiers
     291                 :             :   lower_qualifiers (const AST::FunctionQualifiers &qualifiers);
     292                 :             : 
     293                 :             :   void handle_outer_attributes (const ItemWrapper &item);
     294                 :             : 
     295                 :             :   void handle_lang_item_attribute (const ItemWrapper &item,
     296                 :             :                                    const AST::Attribute &attr);
     297                 :             : 
     298                 :             :   void handle_doc_item_attribute (const ItemWrapper &item,
     299                 :             :                                   const AST::Attribute &attr);
     300                 :             : 
     301                 :             :   bool is_known_attribute (const std::string &attribute_path) const;
     302                 :             : 
     303                 :             :   bool
     304                 :             :   attribute_handled_in_another_pass (const std::string &attribute_path) const;
     305                 :             : 
     306                 :             :   std::unique_ptr<TuplePatternItems>
     307                 :             :   lower_tuple_pattern_multiple (AST::TuplePatternItemsMultiple &pattern);
     308                 :             : 
     309                 :             :   std::unique_ptr<TuplePatternItems>
     310                 :             :   lower_tuple_pattern_ranged (AST::TuplePatternItemsRanged &pattern);
     311                 :             : 
     312                 :             :   std::unique_ptr<HIR::RangePatternBound>
     313                 :             :   lower_range_pattern_bound (AST::RangePatternBound &bound);
     314                 :             : 
     315                 :             :   HIR::Literal lower_literal (const AST::Literal &literal);
     316                 :             : 
     317                 :             :   HIR::ExternBlock *lower_extern_block (AST::ExternBlock &extern_block);
     318                 :             : 
     319                 :             :   HIR::ClosureParam lower_closure_param (AST::ClosureParam &param);
     320                 :             : 
     321                 :             :   /* Lower a macro definition if it should be exported */
     322                 :             :   void lower_macro_definition (AST::MacroRulesDefinition &def);
     323                 :             : };
     324                 :             : 
     325                 :             : } // namespace HIR
     326                 :             : } // namespace Rust
     327                 :             : 
     328                 :             : #endif // RUST_AST_LOWER_BASE
        

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.