Small optimization in checkmemoryleak.cpp: Allow passing literals to addtoken()
Ran AStyle
This commit is contained in:
parent
7ef714b0c6
commit
4d549553b0
|
@ -426,42 +426,42 @@ bool isWithoutSideEffects(bool cpp, const Token* tok)
|
||||||
|
|
||||||
bool isUniqueExpression(const Token* tok)
|
bool isUniqueExpression(const Token* tok)
|
||||||
{
|
{
|
||||||
if(!tok)
|
if (!tok)
|
||||||
return true;
|
return true;
|
||||||
if(tok->function()) {
|
if (tok->function()) {
|
||||||
const Function * fun = tok->function();
|
const Function * fun = tok->function();
|
||||||
const Scope * scope = fun->nestedIn;
|
const Scope * scope = fun->nestedIn;
|
||||||
if(!scope)
|
if (!scope)
|
||||||
return true;
|
return true;
|
||||||
for(const Function& f:scope->functionList) {
|
for (const Function& f:scope->functionList) {
|
||||||
if(f.argumentList.size() == fun->argumentList.size() && f.name() != fun->name()) {
|
if (f.argumentList.size() == fun->argumentList.size() && f.name() != fun->name()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(tok->variable()) {
|
} else if (tok->variable()) {
|
||||||
const Variable * var = tok->variable();
|
const Variable * var = tok->variable();
|
||||||
const Scope * scope = var->scope();
|
const Scope * scope = var->scope();
|
||||||
if(!scope)
|
if (!scope)
|
||||||
return true;
|
return true;
|
||||||
const Type * varType = var->type();
|
const Type * varType = var->type();
|
||||||
// Iterate over the variables in scope and the parameters of the function if possible
|
// Iterate over the variables in scope and the parameters of the function if possible
|
||||||
const Function * fun = scope->function;
|
const Function * fun = scope->function;
|
||||||
const std::list<Variable>* setOfVars[] = {&scope->varlist, fun ? &fun->argumentList : nullptr};
|
const std::list<Variable>* setOfVars[] = {&scope->varlist, fun ? &fun->argumentList : nullptr};
|
||||||
if (varType) {
|
if (varType) {
|
||||||
for(const std::list<Variable>* vars:setOfVars) {
|
for (const std::list<Variable>* vars:setOfVars) {
|
||||||
if(!vars)
|
if (!vars)
|
||||||
continue;
|
continue;
|
||||||
for(const Variable& v:*vars) {
|
for (const Variable& v:*vars) {
|
||||||
if (v.type() && v.type()->name() == varType->name() && v.name() != var->name()) {
|
if (v.type() && v.type()->name() == varType->name() && v.name() != var->name()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(const std::list<Variable>* vars:setOfVars) {
|
for (const std::list<Variable>* vars:setOfVars) {
|
||||||
if(!vars)
|
if (!vars)
|
||||||
continue;
|
continue;
|
||||||
for(const Variable& v:*vars) {
|
for (const Variable& v:*vars) {
|
||||||
if (v.isFloatingType() == var->isFloatingType() &&
|
if (v.isFloatingType() == var->isFloatingType() &&
|
||||||
v.isEnumType() == var->isEnumType() &&
|
v.isEnumType() == var->isEnumType() &&
|
||||||
v.isClass() == var->isClass() &&
|
v.isClass() == var->isClass() &&
|
||||||
|
@ -472,7 +472,7 @@ bool isUniqueExpression(const Token* tok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(!isUniqueExpression(tok->astOperand1())) {
|
} else if (!isUniqueExpression(tok->astOperand1())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -671,8 +671,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
||||||
return (eq || _settings->experimental) ? nullptr : "callfunc";
|
return (eq || _settings->experimental) ? nullptr : "callfunc";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
static void addtoken(Token **rettail, const Token *tok, const std::string &str)
|
static void addtoken(Token **rettail, const Token *tok, T&& str)
|
||||||
{
|
{
|
||||||
(*rettail)->insertToken(str);
|
(*rettail)->insertToken(str);
|
||||||
(*rettail) = (*rettail)->next();
|
(*rettail) = (*rettail)->next();
|
||||||
|
|
|
@ -860,16 +860,16 @@ private:
|
||||||
|
|
||||||
void tokenize37() { // #8550
|
void tokenize37() { // #8550
|
||||||
const char codeC[] = "class name { public: static void init ( ) {} } ; "
|
const char codeC[] = "class name { public: static void init ( ) {} } ; "
|
||||||
"typedef class name N; "
|
"typedef class name N; "
|
||||||
"void foo ( ) { return N :: init ( ) ; }";
|
"void foo ( ) { return N :: init ( ) ; }";
|
||||||
const char expC [] = "class name { public: static void init ( ) { } } ; "
|
const char expC [] = "class name { public: static void init ( ) { } } ; "
|
||||||
"void foo ( ) { return name :: init ( ) ; }";
|
"void foo ( ) { return name :: init ( ) ; }";
|
||||||
ASSERT_EQUALS(expC, tokenizeAndStringify(codeC));
|
ASSERT_EQUALS(expC, tokenizeAndStringify(codeC));
|
||||||
const char codeS[] = "class name { public: static void init ( ) {} } ; "
|
const char codeS[] = "class name { public: static void init ( ) {} } ; "
|
||||||
"typedef struct name N; "
|
"typedef struct name N; "
|
||||||
"void foo ( ) { return N :: init ( ) ; }";
|
"void foo ( ) { return N :: init ( ) ; }";
|
||||||
const char expS [] = "class name { public: static void init ( ) { } } ; "
|
const char expS [] = "class name { public: static void init ( ) { } } ; "
|
||||||
"void foo ( ) { return name :: init ( ) ; }";
|
"void foo ( ) { return name :: init ( ) ; }";
|
||||||
ASSERT_EQUALS(expS, tokenizeAndStringify(codeS));
|
ASSERT_EQUALS(expS, tokenizeAndStringify(codeS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue