1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of GCC.
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
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
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/>.
19 #ifndef RUST_HIR_TYPE_CHECK_EXPR
20 #define RUST_HIR_TYPE_CHECK_EXPR
22 #include "rust-hir-type-check-base.h"
23 #include "rust-hir-visitor.h"
24 #include "rust-tyty.h"
29 class TypeCheckExpr
: private TypeCheckBase
, private HIR::HIRExpressionVisitor
32 static TyTy::BaseType
*Resolve (HIR::Expr
*expr
);
34 void visit (HIR::TupleIndexExpr
&expr
) override
;
35 void visit (HIR::TupleExpr
&expr
) override
;
36 void visit (HIR::ReturnExpr
&expr
) override
;
37 void visit (HIR::CallExpr
&expr
) override
;
38 void visit (HIR::MethodCallExpr
&expr
) override
;
39 void visit (HIR::AssignmentExpr
&expr
) override
;
40 void visit (HIR::CompoundAssignmentExpr
&expr
) override
;
41 void visit (HIR::LiteralExpr
&expr
) override
;
42 void visit (HIR::ArithmeticOrLogicalExpr
&expr
) override
;
43 void visit (HIR::ComparisonExpr
&expr
) override
;
44 void visit (HIR::LazyBooleanExpr
&expr
) override
;
45 void visit (HIR::NegationExpr
&expr
) override
;
46 void visit (HIR::IfExpr
&expr
) override
;
47 void visit (HIR::IfExprConseqElse
&expr
) override
;
48 void visit (HIR::IfLetExpr
&expr
) override
;
49 void visit (HIR::IfLetExprConseqElse
&) override
;
50 void visit (HIR::BlockExpr
&expr
) override
;
51 void visit (HIR::UnsafeBlockExpr
&expr
) override
;
52 void visit (HIR::ArrayIndexExpr
&expr
) override
;
53 void visit (HIR::ArrayExpr
&expr
) override
;
54 void visit (HIR::StructExprStruct
&struct_expr
) override
;
55 void visit (HIR::StructExprStructFields
&struct_expr
) override
;
56 void visit (HIR::GroupedExpr
&expr
) override
;
57 void visit (HIR::FieldAccessExpr
&expr
) override
;
58 void visit (HIR::QualifiedPathInExpression
&expr
) override
;
59 void visit (HIR::PathInExpression
&expr
) override
;
60 void visit (HIR::LoopExpr
&expr
) override
;
61 void visit (HIR::BreakExpr
&expr
) override
;
62 void visit (HIR::ContinueExpr
&expr
) override
;
63 void visit (HIR::BorrowExpr
&expr
) override
;
64 void visit (HIR::DereferenceExpr
&expr
) override
;
65 void visit (HIR::TypeCastExpr
&expr
) override
;
66 void visit (HIR::MatchExpr
&expr
) override
;
67 void visit (HIR::RangeFromToExpr
&expr
) override
;
68 void visit (HIR::RangeFromExpr
&expr
) override
;
69 void visit (HIR::RangeToExpr
&expr
) override
;
70 void visit (HIR::RangeFullExpr
&expr
) override
;
71 void visit (HIR::RangeFromToInclExpr
&expr
) override
;
72 void visit (HIR::WhileLoopExpr
&expr
) override
;
73 void visit (HIR::ClosureExpr
&expr
) override
;
76 void visit (HIR::ErrorPropagationExpr
&) override
{}
77 void visit (HIR::RangeToInclExpr
&) override
{}
78 void visit (HIR::WhileLetLoopExpr
&) override
{}
80 // lets not worry about async yet....
81 void visit (HIR::AwaitExpr
&) override
{}
82 void visit (HIR::AsyncBlockExpr
&) override
{}
84 // don't need to implement these see rust-hir-type-check-struct-field.h
85 void visit (HIR::StructExprFieldIdentifier
&) override
89 void visit (HIR::StructExprFieldIndexValue
&) override
93 void visit (HIR::StructExprFieldIdentifierValue
&) override
99 bool resolve_operator_overload (LangItem::Kind lang_item_type
,
100 HIR::OperatorExprMeta expr
,
101 TyTy::BaseType
*lhs
, TyTy::BaseType
*rhs
);
103 bool resolve_fn_trait_call (HIR::CallExpr
&expr
,
104 TyTy::BaseType
*function_tyty
,
105 TyTy::BaseType
**result
);
107 HIR::PathIdentSegment
resolve_possible_fn_trait_call_method_name (
108 TyTy::BaseType
&receiver
, TyTy::TypeBoundPredicate
*associated_predicate
);
113 TyTy::BaseType
*resolve_root_path (HIR::PathInExpression
&expr
,
115 NodeId
*root_resolved_node_id
);
117 void resolve_segments (NodeId root_resolved_node_id
,
118 std::vector
<HIR::PathExprSegment
> &segments
,
119 size_t offset
, TyTy::BaseType
*tyseg
,
120 const Analysis::NodeMapping
&expr_mappings
,
121 location_t expr_locus
);
124 validate_arithmetic_type (const TyTy::BaseType
*tyty
,
125 HIR::ArithmeticOrLogicalExpr::ExprType expr_type
);
127 /* The return value of TypeCheckExpr::Resolve */
128 TyTy::BaseType
*infered
;
131 } // namespace Resolver
134 #endif // RUST_HIR_TYPE_CHECK_EXPR