Branch data Line data Source code
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_BASE
20 : : #define RUST_COMPILE_BASE
21 : :
22 : : #include "rust-compile-context.h"
23 : :
24 : : namespace Rust {
25 : : namespace Compile {
26 : :
27 : : class HIRCompileBase
28 : : {
29 : : public:
30 : 264285 : virtual ~HIRCompileBase () {}
31 : :
32 : : static tree address_expression (tree expr, location_t locus,
33 : : tree ptrty = NULL_TREE);
34 : :
35 : : static tree compile_constant_expr (
36 : : Context *ctx, HirId coercion_id, TyTy::BaseType *resolved_type,
37 : : TyTy::BaseType *expected_type,
38 : : const Resolver::CanonicalPath &canonical_path, HIR::Expr &const_value_expr,
39 : : location_t locus, location_t expr_locus);
40 : :
41 : : static tree query_compile_const_expr (Context *ctx, TyTy::BaseType *expr_ty,
42 : : HIR::Expr &const_value_expr);
43 : :
44 : : protected:
45 : 83296 : HIRCompileBase (Context *ctx) : ctx (ctx) {}
46 : :
47 : : Context *ctx;
48 : :
49 : : protected:
50 : : Context *get_context () { return ctx; }
51 : :
52 : : tree coercion_site (HirId id, tree rvalue, TyTy::BaseType *actual,
53 : : TyTy::BaseType *expected, location_t lvalue_locus,
54 : : location_t rvalue_locus);
55 : : tree coercion_site1 (tree rvalue, TyTy::BaseType *actual,
56 : : TyTy::BaseType *expected, location_t lvalue_locus,
57 : : location_t rvalue_locus);
58 : :
59 : : tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual,
60 : : const TyTy::DynamicObjectType *ty,
61 : : location_t locus);
62 : :
63 : : tree compute_address_for_trait_item (
64 : : const Resolver::TraitItemReference *ref,
65 : : const TyTy::TypeBoundPredicate *predicate,
66 : : std::vector<std::pair<Resolver::TraitReference *, HIR::ImplBlock *>>
67 : : &receiver_bounds,
68 : : const TyTy::BaseType *receiver, const TyTy::BaseType *root,
69 : : location_t locus);
70 : :
71 : : bool verify_array_capacities (tree ltype, tree rtype, location_t ltype_locus,
72 : : location_t rtype_locus);
73 : :
74 : : tree query_compile (HirId ref, TyTy::BaseType *lookup,
75 : : const HIR::PathIdentSegment &final_segment,
76 : : const Analysis::NodeMapping &mappings,
77 : : location_t expr_locus, bool is_qualified_path);
78 : :
79 : : tree resolve_adjustements (std::vector<Resolver::Adjustment> &adjustments,
80 : : tree expression, location_t locus);
81 : :
82 : : tree resolve_deref_adjustment (Resolver::Adjustment &adjustment,
83 : : tree expression, location_t locus);
84 : :
85 : : tree resolve_indirection_adjustment (Resolver::Adjustment &adjustment,
86 : : tree expression, location_t locus);
87 : :
88 : : tree resolve_unsized_adjustment (Resolver::Adjustment &adjustment,
89 : : tree expression, location_t locus);
90 : :
91 : : tree resolve_unsized_slice_adjustment (Resolver::Adjustment &adjustment,
92 : : tree expression, location_t locus);
93 : :
94 : : tree resolve_unsized_dyn_adjustment (Resolver::Adjustment &adjustment,
95 : : tree expression, location_t locus);
96 : :
97 : : tree resolve_method_address (TyTy::FnType *fntype, TyTy::BaseType *receiver,
98 : : location_t expr_locus);
99 : :
100 : : void compile_function_body (tree fndecl, HIR::BlockExpr &function_body,
101 : : TyTy::BaseType *fn_return_ty);
102 : :
103 : : tree compile_constant_item (HirId coercion_id, TyTy::BaseType *resolved_type,
104 : : TyTy::BaseType *expected_type,
105 : : const Resolver::CanonicalPath &canonical_path,
106 : : HIR::Expr &const_value_expr, location_t locus,
107 : : location_t expr_locus);
108 : :
109 : : tree compile_function (bool is_root_item, const std::string &fn_name,
110 : : tl::optional<HIR::SelfParam> &self_param,
111 : : std::vector<HIR::FunctionParam> &function_params,
112 : : const HIR::FunctionQualifiers &qualifiers,
113 : : HIR::Visibility &visibility, AST::AttrVec &outer_attrs,
114 : : location_t locus, HIR::BlockExpr *function_body,
115 : : const Resolver::CanonicalPath &canonical_path,
116 : : TyTy::FnType *fntype);
117 : :
118 : : tree unit_expression (location_t locus);
119 : :
120 : : void setup_fndecl (tree fndecl, bool is_main_entry_point, bool is_generic_fn,
121 : : HIR::Visibility &visibility,
122 : : const HIR::FunctionQualifiers &qualifiers,
123 : : const AST::AttrVec &attrs);
124 : :
125 : : static void handle_inline_attribute_on_fndecl (tree fndecl,
126 : : const AST::Attribute &attr);
127 : :
128 : : void handle_bang_proc_macro_attribute_on_fndecl (tree fndecl,
129 : : const AST::Attribute &attr);
130 : :
131 : : void
132 : : handle_attribute_proc_macro_attribute_on_fndecl (tree fndecl,
133 : : const AST::Attribute &attr);
134 : :
135 : : void
136 : : handle_derive_proc_macro_attribute_on_fndecl (tree fndecl,
137 : : const AST::Attribute &attr);
138 : :
139 : : static void handle_cold_attribute_on_fndecl (tree fndecl,
140 : : const AST::Attribute &attr);
141 : :
142 : : static void handle_must_use_attribute_on_fndecl (tree fndecl,
143 : : const AST::Attribute &attr);
144 : :
145 : : static void
146 : : handle_link_section_attribute_on_fndecl (tree fndecl,
147 : : const AST::Attribute &attr);
148 : : static void
149 : : handle_deprecated_attribute_on_fndecl (tree fndecl,
150 : : const AST::Attribute &attr);
151 : :
152 : : static void handle_no_mangle_attribute_on_fndecl (tree fndecl,
153 : : const AST::Attribute &attr);
154 : :
155 : : static void setup_abi_options (tree fndecl, ABI abi);
156 : :
157 : : static tree indirect_expression (tree expr, location_t locus);
158 : :
159 : : static bool mark_addressable (tree, location_t);
160 : :
161 : : static tree named_constant_expression (tree type_tree,
162 : : const std::string &name,
163 : : tree const_val, location_t location);
164 : : };
165 : :
166 : : } // namespace Compile
167 : : } // namespace Rust
168 : :
169 : : #endif // RUST_COMPILE_BASE
|