Skip to content

Commit 6256391

Browse files
powerboat9CohenArthur
authored andcommitted
Remove AST::TraitItemConst
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove overload for TraitItemConst. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit): Likewise. * ast/rust-ast-pointer-visitor.h (PointerVisitor::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise. (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h (CfgStrip::visit): Likewise. * expand/rust-derive.h (DeriveVisitor::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h (AttributeChecker::visit): Likewise. * ast/rust-ast.cc (ConstantItem::as_string): Handle missing expression. (TraitItemConst::as_string): Remove function definition. (TraitItemConst::accept_vis): Remove function definition. * ast/rust-item.h (ConstantItem::mark_for_strip): Adjust comment. (ConstantItem::has_expr): Make const. (class TraitItemConst): Remove definition. * ast/rust-ast-full-decls.h (class TraitItemConst): Remove declaration. * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Handle ConstantItem instead of TraitItemConst. * hir/rust-ast-lower-implitem.h (ASTLowerTraitItem::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_trait_const): Return pointer to ConstantItem instead of TraitItemConst. * parse/rust-parse.h (Parser::parse_trait_const): Likewise. Signed-off-by: Owen Avery <[email protected]>
1 parent 4db0cf7 commit 6256391

22 files changed

+12
-245
lines changed

gcc/rust/ast/rust-ast-collector.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,19 +2171,6 @@ TokenCollector::visit (SelfParam &param)
21712171
}
21722172
}
21732173

2174-
void
2175-
TokenCollector::visit (TraitItemConst &item)
2176-
{
2177-
auto id = item.get_identifier ().as_string ();
2178-
indentation ();
2179-
push (Rust::Token::make (CONST, item.get_locus ()));
2180-
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
2181-
push (Rust::Token::make (COLON, UNDEF_LOCATION));
2182-
visit (item.get_type ());
2183-
push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
2184-
newline ();
2185-
}
2186-
21872174
void
21882175
TokenCollector::visit (TraitItemType &item)
21892176
{

gcc/rust/ast/rust-ast-collector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ class TokenCollector : public ASTVisitor
330330
void visit (ConstantItem &const_item);
331331
void visit (StaticItem &static_item);
332332
void visit (SelfParam &param);
333-
void visit (TraitItemConst &item);
334333
void visit (TraitItemType &item);
335334
void visit (Trait &trait);
336335
void visit (InherentImpl &impl);

gcc/rust/ast/rust-ast-full-decls.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ class Enum;
195195
class Union;
196196
class ConstantItem;
197197
class StaticItem;
198-
class TraitItemConst;
199198
class TraitItemType;
200199
class Trait;
201200
class Impl;

gcc/rust/ast/rust-ast-pointer-visitor.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,15 +1003,6 @@ PointerVisitor::visit (AST::StaticItem &static_item)
10031003
reseat (static_item.get_expr_ptr ());
10041004
}
10051005

1006-
void
1007-
PointerVisitor::visit (AST::TraitItemConst &item)
1008-
{
1009-
visit_outer_attrs (item);
1010-
reseat (item.get_type_ptr ());
1011-
if (item.has_expr ())
1012-
reseat (item.get_expr_ptr ());
1013-
}
1014-
10151006
void
10161007
PointerVisitor::visit (AST::TraitItemType &item)
10171008
{

gcc/rust/ast/rust-ast-pointer-visitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class PointerVisitor : public DefaultASTVisitor
165165
void visit (AST::Union &union_item) override;
166166
void visit (AST::ConstantItem &const_item) override;
167167
void visit (AST::StaticItem &static_item) override;
168-
void visit (AST::TraitItemConst &item) override;
169168
void visit (AST::TraitItemType &item) override;
170169
void visit (AST::Trait &trait) override;
171170
void visit (AST::InherentImpl &impl) override;

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,15 +1024,6 @@ DefaultASTVisitor::visit (AST::StaticItem &static_item)
10241024
visit (static_item.get_expr ());
10251025
}
10261026

1027-
void
1028-
DefaultASTVisitor::visit (AST::TraitItemConst &item)
1029-
{
1030-
visit_outer_attrs (item);
1031-
visit (item.get_type ());
1032-
if (item.has_expr ())
1033-
visit (item.get_expr ());
1034-
}
1035-
10361027
void
10371028
DefaultASTVisitor::visit (AST::TraitItemType &item)
10381029
{

gcc/rust/ast/rust-ast-visitor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ class ASTVisitor
164164
virtual void visit (Union &union_item) = 0;
165165
virtual void visit (ConstantItem &const_item) = 0;
166166
virtual void visit (StaticItem &static_item) = 0;
167-
virtual void visit (TraitItemConst &item) = 0;
168167
virtual void visit (TraitItemType &item) = 0;
169168
virtual void visit (Trait &trait) = 0;
170169
virtual void visit (InherentImpl &impl) = 0;
@@ -349,7 +348,6 @@ class DefaultASTVisitor : public ASTVisitor
349348
virtual void visit (AST::Union &union_item) override;
350349
virtual void visit (AST::ConstantItem &const_item) override;
351350
virtual void visit (AST::StaticItem &static_item) override;
352-
virtual void visit (AST::TraitItemConst &item) override;
353351
virtual void visit (AST::TraitItemType &item) override;
354352
virtual void visit (AST::Trait &trait) override;
355353
virtual void visit (AST::InherentImpl &impl) override;

gcc/rust/ast/rust-ast.cc

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,8 @@ ConstantItem::as_string () const
652652
}
653653
str += "\n Type: " + type->as_string ();
654654

655-
// DEBUG: null pointer check
656-
if (const_expr == nullptr)
657-
{
658-
rust_debug ("something really terrible has gone wrong - null "
659-
"pointer expr in const item.");
660-
return "NULL_POINTER_MARK";
661-
}
662-
str += "\n Expression: " + const_expr->as_string ();
655+
if (has_expr ())
656+
str += "\n Expression: " + const_expr->as_string ();
663657

664658
return str + "\n";
665659
}
@@ -3049,20 +3043,6 @@ ExternalStaticItem::as_string () const
30493043
return str;
30503044
}
30513045

