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