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
10using namespace std;
11using 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 */
17struct 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 */
29class plain_cpp_generator : public cpp_generator {
30 struct plain_printer;
31 struct decl_printer;
32 struct impl_printer;
33protected:
34 bool checked;
35public:
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();
43private:
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 */
70struct plain_cpp_generator::plain_printer : public cpp_generator::class_printer {
71 plain_cpp_generator &generator;
72
73 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 virtual void print_public_constructors() = 0;
85 virtual void print_copy_assignment() = 0;
86 virtual void print_destructor() = 0;
87 virtual void print_ptr() = 0;
88 virtual void print_downcast() = 0;
89 virtual void print_ctx() = 0;
90 virtual void print_method_separator() = 0;
91 virtual void print_persistent_callbacks() = 0;
92 void print_public_methods();
93 void print_id_constructor_user_header();
94 void print_id_user_header(bool optional);
95 virtual void print_id_constructor_user() = 0;
96 virtual void print_id_user(bool optional) = 0;
97 void print_special_id();
98 void print_special();
99};
100
101/* A helper class for printing method declarations of a class.
102 */
103struct plain_cpp_generator::decl_printer :
104 public plain_cpp_generator::plain_printer
105{
106 decl_printer(std::ostream &os, const isl_class &clazz,
107 plain_cpp_generator &generator) :
108 plain_printer(os, clazz, generator, true) {}
109
110 void print_subclass_type();
111 void print_class_factory(const std::string &prefix = std::string());
112 void print_protected_constructors();
113 virtual void print_copy_assignment() override;
114 virtual void print_public_constructors() override;
115 virtual void print_destructor() override;
116 virtual void print_ptr() override;
117 void print_isa_type_template(int indent, const isl_class &super);
118 virtual void print_downcast() override;
119 virtual void print_ctx() override;
120 virtual void print_method_separator() override;
121 void print_persistent_callback_data(FunctionDecl *method);
122 virtual void print_persistent_callbacks() override;
123 virtual void print_method(const Method &method) override;
124 virtual void print_method(const ConversionMethod &method) override;
125 virtual void print_get_method(FunctionDecl *fd) override;
126 virtual void print_id_constructor_user() override;
127 virtual void print_id_user(bool optional) override;
128};
129
130/* A helper class for printing method definitions of a class.
131 */
132struct plain_cpp_generator::impl_printer :
133 public plain_cpp_generator::plain_printer
134{
135 impl_printer(std::ostream &os, const isl_class &clazz,
136 plain_cpp_generator &generator) :
137 plain_printer(os, clazz, generator, false) {}
138
139 void print_arg_conversion(ParmVarDecl *dst, ParmVarDecl *src);
140 virtual void print_method(const Method &method) override;
141 virtual void print_method(const ConversionMethod &method) override;
142 virtual void print_get_method(FunctionDecl *fd) override;
143 void print_check_ptr(const char *ptr);
144 void print_check_ptr_start(const char *ptr);
145 void print_check_ptr_end(const char *ptr);
146 void print_class_factory();
147 void print_protected_constructors();
148 virtual void print_public_constructors() override;
149 virtual void print_copy_assignment() override;
150 virtual void print_destructor() override;
151 virtual void print_ptr() override;
152 virtual void print_downcast() override;
153 virtual void print_ctx() override;
154 virtual void print_method_separator() override;
155 void print_set_persistent_callback(const Method &method);
156 virtual void print_persistent_callbacks() override;
157 void print_argument_validity_check(const Method &method);
158 void print_save_ctx(const std::string &ctx);
159 void print_save_ctx(const Method &method);
160 void print_on_error_continue();
161 void print_exceptional_execution_check(const Method &method);
162 void print_method_return(const Method &method);
163 void print_stream_insertion();
164 void print_wrapped_call_checked(int indent, const std::string &call);
165 void print_wrapped_call(int indent, const std::string &call,
166 QualType rtype);
167 void print_callback_body(int indent, ParmVarDecl *param,
168 const string &name);
169 void print_callback_local(ParmVarDecl *param);
170 virtual void print_id_constructor_user() override;
171 virtual void print_id_user(bool optional) override;
172};
173
174#endif
175

source code of polly/lib/External/isl/interface/plain_cpp.h