3 static FrontendPluginRegistry::Add<PrintFunctionNamesAction>
4 X(
"v8toolkit-generate-bindings",
"generate v8toolkit bindings");
14 void write_classes(
int file_count, vector<WrappedClass*> & classes,
bool last_one) {
16 cerr << fmt::format(
"writing classes, file_count: {}, classes.size: {}, last_one: {}", file_count, classes.size(), last_one) << endl;
18 string class_wrapper_filename = fmt::format(
"v8toolkit_generated_class_wrapper_{}.cpp", file_count);
19 ofstream class_wrapper_file;
21 class_wrapper_file.open(class_wrapper_filename, ios::out);
22 if (!class_wrapper_file) {
23 if (
print_logging) cerr <<
"Couldn't open " << class_wrapper_filename << endl;
24 throw std::exception();
29 set<string> already_included_this_file;
36 class_wrapper_file << fmt::format(
"#include {}\n", include);
37 already_included_this_file.insert(include);
41 std::set<WrappedClass *> extern_templates;
42 set<string> includes_for_this_file;
47 wrapped_class->parse_all_methods();
49 for (
auto derived_type : wrapped_class->derived_types) {
50 extern_templates.insert(derived_type);
53 for (
auto used_class : wrapped_class->used_classes) {
54 if (used_class->should_be_wrapped()) {
55 extern_templates.insert(used_class);
60 if (
print_logging) cerr <<
"Dumping " << wrapped_class->class_name <<
" to file " << class_wrapper_filename << endl;
69 auto base_type_includes = wrapped_class->get_base_type_includes();
70 includes_for_this_file.insert(base_type_includes.begin(), base_type_includes.end());
72 auto derived_type_includes = wrapped_class->get_derived_type_includes();
73 includes_for_this_file.insert(derived_type_includes.begin(), derived_type_includes.end());
79 for(
auto & include_file : includes_for_this_file) {
80 if (include_file !=
"") {
82 if (include_file.find(
"__") == 1) {
86 class_wrapper_file << fmt::format(
"#include {}\n", include_file);
93 for (
auto & wrapped_class : classes) {
99 class_wrapper_file << fmt::format(
"template class v8toolkit::V8ClassWrapper<{}>;\n", wrapped_class->class_name);
102 if (!wrapped_class->wrapper_extension_methods.empty()) {
103 class_wrapper_file << fmt::format(
"template class v8toolkit::V8ClassWrapper<{} const>;\n", wrapped_class->class_name);
108 extern_templates.erase(wrapped_class);
113 for (
auto extern_template : extern_templates) {
115 if (extern_template->is_template_specialization()) {
117 class_wrapper_file <<
"extern template " << extern_template->class_name <<
";\n";
120 class_wrapper_file << fmt::format(
"extern template class v8toolkit::V8ClassWrapper<{}>;\n", extern_template->class_name);
127 class_wrapper_file << fmt::format(
"void v8toolkit_initialize_class_wrappers_{}(v8toolkit::Isolate &); // may not exist -- that's ok\n", file_count+1);
130 if (file_count == 1) {
131 class_wrapper_file << fmt::format(
"void v8toolkit_initialize_class_wrappers(v8toolkit::Isolate & isolate) {{\n");
134 class_wrapper_file << fmt::format(
"void v8toolkit_initialize_class_wrappers_{}(v8toolkit::Isolate & isolate) {{\n",
141 for (
auto wrapped_class : classes) {
144 class_wrapper_file << wrapped_class->get_bindings();
150 class_wrapper_file << fmt::format(
" v8toolkit_initialize_class_wrappers_{}(isolate);\n", file_count + 1);
154 class_wrapper_file <<
"}\n";
155 class_wrapper_file.close();
void EndSourceFileAction()
static FrontendPluginRegistry::Add< PrintFunctionNamesAction > X("v8toolkit-generate-bindings","generate v8toolkit bindings")
string header_for_every_class_wrapper_file
void write_classes(int file_count, vector< WrappedClass * > &classes, bool last_one)
vector< string > includes_for_every_class_wrapper_file
vector< string > never_include_for_any_file