summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-10-08 15:04:56 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2015-10-08 15:04:56 (GMT)
commite170ee146791061f4fcc9523a901cdc1c6c8525b (patch)
tree658a5b13168d59d68e8493f180d23cb898cb5d90
parentc2c05535f6a758d58fd3d7e995ef320778a9eb01 (diff)
downloadnsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.gz
nsgenbind-e170ee146791061f4fcc9523a901cdc1c6c8525b.tar.bz2
Split out idl to c name conversion
-rw-r--r--src/duk-libdom-common.c53
-rw-r--r--src/duk-libdom.c65
-rw-r--r--src/duk-libdom.h15
3 files changed, 69 insertions, 64 deletions
diff --git a/src/duk-libdom-common.c b/src/duk-libdom-common.c
index fb97fe3..ce3ebe9 100644
--- a/src/duk-libdom-common.c
+++ b/src/duk-libdom-common.c
@@ -170,3 +170,56 @@ int output_method_cdata(FILE* outf,
return 0;
}
+
+/* exported interface documented in duk-libdom.h */
+char *gen_idl2c_name(const char *idlname)
+{
+ const char *inc;
+ char *outc;
+ char *name;
+ int wasupper;
+
+ /* enpty strings are a bad idea */
+ if ((idlname == NULL) || (idlname[0] == 0)) {
+ return NULL;
+ }
+
+ /* allocate result buffer as twice the input length as thats the
+ * absolute worst case.
+ */
+ name = calloc(2, strlen(idlname));
+
+ outc = name;
+ inc = idlname;
+ wasupper = 0;
+
+ /* first character handled separately as inserting a leading underscore
+ * is undesirable
+ */
+ *outc++ = tolower(*inc++);
+
+ /* copy input to output */
+ while (*inc != 0) {
+ /* ugly hack as html IDL is always prefixed uppercase and needs
+ * an underscore there
+ */
+ if ((inc == (idlname + 4)) &&
+ (idlname[0] == 'H') &&
+ (idlname[1] == 'T') &&
+ (idlname[2] == 'M') &&
+ (idlname[3] == 'L') &&
+ (islower(inc[1]) == 0)) {
+ *outc++ = '_';
+ }
+ if ((islower(*inc) != 0) && (wasupper != 0)) {
+ *outc = *(outc - 1);
+ *(outc - 1) = '_';
+ outc++;
+ wasupper = 0;
+ } else {
+ wasupper = isupper(*inc);
+ }
+ *outc++ = tolower(*inc++);
+ }
+ return name;
+}
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index fcd55da..a0e8eb5 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -49,70 +49,7 @@ static char *get_prototype_name(const char *interface_name)
}
-/**
- * Generate a C class name for the interface.
- *
- * The IDL interface names are camelcase and not similar to libdom naming so it
- * is necessary to convert them to a libdom compatible class name. This
- * implementation is simple ASCII capable only and cannot cope with multibyte
- * codepoints.
- *
- * The algorithm is:
- * - copy characters to output lowering their case
- * - if the previous character in the input name was uppercase and the current
- * one is lowercase insert an underscore before the *previous* character.
- */
-static char *gen_class_name(struct ir_entry *interfacee)
-{
- const char *inc;
- char *outc;
- char *name;
- int wasupper;
-
- /* enpty strings are a bad idea */
- if ((interfacee->name == NULL) ||
- (interfacee->name[0] == 0)) {
- return NULL;
- }
- /* allocate result buffer as twice the input length as thats the
- * absolute worst case.
- */
- name = calloc(2, strlen(interfacee->name));
-
- outc = name;
- inc = interfacee->name;
- wasupper = 0;
-
- /* first character handled separately as inserting a leading underscore
- * is undesirable
- */
- *outc++ = tolower(*inc++);
- /* copy input to output */
- while (*inc != 0) {
- /* ugly hack as html IDL is always prefixed uppercase and needs
- * an underscore there
- */
- if ((inc == (interfacee->name + 4)) &&
- (interfacee->name[0] == 'H') &&
- (interfacee->name[1] == 'T') &&
- (interfacee->name[2] == 'M') &&
- (interfacee->name[3] == 'L') &&
- (islower(inc[1]) == 0)) {
- *outc++ = '_';
- }
- if ((islower(*inc) != 0) && (wasupper != 0)) {
- *outc = *(outc - 1);
- *(outc - 1) = '_';
- outc++;
- wasupper = 0;
- } else {
- wasupper = isupper(*inc);
- }
- *outc++ = tolower(*inc++);
- }
- return name;
-}
static FILE *open_header(struct ir *ir, const char *name)
@@ -641,7 +578,7 @@ int duk_libdom_output(struct ir *ir)
irentry = ir->entries + idx;
/* compute class name */
- irentry->class_name = gen_class_name(irentry);
+ irentry->class_name = gen_idl2c_name(irentry->name);
if (irentry->class_name != NULL) {
int ifacenamelen;
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index dd27420..73b7233 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -96,4 +96,19 @@ int output_method_cdata(FILE* outf, struct genbind_node *node, enum genbind_meth
*/
int output_ctype(FILE *outf, struct genbind_node *node, bool identifier);
+/**
+ * Generate a C name from an IDL name.
+ *
+ * The IDL interface names are camelcase and not similar to libdom naming so it
+ * is necessary to convert them to a libdom compatible class name. This
+ * implementation is simple ASCII capable only and cannot cope with multibyte
+ * codepoints.
+ *
+ * The algorithm is:
+ * - copy characters to output lowering their case
+ * - if the previous character in the input name was uppercase and the current
+ * one is lowercase insert an underscore before the *previous* character.
+ */
+char *gen_idl2c_name(const char *idlname);
+
#endif