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-ast-lower-base.cc and rust-toplevel-name-resolver.cc #3345

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
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()))
Copy link
Member

Choose a reason for hiding this comment

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

looks like bad formating here you need space before the opening braces for the arguments

{
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
Copy link
Member

Choose a reason for hiding this comment

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

You need to remove this comment since you have moved the function over to another file

// 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)
Copy link
Member

Choose a reason for hiding this comment

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

missing const reference here

{
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.

const please

{
if (attr.get_path ().as_string() == Values::Attributes::MACRO_EXPORT)
{
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 get rid of this braces here in the if statement

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
Loading