Move necessary code into valuetype (#2265)
* Fix parsing of smart pointers * Improve deduction of return type * Valuetype computation for decayed pointers
This commit is contained in:
parent
f99e83ece0
commit
19cf636a4a
|
@ -326,20 +326,11 @@ static bool isNullablePointer(const Token* tok, const Settings* settings)
|
||||||
return true;
|
return true;
|
||||||
if (astIsSmartPointer(tok))
|
if (astIsSmartPointer(tok))
|
||||||
return true;
|
return true;
|
||||||
// TODO: Move this logic into ValueType
|
|
||||||
if (Token::simpleMatch(tok, "."))
|
if (Token::simpleMatch(tok, "."))
|
||||||
return isNullablePointer(tok->astOperand2(), settings);
|
return isNullablePointer(tok->astOperand2(), settings);
|
||||||
if (const Variable* var = tok->variable()) {
|
if (const Variable* var = tok->variable()) {
|
||||||
return (var->isPointer() || var->isSmartPointer());
|
return (var->isPointer() || var->isSmartPointer());
|
||||||
}
|
}
|
||||||
if (Token::Match(tok->previous(), "%name% (")) {
|
|
||||||
if (const Function* f = tok->previous()->function()) {
|
|
||||||
if (f->retDef) {
|
|
||||||
ValueType vt = ValueType::parseDecl(f->retDef, settings);
|
|
||||||
return vt.smartPointerTypeToken || vt.pointer > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5435,6 +5435,9 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
||||||
continue;
|
continue;
|
||||||
valuetype->smartPointerTypeToken = argTok->next();
|
valuetype->smartPointerTypeToken = argTok->next();
|
||||||
valuetype->smartPointerType = argTok->next()->type();
|
valuetype->smartPointerType = argTok->next()->type();
|
||||||
|
valuetype->type = ValueType::Type::NONSTD;
|
||||||
|
type = argTok->link();
|
||||||
|
continue;
|
||||||
} else if (Token::Match(type, "%name% :: %name%")) {
|
} else if (Token::Match(type, "%name% :: %name%")) {
|
||||||
std::string typestr;
|
std::string typestr;
|
||||||
const Token *end = type;
|
const Token *end = type;
|
||||||
|
@ -5755,10 +5758,12 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings)
|
||||||
}
|
}
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
} else if (tok->str() == "return" && tok->scope()) {
|
} else if (tok->str() == "return" && tok->scope()) {
|
||||||
const Function *function = tok->scope()->function;
|
const Scope* fscope = tok->scope();
|
||||||
if (function && function->retDef) {
|
while (fscope && !fscope->function)
|
||||||
|
fscope = fscope->nestedIn;
|
||||||
|
if (fscope && fscope->function && fscope->function->retDef) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings);
|
parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings);
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3499,17 +3499,6 @@ bool isLifetimeBorrowed(const Token *tok, const Settings *settings)
|
||||||
if (!Token::simpleMatch(tok, "{")) {
|
if (!Token::simpleMatch(tok, "{")) {
|
||||||
const ValueType *vt = tok->valueType();
|
const ValueType *vt = tok->valueType();
|
||||||
const ValueType *vtParent = tok->astParent()->valueType();
|
const ValueType *vtParent = tok->astParent()->valueType();
|
||||||
ValueType svt;
|
|
||||||
// TODO: Move logic to ValueType
|
|
||||||
if (!vtParent && Token::simpleMatch(tok->astParent(), "return")) {
|
|
||||||
const Scope* fscope = tok->scope();
|
|
||||||
while (fscope && !fscope->function)
|
|
||||||
fscope = fscope->nestedIn;
|
|
||||||
if (fscope && fscope->function && fscope->function->retDef) {
|
|
||||||
svt = ValueType::parseDecl(fscope->function->retDef, settings);
|
|
||||||
vtParent = &svt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isLifetimeBorrowed(vt, vtParent))
|
if (isLifetimeBorrowed(vt, vtParent))
|
||||||
return true;
|
return true;
|
||||||
if (isLifetimeOwned(vt, vtParent))
|
if (isLifetimeOwned(vt, vtParent))
|
||||||
|
@ -3958,17 +3947,7 @@ static bool isDecayedPointer(const Token *tok, const Settings *settings)
|
||||||
return true;
|
return true;
|
||||||
if (!Token::simpleMatch(tok->astParent(), "return"))
|
if (!Token::simpleMatch(tok->astParent(), "return"))
|
||||||
return false;
|
return false;
|
||||||
if (!tok->scope())
|
return astIsPointer(tok->astParent());
|
||||||
return false;
|
|
||||||
if (!tok->scope()->function)
|
|
||||||
return false;
|
|
||||||
if (!tok->scope()->function->retDef)
|
|
||||||
return false;
|
|
||||||
// TODO: Add valuetypes to return types of functions
|
|
||||||
ValueType vt = ValueType::parseDecl(tok->scope()->function->retDef, settings);
|
|
||||||
if (vt.pointer > 0)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
|
|
Loading…
Reference in New Issue