Polly 19.0.0git
cpp.h
Go to the documentation of this file.
1#ifndef ISL_INTERFACE_CPP_H
2#define ISL_INTERFACE_CPP_H
3
4#include <iostream>
5#include <string>
6#include <vector>
7
8#include "generator.h"
9
10/* A generated C++ method derived from an isl function.
11 *
12 * "clazz" is the class to which the method belongs.
13 * "fd" is the original isl function.
14 * "name" is the name of the method, which may be different
15 * from the default name derived from "fd".
16 * "kind" is the type of the method.
17 * "callbacks" stores the callback arguments.
18 */
19struct Method {
20 enum Kind {
24 };
25
26 struct list_combiner;
27 static list_combiner print_combiner(std::ostream &os);
28 static list_combiner empty_combiner();
29
30 Method(const isl_class &clazz, FunctionDecl *fd,
31 const std::string &name);
32 Method(const isl_class &clazz, FunctionDecl *fd);
33
34 int c_num_params() const;
35 virtual int num_params() const;
36 virtual bool param_needs_copy(int pos) const;
37 virtual clang::ParmVarDecl *get_param(int pos) const;
38 virtual void print_param_use(ostream &os, int pos) const;
39 bool is_subclass_mutator() const;
40 static void on_arg_list(int start, int end,
41 const list_combiner &combiner,
42 const std::function<bool(int i)> &on_arg_skip_next);
43 static void print_arg_list(std::ostream &os, int start, int end,
44 const std::function<bool(int i)> &print_arg_skip_next);
45 void on_fd_arg_list(int start, int end,
46 const list_combiner &combiner,
47 const std::function<void(int i, int arg)> &on_arg) const;
48 void print_fd_arg_list(std::ostream &os, int start, int end,
49 const std::function<void(int i, int arg)> &print_arg) const;
50 void on_cpp_arg_list(const list_combiner &combiner,
51 const std::function<void(int i, int arg)> &on_arg) const;
52 void on_cpp_arg_list(
53 const std::function<void(int i, int arg)> &on_arg) const;
54 void print_cpp_arg_list(std::ostream &os,
55 const std::function<void(int i, int arg)> &print_arg) const;
56
58 FunctionDecl *const fd;
59 const std::string name;
60 const enum Kind kind;
61 const std::vector<ParmVarDecl *> callbacks;
62};
63
64/* A data structure expressing how Method::on_arg_list should combine
65 * the arguments.
66 *
67 * In particular, "before" is called before any argument is handled;
68 * "between" is called between two arguments and
69 * "after" is called after all arguments have been handled.
70 */
72 const std::function<void()> before;
73 const std::function<void()> between;
74 const std::function<void()> after;
75};
76
77/* A method that does not require its isl type parameters to be a copy.
78 */
80 NoCopyMethod(const Method &method) : Method(method) {}
81
82 virtual bool param_needs_copy(int pos) const override;
83};
84
85/* A generated method that performs one or more argument conversions and
86 * then calls the original method.
87 *
88 * A ConversionMethod inherits from a NoCopyMethod, because
89 * unlike methods that call an isl C function,
90 * a conversion method never calls release() on an isl type argument,
91 * so they can all be passed as const references.
92 *
93 * "this_type" is the name of the type to which "this" should be converted
94 * (if different from clazz.name).
95 * "get_param_fn" returns the method argument at position "pos".
96 */
98 ConversionMethod(const Method &method, const std::string &this_type,
99 const std::function<clang::ParmVarDecl *(int pos)> &get_param);
100 ConversionMethod(const Method &method, const std::string &this_type);
101 ConversionMethod(const Method &method,
102 const std::function<clang::ParmVarDecl *(int pos)> &get_param);
103 virtual clang::ParmVarDecl *get_param(int pos) const override;
104
105 void print_call(std::ostream &os, const std::string &ns) const;
106
107 const std::string this_type;
108 const std::function<clang::ParmVarDecl *(int pos)> get_param_fn;
109};
110
111/* A specialized generated C++ method for setting an enum.
112 *
113 * "enum_name" is a string representation of the enum value
114 * set by this method.
115 */
116struct EnumMethod : public Method {
117 EnumMethod(const isl_class &clazz, FunctionDecl *fd,
118 const std::string &method_name, const std::string &enum_name);
119
120 virtual int num_params() const override;
121 virtual void print_param_use(ostream &os, int pos) const override;
122
123 std::string enum_name;
124};
125
126/* A type printer for converting argument and return types,
127 * as well as the class type,
128 * to string representations of the corresponding types
129 * in the C++ interface.
130 */
133
134 virtual std::string isl_bool() const;
135 virtual std::string isl_stat() const;
136 virtual std::string isl_size() const;
137 virtual std::string isl_namespace() const;
138 virtual std::string class_type(const std::string &cpp_name) const;
139 virtual std::string qualified(int arg, const std::string &cpp_type)
140 const;
141 std::string isl_type(int arg, QualType type) const;
142 std::string generate_callback_args(int arg, QualType type, bool cpp)
143 const;
144 std::string generate_callback_type(int arg, QualType type) const;
145 std::string param(int arg, QualType type) const;
146 std::string return_type(const Method &method) const;
147};
148
149/* Generator for C++ bindings.
150 */
151class cpp_generator : public generator {
152protected:
153 struct class_printer;
154public:
155 cpp_generator(SourceManager &SM, set<RecordDecl *> &exported_types,
156 set<FunctionDecl *> exported_functions,
157 set<FunctionDecl *> functions);
158private:
161 void copy_methods(isl_class &clazz, const std::string &name,
162 const isl_class &super, const function_set &methods);
163 void copy_super_methods(isl_class &clazz, const isl_class &super);
164 void copy_super_methods(isl_class &clazz, set<string> &done);
165 void copy_super_methods();
166 bool is_implicit_conversion(const Method &cons);
167 bool is_subclass(QualType subclass_type, const isl_class &class_type);
168public:
169 static string type2cpp(const isl_class &clazz);
170 static string type2cpp(string type_string);
171};
172
173/* A helper class for printing method declarations and definitions
174 * of a class.
175 *
176 * "os" is the stream onto which the methods are printed.
177 * "clazz" describes the methods of the class.
178 * "cppstring" is the C++ name of the class.
179 * "generator" is the C++ interface generator printing the classes.
180 * "declarations" is set if this object is used to print declarations.
181 */
183 std::ostream &os;
185 const std::string cppstring;
187 const bool declarations;
188
189 class_printer(std::ostream &os, const isl_class &clazz,
191
192 void print_constructors();
193 void print_methods();
194 bool next_variant(FunctionDecl *fd, std::vector<bool> &convert);
195 void print_method_variants(FunctionDecl *fd, const std::string &name);
196 virtual bool want_descendent_overloads(const function_set &methods) = 0;
197 void print_descendent_overloads(FunctionDecl *fd,
198 const std::string &name);
199 void print_method_group(const function_set &methods,
200 const std::string &name);
201 virtual void print_method(const Method &method) = 0;
202 virtual void print_method(const ConversionMethod &method) = 0;
203 virtual void print_get_method(FunctionDecl *fd) = 0;
204 void print_set_enums(FunctionDecl *fd);
205 void print_set_enums();
206 ParmVarDecl *get_param(FunctionDecl *fd, int pos,
207 const std::vector<bool> &convert);
208 void print_method_header(const Method &method,
209 const cpp_type_printer &type_printer);
210};
211
212#endif
static string type2cpp(const isl_class &clazz)
Definition: cpp.cc:766
bool is_implicit_conversion(const Method &cons)
Definition: cpp.cc:915
void copy_methods(isl_class &clazz, const std::string &name, const isl_class &super, const function_set &methods)
Definition: cpp.cc:181
void set_construction_types()
Definition: cpp.cc:68
void set_class_construction_types(isl_class &clazz)
Definition: cpp.cc:48
bool is_subclass(QualType subclass_type, const isl_class &class_type)
Definition: cpp.cc:879
void copy_super_methods()
Definition: cpp.cc:250
SourceManager & SM
Definition: generator.h:146
std::set< FunctionDecl *, function_name_less > function_set
Definition: generator.h:45
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
Definition: isl_map.c:70
enum isl_fold type
Definition: isl_test.c:4017
const char * name
Definition: isl_test.c:10938
const char * arg
Definition: isl_test.c:774
void print_call(std::ostream &os, const std::string &ns) const
Definition: cpp.cc:1256
const std::function< clang::ParmVarDecl *(int pos)> get_param_fn
Definition: cpp.h:108
virtual clang::ParmVarDecl * get_param(int pos) const override
Definition: cpp.cc:1244
const std::string this_type
Definition: cpp.h:107
virtual void print_param_use(ostream &os, int pos) const override
Definition: cpp.cc:1283
virtual int num_params() const override
Definition: cpp.cc:1297
std::string enum_name
Definition: cpp.h:123
const std::function< void()> before
Definition: cpp.h:72
const std::function< void()> between
Definition: cpp.h:73
const std::function< void()> after
Definition: cpp.h:74
Definition: cpp.h:19
void on_fd_arg_list(int start, int end, const list_combiner &combiner, const std::function< void(int i, int arg)> &on_arg) const
Definition: cpp.cc:1080
void print_fd_arg_list(std::ostream &os, int start, int end, const std::function< void(int i, int arg)> &print_arg) const
Definition: cpp.cc:1105
FunctionDecl *const fd
Definition: cpp.h:58
static list_combiner print_combiner(std::ostream &os)
Definition: cpp.cc:933
virtual int num_params() const
Definition: cpp.cc:1021
static void on_arg_list(int start, int end, const list_combiner &combiner, const std::function< bool(int i)> &on_arg_skip_next)
Definition: cpp.cc:1031
int c_num_params() const
Definition: cpp.cc:1010
static void print_arg_list(std::ostream &os, int start, int end, const std::function< bool(int i)> &print_arg_skip_next)
Definition: cpp.cc:1050
virtual void print_param_use(ostream &os, int pos) const
Definition: cpp.cc:504
bool is_subclass_mutator() const
Definition: cpp.cc:543
const std::vector< ParmVarDecl * > callbacks
Definition: cpp.h:61
virtual clang::ParmVarDecl * get_param(int pos) const
Definition: cpp.cc:1176
void print_cpp_arg_list(std::ostream &os, const std::function< void(int i, int arg)> &print_arg) const
Definition: cpp.cc:1144
@ static_method
Definition: cpp.h:21
@ constructor
Definition: cpp.h:23
@ member_method
Definition: cpp.h:22
enum Kind kind
Definition: cpp.h:60
const isl_class & clazz
Definition: cpp.h:57
virtual bool param_needs_copy(int pos) const
Definition: cpp.cc:1162
static list_combiner empty_combiner()
Definition: cpp.cc:944
const std::string name
Definition: cpp.h:59
void on_cpp_arg_list(const list_combiner &combiner, const std::function< void(int i, int arg)> &on_arg) const
Definition: cpp.cc:1118
NoCopyMethod(const Method &method)
Definition: cpp.h:80
virtual bool param_needs_copy(int pos) const override
Definition: cpp.cc:1229
void print_descendent_overloads(FunctionDecl *fd, const std::string &name)
Definition: cpp.cc:441
void print_method_group(const function_set &methods, const std::string &name)
Definition: cpp.cc:466
virtual void print_method(const Method &method)=0
virtual bool want_descendent_overloads(const function_set &methods)=0
bool next_variant(FunctionDecl *fd, std::vector< bool > &convert)
Definition: cpp.cc:331
virtual void print_get_method(FunctionDecl *fd)=0
virtual void print_method(const ConversionMethod &method)=0
cpp_generator & generator
Definition: cpp.h:186
ParmVarDecl * get_param(FunctionDecl *fd, int pos, const std::vector< bool > &convert)
Definition: cpp.cc:567
std::ostream & os
Definition: cpp.h:183
const std::string cppstring
Definition: cpp.h:185
const bool declarations
Definition: cpp.h:187
void print_method_header(const Method &method, const cpp_type_printer &type_printer)
Definition: cpp.cc:620
void print_method_variants(FunctionDecl *fd, const std::string &name)
Definition: cpp.cc:375
const isl_class & clazz
Definition: cpp.h:184
std::string generate_callback_type(int arg, QualType type) const
Definition: cpp.cc:725
virtual std::string isl_stat() const
Definition: cpp.cc:793
virtual std::string isl_bool() const
Definition: cpp.cc:783
std::string param(int arg, QualType type) const
Definition: cpp.cc:851
std::string return_type(const Method &method) const
Definition: cpp.cc:554
std::string generate_callback_args(int arg, QualType type, bool cpp) const
Definition: cpp.cc:684
virtual std::string qualified(int arg, const std::string &cpp_type) const
Definition: cpp.cc:831
cpp_type_printer()
Definition: cpp.h:132
virtual std::string class_type(const std::string &cpp_name) const
Definition: cpp.cc:821
virtual std::string isl_namespace() const
Definition: cpp.cc:812
std::string isl_type(int arg, QualType type) const
Definition: cpp.cc:840
virtual std::string isl_size() const
Definition: cpp.cc:803