Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Apr 16, 2024
1 parent e06432f commit 7c17958
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
43 changes: 37 additions & 6 deletions gcc/rust/hir/rust-ast-lower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.

#include "rust-ast-lower.h"
#include "optional.h"
#include "rust-ast-lower-item.h"
#include "rust-ast-lower-stmt.h"
#include "rust-ast-lower-expr.h"
Expand All @@ -25,6 +26,7 @@
#include "rust-ast-lower-pattern.h"
#include "rust-ast-lower-struct-field-expr.h"
#include "rust-common.h"
#include "rust-diagnostics.h"
#include "rust-hir-expr.h"
#include "rust-hir-full-decls.h"
#include "rust-hir-map.h"
Expand Down Expand Up @@ -436,6 +438,20 @@ struct ForLoopDesugarCtx
std::move (args), {}, loc));
}

std::unique_ptr<MethodCallExpr>
make_method_call (std::unique_ptr<Expr> &&receiver,
PathExprSegment &&method_path,
tl::optional<std::unique_ptr<Expr>> &&arg)
{
auto args = std::vector<std::unique_ptr<Expr>> ();
if (arg)
args.emplace_back (std::move (*arg));

return std::unique_ptr<MethodCallExpr> (
new MethodCallExpr (next_mapping (), std::move (receiver),
std::move (method_path), std::move (args), {}, loc));
}

std::unique_ptr<Pattern> make_identifier_pattern (std::string &&name,
Mutability mutability,
bool is_ref = false)
Expand Down Expand Up @@ -545,15 +561,28 @@ ASTLoweringExprWithBlock::visit (AST::ForLoopExpr &expr)
rust_assert (body);

// core::iter::IntoIterator::into_iter(<head>)
// auto into_iter_call
// = ctx.make_function_call (ctx.path_in_expr (
// {"core", "iter", "IntoIterator", "into_iter"}),
// std::move (head));

// <head>.into_iter()
auto into_iter_call
= ctx.make_function_call (ctx.path_in_expr (
{"core", "iter", "IntoIterator", "into_iter"}),
std::move (head));
= ctx.make_method_call (std::move (head), ctx.path_segment ("into_iter"),
tl::nullopt);

auto iter = ctx.path_in_expr ({"iter"});

// core::iter::Iterator::next(&mut iter)
auto next_call = ctx.make_function_call (
ctx.path_in_expr ({"core", "iter", "Iterator", "next"}),
ctx.make_mutable_borrow (ctx.path_in_expr ({"iter"})));
// auto next_call
// = ctx.make_function_call (ctx.path_in_expr (
// {"core", "iter", "Iterator", "next"}),
// ctx.make_mutable_borrow (iter->clone_expr ()));

// iter.next()
auto next_call
= ctx.make_method_call (iter->clone_expr (), ctx.path_segment ("next"),
tl::nullopt);

// core::option::Option::None => break,
auto break_arm = ctx.make_break_arm ();
Expand Down Expand Up @@ -613,6 +642,8 @@ ASTLoweringExprWithBlock::visit (AST::ForLoopExpr &expr)
// }
auto block = ctx.make_block (std::move (let_result), std::move (result));

rust_debug ("[ARTHUR] \n%s", block->as_string ().c_str ());

translated = block.release ();
}

Expand Down
6 changes: 4 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,10 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
richloc.add_fixit_replace ("method not found");
rust_error_at (
richloc, ErrorCode::E0599,
"no method named %qs found in the current scope",
expr.get_method_name ().get_segment ().as_string ().c_str ());
"no method named %qs found in the current scope for type %qs (%qs)",
expr.get_method_name ().get_segment ().as_string ().c_str (),
receiver_tyty->as_string ().c_str (),
receiver_tyty->debug_str ().c_str ());
return;
}

Expand Down
3 changes: 0 additions & 3 deletions gcc/rust/typecheck/rust-typecheck-context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,18 @@ TypeCheckContext::lookup_predicate (HirId id, TyTy::TypeBoundPredicate *result)
void
TypeCheckContext::insert_query (HirId id)
{
rust_debug ("[ARTHUR] INSERTING QUERY: %u", id);
querys_in_progress.insert (id);
}

void
TypeCheckContext::query_completed (HirId id)
{
rust_debug ("[ARTHUR] COMPLETING QUERY: %u", id);
querys_in_progress.erase (id);
}

bool
TypeCheckContext::query_in_progress (HirId id) const
{
rust_debug ("[ARTHUR] CHECKING IF QUERY IN PROGRESS: %u", id);
return querys_in_progress.find (id) != querys_in_progress.end ();
}

Expand Down

0 comments on commit 7c17958

Please sign in to comment.