aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2025-01-22 14:09:08 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-24 13:06:54 +0100
commit379b69c149dbbd3c6b3b3b341c58de0b39795be1 (patch)
tree2fe772eb5e5bb34b765a577a5d2938d47cecc599
parentd9a02b1f6164428772a2eb8612cffb2eff9829d7 (diff)
downloadgcc-379b69c149dbbd3c6b3b3b341c58de0b39795be1.zip
gcc-379b69c149dbbd3c6b3b3b341c58de0b39795be1.tar.gz
gcc-379b69c149dbbd3c6b3b3b341c58de0b39795be1.tar.bz2
gccrs: ast: More visitors to allow lang item paths in expressions
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.
-rw-r--r--gcc/rust/ast/rust-ast-collector.cc18
-rw-r--r--gcc/rust/ast/rust-ast-visitor.cc6
-rw-r--r--gcc/rust/expand/rust-cfg-strip.cc10
-rw-r--r--gcc/rust/expand/rust-expand-visitor.cc7
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc35
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-path.cc5
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver.cc7
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 978de64..073fa72 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 e2e2d9d..077b41b 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 4e6a8ac..a8c3ca5 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 38399d0d..6e06fa5 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 a94a843..ebdf981 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 ea39fd4..256159b 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 34bac98..42a4a17 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