aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-07-21 18:23:00 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 19:00:27 +0100
commit3a5a74d91774dccd4ff7adc8b809781dd25a0f44 (patch)
tree7c0c3fae1903eceb87131871336ac955fb493eaa /gcc
parentd3d006d6b08710c42ccede8a041f6a8366a75ffa (diff)
downloadgcc-3a5a74d91774dccd4ff7adc8b809781dd25a0f44.zip
gcc-3a5a74d91774dccd4ff7adc8b809781dd25a0f44.tar.gz
gcc-3a5a74d91774dccd4ff7adc8b809781dd25a0f44.tar.bz2
gccrs: toplevel: Handle macro definitions properly
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_or_error_out): Fix format string. (is_macro_export): New method. (TopLevel::visit): Handle macro definitions.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc35
1 files changed, 31 insertions, 4 deletions
diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
index 7923342..2c0e077 100644
--- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
@@ -45,7 +45,8 @@ TopLevel::insert_or_error_out (const Identifier &identifier, const T &node,
rich_location rich_loc (line_table, loc);
rich_loc.add_range (node_locations[result.error ().existing]);
- rust_error_at (rich_loc, "already defined");
+ rust_error_at (rich_loc, ErrorCode::E0428, "%qs defined multiple times",
+ identifier.as_string ().c_str ());
}
}
@@ -70,12 +71,38 @@ TopLevel::visit (AST::Module &module)
module.get_name ());
}
+static bool
+is_macro_export (AST::MacroRulesDefinition &def)
+{
+ for (const auto &attr : def.get_outer_attrs ())
+ if (attr.get_path ().as_string () == "macro_export")
+ return true;
+
+ return false;
+}
+
void
TopLevel::visit (AST::MacroRulesDefinition &macro)
{
- // FIXME: Do we want to insert macro rules here already? Probably, right?
- // So that we can easily resolve in `Early`?
- insert_or_error_out (macro.get_rule_name (), macro, Namespace::Macros);
+ // we do not insert macros in the current rib as that needs to be done in the
+ // textual scope of the Early pass. we only insert them in the root of the
+ // crate if they are marked with #[macro_export]
+
+ if (is_macro_export (macro))
+ {
+ auto res = ctx.macros.insert_at_root (macro.get_rule_name (),
+ macro.get_node_id ());
+ if (!res)
+ {
+ // TODO: Factor this
+ rich_location rich_loc (line_table, macro.get_locus ());
+ rich_loc.add_range (node_locations[res.error ().existing]);
+
+ rust_error_at (rich_loc, ErrorCode::E0428,
+ "macro %qs defined multiple times",
+ macro.get_rule_name ().as_string ().c_str ());
+ }
+ }
}
void