Skip to content

Commit

Permalink
wip: split me up
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Dec 23, 2024
1 parent 4f99160 commit de41902
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
19 changes: 17 additions & 2 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#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"

Expand Down Expand Up @@ -553,11 +554,25 @@ TokenCollector::visit (PathExprSegment &segment)
void
TokenCollector::visit (PathInExpression &path)
{
if (path.opening_scope_resolution ())
if (path.get_path ().get_path_kind () == Path::Kind::LangItem)
{
push (Rust::Token::make (SCOPE_RESOLUTION, path.get_locus ()));
auto lang_item = static_cast<LangItemPath &> (path.get_path ());

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 (
lang_item.get_lang_item_kind ())));
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);
}

Expand Down
4 changes: 3 additions & 1 deletion gcc/rust/ast/rust-desugar-for-loops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rust-diagnostics.h"
#include "rust-expr.h"
#include "rust-ast-builder.h"
#include "rust-ast-dump.h"

namespace Rust {
namespace AST {
Expand Down Expand Up @@ -133,7 +134,8 @@ DesugarForLoops::desugar (AST::ForLoopExpr &expr)
loop_stmts.emplace_back (std::move (let_next));
loop_stmts.emplace_back (ctx.statementify (std::move (match_next)));
loop_stmts.emplace_back (std::move (let_pat));
loop_stmts.emplace_back (ctx.statementify (expr.get_loop_block().clone_expr()));
loop_stmts.emplace_back (
ctx.statementify (expr.get_loop_block ().clone_expr ()));

// loop {
// <let_next>;
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ class PathInExpression : public Pattern, public ExprWithoutBlock

location_t get_locus () const override final { return locus; }

Path& get_path() { return *path; }

void accept_vis (ASTVisitor &vis) override;

void mark_for_strip () override { marked_for_strip = true; }
Expand Down
19 changes: 1 addition & 18 deletions gcc/rust/hir/rust-ast-lower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de41902

Please sign in to comment.