[gcc r14-7822] gccrs: resolve: Convert identifier to a SimplePath

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:01:32 GMT 2024


https://gcc.gnu.org/g:987a411d409fac53041033979e12c404a8995e93

commit r14-7822-g987a411d409fac53041033979e12c404a8995e93
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Thu Jul 13 11:57:41 2023 +0200

    gccrs: resolve: Convert identifier to a SimplePath
    
    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>

Diff:
---
 gcc/rust/ast/rust-ast.h                | 7 +++++++
 gcc/rust/expand/rust-expand-visitor.cc | 9 ++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 5be6932ce60..8ec707f3afe 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -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 ()
   {
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 3fa0b5ffdcb..54075e1fa48 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -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:


More information about the Gcc-cvs mailing list