gccrs: Add support for feature check.
[official-gcc.git] / gcc / rust / checks / errors / rust-feature-gate.cc
blobcd26f8a17f516b2980903d51abdaeb7319d3d9da
1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 // This file is part of GCC.
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.
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.
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/>.
19 #include "rust-feature-gate.h"
20 #include "rust-feature.h"
22 namespace Rust {
24 void
25 FeatureGate::check (AST::Crate &crate)
27 std::vector<Feature> valid_features;
28 for (const auto &attr : crate.inner_attrs)
30 if (attr.get_path ().as_string () == "feature")
32 const auto &attr_input = attr.get_attr_input ();
33 auto type = attr_input.get_attr_input_type ();
34 if (type == AST::AttrInput::AttrInputType::TOKEN_TREE)
36 const auto &option = static_cast<const AST::DelimTokenTree &> (
37 attr.get_attr_input ());
38 std::unique_ptr<AST::AttrInputMetaItemContainer> meta_item (
39 option.parse_to_meta_item ());
40 for (const auto &item : meta_item->get_items ())
42 const auto &name = item->as_string ();
43 auto tname = Feature::as_name (name);
44 if (!tname.is_none ())
45 valid_features.push_back (Feature::create (tname.get ()));
46 else
47 rust_error_at (item->get_locus (), "unknown feature '%s'",
48 name.c_str ());
53 valid_features.shrink_to_fit ();
55 // TODO (mxlol233): add the real feature gate stuff.
56 auto &items = crate.items;
57 for (auto it = items.begin (); it != items.end (); it++)
59 auto &item = *it;
60 item->accept_vis (*this);
63 } // namespace Rust