diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-10-28 01:04:19 -0400 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2023-11-09 21:02:22 +0000 |
commit | 9864d7fe8a6dd8abe1cf95e36e35b1762d4d34fe (patch) | |
tree | 75a272783d166df0bdd9cbb006a351df56425c6d /gcc/rust/expand | |
parent | 25652e25b53c1a47162256dcf644d2f19f9b0966 (diff) | |
download | gcc-9864d7fe8a6dd8abe1cf95e36e35b1762d4d34fe.zip gcc-9864d7fe8a6dd8abe1cf95e36e35b1762d4d34fe.tar.gz gcc-9864d7fe8a6dd8abe1cf95e36e35b1762d4d34fe.tar.bz2 |
Replace AST::Method with existing AST::Function
gcc/rust/ChangeLog:
* ast/rust-item.h
(class Method): Remove.
(Function::self_param): New.
(Function::has_self_param): New.
(Function::Function): Initialize self_param.
(Function::operator=): Likewise.
(Function::get_self_param): New.
* ast/rust-ast.cc
(Method::as_string): Remove.
(Method::accept_vis): Remove.
* ast/rust-ast-collector.cc
(TokenCollector::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* ast/rust-ast-collector.h
(TokenCollector::visit): Remove AST::Method visitor.
* ast/rust-ast-full-decls.h (class Method): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove AST::Method visitor.
(DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* checks/errors/rust-feature-gate.cc
(FeatureGate::visit): Remove AST::Method visitor.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise..
* expand/rust-cfg-strip.cc
(CfgStrip::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Remove AST::Method visitor.
* expand/rust-derive-clone.cc
(DeriveClone::clone_fn): Return AST::Function instead of AST::Method.
* expand/rust-derive.h (DeriveVisitor::visit): Remove AST::Method visitor.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* expand/rust-expand-visitor.h:
(ExpandVisitor::visit): Remove AST::Method visitor.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-implitem.h
(ASTLowerImplItem::visit):
Remove AST::Method visitor, handle self_param in AST::Function visitor.
* parse/rust-parse-impl.h: Include optional.h.
(Parser::parse_function): Adjust AST::Function construction.
(Parser::parse_inherent_impl_function_or_method):
Construct AST::Function instead of AST::Method,
adjust AST::Function construction.
(Parser::parse_trait_impl_function_or_method): Likewise.
(Parser::parse_method):
Return std::unique_ptr<AST::Function> instead of AST::Method.
* parse/rust-parse.h
(Parser::parse_method): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Remove AST::Method visitor.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-implitem.h
(ResolveToplevelImplItem::visit): Likewise.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Remove AST::Method visitor,
handle self_param in AST::Function visitor.
* resolve/rust-ast-resolve-item.h
(ResolveItem::visit): Remove AST::Method visitor.
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove AST::Method visitor.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Remove AST::Method visitor,
handle self_param in AST::Function visitor.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Remove AST::Method visitor.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/expand')
-rw-r--r-- | gcc/rust/expand/rust-cfg-strip.cc | 54 | ||||
-rw-r--r-- | gcc/rust/expand/rust-cfg-strip.h | 1 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive-clone.cc | 11 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive.h | 1 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.cc | 20 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.h | 1 |
6 files changed, 15 insertions, 73 deletions
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 731d8fd..6bf3a25 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -1945,53 +1945,6 @@ CfgStrip::visit (AST::TypeBoundWhereClauseItem &item) bound->accept_vis (*this); } void -CfgStrip::visit (AST::Method &method) -{ - // initial test based on outer attrs - expand_cfg_attrs (method.get_outer_attrs ()); - if (fails_cfg_with_expand (method.get_outer_attrs ())) - { - method.mark_for_strip (); - return; - } - - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : method.get_generic_params ()) - param->accept_vis (*this); - - /* assuming you can't strip self param - wouldn't be a method - * anymore. spec allows outer attrs on self param, but doesn't - * specify whether cfg is used. */ - maybe_strip_self_param (method.get_self_param ()); - - /* strip method parameters if required - this is specifically - * allowed by spec */ - maybe_strip_function_params (method.get_function_params ()); - - if (method.has_return_type ()) - { - auto &return_type = method.get_return_type (); - return_type->accept_vis (*this); - - if (return_type->is_marked_for_strip ()) - rust_error_at (return_type->get_locus (), - "cannot strip type in this position"); - } - - if (method.has_where_clause ()) - maybe_strip_where_clause (method.get_where_clause ()); - - /* body should always exist - if error state, should have returned - * before now */ - // can't strip block itself, but can strip sub-expressions - auto &block_expr = method.get_definition (); - block_expr->accept_vis (*this); - if (block_expr->is_marked_for_strip ()) - rust_error_at (block_expr->get_locus (), - "cannot strip block expression in this position - outer " - "attributes not allowed"); -} -void CfgStrip::visit (AST::Module &module) { // strip test based on outer attrs @@ -2076,6 +2029,13 @@ CfgStrip::visit (AST::Function &function) for (auto ¶m : function.get_generic_params ()) param->accept_vis (*this); + /* assuming you can't strip self param - wouldn't be a method + * anymore. spec allows outer attrs on self param, but doesn't + * specify whether cfg is used. */ + // TODO: verify this + if (function.has_self_param ()) + maybe_strip_self_param (function.get_self_param ()); + /* strip function parameters if required - this is specifically * allowed by spec */ maybe_strip_function_params (function.get_function_params ()); diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index 7235bfa..b3bb3fb 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -140,7 +140,6 @@ public: void visit (AST::TypeParam ¶m) override; void visit (AST::LifetimeWhereClauseItem &) override; void visit (AST::TypeBoundWhereClauseItem &item) override; - void visit (AST::Method &method) override; void visit (AST::Module &module) override; void visit (AST::ExternCrate &crate) override; void visit (AST::UseTreeGlob &) override; diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc index cac3099..28ce402 100644 --- a/gcc/rust/expand/rust-derive-clone.cc +++ b/gcc/rust/expand/rust-derive-clone.cc @@ -51,11 +51,12 @@ DeriveClone::clone_fn (std::unique_ptr<Expr> &&clone_expr) auto big_self_type = builder.single_type_path ("Self"); return std::unique_ptr<TraitImplItem> ( - new Method ({"clone"}, builder.fn_qualifiers (), /* generics */ {}, - SelfParam (Lifetime::error (), /* is_mut */ false, loc), - /* function params */ {}, std::move (big_self_type), - WhereClause::create_empty (), std::move (block), - Visibility::create_private (), {}, loc)); + new Function ({"clone"}, builder.fn_qualifiers (), /* generics */ {}, + tl::optional<SelfParam> (tl::in_place, Lifetime::error (), + /* is_mut */ false, loc), + /* function params */ {}, std::move (big_self_type), + WhereClause::create_empty (), std::move (block), + Visibility::create_private (), {}, loc)); } /** diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index f315f06..915c054 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -145,7 +145,6 @@ private: virtual void visit (TypeParam ¶m) override final{}; virtual void visit (LifetimeWhereClauseItem &item) override final{}; virtual void visit (TypeBoundWhereClauseItem &item) override final{}; - virtual void visit (Method &method) override final{}; virtual void visit (Module &module) override final{}; virtual void visit (ExternCrate &crate) override final{}; virtual void visit (UseTreeGlob &use_tree) override final{}; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index cb9e8b6..0dd6f59 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -984,24 +984,6 @@ ExpandVisitor::visit (AST::TypeBoundWhereClauseItem &item) } void -ExpandVisitor::visit (AST::Method &method) -{ - for (auto ¶m : method.get_generic_params ()) - visit (param); - - expand_self_param (method.get_self_param ()); - expand_function_params (method.get_function_params ()); - - if (method.has_return_type ()) - visit (method.get_return_type ()); - - if (method.has_where_clause ()) - expand_where_clause (method.get_where_clause ()); - - visit (method.get_definition ()); -} - -void ExpandVisitor::visit (AST::Module &module) { if (module.get_kind () == AST::Module::ModuleKind::LOADED) @@ -1040,6 +1022,8 @@ ExpandVisitor::visit (AST::Function &function) for (auto ¶m : function.get_generic_params ()) visit (param); + if (function.has_self_param ()) + expand_self_param (function.get_self_param ()); expand_function_params (function.get_function_params ()); if (function.has_return_type ()) diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index a88c91e..d7612ac 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -265,7 +265,6 @@ public: void visit (AST::TypeParam ¶m) override; void visit (AST::LifetimeWhereClauseItem &) override; void visit (AST::TypeBoundWhereClauseItem &item) override; - void visit (AST::Method &method) override; void visit (AST::Module &module) override; void visit (AST::ExternCrate &crate) override; void visit (AST::UseTreeGlob &) override; |