39#include "isl_config.h"
58 param = cons->getParamDecl(0);
59 type = param->getOriginalType();
71 auto &clazz = kvp.second;
87 set<RecordDecl *> &exported_types,
88 set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions) :
89 generator(SM, exported_types, exported_functions, functions)
102 const std::string &
name, FunctionDecl *fd,
int depth)
115 int n1 = fd1->getNumParams();
116 int n2 = fd2->getNumParams();
121 for (
int i = 1; i < n1; ++i) {
122 ParmVarDecl *p1 = fd1->getParamDecl(i);
123 ParmVarDecl *p2 = fd2->getParamDecl(i);
125 if (p1->getOriginalType() != p2->getOriginalType())
160 const std::string &
name,
int depth)
184 for (
auto fd : methods) {
203 for (
const auto &kvp : super.
methods) {
204 const auto &
name = kvp.first;
205 const auto &methods = kvp.second;
225 for (
const auto &super : supers)
226 if (done.count(super) == 0)
228 done.insert(clazz.
name);
230 for (
const auto &super_name : supers) {
231 const auto &super =
classes[super_name];
233 if (super.construction_types.count(clazz.
name) == 0)
255 auto &clazz = kvp.second;
257 if (clazz.is_type_subclass())
259 if (done.count(clazz.name) != 0)
287 for (
const auto &kvp : clazz.methods)
288 print_method_group(kvp.second, kvp.first);
299 for (
const auto &
set : clazz.set_enums.at(fd)) {
302 print_method(method);
311 for (
const auto &kvp : clazz.set_enums)
312 print_set_enums(kvp.first);
332 std::vector<bool> &convert)
334 size_t n = convert.size();
336 for (
int i =
n - 1; i >= 1; --i) {
337 ParmVarDecl *param = fd->getParamDecl(i);
338 const Type *
type = param->getOriginalType().getTypePtr();
345 for (
size_t j = i + 1; j <
n; ++j)
376 const std::string &
name)
379 std::vector<bool> convert(method.
num_params());
382 print_method(method);
383 if (clazz.is_get_method(fd))
384 print_get_method(fd);
391 while (next_variant(fd, convert)) {
393 return get_param(fd,
pos, convert);
407 if (fd->getNumParams() != 2)
410 param = fd->getParamDecl(1);
424 for (
const auto &
fn : methods) {
431 return count == 1 ? local : NULL;
442 FunctionDecl *fd,
const std::string &
name)
445 ParmVarDecl *param = fd->getParamDecl(1);
446 QualType
type = param->getOriginalType();
447 std::string
arg =
type->getPointeeType().getAsString();
450 const auto sub = kvp.second;
471 for (
const auto &fd : methods)
472 print_method_variants(fd,
name);
473 if (!want_descendent_overloads(methods))
480 print_descendent_overloads(local,
name);
506 ParmVarDecl *param = fd->getParamDecl(
pos);
507 bool load_from_this_ptr =
pos == 0 && kind == member_method;
508 string name = param->getName().str();
509 QualType
type = param->getOriginalType();
511 if (
type->isIntegerType()) {
517 os <<
name <<
".c_str()";
522 os <<
name <<
"_lambda, ";
523 os <<
"&" <<
name <<
"_data";
527 if (!load_from_this_ptr)
533 if (load_from_this_ptr)
559 return param(-1, method.
fd->getReturnType());
568 int pos,
const std::vector<bool> &convert)
570 ParmVarDecl *param = fd->getParamDecl(
pos);
623 string rettype_str = type_printer.
return_type(method);
634 if (
generator.is_implicit_conversion(method))
635 os <<
"/* implicit */ ";
642 os << rettype_str <<
" ";
645 os << type_printer.
class_type(cppstring) <<
"::";
653 std::string
name = method.
fd->getParamDecl(i)->getName().
str();
654 ParmVarDecl *param = method.
get_param(i);
655 QualType
type = param->getOriginalType();
659 os <<
"const " << cpptype <<
" &" <<
name;
661 os << cpptype <<
" " <<
name;
687 std::string type_str;
688 const FunctionProtoType *callback;
692 num_params = callback->getNumArgs();
696 for (
long i = 0; i < num_params; i++) {
697 QualType
type = callback->getArgType(i);
700 type_str += param(
arg + 1 + i,
type);
702 type_str +=
type.getAsString();
707 if (i != num_params - 1)
728 std::string type_str;
730 QualType return_type = callback->getReturnType();
731 string rettype_str = param(
arg, return_type);
733 type_str =
"std::function<";
734 type_str += rettype_str;
736 type_str += generate_callback_args(
arg,
type,
true);
747 {
"union",
"unite" },
775 return type_str.substr(4);
834 return isl_namespace() + cpp_type;
842 auto name =
type->getPointeeType().getAsString();
865 if (
type->isIntegerType())
866 return type.getAsString();
869 return "std::string";
872 return generate_callback_type(
arg,
type);
882 std::string type_str = subclass_type->getPointeeType().getAsString();
883 std::vector<std::string> superclasses;
884 std::vector<const isl_class *> parents;
885 std::vector<std::string>::iterator ci;
889 for (ci = superclasses.begin(); ci < superclasses.end(); ci++)
890 parents.push_back(&
classes[*ci]);
892 while (!parents.empty()) {
893 const isl_class *candidate = parents.back();
897 if (&class_type == candidate)
902 for (ci = superclasses.begin(); ci < superclasses.end(); ci++)
903 parents.push_back(&
classes[*ci]);
917 const auto &clazz = cons.
clazz;
918 ParmVarDecl *param = cons.
fd->getParamDecl(0);
919 QualType
type = param->getOriginalType();
921 int num_params = cons.
fd->getNumParams();
936 [&] () { os <<
"("; },
937 [&] () { os <<
", "; },
938 [&] () { os <<
")"; }
946 return { [&] () { }, [&] () { }, [&] () { } };
967 std::vector<ParmVarDecl *> callbacks;
968 int num_params = fd->getNumParams();
970 for (
int i = 0; i < num_params; ++i) {
971 ParmVarDecl *param = fd->getParamDecl(i);
973 callbacks.emplace_back(param);
986 const std::string &
name) :
1000 Method(clazz, fd, clazz.method_name(fd))
1012 return fd->getNumParams();
1033 const std::function<
bool(
int i)> &on_arg_skip_next)
1036 for (
int i = start; i < end; ++i) {
1039 if (on_arg_skip_next(i))
1051 const std::function<
bool(
int i)> &print_arg_skip_next)
1054 return print_arg_skip_next(i);
1082 const std::function<
void(
int i,
int arg)> &on_arg)
const
1086 on_arg_list(start, end, combiner, [
this, &on_arg, &
arg] (
int i) {
1087 auto type =
fd->getParamDecl(i)->getType();
1106 const std::function<
void(
int i,
int arg)> &print_arg)
const
1119 const std::function<
void(
int i,
int arg)> &on_arg)
const
1132 const std::function<
void(
int i,
int arg)> &on_arg)
const
1145 const std::function<
void(
int i,
int arg)> &print_arg)
const
1165 QualType
type = param->getOriginalType();
1178 return fd->getParamDecl(
pos);
1187 const std::string &this_type,
1188 const std::function<clang::ParmVarDecl *(
int pos)> &get_param) :
1190 get_param_fn(get_param)
1203 const std::string &this_type) :
1218 const std::function<clang::ParmVarDecl *(
int pos)> &get_param) :
1232 QualType
type = param->getOriginalType();
1262 os << cpp_type <<
"(*this).";
1272 const std::string &method_name,
const std::string &enum_name) :
1273 Method(clazz, fd, method_name), enum_name(enum_name)
1307 bool declarations) :
1309 declarations(declarations)
cpp_generator(SourceManager &SM, set< RecordDecl * > &exported_types, set< FunctionDecl * > exported_functions, set< FunctionDecl * > functions)
static string type2cpp(const isl_class &clazz)
bool is_implicit_conversion(const Method &cons)
void copy_methods(isl_class &clazz, const std::string &name, const isl_class &super, const function_set &methods)
void set_construction_types()
void set_class_construction_types(isl_class &clazz)
bool is_subclass(QualType subclass_type, const isl_class &class_type)
void copy_super_methods()
static bool keeps(Decl *decl)
static string extract_type(QualType type)
static void die(const char *msg) __attribute__((noreturn))
std::map< const Type *, ParmVarDecl * > conversions
static bool is_callback(QualType type)
static bool is_isl_type(QualType type)
static int prototype_n_args(QualType type)
static bool is_isl_size(QualType type)
isl_class * method2class(FunctionDecl *fd)
static bool is_isl_ctx(QualType type)
static bool is_mutator(const isl_class &clazz, FunctionDecl *fd)
static bool is_string(QualType type)
static bool is_static(const isl_class &clazz, FunctionDecl *method)
static bool is_isl_bool(QualType type)
static bool is_isl_stat(QualType type)
map< string, isl_class > classes
static bool is_constructor(Decl *decl)
static const FunctionProtoType * extract_prototype(QualType type)
static vector< string > find_superclasses(Decl *decl)
static int copy_depth(const isl_class &clazz, FunctionDecl *fd)
static bool has_single_isl_argument(FunctionDecl *fd)
static Method::Kind get_kind(const isl_class &clazz, FunctionDecl *method)
static const char * rename_map[][2]
static std::vector< ParmVarDecl * > find_callback_args(FunctionDecl *fd)
static bool same_signature(FunctionDecl *fd1, FunctionDecl *fd2)
static void copy_method(isl_class &clazz, const isl_class &super, const std::string &name, FunctionDecl *fd, int depth)
static FunctionDecl * single_local(const isl_class &clazz, const function_set &methods)
static bool is_overridden(FunctionDecl *fd, isl_class &clazz, const std::string &name, int depth)
static std::string rename_method(std::string name)
std::set< FunctionDecl *, function_name_less > function_set
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
void GMPZAPI() sub(mp_int rop, mp_int op1, mp_int op2)
static int count(int *con, unsigned len, int status)
static unsigned pos(__isl_keep isl_space *space, enum isl_dim_type type)
static std::string to_string(long l)
void print_call(std::ostream &os, const std::string &ns) const
const std::function< clang::ParmVarDecl *(int pos)> get_param_fn
virtual clang::ParmVarDecl * get_param(int pos) const override
ConversionMethod(const Method &method, const std::string &this_type, const std::function< clang::ParmVarDecl *(int pos)> &get_param)
const std::string this_type
EnumMethod(const isl_class &clazz, FunctionDecl *fd, const std::string &method_name, const std::string &enum_name)
virtual void print_param_use(ostream &os, int pos) const override
virtual int num_params() const override
const std::function< void()> before
const std::function< void()> between
const std::function< void()> after
Method(const isl_class &clazz, FunctionDecl *fd, const std::string &name)
void on_fd_arg_list(int start, int end, const list_combiner &combiner, const std::function< void(int i, int arg)> &on_arg) const
void print_fd_arg_list(std::ostream &os, int start, int end, const std::function< void(int i, int arg)> &print_arg) const
static list_combiner print_combiner(std::ostream &os)
virtual int num_params() const
static void on_arg_list(int start, int end, const list_combiner &combiner, const std::function< bool(int i)> &on_arg_skip_next)
static void print_arg_list(std::ostream &os, int start, int end, const std::function< bool(int i)> &print_arg_skip_next)
virtual void print_param_use(ostream &os, int pos) const
bool is_subclass_mutator() const
virtual clang::ParmVarDecl * get_param(int pos) const
void print_cpp_arg_list(std::ostream &os, const std::function< void(int i, int arg)> &print_arg) const
virtual bool param_needs_copy(int pos) const
static list_combiner empty_combiner()
void on_cpp_arg_list(const list_combiner &combiner, const std::function< void(int i, int arg)> &on_arg) const
virtual bool param_needs_copy(int pos) const override
void print_descendent_overloads(FunctionDecl *fd, const std::string &name)
void print_method_group(const function_set &methods, const std::string &name)
virtual void print_method(const Method &method)=0
bool next_variant(FunctionDecl *fd, std::vector< bool > &convert)
void print_constructors()
ParmVarDecl * get_param(FunctionDecl *fd, int pos, const std::vector< bool > &convert)
void print_method_header(const Method &method, const cpp_type_printer &type_printer)
class_printer(std::ostream &os, const isl_class &clazz, cpp_generator &generator, bool declarations)
void print_method_variants(FunctionDecl *fd, const std::string &name)
std::string generate_callback_type(int arg, QualType type) const
virtual std::string isl_stat() const
virtual std::string isl_bool() const
std::string param(int arg, QualType type) const
std::string return_type(const Method &method) const
std::string generate_callback_args(int arg, QualType type, bool cpp) const
virtual std::string qualified(int arg, const std::string &cpp_type) const
virtual std::string class_type(const std::string &cpp_name) const
virtual std::string isl_namespace() const
std::string isl_type(int arg, QualType type) const
virtual std::string isl_size() const
bool first_arg_matches_class(FunctionDecl *method) const
map< string, function_set > methods
std::map< clang::FunctionDecl *, int > copy_depth
std::map< clang::FunctionDecl *, const isl_class & > copied_from
std::map< std::string, clang::ParmVarDecl * > construction_types
function_set constructors