Line data Source code
1 : // Copyright (C) 2020-2026 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 : #include "rust-feature.h"
20 :
21 : namespace Rust {
22 :
23 : Feature Feature::feature_list[] = {
24 : #define ISSUE_SOME(n) n
25 : #define ISSUE_NONE tl::nullopt
26 : #define EDITION_2018 Edition::E2018
27 : #define EDITION_NONE tl::nullopt
28 : #define REASON_SOME(r) r
29 : #define REASON_NONE tl::nullopt
30 :
31 : #define FEATURE_BASE(state, name_str, name, rust_since, issue, ...) \
32 : Feature (Feature::Name::name, Feature::State::state, name_str, rust_since, \
33 : issue, __VA_ARGS__),
34 :
35 : #define FEATURE_ACTIVE(a, b, c, d, edition) \
36 : FEATURE_BASE (ACTIVE, a, b, c, d, edition, tl::nullopt)
37 :
38 : #define FEATURE_ACCEPTED(a, b, c, d) \
39 : FEATURE_BASE (ACCEPTED, a, b, c, d, tl::nullopt, tl::nullopt)
40 :
41 : #define FEATURE_REMOVED(a, b, c, d, reason) \
42 : FEATURE_BASE (REMOVED, a, b, c, d, tl::nullopt, reason)
43 :
44 : #define FEATURE_STABLE_REMOVED(a, b, c, d) \
45 : FEATURE_BASE (ACCEPTED, a, b, c, d, tl::nullopt, tl::nullopt)
46 :
47 : #include "rust-feature-defs.h"
48 :
49 : #undef ISSUE_SOME
50 : #undef ISSUE_NONE
51 : #undef EDITION_2018
52 : #undef EDITION_NONE
53 : #undef REASON_SOME
54 : #undef REASON_NONE
55 :
56 : #undef FEATURE_BASE
57 : #undef FEATURE_ACTIVE
58 : #undef FEATURE_ACCEPTED
59 : #undef FEATURE_REMOVED
60 : #undef FEATURE_STABLE_REMOVED
61 : };
62 :
63 : const std::map<std::string, Feature::Name> Feature::name_hash_map = {
64 : #define FEATURE(s, name, ...) {s, Feature::Name::name},
65 : #define FEATURE_ACTIVE(...) FEATURE (__VA_ARGS__)
66 : #define FEATURE_ACCEPTED(...) FEATURE (__VA_ARGS__)
67 : #define FEATURE_REMOVED(...) FEATURE (__VA_ARGS__)
68 : #define FEATURE_STABLE_REMOVED(...) FEATURE (__VA_ARGS__)
69 : #include "rust-feature-defs.h"
70 : #undef FEATURE
71 : #undef FEATURE_ACTIVE
72 : #undef FEATURE_ACCEPTED
73 : #undef FEATURE_REMOVED
74 : #undef FEATURE_STABLE_REMOVED
75 : };
76 :
77 : tl::optional<Feature::Name>
78 6751 : Feature::as_name (const std::string &name)
79 : {
80 6751 : auto it = Feature::name_hash_map.find (name);
81 6751 : if (it == Feature::name_hash_map.end ())
82 5 : return tl::nullopt;
83 : else
84 6746 : return it->second;
85 : }
86 :
87 : tl::optional<std::reference_wrapper<const Feature>>
88 0 : Feature::lookup (const std::string &name)
89 : {
90 0 : return as_name (name).map (
91 0 : [] (Name n) { return std::ref (Feature::lookup (n)); });
92 : }
93 :
94 : const Feature &
95 13 : Feature::lookup (Feature::Name name)
96 : {
97 13 : return feature_list[static_cast<size_t> (name)];
98 : }
99 :
100 : } // namespace Rust
|