1 #include "generator.h" 2 3 using namespace std; 4 using namespace clang; 5 6 /* Generator for C++ bindings. 7 * 8 * "checked" is set if C++ bindings should be generated 9 * that rely on the user to check for error conditions. 10 */ 11 class cpp_generator : public generator { 12 protected: 13 bool checked; 14 public: 15 cpp_generator(SourceManager &SM, set<RecordDecl *> &exported_types, 16 set<FunctionDecl *> exported_functions, 17 set<FunctionDecl *> functions, 18 bool checked = false) : generator(SM,exported_types,exported_functions,functions)19 generator(SM, exported_types, exported_functions, functions), 20 checked(checked) {} 21 22 enum function_kind { 23 function_kind_static_method, 24 function_kind_member_method, 25 function_kind_constructor, 26 }; 27 28 virtual void generate(); 29 private: 30 void print_file(ostream &os, std::string filename); 31 void print_forward_declarations(ostream &os); 32 void print_declarations(ostream &os); 33 void print_class(ostream &os, const isl_class &clazz); 34 void print_class_forward_decl(ostream &os, const isl_class &clazz); 35 void print_class_factory_decl(ostream &os, const isl_class &clazz, 36 const std::string &prefix = std::string()); 37 void print_private_constructors_decl(ostream &os, 38 const isl_class &clazz); 39 void print_copy_assignment_decl(ostream &os, const isl_class &clazz); 40 void print_public_constructors_decl(ostream &os, 41 const isl_class &clazz); 42 void print_constructors_decl(ostream &os, const isl_class &clazz); 43 void print_destructor_decl(ostream &os, const isl_class &clazz); 44 void print_ptr_decl(ostream &os, const isl_class &clazz); 45 void print_get_ctx_decl(ostream &os); 46 void print_methods_decl(ostream &os, const isl_class &clazz); 47 void print_method_group_decl(ostream &os, const isl_class &clazz, 48 const set<FunctionDecl *> &methods); 49 void print_method_decl(ostream &os, const isl_class &clazz, 50 FunctionDecl *method, function_kind kind); 51 void print_implementations(ostream &os); 52 void print_class_impl(ostream &os, const isl_class &clazz); 53 void print_check_ptr(ostream &os, const char *ptr); 54 void print_check_ptr_start(ostream &os, const isl_class &clazz, 55 const char *ptr); 56 void print_check_ptr_end(ostream &os, const char *ptr); 57 void print_class_factory_impl(ostream &os, const isl_class &clazz); 58 void print_private_constructors_impl(ostream &os, 59 const isl_class &clazz); 60 void print_public_constructors_impl(ostream &os, 61 const isl_class &clazz); 62 void print_constructors_impl(ostream &os, const isl_class &clazz); 63 void print_copy_assignment_impl(ostream &os, const isl_class &clazz); 64 void print_destructor_impl(ostream &os, const isl_class &clazz); 65 void print_ptr_impl(ostream &os, const isl_class &clazz); 66 void print_get_ctx_impl(ostream &os, const isl_class &clazz); 67 void print_methods_impl(ostream &os, const isl_class &clazz); 68 void print_method_group_impl(ostream &os, const isl_class &clazz, 69 const set<FunctionDecl *> &methods); 70 void print_argument_validity_check(ostream &os, FunctionDecl *method, 71 function_kind kind); 72 void print_save_ctx(ostream &os, FunctionDecl *method, 73 function_kind kind); 74 void print_on_error_continue(ostream &os); 75 void print_exceptional_execution_check(ostream &os, 76 FunctionDecl *method); 77 void print_method_return(ostream &os, const isl_class &clazz, 78 FunctionDecl *method); 79 void print_method_impl(ostream &os, const isl_class &clazz, 80 FunctionDecl *method, function_kind kind); 81 void print_method_param_use(ostream &os, ParmVarDecl *param, 82 bool load_from_this_ptr); 83 void print_method_header(ostream &os, const isl_class &clazz, 84 FunctionDecl *method, bool is_declaration, function_kind kind); 85 string generate_callback_args(QualType type, bool cpp); 86 string generate_callback_type(QualType type); 87 void print_wrapped_call_checked(std::ostream &os, 88 const std::string &call); 89 void print_wrapped_call(std::ostream &os, const std::string &call); 90 void print_callback_local(ostream &os, ParmVarDecl *param); 91 std::string rename_method(std::string name); 92 string type2cpp(const isl_class &clazz); 93 string type2cpp(QualType type); 94 bool is_implicit_conversion(const isl_class &clazz, FunctionDecl *cons); 95 bool is_subclass(QualType subclass_type, const isl_class &class_type); 96 function_kind get_method_kind(const isl_class &clazz, 97 FunctionDecl *method); 98 public: 99 static string type2cpp(string type_string); 100 }; 101