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-hir-visitor.h"
24 :
25 : namespace Rust {
26 : namespace Compile {
27 :
28 114290 : 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::AnonConst &expr) override;
52 : void visit (HIR::ConstBlock &expr) override;
53 : void visit (HIR::UnsafeBlockExpr &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::WhileLoopExpr &expr) override;
62 : void visit (HIR::BreakExpr &expr) override;
63 : void visit (HIR::ContinueExpr &expr) override;
64 : void visit (HIR::BorrowExpr &expr) override;
65 : void visit (HIR::DereferenceExpr &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::ClosureExpr &expr) override;
73 : void visit (HIR::InlineAsm &expr) override;
74 : void visit (HIR::LlvmInlineAsm &expr) override;
75 : void visit (HIR::OffsetOf &expr) override;
76 :
77 : // TODO
78 0 : void visit (HIR::ErrorPropagationExpr &) override {}
79 0 : void visit (HIR::RangeToInclExpr &) override {}
80 :
81 : // TODO
82 : // these need to be sugared in the HIR to if statements and a match
83 0 : void visit (HIR::WhileLetLoopExpr &) override {}
84 :
85 : // lets not worry about async yet....
86 0 : void visit (HIR::AwaitExpr &) override {}
87 0 : void visit (HIR::AsyncBlockExpr &) override {}
88 :
89 : // nothing to do for these
90 0 : void visit (HIR::StructExprFieldIdentifier &) override {}
91 0 : void visit (HIR::StructExprFieldIdentifierValue &) override {}
92 0 : void visit (HIR::StructExprFieldIndexValue &) override {}
93 :
94 : protected:
95 : tree get_fn_addr_from_dyn (const TyTy::DynamicObjectType *dyn,
96 : TyTy::BaseType *receiver, TyTy::FnType *fntype,
97 : tree receiver_ref, location_t expr_locus);
98 :
99 : tree get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn,
100 : TyTy::BaseType *receiver, TyTy::FnType *fntype,
101 : tree receiver_ref, location_t expr_locus);
102 :
103 : tree resolve_operator_overload (
104 : LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs,
105 : tree rhs, HIR::Expr &lhs_expr,
106 : tl::optional<std::reference_wrapper<HIR::Expr>> rhs_expr,
107 : HIR::PathIdentSegment specified_segment
108 : = HIR::PathIdentSegment::create_error ());
109 :
110 : tree compile_bool_literal (const HIR::LiteralExpr &expr,
111 : const TyTy::BaseType *tyty);
112 :
113 : tree compile_integer_literal (const HIR::LiteralExpr &expr,
114 : const TyTy::BaseType *tyty);
115 :
116 : tree compile_float_literal (const HIR::LiteralExpr &expr,
117 : const TyTy::BaseType *tyty);
118 :
119 : tree compile_char_literal (const HIR::LiteralExpr &expr,
120 : const TyTy::BaseType *tyty);
121 :
122 : tree compile_byte_literal (const HIR::LiteralExpr &expr,
123 : const TyTy::BaseType *tyty);
124 :
125 : tree compile_string_literal (const HIR::LiteralExpr &expr,
126 : const TyTy::BaseType *tyty);
127 :
128 : tree compile_byte_string_literal (const HIR::LiteralExpr &expr,
129 : const TyTy::BaseType *tyty);
130 :
131 : tree type_cast_expression (tree type_to_cast_to, tree expr, location_t locus);
132 :
133 : tree array_value_expr (location_t expr_locus,
134 : const TyTy::ArrayType &array_tyty, tree array_type,
135 : HIR::ArrayElemsValues &elems);
136 :
137 : tree array_copied_expr (location_t expr_locus,
138 : const TyTy::ArrayType &array_tyty, tree array_type,
139 : HIR::ArrayElemsCopied &elems);
140 :
141 : protected:
142 : tree generate_closure_function (HIR::ClosureExpr &expr,
143 : TyTy::ClosureType &closure_tyty,
144 : tree compiled_closure_tyty);
145 :
146 : tree generate_closure_fntype (HIR::ClosureExpr &expr,
147 : const TyTy::ClosureType &closure_tyty,
148 : tree compiled_closure_tyty,
149 : TyTy::FnType **fn_tyty);
150 :
151 : bool generate_possible_fn_trait_call (HIR::CallExpr &expr, tree receiver,
152 : tree *result);
153 :
154 : private:
155 : CompileExpr (Context *ctx);
156 :
157 : tree translated;
158 : };
159 :
160 : } // namespace Compile
161 : } // namespace Rust
162 :
163 : #endif // RUST_COMPILE_EXPR
|