From d2f92e6a73338c986601a071b8641c051e700aba Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 5 Nov 2021 12:31:31 +0000 Subject: Add is_item helper to AST and HIR BlockExpr can contain Items and Stmts this allows us to differentiate between them on the Stmt level. --- gcc/rust/ast/rust-ast.h | 4 ++++ gcc/rust/ast/rust-stmt.h | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'gcc/rust/ast') diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 95e4738..72f2609 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -822,6 +822,8 @@ public: virtual bool is_marked_for_strip () const = 0; NodeId get_node_id () const { return node_id; } + virtual bool is_item () const = 0; + protected: Stmt () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} @@ -847,6 +849,8 @@ public: add_crate_name (std::vector &names ATTRIBUTE_UNUSED) const {} + bool is_item () const override final { return true; } + protected: // Clone function implementation as pure virtual method virtual Item *clone_item_impl () const = 0; diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h index b83ca11..a1b4e57 100644 --- a/gcc/rust/ast/rust-stmt.h +++ b/gcc/rust/ast/rust-stmt.h @@ -46,6 +46,8 @@ public: void mark_for_strip () override { marked_for_strip = true; } bool is_marked_for_strip () const override { return marked_for_strip; } + bool is_item () const override final { return false; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -169,6 +171,8 @@ public: return type; } + bool is_item () const override final { return false; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -186,6 +190,8 @@ class ExprStmt : public Stmt public: Location get_locus () const override final { return locus; } + bool is_item () const override final { return false; } + protected: ExprStmt (Location locus) : locus (locus) {} }; -- cgit v1.1