--- a/c2iec.y +++ b/c2iec.y @@ -57,6 +57,9 @@ // it to the correct section when we know more about // our context void fifo_tag(fifo_entry_t type); + +// check if fifo is empty +int fifo_empty(fifo_entry_t type); // map c datatype to iec (standard and userdefined) char *maptype(char *ctype); @@ -266,6 +269,8 @@ | TYPEDEF declaration_specifiers init_declarator_list ';' { char *p; + while( (p=fifo_pop(decl_func)) != NULL) + /* noop */; while( (p=fifo_pop(decl_all)) != NULL) /* noop */; if (strlen($<str>3) > 0) @@ -408,9 +413,9 @@ // as a lexxer hack, I added a special case for typedefs // to the declaration rule -specifier_qualifier_list - : TYPEDEF type_specifier specifier_qualifier_list - { sprintf($<str>$, "lexxer hack - typedef found\n"); } +//specifier_qualifier_list +// : TYPEDEF type_specifier specifier_qualifier_list +// { sprintf($<str>$, "lexxer hack - typedef found\n"); } specifier_qualifier_list : type_specifier specifier_qualifier_list @@ -473,14 +478,22 @@ : pointer direct_declarator { sprintf($<str>$, "%s: POINTER TO %%s;\n",$<str>2); - fifo_push(decl_all, $<str>$); + // don't push function declarations to decl_all + if (fifo_empty(decl_func)) + { + fifo_push(decl_all, $<str>$); + } } | direct_declarator { if (strlen($<str>1) > 0) { sprintf($<str>$, "%s: %%s;\n",$<str>1); - fifo_push(decl_all, $<str>$); + // don't push function declarations to decl_all + if (fifo_empty(decl_func)) + { + fifo_push(decl_all, $<str>$); + } } } ; @@ -520,21 +533,21 @@ sprintf($<str>$, "FUNCTION %s:%%s;\n",$<str>1); fifo_push(decl_func, $<str>$); strcpy($<str>$, $<str>1); - strcpy($<str>$, ""); +// strcpy($<str>$, ""); } | direct_declarator '(' identifier_list ')' { sprintf($<str>$, "FUNCTION %s:%%s;\n",$<str>1); fifo_push(decl_func, $<str>$); strcpy($<str>$, $<str>1); - strcpy($<str>$, ""); +// strcpy($<str>$, ""); } | direct_declarator '(' ')' { sprintf($<str>$, "FUNCTION %s:%%s;\n",$<str>1); fifo_push(decl_func, $<str>$); strcpy($<str>$, ""); - strcpy($<str>$, ""); +// strcpy($<str>$, ""); } ; @@ -785,6 +798,15 @@ return s_fifos[type].fifo[fifor_prev]; } return NULL; +} + +int fifo_empty(fifo_entry_t type) +{ + if (s_fifos[type].read == s_fifos[type].write) + { + return 1; + } + return 0; } void fifo_tag(fifo_entry_t type)