libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / rust / typecheck / rust-hir-type-check-expr.h
blob9ea4dc6e59c4cf66d08af3db579f5bf00b18aebc
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
8 // version.
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.
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"
26 namespace Rust {
27 namespace Resolver {
29 class TypeCheckExpr : private TypeCheckBase, private HIR::HIRExpressionVisitor
31 public:
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;
75 // TODO
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
87 rust_unreachable ();
89 void visit (HIR::StructExprFieldIndexValue &) override
91 rust_unreachable ();
93 void visit (HIR::StructExprFieldIdentifierValue &) override
95 rust_unreachable ();
98 protected:
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);
110 private:
111 TypeCheckExpr ();
113 TyTy::BaseType *resolve_root_path (HIR::PathInExpression &expr,
114 size_t *offset,
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);
123 bool
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
132 } // namespace Rust
134 #endif // RUST_HIR_TYPE_CHECK_EXPR