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_ITEM
20 : : #define RUST_COMPILE_ITEM
21 : :
22 : : #include "rust-compile-base.h"
23 : : #include "rust-hir-visitor.h"
24 : :
25 : : namespace Rust {
26 : : namespace Compile {
27 : :
28 : 14715 : class CompileItem : private HIRCompileBase, protected HIR::HIRStmtVisitor
29 : : {
30 : : protected:
31 : : public:
32 : 14715 : static tree compile (HIR::Item *item, Context *ctx,
33 : : TyTy::BaseType *concrete = nullptr,
34 : : bool is_query_mode = false,
35 : : location_t ref_locus = UNDEF_LOCATION)
36 : : {
37 : 14715 : CompileItem compiler (ctx, concrete, ref_locus);
38 : 14715 : item->accept_vis (compiler);
39 : :
40 : 14715 : if (is_query_mode && compiler.reference == error_mark_node)
41 : 0 : rust_internal_error_at (ref_locus, "failed to compile item: %s",
42 : 0 : item->as_string ().c_str ());
43 : :
44 : 14715 : return compiler.reference;
45 : 14715 : }
46 : :
47 : : void visit (HIR::StaticItem &var) override;
48 : : void visit (HIR::ConstantItem &constant) override;
49 : : void visit (HIR::Function &function) override;
50 : : void visit (HIR::ImplBlock &impl_block) override;
51 : : void visit (HIR::ExternBlock &extern_block) override;
52 : : void visit (HIR::Module &module) override;
53 : :
54 : : // Empty visit for unused Stmt HIR nodes.
55 : 655 : void visit (HIR::TupleStruct &) override {}
56 : 0 : void visit (HIR::EnumItem &) override {}
57 : 0 : void visit (HIR::EnumItemTuple &) override {}
58 : 0 : void visit (HIR::EnumItemStruct &) override {}
59 : 0 : void visit (HIR::EnumItemDiscriminant &) override {}
60 : 0 : void visit (HIR::TypePathSegmentFunction &) override {}
61 : 0 : void visit (HIR::TypePath &) override {}
62 : 0 : void visit (HIR::QualifiedPathInType &) override {}
63 : 0 : void visit (HIR::ExternCrate &) override {}
64 : 0 : void visit (HIR::UseDeclaration &) override {}
65 : 739 : void visit (HIR::TypeAlias &) override {}
66 : 813 : void visit (HIR::StructStruct &) override {}
67 : 154 : void visit (HIR::Enum &) override {}
68 : 87 : void visit (HIR::Union &) override {}
69 : 1997 : void visit (HIR::Trait &) override {}
70 : 0 : void visit (HIR::EmptyStmt &) override {}
71 : 0 : void visit (HIR::LetStmt &) override {}
72 : 0 : void visit (HIR::ExprStmt &) override {}
73 : :
74 : : protected:
75 : 19397 : CompileItem (Context *ctx, TyTy::BaseType *concrete, location_t ref_locus)
76 : 19397 : : HIRCompileBase (ctx), concrete (concrete), reference (error_mark_node),
77 : 19397 : ref_locus (ref_locus)
78 : : {}
79 : :
80 : : TyTy::BaseType *concrete;
81 : : tree reference;
82 : : location_t ref_locus;
83 : : };
84 : :
85 : : } // namespace Compile
86 : : } // namespace Rust
87 : :
88 : : #endif // RUST_COMPILE_ITEM
|