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_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 : 4682 : class CompileInherentImplItem : public CompileItem
29 : : {
30 : : public:
31 : 4682 : static tree Compile (HIR::ImplItem *item, Context *ctx,
32 : : TyTy::BaseType *concrete = nullptr,
33 : : bool is_query_mode = false,
34 : : location_t ref_locus = UNDEF_LOCATION)
35 : : {
36 : 4682 : CompileInherentImplItem compiler (ctx, concrete, ref_locus);
37 : 4682 : item->accept_vis (compiler);
38 : :
39 : 4682 : if (is_query_mode && compiler.reference == error_mark_node)
40 : 0 : rust_internal_error_at (ref_locus, "failed to compile impl item: %s",
41 : 0 : item->as_string ().c_str ());
42 : :
43 : 4682 : return compiler.reference;
44 : 4682 : }
45 : :
46 : : private:
47 : 4682 : CompileInherentImplItem (Context *ctx, TyTy::BaseType *concrete,
48 : : location_t ref_locus)
49 : 4682 : : CompileItem (ctx, concrete, ref_locus)
50 : : {}
51 : : };
52 : :
53 : 123 : class CompileTraitItem : public HIRCompileBase, public HIR::HIRTraitItemVisitor
54 : : {
55 : : public:
56 : 123 : static tree Compile (HIR::TraitItem *item, Context *ctx,
57 : : TyTy::BaseType *concrete, bool is_query_mode = false,
58 : : location_t ref_locus = UNDEF_LOCATION)
59 : : {
60 : 123 : CompileTraitItem compiler (ctx, concrete, ref_locus);
61 : 123 : item->accept_vis (compiler);
62 : :
63 : 123 : if (is_query_mode && compiler.reference == error_mark_node)
64 : 0 : rust_internal_error_at (ref_locus, "failed to compile trait item: %s",
65 : 0 : item->as_string ().c_str ());
66 : :
67 : 123 : return compiler.reference;
68 : 123 : }
69 : :
70 : : void visit (HIR::TraitItemConst &constant) override;
71 : : void visit (HIR::TraitItemFunc &func) override;
72 : :
73 : 0 : void visit (HIR::TraitItemType &typ) override {}
74 : :
75 : : private:
76 : 123 : CompileTraitItem (Context *ctx, TyTy::BaseType *concrete,
77 : : location_t ref_locus)
78 : 123 : : HIRCompileBase (ctx), concrete (concrete), reference (error_mark_node),
79 : 123 : ref_locus (ref_locus)
80 : : {}
81 : :
82 : : TyTy::BaseType *concrete;
83 : : tree reference;
84 : : location_t ref_locus;
85 : : };
86 : :
87 : : } // namespace Compile
88 : : } // namespace Rust
89 : :
90 : : #endif // RUST_COMPILE_IMPLITEM_H
|