Refactorization: Make use of Function::retDef where it makes sense

This commit is contained in:
PKEuS 2013-09-03 11:40:43 +02:00
parent b36a887608
commit 8e84f30244
2 changed files with 7 additions and 21 deletions

View File

@ -278,12 +278,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
if (function) { if (function) {
retref = function->tokenDef->strAt(-1) == "&"; retref = function->tokenDef->strAt(-1) == "&";
if (!retref) { if (!retref) {
const Token *start = function->tokenDef; const Token *start = function->retDef;
while (start->previous() && !Token::Match(start->previous(), ";|}|{|public:|private:|protected:")) {
if ((start->str() == ")" || start->str() == ">") && start->link())
start = start->link();
start = start->previous();
}
if (start->str() == "const") if (start->str() == "const")
start = start->next(); start = start->next();
if (start->str() == "::") if (start->str() == "::")

View File

@ -1063,15 +1063,14 @@ void CheckClass::operatorEq()
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
if (func->type == Function::eOperatorEqual && func->access != Private) { if (func->type == Function::eOperatorEqual && func->access != Private) {
// use definition for check so we don't have to deal with qualification // use definition for check so we don't have to deal with qualification
if (!(Token::Match(func->tokenDef->tokAt(-3), ";|}|{|public:|protected:|private:|virtual %type% &") && if (!(Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className)) {
func->tokenDef->strAt(-2) == scope->className)) {
// make sure we really have a copy assignment operator // make sure we really have a copy assignment operator
if (Token::Match(func->tokenDef->tokAt(2), "const| %var% &")) { if (Token::Match(func->tokenDef->tokAt(2), "const| %var% &")) {
if (func->tokenDef->strAt(2) == "const" && if (func->tokenDef->strAt(2) == "const" &&
func->tokenDef->strAt(3) == scope->className) func->tokenDef->strAt(3) == scope->className)
operatorEqReturnError(func->tokenDef->previous(), scope->className); operatorEqReturnError(func->retDef, scope->className);
else if (func->tokenDef->strAt(2) == scope->className) else if (func->tokenDef->strAt(2) == scope->className)
operatorEqReturnError(func->tokenDef->previous(), scope->className); operatorEqReturnError(func->retDef, scope->className);
} }
} }
} }
@ -1102,9 +1101,7 @@ void CheckClass::operatorEqRetRefThis()
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
if (func->type == Function::eOperatorEqual && func->hasBody) { if (func->type == Function::eOperatorEqual && func->hasBody) {
// make sure return signature is correct // make sure return signature is correct
if (Token::Match(func->tokenDef->tokAt(-3), ";|}|{|public:|protected:|private:|virtual %type% &") && if (Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className) {
func->tokenDef->strAt(-2) == scope->className) {
checkReturnPtrThis(&(*scope), &(*func), func->functionScope->classStart, func->functionScope->classEnd); checkReturnPtrThis(&(*scope), &(*func), func->functionScope->classStart, func->functionScope->classEnd);
} }
} }
@ -1211,8 +1208,7 @@ void CheckClass::operatorEqToSelf()
continue; continue;
// make sure return signature is correct // make sure return signature is correct
if (Token::Match(func->tokenDef->tokAt(-3), ";|}|{|public:|protected:|private: %type% &") && if (Token::Match(func->retDef, "%type% &") && func->retDef->str() == scope->className) {
func->tokenDef->strAt(-2) == scope->className) {
// find the parameter name // find the parameter name
const Token *rhs = func->argumentList.begin()->nameToken(); const Token *rhs = func->argumentList.begin()->nameToken();
@ -1473,12 +1469,7 @@ void CheckClass::checkConst()
// does the function return a pointer or reference? // does the function return a pointer or reference?
if (Token::Match(previous, "*|&")) { if (Token::Match(previous, "*|&")) {
const Token *temp = previous; if (func->retDef->str() != "const")
while (!Token::Match(temp->previous(), ";|}|{|public:|protected:|private:"))
temp = temp->previous();
if (temp->str() != "const")
continue; continue;
} else if (Token::Match(previous->previous(), "*|& >")) { } else if (Token::Match(previous->previous(), "*|& >")) {
const Token *temp = previous; const Token *temp = previous;