File indexing completed on 2024-05-12 17:13:19
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 "detachingbase.h" 0026 #include "StringUtils.h" 0027 #include "QtUtils.h" 0028 #include "clazy_stl.h" 0029 0030 #include <clang/AST/DeclCXX.h> 0031 #include <llvm/ADT/StringRef.h> 0032 0033 #include <unordered_map> 0034 #include <utility> 0035 #include <vector> 0036 0037 class ClazyContext; 0038 0039 using namespace clang; 0040 using namespace std; 0041 0042 DetachingBase::DetachingBase(const std::string &name, ClazyContext *context, Options options) 0043 : CheckBase(name, context, options) 0044 { 0045 } 0046 0047 bool DetachingBase::isDetachingMethod(CXXMethodDecl *method, DetachingMethodType detachingMethodType) const 0048 { 0049 if (!method) 0050 return false; 0051 0052 CXXRecordDecl *record = method->getParent(); 0053 if (!record) 0054 return false; 0055 0056 StringRef className = clazy::name(record); 0057 0058 const std::unordered_map<string, std::vector<StringRef>> &methodsByType = detachingMethodType == DetachingMethod ? clazy::detachingMethods() 0059 : clazy::detachingMethodsWithConstCounterParts(); 0060 auto it = methodsByType.find(static_cast<std::string>(className)); 0061 if (it != methodsByType.cend()) { 0062 const auto &methods = it->second; 0063 if (clazy::contains(methods, clazy::name(method))) 0064 return true; 0065 } 0066 0067 return false; 0068 }