Fix returnValueType()

This commit is contained in:
chrchr 2023-06-07 17:49:45 +02:00
parent 55f34e2681
commit 68a59830a4
1 changed files with 33 additions and 29 deletions

View File

@ -1366,17 +1366,18 @@ const Library::NonOverlappingData* Library::getNonOverlappingData(const Token *f
Library::UseRetValType Library::getUseRetValType(const Token *ftok) const Library::UseRetValType Library::getUseRetValType(const Token *ftok) const
{ {
if (Token::simpleMatch(ftok->astParent(), ".")) { if (isNotLibraryFunction(ftok)) {
using Yield = Library::Container::Yield; if (Token::simpleMatch(ftok->astParent(), ".")) {
const Yield yield = astContainerYield(ftok->astParent()->astOperand1()); using Yield = Library::Container::Yield;
if (yield == Yield::START_ITERATOR || yield == Yield::END_ITERATOR || yield == Yield::AT_INDEX || const Yield yield = astContainerYield(ftok->astParent()->astOperand1());
yield == Yield::SIZE || yield == Yield::EMPTY || yield == Yield::BUFFER || yield == Yield::BUFFER_NT || if (yield == Yield::START_ITERATOR || yield == Yield::END_ITERATOR || yield == Yield::AT_INDEX ||
(yield == Yield::ITEM && astContainerAction(ftok->astParent()->astOperand1()) == Library::Container::Action::NO_ACTION) || yield == Yield::SIZE || yield == Yield::EMPTY || yield == Yield::BUFFER || yield == Yield::BUFFER_NT ||
(yield == Yield::ITERATOR && astContainerAction(ftok->astParent()->astOperand1()) == Library::Container::Action::NO_ACTION)) (yield == Yield::ITEM && astContainerAction(ftok->astParent()->astOperand1()) == Library::Container::Action::NO_ACTION) ||
return Library::UseRetValType::DEFAULT; (yield == Yield::ITERATOR && astContainerAction(ftok->astParent()->astOperand1()) == Library::Container::Action::NO_ACTION))
} return Library::UseRetValType::DEFAULT;
if (isNotLibraryFunction(ftok)) }
return Library::UseRetValType::NONE; return Library::UseRetValType::NONE;
}
const std::unordered_map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok)); const std::unordered_map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok));
if (it != functions.cend()) if (it != functions.cend())
return it->second.useretval; return it->second.useretval;
@ -1393,13 +1394,14 @@ const std::string& Library::returnValue(const Token *ftok) const
const std::string& Library::returnValueType(const Token *ftok) const const std::string& Library::returnValueType(const Token *ftok) const
{ {
if (Token::simpleMatch(ftok->astParent(), ".") && ftok->astParent()->astOperand1()) { if (isNotLibraryFunction(ftok)) {
const Token* contTok = ftok->astParent()->astOperand1(); if (Token::simpleMatch(ftok->astParent(), ".") && ftok->astParent()->astOperand1()) {
if (contTok->valueType() && contTok->valueType()->container) const Token* contTok = ftok->astParent()->astOperand1();
return contTok->valueType()->container->getReturnType(ftok->str()); if (contTok->valueType() && contTok->valueType()->container)
} return contTok->valueType()->container->getReturnType(ftok->str());
if (isNotLibraryFunction(ftok)) }
return emptyString; return emptyString;
}
const std::map<std::string, std::string>::const_iterator it = mReturnValueType.find(getFunctionName(ftok)); const std::map<std::string, std::string>::const_iterator it = mReturnValueType.find(getFunctionName(ftok));
return it != mReturnValueType.cend() ? it->second : emptyString; return it != mReturnValueType.cend() ? it->second : emptyString;
} }
@ -1492,14 +1494,15 @@ bool Library::isFunctionConst(const Token *ftok) const
{ {
if (ftok->function() && ftok->function()->isConst()) if (ftok->function() && ftok->function()->isConst())
return true; return true;
if (Token::simpleMatch(ftok->astParent(), ".")) { if (isNotLibraryFunction(ftok)) {
using Yield = Library::Container::Yield; if (Token::simpleMatch(ftok->astParent(), ".")) {
const Yield yield = astContainerYield(ftok->astParent()->astOperand1()); using Yield = Library::Container::Yield;
if (yield == Yield::EMPTY || yield == Yield::SIZE || yield == Yield::BUFFER_NT) const Yield yield = astContainerYield(ftok->astParent()->astOperand1());
return true; if (yield == Yield::EMPTY || yield == Yield::SIZE || yield == Yield::BUFFER_NT)
} return true;
if (isNotLibraryFunction(ftok)) }
return false; return false;
}
const std::unordered_map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok)); const std::unordered_map<std::string, Function>::const_iterator it = functions.find(getFunctionName(ftok));
return (it != functions.cend() && it->second.isconst); return (it != functions.cend() && it->second.isconst);
} }
@ -1508,13 +1511,14 @@ bool Library::isnoreturn(const Token *ftok) const
{ {
if (ftok->function() && ftok->function()->isAttributeNoreturn()) if (ftok->function() && ftok->function()->isAttributeNoreturn())
return true; return true;
if (Token::simpleMatch(ftok->astParent(), ".")) { if (isNotLibraryFunction(ftok)) {
if (astContainerAction(ftok->astParent()->astOperand1()) != Library::Container::Action::NO_ACTION || if (Token::simpleMatch(ftok->astParent(), ".")) {
astContainerYield(ftok->astParent()->astOperand1()) != Library::Container::Yield::NO_YIELD) if (astContainerAction(ftok->astParent()->astOperand1()) != Library::Container::Action::NO_ACTION ||
return false; astContainerYield(ftok->astParent()->astOperand1()) != Library::Container::Yield::NO_YIELD)
} return false;
if (isNotLibraryFunction(ftok)) }
return false; return false;
}
const std::unordered_map<std::string, FalseTrueMaybe>::const_iterator it = mNoReturn.find(getFunctionName(ftok)); const std::unordered_map<std::string, FalseTrueMaybe>::const_iterator it = mNoReturn.find(getFunctionName(ftok));
if (it == mNoReturn.end()) if (it == mNoReturn.end())
return false; return false;