Skip to content

Commit

Permalink
gcc/rust/ChangeLog:
Browse files Browse the repository at this point in the history
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): "modified impl"
	* util/rust-attributes.cc (Attributes::is_rustc_builtin_macro): "helper function"
	* util/rust-attributes.h: "added"
	* util/rust-hir-map.cc (Mappings::insert_macro_def): "modified impl"

Signed-off-by: Om Swaroop Nayak <[email protected]>
  • Loading branch information
saeitoshi-10 committed Jan 4, 2025
1 parent 6205877 commit 4ae5d60
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
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)
{
for (auto attr : outer_attrs)
{
if (attr.get_path () == Values::Attributes::RUSTC_BUILTIN_MACRO)
{
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

0 comments on commit 4ae5d60

Please sign in to comment.