public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7819] gccrs: ast: Add manual dispatch for meta item downcasting Date: Tue, 16 Jan 2024 18:01:16 +0000 (GMT) [thread overview] Message-ID: <20240116180116.CBE41385829F@sourceware.org> (raw) https://gcc.gnu.org/g:5920e4b7579c664c17a07d126c7fb09f4d786849 commit r14-7819-g5920e4b7579c664c17a07d126c7fb09f4d786849 Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> Date: Tue Jun 20 13:26:45 2023 +0200 gccrs: ast: Add manual dispatch for meta item downcasting Several meta items shall be downcasted in various places, this commit introduces values to dispatch on. gcc/rust/ChangeLog: * ast/rust-ast.h (class MetaItem): Add MetaItem dispatch values. * ast/rust-expr.h: Add LitExpr and PathLit dispatch. * ast/rust-macro.h: Add remaining dispatch getters. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> Diff: --- gcc/rust/ast/rust-ast.h | 26 ++++++++++++++++++++++++++ gcc/rust/ast/rust-expr.h | 10 ++++++++++ gcc/rust/ast/rust-macro.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 7989bbe13c1..faf14fe722b 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -681,12 +681,20 @@ protected: virtual MetaItemInner *clone_meta_item_inner_impl () const = 0; public: + enum class Kind + { + LitExpr, + MetaItem, + }; + // Unique pointer custom clone function std::unique_ptr<MetaItemInner> clone_meta_item_inner () const { return std::unique_ptr<MetaItemInner> (clone_meta_item_inner_impl ()); } + virtual Kind get_kind () = 0; + virtual ~MetaItemInner (); virtual location_t get_locus () const = 0; @@ -897,6 +905,24 @@ class AttrInputLiteral; // abstract base meta item class class MetaItem : public MetaItemInner { +public: + enum class ItemKind + { + Path, + Word, + NameValueStr, + PathLit, + Seq, + ListPaths, + ListNameValueStr, + }; + + MetaItemInner::Kind get_kind () override + { + return MetaItemInner::Kind::MetaItem; + } + + virtual ItemKind get_item_kind () const = 0; }; // Forward decl - defined in rust-expr.h diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 63c7d107961..b3aa41726c4 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -200,6 +200,11 @@ public: bool check_cfg_predicate (const Session &session) const override; + MetaItemInner::Kind get_kind () override + { + return MetaItemInner::Kind::LitExpr; + } + protected: // Use covariance to implement clone function as returning this type MetaItemLitExpr *clone_meta_item_inner_impl () const override @@ -228,6 +233,11 @@ public: return path.as_string () + " = " + lit.as_string (); } + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::PathLit; + } + // There are two Locations in MetaItemPathLit (path and lit_expr), // we have no idea use which of them, just simply return UNKNOWN_LOCATION // now. diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index c63b480de61..db8cf1ef5d4 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -844,6 +844,11 @@ public: Attribute to_attribute () const override; + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::Path; + } + protected: // Use covariance to implement clone function as returning this type MetaItemPath *clone_meta_item_inner_impl () const override @@ -902,6 +907,11 @@ public: Attribute to_attribute () const override; + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::Seq; + } + protected: // Use covariance to implement clone function as returning this type MetaItemSeq *clone_meta_item_inner_impl () const override @@ -933,6 +943,11 @@ public: Attribute to_attribute () const override; + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::Word; + } + protected: // Use covariance to implement clone function as returning this type MetaWord *clone_meta_item_inner_impl () const override @@ -984,6 +999,11 @@ public: bool is_key_value_pair () const override { return true; } + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::NameValueStr; + } + protected: // Use covariance to implement clone function as returning this type MetaNameValueStr *clone_meta_item_inner_impl () const override @@ -1021,6 +1041,11 @@ public: Attribute to_attribute () const override; + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::ListPaths; + } + private: bool check_path_exists_in_cfg (const Session &session, const SimplePath &path) const; @@ -1061,6 +1086,11 @@ public: Attribute to_attribute () const override; + MetaItem::ItemKind get_item_kind () const override + { + return MetaItem::ItemKind::ListNameValueStr; + } + protected: // Use covariance to implement clone function as returning this type MetaListNameValueStr *clone_meta_item_inner_impl () const override
reply other threads:[~2024-01-16 18:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240116180116.CBE41385829F@sourceware.org \ --to=cohenarthur@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).