| 657 | static const std::string COMMENT_END("*/"); |
| 658 | |
| 659 | void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, OutputList *outputList) |
| 660 | { |
| 661 | std::stack<simplecpp::Location> loc; |
| 662 | |
| 663 | unsigned int multiline = 0U; |
| 664 | |
| 665 | const Token *oldLastToken = nullptr; |
| 666 | |
| 667 | Location location(fileIndex(filename), 1, 1); |
| 668 | while (stream.good()) { |
| 669 | unsigned char ch = stream.readChar(); |
| 670 | if (!stream.good()) |
| 671 | break; |
| 672 | |
| 673 | if (ch >= 0x80) { |
| 674 | if (outputList) { |
| 675 | simplecpp::Output err{ |
| 676 | simplecpp::Output::UNHANDLED_CHAR_ERROR, |
| 677 | location, |
| 678 | "The code contains unhandled character(s) (character code=" + std::to_string(static_cast<int>(ch)) + "). Neither unicode nor extended ascii is supported." |
| 679 | }; |
| 680 | outputList->emplace_back(std::move(err)); |
| 681 | } |
| 682 | clear(); |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | if (ch == '\n') { |
| 687 | if (cback() && cback()->op == '\\') { |
| 688 | if (location.col > cback()->location.col + 1U) |
| 689 | portabilityBackslash(outputList, cback()->location); |
| 690 | ++multiline; |
| 691 | deleteToken(back()); |
| 692 | } else { |
| 693 | location.line += multiline + 1; |
| 694 | multiline = 0U; |
| 695 | } |
| 696 | if (!multiline) |
| 697 | location.col = 1; |
| 698 | |
| 699 | if (oldLastToken != cback()) { |
| 700 | oldLastToken = cback(); |
| 701 | const Token * const llTok = isLastLinePreprocessor(); |
| 702 | if (!llTok) |
| 703 | continue; |
| 704 | const Token * const llNextToken = llTok->next; |
| 705 | if (!llTok->next) |
| 706 | continue; |
| 707 | if (llNextToken->next) { |
| 708 | // #file "file.c" |
| 709 | if (llNextToken->str() == "file" && |
| 710 | llNextToken->next->str()[0] == '\"') |
| 711 | { |
| 712 | const Token *strtok = cback(); |
| 713 | while (strtok->comment) |
| 714 | strtok = strtok->previous; |
| 715 | loc.push(location); |
| 716 | location.fileIndex = fileIndex(strtok->str().substr(1U, strtok->str().size() - 2U)); |
no test coverage detected