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;
|
||||
if (astIsSmartPointer(tok))
|
||||
return true;
|
||||
// TODO: Move this logic into ValueType
|
||||
if (Token::simpleMatch(tok, "."))
|
||||
return isNullablePointer(tok->astOperand2(), settings);
|
||||
if (const Variable* var = tok->variable()) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5435,6 +5435,9 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
|
|||
continue;
|
||||
valuetype->smartPointerTypeToken = argTok->next();
|
||||
valuetype->smartPointerType = argTok->next()->type();
|
||||
valuetype->type = ValueType::Type::NONSTD;
|
||||
type = argTok->link();
|
||||
continue;
|
||||
} else if (Token::Match(type, "%name% :: %name%")) {
|
||||
std::string typestr;
|
||||
const Token *end = type;
|
||||
|
@ -5755,10 +5758,12 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings)
|
|||
}
|
||||
setValueType(tok, vt);
|
||||
} else if (tok->str() == "return" && tok->scope()) {
|
||||
const Function *function = tok->scope()->function;
|
||||
if (function && function->retDef) {
|
||||
const Scope* fscope = tok->scope();
|
||||
while (fscope && !fscope->function)
|
||||
fscope = fscope->nestedIn;
|
||||
if (fscope && fscope->function && fscope->function->retDef) {
|
||||
ValueType vt;
|
||||
parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings);
|
||||
parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings);
|
||||
setValueType(tok, vt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3499,17 +3499,6 @@ bool isLifetimeBorrowed(const Token *tok, const Settings *settings)
|
|||
if (!Token::simpleMatch(tok, "{")) {
|
||||
const ValueType *vt = tok->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))
|
||||
return true;
|
||||
if (isLifetimeOwned(vt, vtParent))
|
||||
|
@ -3958,17 +3947,7 @@ static bool isDecayedPointer(const Token *tok, const Settings *settings)
|
|||
return true;
|
||||
if (!Token::simpleMatch(tok->astParent(), "return"))
|
||||
return false;
|
||||
if (!tok->scope())
|
||||
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;
|
||||
return astIsPointer(tok->astParent());
|
||||
}
|
||||
|
||||
static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger *errorLogger, const Settings *settings)
|
||||
|
|
Loading…
Reference in New Issue