From: Peep P. <so...@us...> - 2004-06-07 15:40:13
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7757 Modified Files: dfparse.y Log Message: Fixed headers; doesn't use array_t Index: dfparse.y =================================================================== RCS file: /cvsroot/agd/server/src/dfparse.y,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- dfparse.y 1 Apr 2004 19:10:53 -0000 1.8 +++ dfparse.y 7 Jun 2004 15:40:03 -0000 1.9 @@ -1,9 +1,9 @@ /* parser for dfdecl - didn't try to muck with indendation in vim, so this has a different indent - style than lang.y Changelog: + 0.08: + * Not using array_{push,concat} etc anymore. No changes in output. 0.07: * prints index of function for easier debugging * now outputs prototypes @@ -25,16 +25,15 @@ Changes prior to 0.03 are undocumented. */ %{ -#include <stdlib.h> /* realloc */ -#include <stdio.h> /* FILE* */ +#include <stdlib.h> +#include <stdio.h> #include <errno.h> #include <time.h> #include "sys.h" /* xmalloc */ -#include "array.h" #include "lpc.h" -#define DFVERSION "0.07" +#define DFVERSION "0.08" #define DFDECL_T "typedef struct {\n\tint ret;\n\tchar *name;\n\tvoid (*fun)(void);\n\t"\ "int arglen;\n\tint args[%d];\n} dfdecl_t;\n" typedef struct { @@ -48,30 +47,32 @@ static int maxarglen; extern FILE *yyin; -/*YYLTYPE yylloc;*/ - -int find_linear_len(array_t *a); %} %union { char *s; int i; - array_t a; + struct arr_t { + int length; + long int *data; + } a; } %token <s> L_IDENTIFIER %token <i> L_DATA_TYPE %type <i> type -%type <a> arguments argument another_argument another_type +%type <a> arguments argument +%type <a> another_argument another_type +%type <a> argument_and_another type_and_another %% all: /* empty */ | all dfdecl -; + ; dfdecl: type L_IDENTIFIER '(' arguments ')' @@ -79,6 +80,8 @@ int i, j, index; dfdecl_t decl; + int find_linear_len(struct arr_t *a); + @1; /* To force bison to define yylloc. */ decl.ret = $1; @@ -89,74 +92,76 @@ if(decl.arglen) decl.args = xmalloc(sizeof(int) * decl.arglen); for(index=i=0;i<$4.length;i++) { - array_t *var = $4.data[i]; + struct arr_t *var = (struct arr_t *) $4.data[i]; + foo(); decl.args[index++] = var->length; for(j=0;j<var->length;j++) decl.args[index++] = (int) var->data[j]; } - dfdecl = realloc(dfdecl, sizeof(dfdecl_t) * ++numdecl); + dfdecl = xrealloc(dfdecl, sizeof(dfdecl_t) * ++numdecl); dfdecl[numdecl-1] = decl; } -; + ; -type: - L_DATA_TYPE /* optional_star */ - { - $$ = $1; - } -; +type: L_DATA_TYPE /* optional_star */; arguments: - /* empty */ - { - init_array(&$$); - } - | argument another_argument - { - init_array(&$$); - if($1.length) - array_push(&$$, copy_array(&$1, NULL)); - array_concat(&$$, &$2); - } -; + /* empty */ { $$.length = 0; } + | argument_and_another + ; -argument: - type another_type - { - init_array(&$$); - if($1 != T_VOID) - array_push(&$$, (void *) $1); - array_concat(&$$, &$2); - } -; +argument: type_and_another; another_argument: - /* empty */ - { - init_array(&$$); - } - | ',' argument another_argument + /* empty */ { $$.length = 0; } + | ',' argument_and_another { $$ = $2; } + ; + +argument_and_another: + argument another_argument { - init_array(&$$); - if($2.length) - array_push(&$$, copy_array(&$2, NULL)); - array_concat(&$$, &$3); + int i, foo; + + foo = $1.length ? 1 : 0; + $$.length = $2.length + foo; + $$.data = xmalloc(sizeof(struct arr_t*) * $$.length); + + if($1.length) { + struct arr_t *a = xmalloc(sizeof(struct arr_t)); + *a = $1; + $$.data[0] = (int) a; + } + + for(i=foo;i<$$.length;i++) { + $$.data[i] = $2.data[i-foo]; + } } -; - + ; + another_type: - /* empty */ - { - init_array(&$$); - } - | '|' type another_type + /* empty */ { $$.length = 0; } + | '|' type_and_another { $$ = $2; } + ; + +type_and_another: + type another_type { - init_array(&$$); - if($2 != T_VOID) - array_push(&$$, (void *) $2); - array_concat(&$$, &$3); + int i, foo; + + foo = $1 != T_VOID ? 1 : 0; + $$.length = $2.length + foo; + $$.data = xmalloc(sizeof(int) * $$.length); + + if($1 != T_VOID) { + $$.data[0] = $1; + } + + for(i=foo;i<$$.length;i++) { + $$.data[i] = $2.data[i-foo]; + } } -; + ; + %% int yyerror(char *s) { @@ -167,12 +172,12 @@ return 0; } -int find_linear_len(array_t *a) +int find_linear_len(struct arr_t *a) { int len; int i, j; for(len=i=0;i<a->length;i++,len++) { - array_t *p = a->data[i]; + struct arr_t *p = (struct arr_t *) a->data[i]; for(j=0;j<p->length;j++,len++); } return len; @@ -262,3 +267,5 @@ return 0; } +foo() { +} |