diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-12-22 12:17:34 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2020-12-22 19:24:37 +0800 |
commit | 627121b6996146d7b14f2ad848f416682b1ce0fe (patch) | |
tree | a3681b6a59e597860e51cfb742b866c64533efd0 /gcc | |
parent | 30dd20c0098948de74f6a18978e78e2950782975 (diff) | |
download | gcc-627121b6996146d7b14f2ad848f416682b1ce0fe.zip gcc-627121b6996146d7b14f2ad848f416682b1ce0fe.tar.gz gcc-627121b6996146d7b14f2ad848f416682b1ce0fe.tar.bz2 |
Added code to expand cfg! macros
Moved function body to prevent compile issues
Moved around some definitions in rust-ast.h in attempt to prevent compile error
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 30 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 296 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 309 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/compilable/arrays2.rs | 66 |
6 files changed, 446 insertions, 262 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index f0a3990..e6bcdb3 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -4628,8 +4628,8 @@ ModuleBodied::add_crate_name (std::vector<std::string> &names) const void Attribute::parse_attr_to_meta_item () { - // only parse if has attribute input - if (!has_attr_input ()) + // only parse if has attribute input and not already parsed + if (!has_attr_input () || is_parsed_to_meta_item ()) return; std::unique_ptr<AttrInput> converted_input ( @@ -4639,7 +4639,7 @@ Attribute::parse_attr_to_meta_item () attr_input = std::move (converted_input); } -AttrInput * +AttrInputMetaItemContainer * DelimTokenTree::parse_to_meta_item () const { // must have token trees @@ -5391,34 +5391,40 @@ AttrInputMetaItemContainer::separate_cfg_attrs () const } bool -Attribute::check_cfg_predicate (const Session &session) +Attribute::check_cfg_predicate (const Session &session) const { /* assume that cfg predicate actually can exist, i.e. attribute has cfg or * cfg_attr path */ if (!has_attr_input () || (path.as_string () != "cfg" && path.as_string () != "cfg_attr")) return false; - - // TODO: maybe replace with storing a "has been parsed" variable? - parse_attr_to_meta_item (); - // can't be const because of this anyway + + // assume that it has already been parsed + if (!is_parsed_to_meta_item ()) + return false; return attr_input->check_cfg_predicate (session); } std::vector<Attribute> -Attribute::separate_cfg_attrs () +Attribute::separate_cfg_attrs () const { if (!has_attr_input () || path.as_string () != "cfg_attr") return {}; - // TODO: maybe replace with storing a "has been parsed" variable? - parse_attr_to_meta_item (); - // can't be const because of this anyway + // assume that it has already been parsed + if (!is_parsed_to_meta_item ()) + return {}; return attr_input->separate_cfg_attrs (); } +bool +Attribute::is_parsed_to_meta_item () const +{ + return has_attr_input () && attr_input->is_meta_item (); +} + /* Visitor implementations - these are short but inlining can't happen anyway * due to virtual functions and I didn't want to make the ast header includes * any longer than they already are. */ diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 58bc372..8ca89fa 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -362,6 +362,11 @@ public: } }; +// path-to-string inverse comparison operator +inline bool operator!= (const SimplePath& lhs, const std::string &rhs) { + return !(lhs == rhs); +} + // forward decl for Attribute class AttrInput; @@ -392,27 +397,9 @@ public: // default destructor ~Attribute () = default; - // Copy constructor must deep copy attr_input as unique pointer - /*Attribute (Attribute const &other) : path (other.path), locus (other.locus) - { - // guard to protect from null pointer dereference - if (other.attr_input != nullptr) - attr_input = other.attr_input->clone_attr_input (); - }*/ // no point in being defined inline as requires virtual call anyway Attribute (const Attribute &other); - // overload assignment operator to use custom clone method - /*Attribute &operator= (Attribute const &other) - { - path = other.path; - locus = other.locus; - // guard to protect from null pointer dereference - if (other.attr_input != nullptr) - attr_input = other.attr_input->clone_attr_input (); - - return *this; - }*/ // no point in being defined inline as requires virtual call anyway Attribute &operator= (const Attribute &other); @@ -489,7 +476,7 @@ public: std::string as_string () const; - // TODO: does this require visitor pattern as not polymorphic? + // no visitor pattern as not currently polymorphic const SimplePath &get_path () const { return path; } SimplePath &get_path () { return path; } @@ -498,10 +485,15 @@ public: void parse_attr_to_meta_item (); /* Determines whether cfg predicate is true and item with attribute should not - * be stripped. */ - bool check_cfg_predicate (const Session &session); + * be stripped. Attribute body must already be parsed to meta item. */ + bool check_cfg_predicate (const Session &session) const; + + // Returns whether body has been parsed to meta item form or not. + bool is_parsed_to_meta_item () const; - std::vector<Attribute> separate_cfg_attrs (); + /* Returns any attributes generated from cfg_attr attributes. Attribute body + * must already be parsed to meta item. */ + std::vector<Attribute> separate_cfg_attrs () const; protected: // not virtual as currently no subclasses of Attribute, but could be in future @@ -534,99 +526,14 @@ public: virtual std::vector<Attribute> separate_cfg_attrs () const { return {}; } + // Returns whether attr input has been parsed to meta item syntax. + virtual bool is_meta_item () const = 0; + protected: // pure virtual clone implementation virtual AttrInput *clone_attr_input_impl () const = 0; }; -// A token tree with delimiters -class DelimTokenTree : public TokenTree, public AttrInput -{ - DelimType delim_type; - std::vector<std::unique_ptr<TokenTree> > token_trees; - Location locus; - -protected: - DelimTokenTree *clone_delim_tok_tree_impl () const - { - return new DelimTokenTree (*this); - } - - /* Use covariance to implement clone function as returning a DelimTokenTree - * object */ - DelimTokenTree *clone_attr_input_impl () const override - { - return clone_delim_tok_tree_impl (); - } - - /* Use covariance to implement clone function as returning a DelimTokenTree - * object */ - DelimTokenTree *clone_token_tree_impl () const override - { - return clone_delim_tok_tree_impl (); - } - -public: - DelimTokenTree (DelimType delim_type, - std::vector<std::unique_ptr<TokenTree> > token_trees - = std::vector<std::unique_ptr<TokenTree> > (), - Location locus = Location ()) - : delim_type (delim_type), token_trees (std::move (token_trees)), - locus (locus) - {} - - // Copy constructor with vector clone - DelimTokenTree (DelimTokenTree const &other) - : delim_type (other.delim_type), locus (other.locus) - { - token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - token_trees.push_back (e->clone_token_tree ()); - } - - // overloaded assignment operator with vector clone - DelimTokenTree &operator= (DelimTokenTree const &other) - { - delim_type = other.delim_type; - locus = other.locus; - - token_trees.reserve (other.token_trees.size ()); - for (const auto &e : other.token_trees) - token_trees.push_back (e->clone_token_tree ()); - - return *this; - } - - // move constructors - DelimTokenTree (DelimTokenTree &&other) = default; - DelimTokenTree &operator= (DelimTokenTree &&other) = default; - - static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); } - - std::string as_string () const override; - - void accept_vis (ASTVisitor &vis) override; - - bool check_cfg_predicate (const Session &) const override - { - // this should never be called - should be converted first - return false; - } - - AttrInput *parse_to_meta_item () const override; - - std::vector<std::unique_ptr<Token> > to_token_stream () const override; - - std::unique_ptr<DelimTokenTree> clone_delim_token_tree () const - { - return std::unique_ptr<DelimTokenTree> (clone_delim_tok_tree_impl ()); - } -}; - -/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to - * be defined */ -class AttrInputLiteral; - // Forward decl - defined in rust-macro.h class MetaNameValueStr; @@ -679,7 +586,26 @@ public: : items (std::move (items)) {} - // no destructor definition required + // copy constructor with vector clone + AttrInputMetaItemContainer (const AttrInputMetaItemContainer &other) + { + items.reserve (other.items.size ()); + for (const auto &e : other.items) + items.push_back (e->clone_meta_item_inner ()); + } + + // copy assignment operator with vector clone + AttrInputMetaItemContainer & + operator= (const AttrInputMetaItemContainer &other) + { + AttrInput::operator= (other); + + items.reserve (other.items.size ()); + for (const auto &e : other.items) + items.push_back (e->clone_meta_item_inner ()); + + return *this; + } // default move constructors AttrInputMetaItemContainer (AttrInputMetaItemContainer &&other) = default; @@ -702,6 +628,12 @@ public: std::vector<Attribute> separate_cfg_attrs () const override; + bool is_meta_item () const override { return true; } + + // TODO: this mutable getter seems dodgy + std::vector<std::unique_ptr<MetaItemInner> > &get_items () { return items; } + const std::vector<std::unique_ptr<MetaItemInner> > &get_items () const { return items; } + protected: // Use covariance to implement clone function as returning this type AttrInputMetaItemContainer *clone_attr_input_impl () const override @@ -713,29 +645,98 @@ protected: { return new AttrInputMetaItemContainer (*this); } +}; - // copy constructor with vector clone - AttrInputMetaItemContainer (const AttrInputMetaItemContainer &other) +// A token tree with delimiters +class DelimTokenTree : public TokenTree, public AttrInput +{ + DelimType delim_type; + std::vector<std::unique_ptr<TokenTree> > token_trees; + Location locus; + +protected: + DelimTokenTree *clone_delim_tok_tree_impl () const { - items.reserve (other.items.size ()); - for (const auto &e : other.items) - items.push_back (e->clone_meta_item_inner ()); + return new DelimTokenTree (*this); } - // copy assignment operator with vector clone - AttrInputMetaItemContainer & - operator= (const AttrInputMetaItemContainer &other) + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_attr_input_impl () const override { - AttrInput::operator= (other); + return clone_delim_tok_tree_impl (); + } - items.reserve (other.items.size ()); - for (const auto &e : other.items) - items.push_back (e->clone_meta_item_inner ()); + /* Use covariance to implement clone function as returning a DelimTokenTree + * object */ + DelimTokenTree *clone_token_tree_impl () const override + { + return clone_delim_tok_tree_impl (); + } + +public: + DelimTokenTree (DelimType delim_type, + std::vector<std::unique_ptr<TokenTree> > token_trees + = std::vector<std::unique_ptr<TokenTree> > (), + Location locus = Location ()) + : delim_type (delim_type), token_trees (std::move (token_trees)), + locus (locus) + {} + + // Copy constructor with vector clone + DelimTokenTree (DelimTokenTree const &other) + : delim_type (other.delim_type), locus (other.locus) + { + token_trees.reserve (other.token_trees.size ()); + for (const auto &e : other.token_trees) + token_trees.push_back (e->clone_token_tree ()); + } + + // overloaded assignment operator with vector clone + DelimTokenTree &operator= (DelimTokenTree const &other) + { + delim_type = other.delim_type; + locus = other.locus; + + token_trees.reserve (other.token_trees.size ()); + for (const auto &e : other.token_trees) + token_trees.push_back (e->clone_token_tree ()); return *this; } + + // move constructors + DelimTokenTree (DelimTokenTree &&other) = default; + DelimTokenTree &operator= (DelimTokenTree &&other) = default; + + static DelimTokenTree create_empty () { return DelimTokenTree (PARENS); } + + std::string as_string () const override; + + void accept_vis (ASTVisitor &vis) override; + + bool check_cfg_predicate (const Session &) const override + { + // this should never be called - should be converted first + return false; + } + + AttrInputMetaItemContainer *parse_to_meta_item () const override; + + std::vector<std::unique_ptr<Token> > to_token_stream () const override; + + std::unique_ptr<DelimTokenTree> clone_delim_token_tree () const + { + return std::unique_ptr<DelimTokenTree> (clone_delim_tok_tree_impl ()); + } + + bool is_meta_item () const override { return false; } }; +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to + * be defined */ +class AttrInputLiteral; + // abstract base meta item class class MetaItem : public MetaItemInner { @@ -1378,15 +1379,64 @@ private: SimplePath path; DelimTokenTree token_tree; + // One way of parsing the macro. Probably not applicable for all macros. + std::vector<std::unique_ptr<MetaItemInner> > parsed_items; + bool parsed_to_meta_item = false; + public: std::string as_string () const; MacroInvocData (SimplePath path, DelimTokenTree token_tree) : path (std::move (path)), token_tree (std::move (token_tree)) {} + // Copy constructor with vector clone + MacroInvocData (const MacroInvocData &other) : path (other.path), token_tree (other.token_tree), parsed_to_meta_item (other.parsed_to_meta_item) { + parsed_items.reserve (other.parsed_items.size ()); + for (const auto &e : other.parsed_items) + parsed_items.push_back (e->clone_meta_item_inner ()); + } + + // Copy assignment operator with vector clone + MacroInvocData &operator= (const MacroInvocData &other) + { + path = other.path; + token_tree = other.token_tree; + parsed_to_meta_item = other.parsed_to_meta_item; + + parsed_items.reserve (other.parsed_items.size ()); + for (const auto &e : other.parsed_items) + parsed_items.push_back (e->clone_meta_item_inner ()); + + return *this; + } + + // Move constructors + MacroInvocData (MacroInvocData &&other) = default; + MacroInvocData &operator= (MacroInvocData &&other) = default; + // Invalid if path is empty, so base stripping on that. void mark_for_strip () { path = SimplePath::create_empty (); } bool is_marked_for_strip () const { return path.is_empty (); } + + // Returns whether the macro has been parsed already. + bool is_parsed () const { return parsed_to_meta_item; } + // TODO: update on other ways of parsing it + + // TODO: this mutable getter seems kinda dodgy + DelimTokenTree &get_delim_tok_tree () { return token_tree; } + const DelimTokenTree &get_delim_tok_tree () const { return token_tree; } + + // TODO: this mutable getter seems kinda dodgy + SimplePath &get_path () { return path; } + const SimplePath &get_path () const { return path; } + + void set_meta_item_output (std::vector<std::unique_ptr<MetaItemInner> > new_items) + { + parsed_items = std::move (new_items); + } + // TODO: mutable getter seems kinda dodgy + std::vector<std::unique_ptr<MetaItemInner> > &get_meta_items () { return parsed_items; } + const std::vector<std::unique_ptr<MetaItemInner> > &get_meta_items () const { return parsed_items; } }; /* A macro invocation item (or statement) AST node (i.e. semi-coloned macro diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index de011c1..89718bc 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -121,6 +121,8 @@ public: * cfg */ bool check_cfg_predicate (const Session &) const override { return false; } + bool is_meta_item () const override { return false; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 53b2851..97e455e 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -22,7 +22,7 @@ public: auto &field_attrs = field.get_outer_attrs (); expander.expand_cfg_attrs (field_attrs); - if (expander.fails_cfg (field_attrs)) + if (expander.fails_cfg_with_expand (field_attrs)) { it = fields.erase (it); continue; @@ -39,14 +39,14 @@ public: ++it; } - #if 0 +#if 0 for (int i = 0; i < fields.size ();) { auto &field = fields[i]; auto &field_attrs = field.get_outer_attrs (); expander.expand_cfg_attrs (field_attrs); - if (expander.fails_cfg (field_attrs)) + if (expander.fails_cfg_with_expand (field_attrs)) { fields.erase (fields.begin () + i); continue; @@ -62,7 +62,7 @@ public: // if nothing else happens, increment i++; } - #endif +#endif } void expand_tuple_fields (std::vector<AST::TupleField> &fields) @@ -73,7 +73,7 @@ public: auto &field_attrs = field.get_outer_attrs (); expander.expand_cfg_attrs (field_attrs); - if (expander.fails_cfg (field_attrs)) + if (expander.fails_cfg_with_expand (field_attrs)) { it = fields.erase (it); continue; @@ -90,14 +90,14 @@ public: ++it; } - #if 0 +#if 0 for (int i = 0; i < fields.size ();) { auto &field = fields[i]; auto &field_attrs = field.get_outer_attrs (); expander.expand_cfg_attrs (field_attrs); - if (expander.fails_cfg (field_attrs)) + if (expander.fails_cfg_with_expand (field_attrs)) { fields.erase (fields.begin () + i); continue; @@ -113,7 +113,7 @@ public: // if nothing else happens, increment i++; } - #endif +#endif } void expand_function_params (std::vector<AST::FunctionParam> ¶ms) @@ -124,7 +124,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { it = params.erase (it); continue; @@ -147,14 +147,14 @@ public: ++it; } - #if 0 +#if 0 for (int i = 0; i < params.size ();) { auto ¶m = params[i]; auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { params.erase (params.begin () + i); continue; @@ -176,7 +176,7 @@ public: // increment i++; } - #endif +#endif } void expand_generic_args (AST::GenericArgs &args) @@ -229,7 +229,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { it = params.erase (it); continue; @@ -254,14 +254,14 @@ public: ++it; } - #if 0 +#if 0 for (int i = 0; i < params.size ();) { auto ¶m = params[i]; auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { params.erase (params.begin () + i); continue; @@ -285,7 +285,7 @@ public: // increment if found nothing else so far i++; } - #endif +#endif } void expand_self_param (AST::SelfParam &self_param) @@ -359,9 +359,8 @@ public: if (decl.has_where_clause ()) expand_where_clause (decl.get_where_clause ()); } - - template <typename T> - void expand_pointer_allow_strip (T &values) + + template <typename T> void expand_pointer_allow_strip (T &values) { for (auto it = values.begin (); it != values.end ();) { @@ -393,7 +392,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (ident_expr.get_outer_attrs ()); - if (expander.fails_cfg (ident_expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (ident_expr.get_outer_attrs ())) { ident_expr.mark_for_strip (); return; @@ -411,7 +410,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ()); - if (expander.fails_cfg (macro_invoc.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ())) { macro_invoc.mark_for_strip (); return; @@ -428,7 +427,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (path.get_outer_attrs ()); - if (expander.fails_cfg (path.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (path.get_outer_attrs ())) { path.mark_for_strip (); return; @@ -484,7 +483,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (path.get_outer_attrs ()); - if (expander.fails_cfg (path.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (path.get_outer_attrs ())) { path.mark_for_strip (); return; @@ -511,7 +510,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -533,7 +532,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -553,7 +552,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -573,7 +572,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -593,7 +592,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -751,7 +750,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -760,7 +759,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -824,7 +823,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -833,7 +832,7 @@ public: /* strip test based on inner attrs - spec says there are separate * inner attributes, not just outer attributes of inner exprs */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -851,7 +850,7 @@ public: * having expansion code anyway. TODO */ // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -881,7 +880,7 @@ public: // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -890,7 +889,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -920,7 +919,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -940,7 +939,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -949,7 +948,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -992,7 +991,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1001,7 +1000,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -1040,7 +1039,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1049,7 +1048,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -1076,7 +1075,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1085,7 +1084,7 @@ public: /* strip test based on inner attrs - spec says these are inner * attributes, not outer attributes of inner expr */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -1122,7 +1121,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1165,7 +1164,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1194,7 +1193,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1244,7 +1243,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1284,7 +1283,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1328,7 +1327,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1348,7 +1347,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1370,7 +1369,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1379,7 +1378,7 @@ public: /* strip test based on inner attrs - spec says there are inner * attributes, not just outer attributes of inner stmts */ expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -1419,7 +1418,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1448,7 +1447,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1458,7 +1457,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1581,7 +1580,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1611,7 +1610,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1629,7 +1628,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1647,7 +1646,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1673,7 +1672,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1707,7 +1706,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1740,7 +1739,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1766,7 +1765,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1800,7 +1799,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1834,7 +1833,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1869,7 +1868,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1903,7 +1902,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1945,7 +1944,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -1987,7 +1986,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -2030,7 +2029,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -2038,7 +2037,7 @@ public: // inner attr strip test expander.expand_cfg_attrs (expr.get_inner_attrs ()); - if (expander.fails_cfg (expr.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_inner_attrs ())) { expr.mark_for_strip (); return; @@ -2061,7 +2060,7 @@ public: // strip match case based on outer attributes in match arm auto &match_arm = match_case.get_arm (); expander.expand_cfg_attrs (match_arm.get_outer_attrs ()); - if (expander.fails_cfg (match_arm.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (match_arm.get_outer_attrs ())) { // strip match case it = match_cases.erase (it); @@ -2110,7 +2109,7 @@ public: // strip match case based on outer attributes in match arm auto &match_arm = match_case.get_arm (); expander.expand_cfg_attrs (match_arm.get_outer_attrs ()); - if (expander.fails_cfg (match_arm.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (match_arm.get_outer_attrs ())) { // strip match case match_cases.erase (match_cases.begin () + i); @@ -2156,7 +2155,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -2175,7 +2174,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (expr.get_outer_attrs ()); - if (expander.fails_cfg (expr.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (expr.get_outer_attrs ())) { expr.mark_for_strip (); return; @@ -2232,7 +2231,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (method.get_outer_attrs ()); - if (expander.fails_cfg (method.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (method.get_outer_attrs ())) { method.mark_for_strip (); return; @@ -2277,7 +2276,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (module.get_outer_attrs ()); - if (expander.fails_cfg (module.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (module.get_outer_attrs ())) { module.mark_for_strip (); return; @@ -2285,7 +2284,7 @@ public: // strip test based on inner attrs expander.expand_cfg_attrs (module.get_inner_attrs ()); - if (expander.fails_cfg (module.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (module.get_inner_attrs ())) { module.mark_for_strip (); return; @@ -2314,7 +2313,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (module.get_outer_attrs ()); - if (expander.fails_cfg (module.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (module.get_outer_attrs ())) { module.mark_for_strip (); return; @@ -2324,7 +2323,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (crate.get_outer_attrs ()); - if (expander.fails_cfg (crate.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (crate.get_outer_attrs ())) { crate.mark_for_strip (); return; @@ -2346,7 +2345,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (use_decl.get_outer_attrs ()); - if (expander.fails_cfg (use_decl.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (use_decl.get_outer_attrs ())) { use_decl.mark_for_strip (); return; @@ -2356,7 +2355,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (function.get_outer_attrs ()); - if (expander.fails_cfg (function.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (function.get_outer_attrs ())) { function.mark_for_strip (); return; @@ -2396,7 +2395,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (type_alias.get_outer_attrs ()); - if (expander.fails_cfg (type_alias.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (type_alias.get_outer_attrs ())) { type_alias.mark_for_strip (); return; @@ -2419,7 +2418,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (struct_item.get_outer_attrs ()); - if (expander.fails_cfg (struct_item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (struct_item.get_outer_attrs ())) { struct_item.mark_for_strip (); return; @@ -2440,7 +2439,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (tuple_struct.get_outer_attrs ()); - if (expander.fails_cfg (tuple_struct.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (tuple_struct.get_outer_attrs ())) { tuple_struct.mark_for_strip (); return; @@ -2461,7 +2460,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2471,7 +2470,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2485,7 +2484,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2499,7 +2498,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2519,7 +2518,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (enum_item.get_outer_attrs ()); - if (expander.fails_cfg (enum_item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (enum_item.get_outer_attrs ())) { enum_item.mark_for_strip (); return; @@ -2556,7 +2555,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (union_item.get_outer_attrs ()); - if (expander.fails_cfg (union_item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (union_item.get_outer_attrs ())) { union_item.mark_for_strip (); return; @@ -2577,7 +2576,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (const_item.get_outer_attrs ()); - if (expander.fails_cfg (const_item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (const_item.get_outer_attrs ())) { const_item.mark_for_strip (); return; @@ -2604,7 +2603,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (static_item.get_outer_attrs ()); - if (expander.fails_cfg (static_item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (static_item.get_outer_attrs ())) { static_item.mark_for_strip (); return; @@ -2631,7 +2630,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2656,7 +2655,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2681,7 +2680,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2711,7 +2710,7 @@ public: { // initial test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2728,7 +2727,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (trait.get_outer_attrs ()); - if (expander.fails_cfg (trait.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (trait.get_outer_attrs ())) { trait.mark_for_strip (); return; @@ -2736,7 +2735,7 @@ public: // strip test based on inner attrs expander.expand_cfg_attrs (trait.get_inner_attrs ()); - if (expander.fails_cfg (trait.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (trait.get_inner_attrs ())) { trait.mark_for_strip (); return; @@ -2779,7 +2778,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (impl.get_outer_attrs ()); - if (expander.fails_cfg (impl.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (impl.get_outer_attrs ())) { impl.mark_for_strip (); return; @@ -2787,7 +2786,7 @@ public: // strip test based on inner attrs expander.expand_cfg_attrs (impl.get_inner_attrs ()); - if (expander.fails_cfg (impl.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (impl.get_inner_attrs ())) { impl.mark_for_strip (); return; @@ -2829,7 +2828,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (impl.get_outer_attrs ()); - if (expander.fails_cfg (impl.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (impl.get_outer_attrs ())) { impl.mark_for_strip (); return; @@ -2837,7 +2836,7 @@ public: // strip test based on inner attrs expander.expand_cfg_attrs (impl.get_inner_attrs ()); - if (expander.fails_cfg (impl.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (impl.get_inner_attrs ())) { impl.mark_for_strip (); return; @@ -2885,7 +2884,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2901,7 +2900,7 @@ public: { // strip test based on outer attrs expander.expand_cfg_attrs (item.get_outer_attrs ()); - if (expander.fails_cfg (item.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (item.get_outer_attrs ())) { item.mark_for_strip (); return; @@ -2920,7 +2919,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { it = params.erase (it); continue; @@ -2942,7 +2941,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { params.erase (params.begin () + i); continue; @@ -2981,7 +2980,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (block.get_outer_attrs ()); - if (expander.fails_cfg (block.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (block.get_outer_attrs ())) { block.mark_for_strip (); return; @@ -2989,7 +2988,7 @@ public: // strip test based on inner attrs expander.expand_cfg_attrs (block.get_inner_attrs ()); - if (expander.fails_cfg (block.get_inner_attrs ())) + if (expander.fails_cfg_with_expand (block.get_inner_attrs ())) { block.mark_for_strip (); return; @@ -3023,7 +3022,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (rules_def.get_outer_attrs ()); - if (expander.fails_cfg (rules_def.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (rules_def.get_outer_attrs ())) { rules_def.mark_for_strip (); return; @@ -3035,7 +3034,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ()); - if (expander.fails_cfg (macro_invoc.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ())) { macro_invoc.mark_for_strip (); return; @@ -3110,7 +3109,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (field.get_outer_attrs ()); - if (expander.fails_cfg (field.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (field.get_outer_attrs ())) { field.mark_for_strip (); return; @@ -3127,7 +3126,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (field.get_outer_attrs ()); - if (expander.fails_cfg (field.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (field.get_outer_attrs ())) { field.mark_for_strip (); return; @@ -3144,7 +3143,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (field.get_outer_attrs ()); - if (expander.fails_cfg (field.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (field.get_outer_attrs ())) { field.mark_for_strip (); return; @@ -3187,7 +3186,7 @@ public: if (elems.has_etc ()) { expander.expand_cfg_attrs (elems.get_etc_outer_attrs ()); - if (expander.fails_cfg (elems.get_etc_outer_attrs ())) + if (expander.fails_cfg_with_expand (elems.get_etc_outer_attrs ())) elems.strip_etc (); } } @@ -3310,7 +3309,7 @@ public: { // initial strip test based on outer attrs expander.expand_cfg_attrs (stmt.get_outer_attrs ()); - if (expander.fails_cfg (stmt.get_outer_attrs ())) + if (expander.fails_cfg_with_expand (stmt.get_outer_attrs ())) { stmt.mark_for_strip (); return; @@ -3498,7 +3497,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { it = params.erase (it); continue; @@ -3520,7 +3519,7 @@ public: auto ¶m_attrs = param.get_outer_attrs (); expander.expand_cfg_attrs (param_attrs); - if (expander.fails_cfg (param_attrs)) + if (expander.fails_cfg_with_expand (param_attrs)) { params.erase (params.begin () + i); continue; @@ -3553,10 +3552,46 @@ public: } }; -AST::Literal +void +MacroExpander::parse_macro_to_meta_item (AST::MacroInvocData &invoc) +{ + // only parse if not already parsed + if (invoc.is_parsed ()) + return; + + std::unique_ptr<AST::AttrInputMetaItemContainer> converted_input ( + invoc.get_delim_tok_tree ().parse_to_meta_item ()); + + if (converted_input == nullptr) + { + fprintf (stderr, "DEBUG: failed to parse macro to meta item\n"); + // TODO: do something now? is this an actual error? + } + else + { + std::vector<std::unique_ptr<AST::MetaItemInner> > meta_items (std::move (converted_input->get_items ())); + invoc.set_meta_item_output (std::move (meta_items)); + } +} + +AST::Literal MacroExpander::expand_cfg_macro (AST::MacroInvocData &invoc) { - return AST::Literal::create_error (); + // only allow on cfg macros + if (invoc.get_path () != "cfg") + return AST::Literal::create_error (); + + parse_macro_to_meta_item (invoc); + + // TODO: assuming that cfg! macros can only have one meta item inner, like cfg attributes + if (invoc.get_meta_items ().size () != 1) + return AST::Literal::create_error (); + + bool result = invoc.get_meta_items ()[0]->check_cfg_predicate (session); + if (result) + return AST::Literal ("true", AST::Literal::BOOL); + else + return AST::Literal ("false", AST::Literal::BOOL); } void @@ -3580,7 +3615,7 @@ MacroExpander::expand_invoc (std::unique_ptr<AST::MacroInvocation> &invoc) - derive or legacy derive - "token-based" vs "AST-based" - else is unreachable - derive container macro - unreachable*/ - + #if 0 // macro_rules macro test code auto rule_def = find_rules_def(invoc->get_path()); @@ -3602,11 +3637,11 @@ MacroExpander::expand_invoc (std::unique_ptr<AST::MacroInvocation> &invoc) } /* Determines whether any cfg predicate is false and hence item with attributes - * should be stripped. */ + * should be stripped. Note that attributes must be expanded before calling. */ bool -MacroExpander::fails_cfg (std::vector<AST::Attribute> &attrs) +MacroExpander::fails_cfg (const std::vector<AST::Attribute> &attrs) const { - for (auto &attr : attrs) + for (const auto &attr : attrs) { if (attr.get_path () == "cfg" && !attr.check_cfg_predicate (session)) return true; @@ -3614,6 +3649,25 @@ MacroExpander::fails_cfg (std::vector<AST::Attribute> &attrs) return false; } +/* Determines whether any cfg predicate is false and hence item with attributes + * should be stripped. Will expand attributes as well. */ +bool +MacroExpander::fails_cfg_with_expand (std::vector<AST::Attribute> &attrs) const +{ + for (auto &attr : attrs) + { + if (attr.get_path () == "cfg") + { + if (!attr.is_parsed_to_meta_item ()) + attr.parse_attr_to_meta_item (); + + if (!attr.check_cfg_predicate (session)) + return true; + } + } + return false; +} + // Expands cfg_attr attributes. void MacroExpander::expand_cfg_attrs (std::vector<AST::Attribute> &attrs) @@ -3623,6 +3677,9 @@ MacroExpander::expand_cfg_attrs (std::vector<AST::Attribute> &attrs) auto &attr = attrs[i]; if (attr.get_path () == "cfg_attr") { + if (!attr.is_parsed_to_meta_item ()) + attr.parse_attr_to_meta_item (); + if (attr.check_cfg_predicate (session)) { // split off cfg_attr @@ -3665,7 +3722,7 @@ MacroExpander::expand_crate () // expand crate cfg_attr attributes expand_cfg_attrs (crate.inner_attrs); - if (fails_cfg (crate.inner_attrs)) + if (fails_cfg_with_expand (crate.inner_attrs)) { // basically, delete whole crate crate.strip_crate (); diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 6752090..0218600 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -42,9 +42,12 @@ struct MacroExpander void expand_invoc (std::unique_ptr<AST::MacroInvocation> &invoc); void expand_cfg_attrs (std::vector<AST::Attribute> &attrs); - bool fails_cfg (std::vector<AST::Attribute> &attr); + bool fails_cfg (const std::vector<AST::Attribute> &attr) const; + bool fails_cfg_with_expand (std::vector<AST::Attribute> &attrs) const; // Expand the data of a cfg! macro. + void parse_macro_to_meta_item (AST::MacroInvocData &invoc); + // Get the literal representation of a cfg! macro. AST::Literal expand_cfg_macro (AST::MacroInvocData &invoc); private: diff --git a/gcc/testsuite/rust.test/compilable/arrays2.rs b/gcc/testsuite/rust.test/compilable/arrays2.rs new file mode 100644 index 0000000..974e346 --- /dev/null +++ b/gcc/testsuite/rust.test/compilable/arrays2.rs @@ -0,0 +1,66 @@ +fn main() { + // const, inferred array + let const_inferred_array = [0, 1, 2, 3]; + // const, inferred, copied array + let const_inferred_copied_array = [0; 4]; + + // const index of const, inferred array + let const_inferred_index = const_inferred_array[1]; + // variable index of const, inferred array + let some_var = 3; + let const_inferred_index_var = const_inferred_array[some_var]; + + // const index of const, inferred, copied array + let const_inferred_copied_index = const_inferred_copied_array[1]; + // variable index of const, inferred array + let const_inferred_copied_index_var = const_inferred_copied_array[some_var]; + + // mut, inferred array + let mut mut_inferred_array = [0, 1, 2, 3]; + // mut, inferred, copied array + let mut mut_inferred_copied_array = [0; 6]; + + // const index of mut, inferred array + let mut_inferred_index = mut_inferred_array[1]; + // variable index of mut, inferred array + let mut_inferred_index_var = mut_inferred_array[some_var]; + + // const index of mut, inferred, copied array + let mut_inferred_copied_index = mut_inferred_copied_array[1]; + // variable index of mut, inferred array + let mut_inferred_copied_index_var = mut_inferred_copied_array[some_var]; + + // const, typed array + let const_typed_array: [i32; 5] = [0, 1, 2, 3, 4]; + // const, typed, copied array + let const_typed_copied_array: [i32; 4] = [2; 4]; + + // const index of const, typed array + let const_typed_index = const_typed_array[1]; + // variable index of const, typed array + let const_typed_index_var = const_typed_array[some_var]; + + // const index of const, typed, copied array + let const_typed_copied_index = const_typed_copied_array[1]; + // variable index of const, typed array + let const_typed_copied_index_var = const_typed_copied_array[some_var]; + + // mut, typed array + let mut mut_typed_array: [i32; 4] = [0, 1, 2, 3]; + // mut, typed, copied array + let mut mut_typed_copied_array: [i32; 4] = [0; 4]; + + // const index of mut, typed array + let mut_typed_index = mut_typed_array[1]; + // variable index of mut, typed array + let mut_typed_index_var = mut_typed_array[some_var]; + + // const index of mut, typed, copied array + let mut_typed_copied_index = mut_typed_copied_array[1]; + // variable index of mut, typed array + let mut_typed_copied_index_var = mut_typed_copied_array[some_var]; + + + // index + 1 expression + let some_thing = mut_inferred_copied_array[some_var + 1]; +}
\ No newline at end of file |