File indexing completed on 2024-04-28 16:57:52
0001 /* 0002 This file is part of the clazy static checker. 0003 0004 Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com 0005 Author: Sérgio Martins <sergio.martins@kdab.com> 0006 0007 Copyright (C) 2015 Sergio Martins <smartins@kde.org> 0008 0009 This library is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this library; see the file COPYING.LIB. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 Boston, MA 02110-1301, USA. 0023 */ 0024 0025 #include "StringUtils.h" 0026 0027 #include <string> 0028 #include <vector> 0029 0030 namespace clang { 0031 class LangOptions; 0032 } // namespace clang 0033 0034 using namespace std; 0035 using namespace clang; 0036 0037 std::string clazy::simpleArgTypeName(clang::FunctionDecl *func, unsigned int index, const clang::LangOptions &lo) 0038 { 0039 if (!func || index >= func->getNumParams()) 0040 return {}; 0041 0042 ParmVarDecl *parm = func->getParamDecl(index); 0043 return simpleTypeName(parm, lo); 0044 } 0045 0046 bool clazy::anyArgIsOfSimpleType(clang::FunctionDecl *func, 0047 const std::string &simpleType, 0048 const clang::LangOptions &lo) 0049 { 0050 if (!func) 0051 return false; 0052 0053 return clazy::any_of(Utils::functionParameters(func), [simpleType, lo](ParmVarDecl *p){ 0054 return simpleTypeName(p, lo) == simpleType; 0055 }); 0056 } 0057 0058 bool clazy::anyArgIsOfAnySimpleType(clang::FunctionDecl *func, 0059 const vector<string> &simpleTypes, 0060 const clang::LangOptions &lo) 0061 { 0062 if (!func) 0063 return false; 0064 0065 return clazy::any_of(simpleTypes, [func, lo](const string &simpleType) { 0066 return clazy::anyArgIsOfSimpleType(func, simpleType, lo); 0067 }); 0068 }