diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-02 13:54:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-02 13:54:14 +0000 |
commit | 5f0df4812c37fc428b5508e019e9fb7f8a7b77b1 (patch) | |
tree | 2a2bef1a866b93287a48990c09a4243d0ab41c0f /gcc/rust/hir | |
parent | 09af9b16b436606fa8ced0aa6cc111555bdc3da7 (diff) | |
parent | fc5f8d746362a42adc52e538dec248bd2992a794 (diff) | |
download | gcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.zip gcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.tar.gz gcc-5f0df4812c37fc428b5508e019e9fb7f8a7b77b1.tar.bz2 |
Merge #781
781: Add missing typechecking for enums r=philberty a=philberty
This PR splits up the Algebraic data type into one which can support many variants which is what an enum is.
It then changes the type checking for construction of ADT's to use the VariantDef structures as required. This
does not fully implement but does allow us to have most of the type checking in place to start code-generation work.
This combines work from Mark Wielaard (https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=enum-type) and Philip
Addresses #79
Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 31 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 2 |
2 files changed, 21 insertions, 12 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 9b8793f..c5a8d06 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -1694,12 +1694,12 @@ public: return std::unique_ptr<EnumItem> (clone_item_impl ()); } - virtual std::string as_string () const; + virtual std::string as_string () const override; // not pure virtual as not abstract - virtual void accept_vis (HIRVisitor &vis); + virtual void accept_vis (HIRVisitor &vis) override; - Location get_locus () const { return locus; } + Location get_locus () const override { return locus; } Identifier get_identifier () const { return variant_name; } @@ -1729,6 +1729,8 @@ public: void accept_vis (HIRVisitor &vis) override; + std::vector<TupleField> &get_tuple_fields () { return tuple_fields; } + protected: // Clone function implementation as (not pure) virtual method EnumItemTuple *clone_item_impl () const override @@ -1759,6 +1761,8 @@ public: void accept_vis (HIRVisitor &vis) override; + std::vector<StructField> &get_struct_fields () { return struct_fields; } + protected: // Clone function implementation as (not pure) virtual method EnumItemStruct *clone_item_impl () const override @@ -1805,6 +1809,8 @@ public: void accept_vis (HIRVisitor &vis) override; + std::unique_ptr<Expr> &get_discriminant_expression () { return expression; } + protected: // Clone function implementation as (not pure) virtual method EnumItemDiscriminant *clone_item_impl () const override @@ -1899,6 +1905,16 @@ public: Identifier get_identifier () const { return enum_name; } + std::vector<std::unique_ptr<GenericParam>> &get_generic_params () + { + return generic_params; + } + + const std::vector<std::unique_ptr<EnumItem>> &get_variants () const + { + return items; + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -1989,14 +2005,7 @@ public: void accept_vis (HIRVisitor &vis) override; - void iterate (std::function<bool (StructField &)> cb) - { - for (auto &variant : variants) - { - if (!cb (variant)) - return; - } - } + std::vector<StructField> &get_variants () { return variants; } WhereClause &get_where_clause () { return where_clause; } diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 667f4d08..d7977b4 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -127,7 +127,7 @@ public: return std::unique_ptr<Item> (clone_item_impl ()); } - std::string as_string () const; + std::string as_string () const override; /* Adds crate names to the vector passed by reference, if it can * (polymorphism). */ |