Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace AST::Method with existing AST::Function #2715

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading