Debian Codegraph @

gcc/rust/backend/rust-compile-implitem.h

raw
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_IMPLITEM_H
20 #define RUST_COMPILE_IMPLITEM_H
21
22 #include "rust-compile-item.h"
23
24 namespace Rust {
25 namespace Compile {
26
27 // this is a proxy for HIR::ImplItem's back to use the normal HIR::Item path
28 class CompileInherentImplItem : public CompileItem
29 {
30 public:
31 static tree Compile (HIR::ImplItem *item, Context *ctx,
32 TyTy::BaseType *concrete = nullptr,
33 location_t ref_locus = UNDEF_LOCATION)
34 {
35 CompileInherentImplItem compiler (ctx, concrete, ref_locus);
36 item->accept_vis (compiler);
37 return compiler.reference;
38 }
39
40 private:
41 CompileInherentImplItem (Context *ctx, TyTy::BaseType *concrete,
42 location_t ref_locus)
43 : CompileItem (ctx, concrete, ref_locus)
44 {}
45 };
46
47 class CompileTraitItem : public HIRCompileBase, public HIR::HIRTraitItemVisitor
48 {
49 public:
50 static tree Compile (HIR::TraitItem *item, Context *ctx,
51 TyTy::BaseType *concrete, bool is_query_mode = false,
52 location_t ref_locus = UNDEF_LOCATION)
53 {
54 CompileTraitItem compiler (ctx, concrete, ref_locus);
55 item->accept_vis (compiler);
56
57 if (is_query_mode && compiler.reference == error_mark_node)
58 rust_internal_error_at (ref_locus, "failed to compile trait item: %s",
59 item->as_string ().c_str ());
60
61 return compiler.reference;
62 }
63
64 void visit (HIR::TraitItemConst &constant) override;
65 void visit (HIR::TraitItemFunc &func) override;
66
67 void visit (HIR::TraitItemType &typ) override {}
68
69 private:
70 CompileTraitItem (Context *ctx, TyTy::BaseType *concrete,
71 location_t ref_locus)
72 : HIRCompileBase (ctx), concrete (concrete), reference (error_mark_node),
73 ref_locus (ref_locus)
74 {}
75
76 TyTy::BaseType *concrete;
77 tree reference;
78 location_t ref_locus;
79 };
80
81 } // namespace Compile
82 } // namespace Rust
83
84 #endif // RUST_COMPILE_IMPLITEM_H