aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-16 15:18:41 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-11-21 12:45:32 +0000
commit897532ac166e528f0d9246b2e7744b2e5b859368 (patch)
tree9e0b4aabba2b35797787d412b3ea894f33dd3f04 /gcc/rust/parse
parent0f379bd8c9e5a966b7d1371888bdacf36dd2d531 (diff)
downloadgcc-897532ac166e528f0d9246b2e7744b2e5b859368.zip
gcc-897532ac166e528f0d9246b2e7744b2e5b859368.tar.gz
gcc-897532ac166e528f0d9246b2e7744b2e5b859368.tar.bz2
Replace some weak keyword raw value with constexpr
Raw values may have typos or contain error, replacing those will improve the codebase. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value. * parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise. (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_macro_rules_def): Likewise. (Parser::parse_union): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_stmt): Likewise. (Parser::parse_stmt_or_expr): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 798f375..5a186d9 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1085,7 +1085,7 @@ Parser<ManagedTokenSource>::is_macro_rules_def (const_TokenPtr t)
bool allowed_macro_name = (macro_name == IDENTIFIER || macro_name == TRY);
- return t->get_str () == "macro_rules"
+ return t->get_str () == Values::WeakKeywords::MACRO_RULES
&& lexer.peek_token (1)->get_id () == EXCLAM && allowed_macro_name;
}
@@ -1146,13 +1146,13 @@ Parser<ManagedTokenSource>::parse_item (bool called_from_statement)
// crappy hack to do union "keyword"
case IDENTIFIER:
// TODO: ensure std::string and literal comparison works
- if (t->get_str () == "union"
+ if (t->get_str () == Values::WeakKeywords::UNION
&& lexer.peek_token (1)->get_id () == IDENTIFIER)
{
return parse_vis_item (std::move (outer_attrs));
// or should this go straight to parsing union?
}
- else if (t->get_str () == "default"
+ else if (t->get_str () == Values::WeakKeywords::DEFAULT
&& lexer.peek_token (1)->get_id () != EXCLAM)
{
add_error (Error (t->get_locus (),
@@ -1357,7 +1357,7 @@ Parser<ManagedTokenSource>::parse_vis_item (AST::AttrVec outer_attrs)
// TODO: implement union keyword but not really because of
// context-dependence case UNION: crappy hack to do union "keyword"
case IDENTIFIER:
- if (t->get_str () == "union"
+ if (t->get_str () == Values::WeakKeywords::UNION
&& lexer.peek_token (1)->get_id () == IDENTIFIER)
{
return parse_union (std::move (vis), std::move (outer_attrs));
@@ -1436,7 +1436,8 @@ Parser<ManagedTokenSource>::parse_macro_rules_def (AST::AttrVec outer_attrs)
{
// ensure that first token is identifier saying "macro_rules"
const_TokenPtr t = lexer.peek_token ();
- if (t->get_id () != IDENTIFIER || t->get_str () != "macro_rules")
+ if (t->get_id () != IDENTIFIER
+ || t->get_str () != Values::WeakKeywords::MACRO_RULES)
{
Error error (
t->get_locus (),
@@ -4734,7 +4735,7 @@ Parser<ManagedTokenSource>::parse_union (AST::Visibility vis,
/* hack - "weak keyword" by finding identifier called "union" (lookahead in
* item switch) */
const_TokenPtr union_keyword = expect_token (IDENTIFIER);
- rust_assert (union_keyword->get_str () == "union");
+ rust_assert (union_keyword->get_str () == Values::WeakKeywords::UNION);
location_t locus = union_keyword->get_locus ();
// parse actual union name
@@ -5715,7 +5716,7 @@ Parser<ManagedTokenSource>::parse_trait_impl_item ()
// semi
return parse_macro_invocation_semi (std::move (outer_attrs));
case IDENTIFIER:
- if (lexer.peek_token ()->get_str () == "default")
+ if (lexer.peek_token ()->get_str () == Values::WeakKeywords::DEFAULT)
return parse_trait_impl_function_or_method (visibility,
std::move (outer_attrs));
else
@@ -5779,7 +5780,8 @@ Parser<ManagedTokenSource>::parse_trait_impl_function_or_method (
auto is_default = false;
auto t = lexer.peek_token ();
- if (t->get_id () == IDENTIFIER && t->get_str () == "default")
+ if (t->get_id () == IDENTIFIER
+ && t->get_str () == Values::WeakKeywords::DEFAULT)
{
is_default = true;
lexer.skip_token ();
@@ -6300,7 +6302,7 @@ Parser<ManagedTokenSource>::parse_stmt (ParseRestrictions restrictions)
break;
// crappy hack to do union "keyword"
case IDENTIFIER:
- if (t->get_str () == "union"
+ if (t->get_str () == Values::WeakKeywords::UNION
&& lexer.peek_token (1)->get_id () == IDENTIFIER)
{
return parse_vis_item (std::move (outer_attrs));
@@ -11704,7 +11706,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
// crappy hack to do union "keyword"
case IDENTIFIER:
- if (t->get_str () == "union"
+ if (t->get_str () == Values::WeakKeywords::UNION
&& lexer.peek_token (1)->get_id () == IDENTIFIER)
{
std::unique_ptr<AST::VisItem> item (
@@ -11712,7 +11714,7 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr ()
return ExprOrStmt (std::move (item));
// or should this go straight to parsing union?
}
- else if (t->get_str () == "macro_rules"
+ else if (t->get_str () == Values::WeakKeywords::MACRO_RULES
&& lexer.peek_token (1)->get_id () == EXCLAM)
{
// macro_rules! macro item