Set ValueType for free function returning iterator (#4837)
This commit is contained in:
parent
514e605598
commit
072e822020
|
@ -7045,7 +7045,8 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typestr.empty() || typestr == "iterator") {
|
const bool isReturnIter = typestr == "iterator";
|
||||||
|
if (typestr.empty() || isReturnIter) {
|
||||||
if (Token::simpleMatch(tok->astOperand1(), ".") &&
|
if (Token::simpleMatch(tok->astOperand1(), ".") &&
|
||||||
tok->astOperand1()->astOperand1() &&
|
tok->astOperand1()->astOperand1() &&
|
||||||
tok->astOperand1()->astOperand2() &&
|
tok->astOperand1()->astOperand2() &&
|
||||||
|
@ -7063,6 +7064,25 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
||||||
vt.containerTypeToken =
|
vt.containerTypeToken =
|
||||||
tok->astOperand1()->astOperand1()->valueType()->containerTypeToken;
|
tok->astOperand1()->astOperand1()->valueType()->containerTypeToken;
|
||||||
setValueType(tok, vt);
|
setValueType(tok, vt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isReturnIter) {
|
||||||
|
const std::vector<const Token*> args = getArguments(tok);
|
||||||
|
if (!args.empty()) {
|
||||||
|
const Library::ArgumentChecks::IteratorInfo* info = mSettings->library.getArgIteratorInfo(tok->previous(), 1);
|
||||||
|
if (info && info->it) {
|
||||||
|
const Token* contTok = args[0];
|
||||||
|
if (Token::simpleMatch(args[0]->astOperand1(), ".") && args[0]->astOperand1()->astOperand1())
|
||||||
|
contTok = args[0]->astOperand1()->astOperand1();
|
||||||
|
if (contTok && contTok->variable() && contTok->variable()->valueType() && contTok->variable()->valueType()->container) {
|
||||||
|
ValueType vt;
|
||||||
|
vt.type = ValueType::Type::ITERATOR;
|
||||||
|
vt.container = contTok->variable()->valueType()->container;
|
||||||
|
vt.containerTypeToken = contTok->variable()->valueType()->containerTypeToken;
|
||||||
|
setValueType(tok, vt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8111,16 +8111,40 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueType3() {
|
void valueType3() {
|
||||||
GET_SYMBOL_DB("void f(std::vector<std::unordered_map<int, std::unordered_set<int>>>& v, int i, int j) {\n"
|
{
|
||||||
" auto& s = v[i][j];\n"
|
GET_SYMBOL_DB("void f(std::vector<std::unordered_map<int, std::unordered_set<int>>>& v, int i, int j) {\n"
|
||||||
" s.insert(0);\n"
|
" auto& s = v[i][j];\n"
|
||||||
"}\n");
|
" s.insert(0);\n"
|
||||||
ASSERT_EQUALS("", errout.str());
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
const Token* tok = tokenizer.tokens();
|
const Token* tok = tokenizer.tokens();
|
||||||
tok = Token::findsimplematch(tok, "s .");
|
tok = Token::findsimplematch(tok, "s .");
|
||||||
ASSERT(tok && tok->valueType());
|
ASSERT(tok && tok->valueType());
|
||||||
ASSERT_EQUALS("container(std :: set|unordered_set <)", tok->valueType()->str());
|
ASSERT_EQUALS("container(std :: set|unordered_set <)", tok->valueType()->str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("void f(std::vector<int> v) {\n"
|
||||||
|
" auto it = std::find(v.begin(), v.end(), 0);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
const Token* tok = tokenizer.tokens();
|
||||||
|
tok = Token::findsimplematch(tok, "auto");
|
||||||
|
ASSERT(tok && tok->valueType());
|
||||||
|
ASSERT_EQUALS("iterator(std :: vector <)", tok->valueType()->str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("void f(std::vector<int>::iterator beg, std::vector<int>::iterator end) {\n"
|
||||||
|
" auto it = std::find(beg, end, 0);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
const Token* tok = tokenizer.tokens();
|
||||||
|
tok = Token::findsimplematch(tok, "auto");
|
||||||
|
ASSERT(tok && tok->valueType());
|
||||||
|
ASSERT_EQUALS("iterator(std :: vector <)", tok->valueType()->str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueTypeThis() {
|
void valueTypeThis() {
|
||||||
|
|
Loading…
Reference in New Issue