diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-06-16 05:00:29 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-06-17 09:43:07 +0200 |
commit | d9fb7d06ca79e8c0f784da02696b436bc50e2f49 (patch) | |
tree | 3c8718dcfcaa8c714a2f72e242ab3988a328fcaa /gcc/rust/ast/rust-ast.h | |
parent | 848a1a28b91d105ff4f21cc9993befbcecb3e39d (diff) | |
download | gcc-d9fb7d06ca79e8c0f784da02696b436bc50e2f49.zip gcc-d9fb7d06ca79e8c0f784da02696b436bc50e2f49.tar.gz gcc-d9fb7d06ca79e8c0f784da02696b436bc50e2f49.tar.bz2 |
ast: Add ConstGenericParam class
This also implements all the necessary boilerplate to allow visitors to
work properly. For now, no operation is performed on const generic
params - similarly to lifetimes
Diffstat (limited to 'gcc/rust/ast/rust-ast.h')
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 2d7d31a..b4d401c 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1342,6 +1342,72 @@ protected: } }; +/** + * Representation of const generic parameters + */ +class ConstGenericParam : public GenericParam +{ + /* Name of the parameter */ + Identifier name; + + /* Mandatory type of the const parameter - a null pointer is an error */ + std::unique_ptr<AST::Type> type; + + /** + * Default value for the const generic parameter - nullptr indicates a lack + * of default value, not an error, as these errors are reported during + * parsing. + */ + std::unique_ptr<AST::Expr> default_value; + + Attribute outer_attr; + Location locus; + +public: + ConstGenericParam (Identifier name, std::unique_ptr<AST::Type> type, + std::unique_ptr<AST::Expr> default_value, + Attribute outer_attr, Location locus) + : name (name), type (std::move (type)), + default_value (std::move (default_value)), outer_attr (outer_attr), + locus (locus) + {} + + ConstGenericParam (const ConstGenericParam &other) + : GenericParam (), name (other.name), type (other.type->clone_type ()), + outer_attr (other.outer_attr), locus (other.locus) + { + if (other.default_value) + default_value = other.default_value->clone_expr (); + } + + bool has_type () { return type != nullptr; } + + std::unique_ptr<AST::Type> &get_type () + { + rust_assert (has_type ()); + + return type; + } + + std::unique_ptr<AST::Expr> &get_default_value () { return default_value; } + + std::string as_string () const override; + + void accept_vis (ASTVisitor &vis) override; + + Location get_locus () const override final { return locus; } + + Kind get_kind () const override final { return Kind::Const; } + +protected: + /* Use covariance to implement clone function as returning this object rather + * than base */ + ConstGenericParam *clone_generic_param_impl () const override + { + return new ConstGenericParam (*this); + } +}; + // A macro item AST node - abstract base class class MacroItem : public Item { |