| 565 | } |
| 566 | |
| 567 | std::string simplecpp::TokenList::stringify(bool linenrs) const |
| 568 | { |
| 569 | std::ostringstream ret; |
| 570 | Location loc; |
| 571 | loc.line = 1; |
| 572 | bool filechg = true; |
| 573 | for (const Token *tok = cfront(); tok; tok = tok->next) { |
| 574 | if (tok->location.line < loc.line || tok->location.fileIndex != loc.fileIndex) { |
| 575 | ret << "\n#line " << tok->location.line << " \"" << file(tok->location) << "\"\n"; |
| 576 | loc = tok->location; |
| 577 | filechg = true; |
| 578 | } |
| 579 | |
| 580 | if (linenrs && filechg) { |
| 581 | ret << loc.line << ": "; |
| 582 | filechg = false; |
| 583 | } |
| 584 | |
| 585 | while (tok->location.line > loc.line) { |
| 586 | ret << '\n'; |
| 587 | loc.line++; |
| 588 | if (linenrs) |
| 589 | ret << loc.line << ": "; |
| 590 | } |
| 591 | |
| 592 | if (sameline(tok->previous, tok)) |
| 593 | ret << ' '; |
| 594 | |
| 595 | ret << tok->str(); |
| 596 | |
| 597 | loc.adjust(tok->str()); |
| 598 | } |
| 599 | |
| 600 | return ret.str(); |
| 601 | } |
| 602 | |
| 603 | static bool isNameChar(int ch) |
| 604 | { |