summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/plugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r--compilerplugins/clang/plugin.cxx27
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 {