| 523 | |
| 524 | |
| 525 | vector<DisassemblyTextLine> GenericLineFormatter::FormatLines( |
| 526 | const vector<DisassemblyTextLine>& lines, const LineFormatterSettings& settings) |
| 527 | { |
| 528 | vector<DisassemblyTextLine> result; |
| 529 | for (size_t i = 0; i < lines.size(); i++) |
| 530 | { |
| 531 | const DisassemblyTextLine& currentLine = lines[i]; |
| 532 | |
| 533 | size_t totalLength = currentLine.GetTotalWidth(); |
| 534 | size_t indentation = currentLine.GetAddressAndIndentationWidth(); |
| 535 | |
| 536 | // Check width against settings |
| 537 | size_t contentLength = totalLength - indentation; |
| 538 | if (totalLength <= settings.desiredLineLength || contentLength <= settings.minimumContentLength) |
| 539 | { |
| 540 | // Line fits, emit as-is |
| 541 | result.push_back(currentLine); |
| 542 | continue; |
| 543 | } |
| 544 | |
| 545 | // Calculate indentation for continuation lines. If the next line in the input is more indented, make |
| 546 | // the continuation lines more indented than that to separate the continuation from the new scope. |
| 547 | size_t continuationIndentation = indentation + settings.tabWidth; |
| 548 | if ((i + 1) < lines.size()) |
| 549 | { |
| 550 | size_t nextLineIndentation = lines[i + 1].GetAddressAndIndentationWidth(); |
| 551 | if (nextLineIndentation > indentation) |
| 552 | continuationIndentation = nextLineIndentation + settings.tabWidth; |
| 553 | } |
| 554 | size_t additionalContinuationIndentation = continuationIndentation - indentation; |
| 555 | |
| 556 | // Compute the target length for this line |
| 557 | size_t desiredWidth = settings.minimumContentLength; |
| 558 | if (indentation < settings.desiredLineLength) |
| 559 | { |
| 560 | size_t remainingWidth = settings.desiredLineLength - indentation; |
| 561 | if (remainingWidth > desiredWidth) |
| 562 | desiredWidth = remainingWidth; |
| 563 | } |
| 564 | |
| 565 | // Compute the target length for the continuation lines |
| 566 | size_t desiredContinuationWidth = settings.minimumContentLength; |
| 567 | if (continuationIndentation < settings.desiredLineLength) |
| 568 | { |
| 569 | size_t remainingWidth = settings.desiredLineLength - continuationIndentation; |
| 570 | if (remainingWidth > desiredContinuationWidth) |
| 571 | desiredContinuationWidth = remainingWidth; |
| 572 | } |
| 573 | |
| 574 | // Gather the indentation tokens at the beginning of the line |
| 575 | vector<InstructionTextToken> indentationTokens = currentLine.GetAddressAndIndentationTokens(); |
| 576 | size_t tokenIndex = indentationTokens.size(); |
| 577 | |
| 578 | // First break the line down into nested container items. A container is anything between a pair of |
| 579 | // BraceTokens (except for strings, where the entire string, including the quotes, are treated as |
| 580 | // a single atom). |
| 581 | vector<Item> items; |
| 582 | stack<vector<Item>> itemStack; |
nothing calls this directly
no test coverage detected