MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / copyTokens

Method copyTokens

lib/tokenlist.cpp:255–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253//---------------------------------------------------------------------------
254
255Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last, bool one_line)
256{
257 std::stack<Token *> links;
258 Token *tok2 = dest;
259 int linenr = dest->linenr();
260 const int commonFileIndex = dest->fileIndex();
261 for (const Token *tok = first; tok != last->next(); tok = tok->next()) {
262 tok2->insertToken(tok->str());
263 tok2 = tok2->next();
264 tok2->fileIndex(commonFileIndex);
265 tok2->linenr(linenr);
266 tok2->tokType(tok->tokType());
267 tok2->flags(tok->flags());
268 tok2->varId(tok->varId());
269 tok2->setTokenDebug(tok->getTokenDebug());
270
271 // Check for links and fix them up
272 if (Token::Match(tok2, "(|[|{"))
273 links.push(tok2);
274 else if (Token::Match(tok2, ")|]|}")) {
275 if (links.empty())
276 return tok2;
277
278 Token * link = links.top();
279
280 tok2->link(link);
281 link->link(tok2);
282
283 links.pop();
284 }
285 if (!one_line && tok->next())
286 linenr += tok->next()->linenr() - tok->linenr();
287 }
288 return tok2;
289}
290
291//---------------------------------------------------------------------------
292// InsertTokens - Copy and insert tokens

Callers

nothing calls this directly

Calls 5

fileIndexMethod · 0.80
nextMethod · 0.80
insertTokenMethod · 0.80
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected