SymbolDatabase: Refactoring handling of library-function return type

This commit is contained in:
Daniel Marjamäki 2016-10-23 23:20:36 +02:00
parent c8f831b70d
commit f973a9a9d5
2 changed files with 19 additions and 10 deletions

View File

@ -545,10 +545,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
leakignore.insert(name); leakignore.insert(name);
else if (functionnodename == "use-retval") else if (functionnodename == "use-retval")
_useretval.insert(name); _useretval.insert(name);
else if (functionnodename == "returnValue" && functionnode->GetText()) { else if (functionnodename == "returnValue") {
_returnValue[name] = functionnode->GetText(); if (const char *expr = functionnode->GetText())
const char *type = functionnode->Attribute("type"); _returnValue[name] = expr;
if (type) if (const char *type = functionnode->Attribute("type"))
_returnValueType[name] = type; _returnValueType[name] = type;
} else if (functionnodename == "arg") { } else if (functionnodename == "arg") {
const char* argNrString = functionnode->Attribute("nr"); const char* argNrString = functionnode->Attribute("nr");

View File

@ -4602,12 +4602,6 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
::setValueType(tok, valuetype, cpp, defsign, settings); ::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 (")) { else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
// TODO: use specified size_t type // TODO: use specified size_t type
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U); 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()) { } else if (tok->variable()) {
setValueType(tok, *tok->variable(), cpp, defsign, settings); setValueType(tok, *tok->variable(), cpp, defsign, settings);
} else if (tok->enumerator()) { } else if (tok->enumerator()) {