summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-09-26 22:20:38 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2015-09-26 22:20:38 (GMT)
commit017eb2ef4da167466c05ad83eb0714129a2e46ff (patch)
treee64da1b284e709c5904219c28ed3be6f35d77fa8
parent53acb5a29b8eb4fe89dd2e8bc3b808d5e7183b81 (diff)
downloadnsgenbind-017eb2ef4da167466c05ad83eb0714129a2e46ff.tar.gz
nsgenbind-017eb2ef4da167466c05ad83eb0714129a2e46ff.tar.bz2
Simplify genbind AST handling of preface, prologue, epilogue and postface
-rw-r--r--src/duk-libdom-common.c32
-rw-r--r--src/duk-libdom-dictionary.c40
-rw-r--r--src/duk-libdom-interface.c40
-rw-r--r--src/duk-libdom.c32
-rw-r--r--src/duk-libdom.h14
-rw-r--r--src/nsgenbind-ast.c16
-rw-r--r--src/nsgenbind-ast.h22
-rw-r--r--src/nsgenbind-parser.y172
8 files changed, 196 insertions, 172 deletions
diff --git a/src/duk-libdom-common.c b/src/duk-libdom-common.c
index a1298e9..fc62863 100644
--- a/src/duk-libdom-common.c
+++ b/src/duk-libdom-common.c
@@ -115,3 +115,35 @@ int output_ctype(FILE *outf, struct genbind_node *node, bool identifier)
return 0;
}
+
+/* exported interface documented in duk-libdom.h */
+int output_method_cdata(FILE* outf,
+ struct genbind_node *node,
+ enum genbind_method_type sel_method_type)
+{
+ struct genbind_node *method;
+
+ method = genbind_node_find_type(genbind_node_getnode(node),
+ NULL,
+ GENBIND_NODE_TYPE_METHOD);
+
+ while (method != NULL) {
+ enum genbind_method_type *method_type;
+
+ method_type = (enum genbind_method_type *)genbind_node_getint(
+ genbind_node_find_type(
+ genbind_node_getnode(method),
+ NULL,
+ GENBIND_NODE_TYPE_METHOD_TYPE));
+ if ((method_type != NULL) &&
+ (*method_type == sel_method_type)) {
+ output_cdata(outf, method, GENBIND_NODE_TYPE_CDATA);
+ }
+
+ method = genbind_node_find_type(genbind_node_getnode(node),
+ method,
+ GENBIND_NODE_TYPE_METHOD);
+ }
+
+ return 0;
+}
diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c
index 69ce8aa..65a140a 100644
--- a/src/duk-libdom-dictionary.c
+++ b/src/duk-libdom-dictionary.c
@@ -323,23 +323,27 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
output_tool_preface(ifacef);
/* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PREFACE);
/* class preface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(ifacef,
+ dictionarye->class,
+ GENBIND_METHOD_TYPE_PREFACE);
/* tool prologue */
output_tool_prologue(ifacef);
/* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PROLOGUE);
/* class prologue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
+ output_method_cdata(ifacef,
+ dictionarye->class,
+ GENBIND_METHOD_TYPE_PROLOGUE);
fprintf(ifacef, "\n");
@@ -352,20 +356,24 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
fprintf(ifacef, "\n");
/* class epilogue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
+ output_method_cdata(ifacef,
+ dictionarye->class,
+ GENBIND_METHOD_TYPE_EPILOGUE);
/* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_EPILOGUE);
/* class postface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(ifacef,
+ dictionarye->class,
+ GENBIND_METHOD_TYPE_POSTFACE);
/* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_POSTFACE);
op_error:
genb_fclose_tmp(ifacef, dictionarye->filename);
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c
index 38e1277..997cb9a 100644
--- a/src/duk-libdom-interface.c
+++ b/src/duk-libdom-interface.c
@@ -1296,23 +1296,27 @@ int output_interface(struct ir *ir, struct ir_entry *interfacee)
output_tool_preface(ifacef);
/* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PREFACE);
/* class preface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(ifacef,
+ interfacee->class,
+ GENBIND_METHOD_TYPE_PREFACE);
/* tool prologue */
output_tool_prologue(ifacef);
/* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PROLOGUE);
/* class prologue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PROLOGUE);
+ output_method_cdata(ifacef,
+ interfacee->class,
+ GENBIND_METHOD_TYPE_PROLOGUE);
fprintf(ifacef, "\n");
@@ -1343,20 +1347,24 @@ int output_interface(struct ir *ir, struct ir_entry *interfacee)
fprintf(ifacef, "\n");
/* class epilogue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_EPILOGUE);
+ output_method_cdata(ifacef,
+ interfacee->class,
+ GENBIND_METHOD_TYPE_EPILOGUE);
/* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_EPILOGUE);
/* class postface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(ifacef,
+ interfacee->class,
+ GENBIND_METHOD_TYPE_POSTFACE);
/* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_POSTFACE);
op_error:
genb_fclose_tmp(ifacef, interfacee->filename);
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index ee7cc3b..fcd55da 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -136,9 +136,9 @@ static FILE *open_header(struct ir *ir, const char *name)
output_tool_preface(hdrf);
/* binding preface */
- output_cdata(hdrf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(hdrf,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PREFACE);
/* header guard */
fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
@@ -161,9 +161,9 @@ static int close_header(struct ir *ir,
fprintf(hdrf, "\n#endif\n");
/* binding postface */
- output_cdata(hdrf,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(hdrf,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_POSTFACE);
genb_fclose_tmp(hdrf, fname);
free(fname);
@@ -401,17 +401,17 @@ output_binding_src(struct ir *ir)
output_tool_preface(bindf);
/* binding preface */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
+ output_method_cdata(bindf,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PREFACE);
+ /* tool prologue */
output_tool_prologue(bindf);
/* binding prologue */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
+ output_method_cdata(bindf,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_PROLOGUE);
fprintf(bindf, "\n");
@@ -582,9 +582,9 @@ output_binding_src(struct ir *ir)
fprintf(bindf, "}\n");
/* binding postface */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
+ output_method_cdata(bindf,
+ ir->binding_node,
+ GENBIND_METHOD_TYPE_POSTFACE);
genb_fclose_tmp(bindf, "binding.c");
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 3b07009..b9eeea3 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -47,7 +47,7 @@ int output_tool_prologue(FILE* outf);
/**
* output character data of node of given type.
*
- * used for any cdata including pre/pro/epi/post sections
+ * used for any cdata sections
*
* \param outf The file handle to write output.
* \param node The node to search.
@@ -57,6 +57,18 @@ int output_tool_prologue(FILE* outf);
int output_cdata(FILE* outf, struct genbind_node *node, enum genbind_node_type nodetype);
/**
+ * output character data of method node of given type.
+ *
+ * used for any cdata including pre/pro/epi/post sections
+ *
+ * \param outf The file handle to write output.
+ * \param node The node to search.
+ * \param nodetype the type of child node to search for.
+ * \return The number of nodes written or 0 for none.
+ */
+int output_method_cdata(FILE* outf, struct genbind_node *node, enum genbind_method_type sel_method_type);
+
+/**
* output a C variable type
*
* Used to output c type and optionlly identifier declarations for parameters
diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c
index 6b39461..2915010 100644
--- a/src/nsgenbind-ast.c
+++ b/src/nsgenbind-ast.c
@@ -338,10 +338,6 @@ char *genbind_node_gettext(struct genbind_node *node)
switch(node->type) {
case GENBIND_NODE_TYPE_WEBIDL:
case GENBIND_NODE_TYPE_STRING:
- case GENBIND_NODE_TYPE_PREFACE:
- case GENBIND_NODE_TYPE_PROLOGUE:
- case GENBIND_NODE_TYPE_EPILOGUE:
- case GENBIND_NODE_TYPE_POSTFACE:
case GENBIND_NODE_TYPE_IDENT:
case GENBIND_NODE_TYPE_NAME:
case GENBIND_NODE_TYPE_CDATA:
@@ -406,18 +402,6 @@ static const char *genbind_node_type_to_str(enum genbind_node_type type)
case GENBIND_NODE_TYPE_STRING:
return "String";
- case GENBIND_NODE_TYPE_PREFACE:
- return "Preface";
-
- case GENBIND_NODE_TYPE_POSTFACE:
- return "Postface";
-
- case GENBIND_NODE_TYPE_PROLOGUE:
- return "Prologue";
-
- case GENBIND_NODE_TYPE_EPILOGUE:
- return "Epilogue";
-
case GENBIND_NODE_TYPE_BINDING:
return "Binding";
diff --git a/src/nsgenbind-ast.h b/src/nsgenbind-ast.h
index 282544e..b130db2 100644
--- a/src/nsgenbind-ast.h
+++ b/src/nsgenbind-ast.h
@@ -17,12 +17,8 @@ enum genbind_node_type {
GENBIND_NODE_TYPE_CDATA, /**< verbatim block of character data */
GENBIND_NODE_TYPE_STRING, /**< text string */
- GENBIND_NODE_TYPE_BINDING,
+ GENBIND_NODE_TYPE_BINDING, /**< Binding */
GENBIND_NODE_TYPE_WEBIDL,
- GENBIND_NODE_TYPE_PREFACE,
- GENBIND_NODE_TYPE_PROLOGUE,
- GENBIND_NODE_TYPE_EPILOGUE,
- GENBIND_NODE_TYPE_POSTFACE,
GENBIND_NODE_TYPE_CLASS, /**< class definition */
GENBIND_NODE_TYPE_PRIVATE,
@@ -45,12 +41,16 @@ enum genbind_type_modifier {
/* binding method types */
enum genbind_method_type {
- GENBIND_METHOD_TYPE_INIT = 0, /**< binding method is initialiser */
- GENBIND_METHOD_TYPE_FINI, /**< binding method is finalizer */
- GENBIND_METHOD_TYPE_METHOD, /**< binding method is a method */
- GENBIND_METHOD_TYPE_GETTER, /**< binding method is a getter */
- GENBIND_METHOD_TYPE_SETTER, /**< binding method is a setter */
- GENBIND_METHOD_TYPE_PROTOTYPE, /**< binding method is a prototype */
+ GENBIND_METHOD_TYPE_INIT = 0, /**< method is initialiser */
+ GENBIND_METHOD_TYPE_FINI, /**< method is finalizer */
+ GENBIND_METHOD_TYPE_METHOD, /**< method is a method */
+ GENBIND_METHOD_TYPE_GETTER, /**< method is a getter */
+ GENBIND_METHOD_TYPE_SETTER, /**< method is a setter */
+ GENBIND_METHOD_TYPE_PROTOTYPE, /**< method is a prototype */
+ GENBIND_METHOD_TYPE_PREFACE, /**< method is a preface */
+ GENBIND_METHOD_TYPE_PROLOGUE, /**< method is a prologue */
+ GENBIND_METHOD_TYPE_EPILOGUE, /**< method is a epilogue */
+ GENBIND_METHOD_TYPE_POSTFACE, /**< method is a postface */
};
struct genbind_node;
diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y
index b883833..247a047 100644
--- a/src/nsgenbind-parser.y
+++ b/src/nsgenbind-parser.y
@@ -80,7 +80,6 @@ add_method(struct genbind_node **genbind_ast,
genbind_new_node(GENBIND_NODE_TYPE_IDENT,
method_node,
class_name));
-
} else {
/* update the existing class */
@@ -156,21 +155,14 @@ add_method(struct genbind_node **genbind_ast,
%type <node> Class
%type <node> ClassArgs
%type <node> ClassArg
-%type <node> ClassFlag
%type <node> ClassFlags
%type <node> Method
%type <node> MethodDeclarator
%type <value> MethodType
+%type <value> BindingAndMethodType
%type <node> WebIDL
-%type <node> Preface
-%type <node> Prologue
-%type <node> Epilogue
-%type <node> Postface
-%type <node> Private
-%type <node> Internal
-%type <node> Property
%type <node> ParameterList
%type <node> CTypeIdent
@@ -188,7 +180,7 @@ Input:
Statements:
Statement
- |
+ |
Statements Statement
{
$$ = *genbind_ast = genbind_node_prepend($2, $1);
@@ -225,23 +217,26 @@ BindingArgs:
|
BindingArgs BindingArg
{
- $$ = genbind_node_link($2, $1);
+ $$ = genbind_node_link($2, $1);
}
;
BindingArg:
WebIDL
|
- Preface
- |
- Prologue
- |
- Epilogue
- |
- Postface
+ BindingAndMethodType CBlock ';'
+ {
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_METHOD,
+ NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_METHOD_TYPE,
+ genbind_new_node(GENBIND_NODE_TYPE_CDATA,
+ NULL,
+ $2),
+ (void *)$1));
+ }
;
- /* a web IDL file specifier */
+/* a web IDL file specifier */
WebIDL:
TOK_WEBIDL TOK_STRING_LITERAL ';'
{
@@ -308,40 +303,42 @@ CTypeIdent:
}
;
-Preface:
- TOK_PREFACE CBlock ';'
+
+CBlock:
+ TOK_CCODE_LITERAL
+ |
+ CBlock TOK_CCODE_LITERAL
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_PREFACE, NULL, $2);
+ $$ = genbind_strapp($1, $2);
}
;
-Prologue:
- TOK_PROLOGUE CBlock ';'
+
+ParameterList:
+ CTypeIdent
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_PROLOGUE, NULL, $2);
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_PARAMETER, NULL, $1);
}
- ;
-
-Epilogue:
- TOK_EPILOGUE CBlock ';'
+ |
+ ParameterList ',' CTypeIdent
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_EPILOGUE, NULL, $2);
+ $$ = genbind_node_prepend($1,
+ genbind_new_node(
+ GENBIND_NODE_TYPE_PARAMETER,
+ NULL,
+ $3));
}
;
-Postface:
- TOK_POSTFACE CBlock ';'
+Method:
+ MethodType MethodDeclarator CBlock
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_POSTFACE, NULL, $2);
+ $$ = add_method(genbind_ast, $1, $2, $3);
}
- ;
-
-CBlock:
- TOK_CCODE_LITERAL
|
- CBlock TOK_CCODE_LITERAL
+ MethodType MethodDeclarator ';'
{
- $$ = genbind_strapp($1, $2);
+ $$ = add_method(genbind_ast, $1, $2, NULL);
}
;
@@ -375,21 +372,29 @@ MethodType:
{
$$ = GENBIND_METHOD_TYPE_PROTOTYPE;
}
+ |
+ BindingAndMethodType
;
-ParameterList:
- CTypeIdent
+BindingAndMethodType:
+ TOK_PREFACE
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_PARAMETER, NULL, $1);
+ $$ = GENBIND_METHOD_TYPE_PREFACE;
}
|
- ParameterList ',' CTypeIdent
+ TOK_PROLOGUE
{
- $$ = genbind_node_prepend($1,
- genbind_new_node(
- GENBIND_NODE_TYPE_PARAMETER,
- NULL,
- $3));
+ $$ = GENBIND_METHOD_TYPE_PROLOGUE;
+ }
+ |
+ TOK_EPILOGUE
+ {
+ $$ = GENBIND_METHOD_TYPE_EPILOGUE;
+ }
+ |
+ TOK_POSTFACE
+ {
+ $$ = GENBIND_METHOD_TYPE_POSTFACE;
}
;
@@ -434,17 +439,6 @@ MethodDeclarator:
}
;
-Method:
- MethodType MethodDeclarator CBlock
- {
- $$ = add_method(genbind_ast, $1, $2, $3);
- }
- |
- MethodType MethodDeclarator ';'
- {
- $$ = add_method(genbind_ast, $1, $2, NULL);
- }
- ;
Class:
TOK_CLASS TOK_IDENTIFIER '{' ClassArgs '}' ';'
@@ -464,43 +458,41 @@ ClassArgs:
;
ClassArg:
- Private
- |
- Internal
- |
- Property
- |
- ClassFlag
- |
- Preface
- |
- Prologue
- |
- Epilogue
- |
- Postface
- ;
-
-
-Private:
TOK_PRIVATE CTypeIdent ';'
{
$$ = genbind_new_node(GENBIND_NODE_TYPE_PRIVATE, NULL, $2);
}
- ;
-
-Internal:
+ |
TOK_INTERNAL CTypeIdent ';'
{
$$ = genbind_new_node(GENBIND_NODE_TYPE_INTERNAL, NULL, $2);
}
- ;
-
-ClassFlag:
+ |
+ TOK_PROPERTY Modifiers TOK_IDENTIFIER ';'
+ {
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_PROPERTY, NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_MODIFIER,
+ genbind_new_node(GENBIND_NODE_TYPE_IDENT,
+ NULL,
+ $3),
+ (void *)$2));
+ }
+ |
TOK_FLAGS ClassFlags ';'
{
$$ = genbind_new_node(GENBIND_NODE_TYPE_FLAGS, NULL, $2);
}
+ |
+ BindingAndMethodType CBlock ';'
+ {
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_METHOD,
+ NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_METHOD_TYPE,
+ genbind_new_node(GENBIND_NODE_TYPE_CDATA,
+ NULL,
+ $2),
+ (void *)$1));
+ }
;
ClassFlags:
@@ -515,18 +507,6 @@ ClassFlags:
}
;
-Property:
- TOK_PROPERTY Modifiers TOK_IDENTIFIER ';'
- {
- $$ = genbind_new_node(GENBIND_NODE_TYPE_PROPERTY, NULL,
- genbind_new_node(GENBIND_NODE_TYPE_MODIFIER,
- genbind_new_node(GENBIND_NODE_TYPE_IDENT,
- NULL,
- $3),
- (void *)$2));
- }
- ;
-
Modifiers:
/* empty */
{