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

Method findFunction1

test/testsymboldatabase.cpp:7165–7192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7163
7164
7165 void findFunction1() {
7166 GET_SYMBOL_DB("int foo(int x);\n" /* 1 */
7167 "void foo();\n" /* 2 */
7168 "void bar() {\n" /* 3 */
7169 " foo();\n" /* 4 */
7170 " foo(1);\n" /* 5 */
7171 "}"); /* 6 */
7172 ASSERT_EQUALS("", errout_str());
7173 ASSERT(db);
7174 const Scope * bar = db->findScopeByName("bar");
7175 ASSERT(bar != nullptr);
7176 constexpr unsigned int linenrs[2] = { 2, 1 };
7177 unsigned int index = 0;
7178 for (const Token * tok = bar->bodyStart->next(); tok != bar->bodyEnd; tok = tok->next()) {
7179 if (Token::Match(tok, "%name% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) {
7180 const Function * function = db->findFunction(tok);
7181 ASSERT(function != nullptr);
7182 if (function) {
7183 std::stringstream expected;
7184 expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl;
7185 std::stringstream actual;
7186 actual << "Function call on line " << tok->linenr() << " calls function on line " << function->tokenDef->linenr() << std::endl;
7187 ASSERT_EQUALS(expected.str(), actual.str());
7188 }
7189 index++;
7190 }
7191 }
7192 }
7193
7194 void findFunction2() {
7195 // The function does not match the function call.

Callers

nothing calls this directly

Calls 6

findScopeByNameMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
findFunctionMethod · 0.80
simpleMatchFunction · 0.50
strMethod · 0.45

Tested by

no test coverage detected