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/parse | |
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/parse')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 59 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse.h | 2 |
2 files changed, 33 insertions, 28 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index f08ab69..e1d7388 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -29,6 +29,8 @@ #include "rust-dir-owner.h" #include "rust-attribute-values.h" +#include "optional.h" + namespace Rust { // Left binding powers of operations. enum binding_powers @@ -2903,10 +2905,11 @@ Parser<ManagedTokenSource>::parse_function (AST::Visibility vis, return std::unique_ptr<AST::Function> ( new AST::Function (std::move (function_name), std::move (qualifiers), - std::move (generic_params), std::move (function_params), - std::move (return_type), std::move (where_clause), - std::move (block_expr), std::move (vis), - std::move (outer_attrs), locus)); + std::move (generic_params), + tl::optional<AST::SelfParam> (), + std::move (function_params), std::move (return_type), + std::move (where_clause), std::move (block_expr), + std::move (vis), std::move (outer_attrs), locus)); } // Parses function or method qualifiers (i.e. const, unsafe, and extern). @@ -5645,18 +5648,18 @@ Parser<ManagedTokenSource>::parse_inherent_impl_function_or_method ( // do actual if instead of ternary for return value optimisation if (is_method) { - return std::unique_ptr<AST::Method> ( - new AST::Method (std::move (ident), std::move (qualifiers), - std::move (generic_params), std::move (self_param), - std::move (function_params), std::move (return_type), - std::move (where_clause), std::move (body), - std::move (vis), std::move (outer_attrs), locus)); + return std::unique_ptr<AST::Function> (new AST::Function ( + std::move (ident), std::move (qualifiers), std::move (generic_params), + tl::optional<AST::SelfParam> (tl::in_place, std::move (self_param)), + std::move (function_params), std::move (return_type), + std::move (where_clause), std::move (body), std::move (vis), + std::move (outer_attrs), locus)); } else { return std::unique_ptr<AST::Function> ( new AST::Function (std::move (ident), std::move (qualifiers), - std::move (generic_params), + std::move (generic_params), tl::nullopt, std::move (function_params), std::move (return_type), std::move (where_clause), std::move (body), std::move (vis), std::move (outer_attrs), locus)); @@ -5884,17 +5887,18 @@ Parser<ManagedTokenSource>::parse_trait_impl_function_or_method ( // do actual if instead of ternary for return value optimisation if (is_method) { - return std::unique_ptr<AST::Method> (new AST::Method ( + return std::unique_ptr<AST::Function> (new AST::Function ( std::move (ident), std::move (qualifiers), std::move (generic_params), - std::move (self_param), std::move (function_params), - std::move (return_type), std::move (where_clause), std::move (body), - std::move (vis), std::move (outer_attrs), locus, is_default)); + tl::optional<AST::SelfParam> (tl::in_place, std::move (self_param)), + std::move (function_params), std::move (return_type), + std::move (where_clause), std::move (body), std::move (vis), + std::move (outer_attrs), locus, is_default)); } else { return std::unique_ptr<AST::Function> (new AST::Function ( std::move (ident), std::move (qualifiers), std::move (generic_params), - std::move (function_params), std::move (return_type), + tl::nullopt, std::move (function_params), std::move (return_type), std::move (where_clause), std::move (body), std::move (vis), std::move (outer_attrs), locus, is_default)); } @@ -7188,7 +7192,7 @@ Parser<ManagedTokenSource>::parse_self_param () * resolve it into whatever it is afterward. As such, this is only here for * algorithmically defining the grammar rule. */ template <typename ManagedTokenSource> -AST::Method +std::unique_ptr<AST::Function> Parser<ManagedTokenSource>::parse_method () { location_t locus = lexer.peek_token ()->get_locus (); @@ -7202,7 +7206,7 @@ Parser<ManagedTokenSource>::parse_method () if (ident_tok == nullptr) { skip_after_next_block (); - return AST::Method::create_error (); + return nullptr; } Identifier method_name{ident_tok}; @@ -7217,7 +7221,7 @@ Parser<ManagedTokenSource>::parse_method () add_error (std::move (error)); skip_after_next_block (); - return AST::Method::create_error (); + return nullptr; } // parse self param @@ -7229,7 +7233,7 @@ Parser<ManagedTokenSource>::parse_method () add_error (std::move (error)); skip_after_next_block (); - return AST::Method::create_error (); + return nullptr; } // skip comma if it exists @@ -7248,7 +7252,7 @@ Parser<ManagedTokenSource>::parse_method () add_error (std::move (error)); skip_after_next_block (); - return AST::Method::create_error (); + return nullptr; } // parse function return type - if exists @@ -7266,15 +7270,16 @@ Parser<ManagedTokenSource>::parse_method () add_error (std::move (error)); skip_after_end_block (); - return AST::Method::create_error (); + return nullptr; } // does not parse visibility, but this method isn't used, so doesn't matter - return AST::Method (std::move (method_name), std::move (qualifiers), - std::move (generic_params), std::move (self_param), - std::move (function_params), std::move (return_type), - std::move (where_clause), std::move (block_expr), - AST::Visibility::create_error (), AST::AttrVec (), locus); + return std::unique_ptr<AST::Function> (new AST::Function ( + std::move (method_name), std::move (qualifiers), std::move (generic_params), + tl::optional<AST::SelfParam> (tl::in_place, std::move (self_param)), + std::move (function_params), std::move (return_type), + std::move (where_clause), std::move (block_expr), + AST::Visibility::create_error (), AST::AttrVec (), locus)); } /* Parses an expression or macro statement. */ diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index e432275..3ff9b99 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -345,7 +345,7 @@ private: AST::AttrVec outer_attrs); std::unique_ptr<AST::ExternBlock> parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs); - AST::Method parse_method (); + std::unique_ptr<AST::Function> parse_method (); // Expression-related (Pratt parsed) std::unique_ptr<AST::Expr> |