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

Method createTokens

lib/tokenlist.cpp:367–416  ·  view source on GitHub ↗

NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)

Source from the content-addressed store, hash-verified

365
366// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
367void TokenList::createTokens(simplecpp::TokenList&& tokenList)
368{
369 // TODO: what to do if the list has been filled already? clear mTokensFrontBack?
370
371 // tokenList.cfront() might be NULL if the file contained nothing to tokenize so we need to check the files instead
372 if (!tokenList.getFiles().empty()) {
373 // this is a copy
374 // TODO: this points to mFiles when called from createTokens(std::istream &, const std::string&)
375 mOrigFiles = mFiles = tokenList.getFiles();
376 }
377 else {
378 // TODO: clear mOrigFiles?
379 mFiles.clear();
380 }
381
382 for (const simplecpp::Token *tok = tokenList.cfront(); tok;) {
383
384 // TODO: move from TokenList
385 std::string str = tok->str();
386
387 // Float literal
388 if (str.size() > 1 && str[0] == '.' && std::isdigit(str[1]))
389 str = '0' + str;
390
391 if (mTokensFrontBack->back) {
392 mTokensFrontBack->back->insertToken(str);
393 } else {
394 mTokensFrontBack->front = new Token(*this, mTokensFrontBack);
395 mTokensFrontBack->back = mTokensFrontBack->front;
396 mTokensFrontBack->back->str(str);
397 }
398
399 mTokensFrontBack->back->fileIndex(tok->location.fileIndex);
400 mTokensFrontBack->back->linenr(tok->location.line);
401 mTokensFrontBack->back->column(tok->location.col);
402 if (!tok->macro.empty())
403 mTokensFrontBack->back->setMacroName(tok->macro);
404
405 tok = tok->next;
406 if (tok)
407 tokenList.deleteToken(tok->previous);
408 }
409
410 if (mSettings.relativePaths) {
411 for (std::string & mFile : mFiles)
412 mFile = Path::getRelativePath(mFile, mSettings.basePaths);
413 }
414
415 Token::assignProgressValues(mTokensFrontBack->front);
416}
417
418//---------------------------------------------------------------------------
419

Callers 4

checkInternalMethod · 0.45
preprocessMethod · 0.45
notokensMethod · 0.45
preprocessMethod · 0.45

Calls 8

insertTokenMethod · 0.80
fileIndexMethod · 0.80
columnMethod · 0.80
deleteTokenMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45

Tested by 2

preprocessMethod · 0.36
notokensMethod · 0.36