]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: hir: Lower lang-item paths
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 29 Nov 2024 10:06:25 +0000 (11:06 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 21 Mar 2025 11:33:13 +0000 (12:33 +0100)
gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Adapt to
handle lang item paths.
(ASTLowerTypePath::visit): Likewise.
(ASTLowerTypePath::translate_type_path): New.
(ASTLowerTypePath::translate_lang_item_type_path): New.
* hir/rust-ast-lower-type.h: Adapt to handle lang item paths.
* resolve/rust-ast-resolve-type.h: Likewise.

gcc/rust/hir/rust-ast-lower-type.cc
gcc/rust/hir/rust-ast-lower-type.h
gcc/rust/resolve/rust-ast-resolve-type.h

index c09d60fafc6fa19f09a9e894796bfee4e5a913d3..df06e48b801d6ddd1cb74e9fdb849103dc8bf218 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-ast-lower-type.h"
-#include "optional.h"
-#include "rust-attribute-values.h"
+#include "rust-hir-map.h"
+#include "rust-hir-path.h"
 #include "rust-path.h"
+#include "rust-pattern.h"
 
 namespace Rust {
 namespace HIR {
@@ -27,16 +28,20 @@ namespace HIR {
 HIR::TypePath *
 ASTLowerTypePath::translate (AST::Path &type)
 {
-  rust_assert (type.get_path_kind () == AST::Path::Kind::Type);
+  ASTLowerTypePath resolver;
 
-  return ASTLowerTypePath::translate (static_cast<AST::TypePath &> (type));
-}
+  switch (type.get_path_kind ())
+    {
+    case AST::Path::Kind::LangItem:
+      resolver.visit (static_cast<AST::LangItemPath &> (type));
+      break;
+    case AST::Path::Kind::Type:
+      resolver.visit (static_cast<AST::TypePath &> (type));
+      break;
+    default:
+      rust_unreachable ();
+    }
 
-HIR::TypePath *
-ASTLowerTypePath::translate (AST::TypePath &type)
-{
-  ASTLowerTypePath resolver;
-  type.accept_vis (resolver);
   rust_assert (resolver.translated != nullptr);
   return resolver.translated;
 }
@@ -135,6 +140,26 @@ ASTLowerTypePath::visit (AST::TypePath &path)
                         path.has_opening_scope_resolution_op ());
 }
 
+void
+ASTLowerTypePath::visit (AST::LangItemPath &path)
+{
+  auto crate_num = mappings.get_current_crate ();
+  auto hirid = mappings.get_next_hir_id (crate_num);
+
+  Analysis::NodeMapping mapping (crate_num, path.get_node_id (), hirid,
+                                mappings.get_next_localdef_id (crate_num));
+
+  std::vector<std::unique_ptr<HIR::TypePathSegment>> translated_segments;
+  translated_segments.emplace_back (std::unique_ptr<HIR::TypePathSegment> (
+    new HIR::TypePathSegment (mapping,
+                             LangItem::ToString (path.get_lang_item_kind ()),
+                             false, path.get_locus ())));
+
+  translated
+    = new HIR::TypePath (std::move (mapping), std::move (translated_segments),
+                        path.get_locus ());
+}
+
 HIR::QualifiedPathInType *
 ASTLowerQualifiedPathInType::translate (AST::QualifiedPathInType &type)
 {
index 72c6b29d7dd05c2c163c62f25b06aae16d45ef50..0429e3fcf986e3ab1da84741f9eef3d5edd4f78e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "rust-ast-lower-base.h"
 #include "rust-ast-lower-expr.h"
+#include "rust-hir-path.h"
 
 namespace Rust {
 namespace HIR {
@@ -32,18 +33,21 @@ protected:
 
 public:
   static HIR::TypePath *translate (AST::Path &type);
-  static HIR::TypePath *translate (AST::TypePath &type);
 
   void visit (AST::TypePathSegmentFunction &segment) override;
   void visit (AST::TypePathSegment &segment) override;
   void visit (AST::TypePathSegmentGeneric &segment) override;
   void visit (AST::TypePath &path) override;
+  void visit (AST::LangItemPath &path) override;
 
 protected:
   HIR::TypePathSegment *translated_segment;
 
 private:
   HIR::TypePath *translated;
+
+  static HIR::TypePath *translate_type_path (AST::TypePath &type);
+  static HIR::TypePath *translate_lang_item_type_path (AST::LangItemPath &type);
 };
 
 class ASTLowerQualifiedPathInType : public ASTLowerTypePath
index 7c3831a28294ae297fa533cb68713fde7928679d..518c0d80b14d15e8c52b9ec58fb935df05e6dc1d 100644 (file)
@@ -71,13 +71,13 @@ public:
       {
        auto &type = static_cast<AST::LangItemPath &> (type_path);
 
-       rust_debug ("[ARTHUR]: lang item kind: %s",
-                   LangItem::ToString (type.get_lang_item_kind ()).c_str ());
-
        auto lang_item = Analysis::Mappings::get ()
                           .lookup_lang_item_node (type.get_lang_item_kind ())
                           .value ();
 
+       auto resolver = Resolver::get ();
+       resolver->insert_resolved_type (type.get_node_id (), lang_item);
+
        return lang_item;
       }