diff options
author | Noel Grandin <noel@peralex.com> | 2016-06-28 14:52:54 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-06-28 14:53:17 +0200 |
commit | 442dd6a153385d7c2826eabe0737d4d53332f392 (patch) | |
tree | e16a8a31526551de1f6810a0c22a6ac898231bf4 /compilerplugins/clang/plugin.cxx | |
parent | e3e79246cb7dd28a8b3511cefd0c41cf19b3e7de (diff) |
loplugin: move parentFunctionDecl() into common code
Change-Id: Ia10a76a98a63c6ea3b516d9146281f672b213ab3
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 04dcceb07e68..af618de232b8 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -75,6 +75,33 @@ Stmt* Plugin::parentStmt( Stmt* stmt ) return const_cast< Stmt* >( parents[ stmt ] ); } +static const Decl* getDeclContext(ASTContext& context, const Stmt* stmt) + { + auto it = context.getParents(*stmt).begin(); + + if (it == context.getParents(*stmt).end()) + return nullptr; + + const Decl *aDecl = it->get<Decl>(); + if (aDecl) + return aDecl; + + const Stmt *aStmt = it->get<Stmt>(); + if (aStmt) + return getDeclContext(context, aStmt); + + return nullptr; + } + +const FunctionDecl* Plugin::parentFunctionDecl( const Stmt* stmt ) + { + const Decl *decl = getDeclContext(compiler.getASTContext(), stmt); + if (decl) + return static_cast<const FunctionDecl*>(decl->getNonClosureContext()); + + return nullptr; + } + bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const { StringRef name { |