aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-14 22:35:55 +0000
committerGitHub <noreply@github.com>2023-01-14 22:35:55 +0000
commit9e6c79054f8f85b148f21576feb15e3246936827 (patch)
tree087adfda1099f03c7d8432bfeb3883ca1c91c5a1 /gcc
parent2f9f77f9dd6330fe60554400133d7217f78afa43 (diff)
parentdc31146d6392c620a31b0f3e3625224ca4afb3cd (diff)
downloadgcc-9e6c79054f8f85b148f21576feb15e3246936827.zip
gcc-9e6c79054f8f85b148f21576feb15e3246936827.tar.gz
gcc-9e6c79054f8f85b148f21576feb15e3246936827.tar.bz2
Merge #1736
1736: Change how CompileVarDecl outputs Bvariable's r=philberty a=powerboat9 This allows patterns to declare multiple/no variables Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com> --- Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc4
-rw-r--r--gcc/rust/backend/rust-compile-var-decl.h26
2 files changed, 16 insertions, 14 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index a5643d2..5e7ab31 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -457,9 +457,7 @@ HIRCompileBase::compile_locals_for_block (Context *ctx, Resolver::Rib &rib,
// compile the local
tree type = TyTyResolveCompile::compile (ctx, tyty);
- Bvariable *compiled
- = CompileVarDecl::compile (fndecl, type, pattern, ctx);
- locals.push_back (compiled);
+ CompileVarDecl::compile (fndecl, type, pattern, locals, ctx);
}
return locals;
}
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index e2ee05b..a1dee2d 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -30,12 +30,11 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor
using HIR::HIRPatternVisitor::visit;
public:
- static ::Bvariable *compile (tree fndecl, tree translated_type,
- HIR::Pattern *pattern, Context *ctx)
+ static void compile (tree fndecl, tree translated_type, HIR::Pattern *pattern,
+ std::vector<Bvariable *> &locals, Context *ctx)
{
- CompileVarDecl compiler (ctx, fndecl, translated_type);
+ CompileVarDecl compiler (ctx, fndecl, translated_type, locals);
pattern->accept_vis (compiler);
- return compiler.compiled_variable;
}
void visit (HIR::IdentifierPattern &pattern) override
@@ -43,26 +42,30 @@ public:
if (!pattern.is_mut ())
translated_type = ctx->get_backend ()->immutable_type (translated_type);
- compiled_variable
+ Bvariable *var
= ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (),
translated_type, NULL /*decl_var*/,
pattern.get_locus ());
HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
- ctx->insert_var_decl (stmt_id, compiled_variable);
+ ctx->insert_var_decl (stmt_id, var);
+
+ locals.push_back (var);
}
void visit (HIR::WildcardPattern &pattern) override
{
translated_type = ctx->get_backend ()->immutable_type (translated_type);
- compiled_variable
+ Bvariable *var
= ctx->get_backend ()->local_variable (fndecl, "_", translated_type,
NULL /*decl_var*/,
pattern.get_locus ());
HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
- ctx->insert_var_decl (stmt_id, compiled_variable);
+ ctx->insert_var_decl (stmt_id, var);
+
+ locals.push_back (var);
}
// Empty visit for unused Pattern HIR nodes.
@@ -78,15 +81,16 @@ public:
void visit (HIR::TupleStructPattern &) override {}
private:
- CompileVarDecl (Context *ctx, tree fndecl, tree translated_type)
+ CompileVarDecl (Context *ctx, tree fndecl, tree translated_type,
+ std::vector<Bvariable *> &locals)
: HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type),
- compiled_variable (ctx->get_backend ()->error_variable ())
+ locals (locals)
{}
tree fndecl;
tree translated_type;
- Bvariable *compiled_variable;
+ std::vector<Bvariable *> &locals;
};
} // namespace Compile