diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2023-10-28 01:04:19 -0400 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:13:12 +0100 |
commit | 6b8365a990df346a4cc0e4fa545e5259de20edc9 (patch) | |
tree | 938a350d68a7c78bb7ad7cc7afbd9004c5467d60 /gcc/rust/resolve | |
parent | 0df14bb1f3d944ea7281979d03c812a8d2c09ce7 (diff) | |
download | gcc-6b8365a990df346a4cc0e4fa545e5259de20edc9.zip gcc-6b8365a990df346a4cc0e4fa545e5259de20edc9.tar.gz gcc-6b8365a990df346a4cc0e4fa545e5259de20edc9.tar.bz2 |
gccrs: 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/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.cc | 4 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.h | 1 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 16 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 113 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 1 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-default-resolver.cc | 16 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-default-resolver.h | 1 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver.cc | 22 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver.h | 1 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h | 1 |
11 files changed, 33 insertions, 151 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index e415a90..34ebbc7 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -331,10 +331,6 @@ ResolverBase::visit (AST::TypeBoundWhereClauseItem &) {} void -ResolverBase::visit (AST::Method &) -{} - -void ResolverBase::visit (AST::Module &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index 2db579d..f9ae701 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -107,7 +107,6 @@ public: void visit (AST::LifetimeWhereClauseItem &); void visit (AST::TypeBoundWhereClauseItem &); - void visit (AST::Method &); void visit (AST::Module &); void visit (AST::ExternCrate &); diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index bec43af..365bdd61 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -88,22 +88,6 @@ public: }); } - void visit (AST::Method &method) override - { - auto decl = CanonicalPath::new_seg (method.get_node_id (), - method.get_method_name ().as_string ()); - auto path = prefix.append (decl); - - resolver->get_name_scope ().insert ( - path, method.get_node_id (), method.get_locus (), false, - Rib::ItemType::Function, - [&] (const CanonicalPath &, NodeId, location_t locus) -> void { - rich_location r (line_table, method.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - } - private: ResolveToplevelImplItem (const CanonicalPath &prefix) : ResolverBase (), prefix (prefix) diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 8126f83..4c6958d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -524,6 +524,36 @@ ResolveItem::visit (AST::Function &function) if (function.has_return_type ()) ResolveType::go (function.get_return_type ().get ()); + if (function.has_self_param ()) + { + // self turns into (self: Self) as a function param + AST::SelfParam &self_param = function.get_self_param (); + // FIXME: which location should be used for Rust::Identifier `self`? + AST::IdentifierPattern self_pattern ( + self_param.get_node_id (), {"self"}, self_param.get_locus (), + self_param.get_has_ref (), self_param.get_is_mut (), + std::unique_ptr<AST::Pattern> (nullptr)); + PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); + + if (self_param.has_type ()) + { + // This shouldn't happen the parser should already error for this + rust_assert (!self_param.get_has_ref ()); + ResolveType::go (self_param.get_type ().get ()); + } + else + { + // here we implicitly make self have a type path of Self + std::vector<std::unique_ptr<AST::TypePathSegment>> segments; + segments.push_back (std::unique_ptr<AST::TypePathSegment> ( + new AST::TypePathSegment ("Self", false, self_param.get_locus ()))); + + AST::TypePath self_type_path (std::move (segments), + self_param.get_locus ()); + ResolveType::go (&self_type_path); + } + } + std::vector<PatternBinding> bindings = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())}; @@ -620,89 +650,6 @@ ResolveItem::visit (AST::InherentImpl &impl_block) } void -ResolveItem::visit (AST::Method &method) -{ - auto decl = CanonicalPath::new_seg (method.get_node_id (), - method.get_method_name ().as_string ()); - auto path = prefix.append (decl); - auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (method.get_node_id (), cpath); - - NodeId scope_node_id = method.get_node_id (); - - resolve_visibility (method.get_visibility ()); - - resolver->get_name_scope ().push (scope_node_id); - resolver->get_type_scope ().push (scope_node_id); - resolver->get_label_scope ().push (scope_node_id); - resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); - resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); - resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); - - if (method.has_generics ()) - for (auto &generic : method.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); - - // resolve any where clause items - if (method.has_where_clause ()) - ResolveWhereClause::Resolve (method.get_where_clause ()); - - if (method.has_return_type ()) - ResolveType::go (method.get_return_type ().get ()); - - // self turns into (self: Self) as a function param - AST::SelfParam &self_param = method.get_self_param (); - // FIXME: which location should be used for Rust::Identifier `self`? - AST::IdentifierPattern self_pattern (self_param.get_node_id (), {"self"}, - self_param.get_locus (), - self_param.get_has_ref (), - self_param.get_is_mut (), - std::unique_ptr<AST::Pattern> (nullptr)); - PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); - - if (self_param.has_type ()) - { - // This shouldn't happen the parser should already error for this - rust_assert (!self_param.get_has_ref ()); - ResolveType::go (self_param.get_type ().get ()); - } - else - { - // here we implicitly make self have a type path of Self - std::vector<std::unique_ptr<AST::TypePathSegment>> segments; - segments.push_back (std::unique_ptr<AST::TypePathSegment> ( - new AST::TypePathSegment ("Self", false, self_param.get_locus ()))); - - AST::TypePath self_type_path (std::move (segments), - self_param.get_locus ()); - ResolveType::go (&self_type_path); - } - - std::vector<PatternBinding> bindings - = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())}; - - // we make a new scope so the names of parameters are resolved and shadowed - // correctly - for (auto ¶m : method.get_function_params ()) - { - ResolveType::go (param.get_type ().get ()); - PatternDeclaration::go (param.get_pattern ().get (), Rib::ItemType::Param, - bindings); - } - - // resolve any where clause items - if (method.has_where_clause ()) - ResolveWhereClause::Resolve (method.get_where_clause ()); - - // resolve the function body - ResolveExpr::go (method.get_definition ().get (), path, cpath); - - resolver->get_name_scope ().pop (); - resolver->get_type_scope ().pop (); - resolver->get_label_scope ().pop (); -} - -void ResolveItem::visit (AST::TraitImpl &impl_block) { NodeId scope_node_id = impl_block.get_node_id (); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index 26c36e7..712fe62 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -71,7 +71,6 @@ public: void visit (AST::ConstantItem &constant) override; void visit (AST::Function &function) override; void visit (AST::InherentImpl &impl_block) override; - void visit (AST::Method &method) override; void visit (AST::TraitImpl &impl_block) override; void visit (AST::Trait &trait) override; void visit (AST::ExternBlock &extern_block) override; diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 1d54f91..fc81001 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -68,22 +68,6 @@ DefaultResolver::visit (AST::Function &function) } void -DefaultResolver::visit (AST::Method &method) -{ - auto def_fn = [this, &method] () { - for (auto ¶m : method.get_function_params ()) - { - param.get_pattern ()->accept_vis (*this); - param.get_type ()->accept_vis (*this); - } - - method.get_definition ()->accept_vis (*this); - }; - - ctx.scoped (Rib::Kind::Function, method.get_node_id (), def_fn); -} - -void DefaultResolver::visit (AST::ForLoopExpr &expr) { ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), [this, &expr] () { diff --git a/gcc/rust/resolve/rust-default-resolver.h b/gcc/rust/resolve/rust-default-resolver.h index 03b4a54..8af9513 100644 --- a/gcc/rust/resolve/rust-default-resolver.h +++ b/gcc/rust/resolve/rust-default-resolver.h @@ -43,7 +43,6 @@ public: void visit (AST::BlockExpr &); void visit (AST::Module &); void visit (AST::Function &); - void visit (AST::Method &); void visit (AST::ForLoopExpr &); void visit (AST::Trait &); void visit (AST::InherentImpl &); diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 4c78404..455da30 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -601,25 +601,6 @@ EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item) } void -EarlyNameResolver::visit (AST::Method &method) -{ - if (method.has_generics ()) - for (auto &generic : method.get_generic_params ()) - generic->accept_vis (*this); - - if (method.get_self_param ().has_type ()) - method.get_self_param ().get_type ()->accept_vis (*this); - - for (auto ¶m : method.get_function_params ()) - param.get_type ()->accept_vis (*this); - - if (method.has_return_type ()) - method.get_return_type ()->accept_vis (*this); - - method.get_definition ()->accept_vis (*this); -} - -void EarlyNameResolver::visit (AST::Module &module) { if (module.get_kind () == AST::Module::UNLOADED) @@ -681,6 +662,9 @@ EarlyNameResolver::visit (AST::Function &function) for (auto &generic : function.get_generic_params ()) generic->accept_vis (*this); + if (function.has_self_param () && function.get_self_param ().has_type ()) + function.get_self_param ().get_type ()->accept_vis (*this); + for (auto ¶m : function.get_function_params ()) param.get_type ()->accept_vis (*this); diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index e4b4856..41728c6 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -198,7 +198,6 @@ private: virtual void visit (AST::TypeParam ¶m); virtual void visit (AST::LifetimeWhereClauseItem &item); virtual void visit (AST::TypeBoundWhereClauseItem &item); - virtual void visit (AST::Method &method); virtual void visit (AST::Module &module); virtual void visit (AST::ExternCrate &crate); virtual void visit (AST::UseTreeGlob &use_tree); diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 486998d..fc62db7 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -192,14 +192,6 @@ TopLevel::visit (AST::Function &function) } void -TopLevel::visit (AST::Method &method) -{ - insert_or_error_out (method.get_method_name (), method, Namespace::Values); - - method.get_definition ()->accept_vis (*this); -} - -void TopLevel::visit (AST::BlockExpr &expr) { // extracting the lambda from the `scoped` call otherwise the code looks like diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index b8ed106..95187d7 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -60,7 +60,6 @@ private: void visit (AST::Module &module) override; void visit (AST::MacroRulesDefinition ¯o) override; void visit (AST::Function &function) override; - void visit (AST::Method &method) override; void visit (AST::BlockExpr &expr) override; void visit (AST::StaticItem &static_item) override; void visit (AST::TraitItemFunc &item) override; |