diff options
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; |