summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2013-06-03 15:15:05 +0100
committerVincent Sanders <vincent.sanders@collabora.co.uk>2013-06-03 15:15:05 +0100
commitaab61ebdb4494309e688ea8afbd97c5a2f89e935 (patch)
tree716a29b96f3408ba2c7cf71534b97430c10b8ef4
parent85287e9287e29fd715470253b1075e726a2ec594 (diff)
downloadnsgenbind-aab61ebdb4494309e688ea8afbd97c5a2f89e935.tar.gz
nsgenbind-aab61ebdb4494309e688ea8afbd97c5a2f89e935.tar.bz2
add switch and implementation to enable debug trace logging in generated code
-rw-r--r--src/jsapi-libdom-operator.c59
-rw-r--r--src/jsapi-libdom-property.c33
-rw-r--r--src/jsapi-libdom.c91
-rw-r--r--src/nsgenbind.c8
-rw-r--r--src/options.h1
5 files changed, 166 insertions, 26 deletions
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 */
};