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,6 +424,7 @@ class simplecpp::TokenList::Stream {
424424 return 0 ;
425425 }
426426
427+ // cppcheck-suppress uninitMemberVarPrivate - FP this class is a abstract base class and its members are initialized in init()
427428 unsigned short bom;
428429
429430 /* * characters that are read but not used yet. The next character is at the back. */
@@ -435,11 +436,12 @@ class simplecpp::TokenList::Stream {
435436 /* * get() has returned EOF */
436437 bool inputEnd{false };
437438protected:
439+ // cppcheck-suppress uninitMemberVarNoCtor - FP this class is a abstract base class and its members are initialized in init()
438440 bool isUtf16;
439441};
440442
441443namespace {
442- class StdIStream : public simplecpp ::TokenList::Stream {
444+ class StdIStream final : public simplecpp::TokenList::Stream {
443445 public:
444446 // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
445447 explicit StdIStream (std::istream &istr)
@@ -463,7 +465,7 @@ namespace {
463465 std::istream &istr;
464466 };
465467
466- class StdCharBufStream : public simplecpp ::TokenList::Stream {
468+ class StdCharBufStream final : public simplecpp::TokenList::Stream {
467469 public:
468470 // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
469471 StdCharBufStream (const unsigned char * str, std::size_t size)
@@ -494,7 +496,7 @@ namespace {
494496 std::size_t pos{};
495497 };
496498
497- class FileStream : public simplecpp ::TokenList::Stream {
499+ class FileStream final : public simplecpp::TokenList::Stream {
498500 public:
499501 /* *
500502 * @throws simplecpp::Output thrown if file is not found
@@ -859,7 +861,7 @@ static simplecpp::TokenString readLineComment(simplecpp::TokenList::Stream &stre
859861 return currentToken;
860862}
861863
862- simplecpp::TokenString simplecpp::TokenList::readBlockComment (Stream &stream, unsigned int &multiline)
864+ simplecpp::TokenString simplecpp::TokenList::readBlockComment (Stream &stream, unsigned int &multiline) const
863865{
864866 TokenString currentToken = " /*" ;
865867 (void )stream.readChar ();
@@ -1844,10 +1846,11 @@ const simplecpp::Token* simplecpp::TokenList::isLastLinePreprocessor(int maxsize
18441846
18451847unsigned int simplecpp::TokenList::fileIndex (const std::string &filename)
18461848{
1847- for (unsigned int i = 0 ; i < files.size (); ++i) {
1848- if (files[i] == filename)
1849- return i;
1850- }
1849+ const auto it = std::find_if (files.cbegin (), files.cend (), [&filename](const std::string &f) {
1850+ return f == filename;
1851+ });
1852+ if (it != files.cend ())
1853+ return static_cast <unsigned int >(std::distance (files.cbegin (), it));
18511854 files.emplace_back (filename);
18521855 return files.size () - 1U ;
18531856}
@@ -2675,16 +2678,16 @@ namespace simplecpp {
26752678
26762679 /* * Expand while the expansion result in @p temp ends with the name of a
26772680 * 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
2681+ * Each round consumes that macro call from the token stream. The @p gather
26792682 * callback copies the macro name and its call into its list and returns the
26802683 * last token of the call, or nullptr when no complete call is available (see
26812684 * gatherCall and gatherCallAfter). Returns the first token that was not
26822685 * consumed (tok->next when no call was expanded). */
26832686 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 {
2687+ 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 {
26852688 while (const Macro * const calledMacro = callableMacro (temp.cback (), macros, expandedmacros)) {
26862689 TokenList call (files);
2687- const Token * const last = gatherCall (call, temp.cback (), tok);
2690+ const Token * const last = gather (call, temp.cback (), tok);
26882691 if (!last)
26892692 break ;
26902693 output.takeTokens (temp);
0 commit comments