ValueType: handling scoped types in 'new ...'

This commit is contained in:
Daniel Marjamäki 2017-03-05 10:24:51 +01:00
parent e0dd0a82ed
commit f3c0461001
2 changed files with 12 additions and 5 deletions

View File

@ -4864,17 +4864,23 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
const Token *typeTok = tok->next();
if (Token::Match(typeTok, "( std| ::| nothrow )"))
typeTok = typeTok->link()->next();
std::string typestr;
while (Token::Match(typeTok, "%name% :: %name%")) {
typestr += typeTok->str() + "::";
typeTok = typeTok->tokAt(2);
}
if (!Token::Match(typeTok, "%type% ;|[|("))
return;
typestr += typeTok->str();
ValueType vt;
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(typestr, typeTok->isLong());
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
vt.fromLibraryType(typeTok->str(), settings);
vt.fromLibraryType(typestr, settings);
if (vt.type == ValueType::Type::UNKNOWN_TYPE)
return;
if (typeTok->isUnsigned())

View File

@ -4289,13 +4289,14 @@ private:
settingsWin64.platformType = Settings::Win64;
const Library::PodType u32 = { 4, 'u' };
settingsWin64.library.podtypes["u32"] = u32;
settingsWin64.library.podtypes["xyz::u32"] = u32;
settingsWin64.library.podtypes["xyz::x"] = u32;
ValueType vt;
ASSERT_EQUALS(true, vt.fromLibraryType("u32", &settingsWin64));
ASSERT_EQUALS(true, vt.fromLibraryType("xyz::u32", &settingsWin64));
ASSERT_EQUALS(true, vt.fromLibraryType("xyz::x", &settingsWin64));
ASSERT_EQUALS(ValueType::Type::INT, vt.type);
ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new u32[10];", "new", "test.cpp", &settingsWin64));
ASSERT_EQUALS("unsigned int", typeOf("; x = (xyz::u32)12;", "(", "test.cpp", &settingsWin64));
ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new xyz::x[10];", "new", "test.cpp", &settingsWin64));
ASSERT_EQUALS("unsigned int", typeOf("; x = (xyz::x)12;", "(", "test.cpp", &settingsWin64));
}
{
// PlatformType