From 79356b1883020a0912117cf5de547d35860e06fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 8 Oct 2019 11:24:54 +0200 Subject: [PATCH] SymbolDatabase: Better ValueType handling of 'LibraryType(..)' --- lib/symboldatabase.cpp | 18 +++++++++++++++++- test/testsymboldatabase.cpp | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d2f3ad8dd..c3dca6b69 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5559,6 +5559,11 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings) // function style cast else if (tok->previous() && tok->previous()->isStandardType()) { ValueType valuetype; + if (valuetype.fromLibraryType(tok->astOperand1()->expressionString(), mSettings)) { + setValueType(tok, valuetype); + continue; + } + valuetype.type = ValueType::typeFromString(tok->previous()->str(), tok->previous()->isLong()); if (tok->previous()->isUnsigned()) valuetype.sign = ValueType::Sign::UNSIGNED; @@ -5575,8 +5580,19 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings) setValueType(tok, valuetype); } - // library function + // library type/function else if (tok->previous()) { + if (tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) { + if (const Library::Container *c = mSettings->library.detectContainer(tok->astOperand1())) { + ValueType vt; + vt.pointer = 0; + vt.container = c; + vt.type = ValueType::Type::CONTAINER; + setValueType(tok, vt); + continue; + } + } + const std::string& typestr(mSettings->library.returnValueType(tok->previous())); if (!typestr.empty()) { ValueType valuetype; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4304cc35b..c7510fe9f 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6319,6 +6319,7 @@ private: ASSERT_EQUALS("unsigned int *", typeOf(";void *data = new u32[10];", "new", "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)); + ASSERT_EQUALS("unsigned int", typeOf(";u32(12);", "(", "test.cpp", &settingsWin64)); } { // PlatformType @@ -6351,6 +6352,7 @@ private: sC.library.containers["C"] = c; ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC)); ASSERT_EQUALS("container(C) *", typeOf("x=(C*)c;","(","test.cpp",&sC)); + ASSERT_EQUALS("container(C)", typeOf("C c = C();","(","test.cpp",&sC)); } { // Container (vector)