1 #ifndef ISL_INTERFACE_TEMPLATE_CPP_H
2 #define ISL_INTERFACE_TEMPLATE_CPP_H
4 #include <initializer_list>
10 #include <unordered_map>
18 /* A shared pointer to a TupleKind.
20 struct TupleKindPtr
: public std::shared_ptr
<const TupleKind
> {
21 using Base
= std::shared_ptr
<const TupleKind
>;
22 TupleKindPtr() = default;
24 TupleKindPtr(Base base
) : Base(base
) {}
25 TupleKindPtr(const std::string
&name
);
26 TupleKindPtr(const TupleKindPtr
&left
, const TupleKindPtr
&right
);
29 /* A substitution mapping leaf tuple kind names to tuple kinds.
31 using Substitution
= std::unordered_map
<std::string
, TupleKindPtr
>;
33 /* A representation of a (possibly improper) tuple kind.
34 * That is, this also includes tuple kinds for types
35 * that do not have any tuples.
37 * The kind could be a name (the base case) or
38 * a (currently) unnamed nested pair of tuple kinds.
41 TupleKind(const std::string
&name
) : name(name
) {}
43 virtual std::string
to_string() const;
44 virtual std::vector
<std::string
> params() const;
45 virtual TupleKindPtr
apply(const Substitution
&subs
,
46 const TupleKindPtr
&self
) const;
47 virtual TupleKindPtr
left() const;
48 virtual TupleKindPtr
right() const;
50 const std::string name
;
53 /* A sequence of tuple kinds, representing a kind of objects.
55 struct Kind
: public std::vector
<TupleKindPtr
> {
57 Kind(std::initializer_list
<TupleKindPtr
> list
) : vector(list
) {}
61 bool is_anon_set() const;
62 std::vector
<std::string
> params() const;
63 Kind
apply(const Substitution
&subs
) const;
66 /* A representation of a template class.
68 * "class_name" is the name of the template class.
69 * "super_name" is the (fully qualified) name of the corresponding
70 * plain C++ interface class, from which this template class derives.
71 * "clazz" describes the plain class.
73 * "class_tuples" contains the specializations.
74 * It is initialized with a predefined set of specializations,
75 * but may be extended during the generations of the specializations.
77 struct template_class
{
78 const std::string class_name
;
79 const std::string super_name
;
80 const isl_class
&clazz
;
82 std::vector
<Kind
> class_tuples
;
85 bool is_anon_set() const;
86 void add_specialization(const Kind
&kind
);
89 /* A generator for templated C++ bindings.
91 * "template_classes" contains all generated template classes,
92 * keyed on their names.
94 class template_cpp_generator
: public cpp_generator
{
96 struct method_decl_printer
;
97 struct method_impl_printer
;
98 struct class_decl_printer
;
99 struct class_impl_printer
;
101 void add_template_class(const isl_class
&clazz
, const std::string
&name
,
102 const std::vector
<Kind
> &class_tuples
);
104 template_cpp_generator(clang::SourceManager
&SM
,
105 std::set
<clang::RecordDecl
*> &exported_types
,
106 std::set
<clang::FunctionDecl
*> exported_functions
,
107 std::set
<clang::FunctionDecl
*> functions
);
109 virtual void generate() override
;
110 void foreach_template_class(
111 const std::function
<void(const template_class
&)> &fn
) const;
112 void print_forward_declarations(std::ostream
&os
);
113 void print_friends(std::ostream
&os
);
115 std::map
<std::string
, template_class
> template_classes
;