3052-
std::string
3053-
TraitItemConst::as_string () const
3054-
{
3055-
// TODO: rewrite to work with non-linearisable exprs
3056-
std::string str = append_attributes (outer_attrs, OUTER);
3057-
3058-
str += "\nconst " + name.as_string () + " : " + type->as_string ();
3059-
3060-
if (has_expression ())
3061-
str += " = " + expr->as_string ();
3062-
3063-
return str;
3064-
}
3065-
30663046
std::string
30673047
TraitItemType::as_string () const
30683048
{
@@ -4763,12 +4743,6 @@ StaticItem::accept_vis (ASTVisitor &vis)
47634743
vis.visit (*this);
47644744
}
47654745

4766-
void
4767-
TraitItemConst::accept_vis (ASTVisitor &vis)
4768-
{
4769-
vis.visit (*this);
4770-
}
4771-
47724746
void
47734747
TraitItemType::accept_vis (ASTVisitor &vis)
47744748
{

gcc/rust/ast/rust-item.h

Lines changed: 2 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ class ConstantItem : public VisItem, public AssociatedItem
25412541

25422542
void accept_vis (ASTVisitor &vis) override;
25432543

2544-
// Invalid if type or expression are null, so base stripping on that.
2544+
// Invalid if type and expression are null, so base stripping on that.
25452545
void mark_for_strip () override
25462546
{
25472547
type = nullptr;
@@ -2552,7 +2552,7 @@ class ConstantItem : public VisItem, public AssociatedItem
25522552
return type == nullptr && const_expr == nullptr;
25532553
}
25542554

2555-
bool has_expr () { return const_expr != nullptr; }
2555+
bool has_expr () const { return const_expr != nullptr; }
25562556

25572557
// TODO: is this better? Or is a "vis_block" better?
25582558
Expr &get_expr ()
@@ -2719,123 +2719,6 @@ class StaticItem : public VisItem
27192719
}
27202720
};
27212721

