| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2019 Sergio Martins <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "overloaded-signal.h" |
| 8 |
#include "AccessSpecifierManager.h" |
| 9 |
#include "FunctionUtils.h" |
| 10 |
#include "QtUtils.h" |
| 11 |
#include "TypeUtils.h" |
| 12 |
#include "Utils.h" |
| 13 |
|
| 14 |
#include <ClazyContext.h> |
| 15 |
#include <clang/AST/AST.h> |
| 16 |
|
| 17 |
using namespace clang; |
| 18 |
|
| 19 |
void OverloadedSignal::VisitDecl(clang::Decl *decl) |
| 20 |
{ |
| 21 |
const AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager; |
| 22 |
auto *method = dyn_cast<CXXMethodDecl>(decl); |
| 23 |
if (!accessSpecifierManager || !method) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
if (method->isThisDeclarationADefinition() && !method->hasInlineBody()) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
CXXRecordDecl *record = method->getParent(); |
| 32 |
|
| 33 |
const bool methodIsSignal = accessSpecifierManager->qtAccessSpecifierType(method) == QtAccessSpecifier_Signal; |
| 34 |
if (!methodIsSignal) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
const StringRef methodName = clazy::name(method); |
| 39 |
CXXRecordDecl *p = record; // baseClass starts at record so we check overloaded methods there |
| 40 |
while (p) { |
| 41 |
for (auto *m : p->methods()) { |
| 42 |
if (clazy::name(m) == methodName) { |
| 43 |
if (!clazy::parametersMatch(m, method)) { |
| 44 |
if (p == record) { |
| 45 |
emitWarning(decl, "signal " + methodName.str() + " is overloaded"); |
| 46 |
continue; // No point in spitting more warnings for the same signal |
| 47 |
} |
| 48 |
emitWarning(decl, "signal " + methodName.str() + " is overloaded (with " + p->getBeginLoc().printToString(sm()) + ")"); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
p = clazy::getQObjectBaseClass(p, m_context->qtNamespace()); |
| 54 |
} |
| 55 |
} |