diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-08-17 12:12:36 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-08-17 13:01:13 +0100 |
commit | 73e79179486b21b13fd8dcc138f84398ca0306e4 (patch) | |
tree | 32a8727145460104e05c00f65b0c06f262c6179c /gcc/rust/backend/rust-compile-fnparam.h | |
parent | 4f039ff9f6f18d15e32ddb54e3a6124802c45b7f (diff) | |
download | gcc-73e79179486b21b13fd8dcc138f84398ca0306e4.zip gcc-73e79179486b21b13fd8dcc138f84398ca0306e4.tar.gz gcc-73e79179486b21b13fd8dcc138f84398ca0306e4.tar.bz2 |
Refactor backend to use finegrained visitors
This also moves more code out of the headers to their associated impl files
to improve compilation times and code navigation.
Diffstat (limited to 'gcc/rust/backend/rust-compile-fnparam.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-fnparam.h | 57 |
1 files changed, 8 insertions, 49 deletions
diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h index 7c4a43a..0dbbd99 100644 --- a/gcc/rust/backend/rust-compile-fnparam.h +++ b/gcc/rust/backend/rust-compile-fnparam.h @@ -24,45 +24,17 @@ namespace Rust { namespace Compile { -class CompileFnParam : public HIRCompileBase, public HIR::HIRPatternVisitor +class CompileFnParam : private HIRCompileBase, protected HIR::HIRPatternVisitor { public: static Bvariable *compile (Context *ctx, tree fndecl, HIR::FunctionParam *param, tree decl_type, - Location locus) - { - CompileFnParam compiler (ctx, fndecl, decl_type, locus); - param->get_param_name ()->accept_vis (compiler); - return compiler.compiled_param; - } - + Location locus); static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern *param, - tree decl_type, Location locus) - { - CompileFnParam compiler (ctx, fndecl, decl_type, locus); - param->accept_vis (compiler); - return compiler.compiled_param; - } - - void visit (HIR::IdentifierPattern &pattern) override - { - if (!pattern.is_mut ()) - decl_type = ctx->get_backend ()->immutable_type (decl_type); - - compiled_param - = ctx->get_backend ()->parameter_variable (fndecl, - pattern.get_identifier (), - decl_type, locus); - } - - void visit (HIR::WildcardPattern &pattern) override - { - decl_type = ctx->get_backend ()->immutable_type (decl_type); - - compiled_param - = ctx->get_backend ()->parameter_variable (fndecl, "_", decl_type, locus); - } + tree decl_type, Location locus); + void visit (HIR::IdentifierPattern &pattern) override; + void visit (HIR::WildcardPattern &pattern) override; void visit (HIR::StructPattern &) override; void visit (HIR::TupleStructPattern &) override; @@ -77,10 +49,7 @@ public: void visit (HIR::TuplePattern &) override {} private: - CompileFnParam (Context *ctx, tree fndecl, tree decl_type, Location locus) - : HIRCompileBase (ctx), fndecl (fndecl), decl_type (decl_type), - locus (locus), compiled_param (ctx->get_backend ()->error_variable ()) - {} + CompileFnParam (Context *ctx, tree fndecl, tree decl_type, Location locus); tree fndecl; tree decl_type; @@ -88,21 +57,11 @@ private: Bvariable *compiled_param; }; -class CompileSelfParam : public HIRCompileBase, public HIR::HIRStmtVisitor +class CompileSelfParam : private HIRCompileBase { public: static Bvariable *compile (Context *ctx, tree fndecl, HIR::SelfParam &self, - tree decl_type, Location locus) - { - bool is_immutable - = self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM - || self.get_self_kind () == HIR::SelfParam::ImplicitSelfKind::IMM_REF; - if (is_immutable) - decl_type = ctx->get_backend ()->immutable_type (decl_type); - - return ctx->get_backend ()->parameter_variable (fndecl, "self", decl_type, - locus); - } + tree decl_type, Location locus); }; } // namespace Compile |