diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-11-29 11:06:25 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:33:13 +0100 |
commit | c7c6b5f89a39a39322aefb6e8f181c5fc230b162 (patch) | |
tree | 598cee8f91edc494f6fc0b95e8738064ce1c1475 /gcc/rust/hir | |
parent | 70c87e94e11d97dc63d6ffa4862bd4f97c5f25ba (diff) | |
download | gcc-c7c6b5f89a39a39322aefb6e8f181c5fc230b162.zip gcc-c7c6b5f89a39a39322aefb6e8f181c5fc230b162.tar.gz gcc-c7c6b5f89a39a39322aefb6e8f181c5fc230b162.tar.bz2 |
gccrs: hir: Lower lang-item paths
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.
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-type.cc | 45 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-type.h | 6 |
2 files changed, 40 insertions, 11 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index c09d60f..df06e48 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -17,9 +17,10 @@ // <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) { diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index 72c6b29..0429e3f 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -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 |