aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-10-05 14:19:05 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-10-05 14:19:05 +0100
commit579d76f771bd18c27a527df729d0dcf460c08744 (patch)
tree9cd6c4587fbfb98fc471a26940dc1d2d15684017 /gcc
parent99c28309d3553346d4f0337dbae49f4a8e48da01 (diff)
downloadgcc-579d76f771bd18c27a527df729d0dcf460c08744.zip
gcc-579d76f771bd18c27a527df729d0dcf460c08744.tar.gz
gcc-579d76f771bd18c27a527df729d0dcf460c08744.tar.bz2
Remove lambda iterator from HIR::CallExpr
This removes the bad code style lambda iterators for arguments. They are a bad design choice for static analysis code since the user of the api looses scope to break/return outside from the caller api. This will need to be added to a style-guide in the future. Fixes: #708
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile.cc22
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h14
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h6
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc131
-rw-r--r--gcc/testsuite/rust/compile/tuple_struct3.rs5
5 files changed, 87 insertions, 91 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 58c679f..d6c6066 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -74,11 +74,11 @@ CompileExpr::visit (HIR::CallExpr &expr)
// this assumes all fields are in order from type resolution and if a
// base struct was specified those fields are filed via accesors
std::vector<Bexpression *> vals;
- expr.iterate_params ([&] (HIR::Expr *argument) mutable -> bool {
- Bexpression *e = CompileExpr::Compile (argument, ctx);
- vals.push_back (e);
- return true;
- });
+ for (auto &argument : expr.get_arguments ())
+ {
+ Bexpression *e = CompileExpr::Compile (argument.get (), ctx);
+ vals.push_back (e);
+ }
translated
= ctx->get_backend ()->constructor_expression (type, vals, -1,
@@ -91,12 +91,12 @@ CompileExpr::visit (HIR::CallExpr &expr)
rust_assert (fn != nullptr);
std::vector<Bexpression *> args;
- expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
- Bexpression *compiled_expr = CompileExpr::Compile (p, ctx);
- rust_assert (compiled_expr != nullptr);
- args.push_back (compiled_expr);
- return true;
- });
+ for (auto &argument : expr.get_arguments ())
+ {
+ Bexpression *compiled_expr
+ = CompileExpr::Compile (argument.get (), ctx);
+ args.push_back (compiled_expr);
+ }
auto fncontext = ctx->peek_fn ();
translated
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index 05bc1f9..d66640d 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -1578,14 +1578,10 @@ protected:
}
};
-// Forward decl for Function - used in CallExpr
-class Function;
-
// Function call expression HIR node
class CallExpr : public ExprWithoutBlock
{
std::unique_ptr<Expr> function;
- // inlined form of CallParams
std::vector<std::unique_ptr<Expr> > params;
Location locus;
@@ -1642,13 +1638,11 @@ public:
size_t num_params () const { return params.size (); }
- void iterate_params (std::function<bool (Expr *)> cb)
+ std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; }
+
+ const std::vector<std::unique_ptr<Expr> > &get_arguments () const
{
- for (auto &param : params)
- {
- if (!cb (param.get ()))
- return;
- }
+ return params;
}
protected:
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 062bb96..481c956 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -165,10 +165,8 @@ public:
void visit (HIR::CallExpr &expr) override
{
expr.get_fnexpr ()->accept_vis (*this);
- expr.iterate_params ([&] (HIR::Expr *expr) -> bool {
- expr->accept_vis (*this);
- return true;
- });
+ for (auto &argument : expr.get_arguments ())
+ argument->accept_vis (*this);
}
void visit (HIR::ArithmeticOrLogicalExpr &expr) override
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index f4ce501..8de9d9d 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2383,27 +2383,28 @@ TypeCheckCallExpr::visit (ADTType &type)
}
size_t i = 0;
- call.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
- StructFieldType *field = type.get_field (i);
- BaseType *field_tyty = field->get_field_type ();
+ for (auto &argument : call.get_arguments ())
+ {
+ StructFieldType *field = type.get_field (i);
+ BaseType *field_tyty = field->get_field_type ();
- BaseType *arg = Resolver::TypeCheckExpr::Resolve (p, false);
- if (arg->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (p->get_locus (), "failed to resolve argument type");
- return false;
- }
+ BaseType *arg = Resolver::TypeCheckExpr::Resolve (argument.get (), false);
+ if (arg->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ rust_error_at (argument->get_locus (),
+ "failed to resolve argument type");
+ return;
+ }
- auto res = field_tyty->coerce (arg);
- if (res->get_kind () == TyTy::TypeKind::ERROR)
- {
- return false;
- }
+ auto res = field_tyty->coerce (arg);
+ if (res->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ return;
+ }
- delete res;
- i++;
- return true;
- });
+ delete res;
+ i++;
+ }
if (i != call.num_params ())
{
@@ -2441,35 +2442,37 @@ TypeCheckCallExpr::visit (FnType &type)
}
size_t i = 0;
- call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
- auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (param->get_locus (),
- "failed to resolve type for argument expr in CallExpr");
- return false;
- }
+ for (auto &argument : call.get_arguments ())
+ {
+ auto argument_expr_tyty
+ = Resolver::TypeCheckExpr::Resolve (argument.get (), false);
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ rust_error_at (
+ argument->get_locus (),
+ "failed to resolve type for argument expr in CallExpr");
+ return;
+ }
- auto resolved_argument_type = argument_expr_tyty;
+ auto resolved_argument_type = argument_expr_tyty;
- // it might be a varadic function
- if (i < type.num_params ())
- {
- auto fnparam = type.param_at (i);
- resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (param->get_locus (),
- "Type Resolution failure on parameter");
- return false;
- }
- }
+ // it might be a varadic function
+ if (i < type.num_params ())
+ {
+ auto fnparam = type.param_at (i);
+ resolved_argument_type = fnparam.second->coerce (argument_expr_tyty);
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ rust_error_at (argument->get_locus (),
+ "Type Resolution failure on parameter");
+ return;
+ }
+ }
- context->insert_type (param->get_mappings (), resolved_argument_type);
+ context->insert_type (argument->get_mappings (), resolved_argument_type);
- i++;
- return true;
- });
+ i++;
+ }
if (i < call.num_params ())
{
@@ -2505,29 +2508,31 @@ TypeCheckCallExpr::visit (FnPtr &type)
}
size_t i = 0;
- call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
- auto fnparam = type.param_at (i);
- auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (param->get_locus (),
- "failed to resolve type for argument expr in CallExpr");
- return false;
- }
+ for (auto &argument : call.get_arguments ())
+ {
+ auto fnparam = type.param_at (i);
+ auto argument_expr_tyty
+ = Resolver::TypeCheckExpr::Resolve (argument.get (), false);
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ rust_error_at (
+ argument->get_locus (),
+ "failed to resolve type for argument expr in CallExpr");
+ return;
+ }
- auto resolved_argument_type = fnparam->coerce (argument_expr_tyty);
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
- {
- rust_error_at (param->get_locus (),
- "Type Resolution failure on parameter");
- return false;
- }
+ auto resolved_argument_type = fnparam->coerce (argument_expr_tyty);
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ rust_error_at (argument->get_locus (),
+ "Type Resolution failure on parameter");
+ return;
+ }
- context->insert_type (param->get_mappings (), resolved_argument_type);
+ context->insert_type (argument->get_mappings (), resolved_argument_type);
- i++;
- return true;
- });
+ i++;
+ }
if (i != call.num_params ())
{
diff --git a/gcc/testsuite/rust/compile/tuple_struct3.rs b/gcc/testsuite/rust/compile/tuple_struct3.rs
index 1af72a2..a70306d 100644
--- a/gcc/testsuite/rust/compile/tuple_struct3.rs
+++ b/gcc/testsuite/rust/compile/tuple_struct3.rs
@@ -3,7 +3,6 @@ struct Foo(i32, i32, bool);
fn main() {
let c = Foo(1, 2f32, true);
// { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
- // { dg-error "unexpected number of arguments 1 expected 3" "" { target *-*-* } .-2 }
- // { dg-error "failed to lookup type to CallExpr" "" { target *-*-* } .-3 }
- // { dg-error "failed to type resolve expression" "" { target *-*-* } .-4 }
+ // { dg-error "failed to lookup type to CallExpr" "" { target *-*-* } .-2 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-3 }
}