aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-11-06 16:32:35 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:33:13 +0100
commit5d79fbd65ccaf51afa90cab5454b3f6f5b0e6f75 (patch)
tree7a224ceaeeb98b238a7ad5f56d83a9d88bd90317 /gcc/rust/resolve
parent081828243086965b3882489ffc36216c1d7b3cb0 (diff)
downloadgcc-5d79fbd65ccaf51afa90cab5454b3f6f5b0e6f75.zip
gcc-5d79fbd65ccaf51afa90cab5454b3f6f5b0e6f75.tar.gz
gcc-5d79fbd65ccaf51afa90cab5454b3f6f5b0e6f75.tar.bz2
gccrs: hir: Start adapting visitors to accept multiple kinds of Paths
gcc/rust/ChangeLog: * ast/rust-item.h: Add new method to specifically get a type-path. * ast/rust-path.cc (LangItemPath::as_string): Implement properly. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt visitor to use the new LangItemPath. * hir/rust-ast-lower-type.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-type.h: Likewise.
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.cc2
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h28
2 files changed, 29 insertions, 1 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 245523a..a330541 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -680,7 +680,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block)
// setup paths
CanonicalPath canonical_trait_type = CanonicalPath::create_empty ();
- bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (),
+ bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path_type (),
canonical_trait_type);
if (!ok)
{
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index 561948e..ed055a1 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -21,6 +21,8 @@
#include "rust-ast-resolve-base.h"
#include "rust-ast-resolve-expr.h"
+#include "rust-hir-map.h"
+#include "rust-path.h"
namespace Rust {
namespace Resolver {
@@ -56,6 +58,32 @@ class ResolveType : public ResolverBase
using Rust::Resolver::ResolverBase::visit;
public:
+ static NodeId go (AST::TypePath &type_path)
+ {
+ return ResolveType::go ((AST::Type &) type_path);
+ }
+
+ static NodeId go (AST::Path &type_path)
+ {
+ if (type_path.get_path_kind () == AST::Path::Kind::LangItem)
+ {
+ auto &type = static_cast<AST::LangItemPath &> (type_path);
+
+ Analysis::Mappings::get_lang_item (type);
+
+ type.get_node_id ();
+ }
+
+ rust_assert (type_path.get_path_kind () == AST::Path::Kind::Type);
+
+ // We have to do this dance to first downcast to a typepath, and then upcast
+ // to a Type. The altnernative is to split `go` into `go` and `go_inner` or
+ // something, but eventually this will need to change as we'll need
+ // `ResolveType::` to resolve other kinds of `Path`s as well.
+ return ResolveType::go (
+ (AST::Type &) static_cast<AST::TypePath &> (type_path));
+ }
+
static NodeId go (AST::Type &type)
{
ResolveType resolver;