aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
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/hir
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/hir')
-rw-r--r--gcc/rust/hir/rust-ast-lower-base.cc7
-rw-r--r--gcc/rust/hir/rust-hir-dump.cc3
2 files changed, 6 insertions, 4 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index da36d75..cec2410 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -20,6 +20,7 @@
#include "rust-ast-lower-type.h"
#include "rust-ast-lower-pattern.h"
#include "rust-ast-lower-extern.h"
+#include "rust-attribute-values.h"
namespace Rust {
namespace HIR {
@@ -722,12 +723,12 @@ ASTLoweringBase::handle_outer_attributes (const ItemWrapper &item)
continue;
}
- bool is_lang_item = str_path.compare ("lang") == 0
+ bool is_lang_item = str_path == Values::Attributes::LANG
&& attr.has_attr_input ()
&& attr.get_attr_input ().get_attr_input_type ()
== AST::AttrInput::AttrInputType::LITERAL;
- bool is_doc_item = str_path.compare ("doc") == 0;
+ bool is_doc_item = str_path == Values::Attributes::DOC;
if (is_doc_item)
handle_doc_item_attribute (item, attr);
@@ -967,7 +968,7 @@ ASTLoweringBase::lower_macro_definition (AST::MacroRulesDefinition &def)
{
auto is_export = false;
for (const auto &attr : def.get_outer_attrs ())
- if (attr.get_path ().as_string () == "macro_export")
+ if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT)
is_export = true;
if (is_export)
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index 8870ece..8078ed1 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -23,6 +23,7 @@
#include "rust-hir-type.h"
#include "rust-hir.h"
#include <string>
+#include "rust-attribute-values.h"
namespace Rust {
namespace HIR {
@@ -633,7 +634,7 @@ void
Dump::visit (AST::Attribute &attribute)
{
// Special, no begin/end as this is called by do_inner_attrs.
- put_field ("path", attribute.get_path ().as_string ());
+ put_field (Values::Attributes::PATH, attribute.get_path ().as_string ());
std::string str = "none";
if (attribute.has_attr_input ())