Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor some attribute functions in rust-hir-map.cc and rust-early-name-resolver.cc #3344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions gcc/rust/resolve/rust-early-name-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "rust-name-resolver.h"
#include "rust-macro-builtins.h"
#include "rust-attribute-values.h"
#include "rust-attributes.h"

namespace Rust {
namespace Resolver {
Expand Down Expand Up @@ -485,14 +486,8 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
auto rules_def = mappings.lookup_macro_def (resolved_node);

auto &outer_attrs = rules_def.value ()->get_outer_attrs ();
bool is_builtin
= std::any_of (outer_attrs.begin (), outer_attrs.end (),
[] (AST::Attribute attr) {
return attr.get_path ()
== Values::Attributes::RUSTC_BUILTIN_MACRO;
});

if (is_builtin)

if (Analysis::Attributes::is_rustc_builtin_macro (outer_attrs))
{
auto builtin_kind = builtin_macro_from_string (
rules_def.value ()->get_rule_name ().as_string ());
Expand Down
12 changes: 12 additions & 0 deletions gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ Attributes::is_known (const std::string &attribute_path)

return !lookup.is_error ();
}
bool
Attributes::is_rustc_builtin_macro (AST::AttrVec outer_attrs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using const AST::AttrVec& outer_attrs since this can be constified

{
for (auto attr : outer_attrs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should probably do const auto attr

{
if (attr.get_path () == Values::Attributes::RUSTC_BUILTIN_MACRO)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do return true here no need for the extra braces

return true;
}
}
return false;
}

using Attrs = Values::Attributes;

Expand Down
1 change: 1 addition & 0 deletions gcc/rust/util/rust-attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Attributes
{
public:
static bool is_known (const std::string &attribute_path);
static bool is_rustc_builtin_macro (AST::AttrVec outer_attrs);
};

enum CompilerPass
Expand Down
10 changes: 3 additions & 7 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rust-macro-builtins.h"
#include "rust-mapping-common.h"
#include "rust-attribute-values.h"
#include "rust-attributes.h"

namespace Rust {
namespace Analysis {
Expand Down Expand Up @@ -848,13 +849,8 @@ void
Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
{
auto outer_attrs = macro->get_outer_attrs ();
bool should_be_builtin
= std::any_of (outer_attrs.begin (), outer_attrs.end (),
[] (AST::Attribute attr) {
return attr.get_path ()
== Values::Attributes::RUSTC_BUILTIN_MACRO;
});
if (should_be_builtin)

if (Analysis::Attributes::is_rustc_builtin_macro (outer_attrs))
{
auto builtin
= MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
Expand Down
Loading