| 1329 | } |
| 1330 | |
| 1331 | static NODISCARD overflow_status printer_print_const(struct printer *printer, bool in_value) { |
| 1332 | uint8_t tag; |
| 1333 | |
| 1334 | PARSE(printer, parser_ch, &tag); |
| 1335 | PARSE(printer, parser_push_depth); |
| 1336 | |
| 1337 | struct buf hex; |
| 1338 | uint64_t val; |
| 1339 | size_t count; |
| 1340 | |
| 1341 | bool opened_brace = false; |
| 1342 | #define OPEN_BRACE_IF_OUTSIDE_EXPR \ |
| 1343 | do { if (!in_value) { \ |
| 1344 | opened_brace = true; \ |
| 1345 | PRINT_STR(printer, "{"); \ |
| 1346 | } } while(0) |
| 1347 | |
| 1348 | switch(tag) { |
| 1349 | case 'p': |
| 1350 | PRINT_STR(printer, "_"); |
| 1351 | break; |
| 1352 | // Primitive leaves with hex-encoded values (see `basic_type`). |
| 1353 | case 'a': |
| 1354 | case 's': |
| 1355 | case 'l': |
| 1356 | case 'x': |
| 1357 | case 'n': |
| 1358 | case 'i': |
| 1359 | if (printer_eat(printer, 'n')) { |
| 1360 | PRINT_STR(printer, "-"); |
| 1361 | } |
| 1362 | /* fallthrough */ |
| 1363 | case 'h': |
| 1364 | case 't': |
| 1365 | case 'm': |
| 1366 | case 'y': |
| 1367 | case 'o': |
| 1368 | case 'j': |
| 1369 | PRINT(printer_print_const_uint(printer, tag)); |
| 1370 | break; |
| 1371 | case 'b': |
| 1372 | PARSE(printer, parser_hex_nibbles, &hex); |
| 1373 | if (try_parse_uint(hex.start, hex.len, &val)) { |
| 1374 | if (val == 0) { |
| 1375 | PRINT_STR(printer, "false"); |
| 1376 | } else if (val == 1) { |
| 1377 | PRINT_STR(printer, "true"); |
| 1378 | } else { |
| 1379 | INVALID(printer); |
| 1380 | } |
| 1381 | } else { |
| 1382 | INVALID(printer); |
| 1383 | } |
| 1384 | break; |
| 1385 | case 'c': |
| 1386 | PARSE(printer, parser_hex_nibbles, &hex); |
| 1387 | if (try_parse_uint(hex.start, hex.len, &val) |
| 1388 | && val < UINT32_MAX |
nothing calls this directly
no test coverage detected