| 293 | //--------------------------------------------------------------------------- |
| 294 | |
| 295 | void TokenList::insertTokens(Token *dest, const Token *src, nonneg int n) |
| 296 | { |
| 297 | // TODO: put the linking in a helper? |
| 298 | std::stack<Token *> link; |
| 299 | |
| 300 | while (n > 0) { |
| 301 | if (!src) |
| 302 | throw InternalError(dest, std::string(__func__) + ": invalid source range", InternalError::INTERNAL); |
| 303 | dest->insertToken(src->str(), src->originalName()); |
| 304 | dest = dest->next(); |
| 305 | |
| 306 | // Set links |
| 307 | if (Token::Match(dest, "(|[|{")) |
| 308 | link.push(dest); |
| 309 | else if (!link.empty() && Token::Match(dest, ")|]|}")) { |
| 310 | Token::createMutualLinks(dest, link.top()); |
| 311 | link.pop(); |
| 312 | } |
| 313 | |
| 314 | dest->fileIndex(src->fileIndex()); |
| 315 | dest->linenr(src->linenr()); |
| 316 | dest->column(src->column()); |
| 317 | dest->varId(src->varId()); |
| 318 | dest->tokType(src->tokType()); |
| 319 | dest->flags(src->flags()); |
| 320 | if (!src->getMacroName().empty()) |
| 321 | dest->setMacroName(src->getMacroName()); |
| 322 | src = src->next(); |
| 323 | --n; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | //--------------------------------------------------------------------------- |
| 328 | |