From: Arthur Cohen <arthur.co...@embecosm.com>

gcc/rust/ChangeLog:

        * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to 
lang item
        PathInExpressions.
        * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
        * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
        * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
        * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise.
        (ASTLowerPathInExpression::visit): Likewise.
        * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): 
Likewise.
        * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): 
Likewise.
---
 gcc/rust/ast/rust-ast-collector.cc           | 18 ++++++++--
 gcc/rust/ast/rust-ast-visitor.cc             |  6 ++--
 gcc/rust/expand/rust-cfg-strip.cc            | 10 ++++--
 gcc/rust/expand/rust-expand-visitor.cc       |  7 ++--
 gcc/rust/hir/rust-ast-lower.cc               | 35 ++++++++------------
 gcc/rust/resolve/rust-ast-resolve-path.cc    |  5 +++
 gcc/rust/resolve/rust-early-name-resolver.cc |  7 ++--
 7 files changed, 53 insertions(+), 35 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc 
b/gcc/rust/ast/rust-ast-collector.cc
index 978de648a58..073fa728dcf 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -15,12 +15,14 @@
 // You should have received a copy of the GNU General Public License
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
+
 #include "rust-ast-collector.h"
 #include "rust-ast.h"
 #include "rust-diagnostics.h"
 #include "rust-expr.h"
 #include "rust-item.h"
 #include "rust-keyword-values.h"
+#include "rust-path.h"
 #include "rust-system.h"
 #include "rust-token.h"
 
@@ -530,11 +532,23 @@ TokenCollector::visit (PathExprSegment &segment)
 void
 TokenCollector::visit (PathInExpression &path)
 {
-  if (path.opening_scope_resolution ())
+  if (path.is_lang_item ())
     {
-      push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
+      push (Rust::Token::make (TokenId::HASH, path.get_locus ()));
+      push (Rust::Token::make (TokenId::LEFT_SQUARE, path.get_locus ()));
+      push (Rust::Token::make_identifier (path.get_locus (), "lang"));
+      push (Rust::Token::make (TokenId::EQUAL, path.get_locus ()));
+      push (
+       Rust::Token::make_string (path.get_locus (),
+                                 LangItem::ToString (path.get_lang_item ())));
+      push (Rust::Token::make (TokenId::RIGHT_SQUARE, path.get_locus ()));
+
+      return;
     }
 
+  if (path.opening_scope_resolution ())
+    push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
+
   visit_items_joined_by_separator (path.get_segments (), SCOPE_RESOLUTION);
 }
 
diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index e2e2d9dda37..077b41b5cac 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -89,8 +89,10 @@ void
 DefaultASTVisitor::visit (AST::PathInExpression &path)
 {
   visit_outer_attrs (path);
-  for (auto &segment : path.get_segments ())
-    visit (segment);
+
+  if (!path.is_lang_item ())
+    for (auto &segment : path.get_segments ())
+      visit (segment);
 }
 
 void
diff --git a/gcc/rust/expand/rust-cfg-strip.cc 
b/gcc/rust/expand/rust-cfg-strip.cc
index 4e6a8ac2b5f..a8c3ca5bfc9 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -19,6 +19,7 @@
 #include "rust-cfg-strip.h"
 #include "rust-ast-full.h"
 #include "rust-ast-visitor.h"
+#include "rust-path.h"
 #include "rust-session-manager.h"
 #include "rust-attribute-values.h"
 
@@ -434,10 +435,13 @@ CfgStrip::visit (AST::PathInExpression &path)
       return;
     }
 
-  for (auto &segment : path.get_segments ())
+  if (!path.is_lang_item ())
     {
-      if (segment.has_generic_args ())
-       maybe_strip_generic_args (segment.get_generic_args ());
+      for (auto &segment : path.get_segments ())
+       {
+         if (segment.has_generic_args ())
+           maybe_strip_generic_args (segment.get_generic_args ());
+       }
     }
 }
 
diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index 38399d0d74b..6e06fa51609 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -477,9 +477,10 @@ ExpandVisitor::visit (AST::MacroInvocation &macro_invoc)
 void
 ExpandVisitor::visit (AST::PathInExpression &path)
 {
-  for (auto &segment : path.get_segments ())
-    if (segment.has_generic_args ())
-      expand_generic_args (segment.get_generic_args ());
+  if (!path.is_lang_item ())
+    for (auto &segment : path.get_segments ())
+      if (segment.has_generic_args ())
+       expand_generic_args (segment.get_generic_args ());
 }
 
 void
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index a94a8432273..ebdf9810b34 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -418,24 +418,7 @@ ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr)
 void
 ASTLoweringExprWithBlock::visit (AST::ForLoopExpr &expr)
 {
-  // TODO FIXME
-
-  // HIR::BlockExpr *loop_block
-  //   = ASTLoweringBlock::translate (expr.get_loop_block ().get (),
-  //   &terminated);
-  // HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ());
-  // HIR::Expr *iterator_expr
-  //   = ASTLoweringExpr::translate (expr.get_iterator_expr ().get (),
-  //                             &terminated);
-  // HIR::Pattern *loop_pattern
-  //   = ASTLoweringPattern::translate (expr.get_pattern ().get ());
-
-  // auto crate_num = mappings->get_current_crate ();
-  // Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
-  //                            mappings->get_next_hir_id (crate_num),
-  //                            UNKNOWN_LOCAL_DEFID);
-
-  gcc_unreachable ();
+  rust_unreachable ();
 }
 
 void
@@ -494,6 +477,18 @@ ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr)
 void
 ASTLowerPathInExpression::visit (AST::PathInExpression &expr)
 {
+  auto crate_num = mappings.get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
+                                mappings.get_next_hir_id (crate_num),
+                                UNKNOWN_LOCAL_DEFID);
+
+  if (expr.is_lang_item ())
+    {
+      translated = new HIR::PathInExpression (mapping, expr.get_lang_item (),
+                                             expr.get_locus (), false);
+      return;
+    }
+
   std::vector<HIR::PathExprSegment> path_segments;
   auto &segments = expr.get_segments ();
   for (auto &s : segments)
@@ -504,10 +499,6 @@ ASTLowerPathInExpression::visit (AST::PathInExpression 
&expr)
       HIR::PathExprSegment *lowered_seg = &path_segments.back ();
       mappings.insert_hir_path_expr_seg (lowered_seg);
     }
-  auto crate_num = mappings.get_current_crate ();
-  Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
-                                mappings.get_next_hir_id (crate_num),
-                                UNKNOWN_LOCAL_DEFID);
 
   translated = new HIR::PathInExpression (mapping, std::move (path_segments),
                                          expr.get_locus (),
diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc 
b/gcc/rust/resolve/rust-ast-resolve-path.cc
index ea39fd46690..256159bc5cc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-path.cc
@@ -18,6 +18,7 @@
 
 #include "rust-ast-resolve-path.h"
 #include "rust-ast-resolve-type.h"
+#include "rust-hir-map.h"
 #include "rust-path.h"
 
 namespace Rust {
@@ -49,6 +50,10 @@ ResolvePath::go (AST::SimplePath &expr)
 NodeId
 ResolvePath::resolve_path (AST::PathInExpression &expr)
 {
+  if (expr.is_lang_item ())
+    return Analysis::Mappings::get ().get_lang_item_node (
+      expr.get_lang_item ());
+
   NodeId resolved_node_id = UNKNOWN_NODEID;
   NodeId module_scope_id = resolver->peek_current_module_scope ();
   NodeId previous_resolved_node_id = module_scope_id;
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc 
b/gcc/rust/resolve/rust-early-name-resolver.cc
index 34bac98534c..42a4a17090f 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -156,9 +156,10 @@ EarlyNameResolver::visit (AST::ConstGenericParam &)
 void
 EarlyNameResolver::visit (AST::PathInExpression &path)
 {
-  for (auto &segment : path.get_segments ())
-    if (segment.has_generic_args ())
-      resolve_generic_args (segment.get_generic_args ());
+  if (!path.is_lang_item ())
+    for (auto &segment : path.get_segments ())
+      if (segment.has_generic_args ())
+       resolve_generic_args (segment.get_generic_args ());
 }
 
 void
-- 
2.45.2

Reply via email to