Skip to content

Commit a07c117

Browse files
committed
gccrs: Remove unnecessary methods of Rust::Lexer
gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::build_token): Replace function call. (Lexer::parse_string): Likewise. (Lexer::parse_identifier_or_keyword): Likewise. (Lexer::parse_raw_string): Likewise. (Lexer::parse_char_or_lifetime): Likewise. (Lexer::get_input_codepoint_length): Deleted. (Lexer::peek_codepoint_input): Deleted. (Lexer::skip_codepoint_input): Deleted. * lex/rust-lex.h: Signed-off-by: Raiki Tamura <[email protected]>
1 parent 3d2a0c0 commit a07c117

File tree

2 files changed

+50
-83
lines changed

2 files changed

+50
-83
lines changed

gcc/rust/lex/rust-lex.cc

Lines changed: 50 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ Lexer::build_token ()
306306
Location loc = get_current_location ();
307307

308308
current_char = peek_input ();
309-
current_char32 = peek_codepoint_input ();
310-
skip_codepoint_input ();
309+
skip_input ();
311310

312311
// detect shebang
313312
// Must be the first thing on the first line, starting with #!
@@ -1080,7 +1079,7 @@ Lexer::build_token ()
10801079
}
10811080

10821081
// find identifiers and keywords.
1083-
if (is_identifier_start (current_char32.value))
1082+
if (is_identifier_start (current_char.value))
10841083
return parse_identifier_or_keyword (loc);
10851084

10861085
// int and float literals
@@ -1985,59 +1984,56 @@ Lexer::skip_broken_string_input (Codepoint current_char)
19851984
current_column);
19861985
}
19871986

