From d71750b7829b3ef3443c75880e439e3e145aa8a7 Mon Sep 17 00:00:00 2001 From: Yizhe Date: Wed, 17 Mar 2021 02:06:21 +0000 Subject: Remove ArrayExpr::has_array_elems has_array_elems() is mostly used as a nullptr check. We don't need it anymore. To implement has_array_elems() correctly(i.e. return true when the array is zero length) would be difficult, because we may need to perform constant folding first. --- gcc/rust/ast/rust-ast-full-test.cc | 5 +---- gcc/rust/ast/rust-expr.h | 9 +-------- gcc/rust/expand/rust-macro-expand.cc | 7 +++---- 3 files changed, 5 insertions(+), 16 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 69d1e6e..f17d269 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -2165,10 +2165,7 @@ ArrayExpr::as_string () const str += append_attributes (inner_attrs, INNER); str += "\n Array elems: "; - if (!has_array_elems ()) - str += "none"; - else - str += internal_elements->as_string (); + str += internal_elements->as_string (); return str; } diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 08dc193..b535f8f 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -1099,9 +1099,6 @@ public: outer_attrs = std::move (new_attrs); } - // Returns whether array expr has array elems or if it is just empty. - bool has_array_elems () const { return internal_elements != nullptr; } - // Constructor requires ArrayElems pointer ArrayExpr (std::unique_ptr array_elems, std::vector inner_attribs, @@ -1119,7 +1116,6 @@ public: inner_attrs (other.inner_attrs), locus (other.locus), marked_for_strip (other.marked_for_strip) { - if (other.has_array_elems ()) internal_elements = other.internal_elements->clone_array_elems (); rust_assert (internal_elements != nullptr); } @@ -1133,10 +1129,7 @@ public: marked_for_strip = other.marked_for_strip; outer_attrs = other.outer_attrs; - if (other.has_array_elems ()) - internal_elements = other.internal_elements->clone_array_elems (); - else - internal_elements = nullptr; + internal_elements = other.internal_elements->clone_array_elems (); rust_assert (internal_elements != nullptr); return *this; diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index b2a0bb5..b60f9b2 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -727,8 +727,7 @@ public: /* assuming you can't strip away the ArrayElems type, but can strip * internal expressions and whatever */ - if (expr.has_array_elems ()) - expr.get_array_elems ()->accept_vis (*this); + expr.get_array_elems ()->accept_vis (*this); } void visit (AST::ArrayIndexExpr &expr) override { @@ -3262,8 +3261,8 @@ MacroExpander::expand_invoc (std::unique_ptr &invoc) // how would errors be signalled? null fragment? something else? // what about error vs just not having stuff in rules definition yet? - /* replace macro invocation with ast frag. actually, don't have any context here. maybe attach ast - * frag to macro invocation, and then have a method above get it? Or just return the ast frag from + /* replace macro invocation with ast frag. actually, don't have any context here. maybe attach ast + * frag to macro invocation, and then have a method above get it? Or just return the ast frag from * this method. */ } #endif -- cgit v1.1