From f973a9a9d549fa46a7d5bb956b0026a8550bc225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Oct 2016 23:20:36 +0200 Subject: [PATCH] SymbolDatabase: Refactoring handling of library-function return type --- lib/library.cpp | 8 ++++---- lib/symboldatabase.cpp | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 7aff6a0f3..404a321c4 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -545,10 +545,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co leakignore.insert(name); else if (functionnodename == "use-retval") _useretval.insert(name); - else if (functionnodename == "returnValue" && functionnode->GetText()) { - _returnValue[name] = functionnode->GetText(); - const char *type = functionnode->Attribute("type"); - if (type) + else if (functionnodename == "returnValue") { + if (const char *expr = functionnode->GetText()) + _returnValue[name] = expr; + if (const char *type = functionnode->Attribute("type")) _returnValueType[name] = type; } else if (functionnodename == "arg") { const char* argNrString = functionnode->Attribute("nr"); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b9b563cb1..7a66bc735 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -4602,12 +4602,6 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett ::setValueType(tok, valuetype, cpp, defsign, settings); } - // library function - else if (tok->previous() && settings->library.returnValueType(tok->previous()) == "int") { - ValueType valuetype(ValueType::Sign::SIGNED, ValueType::Type::INT, 0U); - ::setValueType(tok, valuetype, cpp, defsign, settings); - } - else if (Token::simpleMatch(tok->previous(), "sizeof (")) { // TODO: use specified size_t type ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); @@ -4621,6 +4615,21 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett } } } + + // library function + else if (tok->previous()) { + const std::string typestr(settings->library.returnValueType(tok->previous())); + if (typestr.empty()) + continue; + TokenList tokenList(settings); + std::istringstream istr(typestr+";"); + if (tokenList.createTokens(istr)) { + ValueType vt; + if (parsedecl(tokenList.front(), &vt, defsign, settings)) { + setValueType(tok, vt, cpp, defsign, settings); + } + } + } } else if (tok->variable()) { setValueType(tok, *tok->variable(), cpp, defsign, settings); } else if (tok->enumerator()) {