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