diff options
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 6 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 19 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 8 |
4 files changed, 34 insertions, 5 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index d23cb81..1ad0cf9 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -473,9 +473,9 @@ public: std::string as_string () const; // TODO: does this require visitor pattern as not polymorphic? - - // Maybe change to const-reference in future - SimplePath get_path () const { return path; } + + const SimplePath &get_path () const { return path; } + SimplePath &get_path () { return path; } // Call to parse attribute body to meta item syntax. void parse_attr_to_meta_item (); diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 5760392..2cae0f9 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -318,6 +318,9 @@ public: std::vector<Attribute> &get_outer_attrs () { return outer_attrs; } const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; } + std::vector<MacroRule> &get_macro_rules () { return rules; } + const std::vector<MacroRule> &get_macro_rules () const { return rules; } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -355,6 +358,9 @@ public: void mark_for_strip () override { path = SimplePath::create_empty (); } bool is_marked_for_strip () const override { return path.is_empty (); } + const SimplePath &get_path () const { return path; } + SimplePath &get_path () { return path; } + 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 82941c7..4f28836 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -3291,6 +3291,25 @@ 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()); + if (rule_def != nullptr) { + ASTFrag expanded = expand_decl_macro(invoc, rule_def); + /* could make this a data structure containing vectors of exprs, patterns and types (for regular), + * and then stmts and items (for semi). Except what about having an expr, then a type? Hmm. Might + * have to do the "unified base type" thing OR just have a simulated union, and then have AST frag + * be a vector of these simulated unions. */ + + // 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 + * this method. */ + } +#endif } /* Determines whether any cfg predicate is false and hence item with attributes diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3315da3..bade40c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8431,6 +8431,8 @@ Parser<ManagedTokenSource>::parse_array_expr ( return nullptr; } + skip_token (RIGHT_SQUARE); + std::unique_ptr<AST::ArrayElemsCopied> copied_array_elems ( new AST::ArrayElemsCopied (std::move (initial_expr), std::move (copy_amount))); @@ -8447,6 +8449,8 @@ Parser<ManagedTokenSource>::parse_array_expr ( exprs.push_back (std::move (initial_expr)); exprs.shrink_to_fit (); + skip_token (RIGHT_SQUARE); + std::unique_ptr<AST::ArrayElemsValues> array_elems ( new AST::ArrayElemsValues (std::move (exprs))); return std::unique_ptr<AST::ArrayExpr> ( @@ -13709,8 +13713,8 @@ Parser<ManagedTokenSource>::parse_field_access_expr ( std::vector<AST::Attribute> outer_attrs, ParseRestrictions restrictions ATTRIBUTE_UNUSED) { - // get field name identifier (assume that this is a field access expr and not - // say await) + /* get field name identifier (assume that this is a field access expr and not + * await, for instance) */ const_TokenPtr ident_tok = expect_token (IDENTIFIER); Identifier ident = ident_tok->get_str (); |