Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 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 : 65925 : 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 : :
72 : : // TODO
73 : 0 : void visit (HIR::ErrorPropagationExpr &) override {}
74 : 0 : void visit (HIR::RangeToInclExpr &) override {}
75 : :
76 : : // TODO
77 : : // these need to be sugared in the HIR to if statements and a match
78 : 0 : void visit (HIR::WhileLetLoopExpr &) override {}
79 : 0 : void visit (HIR::IfLetExpr &) override {}
80 : 1 : void visit (HIR::IfLetExprConseqElse &) 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
101 : : resolve_operator_overload (Analysis::RustLangItem::ItemType lang_item_type,
102 : : HIR::OperatorExprMeta expr, tree lhs, tree rhs,
103 : : HIR::Expr *lhs_expr, HIR::Expr *rhs_expr);
104 : :
105 : : tree compile_bool_literal (const HIR::LiteralExpr &expr,
106 : : const TyTy::BaseType *tyty);
107 : :
108 : : tree compile_integer_literal (const HIR::LiteralExpr &expr,
109 : : const TyTy::BaseType *tyty);
110 : :
111 : : tree compile_float_literal (const HIR::LiteralExpr &expr,
112 : : const TyTy::BaseType *tyty);
113 : :
114 : : tree compile_char_literal (const HIR::LiteralExpr &expr,
115 : : const TyTy::BaseType *tyty);
116 : :
117 : : tree compile_byte_literal (const HIR::LiteralExpr &expr,
118 : : const TyTy::BaseType *tyty);
119 : :
120 : : tree compile_string_literal (const HIR::LiteralExpr &expr,
121 : : const TyTy::BaseType *tyty);
122 : :
123 : : tree compile_byte_string_literal (const HIR::LiteralExpr &expr,
124 : : const TyTy::BaseType *tyty);
125 : :
126 : : tree type_cast_expression (tree type_to_cast_to, tree expr, location_t locus);
127 : :
128 : : tree array_value_expr (location_t expr_locus,
129 : : const TyTy::ArrayType &array_tyty, tree array_type,
130 : : HIR::ArrayElemsValues &elems);
131 : :
132 : : tree array_copied_expr (location_t expr_locus,
133 : : const TyTy::ArrayType &array_tyty, tree array_type,
134 : : HIR::ArrayElemsCopied &elems);
135 : :
136 : : protected:
137 : : tree generate_closure_function (HIR::ClosureExpr &expr,
138 : : TyTy::ClosureType &closure_tyty,
139 : : tree compiled_closure_tyty);
140 : :
141 : : tree generate_closure_fntype (HIR::ClosureExpr &expr,
142 : : const TyTy::ClosureType &closure_tyty,
143 : : tree compiled_closure_tyty,
144 : : TyTy::FnType **fn_tyty);
145 : :
146 : : bool generate_possible_fn_trait_call (HIR::CallExpr &expr, tree receiver,
147 : : tree *result);
148 : :
149 : : private:
150 : : CompileExpr (Context *ctx);
151 : :
152 : : tree translated;
153 : : };
154 : :
155 : : } // namespace Compile
156 : : } // namespace Rust
157 : :
158 : : #endif // RUST_COMPILE_EXPR
|