SymbolDatabase; Improved ValueType when container methods items

This commit is contained in:
Daniel Marjamäki 2020-06-26 22:47:28 +02:00
parent b33326bf51
commit f5ace9ffbe
2 changed files with 8 additions and 0 deletions

View File

@ -5323,6 +5323,12 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
return;
}
if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") && vt1->container->getYield(parent->next()->str()) == Library::Container::Yield::ITEM) {
ValueType item;
if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings))
setValueType(parent->tokAt(2), item);
}
if (vt1 && vt1->smartPointerType && Token::Match(parent, ". %name% (") && parent->originalName() == "->" && !parent->next()->function()) {
const Scope *scope = vt1->smartPointerType->classScope;
const Function *f = scope ? scope->findFunction(parent->next(), false) : nullptr;

View File

@ -6868,6 +6868,7 @@ private:
vector.startPattern2 = "Vector !!::";
vector.type_templateArgNo = 0;
vector.arrayLike_indexOp = true;
vector.functions["front"] = Library::Container::Function{Library::Container::Action::NO_ACTION, Library::Container::Yield::ITEM};
set.library.containers["Vector"] = vector;
Library::Container string;
string.startPattern = "test :: string";
@ -6878,6 +6879,7 @@ private:
ASSERT_EQUALS("container(test :: string)", typeOf("{return test::string();}", "(", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector<test::string> v) { for (auto s: v) { x=s+s; } }", "s", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector<test::string> v) { for (auto s: v) { x=s+s; } }", "+", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("Vector<test::string> v; x = v.front();", "(", "test.cpp", &set));
}
// new