Method::print_fd_arg_list: skip user pointer arguments
[isl.git] / interface / cpp.h
blobb28d4f3c29d249f3e71f405a6caa864dea1b4bbc
1 #ifndef ISL_INTERFACE_CPP_H
2 #define ISL_INTERFACE_CPP_H
4 #include <iostream>
5 #include <string>
6 #include <vector>
8 #include "generator.h"
10 /* A generated C++ method derived from an isl function.
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 * "callback" stores the callback argument, if any, or NULL.
19 struct Method {
20 enum Kind {
21 static_method,
22 member_method,
23 constructor,
26 Method(const isl_class &clazz, FunctionDecl *fd,
27 const std::string &name);
28 Method(const isl_class &clazz, FunctionDecl *fd);
30 int c_num_params() const;
31 virtual int num_params() const;
32 virtual bool param_needs_copy(int pos) const;
33 virtual clang::ParmVarDecl *get_param(int pos) const;
34 virtual void print_param_use(ostream &os, int pos) const;
35 bool is_subclass_mutator() const;
36 static void print_arg_list(std::ostream &os, int start, int end,
37 const std::function<bool(int i)> &print_arg_skip_next);
38 void print_fd_arg_list(std::ostream &os, int start, int end,
39 const std::function<void(int i)> &print_arg) const;
40 void print_cpp_arg_list(std::ostream &os,
41 const std::function<void(int i)> &print_arg) const;
43 const isl_class &clazz;
44 FunctionDecl *const fd;
45 const std::string name;
46 const enum Kind kind;
47 ParmVarDecl *const callback;
50 /* A method that does not require its isl type parameters to be a copy.
52 struct NoCopyMethod : Method {
53 NoCopyMethod(const Method &method) : Method(method) {}
55 virtual bool param_needs_copy(int pos) const override;
58 /* A generated method that performs one or more argument conversions and
59 * then calls the original method.
61 * A ConversionMethod inherits from a NoCopyMethod, because
62 * unlike methods that call an isl C function,
63 * a conversion method never calls release() on an isl type argument,
64 * so they can all be passed as const references.
66 * "this_type" is the name of the type to which "this" should be converted
67 * (if different from clazz.name).
68 * "get_param_fn" returns the method argument at position "pos".
70 struct ConversionMethod : NoCopyMethod {
71 ConversionMethod(const Method &method, const std::string &this_type,
72 const std::function<clang::ParmVarDecl *(int pos)> &get_param);
73 ConversionMethod(const Method &method, const std::string &this_type);
74 ConversionMethod(const Method &method,
75 const std::function<clang::ParmVarDecl *(int pos)> &get_param);
76 virtual clang::ParmVarDecl *get_param(int pos) const override;
78 void print_call(std::ostream &os, const std::string &ns) const;
80 const std::string this_type;
81 const std::function<clang::ParmVarDecl *(int pos)> get_param_fn;
84 /* A specialized generated C++ method for setting an enum.
86 * "enum_name" is a string representation of the enum value
87 * set by this method.
89 struct EnumMethod : public Method {
90 EnumMethod(const isl_class &clazz, FunctionDecl *fd,
91 const std::string &method_name, const std::string &enum_name);
93 virtual int num_params() const override;
94 virtual void print_param_use(ostream &os, int pos) const override;
96 std::string enum_name;
99 /* A type printer for converting argument and return types,
100 * as well as the class type,
101 * to string representations of the corresponding types
102 * in the C++ interface.
104 struct cpp_type_printer {
105 cpp_type_printer() {}
107 virtual std::string isl_bool() const;
108 virtual std::string isl_stat() const;
109 virtual std::string isl_size() const;
110 virtual std::string isl_namespace() const;
111 virtual std::string class_type(const std::string &cpp_name) const;
112 virtual std::string qualified(int arg, const std::string &cpp_type)
113 const;
114 std::string isl_type(int arg, QualType type) const;
115 std::string generate_callback_args(int arg, QualType type, bool cpp)
116 const;
117 std::string generate_callback_type(int arg, QualType type) const;
118 std::string param(int arg, QualType type) const;
119 std::string return_type(const Method &method) const;
122 /* Generator for C++ bindings.
124 class cpp_generator : public generator {
125 protected:
126 struct class_printer;
127 public:
128 cpp_generator(SourceManager &SM, set<RecordDecl *> &exported_types,
129 set<FunctionDecl *> exported_functions,
130 set<FunctionDecl *> functions);
131 private:
132 void set_class_construction_types(isl_class &clazz);
133 void set_construction_types();
134 void copy_methods(isl_class &clazz, const std::string &name,
135 const isl_class &super, const function_set &methods);
136 void copy_super_methods(isl_class &clazz, const isl_class &super);
137 void copy_super_methods(isl_class &clazz, set<string> &done);
138 void copy_super_methods();
139 bool is_implicit_conversion(const Method &cons);
140 bool is_subclass(QualType subclass_type, const isl_class &class_type);
141 public:
142 static string type2cpp(const isl_class &clazz);
143 static string type2cpp(string type_string);
146 /* A helper class for printing method declarations and definitions
147 * of a class.
149 * "os" is the stream onto which the methods are printed.
150 * "clazz" describes the methods of the class.
151 * "cppstring" is the C++ name of the class.
152 * "generator" is the C++ interface generator printing the classes.
153 * "declarations" is set if this object is used to print declarations.
155 struct cpp_generator::class_printer {
156 std::ostream &os;
157 const isl_class &clazz;
158 const std::string cppstring;
159 cpp_generator &generator;
160 const bool declarations;
162 class_printer(std::ostream &os, const isl_class &clazz,
163 cpp_generator &generator, bool declarations);
165 void print_constructors();
166 void print_methods();
167 bool next_variant(FunctionDecl *fd, std::vector<bool> &convert);
168 void print_method_variants(FunctionDecl *fd, const std::string &name);
169 virtual bool want_descendent_overloads(const function_set &methods) = 0;
170 void print_descendent_overloads(FunctionDecl *fd,
171 const std::string &name);
172 void print_method_group(const function_set &methods,
173 const std::string &name);
174 virtual void print_method(const Method &method) = 0;
175 virtual void print_method(const ConversionMethod &method) = 0;
176 virtual void print_get_method(FunctionDecl *fd) = 0;
177 void print_set_enums(FunctionDecl *fd);
178 void print_set_enums();
179 ParmVarDecl *get_param(FunctionDecl *fd, int pos,
180 const std::vector<bool> &convert);
181 void print_method_header(const Method &method,
182 const cpp_type_printer &type_printer);
185 #endif