aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-30 12:44:25 +0000
committerGitHub <noreply@github.com>2023-01-30 12:44:25 +0000
commitd7c321da9f8fdee4527285c782db57c7c4d520e4 (patch)
treeba6531ab7ceea6caca1c74cf89cb219a9ce40c84 /gcc/rust/parse/rust-parse-impl.h
parent0ae13efb5a6383a3e7e22ceb064fa358038bd36f (diff)
parent3630e0e2bf0fced043efb23f077adfe9b576dcad (diff)
downloadgcc-d7c321da9f8fdee4527285c782db57c7c4d520e4.zip
gcc-d7c321da9f8fdee4527285c782db57c7c4d520e4.tar.gz
gcc-d7c321da9f8fdee4527285c782db57c7c4d520e4.tar.bz2
Merge #1735
1735: macro: Allow builtin `MacroInvocation`s within the AST r=CohenArthur a=CohenArthur gcc/rust/ChangeLog: * ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention switching on `macro.kind` once builtin macro invocations are properly handled * parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to new MacroInvocation API (Parser::parse_type): Switch to new MacroInvocation API (Parser::parse_type_no_bounds): Switch to new MacroInvocation API This will be necessary for proper handling of builtin macros with the new `EarlyNameResolver` class and associated fixed-point algorithm Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h70
1 files changed, 32 insertions, 38 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index c19fe9b..7e4e794 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1752,10 +1752,9 @@ Parser<ManagedTokenSource>::parse_macro_invocation_semi (
{
// as this is the end, allow recovery (probably) - may change
- return std::unique_ptr<AST::MacroInvocation> (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs), macro_locus,
- true));
+ return AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs),
+ macro_locus, true);
}
}
@@ -1764,9 +1763,9 @@ Parser<ManagedTokenSource>::parse_macro_invocation_semi (
t->get_token_description (),
lexer.peek_token ()->get_token_description ());
- return std::unique_ptr<AST::MacroInvocation> (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs), macro_locus, true));
+ return AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs),
+ macro_locus, true);
}
else
{
@@ -1814,10 +1813,9 @@ Parser<ManagedTokenSource>::parse_macro_invocation (AST::AttrVec outer_attrs)
Location macro_locus = macro_path.get_locus ();
- return std::unique_ptr<AST::MacroInvocation> (
- new AST::MacroInvocation (AST::MacroInvocData (std::move (macro_path),
- std::move (delim_tok_tree)),
- std::move (outer_attrs), macro_locus));
+ return AST::MacroInvocation::Regular (
+ AST::MacroInvocData (std::move (macro_path), std::move (delim_tok_tree)),
+ std::move (outer_attrs), macro_locus);
}
// Parses a macro rule definition - does not parse semicolons.
@@ -9308,11 +9306,10 @@ Parser<ManagedTokenSource>::parse_type (bool save_errors)
AST::DelimTokenTree tok_tree = parse_delim_token_tree ();
- return std::unique_ptr<AST::MacroInvocation> (
- new AST::MacroInvocation (
- AST::MacroInvocData (std::move (macro_path),
- std::move (tok_tree)),
- {}, locus));
+ return AST::MacroInvocation::Regular (
+ AST::MacroInvocData (std::move (macro_path),
+ std::move (tok_tree)),
+ {}, locus);
}
case PLUS: {
// type param bounds
@@ -10146,11 +10143,10 @@ Parser<ManagedTokenSource>::parse_type_no_bounds ()
AST::DelimTokenTree tok_tree = parse_delim_token_tree ();
- return std::unique_ptr<AST::MacroInvocation> (
- new AST::MacroInvocation (
- AST::MacroInvocData (std::move (macro_path),
- std::move (tok_tree)),
- {}, locus));
+ return AST::MacroInvocation::Regular (
+ AST::MacroInvocData (std::move (macro_path),
+ std::move (tok_tree)),
+ {}, locus);
}
default:
// assume that this is a type path and not an error
@@ -12010,18 +12006,17 @@ Parser<ManagedTokenSource>::parse_path_based_stmt_or_expr (
{
lexer.skip_token ();
- std::unique_ptr<AST::MacroInvocation> stmt (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs),
- stmt_or_expr_loc, true));
+ auto stmt
+ = AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs),
+ stmt_or_expr_loc, true);
return ExprOrStmt (std::move (stmt));
}
// otherwise, create macro invocation
- std::unique_ptr<AST::MacroInvocation> expr (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs),
- stmt_or_expr_loc, false));
+ auto expr = AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs),
+ stmt_or_expr_loc, false);
return ExprOrStmt (std::move (expr));
}
else
@@ -12330,17 +12325,16 @@ Parser<ManagedTokenSource>::parse_macro_invocation_maybe_semi (
{
lexer.skip_token ();
- std::unique_ptr<AST::MacroInvocation> stmt (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs), macro_locus,
- true));
+ auto stmt = AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs),
+ macro_locus, true);
return ExprOrStmt (std::move (stmt));
}
// otherwise, create macro invocation
- std::unique_ptr<AST::MacroInvocation> expr (
- new AST::MacroInvocation (std::move (invoc_data),
- std::move (outer_attrs), macro_locus));
+ auto expr
+ = AST::MacroInvocation::Regular (std::move (invoc_data),
+ std::move (outer_attrs), macro_locus);
return ExprOrStmt (std::move (expr));
}
else
@@ -14546,9 +14540,9 @@ Parser<ManagedTokenSource>::parse_macro_invocation_partial (
Location macro_locus = converted_path.get_locus ();
- return std::unique_ptr<AST::MacroInvocation> (new AST::MacroInvocation (
+ return AST::MacroInvocation::Regular (
AST::MacroInvocData (std::move (converted_path), std::move (tok_tree)),
- std::move (outer_attrs), macro_locus, restrictions.expr_can_be_stmt));
+ std::move (outer_attrs), macro_locus, restrictions.expr_can_be_stmt);
}
/* Parses a struct expr struct with a path in expression already parsed (but