diff options
-rw-r--r-- | Makefile | 22 | ||||
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/genbind-parser.y | 58 | ||||
-rw-r--r-- | src/genjsbind-lexer.l (renamed from src/genbind-lexer.l) | 7 | ||||
-rw-r--r-- | src/genjsbind-parser.y | 60 | ||||
-rw-r--r-- | src/genjsbind.c | 173 | ||||
-rw-r--r-- | src/genjsbind.h | 1 | ||||
-rw-r--r-- | src/webidl-ast.h | 6 | ||||
-rw-r--r-- | src/webidl-lexer.l | 1 | ||||
-rw-r--r-- | src/webidl-parser.y | 10 | ||||
-rw-r--r-- | test/Makefile | 7 | ||||
-rw-r--r-- | test/data/bindings/htmldocument.bnd | 4 | ||||
-rw-r--r-- | test/data/idl/document.idl (renamed from test/document.idl) | 0 | ||||
-rw-r--r-- | test/data/idl/eventtarget.idl (renamed from test/eventtarget.idl) | 0 | ||||
-rw-r--r-- | test/data/idl/htmldocument.idl (renamed from test/htmldocument.idl) | 0 | ||||
-rw-r--r-- | test/data/idl/window.idl (renamed from test/window.idl) | 0 | ||||
-rw-r--r-- | test/htmldocument.bnd | 3 | ||||
-rwxr-xr-x | test/testrunner.sh | 43 |
19 files changed, 312 insertions, 97 deletions
@@ -10,9 +10,29 @@ PREFIX ?= /opt/netsurf NSSHARED ?= $(PREFIX)/share/netsurf-buildsystem include $(NSSHARED)/makefiles/Makefile.tools +TESTRUNNER := test/testrunner.sh + +# Toolchain flags +WARNFLAGS := -Wall -W -Wundef -Wpointer-arith -Wcast-align \ + -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes \ + -Wmissing-declarations -Wnested-externs -pedantic +# BeOS/Haiku/AmigaOS have standard library errors that issue warnings. +ifneq ($(TARGET),beos) + ifneq ($(TARGET),amiga) +# WARNFLAGS := $(WARNFLAGS) -Werror + endif +endif +CFLAGS := -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -I$(CURDIR)/include/ \ + -I$(CURDIR)/src $(WARNFLAGS) $(CFLAGS) +ifneq ($(GCCVER),2) + CFLAGS := $(CFLAGS) -std=c99 +else + # __inline__ is a GCCism + CFLAGS := $(CFLAGS) -Dinline="__inline__" +endif + # Grab the core makefile include $(NSBUILD)/Makefile.top # Add extra install rules for our pkg-config control file and the library itself -#INSTALL_ITEMS := $(INSTALL_ITEMS) /lib/pkgconfig:lib$(COMPONENT).pc.in INSTALL_ITEMS := $(INSTALL_ITEMS) /bin:$(BUILDDIR)/$(COMPONENT)$(EXEEXT) @@ -0,0 +1,10 @@ +genjsbind +========= + +This is a tool to generate javascript to dom bindings from w3c webidl +files and a binding configuration file. + +building +-------- + +The tool requires bison and flex as pre-requisites
\ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 232a7dd..6740140 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ CFLAGS := $(CFLAGS) -I$(BUILDDIR) -Isrc/ # Sources in this directory DIR_SOURCES := genjsbind.c -SOURCES := $(SOURCES) $(BUILDDIR)/genbind-parser.c $(BUILDDIR)/genbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c +SOURCES := $(SOURCES) $(BUILDDIR)/genjsbind-parser.c $(BUILDDIR)/genjsbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c $(BUILDDIR)/%-lexer.c $(BUILDDIR)/%-lexer.h: src/%-lexer.l $(VQ)$(ECHO) " FLEX: $<" @@ -31,7 +31,7 @@ endif $(BUILDDIR)/%-parser.c $(BUILDDIR)/%-parser.h: src/%-parser.y $(VQ)$(ECHO) " BISON: $<" - $(Q)bison -d -t $(BISON_DEFINES) --output=$(BUILDDIR)/$(*F)-parser.c --defines=$(BUILDDIR)/$(*F)-parser.h $< + $(Q)bison -d -t $(BISON_DEFINES) --report=all --output=$(BUILDDIR)/$(*F)-parser.c --defines=$(BUILDDIR)/$(*F)-parser.h $< # Grab the core makefile include $(NSBUILD)/Makefile.subdir diff --git a/src/genbind-parser.y b/src/genbind-parser.y deleted file mode 100644 index cad20b4..0000000 --- a/src/genbind-parser.y +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This is a bison parser for genbind - * - */ - -%{ - -#include <stdio.h> -#include <string.h> - -#include "genbind-parser.h" -#include "genbind-lexer.h" - - extern int loadwebidl(char *filename); - -void genbind_error(const char *str) -{ - fprintf(stderr,"error: %s\n",str); -} - - -int genbind_wrap() -{ - return 1; -} - - - -%} - -%define api.pure - -%union -{ - char* text; -} - -%token TOK_IDLFILE - -%token <text> TOK_STRING_LITERAL - -%% - - /* [1] start with instructions */ -Instructions: - /* empty */ - | - IdlFile - ; - -IdlFile: - TOK_IDLFILE TOK_STRING_LITERAL - { - loadwebidl($2); - } - ; - -%% diff --git a/src/genbind-lexer.l b/src/genjsbind-lexer.l index 6150f09..e976a8f 100644 --- a/src/genbind-lexer.l +++ b/src/genjsbind-lexer.l @@ -7,8 +7,7 @@ %option bison-bridge %option nodefault %option warn -%option debug -%option prefix="genbind_" +%option prefix="genjsbind_" %option nounput /* header block */ @@ -18,7 +17,7 @@ #include <stdio.h> #include <string.h> -#include "genbind-parser.h" +#include "genjsbind-parser.h" %} @@ -50,4 +49,4 @@ webidlfile return TOK_IDLFILE; . /* nothing */ -%%
\ No newline at end of file +%% diff --git a/src/genjsbind-parser.y b/src/genjsbind-parser.y new file mode 100644 index 0000000..08b8926 --- /dev/null +++ b/src/genjsbind-parser.y @@ -0,0 +1,60 @@ +/* + * This is a bison parser for genbind + * + */ + +%{ + +#include <stdio.h> +#include <string.h> + +#include "genjsbind-parser.h" +#include "genjsbind-lexer.h" +#include "genjsbind.h" + +static void genjsbind_error(const char *str) +{ + fprintf(stderr,"error: %s\n",str); +} + + +int genjsbind_wrap() +{ + return 1; +} + + + +%} + +%define api.pure + +%union +{ + char* text; +} + +%token TOK_IDLFILE + +%token <text> TOK_STRING_LITERAL + +%% + + /* [1] start with Statements */ +Statements: + /* empty */ + | + IdlFile + ; + + /* [2] load a web IDL file */ +IdlFile: + TOK_IDLFILE TOK_STRING_LITERAL ';' + { + if (loadwebidl($2) != 0) { + YYABORT; + } + } + ; + +%% diff --git a/src/genjsbind.c b/src/genjsbind.c index 150c780..145c16e 100644 --- a/src/genjsbind.c +++ b/src/genjsbind.c @@ -1,52 +1,177 @@ #include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> +#include <unistd.h> +#include <getopt.h> +#include <errno.h> #include "webidl-ast.h" - #include "webidl-parser.h" -#include "genbind-parser.h" +#include "genjsbind-parser.h" +#include "genjsbind.h" extern int webidl_debug; +extern int webidl__flex_debug; extern FILE* webidl_in; -extern int webidl_parse(); +extern int webidl_parse(void); + +extern int genjsbind_debug; +extern int genjsbind__flex_debug; +extern FILE* genjsbind_in; +extern int genjsbind_parse(void); + +struct options { + char *outfilename; + char *infilename; + char *idlpath; + bool verbose; + bool debug; +}; + +struct options *options; + +static FILE *idlopen(const char *filename) +{ + FILE *idlfile; -extern int genbind_debug; -extern FILE* genbind_in; -extern int genbind_parse(); + if (options->idlpath == NULL) { + if (options->verbose) { + printf("Opening IDL file %s\n", filename); + } + idlfile = fopen(filename, "r"); + } else { + char *fullname; + int fulllen = strlen(options->idlpath) + strlen(filename) + 2; + fullname = malloc(fulllen); + snprintf(fullname, fulllen, "%s/%s", options->idlpath, filename); + if (options->verbose) { + printf("Opening IDL file %s\n", fullname); + } + idlfile = fopen(fullname, "r"); + free(fullname); + } + return idlfile; +} int loadwebidl(char *filename) { - FILE *myfile = fopen(filename, "r"); - if (!myfile) { - perror(filename); + /* set flex to read from file */ + webidl_in = idlopen(filename); + if (!webidl_in) { + fprintf(stderr, "Error opening %s: %s\n", + filename, + strerror(errno)); return 2; } - /* set flex to read from file */ - webidl_in = myfile; - webidl_debug = 1; + if (options->debug) { + webidl_debug = 1; + webidl__flex_debug = 1; + } - /* parse through the input until there is no more: */ - while (!feof(webidl_in)) { - webidl_parse(); + /* parse the file */ + return webidl_parse(); +} + + +static struct options* process_cmdline(int argc, char **argv) +{ + int opt; + + options = calloc(1,sizeof(struct options)); + if (options == NULL) { + fprintf(stderr, "Allocation error\n"); + return NULL; } - return 0; + + while ((opt = getopt(argc, argv, "vdI:o:")) != -1) { + switch (opt) { + case 'I': + options->idlpath = strdup(optarg); + break; + + case 'o': + options->outfilename = strdup(optarg); + break; + + case 'v': + options->verbose = true; + break; + + case 'd': + options->debug = true; + break; + + default: /* '?' */ + fprintf(stderr, + "Usage: %s [-I idlpath] [-o filename] inputfile\n", + argv[0]); + free(options); + return NULL; + + } + } + + if (optind >= argc) { + fprintf(stderr, "Error: expected input filename\n"); + free(options); + return NULL; + } + + options->infilename = strdup(argv[optind]); + + return options; + } int main(int argc, char **argv) { - FILE *myfile = fopen("htmldocument.bnd", "r"); - if (!myfile) { - perror(NULL); + FILE *infile; + int parse_res; + + options = process_cmdline(argc, argv); + if (options == NULL) { + return 1; /* bad commandline */ + } + + if (options->verbose && (options->outfilename == NULL)) { + fprintf(stderr, "Error: outputting to stdout with verbose logging would fail\n"); return 2; } + + if ((options->infilename[0] == '-') && + (options->infilename[1] == 0)) { + if (options->verbose) { + printf("Using stdin for input\n"); + } + infile = stdin; + } else { + if (options->verbose) { + printf("Opening binding file %s\n", options->infilename); + } + infile = fopen(options->infilename, "r"); + } + + if (!infile) { + fprintf(stderr, "Error opening %s: %s\n", + options->infilename, + strerror(errno)); + return 3; + } + /* set flex to read from file */ - genbind_in = myfile; + genjsbind_in = infile; - genbind_debug = 1; + if (options->debug) { + genjsbind_debug = 1; + genjsbind__flex_debug = 1; + } - /* parse through the input until there is no more: */ - while (!feof(genbind_in)) { - genbind_parse(); + parse_res = genjsbind_parse(); + if (parse_res) { + fprintf(stderr, "parse result was %d\n", parse_res); + return parse_res; } return 0; } diff --git a/src/genjsbind.h b/src/genjsbind.h new file mode 100644 index 0000000..69d2f59 --- /dev/null +++ b/src/genjsbind.h @@ -0,0 +1 @@ +extern int loadwebidl(char *filename); diff --git a/src/webidl-ast.h b/src/webidl-ast.h index 96d7c2a..f56c5d9 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -1,2 +1,4 @@ - struct ifmembers_s { - }; + +struct ifmembers_s { + char *name; +}; diff --git a/src/webidl-lexer.l b/src/webidl-lexer.l index 1d2db67..20ee4c5 100644 --- a/src/webidl-lexer.l +++ b/src/webidl-lexer.l @@ -16,7 +16,6 @@ %option bison-locations %option nodefault %option warn -%option debug %option prefix="webidl_" %option nounput diff --git a/src/webidl-parser.y b/src/webidl-parser.y index 73ed2c6..c4e25f1 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -16,9 +16,9 @@ -void webidl_error(const char *str) +static void webidl_error(const char *str) { - fprintf(stderr,"error: %s\n",str); + fprintf(stderr,"error: %s\n",str); } int webidl_wrap() @@ -33,6 +33,12 @@ int webidl_wrap() %locations %define api.pure + /* the w3c grammar results in 10 shift/reduce, 2 reduce/reduce conflicts + * The reduce/reduce error are both the result of empty sequences + */ + /* %expect 10 */ + /* %expect-rr 2 */ + %union { int attr; diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..0e5236e --- /dev/null +++ b/test/Makefile @@ -0,0 +1,7 @@ + +TEST_TARGETS := $(TEST_TARGETS) test_bindings + +test_bindings: + $(Q)$(SHAREDLDPATH) $(TESTRUNNER) $(BUILDDIR) $(CURDIR)/test + +include $(NSBUILD)/Makefile.subdir diff --git a/test/data/bindings/htmldocument.bnd b/test/data/bindings/htmldocument.bnd new file mode 100644 index 0000000..4f3095f --- /dev/null +++ b/test/data/bindings/htmldocument.bnd @@ -0,0 +1,4 @@ +/* test binding docuemnt */ + +webidlfile "htmldocument.idl"; + diff --git a/test/document.idl b/test/data/idl/document.idl index afab566..afab566 100644 --- a/test/document.idl +++ b/test/data/idl/document.idl diff --git a/test/eventtarget.idl b/test/data/idl/eventtarget.idl index 2cfd15e..2cfd15e 100644 --- a/test/eventtarget.idl +++ b/test/data/idl/eventtarget.idl diff --git a/test/htmldocument.idl b/test/data/idl/htmldocument.idl index 923aa08..923aa08 100644 --- a/test/htmldocument.idl +++ b/test/data/idl/htmldocument.idl diff --git a/test/window.idl b/test/data/idl/window.idl index 7114709..7114709 100644 --- a/test/window.idl +++ b/test/data/idl/window.idl diff --git a/test/htmldocument.bnd b/test/htmldocument.bnd deleted file mode 100644 index 6f02c75..0000000 --- a/test/htmldocument.bnd +++ /dev/null @@ -1,3 +0,0 @@ -/* test binding docuemnt */ - -webidlfile "htmldocument.idl" diff --git a/test/testrunner.sh b/test/testrunner.sh new file mode 100755 index 0000000..b717e34 --- /dev/null +++ b/test/testrunner.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +outline() { +echo >>${LOGFILE} +echo "-----------------------------------------------------------" >>${LOGFILE} +echo >>${LOGFILE} +} + +BUILDDIR=$1 +TESTDIR=$2 + +# locations +LOGFILE=${BUILDDIR}/testlog + +GENJSBIND=${BUILDDIR}/genjsbind + +BINDINGDIR=${TESTDIR}/data/bindings +BINDINGTESTS=$(ls ${BINDINGDIR}/*.bnd) + +IDLDIR=${TESTDIR}/data/idl + +echo "$*" >${LOGFILE} + +for TEST in ${BINDINGTESTS};do + + TESTNAME=$(basename ${TEST} .bnd) + + echo -n " TEST: ${TESTNAME}......" + outline + + echo ${GENJSBIND} -d -v -I ${IDLDIR} -o ${BUILDDIR}/test_${TESTNAME}.c ${TEST} >>${LOGFILE} 2>&1 + + ${GENJSBIND} -d -v -I ${IDLDIR} -o ${BUILDDIR}/test_${TESTNAME}.c ${TEST} >>${LOGFILE} 2>&1 + + if [ $? -eq 0 ]; then + echo "PASS" + else + echo "FAIL" + fi + + +done + |