Skip to content

Commit

Permalink
Remove obsolete classes and functions.
Browse files Browse the repository at this point in the history
Trait functions now use AST::Function class, so classes
AST::TraitItemFunc, AST::TraitItemMethod, AST::TraitFunctionDecl,
AST::TraitMethodDecl and their related functions can be removed.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit):
	Remove obsolete classes and functions.
	* ast/rust-ast-collector.h:
	Likewise.
	* ast/rust-ast-full-decls.h (class TraitFunctionDecl):
	Likewise.
	(class TraitItemFunc):
	Likewise.
	(class TraitMethodDecl):
	Likewise.
	(class TraitItemMethod):
	Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
	Likewise.
	* ast/rust-ast-visitor.h:
	Likewise.
	* ast/rust-ast.cc (TraitItemFunc::TraitItemFunc):
	Likewise.
	(TraitItemFunc::operator=):
	Likewise.
	(TraitItemFunc::as_string):
	Likewise.
	(TraitFunctionDecl::as_string):
	Likewise.
	(TraitItemMethod::TraitItemMethod):
	Likewise.
	(TraitItemMethod::operator=):
	Likewise.
	(TraitItemMethod::as_string):
	Likewise.
	(TraitMethodDecl::as_string):
	Likewise.
	(TraitItemFunc::accept_vis):
	Likewise.
	(TraitItemMethod::accept_vis):
	Likewise.
	* ast/rust-item.h (class TraitFunctionDecl):
	Likewise.
	(class TraitItemFunc):
	Likewise.
	(class TraitMethodDecl):
	Likewise.
	(class TraitItemMethod):
	Likewise.
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	Likewise.
	* checks/errors/rust-ast-validation.h:
	Likewise.
	* checks/errors/rust-feature-gate.h:
	Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_trait_function_decl):
	Likewise.
	(CfgStrip::maybe_strip_trait_method_decl):
	Likewise.
	(CfgStrip::visit):
	Likewise.
	* expand/rust-cfg-strip.h:
	Likewise.
	* expand/rust-derive.h:
	Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::expand_trait_function_decl):
	Likewise.
	(ExpandVisitor::expand_trait_method_decl):
	Likewise.
	(ExpandVisitor::visit):
	Likewise.
	* expand/rust-expand-visitor.h:
	Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):
	Likewise.
	* hir/rust-ast-lower-base.h:
	Likewise.
	* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
	Likewise.
	* hir/rust-ast-lower-implitem.h:
	Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
	Likewise.
	* resolve/rust-ast-resolve-base.h:
	Likewise.
	* resolve/rust-ast-resolve-implitem.h (visit):
	Likewise.
	* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
	Likewise.
	* resolve/rust-ast-resolve-item.h:
	Likewise.
	* resolve/rust-default-resolver.cc (DefaultResolver::visit):
	Likewise.
	* resolve/rust-default-resolver.h:
	Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.h:
	Likewise.
	* util/rust-attributes.cc (AttributeChecker::visit):
	Likewise.
	* util/rust-attributes.h:
	Likewise.

Signed-off-by: Kushal Pal <[email protected]>
  • Loading branch information
braw-lee authored and CohenArthur committed Feb 5, 2024
1 parent a10b39d commit df78aec
Show file tree
Hide file tree
Showing 30 changed files with 0 additions and 1,302 deletions.
34 changes: 0 additions & 34 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1948,23 +1948,6 @@ TokenCollector::visit_function_common (std::unique_ptr<Type> &return_type,
}
}

