ValueType: refactor and improve handling of 'new ...'
This commit is contained in:
parent
6a718baae5
commit
e0dd0a82ed
|
@ -4861,25 +4861,30 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
|
||||||
} else if (tok->enumerator()) {
|
} else if (tok->enumerator()) {
|
||||||
setValueType(tok, *tok->enumerator(), cpp, defsign, settings);
|
setValueType(tok, *tok->enumerator(), cpp, defsign, settings);
|
||||||
} else if (cpp && tok->str() == "new") {
|
} else if (cpp && tok->str() == "new") {
|
||||||
if (Token::Match(tok, "new %type% ;|[") ||
|
const Token *typeTok = tok->next();
|
||||||
Token::Match(tok, "new ( std| ::| nothrow ) %type% ;|[")) {
|
if (Token::Match(typeTok, "( std| ::| nothrow )"))
|
||||||
ValueType vt;
|
typeTok = typeTok->link()->next();
|
||||||
vt.pointer = 1;
|
if (!Token::Match(typeTok, "%type% ;|[|("))
|
||||||
const Token * typeTok = tok->next();
|
return;
|
||||||
if (typeTok->str() == "(")
|
ValueType vt;
|
||||||
typeTok = typeTok->link()->next();
|
vt.pointer = 1;
|
||||||
|
if (typeTok->type() && typeTok->type()->classScope) {
|
||||||
|
vt.type = ValueType::Type::NONSTD;
|
||||||
|
vt.typeScope = typeTok->type()->classScope;
|
||||||
|
} else {
|
||||||
vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong());
|
vt.type = ValueType::typeFromString(typeTok->str(), typeTok->isLong());
|
||||||
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
|
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
|
||||||
vt.fromLibraryType(typeTok->str(), settings);
|
vt.fromLibraryType(typeTok->str(), settings);
|
||||||
|
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
|
||||||
|
return;
|
||||||
if (typeTok->isUnsigned())
|
if (typeTok->isUnsigned())
|
||||||
vt.sign = ValueType::Sign::UNSIGNED;
|
vt.sign = ValueType::Sign::UNSIGNED;
|
||||||
else if (typeTok->isSigned())
|
else if (typeTok->isSigned())
|
||||||
vt.sign = ValueType::Sign::SIGNED;
|
vt.sign = ValueType::Sign::SIGNED;
|
||||||
if (vt.sign == ValueType::Sign::UNKNOWN_SIGN && vt.isIntegral())
|
if (vt.sign == ValueType::Sign::UNKNOWN_SIGN && vt.isIntegral())
|
||||||
vt.sign = (vt.type == ValueType::Type::CHAR) ? defsign : ValueType::Sign::SIGNED;
|
vt.sign = (vt.type == ValueType::Type::CHAR) ? defsign : ValueType::Sign::SIGNED;
|
||||||
if (vt.type != ValueType::Type::UNKNOWN_TYPE)
|
|
||||||
setValueType(tok, vt, cpp, defsign, settings);
|
|
||||||
}
|
}
|
||||||
|
setValueType(tok, vt, cpp, defsign, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4309,6 +4309,9 @@ private:
|
||||||
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// new
|
||||||
|
ASSERT_EQUALS("C *", typeOf("class C {}; x = new C();", "new"));
|
||||||
|
|
||||||
// auto variables
|
// auto variables
|
||||||
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
|
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
|
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
|
||||||
|
|
Loading…
Reference in New Issue