3 std::stringstream result;
4 auto matches = wrapped_class.annotations.get_regex(
"v8toolkit_generate_(.*)");
6 result << fmt::format(
"class JS{} : public {}, public v8toolkit::JSWrapper<{}> {{\npublic:\n",
7 short_name(), short_name(), short_name());
8 result << fmt::format(
" JS{}(v8::Local<v8::Context> context, v8::Local<v8::Object> object,\n", short_name());
9 result << fmt::format(
" v8::Local<v8::FunctionTemplate> created_by");
10 bool got_constructor =
false;
11 int constructor_parameter_count;
12 vector<QualType> constructor_parameters;
14 if (got_constructor) {
15 data_error(fmt::format(
"ERROR: Got more than one constructor for {}", wrapped_class.class_name));
18 got_constructor =
true;
20 constructor_parameter_count = constructor_decl->getNumParams();
24 if (!got_constructor) {
25 data_error(fmt::format(
"ERROR: Got no bidirectional constructor for {}", wrapped_class.class_name));
28 result << fmt::format(
") :\n");
33 result << fmt::format(
" {}({}),\n", short_name(),
join(variable_names));
34 result << fmt::format(
" v8toolkit::JSWrapper<{}>(context, object, created_by) {{}}\n", short_name());
35 result << handle_class(wrapped_class.decl);
44 ofstream bidirectional_class_file;
45 auto bidirectional_class_filename = fmt::format(
"v8toolkit_generated_bidirectional_{}.h", short_name());
46 bidirectional_class_file.open(bidirectional_class_filename, ios::out);
47 if (!bidirectional_class_file) {
48 llvm::report_fatal_error(fmt::format(
"Could not open file: {}", bidirectional_class_filename),
false);
51 bidirectional_class_file <<
"#pragma once\n\n";
57 for (
auto & include : this->wrapped_class.include_files) {
58 if (include ==
""){
continue;}
59 bidirectional_class_file <<
"#include " << include <<
"\n";
65 auto all_base_type_includes = this->wrapped_class.get_base_type_includes();
67 for (
auto & include : all_base_type_includes) {
68 std::cerr << fmt::format(
"for bidirectional {}, adding base type include {}", this->short_name(), include) << std::endl;
69 bidirectional_class_file <<
"#include " << include <<
"\n";
72 bidirectional_class_file << result.str();
73 bidirectional_class_file.close();
void data_error(const string &error)
vector< QualType > get_method_param_qual_types(CompilerInstance &compiler_instance, const CXXMethodDecl *method, string const &annotation)
#define V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR_STRING
#define V8TOOLKIT_BIDIRECTIONAL_CLASS_STRING
vector< string > generate_variable_names(vector< QualType > qual_types, bool with_std_move)
std::string join(const T &source, const std::string &between=", ", bool leading_between=false)
std::string get_method_parameters(CompilerInstance &compiler_instance, WrappedClass &wrapped_class, const CXXMethodDecl *method, bool add_leading_comma=false, bool insert_variable_names=false, const string &annotation="")
void foreach_constructor(const CXXRecordDecl *klass, Callback &&callback, const std::string &annotation="")