File indexing completed on 2024-04-21 05:38:48

0001 /*
0002     SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB a KDAB Group company info@kdab.com
0003     SPDX-FileContributor: SĂ©rgio Martins <sergio.martins@kdab.com>
0004 
0005     SPDX-FileCopyrightText: 2015 Sergio Martins <smartins@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "StringUtils.h"
0011 
0012 #include <string>
0013 #include <vector>
0014 
0015 namespace clang
0016 {
0017 class LangOptions;
0018 } // namespace clang
0019 
0020 using namespace clang;
0021 
0022 std::string clazy::simpleArgTypeName(clang::FunctionDecl *func, unsigned int index, const clang::LangOptions &lo)
0023 {
0024     if (!func || index >= func->getNumParams()) {
0025         return {};
0026     }
0027 
0028     ParmVarDecl *parm = func->getParamDecl(index);
0029     return simpleTypeName(parm, lo);
0030 }
0031 
0032 bool clazy::anyArgIsOfSimpleType(clang::FunctionDecl *func, const std::string &simpleType, const clang::LangOptions &lo)
0033 {
0034     if (!func) {
0035         return false;
0036     }
0037 
0038     return clazy::any_of(Utils::functionParameters(func), [simpleType, lo](ParmVarDecl *p) {
0039         return simpleTypeName(p, lo) == simpleType;
0040     });
0041 }
0042 
0043 bool clazy::anyArgIsOfAnySimpleType(clang::FunctionDecl *func, const std::vector<std::string> &simpleTypes, const clang::LangOptions &lo)
0044 {
0045     if (!func) {
0046         return false;
0047     }
0048 
0049     return clazy::any_of(simpleTypes, [func, lo](const std::string &simpleType) {
0050         return clazy::anyArgIsOfSimpleType(func, simpleType, lo);
0051     });
0052 }