diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2013-12-10 14:07:18 +0000 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2013-12-10 14:09:04 +0000 |
commit | a94c6b1fef6cb3380323c818f14e3512d1831983 (patch) | |
tree | f84f27d9d5a796f7a51bcc0b7efe5f731de9611b /clang-plugin | |
parent | 2be05e5c86dff0ffd45e20f580a7e34ab29636a8 (diff) |
clang-plugin: Use a shared_ptr for the GirManager
It’s shared between multiple AST consumers, but owned by the original
plugin object, which is destroyed immediately after CreateASTConsumer()
returns. Instead of using a normal pointer, use a shared_ptr to the
GirManager so it’s kept alive for the consumers to use.
Diffstat (limited to 'clang-plugin')
-rw-r--r-- | clang-plugin/gir-attributes.cpp | 2 | ||||
-rw-r--r-- | clang-plugin/gir-attributes.h | 5 | ||||
-rw-r--r-- | clang-plugin/gir-manager.cpp | 8 | ||||
-rw-r--r-- | clang-plugin/nullability-checker.cpp | 3 | ||||
-rw-r--r-- | clang-plugin/nullability-checker.h | 6 | ||||
-rw-r--r-- | clang-plugin/plugin.cpp | 12 |
6 files changed, 21 insertions, 15 deletions
diff --git a/clang-plugin/gir-attributes.cpp b/clang-plugin/gir-attributes.cpp index 3f590f2..f66f87f 100644 --- a/clang-plugin/gir-attributes.cpp +++ b/clang-plugin/gir-attributes.cpp @@ -103,7 +103,7 @@ GirAttributesConsumer::_handle_function_decl (FunctionDecl& func) /* Try to find typelib information about the function. */ const std::string func_name = func.getNameAsString (); /* TODO: expensive? */ - GIBaseInfo *info = this->_gir_manager.find_function_info (func_name); + GIBaseInfo *info = this->_gir_manager.get ()->find_function_info (func_name); if (info == NULL) return; diff --git a/clang-plugin/gir-attributes.h b/clang-plugin/gir-attributes.h index 2b242e6..b0968a4 100644 --- a/clang-plugin/gir-attributes.h +++ b/clang-plugin/gir-attributes.h @@ -35,11 +35,12 @@ using namespace clang; class GirAttributesConsumer : public ASTConsumer { public: - explicit GirAttributesConsumer (const GirManager& gir_manager) : + explicit GirAttributesConsumer ( + std::shared_ptr<const GirManager> gir_manager) : _gir_manager (gir_manager) {} private: - const GirManager& _gir_manager; + std::shared_ptr<const GirManager> _gir_manager; void _handle_function_decl (FunctionDecl& func); public: diff --git a/clang-plugin/gir-manager.cpp b/clang-plugin/gir-manager.cpp index f75f564..9025b4a 100644 --- a/clang-plugin/gir-manager.cpp +++ b/clang-plugin/gir-manager.cpp @@ -53,7 +53,7 @@ GirManager::load_namespace (const std::string& gi_namespace, g_irepository_get_c_prefix (this->_repo, gi_namespace.c_str ()); - Nspace r = Nspace (); + Nspace r; r.nspace = gi_namespace; r.version = gi_version; r.c_prefix = std::string (c_prefix); @@ -72,9 +72,9 @@ GirManager::find_function_info (const std::string& func_name) const GIBaseInfo *info = NULL; std::string func_name_stripped; - for (std::vector<Nspace>::const_iterator it = this->_typelibs.begin (); - it != this->_typelibs.end (); ++it) { - Nspace r = *it; + for (std::vector<Nspace>::const_iterator it = this->_typelibs.begin (), + ie = this->_typelibs.end (); it != ie; ++it) { + const Nspace r = *it; DEBUG ("Looking for function " << func_name << " in repository " << r.nspace << " (version " << diff --git a/clang-plugin/nullability-checker.cpp b/clang-plugin/nullability-checker.cpp index 7a69225..5cf3f17 100644 --- a/clang-plugin/nullability-checker.cpp +++ b/clang-plugin/nullability-checker.cpp @@ -93,7 +93,8 @@ NullabilityVisitor::TraverseFunctionDecl (FunctionDecl* func) /* Try to find typelib information about the function. */ std::string func_name = func->getNameAsString (); /* TODO: expensive? */ - GIBaseInfo* info = this->_gir_manager.find_function_info (func_name); + GIBaseInfo* info = + this->_gir_manager.get ()->find_function_info (func_name); if (info == NULL) return true; diff --git a/clang-plugin/nullability-checker.h b/clang-plugin/nullability-checker.h index c254089..8a913cf 100644 --- a/clang-plugin/nullability-checker.h +++ b/clang-plugin/nullability-checker.h @@ -35,14 +35,14 @@ using namespace clang; class NullabilityVisitor : public RecursiveASTVisitor<NullabilityVisitor> { public: explicit NullabilityVisitor (CompilerInstance& compiler, - const GirManager& gir_manager) : + std::shared_ptr<const GirManager> gir_manager) : _compiler (compiler), _context (compiler.getASTContext ()), _gir_manager (gir_manager) {} private: CompilerInstance& _compiler; const ASTContext& _context; - const GirManager& _gir_manager; + std::shared_ptr<const GirManager> _gir_manager; public: bool TraverseFunctionDecl (FunctionDecl* func); @@ -51,7 +51,7 @@ public: class NullabilityConsumer : public ASTConsumer { public: NullabilityConsumer (CompilerInstance& compiler, - const GirManager& gir_manager) : + std::shared_ptr<const GirManager> gir_manager) : _visitor (compiler, gir_manager) {} private: diff --git a/clang-plugin/plugin.cpp b/clang-plugin/plugin.cpp index faf1e5f..acd90c2 100644 --- a/clang-plugin/plugin.cpp +++ b/clang-plugin/plugin.cpp @@ -40,11 +40,14 @@ namespace { */ class GnomeAction : public PluginASTAction { private: - GirManager _gir_manager; + std::shared_ptr<GirManager> _gir_manager = + std::make_shared<GirManager> (); protected: /* Note: This is called before ParseArgs, and must transfer ownership - * of the ASTConsumer. */ + * of the ASTConsumer. The GnomeAction object is destroyed immediately + * after this function call returns, so must be careful not to retain + * state which is needed by the consumers. */ ASTConsumer * CreateASTConsumer (CompilerInstance &compiler, llvm::StringRef in_file) { @@ -104,8 +107,9 @@ private: /* Load the repository. */ GError *error = NULL; - this->_gir_manager.load_namespace (gi_namespace, gi_version, - &error); + this->_gir_manager.get ()->load_namespace (gi_namespace, + gi_version, + &error); if (error != NULL) { DiagnosticsEngine &d = CI.getDiagnostics (); unsigned int id = d.getCustomDiagID ( |