1988-
// Parses a unicode string.
1987+
// Parses a string.
19891988
TokenPtr
19901989
Lexer::parse_string (Location loc)
19911990
{
1992-
Codepoint current_char32;
1993-
19941991
std::string str;
19951992
str.reserve (16); // some sensible default
19961993

19971994
int length = 1;
1998-
current_char32 = peek_codepoint_input ();
1995+
current_char = peek_input ();
19991996

20001997
// FIXME: This fails if the input ends. How do we check for EOF?
2001-
while (current_char32.value != '"' && !current_char32.is_eof ())
1998+
while (current_char.value != '"' && !current_char.is_eof ())
20021999
{
2003-
if (current_char32.value == '\\')
2000+
if (current_char.value == '\\')
20042001
{
20052002
// parse escape
20062003
auto utf8_escape_pair = parse_utf8_escape ();
2007-
current_char32 = std::get<0> (utf8_escape_pair);
2004+
current_char = std::get<0> (utf8_escape_pair);
20082005

2009-
if (current_char32 == Codepoint (0) && std::get<2> (utf8_escape_pair))
2006+
if (current_char == Codepoint (0) && std::get<2> (utf8_escape_pair))
20102007
length = std::get<1> (utf8_escape_pair) - 1;
20112008
else
20122009
length += std::get<1> (utf8_escape_pair);
20132010

2014-
if (current_char32 != Codepoint (0)
2015-
|| !std::get<2> (utf8_escape_pair))
2016-
str += current_char32;
2017-
2018-
// required as parsing utf8 escape only changes current_char
2019-
current_char32 = peek_codepoint_input ();
2011+
if (current_char != Codepoint (0) || !std::get<2> (utf8_escape_pair))
2012+
str += current_char.as_string ();
20202013

2014+
// FIXME: should remove this but can't.
2015+
// `parse_utf8_escape` does not update `current_char` correctly.
2016+
current_char = peek_input ();
20212017
continue;
20222018
}
20232019

2024-
length += get_input_codepoint_length ();
2020+
length++;
20252021

2026-
str += current_char32;
2027-
skip_codepoint_input ();
2028-
current_char32 = peek_codepoint_input ();
2022+
str += current_char;
2023+
skip_input ();
2024+
current_char = peek_input ();
20292025
}
20302026

20312027
current_column += length;
20322028

2033-
if (current_char32.value == '"')
2029+
if (current_char.value == '"')
20342030
{
20352031
current_column++;
20362032

20372033
skip_input ();
20382034
current_char = peek_input ();
20392035
}
2040-
else if (current_char32.is_eof ())
2036+
else if (current_char.is_eof ())
20412037
{
20422038
rust_error_at (get_current_location (), "unended string literal");
20432039
return Token::make (END_OF_FILE, get_current_location ());
@@ -2059,22 +2055,22 @@ Lexer::parse_identifier_or_keyword (Location loc)
20592055
{
20602056
std::string str;
20612057
str.reserve (16); // default
2062-
str += current_char32.as_string ();
2058+
str += current_char.as_string ();
20632059

20642060
bool first_is_underscore = current_char == '_';
20652061

20662062
int length = 1;
2067-
current_char32 = peek_codepoint_input ();
2063+
current_char = peek_input ();
20682064

20692065
// loop through entire name
2070-
while (is_identifier_continue (current_char32.value))
2066+
while (is_identifier_continue (current_char.value))
20712067
{
2072-
auto s = current_char32.as_string ();
2068+
auto s = current_char.as_string ();
20732069
length++;
20742070

2075-
str += current_char32.as_string ();
2076-
skip_codepoint_input ();
2077-
current_char32 = peek_codepoint_input ();
2071+
str += current_char.as_string ();
2072+
skip_input ();
2073+
current_char = peek_input ();
20782074
}
20792075

20802076
current_column += length;
@@ -2128,11 +2124,11 @@ Lexer::parse_raw_string (Location loc, int initial_hash_count)
21282124

21292125
length++;
21302126
skip_input ();
2131-
Codepoint current_char32 = peek_codepoint_input ();
2127+
current_char = peek_input ();
21322128

2133-
while (!current_char32.is_eof ())
2129+
while (!current_char.is_eof ())
21342130
{
2135-
if (current_char32.value == '"')
2131+
if (current_char.value == '"')
21362132
{
21372133
bool enough_hashes = true;
21382134

@@ -2157,9 +2153,9 @@ Lexer::parse_raw_string (Location loc, int initial_hash_count)
21572153

21582154
length++;
21592155

2160-
str += current_char32;
2161-
skip_codepoint_input ();
2162-
current_char32 = peek_codepoint_input ();
2156+
str += current_char.as_string ();
2157+
skip_input ();
2158+
current_char = peek_input ();
21632159
}
21642160

21652161
current_column += length;
@@ -2411,29 +2407,27 @@ Lexer::parse_decimal_int_or_float (Location loc)
24112407
TokenPtr
24122408
Lexer::parse_char_or_lifetime (Location loc)
24132409
{
2414-
Codepoint current_char32;
2415-
24162410
int length = 1;
24172411

2418-
current_char32 = peek_codepoint_input ();
2419-
if (current_char32.is_eof ())
2412+
current_char = peek_input ();
2413+
if (current_char.is_eof ())
24202414
return nullptr;
24212415

24222416
// parse escaped char literal
2423-
if (current_char32.value == '\\')
2417+
if (current_char.value == '\\')
24242418
{
24252419
// parse escape
24262420
auto utf8_escape_pair = parse_utf8_escape ();
2427-
current_char32 = std::get<0> (utf8_escape_pair);
2421+
Codepoint escaped_char = std::get<0> (utf8_escape_pair);
24282422
length += std::get<1> (utf8_escape_pair);
24292423

2430-
if (peek_codepoint_input ().value != '\'')
2424+
if (peek_input ().value != '\'')
24312425
{
24322426
rust_error_at (get_current_location (), "unended character literal");
24332427
}
24342428
else
24352429
{
2436-
skip_codepoint_input ();
2430+
skip_input ();
24372431
current_char = peek_input ();
24382432
length++;
24392433
}
@@ -2442,15 +2436,16 @@ Lexer::parse_char_or_lifetime (Location loc)
24422436

24432437
loc += length - 1;
24442438

2445-
return Token::make_char (loc, current_char32);
2439+
return Token::make_char (loc, escaped_char);
24462440
}
24472441
else
24482442
{
2449-
skip_codepoint_input ();
2443+
skip_input ();
24502444

2451-
if (peek_codepoint_input ().value == '\'')
2445+
if (peek_input ().value == '\'')
24522446
{
24532447
// parse non-escaped char literal
2448+
Codepoint non_escaped_char = current_char;
24542449

24552450
// skip the ' character
24562451
skip_input ();
@@ -2461,21 +2456,21 @@ Lexer::parse_char_or_lifetime (Location loc)
24612456

24622457
loc += 2;
24632458

2464-
return Token::make_char (loc, current_char32);
2459+
return Token::make_char (loc, non_escaped_char);
24652460
}
2466-
else if (is_identifier_start (current_char32.value))
2461+
else if (is_identifier_start (current_char.value))
24672462
{
24682463
// parse lifetime name
24692464
std::string str;
2470-
str += current_char32;
2465+
str += current_char.as_string ();
24712466
length++;
24722467

2473-
current_char32 = peek_codepoint_input ();
2474-
while (is_identifier_continue (current_char32.value))
2468+
current_char = peek_input ();
2469+
while (is_identifier_continue (current_char.value))
24752470
{
2476-
str += current_char32;
2477-
skip_codepoint_input ();
2478-
current_char32 = peek_codepoint_input ();
2471+
str += current_char.as_string ();
2472+
skip_input ();
2473+
current_char = peek_input ();
24792474
length++;
24802475
}
24812476

@@ -2499,29 +2494,6 @@ Lexer::parse_char_or_lifetime (Location loc)
24992494
}
25002495
}
25012496

2502-
// TODO remove this function
2503-
// Returns the length of the codepoint at the current position.
2504-
int
2505-
Lexer::get_input_codepoint_length ()
2506-
{
2507-
return 1;
2508-
}
2509-
2510-
// TODO remove this function
2511-
// Returns the codepoint at the current position.
2512-
Codepoint
2513-
Lexer::peek_codepoint_input ()
2514-
{
2515-
return peek_input ();
2516-
}
2517-
2518-
// TODO remove this function
2519-
void
2520-
Lexer::skip_codepoint_input ()
2521-
{
2522-
skip_input ();
2523-
}
2524-
25252497
void
25262498
Lexer::split_current_token (TokenId new_left, TokenId new_right)
25272499
{

gcc/rust/lex/rust-lex.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ class Lexer
136136
std::pair<long, int> parse_partial_hex_escape ();
137137
std::pair<Codepoint, int> parse_partial_unicode_escape ();
138138

139-
int get_input_codepoint_length ();
140-
// Peeks the current utf-8 char
141-
Codepoint peek_codepoint_input ();
142-
void skip_codepoint_input ();
143139
void skip_broken_string_input (Codepoint current_char);
144140

145141
TokenPtr parse_byte_char (Location loc);
@@ -393,7 +389,6 @@ class Lexer
393389
int current_column;
394390
// Current character.
395391
Codepoint current_char;
396-
Codepoint current_char32;
397392
// Line map.
398393
Linemap *line_map;
399394

0 commit comments

Comments
 (0)