From aab61ebdb4494309e688ea8afbd97c5a2f89e935 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 3 Jun 2013 15:15:05 +0100 Subject: add switch and implementation to enable debug trace logging in generated code --- src/jsapi-libdom-operator.c | 59 +++++++++++++++++++++-------- src/jsapi-libdom-property.c | 33 ++++++++++++---- src/jsapi-libdom.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ src/nsgenbind.c | 8 +++- src/options.h | 1 + 5 files changed, 166 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c index f30bdb3..1d16afe 100644 --- a/src/jsapi-libdom-operator.c +++ b/src/jsapi-libdom-operator.c @@ -702,14 +702,52 @@ output_operator_placeholder(struct binding *binding, binding->interface, webidl_node_gettext(ident_node)); - fprintf(binding->outfile, - "\tJSLOG(\"operation %s.%s has no implementation\");\n", - binding->interface, - webidl_node_gettext(ident_node)); + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"operation %s.%s has no implementation\");\n", + binding->interface, + webidl_node_gettext(ident_node)); + } return 0; } + +/* generate context data fetcher if the binding has private data */ +static inline int +output_private_get(struct binding *binding, const char *argname) +{ + int ret = 0; + + if (binding->has_private) { + + ret = fprintf(binding->outfile, + "\tstruct jsclass_private *%s;\n" + "\n" + "\t%s = JS_GetInstancePrivate(cx,\n" + "\t\t\tJSAPI_THIS_OBJECT(cx,vp),\n" + "\t\t\t&JSClass_%s,\n" + "\t\t\targv);\n" + "\tif (%s == NULL) {\n" + "\t\treturn JS_FALSE;\n" + "\t}\n\n", + argname, argname, binding->interface, argname); + + if (options->dbglog) { + ret += fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, JSAPI_THIS_OBJECT(cx,vp), %s);\n", argname); + } + } else { + if (options->dbglog) { + ret += fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, JSAPI_THIS_OBJECT(cx,vp));\n"); + } + + } + + return ret; +} + static int webidl_operator_body_cb(struct webidl_node *node, void *ctx) { struct binding *binding = ctx; @@ -743,18 +781,7 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx) output_variable_definitions(binding, webidl_node_getnode(node)); - if (binding->has_private) { - fprintf(binding->outfile, - "\tstruct jsclass_private *private;\n" - "\n" - "\tprivate = JS_GetInstancePrivate(cx,\n" - "\t\t\tJSAPI_THIS_OBJECT(cx,vp),\n" - "\t\t\t&JSClass_%s,\n" - "\t\t\targv);\n" - "\tif (private == NULL)\n" - "\t\treturn JS_FALSE;\n\n", - binding->interface); - } + output_private_get(binding, "private"); output_operation_input(binding, webidl_node_getnode(node)); diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c index 0f82c3f..2bd3068 100644 --- a/src/jsapi-libdom-property.c +++ b/src/jsapi-libdom-property.c @@ -26,11 +26,11 @@ static int generate_property_body(struct binding *binding, const char *interface static inline int output_private_get(struct binding *binding, const char *argname) { - if (!binding->has_private) { - return 0; - } + int ret = 0; - return fprintf(binding->outfile, + if (binding->has_private) { + + ret = fprintf(binding->outfile, "\tstruct jsclass_private *%s;\n" "\n" "\t%s = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n" @@ -38,6 +38,20 @@ output_private_get(struct binding *binding, const char *argname) "\t\treturn JS_FALSE;\n" "\t}\n\n", argname, argname, binding->interface, argname); + + if (options->dbglog) { + ret += fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, %s);\n", argname); + } + } else { + if (options->dbglog) { + ret += fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + + } + + return ret; } /* generate vars for property name getter */ @@ -756,10 +770,13 @@ output_property_placeholder(struct binding *binding, binding->interface, ident); - fprintf(binding->outfile, - "\tJSLOG(\"property %s.%s has no implementation\");\n", - binding->interface, - ident); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"property %s.%s has no implementation\");\n", + binding->interface, + ident); + } return 0; } diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index fef1656..7104a83 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -238,6 +238,11 @@ output_api_operations(struct binding *binding) "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + if (binding->finalise != NULL) { output_code_block(binding, genbind_node_getnode(binding->finalise)); @@ -254,6 +259,11 @@ output_api_operations(struct binding *binding) "static void jsclass_finalize(JSContext *cx, JSObject *obj)\n" "{\n"); + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + output_code_block(binding, genbind_node_getnode(binding->finalise)); @@ -275,8 +285,20 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } + output_code_block(binding, genbind_node_getnode(binding->addproperty)); @@ -298,8 +320,20 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } + output_code_block(binding, genbind_node_getnode(binding->delproperty)); @@ -321,8 +355,20 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } + output_code_block(binding, genbind_node_getnode(binding->getproperty)); @@ -344,8 +390,20 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } + output_code_block(binding, genbind_node_getnode(binding->setproperty)); @@ -367,6 +425,17 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } output_code_block(binding, genbind_node_getnode(binding->enumerate)); @@ -389,8 +458,19 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(cx, obj, &JSClass_%s, NULL);\n", binding->interface); + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", cx, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", cx, obj);\n"); + } + } + output_code_block(binding, genbind_node_getnode(binding->resolve)); fprintf(binding->outfile, @@ -410,6 +490,17 @@ output_api_operations(struct binding *binding) "\n" "\tprivate = JS_GetInstancePrivate(JSAPI_MARKCX, obj, &JSClass_%s, NULL);\n", binding->interface); + + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p private:%%p\", JSAPI_MARKCX, obj, private);\n"); + } + } else { + if (options->dbglog) { + fprintf(binding->outfile, + "\tJSLOG(\"jscontext:%%p jsobject:%%p\", JSAPI_MARKCX, obj);\n"); + } + } output_code_block(binding, genbind_node_getnode(binding->mark)); diff --git a/src/nsgenbind.c b/src/nsgenbind.c index 1c5100e..d993646 100644 --- a/src/nsgenbind.c +++ b/src/nsgenbind.c @@ -30,7 +30,7 @@ static struct options* process_cmdline(int argc, char **argv) return NULL; } - while ((opt = getopt(argc, argv, "vDW::d:I:o:h:")) != -1) { + while ((opt = getopt(argc, argv, "vgDW::d:I:o:h:")) != -1) { switch (opt) { case 'I': options->idlpath = strdup(optarg); @@ -56,13 +56,17 @@ static struct options* process_cmdline(int argc, char **argv) options->debug = true; break; + case 'g': + options->dbglog = true; + break; + case 'W': options->warnings = 1; /* warning flags */ break; default: /* '?' */ fprintf(stderr, - "Usage: %s [-v] [-D] [-W] [-d depfilename] [-I idlpath] [-o filename] [-h headerfile] inputfile\n", + "Usage: %s [-v] [-g] [-D] [-W] [-d depfilename] [-I idlpath] [-o filename] [-h headerfile] inputfile\n", argv[0]); free(options); return NULL; diff --git a/src/options.h b/src/options.h index ca71078..13c02be 100644 --- a/src/options.h +++ b/src/options.h @@ -22,6 +22,7 @@ struct options { bool verbose; /**< verbose processing */ bool debug; /**< debug enabled */ + bool dbglog; /**< embed debug logging in output */ unsigned int warnings; /**< warning flags */ }; -- cgit v1.2.3