MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / getParentValueTypes

Function getParentValueTypes

lib/astutils.cpp:737–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

735}
736
737std::vector<ValueType> getParentValueTypes(const Token* tok, const Settings& settings, const Token** parent)
738{
739 if (!tok)
740 return {};
741 if (!tok->astParent())
742 return {};
743 if (isInConstructorList(tok)) {
744 if (parent)
745 *parent = tok->astParent()->astOperand1();
746 if (tok->astParent()->astOperand1()->valueType())
747 return {*tok->astParent()->astOperand1()->valueType()};
748 return {};
749 }
750 const Token* ftok = nullptr;
751 if (Token::Match(tok->astParent(), "(|{|,")) {
752 int argn = -1;
753 ftok = getTokenArgumentFunction(tok, argn);
754 const Token* typeTok = nullptr;
755 if (ftok && argn >= 0) {
756 if (ftok->function()) {
757 std::vector<ValueType> result;
758 const Token* nameTok = nullptr;
759 for (const Variable* var : getArgumentVars(ftok, argn)) {
760 if (!var)
761 continue;
762 if (!var->valueType())
763 continue;
764 nameTok = var->nameToken();
765 result.push_back(*var->valueType());
766 if (var->isArray())
767 result.back().pointer += var->dimensions().size();
768 }
769 if (result.size() == 1 && nameTok && parent) {
770 *parent = nameTok;
771 }
772 return result;
773 }
774 if (const Type* t = Token::typeOf(ftok, &typeTok)) {
775 if (astIsPointer(typeTok))
776 return {*typeTok->valueType()};
777 const Scope* scope = t->classScope;
778 // Check for aggregate constructors
779 if (scope && scope->numConstructors == 0 && t->derivedFrom.empty() &&
780 (t->isClassType() || t->isStructType()) && numberOfArguments(ftok) <= scope->varlist.size() &&
781 !scope->varlist.empty()) {
782 if (argn < scope->varlist.size()) {
783 auto it = std::next(scope->varlist.cbegin(), argn);
784 if (it->valueType())
785 return { *it->valueType() };
786 }
787 }
788 }
789 }
790 }
791 if (Token::Match(tok->astParent()->tokAt(-2), ". push_back|push_front|insert|push (") &&
792 astIsContainer(tok->astParent()->tokAt(-2)->astOperand1())) {
793 const Token* contTok = tok->astParent()->tokAt(-2)->astOperand1();
794 const ValueType* vtCont = contTok->valueType();

Callers 6

isConvertedToIntegralFunction · 0.85
getLifetimeTokensFunction · 0.85
isLifetimeBorrowedMethod · 0.85
isConvertedToViewFunction · 0.85
isUsedAsBoolFunction · 0.85

Calls 15

isInConstructorListFunction · 0.85
getTokenArgumentFunctionFunction · 0.85
getArgumentVarsFunction · 0.85
astIsPointerFunction · 0.85
numberOfArgumentsFunction · 0.85
nextFunction · 0.85
astIsContainerFunction · 0.85
astParentMethod · 0.80
astOperand1Method · 0.80
isArrayMethod · 0.80
isClassTypeMethod · 0.80
isStructTypeMethod · 0.80

Tested by

no test coverage detected