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

Function getEndOfVarScope

lib/valueflow.cpp:1893–1914  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1891}
1892
1893static const Token* getEndOfVarScope(const Variable* var)
1894{
1895 if (!var)
1896 return nullptr;
1897 const Scope* innerScope = var->scope();
1898 const Scope* outerScope = innerScope;
1899 if (var->typeStartToken() && var->typeStartToken()->scope())
1900 outerScope = var->typeStartToken()->scope();
1901 if (!innerScope && outerScope)
1902 innerScope = outerScope;
1903 if (!innerScope || !outerScope)
1904 return nullptr;
1905 if (!innerScope->isExecutable())
1906 return nullptr;
1907 // If the variable is defined in a for/while initializer then we want to
1908 // pick one token after the end so forward analysis can analyze the exit
1909 // conditions
1910 if (innerScope != outerScope && outerScope->isExecutable() && innerScope->isLoopScope() &&
1911 !isRangeForScope(innerScope))
1912 return innerScope->bodyEnd->next();
1913 return innerScope->bodyEnd;
1914}
1915
1916const Token* ValueFlow::getEndOfExprScope(const Token* tok, const Scope* defaultScope, bool smallest)
1917{

Callers 1

getEndOfExprScopeMethod · 0.85

Calls 3

isRangeForScopeFunction · 0.85
scopeMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected