do not do C++ processing for C code in `parsedecl()` (#4304)
This commit is contained in:
parent
9cd9afa1b6
commit
0e1cd8b2ac
|
@ -2914,7 +2914,7 @@ void CheckClass::checkThisUseAfterFree()
|
||||||
for (const Variable &var : classScope->varlist) {
|
for (const Variable &var : classScope->varlist) {
|
||||||
// Find possible "self pointer".. pointer/smartpointer member variable of "self" type.
|
// Find possible "self pointer".. pointer/smartpointer member variable of "self" type.
|
||||||
if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) {
|
if (var.valueType() && var.valueType()->smartPointerType != classScope->definedType && var.valueType()->typeScope != classScope) {
|
||||||
const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), mSettings);
|
const ValueType valueType = ValueType::parseDecl(var.typeStartToken(), mSettings, true); // this is only called for C++
|
||||||
if (valueType.smartPointerType != classScope->definedType)
|
if (valueType.smartPointerType != classScope->definedType)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ void CheckType::checkFloatToIntegerOverflow()
|
||||||
while (scope && scope->type != Scope::ScopeType::eLambda && scope->type != Scope::ScopeType::eFunction)
|
while (scope && scope->type != Scope::ScopeType::eLambda && scope->type != Scope::ScopeType::eFunction)
|
||||||
scope = scope->nestedIn;
|
scope = scope->nestedIn;
|
||||||
if (scope && scope->type == Scope::ScopeType::eFunction && scope->function && scope->function->retDef) {
|
if (scope && scope->type == Scope::ScopeType::eFunction && scope->function && scope->function->retDef) {
|
||||||
const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, mSettings);
|
const ValueType &valueType = ValueType::parseDecl(scope->function->retDef, mSettings, mTokenizer->isCPP());
|
||||||
vtfloat = tok->astOperand1()->valueType();
|
vtfloat = tok->astOperand1()->valueType();
|
||||||
floatValues = &tok->astOperand1()->values();
|
floatValues = &tok->astOperand1()->values();
|
||||||
checkFloatToIntegerOverflow(tok, &valueType, vtfloat, floatValues);
|
checkFloatToIntegerOverflow(tok, &valueType, vtfloat, floatValues);
|
||||||
|
|
|
@ -628,7 +628,7 @@ void clangimport::AstNode::setValueType(Token *tok)
|
||||||
if (!decl.front())
|
if (!decl.front())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ValueType valueType = ValueType::parseDecl(decl.front(), mData->mSettings);
|
ValueType valueType = ValueType::parseDecl(decl.front(), mData->mSettings, true); // TODO: set isCpp
|
||||||
if (valueType.type != ValueType::Type::UNKNOWN_TYPE) {
|
if (valueType.type != ValueType::Type::UNKNOWN_TYPE) {
|
||||||
tok->setValueType(new ValueType(valueType));
|
tok->setValueType(new ValueType(valueType));
|
||||||
break;
|
break;
|
||||||
|
@ -1542,7 +1542,7 @@ static void setValues(Tokenizer *tokenizer, SymbolDatabase *symbolDatabase)
|
||||||
|
|
||||||
for (Token *tok = const_cast<Token*>(tokenizer->tokens()); tok; tok = tok->next()) {
|
for (Token *tok = const_cast<Token*>(tokenizer->tokens()); tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok, "sizeof (")) {
|
if (Token::simpleMatch(tok, "sizeof (")) {
|
||||||
ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings);
|
ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings, tokenizer->isCPP());
|
||||||
int sz = vt.typeSize(*settings, true);
|
int sz = vt.typeSize(*settings, true);
|
||||||
if (sz <= 0)
|
if (sz <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -2132,7 +2132,7 @@ void Variable::evaluate(const Settings* settings)
|
||||||
setFlag(fIsArray, arrayDimensions(settings, &isContainer));
|
setFlag(fIsArray, arrayDimensions(settings, &isContainer));
|
||||||
|
|
||||||
if (mTypeStartToken)
|
if (mTypeStartToken)
|
||||||
setValueType(ValueType::parseDecl(mTypeStartToken,settings));
|
setValueType(ValueType::parseDecl(mTypeStartToken,settings, true)); // TODO: set isCpp
|
||||||
|
|
||||||
const Token* tok = mTypeStartToken;
|
const Token* tok = mTypeStartToken;
|
||||||
while (tok && tok->previous() && tok->previous()->isName())
|
while (tok && tok->previous() && tok->previous()->isName())
|
||||||
|
@ -5502,7 +5502,7 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
|
||||||
return tok1->valueType()->typeScope->findFunction(tok, tok1->valueType()->constness == 1);
|
return tok1->valueType()->typeScope->findFunction(tok, tok1->valueType()->constness == 1);
|
||||||
} else if (tok1 && Token::Match(tok1->previous(), "%name% (") && tok1->previous()->function() &&
|
} else if (tok1 && Token::Match(tok1->previous(), "%name% (") && tok1->previous()->function() &&
|
||||||
tok1->previous()->function()->retDef) {
|
tok1->previous()->function()->retDef) {
|
||||||
ValueType vt = ValueType::parseDecl(tok1->previous()->function()->retDef, mSettings);
|
ValueType vt = ValueType::parseDecl(tok1->previous()->function()->retDef, mSettings, mIsCpp);
|
||||||
if (vt.typeScope)
|
if (vt.typeScope)
|
||||||
return vt.typeScope->findFunction(tok, vt.constness == 1);
|
return vt.typeScope->findFunction(tok, vt.constness == 1);
|
||||||
} else if (Token::Match(tok1, "%var% .")) {
|
} else if (Token::Match(tok1, "%var% .")) {
|
||||||
|
@ -5514,7 +5514,7 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
|
||||||
} else if (Token::simpleMatch(tok->previous()->astOperand1(), "(")) {
|
} else if (Token::simpleMatch(tok->previous()->astOperand1(), "(")) {
|
||||||
const Token *castTok = tok->previous()->astOperand1();
|
const Token *castTok = tok->previous()->astOperand1();
|
||||||
if (castTok->isCast()) {
|
if (castTok->isCast()) {
|
||||||
ValueType vt = ValueType::parseDecl(castTok->next(),mSettings);
|
ValueType vt = ValueType::parseDecl(castTok->next(),mSettings, mIsCpp);
|
||||||
if (vt.typeScope)
|
if (vt.typeScope)
|
||||||
return vt.typeScope->findFunction(tok, vt.constness == 1);
|
return vt.typeScope->findFunction(tok, vt.constness == 1);
|
||||||
}
|
}
|
||||||
|
@ -5532,7 +5532,7 @@ const Function* SymbolDatabase::findFunction(const Token *tok) const
|
||||||
}
|
}
|
||||||
// Check for constructor
|
// Check for constructor
|
||||||
if (Token::Match(tok, "%name% (|{")) {
|
if (Token::Match(tok, "%name% (|{")) {
|
||||||
ValueType vt = ValueType::parseDecl(tok, mSettings);
|
ValueType vt = ValueType::parseDecl(tok, mSettings, mIsCpp);
|
||||||
if (vt.typeScope)
|
if (vt.typeScope)
|
||||||
return vt.typeScope->findFunction(tok, false);
|
return vt.typeScope->findFunction(tok, false);
|
||||||
}
|
}
|
||||||
|
@ -5939,6 +5939,7 @@ static const Token* parsedecl(const Token* type,
|
||||||
ValueType* const valuetype,
|
ValueType* const valuetype,
|
||||||
ValueType::Sign defaultSignedness,
|
ValueType::Sign defaultSignedness,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
|
bool isCpp,
|
||||||
SourceLocation loc = SourceLocation::current());
|
SourceLocation loc = SourceLocation::current());
|
||||||
|
|
||||||
void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocation loc)
|
void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocation loc)
|
||||||
|
@ -5955,7 +5956,7 @@ void SymbolDatabase::setValueType(Token* tok, const Variable& var, SourceLocatio
|
||||||
valuetype.containerTypeToken = var.valueType()->containerTypeToken;
|
valuetype.containerTypeToken = var.valueType()->containerTypeToken;
|
||||||
}
|
}
|
||||||
valuetype.smartPointerType = var.smartPointerType();
|
valuetype.smartPointerType = var.smartPointerType();
|
||||||
if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) {
|
if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
if (tok->str() == "." && tok->astOperand1()) {
|
if (tok->str() == "." && tok->astOperand1()) {
|
||||||
const ValueType * const vt = tok->astOperand1()->valueType();
|
const ValueType * const vt = tok->astOperand1()->valueType();
|
||||||
if (vt && (vt->constness & 1) != 0)
|
if (vt && (vt->constness & 1) != 0)
|
||||||
|
@ -6050,7 +6051,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") &&
|
if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") &&
|
||||||
isContainerYieldElement(vt1->container->getYield(parent->next()->str()))) {
|
isContainerYieldElement(vt1->container->getYield(parent->next()->str()))) {
|
||||||
ValueType item;
|
ValueType item;
|
||||||
if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings)) {
|
if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
if (item.constness == 0)
|
if (item.constness == 0)
|
||||||
item.constness = vt1->constness;
|
item.constness = vt1->constness;
|
||||||
if (isContainerYieldPointer(vt1->container->getYield(parent->next()->str())))
|
if (isContainerYieldPointer(vt1->container->getYield(parent->next()->str())))
|
||||||
|
@ -6152,7 +6153,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::ITERATOR &&
|
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::ITERATOR &&
|
||||||
valuetype.containerTypeToken) {
|
valuetype.containerTypeToken) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mSettings)) {
|
if (parsedecl(valuetype.containerTypeToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
if (vt.constness == 0)
|
if (vt.constness == 0)
|
||||||
vt.constness = valuetype.constness;
|
vt.constness = valuetype.constness;
|
||||||
vt.reference = Reference::LValue;
|
vt.reference = Reference::LValue;
|
||||||
|
@ -6164,7 +6165,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::SMART_POINTER &&
|
if (parent->str() == "*" && !parent->astOperand2() && valuetype.type == ValueType::Type::SMART_POINTER &&
|
||||||
valuetype.smartPointerTypeToken) {
|
valuetype.smartPointerTypeToken) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mSettings)) {
|
if (parsedecl(valuetype.smartPointerTypeToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
if (vt.constness == 0)
|
if (vt.constness == 0)
|
||||||
vt.constness = valuetype.constness;
|
vt.constness = valuetype.constness;
|
||||||
setValueType(parent, vt);
|
setValueType(parent, vt);
|
||||||
|
@ -6273,7 +6274,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
autovt.smartPointerType = templateArgType;
|
autovt.smartPointerType = templateArgType;
|
||||||
autovt.type = ValueType::Type::NONSTD;
|
autovt.type = ValueType::Type::NONSTD;
|
||||||
}
|
}
|
||||||
} else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings)) {
|
} else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
setType = true;
|
setType = true;
|
||||||
templateArgType = vt2->containerTypeToken->type();
|
templateArgType = vt2->containerTypeToken->type();
|
||||||
}
|
}
|
||||||
|
@ -6301,7 +6302,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
|
||||||
|
|
||||||
if (vt1 && vt1->containerTypeToken && parent->str() == "[") {
|
if (vt1 && vt1->containerTypeToken && parent->str() == "[") {
|
||||||
ValueType vtParent;
|
ValueType vtParent;
|
||||||
if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mSettings)) {
|
if (parsedecl(vt1->containerTypeToken, &vtParent, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
setValueType(parent, vtParent);
|
setValueType(parent, vtParent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6431,6 +6432,7 @@ static const Token* parsedecl(const Token* type,
|
||||||
ValueType* const valuetype,
|
ValueType* const valuetype,
|
||||||
ValueType::Sign defaultSignedness,
|
ValueType::Sign defaultSignedness,
|
||||||
const Settings* settings,
|
const Settings* settings,
|
||||||
|
bool isCpp,
|
||||||
SourceLocation loc)
|
SourceLocation loc)
|
||||||
{
|
{
|
||||||
if (settings->debugnormal || settings->debugwarnings)
|
if (settings->debugnormal || settings->debugwarnings)
|
||||||
|
@ -6491,7 +6493,7 @@ static const Token* parsedecl(const Token* type,
|
||||||
if (valuetype->type == ValueType::Type::UNKNOWN_TYPE &&
|
if (valuetype->type == ValueType::Type::UNKNOWN_TYPE &&
|
||||||
type->type() && type->type()->isTypeAlias() && type->type()->typeStart &&
|
type->type() && type->type()->isTypeAlias() && type->type()->typeStart &&
|
||||||
type->type()->typeStart->str() != type->str() && type->type()->typeStart != previousType)
|
type->type()->typeStart->str() != type->str() && type->type()->typeStart != previousType)
|
||||||
parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings);
|
parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp);
|
||||||
else if (Token::Match(type, "const|constexpr"))
|
else if (Token::Match(type, "const|constexpr"))
|
||||||
valuetype->constness |= (1 << (valuetype->pointer - pointer0));
|
valuetype->constness |= (1 << (valuetype->pointer - pointer0));
|
||||||
else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find("<")) {
|
else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find("<")) {
|
||||||
|
@ -6521,7 +6523,7 @@ static const Token* parsedecl(const Token* type,
|
||||||
if (valuetype->typeScope)
|
if (valuetype->typeScope)
|
||||||
valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
|
valuetype->type = (scope->type == Scope::ScopeType::eClass) ? ValueType::Type::RECORD : ValueType::Type::NONSTD;
|
||||||
}
|
}
|
||||||
} else if (const Library::Container* container = settings->library.detectContainerOrIterator(type, &isIterator)) {
|
} else if (const Library::Container* container = (isCpp ? settings->library.detectContainerOrIterator(type, &isIterator) : nullptr)) {
|
||||||
if (isIterator)
|
if (isIterator)
|
||||||
valuetype->type = ValueType::Type::ITERATOR;
|
valuetype->type = ValueType::Type::ITERATOR;
|
||||||
else
|
else
|
||||||
|
@ -6543,7 +6545,7 @@ static const Token* parsedecl(const Token* type,
|
||||||
// we are past the end of the type
|
// we are past the end of the type
|
||||||
type = type->previous();
|
type = type->previous();
|
||||||
continue;
|
continue;
|
||||||
} else if (const Library::SmartPointer* smartPointer = settings->library.detectSmartPointer(type)) {
|
} else if (const Library::SmartPointer* smartPointer = (isCpp ? settings->library.detectSmartPointer(type) : nullptr)) {
|
||||||
const Token* argTok = Token::findsimplematch(type, "<");
|
const Token* argTok = Token::findsimplematch(type, "<");
|
||||||
if (!argTok)
|
if (!argTok)
|
||||||
break;
|
break;
|
||||||
|
@ -6720,7 +6722,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
const Function *function = getOperatorFunction(tok);
|
const Function *function = getOperatorFunction(tok);
|
||||||
if (function) {
|
if (function) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings);
|
parsedecl(function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp);
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6755,21 +6757,21 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
// cast
|
// cast
|
||||||
if (tok->isCast() && !tok->astOperand2() && Token::Match(tok, "( %name%")) {
|
if (tok->isCast() && !tok->astOperand2() && Token::Match(tok, "( %name%")) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mSettings), ")"))
|
if (Token::simpleMatch(parsedecl(tok->next(), &valuetype, mDefaultSignedness, mSettings, mIsCpp), ")"))
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// C++ cast
|
// C++ cast
|
||||||
else if (tok->astOperand2() && Token::Match(tok->astOperand1(), "static_cast|const_cast|dynamic_cast|reinterpret_cast < %name%") && tok->astOperand1()->linkAt(1)) {
|
else if (tok->astOperand2() && Token::Match(tok->astOperand1(), "static_cast|const_cast|dynamic_cast|reinterpret_cast < %name%") && tok->astOperand1()->linkAt(1)) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mSettings), ">"))
|
if (Token::simpleMatch(parsedecl(tok->astOperand1()->tokAt(2), &valuetype, mDefaultSignedness, mSettings, mIsCpp), ">"))
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct smart pointer
|
// Construct smart pointer
|
||||||
else if (mSettings->library.isSmartPointer(start)) {
|
else if (mSettings->library.isSmartPointer(start)) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings)) {
|
if (parsedecl(start, &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
setValueType(tok->astOperand1(), valuetype);
|
setValueType(tok->astOperand1(), valuetype);
|
||||||
}
|
}
|
||||||
|
@ -6779,7 +6781,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
// function
|
// function
|
||||||
else if (tok->previous() && tok->previous()->function() && tok->previous()->function()->retDef) {
|
else if (tok->previous() && tok->previous()->function() && tok->previous()->function()->retDef) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (parsedecl(tok->previous()->function()->retDef, &valuetype, mDefaultSignedness, mSettings))
|
if (parsedecl(tok->previous()->function()->retDef, &valuetype, mDefaultSignedness, mSettings, mIsCpp))
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6793,7 +6795,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
|
|
||||||
if (Token::Match(tok, "( %type% %type%| *| *| )")) {
|
if (Token::Match(tok, "( %type% %type%| *| *| )")) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
if (parsedecl(tok->next(), &vt, mDefaultSignedness, mSettings)) {
|
if (parsedecl(tok->next(), &vt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
setValueType(tok->next(), vt);
|
setValueType(tok->next(), vt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6835,7 +6837,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
// Aggregate constructor
|
// Aggregate constructor
|
||||||
if (Token::Match(tok->previous(), "%name%")) {
|
if (Token::Match(tok->previous(), "%name%")) {
|
||||||
ValueType valuetype;
|
ValueType valuetype;
|
||||||
if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mSettings)) {
|
if (parsedecl(tok->previous(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
if (valuetype.typeScope) {
|
if (valuetype.typeScope) {
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
continue;
|
continue;
|
||||||
|
@ -6849,7 +6851,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
if (mSettings->library.detectContainerOrIterator(typeStartToken) ||
|
if (mSettings->library.detectContainerOrIterator(typeStartToken) ||
|
||||||
mSettings->library.detectSmartPointer(typeStartToken)) {
|
mSettings->library.detectSmartPointer(typeStartToken)) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) {
|
if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -6859,7 +6861,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
|
|
||||||
if ((e == "std::make_shared" || e == "std::make_unique") && Token::Match(tok->astOperand1(), ":: %name% < %name%")) {
|
if ((e == "std::make_shared" || e == "std::make_unique") && Token::Match(tok->astOperand1(), ":: %name% < %name%")) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings);
|
parsedecl(tok->astOperand1()->tokAt(3), &vt, mDefaultSignedness, mSettings, mIsCpp);
|
||||||
if (vt.typeScope) {
|
if (vt.typeScope) {
|
||||||
vt.smartPointerType = vt.typeScope->definedType;
|
vt.smartPointerType = vt.typeScope->definedType;
|
||||||
vt.typeScope = nullptr;
|
vt.typeScope = nullptr;
|
||||||
|
@ -6888,7 +6890,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
std::istringstream istr(typestr+";");
|
std::istringstream istr(typestr+";");
|
||||||
tokenList.createTokens(istr);
|
tokenList.createTokens(istr);
|
||||||
tokenList.simplifyStdType();
|
tokenList.simplifyStdType();
|
||||||
if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings)) {
|
if (parsedecl(tokenList.front(), &valuetype, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
valuetype.originalTypeName = typestr;
|
valuetype.originalTypeName = typestr;
|
||||||
setValueType(tok, valuetype);
|
setValueType(tok, valuetype);
|
||||||
}
|
}
|
||||||
|
@ -6923,7 +6925,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
tokenList.simplifyPlatformTypes();
|
tokenList.simplifyPlatformTypes();
|
||||||
tokenList.simplifyStdType();
|
tokenList.simplifyStdType();
|
||||||
if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mSettings)) {
|
if (parsedecl(tokenList.front(), &vt, mDefaultSignedness, mSettings, mIsCpp)) {
|
||||||
vt.originalTypeName = typestr;
|
vt.originalTypeName = typestr;
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
}
|
}
|
||||||
|
@ -6935,7 +6937,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
functionScope = functionScope->nestedIn;
|
functionScope = functionScope->nestedIn;
|
||||||
if (functionScope && functionScope->type == Scope::eFunction && functionScope->function &&
|
if (functionScope && functionScope->type == Scope::eFunction && functionScope->function &&
|
||||||
functionScope->function->retDef) {
|
functionScope->function->retDef) {
|
||||||
ValueType vt = ValueType::parseDecl(functionScope->function->retDef, mSettings);
|
ValueType vt = ValueType::parseDecl(functionScope->function->retDef, mSettings, mIsCpp);
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
if (Token::simpleMatch(tok, "return {"))
|
if (Token::simpleMatch(tok, "return {"))
|
||||||
setValueType(tok->next(), vt);
|
setValueType(tok->next(), vt);
|
||||||
|
@ -6996,7 +6998,7 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
fscope = fscope->nestedIn;
|
fscope = fscope->nestedIn;
|
||||||
if (fscope && fscope->function && fscope->function->retDef) {
|
if (fscope && fscope->function && fscope->function->retDef) {
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings);
|
parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp);
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7016,10 +7018,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
createSymbolDatabaseSetVariablePointers();
|
createSymbolDatabaseSetVariablePointers();
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType ValueType::parseDecl(const Token *type, const Settings *settings)
|
ValueType ValueType::parseDecl(const Token *type, const Settings *settings, bool isCpp)
|
||||||
{
|
{
|
||||||
ValueType vt;
|
ValueType vt;
|
||||||
parsedecl(type, &vt, settings->defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings);
|
parsedecl(type, &vt, settings->defaultSign == 'u' ? Sign::UNSIGNED : Sign::SIGNED, settings, isCpp);
|
||||||
return vt;
|
return vt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1320,7 +1320,7 @@ public:
|
||||||
debugPath()
|
debugPath()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static ValueType parseDecl(const Token *type, const Settings *settings);
|
static ValueType parseDecl(const Token *type, const Settings *settings, bool isCpp);
|
||||||
|
|
||||||
static Type typeFromString(const std::string &typestr, bool longType);
|
static Type typeFromString(const std::string &typestr, bool longType);
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,7 @@ static std::vector<ValueType> getParentValueTypes(const Token* tok,
|
||||||
const ValueType* vtCont = contTok->valueType();
|
const ValueType* vtCont = contTok->valueType();
|
||||||
if (!vtCont->containerTypeToken)
|
if (!vtCont->containerTypeToken)
|
||||||
return {};
|
return {};
|
||||||
ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, settings);
|
ValueType vtParent = ValueType::parseDecl(vtCont->containerTypeToken, settings, true); // TODO: set isCpp
|
||||||
return {std::move(vtParent)};
|
return {std::move(vtParent)};
|
||||||
}
|
}
|
||||||
if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) {
|
if (Token::Match(tok->astParent(), "return|(|{|%assign%") && parent) {
|
||||||
|
@ -807,7 +807,7 @@ static void setTokenValue(Token* tok,
|
||||||
if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
|
if (contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) &&
|
||||||
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
|
Token::simpleMatch(parent->astOperand1(), "dynamic_cast"))
|
||||||
return;
|
return;
|
||||||
const ValueType &valueType = ValueType::parseDecl(castType, settings);
|
const ValueType &valueType = ValueType::parseDecl(castType, settings, true); // TODO: set isCpp
|
||||||
if (value.isImpossible() && value.isIntValue() && value.intvalue < 0 && astIsUnsigned(tok) &&
|
if (value.isImpossible() && value.isIntValue() && value.intvalue < 0 && astIsUnsigned(tok) &&
|
||||||
valueType.sign == ValueType::SIGNED && tok->valueType() &&
|
valueType.sign == ValueType::SIGNED && tok->valueType() &&
|
||||||
ValueFlow::getSizeOf(*tok->valueType(), settings) >= ValueFlow::getSizeOf(valueType, settings))
|
ValueFlow::getSizeOf(*tok->valueType(), settings) >= ValueFlow::getSizeOf(valueType, settings))
|
||||||
|
@ -1108,7 +1108,7 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V
|
||||||
|
|
||||||
static nonneg int getSizeOfType(const Token *typeTok, const Settings *settings)
|
static nonneg int getSizeOfType(const Token *typeTok, const Settings *settings)
|
||||||
{
|
{
|
||||||
const ValueType &valueType = ValueType::parseDecl(typeTok, settings);
|
const ValueType &valueType = ValueType::parseDecl(typeTok, settings, true); // TODO: set isCpp
|
||||||
if (valueType.pointer > 0)
|
if (valueType.pointer > 0)
|
||||||
return settings->sizeof_pointer;
|
return settings->sizeof_pointer;
|
||||||
if (valueType.type == ValueType::Type::BOOL || valueType.type == ValueType::Type::CHAR)
|
if (valueType.type == ValueType::Type::BOOL || valueType.type == ValueType::Type::CHAR)
|
||||||
|
@ -1323,7 +1323,7 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
||||||
setTokenValue(tok->next(), value, settings);
|
setTokenValue(tok->next(), value, settings);
|
||||||
}
|
}
|
||||||
} else if (!tok2->type()) {
|
} else if (!tok2->type()) {
|
||||||
const ValueType& vt = ValueType::parseDecl(tok2, settings);
|
const ValueType& vt = ValueType::parseDecl(tok2, settings, true); // TODO: set isCpp
|
||||||
size_t sz = ValueFlow::getSizeOf(vt, settings);
|
size_t sz = ValueFlow::getSizeOf(vt, settings);
|
||||||
const Token* brac = tok2->astParent();
|
const Token* brac = tok2->astParent();
|
||||||
while (Token::simpleMatch(brac, "[")) {
|
while (Token::simpleMatch(brac, "[")) {
|
||||||
|
@ -4670,7 +4670,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
bool isContainerOfPointers = true;
|
bool isContainerOfPointers = true;
|
||||||
const Token* containerTypeToken = tok->valueType()->containerTypeToken;
|
const Token* containerTypeToken = tok->valueType()->containerTypeToken;
|
||||||
if (containerTypeToken) {
|
if (containerTypeToken) {
|
||||||
ValueType vt = ValueType::parseDecl(containerTypeToken, settings);
|
ValueType vt = ValueType::parseDecl(containerTypeToken, settings, true); // TODO: set isCpp
|
||||||
isContainerOfPointers = vt.pointer > 0;
|
isContainerOfPointers = vt.pointer > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8050,7 +8050,7 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
|
||||||
if (valueType->container->stdStringLike) {
|
if (valueType->container->stdStringLike) {
|
||||||
initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]);
|
initList = astIsGenericChar(args[0]) && !astIsPointer(args[0]);
|
||||||
} else if (containerTypeToken && settings) {
|
} else if (containerTypeToken && settings) {
|
||||||
ValueType vt = ValueType::parseDecl(containerTypeToken, settings);
|
ValueType vt = ValueType::parseDecl(containerTypeToken, settings, true); // TODO: set isCpp
|
||||||
if (vt.pointer > 0 && astIsPointer(args[0]))
|
if (vt.pointer > 0 && astIsPointer(args[0]))
|
||||||
initList = true;
|
initList = true;
|
||||||
else if (vt.type == ValueType::ITERATOR && astIsIterator(args[0]))
|
else if (vt.type == ValueType::ITERATOR && astIsIterator(args[0]))
|
||||||
|
@ -8434,7 +8434,7 @@ static bool getMinMaxValues(const std::string &typestr, const Settings *settings
|
||||||
return false;
|
return false;
|
||||||
typeTokens.simplifyPlatformTypes();
|
typeTokens.simplifyPlatformTypes();
|
||||||
typeTokens.simplifyStdType();
|
typeTokens.simplifyStdType();
|
||||||
const ValueType &vt = ValueType::parseDecl(typeTokens.front(), settings);
|
const ValueType &vt = ValueType::parseDecl(typeTokens.front(), settings, true); // TODO: set isCpp
|
||||||
return getMinMaxValues(&vt, *settings, minvalue, maxvalue);
|
return getMinMaxValues(&vt, *settings, minvalue, maxvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue