Token debug function printOut() can now print out filename instead of index

This commit is contained in:
Reijo Tomperi 2009-11-28 00:04:04 +02:00
parent 2c51542cf1
commit 0bdf63d864
3 changed files with 32 additions and 4 deletions

View File

@ -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<std::string> fileNames;
std::cout << stringifyList(true, title, fileNames) << std::endl;
}
void Token::printOut(const char *title, const std::vector<std::string> &fileNames) const
{
std::cout << stringifyList(true, title, fileNames) << std::endl;
}
std::string Token::stringifyList(bool varid, const char *title) const
{
const std::vector<std::string> fileNames;
return stringifyList(varid, title, fileNames);
}
std::string Token::stringifyList(bool varid, const char *title, const std::vector<std::string> &fileNames) const
{
std::ostringstream ret;
if (title)
@ -626,7 +638,11 @@ std::string Token::stringifyList(bool varid, const char *title) const
}
fileIndex = static_cast<int>(tok->_fileIndex);
ret << "\n\n##file " << fileIndex << "";
ret << "\n\n##file ";
if (fileNames.size() > static_cast<unsigned int>(fileIndex))
ret << fileNames.at(fileIndex);
else
ret << fileIndex;
linenr = lineNumbers[fileIndex];
fileChange = true;

View File

@ -20,6 +20,7 @@
#define TokenH
#include <string>
#include <vector>
/// @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<std::string> &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<std::string> &fileNames) const;
/**
* This is intended to be used for the first token in the list

View File

@ -2164,7 +2164,7 @@ bool Tokenizer::simplifyTokenList()
simplifyComma();
if (_settings && _settings->_debug)
{
_tokens->printOut();
_tokens->printOut(0, _files);
}
return validate();