File indexing completed on 2024-04-28 05:38:35
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 "detachingbase.h" 0011 #include "QtUtils.h" 0012 #include "StringUtils.h" 0013 #include "clazy_stl.h" 0014 0015 #include <clang/AST/DeclCXX.h> 0016 #include <llvm/ADT/StringRef.h> 0017 0018 #include <unordered_map> 0019 #include <vector> 0020 0021 class ClazyContext; 0022 0023 using namespace clang; 0024 0025 DetachingBase::DetachingBase(const std::string &name, ClazyContext *context, Options options) 0026 : CheckBase(name, context, options) 0027 { 0028 } 0029 0030 bool DetachingBase::isDetachingMethod(CXXMethodDecl *method, DetachingMethodType detachingMethodType) const 0031 { 0032 if (!method) { 0033 return false; 0034 } 0035 0036 CXXRecordDecl *record = method->getParent(); 0037 if (!record) { 0038 return false; 0039 } 0040 0041 StringRef className = clazy::name(record); 0042 0043 const std::unordered_map<std::string, std::vector<StringRef>> &methodsByType = 0044 detachingMethodType == DetachingMethod ? clazy::detachingMethods() : clazy::detachingMethodsWithConstCounterParts(); 0045 auto it = methodsByType.find(static_cast<std::string>(className)); 0046 if (it != methodsByType.cend()) { 0047 const auto &methods = it->second; 0048 if (clazy::contains(methods, clazy::name(method))) { 0049 return true; 0050 } 0051 } 0052 0053 return false; 0054 }