aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-expr.h9
-rw-r--r--gcc/rust/ast/rust-item.h27
-rw-r--r--gcc/rust/hir/rust-ast-lower-expr.h10
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h112
-rw-r--r--gcc/rust/hir/rust-ast-lower-stmt.h112
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.h6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h12
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-stmt.h12
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.cc2
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.h9
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-enumitem.h3
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.cc2
12 files changed, 127 insertions, 189 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 3463f5a..7f6714a 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -996,15 +996,6 @@ public:
size_t get_num_values () const { return values.size (); }
- void iterate (std::function<bool (Expr *)> cb)
- {
- for (auto it = values.begin (); it != values.end (); it++)
- {
- if (!cb ((*it).get ()))
- return;
- }
- }
-
protected:
ArrayElemsValues *clone_array_elems_impl () const override
{
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index f952dcc..a18a8e6 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -1975,15 +1975,6 @@ public:
std::vector<StructField> &get_fields () { return fields; }
const std::vector<StructField> &get_fields () const { return fields; }
- void iterate (std::function<bool (StructField &)> cb)
- {
- for (auto &field : fields)
- {
- if (!cb (field))
- return;
- }
- }
-
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2110,15 +2101,6 @@ public:
std::vector<TupleField> &get_fields () { return fields; }
const std::vector<TupleField> &get_fields () const { return fields; }
- void iterate (std::function<bool (TupleField &)> cb)
- {
- for (auto &field : fields)
- {
- if (!cb (field))
- return;
- }
- }
-
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2490,15 +2472,6 @@ public:
std::vector<StructField> &get_variants () { return variants; }
const std::vector<StructField> &get_variants () const { return variants; }
- void iterate (std::function<bool (StructField &)> cb)
- {
- for (auto &variant : variants)
- {
- if (!cb (variant))
- return;
- }
- }
-
std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
{
return generic_params;
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index f36096b..d6e2194 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -303,11 +303,11 @@ public:
void visit (AST::ArrayElemsValues &elems) override
{
std::vector<std::unique_ptr<HIR::Expr> > elements;
- elems.iterate ([&] (AST::Expr *elem) mutable -> bool {
- HIR::Expr *translated_elem = ASTLoweringExpr::translate (elem);
- elements.push_back (std::unique_ptr<HIR::Expr> (translated_elem));
- return true;
- });
+ for (auto &elem : elems.get_values ())
+ {
+ HIR::Expr *translated_elem = ASTLoweringExpr::translate (elem.get ());
+ elements.push_back (std::unique_ptr<HIR::Expr> (translated_elem));
+ }
translated_array_elems = new HIR::ArrayElemsValues (std::move (elements));
}
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index 697e98a..60315db 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -154,24 +154,24 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::TupleField> fields;
- struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::TupleField translated_field (mapping,
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
- fields.push_back (std::move (translated_field));
- return true;
- });
+ for (AST::TupleField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
+
+ HIR::TupleField translated_field (mapping,
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
@@ -215,28 +215,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
@@ -325,28 +325,28 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::StructField> variants;
- union_decl.iterate ([&] (AST::StructField &variant) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (variant.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::StructField translated_variant (mapping, variant.get_field_name (),
- std::unique_ptr<HIR::Type> (type),
- vis, variant.get_locus (),
- variant.get_outer_attrs ());
+ for (AST::StructField &variant : union_decl.get_variants ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (variant.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- if (struct_field_name_exists (variants, translated_variant))
- return false;
+ HIR::StructField translated_variant (mapping, variant.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, variant.get_locus (),
+ variant.get_outer_attrs ());
- variants.push_back (std::move (translated_variant));
- return true;
- });
+ if (struct_field_name_exists (variants, translated_variant))
+ break;
+
+ variants.push_back (std::move (translated_variant));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, union_decl.get_node_id (),
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h
index eab0922..27fdd22 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.h
+++ b/gcc/rust/hir/rust-ast-lower-stmt.h
@@ -151,24 +151,24 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::TupleField> fields;
- struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::TupleField translated_field (mapping,
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
- fields.push_back (std::move (translated_field));
- return true;
- });
+ for (AST::TupleField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
+
+ HIR::TupleField translated_field (mapping,
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
@@ -203,28 +203,28 @@ public:
bool is_unit = struct_decl.is_unit_struct ();
std::vector<HIR::StructField> fields;
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (field.get_field_type ().get ());
+ for (AST::StructField &field : struct_decl.get_fields ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (field.get_field_type ().get ());
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- HIR::StructField translated_field (mapping, field.get_field_name (),
- std::unique_ptr<HIR::Type> (type), vis,
- field.get_locus (),
- field.get_outer_attrs ());
+ HIR::StructField translated_field (mapping, field.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, field.get_locus (),
+ field.get_outer_attrs ());
- if (struct_field_name_exists (fields, translated_field))
- return false;
+ if (struct_field_name_exists (fields, translated_field))
+ break;
- fields.push_back (std::move (translated_field));
- return true;
- });
+ fields.push_back (std::move (translated_field));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
@@ -258,28 +258,28 @@ public:
HIR::Visibility vis = HIR::Visibility::create_public ();
std::vector<HIR::StructField> variants;
- union_decl.iterate ([&] (AST::StructField &variant) mutable -> bool {
- HIR::Visibility vis = HIR::Visibility::create_public ();
- HIR::Type *type
- = ASTLoweringType::translate (variant.get_field_type ().get ());
-
- auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
- mappings->get_next_hir_id (crate_num),
- mappings->get_next_localdef_id (
- crate_num));
-
- HIR::StructField translated_variant (mapping, variant.get_field_name (),
- std::unique_ptr<HIR::Type> (type),
- vis, variant.get_locus (),
- variant.get_outer_attrs ());
+ for (AST::StructField &variant : union_decl.get_variants ())
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *type
+ = ASTLoweringType::translate (variant.get_field_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, variant.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
- if (struct_field_name_exists (variants, translated_variant))
- return false;
+ HIR::StructField translated_variant (mapping, variant.get_field_name (),
+ std::unique_ptr<HIR::Type> (type),
+ vis, variant.get_locus (),
+ variant.get_outer_attrs ());
- variants.push_back (std::move (translated_variant));
- return true;
- });
+ if (struct_field_name_exists (variants, translated_variant))
+ break;
+
+ variants.push_back (std::move (translated_variant));
+ }
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, union_decl.get_node_id (),
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h
index 12a4f8c..05d116f 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -224,10 +224,8 @@ public:
void visit (AST::ArrayElemsValues &elems) override
{
- elems.iterate ([&] (AST::Expr *elem) mutable -> bool {
- ResolveExpr::go (elem, elems.get_node_id ());
- return true;
- });
+ for (auto &elem : elems.get_values ())
+ ResolveExpr::go (elem.get (), elems.get_node_id ());
}
void visit (AST::ArrayExpr &expr) override
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index a4bf261..b3035ed 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -245,11 +245,9 @@ public:
if (struct_decl.has_where_clause ())
ResolveWhereClause::Resolve (struct_decl.get_where_clause ());
- struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool {
+ for (AST::TupleField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
@@ -310,11 +308,9 @@ public:
if (struct_decl.has_where_clause ())
ResolveWhereClause::Resolve (struct_decl.get_where_clause ());
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
@@ -335,11 +331,9 @@ public:
if (union_decl.has_where_clause ())
ResolveWhereClause::Resolve (union_decl.get_where_clause ());
- union_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : union_decl.get_variants ())
ResolveType::go (field.get_field_type ().get (),
union_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index 98fcaf2..ce6875c 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -115,11 +115,9 @@ public:
}
}
- struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool {
+ for (AST::TupleField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
@@ -239,11 +237,9 @@ public:
}
}
- struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : struct_decl.get_fields ())
ResolveType::go (field.get_field_type ().get (),
struct_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
@@ -271,11 +267,9 @@ public:
}
}
- union_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
+ for (AST::StructField &field : union_decl.get_variants ())
ResolveType::go (field.get_field_type ().get (),
union_decl.get_node_id ());
- return true;
- });
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.cc b/gcc/rust/typecheck/rust-hir-const-fold.cc
index 6acedd1..1545c1a 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.cc
+++ b/gcc/rust/typecheck/rust-hir-const-fold.cc
@@ -64,8 +64,6 @@ void
ConstFoldItem::visit (HIR::ConstantItem &item)
{
auto folded_expr = ConstFoldExpr::fold (item.get_expr ());
- if (folded_expr == nullptr)
- return;
folded = folded_expr;
}
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h
index c965e25..d1f7127 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold.h
@@ -299,7 +299,7 @@ public:
if (folder.ctx->get_backend ()->is_error_expression (folder.folded))
{
rust_error_at (expr->get_locus (), "non const value");
- return nullptr;
+ return folder.ctx->get_backend ()->error_expression ();
}
folder.ctx->insert_const (expr->get_mappings ().get_hirid (),
@@ -423,12 +423,7 @@ public:
void visit (HIR::ArithmeticOrLogicalExpr &expr) override
{
auto lhs = ConstFoldExpr::fold (expr.get_lhs ());
- if (lhs == nullptr)
- return;
-
auto rhs = ConstFoldExpr::fold (expr.get_rhs ());
- if (rhs == nullptr)
- return;
auto op = expr.get_expr_type ();
auto location = expr.get_locus ();
@@ -441,8 +436,6 @@ public:
void visit (HIR::NegationExpr &expr) override
{
auto negated_expr = ConstFoldExpr::fold (expr.get_expr ().get ());
- if (negated_expr == nullptr)
- return;
auto op = expr.get_expr_type ();
auto location = expr.get_locus ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
index e4dcaeb23..4df7df6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h
@@ -74,8 +74,7 @@ public:
auto backend = rust_get_backend ();
auto folded_discriminant
= ConstFold::ConstFoldExpr::fold (discriminant.get ());
- if (folded_discriminant == nullptr
- || backend->is_error_expression (folded_discriminant))
+ if (backend->is_error_expression (folded_discriminant))
return;
size_t specified_discriminant;
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index ca4842a..4596973 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -151,8 +151,6 @@ TypeCheckType::visit (HIR::ArrayType &type)
return;
auto capacity = ConstFold::ConstFoldExpr::fold (type.get_size_expr ());
- if (capacity == nullptr)
- return;
TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ());
translated = new TyTy::ArrayType (type.get_mappings ().get_hirid (), capacity,