aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-05-08 17:32:05 -0400
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2025-05-15 10:32:23 +0000
commit4f772da8df444fbcb84821d4c4c60cf1cc2f5479 (patch)
tree20f2c1ab0e98c05902217f38315fb2054fc6342b
parent7a562bcec1f7604e6df1b604979ce4c1456e6049 (diff)
downloadgcc-4f772da8df444fbcb84821d4c4c60cf1cc2f5479.zip
gcc-4f772da8df444fbcb84821d4c4c60cf1cc2f5479.tar.gz
gcc-4f772da8df444fbcb84821d4c4c60cf1cc2f5479.tar.bz2
Small improvements to DefaultASTVisitor and nr2.0
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Only visit the path of an instance of Visibility if the instance has a path. * ast/rust-ast.h (SimplePath::SimplePath): Make sure constructors are explicit. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Pass entire paths to NameResolutionContext::resolve_path. (Early::visit): Likewise and avoid copying a path. * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Assert that at least one path segment has been passed in. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
-rw-r--r--gcc/rust/ast/rust-ast-visitor.cc3
-rw-r--r--gcc/rust/ast/rust-ast.h8
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver-2.0.cc12
-rw-r--r--gcc/rust/resolve/rust-forever-stack.hxx2
4 files changed, 13 insertions, 12 deletions
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 105417b..8b47a81 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -755,7 +755,8 @@ DefaultASTVisitor::visit (AST::TypeBoundWhereClauseItem &item)
void
DefaultASTVisitor::visit (AST::Visibility &vis)
{
- visit (vis.get_path ());
+ if (vis.has_path ())
+ visit (vis.get_path ());
}
void
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 9581dd5..34d6c09 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -403,15 +403,15 @@ class SimplePath
public:
// Constructor
- SimplePath (std::vector<SimplePathSegment> path_segments,
- bool has_opening_scope_resolution = false,
- location_t locus = UNDEF_LOCATION)
+ explicit SimplePath (std::vector<SimplePathSegment> path_segments,
+ bool has_opening_scope_resolution = false,
+ location_t locus = UNDEF_LOCATION)
: opening_scope_resolution (has_opening_scope_resolution),
segments (std::move (path_segments)), locus (locus),
node_id (Analysis::Mappings::get ().get_next_node_id ())
{}
- SimplePath (Identifier ident)
+ explicit SimplePath (Identifier ident)
: opening_scope_resolution (false),
segments ({SimplePathSegment (ident.as_string (), ident.get_locus ())}),
locus (ident.get_locus ()),
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index 3060b29..73d71ca 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -249,7 +249,7 @@ Early::visit (AST::Module &module)
void
Early::visit (AST::MacroInvocation &invoc)
{
- auto path = invoc.get_invoc_data ().get_path ();
+ auto &path = invoc.get_invoc_data ().get_path ();
if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin)
for (auto &pending_invoc : invoc.get_pending_eager_invocations ())
@@ -272,7 +272,7 @@ Early::visit (AST::MacroInvocation &invoc)
// we won't have changed `definition` from `nullopt` if there are more
// than one segments in our path
if (!definition.has_value ())
- definition = ctx.resolve_path (path.get_segments (), Namespace::Macros);
+ definition = ctx.resolve_path (path, Namespace::Macros);
// if the definition still does not have a value, then it's an error
if (!definition.has_value ())
@@ -314,8 +314,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
auto traits = attr.get_traits_to_derive ();
for (auto &trait : traits)
{
- auto definition = ctx.resolve_path (trait.get ().get_segments (),
- Namespace::Macros);
+ auto definition
+ = ctx.resolve_path (trait.get (), Namespace::Macros);
if (!definition.has_value ())
{
// FIXME: Change to proper error message
@@ -337,8 +337,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
->lookup_builtin (name)
.is_error ()) // Do not resolve builtins
{
- auto definition = ctx.resolve_path (attr.get_path ().get_segments (),
- Namespace::Macros);
+ auto definition
+ = ctx.resolve_path (attr.get_path (), Namespace::Macros);
if (!definition.has_value ())
{
// FIXME: Change to proper error message
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index abf3a53..f814c89 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -629,7 +629,7 @@ ForeverStack<N>::resolve_path (
std::function<void (const S &, NodeId)> insert_segment_resolution,
std::vector<Error> &collect_errors)
{
- // TODO: What to do if segments.empty() ?
+ rust_assert (!segments.empty ());
// handle paths with opening scopes
std::function<void (void)> cleanup_current = [] () {};