@@ -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
28402723class TraitItemType : public TraitItem
28412724{
0 commit comments