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

Function setScopeInfo

lib/tokenize.cpp:2548–2688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2546 };
2547
2548 void setScopeInfo(Token *tok, ScopeInfo3 *&scopeInfo, bool debug=false)
2549 {
2550 if (!tok)
2551 return;
2552 if (tok->str() == "{" && scopeInfo->parent && tok == scopeInfo->bodyStart)
2553 return;
2554 if (tok->str() == "}") {
2555 if (scopeInfo->parent && tok == scopeInfo->bodyEnd)
2556 scopeInfo = scopeInfo->parent;
2557 else {
2558 // Try to find parent scope
2559 ScopeInfo3 *parent = scopeInfo->parent;
2560 while (parent && parent->bodyEnd != tok)
2561 parent = parent->parent;
2562 if (parent) {
2563 scopeInfo = parent;
2564 if (debug)
2565 throw std::runtime_error("Internal error: unmatched }");
2566 }
2567 }
2568 return;
2569 }
2570 if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) {
2571 // check for using namespace
2572 if (Token::Match(tok, "using namespace %name% ;|::")) {
2573 const Token * tok1 = tok->tokAt(2);
2574 std::string nameSpace;
2575 while (tok1 && tok1->str() != ";") {
2576 if (!nameSpace.empty())
2577 nameSpace += " ";
2578 nameSpace += tok1->str();
2579 tok1 = tok1->next();
2580 }
2581 scopeInfo->usingNamespaces.insert(std::move(nameSpace));
2582 }
2583 // check for member function
2584 else if (tok->str() == "{") {
2585 bool added = false;
2586 Token *tok1 = tok;
2587 while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
2588 tok1 = tok1->previous();
2589 if (tok1->previous() && (tok1->strAt(-1) == ")" || tok->strAt(-1) == "}")) {
2590 tok1 = tok1->linkAt(-1);
2591 if (Token::Match(tok1->previous(), "throw|noexcept (")) {
2592 tok1 = tok1->previous();
2593 while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))
2594 tok1 = tok1->previous();
2595 if (tok1->strAt(-1) != ")")
2596 return;
2597 tok1 = tok1->linkAt(-1);
2598 } else {
2599 while (Token::Match(tok1->tokAt(-2), ":|, %name%")) {
2600 tok1 = tok1->tokAt(-2);
2601 if (tok1->strAt(-1) != ")" && tok1->strAt(-1) != "}")
2602 return;
2603 tok1 = tok1->linkAt(-1);
2604 }
2605 }

Callers 1

simplifyUsingMethod · 0.85

Calls 8

nextMethod · 0.80
linkAtMethod · 0.80
findOpeningBracketMethod · 0.80
strMethod · 0.45
tokAtMethod · 0.45
emptyMethod · 0.45
addChildMethod · 0.45
findClosingBracketMethod · 0.45

Tested by

no test coverage detected