| 491 | } |
| 492 | |
| 493 | Type getType(uint64_t typeIndex) { |
| 494 | if (typeIndex >= typeCache.size()) |
| 495 | return Type(); |
| 496 | if (typeCache[typeIndex]) |
| 497 | return typeCache[typeIndex]; |
| 498 | |
| 499 | // Check for recursion. |
| 500 | if (currentlyParsing.count(typeIndex)) |
| 501 | return Type(); |
| 502 | // Mark this type as currently being parsed. |
| 503 | currentlyParsing.insert(typeIndex); |
| 504 | [[maybe_unused]] llvm::scope_exit removeIndex( |
| 505 | [&] { currentlyParsing.erase(typeIndex); }); |
| 506 | // Calculate the boundaries for the type data. |
| 507 | uint32_t start = typeStartIndices[typeIndex]; |
| 508 | uint32_t end = (typeIndex + 1 < typeStartIndices.size()) |
| 509 | ? typeStartIndices[typeIndex + 1] |
| 510 | : payload.size(); |
| 511 | if (end < start || end > payload.size()) |
| 512 | return Type(); |
| 513 | // Parse the type from its specific byte slice. |
| 514 | EncodingReader typeReader(payload.slice(start, end - start), context); |
| 515 | uint64_t typeTag; |
| 516 | if (failed(typeReader.readVarInt(typeTag))) |
| 517 | return nullptr; |
| 518 | ArrayRef<uint8_t> payloadBytes; |
| 519 | if (typeReader.remaining() > 0) |
| 520 | payloadBytes = typeReader.readBytes(typeReader.remaining()); |
| 521 | Type parsedType; |
| 522 | if (failed(parseTypeImpl(typeTag, payloadBytes, parsedType))) |
| 523 | return Type(); |
| 524 | |
| 525 | // Cache the result. |
| 526 | typeCache[typeIndex] = parsedType; |
| 527 | return parsedType; |
| 528 | } |
| 529 | |
| 530 | size_t size() const { return typeStartIndices.size(); } |
| 531 |
no test coverage detected