MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / readfile

Method readfile

externals/simplecpp/simplecpp.cpp:659–979  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

657static const std::string COMMENT_END("*/");
658
659void 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));

Callers 1

MacroMethod · 0.80

Calls 15

fileIndexFunction · 0.85
cbackFunction · 0.85
portabilityBackslashFunction · 0.85
deleteTokenFunction · 0.85
replaceAllFunction · 0.85
isNameCharFunction · 0.85
isStringLiteralPrefixFunction · 0.85
escapeStringFunction · 0.85
readCharMethod · 0.80
ungetCharMethod · 0.80
adjustMethod · 0.80
peekCharMethod · 0.80

Tested by

no test coverage detected