]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: resolve: Convert identifier to a SimplePath
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 13 Jul 2023 09:57:41 +0000 (11:57 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:59 +0000 (18:55 +0100)
We wish to remove node ids from identifiers, because they do not make
that much sense and are only used for procedural macros anyway. This
means we either have to wrap those into a structure or converting them
to an existing structure that already have a node id. This commit
convert those meta word identifiers to a meta path SimplePath.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add new constructor for SimplePath from an
identifier.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Add
conversion.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-ast.h
gcc/rust/expand/rust-expand-visitor.cc

index 5be6932ce609adbf745f761edb5c4026c65e6bf6..8ec707f3afe995abc09bb8e121336883630a6f10 100644 (file)
@@ -427,6 +427,13 @@ public:
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
+  SimplePath (Identifier ident)
+    : opening_scope_resolution (false),
+      segments ({SimplePathSegment (ident.as_string (), ident.get_locus ())}),
+      locus (ident.get_locus ()),
+      node_id (Analysis::Mappings::get ()->get_next_node_id ())
+  {}
+
   // Creates an empty SimplePath.
   static SimplePath create_empty ()
   {
index 3fa0b5ffdcbeea819868ac67811d73632c9c991b..54075e1fa48c4b369d5a054bf5fb36afb7b25cd9 100644 (file)
@@ -87,8 +87,15 @@ get_traits_to_derive (AST::Attribute &attr)
                      break;
                      case AST::MetaItem::ItemKind::Word: {
                        auto word = static_cast<AST::MetaWord *> (meta_item);
+                       // Convert current word to path
+                       current
+                         = make_unique<AST::MetaItemPath> (AST::MetaItemPath (
+                           AST::SimplePath (word->get_ident ())));
+                       auto path
+                         = static_cast<AST::MetaItemPath *> (current.get ());
+
                        result.push_back (
-                         Rust::make_unique<Identifier> (word->get_ident ()));
+                         make_unique<AST::SimplePath> (path->get_path ()));
                      }
                      break;
                    case AST::MetaItem::ItemKind::ListPaths: