Skip to content

Commit

Permalink
gcc/rust/ChangeLog:
Browse files Browse the repository at this point in the history
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_macro_definition): "modified fn"
	* resolve/rust-toplevel-name-resolver-2.0.cc (is_macro_export): "rm check fn"
	(TopLevel::visit): "modified fn"
	* util/rust-attributes.cc (Attributes::is_macro_export): "added checker fn"
	* util/rust-attributes.h: "added"

Signed-off-by: Om Swaroop Nayak <[email protected]>
  • Loading branch information
saeitoshi-10 committed Jan 4, 2025
1 parent 9de4235 commit 4bbad83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
9 changes: 3 additions & 6 deletions gcc/rust/hir/rust-ast-lower-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,9 @@ ASTLoweringBase::lower_extern_block (AST::ExternBlock &extern_block)
void
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 () == Values::Attributes::MACRO_EXPORT)
is_export = true;

if (is_export)


if (Analysis::Attributes::is_macro_export(def.get_outer_attrs()))
{
mappings.insert_exported_macro (def);
mappings.insert_ast_item (&def);
Expand Down
19 changes: 10 additions & 9 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rust-ast-full.h"
#include "rust-hir-map.h"
#include "rust-attribute-values.h"
#include "rust-attributes.h"

namespace Rust {
namespace Resolver2_0 {
Expand Down Expand Up @@ -168,15 +169,15 @@ TopLevel::visit (AST::ExternCrate &crate)
crate.get_referenced_crate ());
}

static bool
is_macro_export (AST::MacroRulesDefinition &def)
{
for (const auto &attr : def.get_outer_attrs ())
if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT)
return true;
// static bool
// is_macro_export (AST::MacroRulesDefinition &def)
// {
// for (const auto &attr : def.get_outer_attrs ())
// if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT)
// return true;

return false;
}
// return false;
// }

void
TopLevel::visit (AST::MacroRulesDefinition &macro)
Expand All @@ -186,7 +187,7 @@ TopLevel::visit (AST::MacroRulesDefinition &macro)
// crate if they are marked with #[macro_export]. The execption to this is
// macros 2.0, which get resolved and inserted like regular items.

if (is_macro_export (macro))
if (Analysis::Attributes::is_macro_export (macro.get_outer_attrs()))
{
auto res = ctx.macros.insert_at_root (macro.get_rule_name (),
macro.get_node_id ());
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_macro_export (AST::AttrVec outer_attrs)
{
for (auto &attr : outer_attrs)
{
if (attr.get_path ().as_string() == Values::Attributes::MACRO_EXPORT)
{
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_export (AST::AttrVec outer_attrs);
};

enum CompilerPass
Expand Down

0 comments on commit 4bbad83

Please sign in to comment.