Polly 20.0.0git
template_cpp.h
Go to the documentation of this file.
1#ifndef ISL_INTERFACE_TEMPLATE_CPP_H
2#define ISL_INTERFACE_TEMPLATE_CPP_H
3
4#include <initializer_list>
5#include <iostream>
6#include <map>
7#include <memory>
8#include <set>
9#include <string>
10#include <unordered_map>
11
12#include "cpp.h"
13
14struct Fixed;
15
16struct TupleKind;
17
18/* A shared pointer to a TupleKind.
19 */
20struct 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);
27};
28
29/* A substitution mapping leaf tuple kind names to tuple kinds.
30 */
31using Substitution = std::unordered_map<std::string, TupleKindPtr>;
32
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.
36 *
37 * The kind could be a name (the base case) or
38 * a (currently) unnamed nested pair of tuple kinds.
39 */
40struct TupleKind {
41 TupleKind(const std::string &name) : name(name) {}
42
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;
49
50 const std::string name;
51};
52
53/* A sequence of tuple kinds, representing a kind of objects.
54 */
55struct Kind : public std::vector<TupleKindPtr> {
56 Kind() {}
57 Kind(std::initializer_list<TupleKindPtr> list) : vector(list) {}
58
59 bool is_anon() const;
60 bool is_set() const;
61 bool is_anon_set() const;
62 std::vector<std::string> params() const;
63 Kind apply(const Substitution &subs) const;
64};
65
66/* A representation of a template class.
67 *
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.
72 *
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.
76 */
78 const std::string class_name;
79 const std::string super_name;
81
82 std::vector<Kind> class_tuples;
83
84 bool is_anon() const;
85 bool is_anon_set() const;
86 void add_specialization(const Kind &kind);
87};
88
89/* A generator for templated C++ bindings.
90 *
91 * "template_classes" contains all generated template classes,
92 * keyed on their names.
93 */
95 struct class_printer;
98 struct class_decl_printer;
99 struct class_impl_printer;
100
101 void add_template_class(const isl_class &clazz, const std::string &name,
102 const std::vector<Kind> &class_tuples);
103public:
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);
108
109 virtual void generate() override;
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);
114
115 std::map<std::string, template_class> template_classes;
116};
117
118#endif
SourceManager & SM
Definition: generator.h:146
std::map< std::string, template_class > template_classes
Definition: template_cpp.h:115
virtual void generate() override
void foreach_template_class(const std::function< void(const template_class &)> &fn) const
void add_template_class(const isl_class &clazz, const std::string &name, const std::vector< Kind > &class_tuples)
void print_friends(std::ostream &os)
void print_forward_declarations(std::ostream &os)
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition: hmap.h:37
const char * name
Definition: isl_test.c:10938
bool is_set() const
std::vector< std::string > params() const
Kind(std::initializer_list< TupleKindPtr > list)
Definition: template_cpp.h:57
Kind apply(const Substitution &subs) const
bool is_anon() const
Kind()
Definition: template_cpp.h:56
bool is_anon_set() const
std::shared_ptr< const TupleKind > Base
Definition: template_cpp.h:21
TupleKindPtr(Base base)
Definition: template_cpp.h:24
TupleKindPtr()=default
virtual std::vector< std::string > params() const
Definition: template_cpp.cc:60
virtual std::string to_string() const
Definition: template_cpp.cc:51
const std::string name
Definition: template_cpp.h:50
virtual TupleKindPtr right() const
virtual TupleKindPtr apply(const Substitution &subs, const TupleKindPtr &self) const
Definition: template_cpp.cc:72
TupleKind(const std::string &name)
Definition: template_cpp.h:41
virtual TupleKindPtr left() const
Definition: template_cpp.cc:91
const isl_class & clazz
Definition: template_cpp.h:80
bool is_anon() const
void add_specialization(const Kind &kind)
bool is_anon_set() const
std::vector< Kind > class_tuples
Definition: template_cpp.h:82
const std::string class_name
Definition: template_cpp.h:78
const std::string super_name
Definition: template_cpp.h:79
std::unordered_map< std::string, TupleKindPtr > Substitution
Definition: template_cpp.h:31