forked from Rust-GCC/gccrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrust-ast-resolve-item.h
163 lines (123 loc) · 4.61 KB
/
rust-ast-resolve-item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (C) 2020-2023 Free Software Foundation, Inc.
// This file is part of GCC.
// GCC is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3, or (at your option) any later
// version.
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#ifndef RUST_AST_RESOLVE_ITEM_H
#define RUST_AST_RESOLVE_ITEM_H
#include "rust-ast-full-decls.h"
#include "rust-ast-resolve-base.h"
#include "config.h"
namespace Rust {
namespace Resolver {
class ResolveTraitItems : public ResolverBase
{
using Rust::Resolver::ResolverBase::visit;
public:
static void go (AST::AssociatedItem *item, const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
void visit (AST::TraitItemType &type) override;
void visit (AST::TraitItemFunc &func) override;
void visit (AST::TraitItemMethod &func) override;
void visit (AST::TraitItemConst &constant) override;
private:
ResolveTraitItems (const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
const CanonicalPath &prefix;
const CanonicalPath &canonical_prefix;
};
class ResolveItem : public ResolverBase
{
public:
using Rust::Resolver::ResolverBase::visit;
static void go (AST::Item *item, const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
void visit (AST::TypeAlias &alias) override;
void visit (AST::Module &module) override;
void visit (AST::TupleStruct &struct_decl) override;
void visit (AST::Enum &enum_decl) override;
/* EnumItem doesn't need to be handled, no fields. */
void visit (AST::EnumItem &item) override;
void visit (AST::EnumItemTuple &item) override;
void visit (AST::EnumItemStruct &item) override;
void visit (AST::EnumItemDiscriminant &item) override;
void visit (AST::StructStruct &struct_decl) override;
void visit (AST::Union &union_decl) override;
void visit (AST::StaticItem &var) override;
void visit (AST::ConstantItem &constant) override;
void visit (AST::Function &function) override;
void visit (AST::InherentImpl &impl_block) override;
void visit (AST::TraitImpl &impl_block) override;
void visit (AST::Trait &trait) override;
void visit (AST::ExternBlock &extern_block) override;
void visit (AST::UseDeclaration &) override;
protected:
void resolve_impl_item (AST::AssociatedItem *item,
const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
void resolve_extern_item (AST::ExternalItem *item);
ResolveItem (const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
const CanonicalPath &prefix;
const CanonicalPath &canonical_prefix;
};
class ResolveImplItems : public ResolveItem
{
using Rust::Resolver::ResolveItem::visit;
public:
static void go (AST::AssociatedItem *item, const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
void visit (AST::TypeAlias &alias) override;
private:
ResolveImplItems (const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
};
class ResolveExternItem : public ResolverBase
{
using Rust::Resolver::ResolverBase::visit;
public:
static void go (AST::ExternalItem *item, const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix);
void visit (AST::ExternalFunctionItem &function) override;
void visit (AST::ExternalStaticItem &item) override;
private:
ResolveExternItem (const CanonicalPath &prefix,
const CanonicalPath &canonical_prefix)
: ResolverBase (), prefix (prefix), canonical_prefix (canonical_prefix)
{}
const CanonicalPath &prefix;
const CanonicalPath &canonical_prefix;
};
class Import
{
public:
Import (AST::SimplePath path, bool is_glob, std::string name)
: path (path), is_glob_f (is_glob), name (name)
{}
AST::SimplePath &get_path () { return path; }
const AST::SimplePath &get_path () const { return path; }
bool is_glob () const { return is_glob_f; }
const std::string &get_name () const { return name; }
void add_prefix (AST::SimplePath prefix);
private:
AST::SimplePath path;
bool is_glob_f;
std::string name;
};
} // namespace Resolver
} // namespace Rust
#if CHECKING_P
namespace selftest {
extern void
rust_simple_path_resolve_test (void);
} // namespace selftest
#endif // CHECKING_P
#endif // RUST_AST_RESOLVE_ITEM_H