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

Method addClassFunction

lib/symboldatabase.cpp:3507–3680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3505}
3506
3507void SymbolDatabase::addClassFunction(Scope *&scope, const Token *&tok, const Token *argStart)
3508{
3509 const bool destructor(tok->strAt(-1) == "~");
3510 const bool has_const(argStart->link()->strAt(1) == "const");
3511 const bool lval(argStart->link()->strAt(has_const ? 2 : 1) == "&");
3512 const bool rval(argStart->link()->strAt(has_const ? 2 : 1) == "&&");
3513 int count = 0;
3514 std::string path;
3515 unsigned int path_length = 0;
3516 const Token *tok1 = tok;
3517
3518 if (destructor)
3519 tok1 = tok1->previous();
3520
3521 // back up to head of path
3522 while (tok1 && tok1->previous() && tok1->strAt(-1) == "::" && tok1->tokAt(-2) &&
3523 ((tok1->tokAt(-2)->isName() && !tok1->tokAt(-2)->isStandardType()) ||
3524 (tok1->strAt(-2) == ">" && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->previous(), "%name%")))) {
3525 count++;
3526 const Token * tok2 = tok1->tokAt(-2);
3527 if (tok2->str() == ">")
3528 tok2 = tok2->link()->previous();
3529
3530 if (tok2) {
3531 do {
3532 path = tok1->strAt(-1) + " " + path;
3533 tok1 = tok1->previous();
3534 path_length++;
3535 } while (tok1 != tok2);
3536 } else
3537 return; // syntax error ?
3538 }
3539
3540 // syntax error?
3541 if (!tok1)
3542 return;
3543
3544 // add global namespace if present
3545 if (tok1->strAt(-1) == "::") {
3546 path_length++;
3547 path.insert(0, ":: ");
3548 }
3549
3550 // search for match
3551 for (auto it1 = scopeList.begin(); it1 != scopeList.end(); ++it1) {
3552 Scope *scope1 = &(*it1);
3553
3554 bool match = false;
3555
3556 // check in namespace if using found
3557 if (scope == scope1 && !scope1->usingList.empty()) {
3558 for (auto it2 = scope1->usingList.cbegin(); it2 != scope1->usingList.cend(); ++it2) {
3559 if (it2->scope) {
3560 Function * func = findFunctionInScope(tok1, it2->scope, path, path_length);
3561 if (func) {
3562 if (!func->hasBody()) {
3563 const Token *closeParen = tok->linkAt(1);
3564 if (closeParen) {

Callers

nothing calls this directly

Calls 12

linkAtMethod · 0.80
argsMatchMethod · 0.80
nextMethod · 0.80
isConstMethod · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45
isStandardTypeMethod · 0.45
strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected