Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 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_COMPILE_EXPR
20 : : #define RUST_COMPILE_EXPR
21 : :
22 : : #include "rust-compile-base.h"
23 : : #include "rust-hir-visitor.h"
24 : :
25 : : namespace Rust {
26 : : namespace Compile {
27 : :
28 : 92421 : class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor
29 : : {
30 : : public:
31 : : static tree Compile (HIR::Expr &expr, Context *ctx);
32 : :
33 : : void visit (HIR::TupleIndexExpr &expr) override;
34 : : void visit (HIR::TupleExpr &expr) override;
35 : : void visit (HIR::ReturnExpr &expr) override;
36 : : void visit (HIR::CallExpr &expr) override;
37 : : void visit (HIR::MethodCallExpr &expr) override;
38 : : void visit (HIR::LiteralExpr &expr) override;
39 : : void visit (HIR::AssignmentExpr &expr) override;
40 : : void visit (HIR::CompoundAssignmentExpr &expr) override;
41 : : void visit (HIR::ArrayIndexExpr &expr) override;
42 : : void visit (HIR::ArrayExpr &expr) override;
43 : : void visit (HIR::ArithmeticOrLogicalExpr &expr) override;
44 : : void visit (HIR::ComparisonExpr &expr) override;
45 : : void visit (HIR::LazyBooleanExpr &expr) override;
46 : : void visit (HIR::NegationExpr &expr) override;
47 : : void visit (HIR::TypeCastExpr &expr) override;
48 : : void visit (HIR::IfExpr &expr) override;
49 : : void visit (HIR::IfExprConseqElse &expr) override;
50 : : void visit (HIR::BlockExpr &expr) override;
51 : : void visit (HIR::UnsafeBlockExpr &expr) override;
52 : : void visit (HIR::StructExprStruct &struct_expr) override;
53 : : void visit (HIR::StructExprStructFields &struct_expr) override;
54 : : void visit (HIR::GroupedExpr &expr) override;
55 : : void visit (HIR::FieldAccessExpr &expr) override;
56 : : void visit (HIR::QualifiedPathInExpression &expr) override;
57 : : void visit (HIR::PathInExpression &expr) override;
58 : : void visit (HIR::LoopExpr &expr) override;
59 : : void visit (HIR::WhileLoopExpr &expr) override;
60 : : void visit (HIR::BreakExpr &expr) override;
61 : : void visit (HIR::ContinueExpr &expr) override;
62 : : void visit (HIR::BorrowExpr &expr) override;
63 : : void visit (HIR::DereferenceExpr &expr) override;
64 : : void visit (HIR::MatchExpr &expr) override;
65 : : void visit (HIR::RangeFromToExpr &expr) override;
66 : : void visit (HIR::RangeFromExpr &expr) override;
67 : : void visit (HIR::RangeToExpr &expr) override;
68 : : void visit (HIR::RangeFullExpr &expr) override;
69 : : void visit (HIR::RangeFromToInclExpr &expr) override;
70 : : void visit (HIR::ClosureExpr &expr) override;
71 : : void visit (HIR::InlineAsm &expr) override;
72 : : void visit (HIR::LlvmInlineAsm &expr) override;
73 : :
74 : : // TODO
75 : 0 : void visit (HIR::ErrorPropagationExpr &) override {}
76 : 0 : void visit (HIR::RangeToInclExpr &) override {}
77 : :
78 : : // TODO
79 : : // these need to be sugared in the HIR to if statements and a match
80 : 0 : void visit (HIR::WhileLetLoopExpr &) override {}
81 : :
82 : : // lets not worry about async yet....
83 : 0 : void visit (HIR::AwaitExpr &) override {}
84 : 0 : void visit (HIR::AsyncBlockExpr &) override {}
85 : :
86 : : // nothing to do for these
87 : 0 : void visit (HIR::StructExprFieldIdentifier &) override {}
88 : 0 : void visit (HIR::StructExprFieldIdentifierValue &) override {}
89 : 0 : void visit (HIR::StructExprFieldIndexValue &) override {}
90 : :
91 : : protected:
92 : : tree get_fn_addr_from_dyn (const TyTy::DynamicObjectType *dyn,
93 : : TyTy::BaseType *receiver, TyTy::FnType *fntype,
94 : : tree receiver_ref, location_t expr_locus);
95 : :
96 : : tree get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
97 : : TyTy::BaseType *receiver, TyTy::FnType *fntype,
98 : : tree receiver_ref, location_t expr_locus);
99 : :
100 : : tree resolve_operator_overload (
101 : : LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs,
102 : : tree rhs, HIR::Expr &lhs_expr,
103 : : tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr,
104 : : HIR::PathIdentSegment specified_segment
105 : : = HIR::PathIdentSegment::create_error ());
106 : :
107 : : tree compile_bool_literal (const HIR::LiteralExpr &expr,
108 : : const TyTy::BaseType *tyty);
109 : :
110 : : tree compile_integer_literal (const HIR::LiteralExpr &expr,
111 : : const TyTy::BaseType *tyty);
112 : :
113 : : tree compile_float_literal (const HIR::LiteralExpr &expr,
114 : : const TyTy::BaseType *tyty);
115 : :
116 : : tree compile_char_literal (const HIR::LiteralExpr &expr,
117 : : const TyTy::BaseType *tyty);
118 : :
119 : : tree compile_byte_literal (const HIR::LiteralExpr &expr,
120 : : const TyTy::BaseType *tyty);
121 : :
122 : : tree compile_string_literal (const HIR::LiteralExpr &expr,
123 : : const TyTy::BaseType *tyty);
124 : :
125 : : tree compile_byte_string_literal (const HIR::LiteralExpr &expr,
126 : : const TyTy::BaseType *tyty);
127 : :
128 : : tree type_cast_expression (tree type_to_cast_to, tree expr, location_t locus);
129 : :
130 : : tree array_value_expr (location_t expr_locus,
131 : : const TyTy::ArrayType &array_tyty, tree array_type,
132 : : HIR::ArrayElemsValues &elems);
133 : :
134 : : tree array_copied_expr (location_t expr_locus,
135 : : const TyTy::ArrayType &array_tyty, tree array_type,
136 : : HIR::ArrayElemsCopied &elems);
137 : :
138 : : protected:
139 : : tree generate_closure_function (HIR::ClosureExpr &expr,
140 : : TyTy::ClosureType &closure_tyty,
141 : : tree compiled_closure_tyty);
142 : :
143 : : tree generate_closure_fntype (HIR::ClosureExpr &expr,
144 : : const TyTy::ClosureType &closure_tyty,
145 : : tree compiled_closure_tyty,
146 : : TyTy::FnType **fn_tyty);
147 : :
148 : : bool generate_possible_fn_trait_call (HIR::CallExpr &expr, tree receiver,
149 : : tree *result);
150 : :
151 : : private:
152 : : CompileExpr (Context *ctx);
153 : :
154 : : tree translated;
155 : : };
156 : :
157 : : } // namespace Compile
158 : : } // namespace Rust
159 : :
160 : : #endif // RUST_COMPILE_EXPR
|