diff options
author | Yizhe <yizhe@pku.edu.cn> | 2021-03-17 02:06:21 +0000 |
---|---|---|
committer | YizhePKU <yizhe@pku.edu.cn> | 2021-04-02 17:10:43 +0000 |
commit | d71750b7829b3ef3443c75880e439e3e145aa8a7 (patch) | |
tree | f685de849e35a359d6f5010876c56bc311a893f2 /gcc/rust | |
parent | 0a63f6d619aba46abeafe9c7544756fee00e072d (diff) | |
download | gcc-d71750b7829b3ef3443c75880e439e3e145aa8a7.zip gcc-d71750b7829b3ef3443c75880e439e3e145aa8a7.tar.gz gcc-d71750b7829b3ef3443c75880e439e3e145aa8a7.tar.bz2 |
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.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 5 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 9 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 7 |
3 files changed, 5 insertions, 16 deletions
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<ArrayElems> array_elems, std::vector<Attribute> 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<AST::MacroInvocation> &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 |