2722-
// Constant item within traits
2723-
class TraitItemConst : public TraitItem
2724-
{
2725-
std::vector<Attribute> outer_attrs;
2726-
Identifier name;
2727-
std::unique_ptr<Type> type;
2728-
2729-
// bool has_expression;
2730-
std::unique_ptr<Expr> expr;
2731-
2732-
public:
2733-
// Whether the constant item has an associated expression.
2734-
bool has_expression () const { return expr != nullptr; }
2735-
2736-
TraitItemConst (Identifier name, std::unique_ptr<Type> type,
2737-
std::unique_ptr<Expr> expr,
2738-
std::vector<Attribute> outer_attrs, location_t locus)
2739-
: TraitItem (locus), outer_attrs (std::move (outer_attrs)),
2740-
name (std::move (name)), type (std::move (type)), expr (std::move (expr))
2741-
{}
2742-
2743-
// Copy constructor with clones
2744-
TraitItemConst (TraitItemConst const &other)
2745-
: TraitItem (other.locus), outer_attrs (other.outer_attrs),
2746-
name (other.name)
2747-
{
2748-
node_id = other.node_id;
2749-
2750-
// guard to prevent null dereference
2751-
if (other.expr != nullptr)
2752-
expr = other.expr->clone_expr ();
2753-
2754-
// guard to prevent null dereference (only for error state)
2755-
if (other.type != nullptr)
2756-
type = other.type->clone_type ();
2757-
}
2758-
2759-
// Overloaded assignment operator to clone
2760-
TraitItemConst &operator= (TraitItemConst const &other)
2761-
{
2762-
TraitItem::operator= (other);
2763-
outer_attrs = other.outer_attrs;
2764-
name = other.name;
2765-
locus = other.locus;
2766-
node_id = other.node_id;
2767-
2768-
// guard to prevent null dereference
2769-
if (other.expr != nullptr)
2770-
expr = other.expr->clone_expr ();
2771-
else
2772-
expr = nullptr;
2773-
2774-
// guard to prevent null dereference (only for error state)
2775-
if (other.type != nullptr)
2776-
type = other.type->clone_type ();
2777-
else
2778-
type = nullptr;
2779-
2780-
return *this;
2781-
}
2782-
2783-
// move constructors
2784-
TraitItemConst (TraitItemConst &&other) = default;
2785-
TraitItemConst &operator= (TraitItemConst &&other) = default;
2786-
2787-
std::string as_string () const override;
2788-
2789-
location_t get_locus () const override { return locus; }
2790-
2791-
void accept_vis (ASTVisitor &vis) override;
2792-
2793-
// Invalid if type is null, so base stripping on that.
2794-
void mark_for_strip () override { type = nullptr; }
2795-
bool is_marked_for_strip () const override { return type == nullptr; }
2796-
2797-
// TODO: this mutable getter seems really dodgy. Think up better way.
2798-
std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
2799-
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
2800-
2801-
bool has_expr () const { return expr != nullptr; }
2802-
2803-
// TODO: is this better? Or is a "vis_block" better?
2804-
Expr &get_expr ()
2805-
{
2806-
rust_assert (has_expr ());
2807-
return *expr;
2808-
}
2809-
2810-
std::unique_ptr<Expr> &get_expr_ptr ()
2811-
{
2812-
rust_assert (has_expr ());
2813-
return expr;
2814-
}
2815-
2816-
// TODO: is this better? Or is a "vis_block" better?
2817-
Type &get_type ()
2818-
{
2819-
rust_assert (type != nullptr);
2820-
return *type;
2821-
}
2822-
2823-
std::unique_ptr<Type> &get_type_ptr ()
2824-
{
2825-
rust_assert (type != nullptr);
2826-
return type;
2827-
}
2828-
2829-
Identifier get_identifier () const { return name; }
2830-
2831-
protected:
2832-
// Clone function implementation as (not pure) virtual method
2833-
TraitItemConst *clone_associated_item_impl () const override
2834-
{
2835-
return new TraitItemConst (*this);
2836-
}
2837-
};
2838-
28392722
// Type items within traits
28402723
class TraitItemType : public TraitItem
28412724
{

gcc/rust/expand/rust-cfg-strip.cc

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,38 +2068,6 @@ CfgStrip::visit (AST::StaticItem &static_item)
20682068
"attributes not allowed");
20692069
}
20702070

2071-
void
2072-
CfgStrip::visit (AST::TraitItemConst &item)
2073-
{
2074-
// initial test based on outer attrs
2075-
expand_cfg_attrs (item.get_outer_attrs ());
2076-
if (fails_cfg_with_expand (item.get_outer_attrs ()))
2077-
{
2078-
item.mark_for_strip ();
2079-
return;
2080-
}
2081-
2082-
AST::DefaultASTVisitor::visit (item);
2083-
2084-
// strip any sub-types
2085-
auto &type = item.get_type ();
2086-
2087-
if (type.is_marked_for_strip ())
2088-
rust_error_at (type.get_locus (), "cannot strip type in this position");
2089-
2090-
/* strip any internal sub-expressions - expression itself isn't
2091-
* allowed to have external attributes in this position so can't be
2092-
* stripped */
2093-
if (item.has_expression ())
2094-
{
2095-
auto &expr = item.get_expr ();
2096-
if (expr.is_marked_for_strip ())
2097-
rust_error_at (expr.get_locus (),
2098-
"cannot strip expression in this position - outer "
2099-
"attributes not allowed");
2100-
}
2101-
}
2102-
21032071
void
21042072
CfgStrip::visit (AST::TraitItemType &item)
21052073
{

0 commit comments

Comments
 (0)