Skip to content

Commit

Permalink
Replace AST::Method with existing AST::Function
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Nov 9, 2023
1 parent 25652e2 commit 9864d7f
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 692 deletions.
43 changes: 8 additions & 35 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1626,41 +1626,6 @@ TokenCollector::visit (TypeBoundWhereClauseItem &item)
visit_items_joined_by_separator (item.get_type_param_bounds (), PLUS);
}

void
TokenCollector::visit (Method &method)
{
visit (method.get_visibility ());
auto method_name = method.get_method_name ().as_string ();
auto qualifiers = method.get_qualifiers ();
visit (qualifiers);

push (Rust::Token::make (FN_TOK, method.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (method_name)));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

visit (method.get_self_param ());
if (!method.get_function_params ().empty ())
{
push (Rust::Token::make (COMMA, UNDEF_LOCATION));
visit_items_joined_by_separator (method.get_function_params (), COMMA);
}

push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));

if (method.has_return_type ())
{
push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
visit (method.get_return_type ());
}

auto &block = method.get_definition ();
if (!block)
push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
else
visit (block);
newline ();
}

void
TokenCollector::visit (Module &module)
{
Expand Down Expand Up @@ -1817,6 +1782,14 @@ TokenCollector::visit (Function &function)
visit (function.get_generic_params ());

push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

if (function.has_self_param ())
{
visit (function.get_self_param ());
if (!function.get_function_params ().empty ())
push (Rust::Token::make (COMMA, UNDEF_LOCATION));
}

visit_items_joined_by_separator (function.get_function_params ());
push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));

Expand Down
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class TokenCollector : public ASTVisitor
void visit (TypeParam &param);
void visit (LifetimeWhereClauseItem &item);
void visit (TypeBoundWhereClauseItem &item);
void visit (Method &method);
void visit (Module &module);
void visit (ExternCrate &crate);
void visit (UseTreeGlob &use_tree);
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/ast/rust-ast-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class SelfParam;
class FunctionQualifiers;
class FunctionParam;
struct Visibility;
class Method;
class VisItem;
class Module;
class ExternCrate;
Expand Down
19 changes: 2 additions & 17 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,23 +728,6 @@ DefaultASTVisitor::visit (AST::FunctionParam &param)
visit (param.get_type ());
}

void
DefaultASTVisitor::visit (AST::Method &method)
{
visit_outer_attrs (method);
visit (method.get_visibility ());
visit (method.get_qualifiers ());
for (auto &generic : method.get_generic_params ())
visit (generic);
visit (method.get_self_param ());
for (auto &param : method.get_function_params ())
visit (param);
if (method.has_return_type ())
visit (method.get_return_type ());
visit (method.get_where_clause ());
visit (method.get_definition ());
}

void
DefaultASTVisitor::visit (AST::Module &module)
{
Expand Down Expand Up @@ -794,6 +777,8 @@ DefaultASTVisitor::visit (AST::Function &function)
visit (function.get_qualifiers ());
for (auto &generic : function.get_generic_params ())
visit (generic);
if (function.has_self_param ())
visit (function.get_self_param ());
for (auto &param : function.get_function_params ())
visit (param);
if (function.has_return_type ())
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ASTVisitor
// virtual void visit(WhereClauseItem& item) = 0;
virtual void visit (LifetimeWhereClauseItem &item) = 0;
virtual void visit (TypeBoundWhereClauseItem &item) = 0;
virtual void visit (Method &method) = 0;
virtual void visit (Module &module) = 0;
virtual void visit (ExternCrate &crate) = 0;
// virtual void visit(UseTree& use_tree) = 0;
Expand Down Expand Up @@ -308,7 +307,6 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::TypeParam &param) override;
virtual void visit (AST::LifetimeWhereClauseItem &item) override;
virtual void visit (AST::TypeBoundWhereClauseItem &item) override;
virtual void visit (AST::Method &method) override;
virtual void visit (AST::Module &module) override;
virtual void visit (AST::ExternCrate &crate) override;
virtual void visit (AST::UseTreeGlob &use_tree) override;
Expand Down
69 changes: 0 additions & 69 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,69 +725,6 @@ InherentImpl::as_string () const
return str;
}

std::string
Method::as_string () const
{
std::string str ("Method: \n ");

str += vis.as_string () + " " + qualifiers.as_string ();

str += " fn " + method_name.as_string ();

// generic params
str += "\n Generic params: ";
if (generic_params.empty ())
{
str += "none";
}
else
{
for (const auto &param : generic_params)
{
// DEBUG: null pointer check
if (param == nullptr)
{
rust_debug (
"something really terrible has gone wrong - null pointer "
"generic param in method.");
return "NULL_POINTER_MARK";
}

str += "\n " + param->as_string ();
}
}

str += "\n Self param: " + self_param.as_string ();

str += "\n Function params: ";
if (function_params.empty ())
{
str += "none";
}
else
{
for (const auto &param : function_params)
str += "\n " + param.as_string ();
}

str += "\n Return type: ";
if (has_return_type ())
str += return_type->as_string ();
else
str += "none (void)";

str += "\n Where clause: ";
if (has_where_clause ())
str += where_clause.as_string ();
else
str += "none";

str += "\n Block expr (body): \n ";
str += function_body->as_string ();

return str;
}

std::string
StructStruct::as_string () const
{
Expand Down Expand Up @@ -4883,12 +4820,6 @@ TypeBoundWhereClauseItem::accept_vis (ASTVisitor &vis)
vis.visit (*this);
}

void
Method::accept_vis (ASTVisitor &vis)
{
vis.visit (*this);
}

void
Module::accept_vis (ASTVisitor &vis)
{
Expand Down
Loading

0 comments on commit 9864d7f

Please sign in to comment.