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