diff --git a/lib/token.cpp b/lib/token.cpp index a561ebe6c..52b1ab255 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -603,10 +603,22 @@ void Token::createMutualLinks(Token *begin, Token *end) void Token::printOut(const char *title) const { - std::cout << stringifyList(true, title) << std::endl; + const std::vector fileNames; + std::cout << stringifyList(true, title, fileNames) << std::endl; +} + +void Token::printOut(const char *title, const std::vector &fileNames) const +{ + std::cout << stringifyList(true, title, fileNames) << std::endl; } std::string Token::stringifyList(bool varid, const char *title) const +{ + const std::vector fileNames; + return stringifyList(varid, title, fileNames); +} + +std::string Token::stringifyList(bool varid, const char *title, const std::vector &fileNames) const { std::ostringstream ret; if (title) @@ -626,7 +638,11 @@ std::string Token::stringifyList(bool varid, const char *title) const } fileIndex = static_cast(tok->_fileIndex); - ret << "\n\n##file " << fileIndex << ""; + ret << "\n\n##file "; + if (fileNames.size() > static_cast(fileIndex)) + ret << fileNames.at(fileIndex); + else + ret << fileIndex; linenr = lineNumbers[fileIndex]; fileChange = true; diff --git a/lib/token.h b/lib/token.h index cfe5ba0f1..e278f3e42 100644 --- a/lib/token.h +++ b/lib/token.h @@ -20,6 +20,7 @@ #define TokenH #include +#include /// @addtogroup Core /// @{ @@ -220,6 +221,16 @@ public: */ void printOut(const char *title = 0) const; + /** + * For debugging purposes, prints token and all tokens + * followed by it. + * @param title Title for the printout or use default parameter or 0 + * for no title. + * @param fileNames Prints out file name instead of file index. + * File index should match the index of the string in this vector. + */ + void printOut(const char *title, const std::vector &fileNames) const; + /** * Replace token replaceThis with tokens between start and end, * including start and end. The replaceThis token is deleted. @@ -230,7 +241,8 @@ public: static void replace(Token *replaceThis, Token *start, Token *end); /** Stringify a token list (with or without varId) */ - std::string stringifyList(bool varid = true, const char *title = 0) const; + std::string stringifyList(bool varid = 0, const char *title = 0) const; + std::string stringifyList(bool varid, const char *title, const std::vector &fileNames) const; /** * This is intended to be used for the first token in the list diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a331415fb..da14810c9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2164,7 +2164,7 @@ bool Tokenizer::simplifyTokenList() simplifyComma(); if (_settings && _settings->_debug) { - _tokens->printOut(); + _tokens->printOut(0, _files); } return validate();