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-early-name-resolver.cc #3341

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
12 changes: 2 additions & 10 deletions gcc/rust/resolve/rust-early-name-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,17 @@
#include "rust-name-resolver.h"
#include "rust-macro-builtins.h"
#include "rust-attribute-values.h"
#include "rust-attributes.h"

namespace Rust {
namespace Resolver {

// Check if a module contains the `#[macro_use]` attribute
static bool
is_macro_use_module (const AST::Module &mod)
{
for (const auto &attr : mod.get_outer_attrs ())
if (attr.get_path ().as_string () == Values::Attributes::MACRO_USE)
return true;

return false;
}

std::vector<std::unique_ptr<AST::Item>>
EarlyNameResolver::accumulate_escaped_macros (AST::Module &module)
{
if (!is_macro_use_module (module))
if (!Analysis::Attributes::is_macro_use_module (module))
return {};

// Parse the module's items if they haven't been expanded and the file
Expand Down
9 changes: 9 additions & 0 deletions gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ Attributes::is_known (const std::string &attribute_path)

return !lookup.is_error ();
}
bool
Attributes::is_macro_use_module (const AST::Module &mod)
{
for (const auto &attr : mod.get_outer_attrs ())
if (attr.get_path ().as_string () == Values::Attributes::MACRO_USE)
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_macro_use_module (const AST::Module &mod);
};

enum CompilerPass
Expand Down
Loading