Skip to content

Commit

Permalink
Replace TOK suffix with KW
Browse files Browse the repository at this point in the history
TOK suffix was chosen to disambiguate some identifiers with c++ reserved
keyword. Even though this list lies within the rust-token header, this
macro is used in many context sometimes unrelated with the lexer and
tokens. This TOK suffix may appear surprising in such context.

gcc/rust/ChangeLog:

	* lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from
	tok to kw.
	* ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to
	match the new declaration.
	* lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise.
	* parse/rust-parse-impl.h (can_tok_start_type): Likewise.
	(Parser::parse_item): Likewise.
	(Parser::parse_vis_item): Likewise.
	(Parser::parse_extern_crate): Likewise.
	(Parser::parse_function): Likewise.
	(Parser::parse_function_qualifiers): Likewise.
	(Parser::parse_struct): Likewise.
	(Parser::parse_enum): Likewise.
	(Parser::parse_static_item): Likewise.
	(Parser::parse_trait_item): Likewise.
	(Parser::parse_inherent_impl_item): Likewise.
	(Parser::parse_trait_impl_item): Likewise.
	(Parser::parse_extern_block): Likewise.
	(Parser::parse_external_item): Likewise.
	(Parser::parse_stmt): Likewise.
	(Parser::parse_return_expr): Likewise.
	(Parser::parse_match_expr): Likewise.
	(Parser::parse_type): Likewise.
	(Parser::parse_for_prefixed_type): Likewise.
	(Parser::parse_type_no_bounds): Likewise.
	(Parser::parse_stmt_or_expr): Likewise.
	* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie.
	* util/rust-token-converter.cc (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
  • Loading branch information
P-E-P committed Nov 15, 2023
1 parent fe0d34c commit 3f87dd3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 111 deletions.
30 changes: 15 additions & 15 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ TokenCollector::visit (FunctionQualifiers &qualifiers)
push (Rust::Token::make (UNSAFE, qualifiers.get_locus ()));
if (qualifiers.is_extern ())
{
push (Rust::Token::make (EXTERN_TOK, qualifiers.get_locus ()));
push (Rust::Token::make (EXTERN_KW, qualifiers.get_locus ()));
if (qualifiers.has_abi ())
{
push (Rust::Token::make_string (UNDEF_LOCATION,
Expand Down Expand Up @@ -1393,7 +1393,7 @@ TokenCollector::visit (RangeToInclExpr &expr)
void
TokenCollector::visit (ReturnExpr &expr)
{
push (Rust::Token::make (RETURN_TOK, expr.get_locus ()));
push (Rust::Token::make (RETURN_KW, expr.get_locus ()));
if (expr.has_returned_expr ())
visit (expr.get_returned_expr ());
}
Expand Down Expand Up @@ -1533,7 +1533,7 @@ TokenCollector::visit (MatchCase &match_case)
void
TokenCollector::visit (MatchExpr &expr)
{
push (Rust::Token::make (MATCH_TOK, expr.get_locus ()));
push (Rust::Token::make (MATCH_KW, expr.get_locus ()));
visit (expr.get_scrutinee_expr ());
push (Rust::Token::make (LEFT_CURLY, UNDEF_LOCATION));
newline ();
Expand Down Expand Up @@ -1679,7 +1679,7 @@ void
TokenCollector::visit (ExternCrate &crate)
{
visit_items_as_lines (crate.get_outer_attrs ());
push (Rust::Token::make (EXTERN_TOK, crate.get_locus ()));
push (Rust::Token::make (EXTERN_KW, crate.get_locus ()));
push (Rust::Token::make (CRATE, UNDEF_LOCATION));
auto ref = crate.get_referenced_crate ();
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (ref)));
Expand Down Expand Up @@ -1787,7 +1787,7 @@ TokenCollector::visit (Function &function)
auto qualifiers = function.get_qualifiers ();
visit (qualifiers);

push (Rust::Token::make (FN_TOK, function.get_locus ()));
push (Rust::Token::make (FN_KW, function.get_locus ()));
auto name = function.get_function_name ().as_string ();
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (name)));
if (function.has_generics ())
Expand Down Expand Up @@ -1848,7 +1848,7 @@ TokenCollector::visit (StructStruct &struct_item)
if (struct_item.has_visibility ())
visit (struct_item.get_visibility ());
auto struct_name = struct_item.get_identifier ().as_string ();
push (Rust::Token::make (STRUCT_TOK, struct_item.get_locus ()));
push (Rust::Token::make (STRUCT_KW, struct_item.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name)));

if (struct_item.has_generics ())
Expand All @@ -1870,7 +1870,7 @@ TokenCollector::visit (TupleStruct &tuple_struct)
{
visit_items_as_lines (tuple_struct.get_outer_attrs ());
auto struct_name = tuple_struct.get_identifier ().as_string ();
push (Rust::Token::make (STRUCT_TOK, tuple_struct.get_locus ()));
push (Rust::Token::make (STRUCT_KW, tuple_struct.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name)));
if (tuple_struct.has_generics ())
visit (tuple_struct.get_generic_params ());
Expand Down Expand Up @@ -1926,7 +1926,7 @@ TokenCollector::visit (Enum &enumeration)
visit_items_as_lines (enumeration.get_outer_attrs ());
if (enumeration.has_visibility ())
visit (enumeration.get_visibility ());
push (Rust::Token::make (ENUM_TOK, enumeration.get_locus ()));
push (Rust::Token::make (ENUM_KW, enumeration.get_locus ()));
auto id = enumeration.get_identifier ().as_string ();
push (
Rust::Token::make_identifier (enumeration.get_locus (), std::move (id)));
Expand Down Expand Up @@ -1985,7 +1985,7 @@ void
TokenCollector::visit (StaticItem &item)
{
visit_items_as_lines (item.get_outer_attrs ());
push (Rust::Token::make (STATIC_TOK, item.get_locus ()));
push (Rust::Token::make (STATIC_KW, item.get_locus ()));
if (item.is_mutable ())
push (Rust::Token::make (MUT, UNDEF_LOCATION));

Expand Down Expand Up @@ -2031,7 +2031,7 @@ TokenCollector::visit (TraitItemFunc &item)
auto func = item.get_trait_function_decl ();
auto id = func.get_identifier ().as_string ();

push (Rust::Token::make (FN_TOK, item.get_locus ()));
push (Rust::Token::make (FN_KW, item.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

Expand Down Expand Up @@ -2070,7 +2070,7 @@ TokenCollector::visit (TraitItemMethod &item)
auto method = item.get_trait_method_decl ();
auto id = method.get_identifier ().as_string ();

push (Rust::Token::make (FN_TOK, item.get_locus ()));
push (Rust::Token::make (FN_KW, item.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

Expand Down Expand Up @@ -2182,7 +2182,7 @@ TokenCollector::visit (ExternalStaticItem &item)
visit_items_as_lines (item.get_outer_attrs ());
if (item.has_visibility ())
visit (item.get_visibility ());
push (Rust::Token::make (STATIC_TOK, item.get_locus ()));
push (Rust::Token::make (STATIC_KW, item.get_locus ()));
if (item.is_mut ())
push (Rust::Token::make (MUT, UNDEF_LOCATION));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
Expand All @@ -2201,7 +2201,7 @@ TokenCollector::visit (ExternalFunctionItem &function)

auto id = function.get_identifier ().as_string ();

push (Rust::Token::make (FN_TOK, function.get_locus ()));
push (Rust::Token::make (FN_KW, function.get_locus ()));
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
if (function.has_generics ())
visit (function.get_generic_params ());
Expand All @@ -2222,7 +2222,7 @@ void
TokenCollector::visit (ExternBlock &block)
{
visit_items_as_lines (block.get_outer_attrs ());
push (Rust::Token::make (EXTERN_TOK, block.get_locus ()));
push (Rust::Token::make (EXTERN_KW, block.get_locus ()));

if (block.has_abi ())
{
Expand Down Expand Up @@ -2891,7 +2891,7 @@ TokenCollector::visit (BareFunctionType &type)

visit (type.get_function_qualifiers ());

push (Rust::Token::make (FN_TOK, type.get_locus ()));
push (Rust::Token::make (FN_KW, type.get_locus ()));
push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));

visit_items_joined_by_separator (type.get_function_params (), COMMA);
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/lex/rust-lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ Lexer::parse_raw_identifier (location_t loc)

using namespace Rust::Values;
std::set<std::string> invalid{
Keywords::CRATE, Keywords::EXTERN_TOK, Keywords::SELF,
Keywords::CRATE, Keywords::EXTERN_KW, Keywords::SELF,
Keywords::SUPER, Keywords::SELF_ALIAS,
};

Expand Down
20 changes: 10 additions & 10 deletions gcc/rust/lex/rust-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,32 @@ enum PrimitiveCoreType
RS_TOKEN_KEYWORD (DO, "do") /* unused */ \
RS_TOKEN_KEYWORD (DYN, "dyn") \
RS_TOKEN_KEYWORD (ELSE, "else") \
RS_TOKEN_KEYWORD (ENUM_TOK, "enum") \
RS_TOKEN_KEYWORD (EXTERN_TOK, "extern") \
RS_TOKEN_KEYWORD (ENUM_KW, "enum") \
RS_TOKEN_KEYWORD (EXTERN_KW, "extern") \
RS_TOKEN_KEYWORD (FALSE_LITERAL, "false") \
RS_TOKEN_KEYWORD (FINAL_TOK, "final") /* unused */ \
RS_TOKEN_KEYWORD (FN_TOK, "fn") \
RS_TOKEN_KEYWORD (FINAL_KW, "final") /* unused */ \
RS_TOKEN_KEYWORD (FN_KW, "fn") \
RS_TOKEN_KEYWORD (FOR, "for") \
RS_TOKEN_KEYWORD (IF, "if") \
RS_TOKEN_KEYWORD (IMPL, "impl") \
RS_TOKEN_KEYWORD (IN, "in") \
RS_TOKEN_KEYWORD (LET, "let") \
RS_TOKEN_KEYWORD (LOOP, "loop") \
RS_TOKEN_KEYWORD (MACRO, "macro") \
RS_TOKEN_KEYWORD (MATCH_TOK, "match") \
RS_TOKEN_KEYWORD (MATCH_KW, "match") \
RS_TOKEN_KEYWORD (MOD, "mod") \
RS_TOKEN_KEYWORD (MOVE, "move") \
RS_TOKEN_KEYWORD (MUT, "mut") \
RS_TOKEN_KEYWORD (OVERRIDE_TOK, "override") /* unused */ \
RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \
RS_TOKEN_KEYWORD (OVERRIDE_KW, "override") /* unused */ \
RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \
RS_TOKEN_KEYWORD (PUB, "pub") \
RS_TOKEN_KEYWORD (REF, "ref") \
RS_TOKEN_KEYWORD (RETURN_TOK, "return") \
RS_TOKEN_KEYWORD (RETURN_KW, "return") \
RS_TOKEN_KEYWORD (SELF_ALIAS, \
"Self") /* mrustc does not treat this as a reserved word*/ \
RS_TOKEN_KEYWORD (SELF, "self") \
RS_TOKEN_KEYWORD (STATIC_TOK, "static") \
RS_TOKEN_KEYWORD (STRUCT_TOK, "struct") \
RS_TOKEN_KEYWORD (STATIC_KW, "static") \
RS_TOKEN_KEYWORD (STRUCT_KW, "struct") \
RS_TOKEN_KEYWORD (SUPER, "super") \
RS_TOKEN_KEYWORD (TRAIT, "trait") \
RS_TOKEN_KEYWORD (TRUE_LITERAL, "true") \
Expand Down
Loading

0 comments on commit 3f87dd3

Please sign in to comment.