3030#include < fstream>
3131#include < iostream>
3232#include < istream>
33+ #include < iterator>
3334#include < limits>
3435#include < list>
3536#include < map>
@@ -290,7 +291,6 @@ void simplecpp::Token::printOut() const
290291 std::cout << std::endl;
291292}
292293
293- // cppcheck-suppress noConstructor - we call init() in the inherited to initialize the private members
294294class simplecpp ::TokenList::Stream {
295295public:
296296 virtual ~Stream () = default ;
@@ -424,7 +424,7 @@ class simplecpp::TokenList::Stream {
424424 return 0 ;
425425 }
426426
427- unsigned short bom;
427+ unsigned short bom{ 0 } ;
428428
429429 /* * characters that are read but not used yet. The next character is at the back. */
430430 std::string buffer;
@@ -435,13 +435,12 @@ class simplecpp::TokenList::Stream {
435435 /* * get() has returned EOF */
436436 bool inputEnd{false };
437437protected:
438- bool isUtf16;
438+ bool isUtf16{ false } ;
439439};
440440
441441namespace {
442- class StdIStream : public simplecpp ::TokenList::Stream {
442+ class StdIStream final : public simplecpp::TokenList::Stream {
443443 public:
444- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
445444 explicit StdIStream (std::istream &istr)
446445 : istr(istr) {
447446 assert (istr.good ());
@@ -463,9 +462,8 @@ namespace {
463462 std::istream &istr;
464463 };
465464
466- class StdCharBufStream : public simplecpp ::TokenList::Stream {
465+ class StdCharBufStream final : public simplecpp::TokenList::Stream {
467466 public:
468- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
469467 StdCharBufStream (const unsigned char * str, std::size_t size)
470468 : str(str)
471469 , size(size)
@@ -494,12 +492,11 @@ namespace {
494492 std::size_t pos{};
495493 };
496494
497- class FileStream : public simplecpp ::TokenList::Stream {
495+ class FileStream final : public simplecpp::TokenList::Stream {
498496 public:
499497 /* *
500498 * @throws simplecpp::Output thrown if file is not found
501499 */
502- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
503500 explicit FileStream (const std::string &filename, std::vector<std::string> &files)
504501 : file(fopen(filename.c_str(), "rb"))
505502 {
@@ -859,7 +856,7 @@ static simplecpp::TokenString readLineComment(simplecpp::TokenList::Stream &stre
859856 return currentToken;
860857}
861858
862- simplecpp::TokenString simplecpp::TokenList::readBlockComment (Stream &stream, unsigned int &multiline)
859+ simplecpp::TokenString simplecpp::TokenList::readBlockComment (Stream &stream, unsigned int &multiline) const
863860{
864861 TokenString currentToken = " /*" ;
865862 (void )stream.readChar ();
@@ -1844,10 +1841,11 @@ const simplecpp::Token* simplecpp::TokenList::isLastLinePreprocessor(int maxsize
18441841
18451842unsigned int simplecpp::TokenList::fileIndex (const std::string &filename)
18461843{
1847- for (unsigned int i = 0 ; i < files.size (); ++i) {
1848- if (files[i] == filename)
1849- return i;
1850- }
1844+ const auto it = std::find_if (files.cbegin (), files.cend (), [&filename](const std::string &f) {
1845+ return f == filename;
1846+ });
1847+ if (it != files.cend ())
1848+ return static_cast <unsigned int >(std::distance (files.cbegin (), it));
18511849 files.emplace_back (filename);
18521850 return files.size () - 1U ;
18531851}
@@ -2675,16 +2673,16 @@ namespace simplecpp {
26752673
26762674 /* * Expand while the expansion result in @p temp ends with the name of a
26772675 * function-like macro whose arguments are supplied by the tokens after @p tok.
2678- * Each round consumes that macro call from the token stream. The @p gatherCall
2676+ * Each round consumes that macro call from the token stream. The @p gather
26792677 * callback copies the macro name and its call into its list and returns the
26802678 * last token of the call, or nullptr when no complete call is available (see
26812679 * gatherCall and gatherCallAfter). Returns the first token that was not
26822680 * consumed (tok->next when no call was expanded). */
26832681 template <class GatherCall >
2684- const Token *expandTrailingCalls (TokenList &output, TokenList &temp, const Location &loc, const Token *tok, const MacroMap ¯os, const std::set<TokenString> &expandedmacros, OutputList *outputList, GatherCall gatherCall ) const {
2682+ const Token *expandTrailingCalls (TokenList &output, TokenList &temp, const Location &loc, const Token *tok, const MacroMap ¯os, const std::set<TokenString> &expandedmacros, OutputList *outputList, GatherCall gather ) const {
26852683 while (const Macro * const calledMacro = callableMacro (temp.cback (), macros, expandedmacros)) {
26862684 TokenList call (files);
2687- const Token * const last = gatherCall (call, temp.cback (), tok);
2685+ const Token * const last = gather (call, temp.cback (), tok);
26882686 if (!last)
26892687 break ;
26902688 output.takeTokens (temp);
@@ -3926,7 +3924,7 @@ std::pair<simplecpp::FileData *, bool> simplecpp::FileDataCache::tryload(FileDat
39263924 return {id_it->second , false };
39273925 }
39283926
3929- auto *const data = new FileData {path, TokenList (path, filenames, {} , outputList)};
3927+ auto *const data = new FileData {path, TokenList (path, filenames, dui , outputList)};
39303928
39313929 if (dui.removeComments )
39323930 data->tokens .removeComments ();
0 commit comments