aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast/rust-item.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/ast/rust-item.h')
-rw-r--r--gcc/rust/ast/rust-item.h406
1 files changed, 0 insertions, 406 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 1defecc..0911719 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -2531,412 +2531,6 @@ protected:
}
};
-// Function declaration in traits
-class TraitFunctionDecl
-{
- // TODO: delete and replace with Function decl item? no as no body in this.
- FunctionQualifiers qualifiers;
- Identifier function_name;
-
- // bool has_generics;
- // Generics generic_params;
- std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
-
- // bool has_params;
- // FunctionParams function_params;
- std::vector<std::unique_ptr<Param>> function_params; // inlined
-
- // bool has_return_type;
- std::unique_ptr<Type> return_type;
-
- // bool has_where_clause;
- WhereClause where_clause;
-
- // should this store location info?
-
-public:
- // Returns whether function decl has generic parameters.
- bool has_generics () const { return !generic_params.empty (); }
-
- // Returns whether function decl has regular parameters.
- bool has_params () const { return !function_params.empty (); }
-
- // Returns whether function has return type (otherwise is void).
- bool has_return_type () const { return return_type != nullptr; }
-
- // Returns whether function has a where clause.
- bool has_where_clause () const { return !where_clause.is_empty (); }
-
- Identifier get_identifier () const { return function_name; }
-
- // Mega-constructor
- TraitFunctionDecl (Identifier function_name, FunctionQualifiers qualifiers,
- std::vector<std::unique_ptr<GenericParam>> generic_params,
- std::vector<std::unique_ptr<Param>> function_params,
- std::unique_ptr<Type> return_type,
- WhereClause where_clause)
- : qualifiers (std::move (qualifiers)),
- function_name (std::move (function_name)),
- generic_params (std::move (generic_params)),
- function_params (std::move (function_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause))
- {}
-
- // Copy constructor with clone
- TraitFunctionDecl (TraitFunctionDecl const &other)
- : qualifiers (other.qualifiers), function_name (other.function_name),
- where_clause (other.where_clause)
- {
- // guard to prevent nullptr dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- function_params.reserve (other.function_params.size ());
- for (const auto &e : other.function_params)
- function_params.push_back (e->clone_param ());
- }
-
- ~TraitFunctionDecl () = default;
-
- // Overloaded assignment operator with clone
- TraitFunctionDecl &operator= (TraitFunctionDecl const &other)
- {
- function_name = other.function_name;
- qualifiers = other.qualifiers;
- where_clause = other.where_clause;
-
- // guard to prevent nullptr dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
- else
- return_type = nullptr;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- function_params.reserve (other.function_params.size ());
- for (const auto &e : other.function_params)
- function_params.push_back (e->clone_param ());
-
- return *this;
- }
-
- // move constructors
- TraitFunctionDecl (TraitFunctionDecl &&other) = default;
- TraitFunctionDecl &operator= (TraitFunctionDecl &&other) = default;
-
- std::string as_string () const;
-
- // Invalid if function name is empty, so base stripping on that.
- void mark_for_strip () { function_name = {""}; }
- bool is_marked_for_strip () const { return function_name.empty (); }
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<std::unique_ptr<Param>> &get_function_params ()
- {
- return function_params;
- }
- const std::vector<std::unique_ptr<Param>> &get_function_params () const
- {
- return function_params;
- }
-
- std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
- {
- return generic_params;
- }
- const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
- {
- return generic_params;
- }
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<Type> &get_return_type () { return return_type; }
-
- // TODO: is this better? Or is a "vis_block" better?
- WhereClause &get_where_clause () { return where_clause; }
-
- FunctionQualifiers get_qualifiers () const { return qualifiers; }
- FunctionQualifiers &get_qualifiers () { return qualifiers; }
-};
-
-// Actual trait item function declaration within traits
-class TraitItemFunc : public TraitItem
-{
- std::vector<Attribute> outer_attrs;
- TraitFunctionDecl decl;
- std::unique_ptr<BlockExpr> block_expr;
-
-public:
- // Returns whether function has a definition or is just a declaration.
- bool has_definition () const { return block_expr != nullptr; }
-
- TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr<BlockExpr> block_expr,
- std::vector<Attribute> outer_attrs, location_t locus)
- : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
- decl (std::move (decl)), block_expr (std::move (block_expr))
- {}
-
- // Copy constructor with clone
- TraitItemFunc (TraitItemFunc const &other);
-
- // Overloaded assignment operator to clone
-
- TraitItemFunc &operator= (TraitItemFunc const &other);
-
- // move constructors
- TraitItemFunc (TraitItemFunc &&other) = default;
- TraitItemFunc &operator= (TraitItemFunc &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- // Invalid if trait decl is empty, so base stripping on that.
- void mark_for_strip () override { decl.mark_for_strip (); }
- bool is_marked_for_strip () const override
- {
- return decl.is_marked_for_strip ();
- }
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<BlockExpr> &get_definition () { return block_expr; }
-
- // TODO: is this better? Or is a "vis_block" better?
- TraitFunctionDecl &get_trait_function_decl ()
- {
- // TODO: maybe only allow access if not marked for strip?
- return decl;
- }
-
-protected:
- // Clone function implementation as (not pure) virtual method
- TraitItemFunc *clone_associated_item_impl () const override
- {
- return new TraitItemFunc (*this);
- }
-};
-
-// Method declaration within traits
-class TraitMethodDecl
-{
- // TODO: delete and replace with Function decl item? no as no body.
- FunctionQualifiers qualifiers;
- Identifier function_name;
-
- // bool has_generics;
- // Generics generic_params;
- std::vector<std::unique_ptr<GenericParam>> generic_params; // inlined
-
- // bool has_params;
- // FunctionParams function_params;
- std::vector<std::unique_ptr<Param>> function_params; // inlined
-
- // bool has_return_type;
- std::unique_ptr<Type> return_type;
-
- // bool has_where_clause;
- WhereClause where_clause;
-
- // should this store location info?
-
-public:
- // Returns whether method decl has generic parameters.
- bool has_generics () const { return !generic_params.empty (); }
-
- // Returns whether method decl has regular parameters.
- bool has_params () const { return !function_params.empty (); }
-
- // Returns whether method has return type (otherwise is void).
- bool has_return_type () const { return return_type != nullptr; }
-
- // Returns whether method has a where clause.
- bool has_where_clause () const { return !where_clause.is_empty (); }
-
- Identifier get_identifier () const { return function_name; }
-
- // Mega-constructor
- TraitMethodDecl (Identifier function_name, FunctionQualifiers qualifiers,
- std::vector<std::unique_ptr<GenericParam>> generic_params,
- std::vector<std::unique_ptr<Param>> function_params,
- std::unique_ptr<Type> return_type, WhereClause where_clause)
- : qualifiers (std::move (qualifiers)),
- function_name (std::move (function_name)),
- generic_params (std::move (generic_params)),
- function_params (std::move (function_params)),
- return_type (std::move (return_type)),
- where_clause (std::move (where_clause))
- {}
-
- // Copy constructor with clone
- TraitMethodDecl (TraitMethodDecl const &other)
- : qualifiers (other.qualifiers), function_name (other.function_name),
- where_clause (other.where_clause)
- {
- // guard to prevent nullptr dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- function_params.reserve (other.function_params.size ());
- for (const auto &e : other.function_params)
- function_params.push_back (e->clone_param ());
- }
-
- ~TraitMethodDecl () = default;
-
- // Overloaded assignment operator with clone
- TraitMethodDecl &operator= (TraitMethodDecl const &other)
- {
- function_name = other.function_name;
- qualifiers = other.qualifiers;
- where_clause = other.where_clause;
-
- // guard to prevent nullptr dereference
- if (other.return_type != nullptr)
- return_type = other.return_type->clone_type ();
- else
- return_type = nullptr;
-
- generic_params.reserve (other.generic_params.size ());
- for (const auto &e : other.generic_params)
- generic_params.push_back (e->clone_generic_param ());
-
- function_params.reserve (other.function_params.size ());
- for (const auto &e : other.function_params)
- function_params.push_back (e->clone_param ());
-
- return *this;
- }
-
- // move constructors
- TraitMethodDecl (TraitMethodDecl &&other) = default;
- TraitMethodDecl &operator= (TraitMethodDecl &&other) = default;
-
- std::string as_string () const;
-
- // Invalid if method name is empty, so base stripping on that.
- void mark_for_strip () { function_name = {""}; }
- bool is_marked_for_strip () const { return function_name.empty (); }
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<std::unique_ptr<Param>> &get_function_params ()
- {
- return function_params;
- }
- const std::vector<std::unique_ptr<Param>> &get_function_params () const
- {
- return function_params;
- }
-
- std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
- {
- return generic_params;
- }
- const std::vector<std::unique_ptr<GenericParam>> &get_generic_params () const
- {
- return generic_params;
- }
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<Type> &get_return_type () { return return_type; }
-
- // TODO: is this better? Or is a "vis_block" better?
- WhereClause &get_where_clause () { return where_clause; }
-
- bool has_self () const
- {
- return !function_params.empty () && function_params[0]->is_self ();
- }
-
- std::unique_ptr<Param> &get_self_param ()
- {
- rust_assert (has_self ());
- return function_params[0];
- }
- const std::unique_ptr<Param> &get_self_param () const
- {
- rust_assert (has_self ());
- return function_params[0];
- }
-
- FunctionQualifiers get_qualifiers () const { return qualifiers; }
-
- FunctionQualifiers &get_qualifiers () { return qualifiers; }
-};
-
-// Actual trait item method declaration within traits
-class TraitItemMethod : public TraitItem
-{
- std::vector<Attribute> outer_attrs;
- TraitMethodDecl decl;
- std::unique_ptr<BlockExpr> block_expr;
-
-public:
- // Returns whether method has a definition or is just a declaration.
- bool has_definition () const { return block_expr != nullptr; }
-
- TraitItemMethod (TraitMethodDecl decl, std::unique_ptr<BlockExpr> block_expr,
- std::vector<Attribute> outer_attrs, location_t locus)
- : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
- decl (std::move (decl)), block_expr (std::move (block_expr))
- {}
-
- // Copy constructor with clone
- TraitItemMethod (TraitItemMethod const &other);
- // Overloaded assignment operator to clone
- TraitItemMethod &operator= (TraitItemMethod const &other);
-
- // move constructors
- TraitItemMethod (TraitItemMethod &&other) = default;
- TraitItemMethod &operator= (TraitItemMethod &&other) = default;
-
- std::string as_string () const override;
-
- void accept_vis (ASTVisitor &vis) override;
-
- // Invalid if trait decl is empty, so base stripping on that.
- void mark_for_strip () override { decl.mark_for_strip (); }
- bool is_marked_for_strip () const override
- {
- return decl.is_marked_for_strip ();
- }
-
- // TODO: this mutable getter seems really dodgy. Think up better way.
- std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
- const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
-
- // TODO: is this better? Or is a "vis_block" better?
- TraitMethodDecl &get_trait_method_decl ()
- {
- // TODO: maybe only allow access if not marked for strip?
- return decl;
- }
-
- // TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<BlockExpr> &get_definition () { return block_expr; }
-
-protected:
- // Clone function implementation as (not pure) virtual method
- TraitItemMethod *clone_associated_item_impl () const override
- {
- return new TraitItemMethod (*this);
- }
-};
-
// Constant item within traits
class TraitItemConst : public TraitItem
{