SymbolDatabase: Improved ValueType in range for loop
This commit is contained in:
parent
2500964b58
commit
f131a99ae3
|
@ -5247,22 +5247,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *containerElementType = typeStart;
|
|
||||||
while (Token::Match(containerElementType, "%name%|::"))
|
|
||||||
containerElementType = containerElementType->next();
|
|
||||||
|
|
||||||
// Try to determine type of "auto" token.
|
// Try to determine type of "auto" token.
|
||||||
// TODO: Get type better
|
// TODO: Get type better
|
||||||
bool setType = false;
|
bool setType = false;
|
||||||
ValueType autovt;
|
ValueType autovt;
|
||||||
const Type *templateArgType = nullptr; // container element type / smart pointer type
|
const Type *templateArgType = nullptr; // container element type / smart pointer type
|
||||||
if (Token::Match(containerElementType, "< %type% *| *| >")) {
|
if (vt2->containerTypeToken) {
|
||||||
if (parsedecl(containerElementType->next(), &autovt, mDefaultSignedness, mSettings)) {
|
if (mSettings->library.isSmartPointer(vt2->containerTypeToken)) {
|
||||||
setType = true;
|
const Token *smartPointerTypeTok = vt2->containerTypeToken;
|
||||||
templateArgType = containerElementType->next()->type();
|
|
||||||
}
|
|
||||||
} else if (mSettings->library.isSmartPointer(containerElementType->next())) {
|
|
||||||
const Token *smartPointerTypeTok = containerElementType->next();
|
|
||||||
while (Token::Match(smartPointerTypeTok, "%name%|::"))
|
while (Token::Match(smartPointerTypeTok, "%name%|::"))
|
||||||
smartPointerTypeTok = smartPointerTypeTok->next();
|
smartPointerTypeTok = smartPointerTypeTok->next();
|
||||||
if (Token::Match(smartPointerTypeTok, "< %name% > >") && smartPointerTypeTok->next()->type()) {
|
if (Token::Match(smartPointerTypeTok, "< %name% > >") && smartPointerTypeTok->next()->type()) {
|
||||||
|
@ -5271,6 +5263,11 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
autovt.smartPointerType = templateArgType;
|
autovt.smartPointerType = templateArgType;
|
||||||
autovt.type = ValueType::Type::NONSTD;
|
autovt.type = ValueType::Type::NONSTD;
|
||||||
}
|
}
|
||||||
|
} else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings)) {
|
||||||
|
setType = true;
|
||||||
|
templateArgType = vt2->containerTypeToken->type();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setType) {
|
if (setType) {
|
||||||
|
|
|
@ -6607,12 +6607,18 @@ private:
|
||||||
// Container (vector)
|
// Container (vector)
|
||||||
Settings set;
|
Settings set;
|
||||||
Library::Container vector;
|
Library::Container vector;
|
||||||
vector.startPattern = "Vector";
|
vector.startPattern = "Vector <";
|
||||||
vector.startPattern2 = "Vector !!::";
|
vector.startPattern2 = "Vector !!::";
|
||||||
vector.type_templateArgNo = 0;
|
vector.type_templateArgNo = 0;
|
||||||
vector.arrayLike_indexOp = true;
|
vector.arrayLike_indexOp = true;
|
||||||
set.library.containers["Vector"] = vector;
|
set.library.containers["Vector"] = vector;
|
||||||
|
Library::Container string;
|
||||||
|
string.startPattern = "test :: string";
|
||||||
|
string.startPattern2 = "test :: string !!::";
|
||||||
|
string.arrayLike_indexOp = string.stdStringLike = true;
|
||||||
|
set.library.containers["test::string"] = string;
|
||||||
ASSERT_EQUALS("signed int", typeOf("Vector<int> v; v[0]=3;", "[", "test.cpp", &set));
|
ASSERT_EQUALS("signed int", typeOf("Vector<int> v; v[0]=3;", "[", "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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// new
|
// new
|
||||||
|
|
Loading…
Reference in New Issue