1 #ifndef ISL_INTERFACE_PLAIN_CPP_H 2 #define ISL_INTERFACE_PLAIN_CPP_H 3 4 #include <functional> 5 #include <memory> 6 7 #include "cpp.h" 8 #include "generator.h" 9 10 using namespace std; 11 using namespace clang; 12 13 /* A type printer for converting argument and return types 14 * to string representations of the corresponding types 15 * in the checked C++ interface. 16 */ 17 struct checked_cpp_type_printer : public cpp_type_printer { 18 virtual std::string isl_bool() const override; 19 virtual std::string isl_stat() const override; 20 virtual std::string isl_size() const override; 21 virtual std::string isl_namespace() const override; 22 }; 23 24 /* Generator for plain C++ bindings. 25 * 26 * "checked" is set if C++ bindings should be generated 27 * that rely on the user to check for error conditions. 28 */ 29 class plain_cpp_generator : public cpp_generator { 30 struct plain_printer; 31 struct decl_printer; 32 struct impl_printer; 33 protected: 34 bool checked; 35 public: 36 plain_cpp_generator(SourceManager &SM, 37 set<RecordDecl *> &exported_types, 38 set<FunctionDecl *> exported_functions, 39 set<FunctionDecl *> functions, 40 bool checked = false); 41 42 virtual void generate(); 43 private: 44 void print_forward_declarations(ostream &os); 45 void print_declarations(ostream &os); 46 void print_class(ostream &os, const isl_class &clazz); 47 void print_class_forward_decl(ostream &os, const isl_class &clazz); 48 void print_implementations(ostream &os); 49 void print_class_impl(ostream &os, const isl_class &clazz); 50 void print_check_no_persistent_callback(ostream &os, 51 const isl_class &clazz, FunctionDecl *fd); 52 void print_invalid(ostream &os, int indent, const char *msg, 53 const char *checked_code); 54 void print_method_param_use(ostream &os, ParmVarDecl *param, 55 bool load_from_this_ptr); 56 std::unique_ptr<cpp_type_printer> type_printer(); 57 std::string get_return_type(const Method &method); 58 string generate_callback_args(QualType type, bool cpp); 59 string generate_callback_type(QualType type); 60 string isl_bool2cpp(); 61 string isl_namespace(); 62 string param2cpp(QualType type); 63 }; 64 65 /* A helper class for printing method declarations and definitions 66 * of a class for the plain C++ interface. 67 * 68 * "generator" is the C++ interface generator printing the classes. 69 */ 70 struct plain_cpp_generator::plain_printer : public cpp_generator::class_printer { 71 plain_cpp_generator &generator; 72 plain_printerplain_printer73 plain_printer(std::ostream &os, const isl_class &clazz, 74 plain_cpp_generator &generator, bool is_declaration) : 75 class_printer(os, clazz, generator, is_declaration), 76 generator(generator) {} 77 78 void print_persistent_callback_prototype(FunctionDecl *method); 79 void print_persistent_callback_setter_prototype(FunctionDecl *method); 80 void print_full_method_header(const Method &method); 81 void print_callback_data_decl(ParmVarDecl *param, const string &name); 82 virtual bool want_descendent_overloads(const function_set &methods) 83 override; 84 }; 85 86 /* A helper class for printing method declarations of a class. 87 */ 88 struct plain_cpp_generator::decl_printer : 89 public plain_cpp_generator::plain_printer 90 { decl_printerdecl_printer91 decl_printer(std::ostream &os, const isl_class &clazz, 92 plain_cpp_generator &generator) : 93 plain_printer(os, clazz, generator, true) {} 94 95 void print_subclass_type(); 96 void print_class_factory(const std::string &prefix = std::string()); 97 void print_protected_constructors(); 98 void print_copy_assignment(); 99 void print_public_constructors(); 100 void print_destructor(); 101 void print_ptr(); 102 void print_isa_type_template(int indent, const isl_class &super); 103 void print_downcast(); 104 void print_ctx(); 105 void print_persistent_callback_data(FunctionDecl *method); 106 void print_persistent_callbacks(); 107 virtual void print_method(const Method &method) override; 108 virtual void print_method(const ConversionMethod &method) override; 109 virtual void print_get_method(FunctionDecl *fd) override; 110 }; 111 112 /* A helper class for printing method definitions of a class. 113 */ 114 struct plain_cpp_generator::impl_printer : 115 public plain_cpp_generator::plain_printer 116 { impl_printerimpl_printer117 impl_printer(std::ostream &os, const isl_class &clazz, 118 plain_cpp_generator &generator) : 119 plain_printer(os, clazz, generator, false) {} 120 121 void print_arg_conversion(ParmVarDecl *dst, ParmVarDecl *src); 122 virtual void print_method(const Method &method) override; 123 virtual void print_method(const ConversionMethod &method) override; 124 virtual void print_get_method(FunctionDecl *fd) override; 125 void print_check_ptr(const char *ptr); 126 void print_check_ptr_start(const char *ptr); 127 void print_check_ptr_end(const char *ptr); 128 void print_class_factory(); 129 void print_protected_constructors(); 130 void print_public_constructors(); 131 void print_copy_assignment(); 132 void print_destructor(); 133 void print_ptr(); 134 void print_downcast(); 135 void print_ctx(); 136 void print_set_persistent_callback(const Method &method); 137 void print_persistent_callbacks(); 138 void print_argument_validity_check(const Method &method); 139 void print_save_ctx(const Method &method); 140 void print_on_error_continue(); 141 void print_exceptional_execution_check(const Method &method); 142 void print_method_return(const Method &method); 143 void print_stream_insertion(); 144 void print_wrapped_call_checked(int indent, const std::string &call); 145 void print_wrapped_call(int indent, const std::string &call, 146 QualType rtype); 147 void print_callback_body(int indent, ParmVarDecl *param, 148 const string &name); 149 void print_callback_local(ParmVarDecl *param); 150 }; 151 152 #endif 153