diff options
Diffstat (limited to 'src/FunctionUtils.h')
-rw-r--r-- | src/FunctionUtils.h | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/FunctionUtils.h b/src/FunctionUtils.h index 327078da..a8f3a499 100644 --- a/src/FunctionUtils.h +++ b/src/FunctionUtils.h @@ -29,11 +29,12 @@ #include "Utils.h" #include "HierarchyUtils.h" +#include "StringUtils.h" #include <clang/AST/Decl.h> #include <string> -namespace FunctionUtils { +namespace clazy { inline bool hasCharPtrArgument(clang::FunctionDecl *func, int expected_arguments = -1) { @@ -65,15 +66,14 @@ inline clang::ValueDecl *valueDeclForCallArgument(clang::CallExpr *call, unsigne clang::Expr *firstArg = call->getArg(argIndex); auto declRef = llvm::isa<clang::DeclRefExpr>(firstArg) ? llvm::cast<clang::DeclRefExpr>(firstArg) - : HierarchyUtils::getFirstChildOfType2<clang::DeclRefExpr>(firstArg); + : clazy::getFirstChildOfType2<clang::DeclRefExpr>(firstArg); if (!declRef) return nullptr; return declRef->getDecl(); } - -inline bool parametersMatch(clang::FunctionDecl *f1, clang::FunctionDecl *f2) +inline bool parametersMatch(const clang::FunctionDecl *f1, const clang::FunctionDecl *f2) { if (!f1 || !f2) return false; @@ -95,6 +95,23 @@ inline bool parametersMatch(clang::FunctionDecl *f1, clang::FunctionDecl *f2) return true; } +/** + * Returns true if a class contains a method with a specific signature. + * (method->getParent() doesn't need to equal record) + */ +inline bool classImplementsMethod(const clang::CXXRecordDecl *record, const clang::CXXMethodDecl *method) +{ + if (!method->getDeclName().isIdentifier()) + return false; + + StringRef methodName = method->getName(); + for (auto m : record->methods()) { + if (!m->isPure() && clazy::name(m) == methodName && parametersMatch(m, method)) + return true; + } + + return false; +} } #endif |