From ec4ece19763ef983b6604ccc5d7c13a0aaeb7e44 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 5 Jul 2017 14:07:48 +0200 Subject: [PATCH] cpp: generate get_ctx method for all exported classes This function is useful for creating objects in the same isl_ctx as that of some other object. No corresponding methods are generated for the Python bindings because the Python bindings use an implicit global isl_ctx. Signed-off-by: Sven Verdoolaege --- interface/cpp.cc | 23 +++++++++++++++++++++++ interface/cpp.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/interface/cpp.cc b/interface/cpp.cc index c56ebd05..916a9d36 100644 --- a/interface/cpp.cc +++ b/interface/cpp.cc @@ -169,6 +169,7 @@ void cpp_generator::print_class(ostream &os, const isl_class &clazz) print_copy_assignment_decl(os, clazz); print_destructor_decl(os, clazz); print_ptr_decl(os, clazz); + print_get_ctx_decl(os); osprintf(os, "\n"); print_methods_decl(os, clazz); @@ -361,6 +362,13 @@ void cpp_generator::print_ptr_decl(ostream &os, const isl_class &clazz) osprintf(os, " inline bool is_null() const;\n"); } +/* Print the declaration of the get_ctx method. + */ +void cpp_generator::print_get_ctx_decl(ostream &os) +{ + osprintf(os, " inline isl::ctx get_ctx() const;\n"); +} + /* Print declarations for methods in class "clazz" to "os". */ void cpp_generator::print_methods_decl(ostream &os, const isl_class &clazz) @@ -426,6 +434,8 @@ void cpp_generator::print_class_impl(ostream &os, const isl_class &clazz) osprintf(os, "\n"); print_ptr_impl(os, clazz); osprintf(os, "\n"); + print_get_ctx_impl(os, clazz); + osprintf(os, "\n"); print_methods_impl(os, clazz); } @@ -547,6 +557,19 @@ void cpp_generator::print_ptr_impl(ostream &os, const isl_class &clazz) osprintf(os, "}\n"); } +/* Print the implementation of the get_ctx method. + */ +void cpp_generator::print_get_ctx_impl(ostream &os, const isl_class &clazz) +{ + const char *name = clazz.name.c_str(); + std::string cppstring = type2cpp(clazz); + const char *cppname = cppstring.c_str(); + + osprintf(os, "isl::ctx %s::get_ctx() const {\n", cppname); + osprintf(os, " return isl::ctx(%s_get_ctx(ptr));\n", name); + osprintf(os, "}\n"); +} + /* Print definitions for methods of class "clazz" to "os". */ void cpp_generator::print_methods_impl(ostream &os, const isl_class &clazz) diff --git a/interface/cpp.h b/interface/cpp.h index 1978e261..3d8d6603 100644 --- a/interface/cpp.h +++ b/interface/cpp.h @@ -33,6 +33,7 @@ private: void print_constructors_decl(ostream &os, const isl_class &clazz); void print_destructor_decl(ostream &os, const isl_class &clazz); void print_ptr_decl(ostream &os, const isl_class &clazz); + void print_get_ctx_decl(ostream &os); void print_methods_decl(ostream &os, const isl_class &clazz); void print_method_group_decl(ostream &os, const isl_class &clazz, const string &fullname, const set &methods); @@ -50,6 +51,7 @@ private: void print_copy_assignment_impl(ostream &os, const isl_class &clazz); void print_destructor_impl(ostream &os, const isl_class &clazz); void print_ptr_impl(ostream &os, const isl_class &clazz); + void print_get_ctx_impl(ostream &os, const isl_class &clazz); void print_methods_impl(ostream &os, const isl_class &clazz); void print_method_group_impl(ostream &os, const isl_class &clazz, const string &fullname, const set &methods); -- 2.11.4.GIT