Lines Matching +full:ascii +full:. +full:r

2    Copyright (C) 2016-2020 Free Software Foundation, Inc.
3 Written by David Tolnay (dtolnay@gmail.com).
5 This file is part of the libiberty library.
9 version 2 of the License, or (at your option) any later version.
15 coming from the use of this file. (The Library Public License
18 combined executable.)
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Library General Public License for more details.
26 License along with libiberty; see the file COPYING.LIB.
27 If not, see <http://www.gnu.org/licenses/>. */
31 #include "config.h"
34 #include "safe-ctype.h"
36 #include <inttypes.h>
37 #include <sys/types.h>
38 #include <string.h>
39 #include <stdio.h>
40 #include <stdlib.h>
43 #include <string.h>
50 #include <demangle.h>
51 #include "libiberty.h"
61 /* Position of the next character to read from the symbol. */
64 /* Non-zero if any error occurred. */
67 /* Non-zero if printing should be verbose (e.g. include hashes). */
70 /* Rust mangling version, with legacy mangling being -1. */
74 /* Parsing functions. */
97 /* ASCII part of the identifier. */
98 const char *ascii; member
109 ident.ascii = NULL; in parse_ident()
110 ident.ascii_len = 0; in parse_ident()
126 /* Check for overflows. */ in parse_ident()
133 ident.ascii = rdm->sym + start; in parse_ident()
134 ident.ascii_len = len; in parse_ident()
136 if (ident.ascii_len == 0) in parse_ident()
137 ident.ascii = NULL; in parse_ident()
142 /* Printing functions. */
153 /* Return a 0x0-0xf value if the char is 0-9a-f, and -1 otherwise. */
164 /* Return the unescaped character for a "$...$" escape, or 0 if invalid. */
192 else if (e[0] == 'R' && e[1] == 'F') in decode_legacy_escape()
200 else if (e[0] == 'R' && e[1] == 'P') in decode_legacy_escape()
213 /* Only allow non-control ASCII characters. */ in decode_legacy_escape()
240 /* Ignore leading underscores preceding escape sequences. in print_ident()
242 identifier begins with a XID_Start character. */ in print_ident()
243 if (ident.ascii_len >= 2 && ident.ascii[0] == '_' in print_ident()
244 && ident.ascii[1] == '$') in print_ident()
246 ident.ascii++; in print_ident()
247 ident.ascii_len--; in print_ident()
250 while (ident.ascii_len > 0) in print_ident()
252 /* Handle legacy escape sequences ("$...$", ".." or "."). */ in print_ident()
253 if (ident.ascii[0] == '$') in print_ident()
256 = decode_legacy_escape (ident.ascii, ident.ascii_len, &len); in print_ident()
261 /* Unexpected escape sequence, print the rest verbatim. */ in print_ident()
262 print_str (rdm, ident.ascii, ident.ascii_len); in print_ident()
266 else if (ident.ascii[0] == '.') in print_ident()
268 if (ident.ascii_len >= 2 && ident.ascii[1] == '.') in print_ident()
270 /* ".." becomes "::" */ in print_ident()
276 /* "." becomes "-" */ in print_ident()
283 /* Print everything before the next escape sequence, at once. */ in print_ident()
284 for (len = 0; len < ident.ascii_len; len++) in print_ident()
285 if (ident.ascii[len] == '$' || ident.ascii[len] == '.') in print_ident()
288 print_str (rdm, ident.ascii, len); in print_ident()
291 ident.ascii += len; in print_ident()
292 ident.ascii_len -= len; in print_ident()
299 /* A legacy hash is the prefix "h" followed by 16 lowercase hex digits.
300 The hex digits must contain at least 5 distinct digits. */
308 if (ident.ascii_len != 17 || ident.ascii[0] != 'h') in is_legacy_prefixed_hash()
314 nibble = decode_lower_hex_nibble (ident.ascii[1 + i]); in is_legacy_prefixed_hash()
320 /* Count how many distinct digits were seen. */ in is_legacy_prefixed_hash()
340 rdm.sym = mangled; in rust_demangle_callback()
341 rdm.sym_len = 0; in rust_demangle_callback()
343 rdm.callback_opaque = opaque; in rust_demangle_callback()
344 rdm.callback = callback; in rust_demangle_callback()
346 rdm.next = 0; in rust_demangle_callback()
347 rdm.errored = 0; in rust_demangle_callback()
348 rdm.verbose = (options & DMGL_VERBOSE) != 0; in rust_demangle_callback()
349 rdm.version = 0; in rust_demangle_callback()
351 /* Rust symbols always start with _ZN (legacy). */ in rust_demangle_callback()
352 if (rdm.sym[0] == '_' && rdm.sym[1] == 'Z' && rdm.sym[2] == 'N') in rust_demangle_callback()
354 rdm.sym += 3; in rust_demangle_callback()
355 rdm.version = -1; in rust_demangle_callback()
360 /* Legacy Rust symbols use only [_0-9a-zA-Z.:$] characters. */ in rust_demangle_callback()
361 for (p = rdm.sym; *p; p++) in rust_demangle_callback()
363 rdm.sym_len++; in rust_demangle_callback()
368 if (rdm.version == -1 && (*p == '$' || *p == '.' || *p == ':')) in rust_demangle_callback()
374 /* Legacy Rust symbols need to be handled separately. */ in rust_demangle_callback()
375 if (rdm.version == -1) in rust_demangle_callback()
377 /* Legacy Rust symbols always end with E. */ in rust_demangle_callback()
378 if (!(rdm.sym_len > 0 && rdm.sym[rdm.sym_len - 1] == 'E')) in rust_demangle_callback()
380 rdm.sym_len--; in rust_demangle_callback()
383 that encodes a 16 hex digit hash, i.e. '17h[a-f0-9]{16}'. in rust_demangle_callback()
385 quickly filter out most C++ symbols unrelated to Rust. */ in rust_demangle_callback()
386 if (!(rdm.sym_len > 19 in rust_demangle_callback()
387 && !memcmp (&rdm.sym[rdm.sym_len - 19], "17h", 3))) in rust_demangle_callback()
393 if (rdm.errored || !ident.ascii) in rust_demangle_callback()
396 while (rdm.next < rdm.sym_len); in rust_demangle_callback()
398 /* The last path segment should be the hash. */ in rust_demangle_callback()
402 /* Reset the state for a second pass, to print the symbol. */ in rust_demangle_callback()
403 rdm.next = 0; in rust_demangle_callback()
404 if (!rdm.verbose && rdm.sym_len > 19) in rust_demangle_callback()
406 /* Hide the last segment, containing the hash, if not verbose. */ in rust_demangle_callback()
407 rdm.sym_len -= 19; in rust_demangle_callback()
412 if (rdm.next > 0) in rust_demangle_callback()
418 while (rdm.next < rdm.sym_len); in rust_demangle_callback()
423 return !rdm.errored; in rust_demangle_callback()
426 /* Growable string buffers. */
441 /* Allocation failed before. */ in str_buf_reserve()
452 /* Check for overflows. */ in str_buf_reserve()
464 /* Double capacity until sufficiently large. */ in str_buf_reserve()
469 /* Check for overflows. */ in str_buf_reserve()
516 out.ptr = NULL; in rust_demangle()
517 out.len = 0; in rust_demangle()
518 out.cap = 0; in rust_demangle()
519 out.errored = 0; in rust_demangle()
526 free (out.ptr); in rust_demangle()
531 return out.ptr; in rust_demangle()