29#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
36get_member_default_str(
struct ir_entry *dictionarye,
51 if (lit_node == NULL) {
63 "Dictionary %s:%s literal boolean type mismatch\n",
70 *defl_out = strdup(
"false");
72 *defl_out = strdup(
"true");
77 *defl_out = strdup(
"NULL");
87 snprintf(*defl_out, 128,
"%d", *lit_int);
93 snprintf(*defl_out, 128,
"%f", *lit_flt);
109output_member_acessor(
struct opctx *outc,
123 if (type_node == NULL) {
124 fprintf(stderr,
"%s:%s has no type\n",
136 if (argument_type == NULL) {
138 "%s:%s has no type base\n",
145 res = get_member_default_str(dictionarye, membere, *argument_type, &defl);
150 switch (*argument_type) {
155 "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
161 "\tconst char *ret = NULL; /* No default */\n");
164 "\tconst char *ret = \"%s\"; /* Default value of %s */\n",
165 defl, membere->
name);
169 "\t/* ... obj@idx ... */\n"
170 "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
171 "\t/* ... obj@idx ... value/undefined */\n"
172 "\tif (!duk_is_undefined(ctx, -1)) {\n"
173 "\t\t/* Note, this throws a duk_error if it's not a string */\n"
174 "\t\tret = duk_require_string(ctx, -1);\n"
186 "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
192 "\tduk_bool_t ret = false; /* No default */\n");
195 "\tduk_bool_t ret = %s; /* Default value of %s */\n",
196 defl, membere->
name);
200 "\t/* ... obj@idx ... */\n"
201 "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
202 "\t/* ... obj@idx ... value/undefined */\n"
203 "\tif (!duk_is_undefined(ctx, -1)) {\n"
204 "\t\t/* Note, this throws a duk_error if it's not a boolean */\n"
205 "\t\tret = duk_require_boolean(ctx, -1);\n"
219 "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
225 "\tduk_int_t ret = 0; /* No default */\n");
228 "\tduk_int_t ret = %s; /* Default value of %s */\n",
229 defl, membere->
name);
233 "\t/* ... obj@idx ... */\n"
234 "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
235 "\t/* ... obj@idx ... value/undefined */\n"
236 "\tif (!duk_is_undefined(ctx, -1)) {\n"
237 "\t\t/* Note, this throws a duk_error if it's not a int */\n"
238 "\t\tret = duk_require_int(ctx, -1);\n"
250 "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n",
255 "\tduk_double_t ret = %s; /* Default value of %s */\n"
256 "\t/* ... obj@idx ... */\n"
257 "\tduk_get_prop_string(ctx, idx, \"%s\");\n",
258 defl, membere->
name, membere->
name);
261 "\t/* ... obj@idx ... value/undefined */\n"
262 "\tif (!duk_is_undefined(ctx, -1)) {\n"
263 "\t\t/* Note, this throws a duk_error if it's not a number */\n"
264 "\t\tret = duk_require_number(ctx, -1);\n"
273 "Dictionary %s:%s unhandled type (%d)",
278 "/* Dictionary %s:%s unhandled type (%d) */\n\n",
292output_member_acessors(
struct opctx *outc,
struct ir_entry *dictionarye)
300 res = output_member_acessor(
353 res = output_member_acessors(dyop, dictionarye);
390output_member_declaration(
struct opctx *outc,
402 if (type_node == NULL) {
403 fprintf(stderr,
"%s:%s has no type\n",
415 if (argument_type == NULL) {
417 "%s:%s has no type base\n",
424 switch (*argument_type) {
428 "const char *%s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
434 "duk_bool_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
442 "duk_int_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
449 "duk_double_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
455 "/* Dictionary %s:%s unhandled type (%d) */\n",
474 res = output_member_declaration(
int output_method_cdata(struct opctx *outc, struct genbind_node *node, enum genbind_method_type sel_method_type)
int output_tool_prologue(struct opctx *outc)
int output_tool_preface(struct opctx *outc)
int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
int output_dictionary_declaration(struct opctx *outc, struct ir_entry *dictionarye)
@ GENBIND_METHOD_TYPE_PREFACE
@ GENBIND_METHOD_TYPE_PROLOGUE
@ GENBIND_METHOD_TYPE_POSTFACE
@ GENBIND_METHOD_TYPE_EPILOGUE
#define WARN(flags, msg, args...)
int outputf(struct opctx *opctx, const char *fmt,...)
int output_close(struct opctx *opctx)
int output_open(const char *filename, struct opctx **opctx_out)
struct ir_operation_argument_entry * memberv
struct ir_dictionary_entry dictionary
struct genbind_node * class
struct webidl_node * node
struct genbind_node * binding_node
struct webidl_node * webidl_node_getnode(struct webidl_node *node)
char * webidl_node_gettext(struct webidl_node *node)
int * webidl_node_getint(struct webidl_node *node)
float * webidl_node_getfloat(struct webidl_node *node)
enum webidl_node_type webidl_node_gettype(struct webidl_node *node)
struct webidl_node * webidl_node_find_type(struct webidl_node *node, struct webidl_node *prev, enum webidl_node_type type)
@ WEBIDL_NODE_TYPE_LITERAL_STRING
@ WEBIDL_NODE_TYPE_TYPE_BASE
@ WEBIDL_NODE_TYPE_LITERAL_NULL
@ WEBIDL_NODE_TYPE_OPTIONAL
@ WEBIDL_NODE_TYPE_LITERAL_BOOL
@ WEBIDL_NODE_TYPE_LITERAL_INT
@ WEBIDL_NODE_TYPE_LITERAL_FLOAT