void
TokenCollector::visit (TraitItemFunc &item)
{
auto func = item.get_trait_function_decl ();
auto id = func.get_identifier ().as_string ();

push (Rust::Token::make (FN_KW, item.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

visit_items_joined_by_separator (func.get_function_params ());

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

visit_function_common (func.get_return_type (), item.get_definition ());
}

void
TokenCollector::visit (SelfParam &param)
{
Expand All @@ -1987,23 +1970,6 @@ TokenCollector::visit (SelfParam &param)
}
}

void
TokenCollector::visit (TraitItemMethod &item)
{
auto method = item.get_trait_method_decl ();
auto id = method.get_identifier ().as_string ();

push (Rust::Token::make (FN_KW, item.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

visit_items_joined_by_separator (method.get_function_params (), COMMA);

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

visit_function_common (method.get_return_type (), item.get_definition ());
}

void
TokenCollector::visit (TraitItemConst &item)
{
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/ast/rust-ast-collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ class TokenCollector : public ASTVisitor
void visit (Union &union_item);
void visit (ConstantItem &const_item);
void visit (StaticItem &static_item);
void visit (TraitItemFunc &item);
void visit (SelfParam &param);
void visit (TraitItemMethod &item);
void visit (TraitItemConst &item);
void visit (TraitItemType &item);
void visit (Trait &trait);
Expand Down
4 changes: 0 additions & 4 deletions gcc/rust/ast/rust-ast-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ class Enum;
class Union;
class ConstantItem;
class StaticItem;
class TraitFunctionDecl;
class TraitItemFunc;
class TraitMethodDecl;
class TraitItemMethod;
class TraitItemConst;
class TraitItemType;
class Trait;
Expand Down
45 changes: 0 additions & 45 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,51 +911,6 @@ DefaultASTVisitor::visit (AST::StaticItem &static_item)
visit (static_item.get_expr ());
}

void
DefaultASTVisitor::visit (AST::TraitFunctionDecl &decl)
{
visit (decl.get_qualifiers ());
for (auto &generic : decl.get_generic_params ())
visit (generic);
visit (decl.get_where_clause ());
for (auto &param : decl.get_function_params ())
visit (param);
if (decl.has_return_type ())
visit (decl.get_return_type ());
}

void
DefaultASTVisitor::visit (AST::TraitItemFunc &item)
{
visit_outer_attrs (item);
visit (item.get_trait_function_decl ());
if (item.has_definition ())
visit (item.get_definition ());
}

void
DefaultASTVisitor::visit (AST::TraitMethodDecl &decl)
{
visit (decl.get_qualifiers ());
for (auto &generic : decl.get_generic_params ())
visit (generic);
visit (decl.get_where_clause ());
visit (decl.get_self_param ());
for (auto &param : decl.get_function_params ())
visit (param);
if (decl.has_return_type ())
visit (decl.get_return_type ());
}

void
DefaultASTVisitor::visit (AST::TraitItemMethod &item)
{
visit_outer_attrs (item);
visit (item.get_trait_method_decl ());
if (item.has_definition ())
visit (item.get_definition ());
}

void
DefaultASTVisitor::visit (AST::TraitItemConst &item)
{
Expand Down
6 changes: 0 additions & 6 deletions gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ class ASTVisitor
virtual void visit (Union &union_item) = 0;
virtual void visit (ConstantItem &const_item) = 0;
virtual void visit (StaticItem &static_item) = 0;
virtual void visit (TraitItemFunc &item) = 0;
virtual void visit (TraitItemMethod &item) = 0;
virtual void visit (TraitItemConst &item) = 0;
virtual void visit (TraitItemType &item) = 0;
virtual void visit (Trait &trait) = 0;
Expand Down Expand Up @@ -330,8 +328,6 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::Union &union_item) override;
virtual void visit (AST::ConstantItem &const_item) override;
virtual void visit (AST::StaticItem &static_item) override;
virtual void visit (AST::TraitItemFunc &item) override;
virtual void visit (AST::TraitItemMethod &item) override;
virtual void visit (AST::TraitItemConst &item) override;
virtual void visit (AST::TraitItemType &item) override;
virtual void visit (AST::Trait &trait) override;
Expand Down Expand Up @@ -420,8 +416,6 @@ class DefaultASTVisitor : public ASTVisitor
virtual void visit (AST::WhereClause &where);
virtual void visit (AST::StructField &field);
virtual void visit (AST::TupleField &field);
virtual void visit (AST::TraitFunctionDecl &decl);
virtual void visit (AST::TraitMethodDecl &decl);
virtual void visit (AST::NamedFunctionParam &param);
virtual void visit (AST::MacroRule &rule);
virtual void visit (AST::MacroInvocData &data);
Expand Down
209 changes: 0 additions & 209 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3049,203 +3049,6 @@ NamedFunctionParam::as_string () const
return str;
}

TraitItemFunc::TraitItemFunc (TraitItemFunc const &other)
: TraitItem (other.locus), outer_attrs (other.outer_attrs), decl (other.decl)
{
node_id = other.node_id;

// guard to prevent null dereference
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
}

TraitItemFunc &
TraitItemFunc::operator= (TraitItemFunc const &other)
{
TraitItem::operator= (other);
outer_attrs = other.outer_attrs;
decl = other.decl;
locus = other.locus;
node_id = other.node_id;

// guard to prevent null dereference
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
else
block_expr = nullptr;

return *this;
}
std::string
TraitItemFunc::as_string () const
{
std::string str = append_attributes (outer_attrs, OUTER);

str += "\n" + decl.as_string ();

str += "\n Definition (block expr): ";
if (has_definition ())
str += block_expr->as_string ();
else
str += "none";

return str;
}

std::string
TraitFunctionDecl::as_string () const
{
std::string str
= qualifiers.as_string () + "fn " + function_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 trait function decl.");
return "NULL_POINTER_MARK";
}

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

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

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";

return str;
}

TraitItemMethod::TraitItemMethod (TraitItemMethod const &other)
: TraitItem (other.locus), outer_attrs (other.outer_attrs), decl (other.decl)
{
node_id = other.node_id;

// guard to prevent null dereference
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
}

TraitItemMethod &
TraitItemMethod::operator= (TraitItemMethod const &other)
{
TraitItem::operator= (other);
outer_attrs = other.outer_attrs;
decl = other.decl;
locus = other.locus;
node_id = other.node_id;

// guard to prevent null dereference
if (other.block_expr != nullptr)
block_expr = other.block_expr->clone_block_expr ();
else
block_expr = nullptr;

return *this;
}

std::string
TraitItemMethod::as_string () const
{
std::string str = append_attributes (outer_attrs, OUTER);

str += "\n" + decl.as_string ();

str += "\n Definition (block expr): ";
if (has_definition ())
str += block_expr->as_string ();
else
str += "none";

return str;
}

std::string
TraitMethodDecl::as_string () const
{
std::string str
= qualifiers.as_string () + "fn " + function_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 trait function decl.");
return "NULL_POINTER_MARK";
}

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

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

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";

return str;
}

std::string
TraitItemConst::as_string () const
{
Expand Down Expand Up @@ -5017,18 +4820,6 @@ StaticItem::accept_vis (ASTVisitor &vis)
vis.visit (*this);
}

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

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

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

0 comments on commit df78aec

Please sign in to comment.