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

Method setLocations

lib/clangimport.cpp:552–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

550}
551
552void clangimport::AstNode::setLocations(TokenList &tokenList, int file, int line, int col)
553{
554 if (mExtTokens.size() >= 2)
555 {
556 const std::string &ext = mExtTokens[1];
557 if (startsWith(ext, "<col:"))
558 col = strToInt<int>(ext.substr(5, ext.find_first_of(",>", 5) - 5));
559 else if (startsWith(ext, "<line:")) {
560 line = strToInt<int>(ext.substr(6, ext.find_first_of(":,>", 6) - 6));
561 const auto pos = ext.find(", col:");
562 if (pos != std::string::npos)
563 col = strToInt<int>(ext.substr(pos+6, ext.find_first_of(":,>", pos+6) - (pos+6)));
564 } else if (ext[0] == '<') {
565 const std::string::size_type colon = ext.find(':');
566 if (colon != std::string::npos) {
567 const bool windowsPath = colon == 2 && ext.size() > 3 && ext[2] == ':';
568 const std::string::size_type sep1 = windowsPath ? ext.find(':', 4) : colon;
569 const std::string::size_type sep2 = ext.find(':', sep1 + 1);
570 file = tokenList.appendFileIfNew(ext.substr(1, sep1 - 1));
571 line = strToInt<int>(ext.substr(sep1 + 1, sep2 - sep1 - 1));
572 }
573 else {
574 // "<invalid sloc>" are encountered in every AST dump by some built-in TypedefDecl
575 // an completely empty location block was encountered with a CompoundStmt
576 if (ext != "<<invalid sloc>" && ext != "<>")
577 throw InternalError(nullptr, "invalid AST location: " + ext, InternalError::AST);
578 }
579 }
580 }
581 mFile = file;
582 mLine = line;
583 mCol = col;
584 for (const auto& child: children) {
585 if (child)
586 child->setLocations(tokenList, file, line, col);
587 }
588}
589
590Token *clangimport::AstNode::addtoken(TokenList &tokenList, const std::string &str, bool valueType)
591{

Callers

nothing calls this directly

Calls 4

appendFileIfNewMethod · 0.80
startsWithFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected