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

Method getFunctionName

lib/library.cpp:1160–1205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1158}
1159
1160std::string Library::getFunctionName(const Token *ftok, bool &error) const
1161{
1162 if (!ftok) {
1163 error = true;
1164 return "";
1165 }
1166 if (ftok->isName()) {
1167 if (Token::simpleMatch(ftok->astParent(), "::"))
1168 return ftok->str();
1169 for (const Scope *scope = ftok->scope(); scope; scope = scope->nestedIn) {
1170 if (!scope->isClassOrStruct())
1171 continue;
1172 const std::vector<Type::BaseInfo> &derivedFrom = scope->definedType->derivedFrom;
1173 for (const Type::BaseInfo & baseInfo : derivedFrom) {
1174 std::string name;
1175 const Token* tok = baseInfo.nameTok; // baseInfo.name still contains template parameters, but is missing namespaces
1176 if (tok->str() == "::")
1177 tok = tok->next();
1178 while (Token::Match(tok, "%name%|::")) {
1179 name += tok->str();
1180 tok = tok->next();
1181 }
1182 name += "::" + ftok->str();
1183 if (mData->mFunctions.find(name) != mData->mFunctions.end() && matchArguments(ftok, name))
1184 return name;
1185 }
1186 }
1187 return ftok->str();
1188 }
1189 if (ftok->str() == "::") {
1190 if (!ftok->astOperand2())
1191 return getFunctionName(ftok->astOperand1(), error);
1192 return getFunctionName(ftok->astOperand1(),error) + "::" + getFunctionName(ftok->astOperand2(),error);
1193 }
1194 if (ftok->str() == "." && ftok->astOperand1()) {
1195 const std::string type = astCanonicalType(ftok->astOperand1(), ftok->originalName() == "->");
1196 if (type.empty()) {
1197 error = true;
1198 return "";
1199 }
1200
1201 return type + "::" + getFunctionName(ftok->astOperand2(),error);
1202 }
1203 error = true;
1204 return "";
1205}
1206
1207std::string Library::getFunctionName(const Token *ftok) const
1208{

Callers 6

assertWithSideEffectsMethod · 0.80
configurationInfoMethod · 0.80
checkScopeMethod · 0.80
functionCallMethod · 0.80
hasNoreturnFunctionFunction · 0.80

Calls 15

astCanonicalTypeFunction · 0.85
astParentMethod · 0.80
scopeMethod · 0.80
nextMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
isUnaryOpMethod · 0.80
simpleMatchFunction · 0.70
startsWithFunction · 0.70
strMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected