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