diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 54a276968..9cafc677c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -225,15 +225,17 @@ void Tokenizer::insertTokens(Token *dest, const Token *src, unsigned int n) //--------------------------------------------------------------------------- -Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last) +Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last, bool one_line) { std::stack links; Token *tok2 = dest; + unsigned int linenrs = dest->linenr(); + unsigned int commonFileIndex = dest->fileIndex(); for (const Token *tok = first; tok != last->next(); tok = tok->next()) { tok2->insertToken(tok->str()); tok2 = tok2->next(); - tok2->fileIndex(dest->fileIndex()); - tok2->linenr(dest->linenr()); + tok2->fileIndex(commonFileIndex); + tok2->linenr(linenrs); tok2->isName(tok->isName()); tok2->isNumber(tok->isNumber()); tok2->isBoolean(tok->isBoolean()); @@ -256,6 +258,8 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last) links.pop(); } + if (!one_line && tok->next()) + linenrs += tok->next()->linenr() - tok->linenr(); } return tok2; } diff --git a/lib/tokenize.h b/lib/tokenize.h index 07f0093d5..ec3a6ae74 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -557,7 +557,7 @@ public: * @param last last token to copy * @return new location of last token copied */ - Token *copyTokens(Token *dest, const Token *first, const Token *last); + Token *copyTokens(Token *dest, const Token *first, const Token *last, bool one_line = true); /** * Send error message to error logger about internal bug.