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 : #ifndef RUST_FEATURE_GATE_H
20 : #define RUST_FEATURE_GATE_H
21 :
22 : #include "rust-ast-visitor.h"
23 : #include "rust-feature-collector.h"
24 :
25 : namespace Rust {
26 :
27 5049 : class FeatureGate : public AST::DefaultASTVisitor
28 : {
29 : public:
30 5049 : FeatureGate (Features::CrateFeatures &features) : features (features) {}
31 :
32 : using AST::DefaultASTVisitor::visit;
33 :
34 : void check (AST::Crate &crate);
35 : void visit (AST::Crate &crate) override;
36 :
37 : void visit (AST::LifetimeParam &lifetime_param) override;
38 : void visit (AST::ConstGenericParam &const_param) override;
39 : void visit (AST::BorrowExpr &expr) override;
40 : void visit (AST::BoxExpr &expr) override;
41 : void visit (AST::TypeParam ¶m) override;
42 : void visit (AST::UseTreeGlob &use_tree) override;
43 : void visit (AST::Function &function) override;
44 : void visit (AST::TraitImpl &impl) override;
45 : void visit (AST::Trait &trait) override;
46 : void visit (AST::ExternalTypeItem &item) override;
47 : void visit (AST::ExternBlock &block) override;
48 : void visit (AST::MacroRulesDefinition &rules_def) override;
49 : void visit (AST::RangePattern &pattern) override;
50 : void visit (AST::StructStruct &struct_item) override;
51 : void visit (AST::TraitItemType &trait_item_type) override;
52 : void visit (AST::Enum &enum_item) override;
53 : void visit (AST::EnumItem &enum_variant) override;
54 : void visit (AST::StaticItem &static_item) override;
55 : void visit (AST::TraitAlias &trait_alias) override;
56 :
57 : void visit (AST::Attribute &attr) override;
58 :
59 : enum class GateResult
60 : {
61 : Gated,
62 : Allowed,
63 : };
64 :
65 : GateResult gate (Feature::Name name, location_t loc,
66 : const std::string &error_msg);
67 :
68 : private:
69 : void check_no_core_attribute (const AST::Attribute &attribute);
70 : void check_used_attribute (const AST::Attribute &attribute);
71 : void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
72 : void
73 : check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
74 : void
75 : check_lang_item_attribute (const std::vector<AST::Attribute> &attributes);
76 : void note_stability_attribute (const std::vector<AST::Attribute> &attributes);
77 :
78 : Features::CrateFeatures &features;
79 :
80 : enum class Stability
81 : {
82 : STABLE,
83 : UNSTABLE,
84 : };
85 :
86 : std::map<std::string, Stability> defined_lib_features;
87 : };
88 : } // namespace Rust
89 : #endif
|