|
| 1 | +// Copyright (C) 2020-2022 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-attributes.h" |
| 20 | + |
| 21 | +namespace Rust { |
| 22 | +namespace Analysis { |
| 23 | + |
| 24 | +// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#256 |
| 25 | +static const BuiltinAttrDefinition __definitions[] = { |
| 26 | + {"inline", CODE_GENERATION}, {"cfg", EXPANSION}, {"cfg_attr", EXPANSION}, |
| 27 | + {"allow", STATIC_ANALYSIS}, {"lang", HIR_LOWERING}, |
| 28 | +}; |
| 29 | + |
| 30 | +BuiltinAttributeMappings * |
| 31 | +BuiltinAttributeMappings::get () |
| 32 | +{ |
| 33 | + static BuiltinAttributeMappings *instance = nullptr; |
| 34 | + if (instance == nullptr) |
| 35 | + instance = new BuiltinAttributeMappings (); |
| 36 | + |
| 37 | + return instance; |
| 38 | +} |
| 39 | + |
| 40 | +const BuiltinAttrDefinition & |
| 41 | +BuiltinAttributeMappings::lookup_builtin (const std::string &attr_name) const |
| 42 | +{ |
| 43 | + auto it = mappings.find (attr_name); |
| 44 | + if (it == mappings.end ()) |
| 45 | + return BuiltinAttrDefinition::error_node (); |
| 46 | + |
| 47 | + return it->second; |
| 48 | +} |
| 49 | + |
| 50 | +BuiltinAttributeMappings::BuiltinAttributeMappings () |
| 51 | +{ |
| 52 | + size_t ndefinitions = sizeof (__definitions) / sizeof (BuiltinAttrDefinition); |
| 53 | + for (size_t i = 0; i < ndefinitions; i++) |
| 54 | + { |
| 55 | + const BuiltinAttrDefinition &def = __definitions[i]; |
| 56 | + mappings.insert ({def.name, def}); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +} // namespace Analysis |
| 61 | +} // namespace Rust |
0 commit comments