aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-expr.h
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-01 10:37:18 +0000
committerGitHub <noreply@github.com>2021-09-01 10:37:18 +0000
commitc33c6f3676dfca1a6bd7984cebf5028c015ea182 (patch)
tree0c830b9a468c78f3b0e4a140093cd09ebdda2989 /gcc/rust/ast/rust-expr.h
parent82e1061579796adaa39ab34da77b6c8c6ea82539 (diff)
parent3b5c0f65ef12bd4771f69195d232588cff86b270 (diff)
downloadgcc-c33c6f3676dfca1a6bd7984cebf5028c015ea182.zip
gcc-c33c6f3676dfca1a6bd7984cebf5028c015ea182.tar.gz
gcc-c33c6f3676dfca1a6bd7984cebf5028c015ea182.tar.bz2
Merge #654
654: Cleanup some StructExpr related classes r=philberty a=dkm From Mark Wielaard: https://gcc.gnu.org/pipermail/gcc-rust/2021-September/000163.html > There are various Structure Expressions that don't actually "exist" > because they are syntactically equivalent to other constructs. So we > never really construct or use these classes. But they are still listed > in various visitors, which is somewhat confusing. Removing the AST and > HIR variants of these classes really cleans up the code IMHO. Co-authored-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r--gcc/rust/ast/rust-expr.h445
1 files changed, 0 insertions, 445 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 88e45fe..f26ed98 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -1852,451 +1852,6 @@ protected:
}
};
-// AST node of a tuple struct creator
-class StructExprTuple : public StructExpr
-{
- std::vector<Attribute> inner_attrs;
- std::vector<std::unique_ptr<Expr> > exprs;
-
- Location locus;
-
-public:
- std::string as_string () const override;
-
- const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
- std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }
-
- StructExprTuple (PathInExpression struct_path,
- std::vector<std::unique_ptr<Expr> > tuple_exprs,
- std::vector<Attribute> inner_attribs,
- std::vector<Attribute> outer_attribs, Location locus)
- : StructExpr (std::move (struct_path), std::move (outer_attribs)),
- inner_attrs (std::move (inner_attribs)), exprs (std::move (tuple_exprs)),
- locus (locus)
- {}
-
- // copy constructor with vector clone
- StructExprTuple (StructExprTuple const &other)
- : StructExpr (other), inner_attrs (other.inner_attrs), locus (other.locus)
- {
- exprs.reserve (other.exprs.size ());
- for (const auto &e : other.exprs)
- exprs.push_back (e->clone_expr ());
- }
-
- // overloaded assignment operator with vector clone
- StructExprTuple &operator= (StructExprTuple const &other)
- {
- StructExpr::operator= (other);
- inner_attrs = other.inner_attrs;
- locus = other.locus;
-
- exprs.reserve (other.exprs.size ());
- for (const auto &e : other.exprs)
- exprs.push_back (e->clone_expr ());
-
- return *this;
- }
-
- // move constructors
- StructExprTuple (StructExprTuple &&other) = default;
- StructExprTuple &operator= (StructExprTuple &&other) = default;
-
- Location get_locus () const override final { return locus; }
-
- void accept_vis (ASTVisitor &vis) override;
-
- const std::vector<std::unique_ptr<Expr> > &get_elems () const
- {
- return exprs;
- }
- std::vector<std::unique_ptr<Expr> > &get_elems () { return exprs; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- StructExprTuple *clone_expr_without_block_impl () const override
- {
- return new StructExprTuple (*this);
- }
-};
-
-// AST node of a "unit" struct creator (no fields and no braces)
-class StructExprUnit : public StructExpr
-{
- Location locus;
-
-public:
- std::string as_string () const override
- {
- return get_struct_name ().as_string ();
- }
-
- StructExprUnit (PathInExpression struct_path,
- std::vector<Attribute> outer_attribs, Location locus)
- : StructExpr (std::move (struct_path), std::move (outer_attribs)),
- locus (locus)
- {}
-
- Location get_locus () const override final { return locus; }
-
- void accept_vis (ASTVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- StructExprUnit *clone_expr_without_block_impl () const override
- {
- return new StructExprUnit (*this);
- }
-};
-
-// aka EnumerationVariantExpr
-// Base AST node representing creation of an enum variant instance - abstract
-class EnumVariantExpr : public ExprWithoutBlock
-{
- std::vector<Attribute> outer_attrs;
- PathInExpression enum_variant_path;
-
-protected:
- // Protected constructor for initialising enum_variant_path
- EnumVariantExpr (PathInExpression path_to_enum_variant,
- std::vector<Attribute> outer_attribs)
- : outer_attrs (std::move (outer_attribs)),
- enum_variant_path (std::move (path_to_enum_variant))
- {}
-
-public:
- const PathInExpression &get_enum_variant_path () const
- {
- return enum_variant_path;
- }
- PathInExpression &get_enum_variant_path () { return enum_variant_path; }
-
- // Invalid if path is in error state, so base stripping on that.
- void mark_for_strip () override
- {
- enum_variant_path = PathInExpression::create_error ();
- }
- bool is_marked_for_strip () const override
- {
- return enum_variant_path.is_error ();
- }
-
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
-
- void set_outer_attrs (std::vector<Attribute> new_attrs) override
- {
- outer_attrs = std::move (new_attrs);
- }
-};
-
-/* Base AST node for a single enum expression field (in enum instance creation)
- * - abstract */
-class EnumExprField
-{
-public:
- virtual ~EnumExprField () {}
-
- // Unique pointer custom clone function
- std::unique_ptr<EnumExprField> clone_enum_expr_field () const
- {
- return std::unique_ptr<EnumExprField> (clone_enum_expr_field_impl ());
- }
-
- virtual std::string as_string () const = 0;
-
- virtual void accept_vis (ASTVisitor &vis) = 0;
-
- virtual Location get_locus () const = 0;
-
-protected:
- // Clone function implementation as pure virtual method
- virtual EnumExprField *clone_enum_expr_field_impl () const = 0;
-};
-
-// Identifier-only variant of EnumExprField AST node
-class EnumExprFieldIdentifier : public EnumExprField
-{
- Identifier field_name;
- Location locus;
-
-public:
- EnumExprFieldIdentifier (Identifier field_identifier, Location locus)
- : field_name (std::move (field_identifier)), locus (locus)
- {}
-
- void accept_vis (ASTVisitor &vis) override;
-
- std::string as_string () const override { return field_name; }
-
- Location get_locus () const override final { return locus; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprFieldIdentifier *clone_enum_expr_field_impl () const override
- {
- return new EnumExprFieldIdentifier (*this);
- }
-};
-
-/* Base AST node for a single enum expression field with an assigned value -
- * abstract */
-class EnumExprFieldWithVal : public EnumExprField
-{
- std::unique_ptr<Expr> value;
-
-protected:
- EnumExprFieldWithVal (std::unique_ptr<Expr> field_value)
- : value (std::move (field_value))
- {}
-
- // Copy constructor must clone unique_ptr value
- EnumExprFieldWithVal (EnumExprFieldWithVal const &other)
- : value (other.value->clone_expr ())
- {}
-
- // Overload assignment operator to clone
- EnumExprFieldWithVal &operator= (EnumExprFieldWithVal const &other)
- {
- value = other.value->clone_expr ();
-
- return *this;
- }
-
- // move constructors
- EnumExprFieldWithVal (EnumExprFieldWithVal &&other) = default;
- EnumExprFieldWithVal &operator= (EnumExprFieldWithVal &&other) = default;
-
-public:
- std::string as_string () const override;
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<Expr> &get_value ()
- {
- rust_assert (value != nullptr);
- return value;
- }
-};
-
-// Identifier and value variant of EnumExprField AST node
-class EnumExprFieldIdentifierValue : public EnumExprFieldWithVal
-{
- Identifier field_name;
- Location locus;
-
-public:
- EnumExprFieldIdentifierValue (Identifier field_name,
- std::unique_ptr<Expr> field_value,
- Location locus)
- : EnumExprFieldWithVal (std::move (field_value)),
- field_name (std::move (field_name)), locus (locus)
- {}
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- Location get_locus () const override final { return locus; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprFieldIdentifierValue *clone_enum_expr_field_impl () const override
- {
- return new EnumExprFieldIdentifierValue (*this);
- }
-};
-
-// Tuple index and value variant of EnumExprField AST node
-class EnumExprFieldIndexValue : public EnumExprFieldWithVal
-{
- TupleIndex index;
- // TODO: implement "with val" as a template with EnumExprField as type param?
-
- Location locus;
-
-public:
- EnumExprFieldIndexValue (TupleIndex field_index,
- std::unique_ptr<Expr> field_value, Location locus)
- : EnumExprFieldWithVal (std::move (field_value)), index (field_index),
- locus (locus)
- {}
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- Location get_locus () const override final { return locus; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprFieldIndexValue *clone_enum_expr_field_impl () const override
- {
- return new EnumExprFieldIndexValue (*this);
- }
-};
-
-// Struct-like syntax enum variant instance creation AST node
-class EnumExprStruct : public EnumVariantExpr
-{
- std::vector<std::unique_ptr<EnumExprField> > fields;
- Location locus;
-
-public:
- std::string as_string () const override;
-
- EnumExprStruct (PathInExpression enum_variant_path,
- std::vector<std::unique_ptr<EnumExprField> > variant_fields,
- std::vector<Attribute> outer_attribs, Location locus)
- : EnumVariantExpr (std::move (enum_variant_path),
- std::move (outer_attribs)),
- fields (std::move (variant_fields)), locus (locus)
- {}
-
- // copy constructor with vector clone
- EnumExprStruct (EnumExprStruct const &other)
- : EnumVariantExpr (other), locus (other.locus)
- {
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_enum_expr_field ());
- }
-
- // overloaded assignment operator with vector clone
- EnumExprStruct &operator= (EnumExprStruct const &other)
- {
- EnumVariantExpr::operator= (other);
- locus = other.locus;
-
- fields.reserve (other.fields.size ());
- for (const auto &e : other.fields)
- fields.push_back (e->clone_enum_expr_field ());
-
- return *this;
- }
-
- // move constructors
- EnumExprStruct (EnumExprStruct &&other) = default;
- EnumExprStruct &operator= (EnumExprStruct &&other) = default;
-
- Location get_locus () const override final { return locus; }
-
- void accept_vis (ASTVisitor &vis) override;
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<std::unique_ptr<EnumExprField> > &get_fields () { return fields; }
- const std::vector<std::unique_ptr<EnumExprField> > &get_fields () const
- {
- return fields;
- }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprStruct *clone_expr_without_block_impl () const override
- {
- return new EnumExprStruct (*this);
- }
-};
-
-// Tuple-like syntax enum variant instance creation AST node
-class EnumExprTuple : public EnumVariantExpr
-{
- std::vector<std::unique_ptr<Expr> > values;
- Location locus;
-
-public:
- std::string as_string () const override;
-
- EnumExprTuple (PathInExpression enum_variant_path,
- std::vector<std::unique_ptr<Expr> > variant_values,
- std::vector<Attribute> outer_attribs, Location locus)
- : EnumVariantExpr (std::move (enum_variant_path),
- std::move (outer_attribs)),
- values (std::move (variant_values)), locus (locus)
- {}
-
- // copy constructor with vector clone
- EnumExprTuple (EnumExprTuple const &other)
- : EnumVariantExpr (other), locus (other.locus)
- {
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
- }
-
- // overloaded assignment operator with vector clone
- EnumExprTuple &operator= (EnumExprTuple const &other)
- {
- EnumVariantExpr::operator= (other);
- locus = other.locus;
-
- values.reserve (other.values.size ());
- for (const auto &e : other.values)
- values.push_back (e->clone_expr ());
-
- return *this;
- }
-
- // move constructors
- EnumExprTuple (EnumExprTuple &&other) = default;
- EnumExprTuple &operator= (EnumExprTuple &&other) = default;
-
- Location get_locus () const override final { return locus; }
-
- void accept_vis (ASTVisitor &vis) override;
-
- const std::vector<std::unique_ptr<Expr> > &get_elems () const
- {
- return values;
- }
- std::vector<std::unique_ptr<Expr> > &get_elems () { return values; }
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprTuple *clone_expr_without_block_impl () const override
- {
- return new EnumExprTuple (*this);
- }
-};
-
-// No-field enum variant instance creation AST node
-class EnumExprFieldless : public EnumVariantExpr
-{
- Location locus;
-
-public:
- std::string as_string () const override
- {
- // return enum_variant_path.as_string();
- return get_enum_variant_path ().as_string ();
- }
-
- EnumExprFieldless (PathInExpression enum_variant_path,
- std::vector<Attribute> outer_attribs, Location locus)
- : EnumVariantExpr (std::move (enum_variant_path),
- std::move (outer_attribs)),
- locus (locus)
- {}
-
- Location get_locus () const override final { return locus; }
-
- void accept_vis (ASTVisitor &vis) override;
-
-protected:
- /* Use covariance to implement clone function as returning this object rather
- * than base */
- EnumExprFieldless *clone_expr_without_block_impl () const override
- {
- return new EnumExprFieldless (*this);
- }
-};
-
// Forward decl for Function - used in CallExpr
class Function;