aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-attribute-values.h
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-09-01 13:14:09 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:04:35 +0100
commitfc024ea79deb5a9ec3cfd68b59719bef52db49ff (patch)
tree5f747b69d801d1f231bb391591ade781db3e7581 /gcc/rust/util/rust-attribute-values.h
parent1f09a4fedca20c0b9068d4c466b360b449af5d56 (diff)
downloadgcc-fc024ea79deb5a9ec3cfd68b59719bef52db49ff.zip
gcc-fc024ea79deb5a9ec3cfd68b59719bef52db49ff.tar.gz
gcc-fc024ea79deb5a9ec3cfd68b59719bef52db49ff.tar.bz2
gccrs: Unify raw attribute values
Attribute values were used as raw string, this is error prone and makes renaming harder. Using a constexpr instead will leverage the power of the compiler and emit an error when an incorrect builtin attribute value is used. gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::check_cfg_predicate): Change raw string to constexpr call. (Attribute::separate_cfg_attrs): Likewise. * backend/rust-compile-base.cc (should_mangle_item): Likewise. (HIRCompileBase::setup_fndecl): Likewise. (HIRCompileBase::handle_cold_attribute_on_fndecl): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute): Likewise. * checks/errors/rust-unsafe-checker.cc (check_target_attr): Likewise. * expand/rust-cfg-strip.cc (fails_cfg): Likewise. (fails_cfg_with_expand): Likewise. (expand_cfg_attrs): Likewise. * expand/rust-macro-builtins.cc: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise. (ASTLoweringBase::lower_macro_definition): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_doc_comment): Likewise. * parse/rust-parse.cc (extract_module_path): Likewise. * resolve/rust-early-name-resolver.cc (is_macro_use_module): Likewise. (EarlyNameResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (is_macro_export): Likwise. * rust-session-manager.cc (Session::injection): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Likewise. * util/rust-attributes.cc (is_proc_macro_type): Likewise. (AttributeChecker::check_attribute): Likewise. (AttributeChecker::visit): Likewise. * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise. * util/rust-attribute-values.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/util/rust-attribute-values.h')
-rw-r--r--gcc/rust/util/rust-attribute-values.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-attribute-values.h b/gcc/rust/util/rust-attribute-values.h
new file mode 100644
index 0000000..513550a
--- /dev/null
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -0,0 +1,40 @@
+#ifndef RUST_ATTRIBUTES_VALUE_H
+#define RUST_ATTRIBUTES_VALUE_H
+
+namespace Rust {
+namespace Values {
+// TODO: Change this to a namespace + inline constexpr in the future
+class Attributes
+{
+public:
+ static constexpr auto &INLINE = "inline";
+ static constexpr auto &COLD = "cold";
+ static constexpr auto &CFG = "cfg";
+ static constexpr auto &CFG_ATTR = "cfg_attr";
+ static constexpr auto &DEPRECATED = "deprecated";
+ static constexpr auto &ALLOW = "allow";
+ static constexpr auto &ALLOW_INTERNAL_UNSTABLE = "allow_internal_unstable";
+ static constexpr auto &DOC = "doc";
+ static constexpr auto &MUST_USE = "must_use";
+ static constexpr auto &LANG = "lang";
+ static constexpr auto &LINK_SECTION = "link_section";
+ static constexpr auto &NO_MANGLE = "no_mangle";
+ static constexpr auto &REPR = "repr";
+ static constexpr auto &RUSTC_BUILTIN_MACRO = "rustc_builtin_macro";
+ static constexpr auto &PATH = "path";
+ static constexpr auto &MACRO_USE = "macro_use";
+ static constexpr auto &MACRO_EXPORT = "macro_export";
+ static constexpr auto &PROC_MACRO = "proc_macro";
+ static constexpr auto &PROC_MACRO_DERIVE = "proc_macro_derive";
+ static constexpr auto &PROC_MACRO_ATTRIBUTE = "proc_macro_attribute";
+ static constexpr auto &TARGET_FEATURE = "target_feature";
+ // From now on, these are reserved by the compiler and gated through
+ // #![feature(rustc_attrs)]
+ static constexpr auto &RUSTC_INHERIT_OVERFLOW_CHECKS
+ = "rustc_inherit_overflow_checks";
+ static constexpr auto &STABLE = "stable";
+};
+} // namespace Values
+} // namespace Rust
+
+#endif /* !RUST_ATTRIBUTES_VALUE_H */