]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/rust/hir/rust-ast-lower-extern.h
Update copyright years.
[thirdparty/gcc.git] / gcc / rust / hir / rust-ast-lower-extern.h
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
7999cf32
PH
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_AST_LOWER_EXTERN_ITEM
20#define RUST_AST_LOWER_EXTERN_ITEM
21
22#include "rust-ast-lower-base.h"
23#include "rust-ast-lower-type.h"
24#include "rust-ast-lower.h"
25
26namespace Rust {
27namespace HIR {
28
29class ASTLoweringExternItem : public ASTLoweringBase
30{
31 using Rust::HIR::ASTLoweringBase::visit;
32
33public:
34 static HIR::ExternalItem *translate (AST::ExternalItem *item,
35 HirId parent_hirid)
36 {
37 ASTLoweringExternItem resolver;
38 item->accept_vis (resolver);
39
40 rust_assert (resolver.translated != nullptr);
41 resolver.mappings->insert_hir_extern_item (resolver.translated,
42 parent_hirid);
43 resolver.mappings->insert_location (
44 resolver.translated->get_mappings ().get_hirid (),
45 resolver.translated->get_locus ());
46
47 return resolver.translated;
48 }
49
50 void visit (AST::ExternalStaticItem &item) override
51 {
52 HIR::Visibility vis = translate_visibility (item.get_visibility ());
53 HIR::Type *static_type
54 = ASTLoweringType::translate (item.get_type ().get ());
55
56 auto crate_num = mappings->get_current_crate ();
57 Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
58 mappings->get_next_hir_id (crate_num),
59 mappings->get_next_localdef_id (crate_num));
60
61 translated = new HIR::ExternalStaticItem (
62 mapping, item.get_identifier (), std::unique_ptr<HIR::Type> (static_type),
63 item.is_mut () ? Mutability::Mut : Mutability::Imm, std::move (vis),
64 item.get_outer_attrs (), item.get_locus ());
65 }
66
67 void visit (AST::ExternalFunctionItem &function) override
68 {
69 std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
70 HIR::WhereClause where_clause (std::move (where_clause_items));
71 HIR::Visibility vis = translate_visibility (function.get_visibility ());
72
73 std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
74 if (function.has_generics ())
75 generic_params = lower_generic_params (function.get_generic_params ());
76
77 HIR::Type *return_type
78 = function.has_return_type ()
79 ? ASTLoweringType::translate (function.get_return_type ().get ())
80 : nullptr;
81
82 std::vector<HIR::NamedFunctionParam> function_params;
83 for (auto &param : function.get_function_params ())
84 {
85 HIR::Type *param_type
86 = ASTLoweringType::translate (param.get_type ().get ());
87 Identifier param_name = param.get_name ();
88
89 auto crate_num = mappings->get_current_crate ();
90 Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
91 mappings->get_next_hir_id (crate_num),
92 mappings->get_next_localdef_id (
93 crate_num));
94
95 function_params.push_back (
96 HIR::NamedFunctionParam (mapping, param_name,
97 std::unique_ptr<HIR::Type> (param_type)));
98 }
99
100 auto crate_num = mappings->get_current_crate ();
101 Analysis::NodeMapping mapping (crate_num, function.get_node_id (),
102 mappings->get_next_hir_id (crate_num),
103 mappings->get_next_localdef_id (crate_num));
104
105 translated = new HIR::ExternalFunctionItem (
106 mapping, function.get_identifier (), std::move (generic_params),
107 std::unique_ptr<HIR::Type> (return_type), std::move (where_clause),
108 std::move (function_params), function.is_variadic (), std::move (vis),
109 function.get_outer_attrs (), function.get_locus ());
110 }
111
112private:
113 ASTLoweringExternItem () : translated (nullptr) {}
114
115 HIR::ExternalItem *translated;
116};
117
118} // namespace HIR
119} // namespace Rust
120
121#endif // RUST_AST_LOWER_ITEM