Branch data Line data Source code
1 : : // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : :
19 : : #ifndef RUST_TOKEN_H
20 : : #define RUST_TOKEN_H
21 : :
22 : : #include "rust-system.h"
23 : : #include "rust-linemap.h"
24 : : #include "rust-unicode.h"
25 : : #include "rust-diagnostics.h"
26 : :
27 : : namespace Rust {
28 : :
29 : : // used by Rust::Token::make_identifier
30 : : class Identifier;
31 : :
32 : : // "Primitive core types" in Rust - the different int and float types, as well
33 : : // as some others
34 : : enum PrimitiveCoreType
35 : : {
36 : : CORETYPE_UNKNOWN,
37 : : // named primitives
38 : : CORETYPE_BOOL,
39 : : CORETYPE_CHAR,
40 : : CORETYPE_STR,
41 : : // okay technically int and uint are arch-dependent (pointer size)
42 : : CORETYPE_INT,
43 : : CORETYPE_UINT,
44 : : // numbered number primitives
45 : : CORETYPE_F32,
46 : : CORETYPE_F64,
47 : : CORETYPE_I8,
48 : : CORETYPE_I16,
49 : : CORETYPE_I32,
50 : : CORETYPE_I64,
51 : : CORETYPE_I128,
52 : : CORETYPE_U8,
53 : : CORETYPE_U16,
54 : : CORETYPE_U32,
55 : : CORETYPE_U64,
56 : : CORETYPE_U128,
57 : : // Pure decimals are used for tuple index.
58 : : // Also means there is no type hint.
59 : : CORETYPE_PURE_DECIMAL,
60 : : // arch-dependent pointer sizes
61 : : CORETYPE_ISIZE = CORETYPE_INT,
62 : : CORETYPE_USIZE = CORETYPE_UINT
63 : : };
64 : :
65 : : // RS_TOKEN(name, description)
66 : : // RS_TOKEN_KEYWORD_{2015,2018}(name, identifier)
67 : :
68 : : // Keep RS_TOKEN_KEYWORD sorted
69 : :
70 : : /* note that abstract, async, become, box, do, final, macro, override, priv,
71 : : * try, typeof, unsized, virtual, and yield are unused */
72 : : #define RS_TOKEN_LIST \
73 : : RS_TOKEN (FIRST_TOKEN, "<first-token-marker>") \
74 : : RS_TOKEN (END_OF_FILE, "end of file") \
75 : : RS_TOKEN (EXCLAM, "!") \
76 : : RS_TOKEN (NOT_EQUAL, "!=") \
77 : : RS_TOKEN (PERCENT, "%") \
78 : : RS_TOKEN (PERCENT_EQ, "%=") \
79 : : RS_TOKEN (AMP, "&") \
80 : : RS_TOKEN (AMP_EQ, "&=") \
81 : : RS_TOKEN (LOGICAL_AND, "&&") \
82 : : RS_TOKEN (ASTERISK, "*") \
83 : : RS_TOKEN (ASTERISK_EQ, "*=") \
84 : : RS_TOKEN (PLUS, "+") \
85 : : RS_TOKEN (PLUS_EQ, "+=") \
86 : : RS_TOKEN (COMMA, ",") \
87 : : RS_TOKEN (MINUS, "-") \
88 : : RS_TOKEN (MINUS_EQ, "-=") \
89 : : RS_TOKEN (RETURN_TYPE, "->") \
90 : : RS_TOKEN (DOT, ".") \
91 : : RS_TOKEN (DOT_DOT, "..") \
92 : : RS_TOKEN (DOT_DOT_EQ, "..=") \
93 : : RS_TOKEN (ELLIPSIS, "...") \
94 : : RS_TOKEN (DIV, "/") \
95 : : RS_TOKEN (DIV_EQ, "/=") \
96 : : RS_TOKEN (COLON, ":") \
97 : : RS_TOKEN (SEMICOLON, ";") \
98 : : RS_TOKEN (LEFT_SHIFT, "<<") \
99 : : RS_TOKEN (LEFT_SHIFT_EQ, "<<=") \
100 : : RS_TOKEN (LEFT_ANGLE, "<") \
101 : : RS_TOKEN (LESS_OR_EQUAL, "<=") \
102 : : RS_TOKEN (EQUAL, "=") \
103 : : RS_TOKEN (EQUAL_EQUAL, "==") \
104 : : RS_TOKEN (MATCH_ARROW, "=>") \
105 : : RS_TOKEN (RIGHT_ANGLE, ">") \
106 : : RS_TOKEN (GREATER_OR_EQUAL, ">=") \
107 : : RS_TOKEN (RIGHT_SHIFT, ">>") \
108 : : RS_TOKEN (RIGHT_SHIFT_EQ, ">>=") \
109 : : RS_TOKEN (PATTERN_BIND, "@") \
110 : : RS_TOKEN (TILDE, "~") \
111 : : RS_TOKEN (BACKSLASH, "\\") \
112 : : RS_TOKEN (BACKTICK, "`") \
113 : : RS_TOKEN (CARET, "^") \
114 : : RS_TOKEN (CARET_EQ, "^=") \
115 : : RS_TOKEN (PIPE, "|") \
116 : : RS_TOKEN (PIPE_EQ, "|=") \
117 : : RS_TOKEN (OR, "||") \
118 : : RS_TOKEN (QUESTION_MARK, "?") \
119 : : RS_TOKEN (HASH, "#") \
120 : : /* from here on, dodgy and may not be correct. not operators and may be \
121 : : * symbols */ \
122 : : /* RS_TOKEN(SPACE, " ") probably too dodgy */ \
123 : : /* RS_TOKEN(NEWLINE, "\n")*/ \
124 : : RS_TOKEN (SCOPE_RESOLUTION, "::") /* dodgy */ \
125 : : RS_TOKEN (SINGLE_QUOTE, "'") /* should i differentiate from lifetime? */ \
126 : : RS_TOKEN (DOUBLE_QUOTE, "\"") \
127 : : RS_TOKEN (IDENTIFIER, "identifier") \
128 : : RS_TOKEN (INT_LITERAL, \
129 : : "integer literal") /* do different int and float types need \
130 : : different literal types? */ \
131 : : RS_TOKEN (FLOAT_LITERAL, "float literal") \
132 : : RS_TOKEN (STRING_LITERAL, "string literal") \
133 : : RS_TOKEN (CHAR_LITERAL, "character literal") \
134 : : RS_TOKEN (BYTE_STRING_LITERAL, "byte string literal") \
135 : : RS_TOKEN (RAW_STRING_LITERAL, "raw string literal") \
136 : : RS_TOKEN (BYTE_CHAR_LITERAL, "byte character literal") \
137 : : RS_TOKEN (LIFETIME, "lifetime") /* TODO: improve token type */ \
138 : : /* Have "interpolated" tokens (whatever that means)? identifer, path, type, \
139 : : * pattern, */ \
140 : : /* expression, statement, block, meta, item in mrustc (but not directly in \
141 : : * lexer). */ \
142 : : RS_TOKEN (LEFT_PAREN, "(") \
143 : : RS_TOKEN (RIGHT_PAREN, ")") \
144 : : RS_TOKEN (LEFT_CURLY, "{") \
145 : : RS_TOKEN (RIGHT_CURLY, "}") \
146 : : RS_TOKEN (LEFT_SQUARE, "[") \
147 : : RS_TOKEN (RIGHT_SQUARE, "]") \
148 : : /* Macros */ \
149 : : RS_TOKEN (DOLLAR_SIGN, "$") \
150 : : /* Doc Comments */ \
151 : : RS_TOKEN (INNER_DOC_COMMENT, "#![doc]") \
152 : : RS_TOKEN (OUTER_DOC_COMMENT, "#[doc]") \
153 : : RS_TOKEN_KEYWORD_2015 (ABSTRACT, "abstract") /* unused */ \
154 : : RS_TOKEN_KEYWORD_2015 (AS, "as") \
155 : : RS_TOKEN_KEYWORD_2018 (ASYNC, "async") /* unused */ \
156 : : RS_TOKEN_KEYWORD_2015 (AUTO, "auto") \
157 : : RS_TOKEN_KEYWORD_2018 (AWAIT, "await") \
158 : : RS_TOKEN_KEYWORD_2015 (BECOME, "become") /* unused */ \
159 : : RS_TOKEN_KEYWORD_2015 (BOX, "box") /* unused */ \
160 : : RS_TOKEN_KEYWORD_2015 (BREAK, "break") \
161 : : RS_TOKEN_KEYWORD_2015 (CONST, "const") \
162 : : RS_TOKEN_KEYWORD_2015 (CONTINUE, "continue") \
163 : : RS_TOKEN_KEYWORD_2015 (CRATE, "crate") \
164 : : RS_TOKEN_KEYWORD_2015 (DO, "do") /* unused */ \
165 : : RS_TOKEN_KEYWORD_2018 (DYN, "dyn") \
166 : : RS_TOKEN_KEYWORD_2015 (ELSE, "else") \
167 : : RS_TOKEN_KEYWORD_2015 (ENUM_KW, "enum") \
168 : : RS_TOKEN_KEYWORD_2015 (EXTERN_KW, "extern") \
169 : : RS_TOKEN_KEYWORD_2015 (FALSE_LITERAL, "false") \
170 : : RS_TOKEN_KEYWORD_2015 (FINAL_KW, "final") /* unused */ \
171 : : RS_TOKEN_KEYWORD_2015 (FN_KW, "fn") \
172 : : RS_TOKEN_KEYWORD_2015 (FOR, "for") \
173 : : RS_TOKEN_KEYWORD_2015 (IF, "if") \
174 : : RS_TOKEN_KEYWORD_2015 (IMPL, "impl") \
175 : : RS_TOKEN_KEYWORD_2015 (IN, "in") \
176 : : RS_TOKEN_KEYWORD_2015 (LET, "let") \
177 : : RS_TOKEN_KEYWORD_2015 (LOOP, "loop") \
178 : : RS_TOKEN_KEYWORD_2015 (MACRO, "macro") \
179 : : RS_TOKEN_KEYWORD_2015 (MATCH_KW, "match") \
180 : : RS_TOKEN_KEYWORD_2015 (MOD, "mod") \
181 : : RS_TOKEN_KEYWORD_2015 (MOVE, "move") \
182 : : RS_TOKEN_KEYWORD_2015 (MUT, "mut") \
183 : : RS_TOKEN_KEYWORD_2015 (OVERRIDE_KW, "override") /* unused */ \
184 : : RS_TOKEN_KEYWORD_2015 (PRIV, "priv") /* unused */ \
185 : : RS_TOKEN_KEYWORD_2015 (PUB, "pub") \
186 : : RS_TOKEN_KEYWORD_2015 (REF, "ref") \
187 : : RS_TOKEN_KEYWORD_2015 (RETURN_KW, "return") \
188 : : RS_TOKEN_KEYWORD_2015 ( \
189 : : SELF_ALIAS, "Self") /* mrustc does not treat this as a reserved word*/ \
190 : : RS_TOKEN_KEYWORD_2015 (SELF, "self") \
191 : : RS_TOKEN_KEYWORD_2015 (STATIC_KW, "static") \
192 : : RS_TOKEN_KEYWORD_2015 (STRUCT_KW, "struct") \
193 : : RS_TOKEN_KEYWORD_2015 (SUPER, "super") \
194 : : RS_TOKEN_KEYWORD_2015 (TRAIT, "trait") \
195 : : RS_TOKEN_KEYWORD_2015 (TRUE_LITERAL, "true") \
196 : : RS_TOKEN_KEYWORD_2015 (TRY, "try") /* unused */ \
197 : : RS_TOKEN_KEYWORD_2015 (TYPE, "type") \
198 : : RS_TOKEN_KEYWORD_2015 (TYPEOF, "typeof") /* unused */ \
199 : : RS_TOKEN_KEYWORD_2015 (UNDERSCORE, "_") \
200 : : RS_TOKEN_KEYWORD_2015 (UNSAFE, "unsafe") \
201 : : RS_TOKEN_KEYWORD_2015 (UNSIZED, "unsized") /* unused */ \
202 : : RS_TOKEN_KEYWORD_2015 (USE, "use") \
203 : : RS_TOKEN_KEYWORD_2015 (VIRTUAL, "virtual") /* unused */ \
204 : : RS_TOKEN_KEYWORD_2015 (WHERE, "where") \
205 : : RS_TOKEN_KEYWORD_2015 (WHILE, "while") \
206 : : RS_TOKEN_KEYWORD_2015 (YIELD, "yield") /* unused */ \
207 : : RS_TOKEN (LAST_TOKEN, "<last-token-marker>")
208 : :
209 : : // Contains all token types. Crappy implementation via x-macros.
210 : : enum TokenId
211 : : {
212 : : #define RS_TOKEN(name, _) name,
213 : : #define RS_TOKEN_KEYWORD_2015(x, y) RS_TOKEN (x, y)
214 : : #define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015
215 : : RS_TOKEN_LIST
216 : : #undef RS_TOKEN_KEYWORD_2015
217 : : #undef RS_TOKEN_KEYWORD_2018
218 : : #undef RS_TOKEN
219 : : };
220 : :
221 : : // dodgy "TokenPtr" declaration with Token forward declaration
222 : : class Token;
223 : : // A smart pointer (shared_ptr) to Token.
224 : : typedef std::shared_ptr<Token> TokenPtr;
225 : : // A smart pointer (shared_ptr) to a constant Token.
226 : : typedef std::shared_ptr<const Token> const_TokenPtr;
227 : :
228 : : // Hackily defined way to get token description for enum value using x-macros
229 : : const char *get_token_description (TokenId id);
230 : : /* Hackily defined way to get token description as a string for enum value using
231 : : * x-macros */
232 : : const char *token_id_to_str (TokenId id);
233 : : /* checks if a token is a keyword */
234 : : bool token_id_is_keyword (TokenId id);
235 : : /* gets the string associated with a keyword */
236 : : const std::string &token_id_keyword_string (TokenId id);
237 : : // Get type hint description as a string.
238 : : const char *get_type_hint_string (PrimitiveCoreType type);
239 : :
240 : : /* Normalize string if a token is a identifier */
241 : : std::string nfc_normalize_token_string (location_t loc, TokenId id,
242 : : const std::string &str);
243 : :
244 : : // Represents a single token. Create using factory static methods.
245 : : class Token
246 : : {
247 : : private:
248 : : // Token kind.
249 : : TokenId token_id;
250 : : // Token location.
251 : : location_t locus;
252 : : // Associated text (if any) of token.
253 : : std::string str;
254 : : // TODO: maybe remove issues and just store std::string as value?
255 : : /* Type hint for token based on lexer data (e.g. type suffix). Does not exist
256 : : * for most tokens. */
257 : : PrimitiveCoreType type_hint;
258 : :
259 : : // Token constructor from token id and location. Has a null string.
260 : 1083533 : Token (TokenId token_id, location_t location)
261 : 1083533 : : token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
262 : : {}
263 : :
264 : : // Token constructor from token id, location, and a string.
265 : 411397 : Token (TokenId token_id, location_t location, std::string paramStr)
266 : 411397 : : token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
267 : : {
268 : : // Normalize identifier tokens
269 : 411397 : str = nfc_normalize_token_string (location, token_id, std::move (paramStr));
270 : 411397 : }
271 : :
272 : : // Token constructor from token id, location, and a char.
273 : 1896 : Token (TokenId token_id, location_t location, char paramChar)
274 : 1896 : : token_id (token_id), locus (location), str (1, paramChar),
275 : 1896 : type_hint (CORETYPE_UNKNOWN)
276 : : {
277 : : // Do not need to normalize 1byte char
278 : : }
279 : :
280 : : // Token constructor from token id, location, and a "codepoint".
281 : 11906 : Token (TokenId token_id, location_t location, Codepoint paramCodepoint)
282 : 11906 : : token_id (token_id), locus (location), type_hint (CORETYPE_UNKNOWN)
283 : : {
284 : : // Normalize identifier tokens
285 : 23812 : str = nfc_normalize_token_string (location, token_id,
286 : 23812 : paramCodepoint.as_string ());
287 : 11906 : }
288 : :
289 : : // Token constructor from token id, location, a string, and type hint.
290 : 99595 : Token (TokenId token_id, location_t location, std::string paramStr,
291 : : PrimitiveCoreType parType)
292 : 99595 : : token_id (token_id), locus (location), type_hint (parType)
293 : : {
294 : : // Normalize identifier tokens
295 : 99595 : str = nfc_normalize_token_string (location, token_id, std::move (paramStr));
296 : 99595 : }
297 : :
298 : : public:
299 : : // No default constructor.
300 : : Token () = delete;
301 : : // Do not copy/assign tokens.
302 : : Token (const Token &) = delete;
303 : : Token &operator= (const Token &) = delete;
304 : :
305 : : // Allow moving tokens.
306 : : Token (Token &&other) = default;
307 : : Token &operator= (Token &&other) = default;
308 : :
309 : 1397239 : ~Token () = default;
310 : :
311 : : /* TODO: make_shared (which saves a heap allocation) does not work with the
312 : : * private constructor */
313 : :
314 : : // Makes and returns a new TokenPtr (with null string).
315 : 1083533 : static TokenPtr make (TokenId token_id, location_t locus)
316 : : {
317 : : // return std::make_shared<Token> (token_id, locus);
318 : 1083533 : return TokenPtr (new Token (token_id, locus));
319 : : }
320 : :
321 : : // Makes and returns a new TokenPtr of type IDENTIFIER.
322 : 355264 : static TokenPtr make_identifier (location_t locus, std::string str)
323 : : {
324 : : // return std::make_shared<Token> (IDENTIFIER, locus, str);
325 : 355264 : return TokenPtr (new Token (IDENTIFIER, locus, std::move (str)));
326 : : }
327 : :
328 : : static TokenPtr make_identifier (const Identifier &ident);
329 : :
330 : : // Makes and returns a new TokenPtr of type INT_LITERAL.
331 : 54221 : static TokenPtr make_int (location_t locus, std::string str,
332 : : PrimitiveCoreType type_hint = CORETYPE_UNKNOWN)
333 : : {
334 : : // return std::make_shared<Token> (INT_LITERAL, locus, str, type_hint);
335 : 54221 : return TokenPtr (
336 : 54221 : new Token (INT_LITERAL, locus, std::move (str), type_hint));
337 : : }
338 : :
339 : : // Makes and returns a new TokenPtr of type FLOAT_LITERAL.
340 : 13848 : static TokenPtr make_float (location_t locus, std::string str,
341 : : PrimitiveCoreType type_hint = CORETYPE_UNKNOWN)
342 : : {
343 : : // return std::make_shared<Token> (FLOAT_LITERAL, locus, str, type_hint);
344 : 13848 : return TokenPtr (
345 : 13848 : new Token (FLOAT_LITERAL, locus, std::move (str), type_hint));
346 : : }
347 : :
348 : : // Makes and returns a new TokenPtr of type STRING_LITERAL.
349 : 31526 : static TokenPtr make_string (location_t locus, std::string str)
350 : : {
351 : : // return std::make_shared<Token> (STRING_LITERAL, locus, str,
352 : : // CORETYPE_STR);
353 : 31526 : return TokenPtr (
354 : 31526 : new Token (STRING_LITERAL, locus, std::move (str), CORETYPE_STR));
355 : : }
356 : :
357 : : // Makes and returns a new TokenPtr of type CHAR_LITERAL.
358 : 11906 : static TokenPtr make_char (location_t locus, Codepoint char_lit)
359 : : {
360 : : // return std::make_shared<Token> (CHAR_LITERAL, locus, char_lit);
361 : 11906 : return TokenPtr (new Token (CHAR_LITERAL, locus, char_lit));
362 : : }
363 : :
364 : : // Makes and returns a new TokenPtr of type BYTE_CHAR_LITERAL.
365 : 1896 : static TokenPtr make_byte_char (location_t locus, char byte_char)
366 : : {
367 : : // return std::make_shared<Token> (BYTE_CHAR_LITERAL, locus, byte_char);
368 : 1896 : return TokenPtr (new Token (BYTE_CHAR_LITERAL, locus, byte_char));
369 : : }
370 : :
371 : : // Makes and returns a new TokenPtr of type BYTE_STRING_LITERAL (fix).
372 : 152 : static TokenPtr make_byte_string (location_t locus, std::string str)
373 : : {
374 : : // return std::make_shared<Token> (BYTE_STRING_LITERAL, locus, str);
375 : 152 : return TokenPtr (new Token (BYTE_STRING_LITERAL, locus, std::move (str)));
376 : : }
377 : :
378 : : // Makes and returns a new TokenPtr of type RAW_STRING_LITERAL.
379 : 31 : static TokenPtr make_raw_string (location_t locus, std::string str)
380 : : {
381 : 31 : return TokenPtr (new Token (RAW_STRING_LITERAL, locus, std::move (str)));
382 : : }
383 : :
384 : : // Makes and returns a new TokenPtr of type INNER_DOC_COMMENT.
385 : 2650 : static TokenPtr make_inner_doc_comment (location_t locus, std::string str)
386 : : {
387 : 2650 : return TokenPtr (new Token (INNER_DOC_COMMENT, locus, std::move (str)));
388 : : }
389 : :
390 : : // Makes and returns a new TokenPtr of type OUTER_DOC_COMMENT.
391 : 49740 : static TokenPtr make_outer_doc_comment (location_t locus, std::string str)
392 : : {
393 : 49740 : return TokenPtr (new Token (OUTER_DOC_COMMENT, locus, std::move (str)));
394 : : }
395 : :
396 : : // Makes and returns a new TokenPtr of type LIFETIME.
397 : 3560 : static TokenPtr make_lifetime (location_t locus, std::string str)
398 : : {
399 : : // return std::make_shared<Token> (LIFETIME, locus, str);
400 : 3560 : return TokenPtr (new Token (LIFETIME, locus, std::move (str)));
401 : : }
402 : :
403 : : // Gets id of the token.
404 : 18388361 : TokenId get_id () const { return token_id; }
405 : :
406 : : // Gets location of the token.
407 : 3058026 : location_t get_locus () const { return locus; }
408 : :
409 : : // Set location of the token.
410 : 0 : void set_locus (location_t locus) { this->locus = locus; }
411 : :
412 : : // Gets string description of the token.
413 : 2894518 : const std::string &get_str () const
414 : : {
415 : 2894518 : if (token_id_is_keyword (token_id))
416 : 1329 : return token_id_keyword_string (token_id);
417 : :
418 : 2893189 : if (!should_have_str ())
419 : 0 : rust_internal_error_at (
420 : 0 : locus, "attempting to get string for %qs, which should have no string",
421 : : get_token_description ());
422 : :
423 : 2893189 : return str;
424 : : }
425 : :
426 : : // Gets token's type hint info.
427 : 437976 : PrimitiveCoreType get_type_hint () const
428 : : {
429 : 437976 : return type_hint == CORETYPE_PURE_DECIMAL ? CORETYPE_UNKNOWN : type_hint;
430 : : }
431 : :
432 : : // diagnostics (error reporting)
433 : 1779871 : const char *get_token_description () const
434 : : {
435 : 1774174 : return Rust::get_token_description (token_id);
436 : : }
437 : :
438 : : // debugging
439 : 0 : const char *token_id_to_str () const
440 : : {
441 : 0 : return Rust::token_id_to_str (token_id);
442 : : }
443 : :
444 : : // debugging
445 : : const char *get_type_hint_str () const;
446 : :
447 : : /* Returns whether the token is a literal of any type (int, float, char,
448 : : * string, byte char, byte string). */
449 : 5372362 : bool is_literal () const
450 : : {
451 : 3063639 : switch (token_id)
452 : : {
453 : : case INT_LITERAL:
454 : : case FLOAT_LITERAL:
455 : : case CHAR_LITERAL:
456 : : case STRING_LITERAL:
457 : : case BYTE_CHAR_LITERAL:
458 : : case BYTE_STRING_LITERAL:
459 : : case RAW_STRING_LITERAL:
460 : : return true;
461 : 4105591 : default:
462 : 2647809 : return false;
463 : : }
464 : : }
465 : :
466 : : // Returns whether the token should have a string.
467 : 5366945 : bool should_have_str () const
468 : : {
469 : 5366945 : return is_literal () || token_id == IDENTIFIER || token_id == LIFETIME
470 : 1675211 : || token_id == INNER_DOC_COMMENT || token_id == OUTER_DOC_COMMENT;
471 : : }
472 : :
473 : : // Returns whether the token is a pure decimal int literal
474 : 8945 : bool is_pure_decimal () const { return type_hint == CORETYPE_PURE_DECIMAL; }
475 : :
476 : : // Return the token representation as someone would find it in the original
477 : : // source code file.
478 : : std::string as_string () const;
479 : : };
480 : : } // namespace Rust
481 : :
482 : : namespace std {
483 : : template <> struct hash<Rust::PrimitiveCoreType>
484 : : {
485 : 187329 : size_t operator() (const Rust::PrimitiveCoreType &coretype) const noexcept
486 : : {
487 : 187329 : return hash<std::underlying_type<Rust::PrimitiveCoreType>::type> () (
488 : : static_cast<std::underlying_type<Rust::PrimitiveCoreType>::type> (
489 : : coretype));
490 : : }
491 : : };
492 : : } // namespace std
493 : :
494 : : #endif
|