diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2014-10-06 14:55:38 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2014-10-06 14:55:38 +0000 |
commit | f78bee35d744f1874ca50e8ba4e237fd6a21ead3 (patch) | |
tree | ec2534002aad46df2cd72b5d285c5970773874d6 /output.c | |
parent | f78755d12f30cfac3dcc1aaaa81545a84b846c73 (diff) | |
download | src-f78bee35d744f1874ca50e8ba4e237fd6a21ead3.tar.gz src-f78bee35d744f1874ca50e8ba4e237fd6a21ead3.zip |
Notes
Diffstat (limited to 'output.c')
-rw-r--r-- | output.c | 164 |
1 files changed, 101 insertions, 63 deletions
@@ -1,4 +1,4 @@ -/* $Id: output.c,v 1.67 2014/04/22 23:16:57 tom Exp $ */ +/* $Id: output.c,v 1.74 2014/10/05 23:21:09 tom Exp $ */ #include "defs.h" @@ -54,6 +54,43 @@ puts_code(FILE * fp, const char *s) } static void +puts_param_types(FILE * fp, param * list, int more) +{ + param *p; + + if (list != 0) + { + for (p = list; p; p = p->next) + { + size_t len_type = strlen(p->type); + fprintf(fp, "%s%s%s%s%s", p->type, + (((len_type != 0) && (p->type[len_type - 1] == '*')) + ? "" + : " "), + p->name, p->type2, + ((more || p->next) ? ", " : "")); + } + } + else + { + if (!more) + fprintf(fp, "void"); + } +} + +static void +puts_param_names(FILE * fp, param * list, int more) +{ + param *p; + + for (p = list; p; p = p->next) + { + fprintf(fp, "%s%s", p->name, + ((more || p->next) ? ", " : "")); + } +} + +static void write_code_lineno(FILE * fp) { if (!lflag && (fp == code_file)) @@ -1007,30 +1044,33 @@ output_ctable(void) { int i; int j; + int limit = (conflicts != 0) ? nconflicts : 0; - if (conflicts) - { - output_line("#if YYBTYACC"); - start_int_table("ctable", conflicts[0]); + if (limit < high) + limit = (int)high; - j = 10; - for (i = 1; i < nconflicts; i++) - { - if (j >= 10) - { - output_newline(); - j = 1; - } - else - ++j; + output_line("#if YYBTYACC"); + start_int_table("ctable", conflicts ? conflicts[0] : -1); - output_int(conflicts[i]); + j = 10; + for (i = 1; i < limit; i++) + { + if (j >= 10) + { + output_newline(); + j = 1; } + else + ++j; - end_table(); - output_line("#endif"); - FREE(conflicts); + output_int((conflicts != 0 && i < nconflicts) ? conflicts[i] : -1); } + + if (conflicts) + FREE(conflicts); + + end_table(); + output_line("#endif"); } #endif @@ -1056,7 +1096,7 @@ output_actions(void) FREE(accessing_symbol); goto_actions(); - FREE(goto_map + ntokens); + FREE(goto_base); FREE(from_state); FREE(to_state); @@ -1607,15 +1647,7 @@ output_parse_decl(FILE * fp) putl_code(fp, "#else\n"); puts_code(fp, "# define YYPARSE_DECL() yyparse("); - if (!parse_param) - puts_code(fp, "void"); - else - { - param *p; - for (p = parse_param; p; p = p->next) - fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2, - p->next ? ", " : ""); - } + puts_param_types(fp, parse_param, 0); putl_code(fp, ")\n"); putl_code(fp, "#endif\n"); @@ -1633,7 +1665,8 @@ output_lex_decl(FILE * fp) #if defined(YYBTYACC) if (locations) { - putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc," + putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," + " YYLTYPE *yylloc," " YYLEX_PARAM_TYPE YYLEX_PARAM)\n"); } else @@ -1646,7 +1679,8 @@ output_lex_decl(FILE * fp) #if defined(YYBTYACC) if (locations) { - putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLTYPE *yylloc," + putl_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval," + " YYLTYPE *yylloc," " void * YYLEX_PARAM)\n"); } else @@ -1672,8 +1706,6 @@ output_lex_decl(FILE * fp) putl_code(fp, "#else\n"); if (pure_parser && lex_param) { - param *p; - #if defined(YYBTYACC) if (locations) puts_code(fp, @@ -1681,9 +1713,7 @@ output_lex_decl(FILE * fp) else #endif puts_code(fp, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, "); - for (p = lex_param; p; p = p->next) - fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2, - p->next ? ", " : ""); + puts_param_types(fp, lex_param, 0); putl_code(fp, ")\n"); #if defined(YYBTYACC) @@ -1692,8 +1722,7 @@ output_lex_decl(FILE * fp) else #endif puts_code(fp, "# define YYLEX yylex(&yylval, "); - for (p = lex_param; p; p = p->next) - fprintf(fp, "%s%s", p->name, p->next ? ", " : ""); + puts_param_names(fp, lex_param, 0); putl_code(fp, ")\n"); } else if (pure_parser) @@ -1714,17 +1743,12 @@ output_lex_decl(FILE * fp) } else if (lex_param) { - param *p; - puts_code(fp, "# define YYLEX_DECL() yylex("); - for (p = lex_param; p; p = p->next) - fprintf(fp, "%s %s%s%s", p->type, p->name, p->type2, - p->next ? ", " : ""); + puts_param_types(fp, lex_param, 0); putl_code(fp, ")\n"); puts_code(fp, "# define YYLEX yylex("); - for (p = lex_param; p; p = p->next) - fprintf(fp, "%s%s", p->name, p->next ? ", " : ""); + puts_param_names(fp, lex_param, 0); putl_code(fp, ")\n"); } else @@ -1738,8 +1762,6 @@ output_lex_decl(FILE * fp) static void output_error_decl(FILE * fp) { - param *p; - putc_code(fp, '\n'); putl_code(fp, "/* Parameters sent to yyerror. */\n"); putl_code(fp, "#ifndef YYERROR_DECL\n"); @@ -1748,22 +1770,20 @@ output_error_decl(FILE * fp) if (locations) puts_code(fp, "YYLTYPE loc, "); #endif - for (p = parse_param; p; p = p->next) - fprintf(fp, "%s %s%s, ", p->type, p->name, p->type2); + puts_param_types(fp, parse_param, 1); putl_code(fp, "const char *s)\n"); putl_code(fp, "#endif\n"); putl_code(fp, "#ifndef YYERROR_CALL\n"); - puts_code(fp, "#define YYERROR_CALL(msg) yyerror("); + puts_code(fp, "#define YYERROR_CALL(msg) yyerror("); #if defined(YYBTYACC) if (locations) puts_code(fp, "yylloc, "); #endif - for (p = parse_param; p; p = p->next) - fprintf(fp, "%s, ", p->name); - + puts_param_names(fp, parse_param, 1); putl_code(fp, "msg)\n"); + putl_code(fp, "#endif\n"); } @@ -1773,24 +1793,42 @@ output_yydestruct_decl(FILE * fp) { putc_code(fp, '\n'); putl_code(fp, "#ifndef YYDESTRUCT_DECL\n"); + + puts_code(fp, + "#define YYDESTRUCT_DECL() " + "yydestruct(const char *msg, int psymb, YYSTYPE *val"); #if defined(YYBTYACC) if (locations) - putl_code(fp, - "#define YYDESTRUCT_DECL() yydestruct(const char *msg, int psymb, YYSTYPE *val, YYLTYPE *loc)\n"); - else + puts_code(fp, ", YYLTYPE *loc"); #endif - putl_code(fp, - "#define YYDESTRUCT_DECL() yydestruct(const char *msg, int psymb, YYSTYPE *val)\n"); + if (parse_param) + { + puts_code(fp, ", "); + puts_param_types(fp, parse_param, 0); + } + putl_code(fp, ")\n"); + putl_code(fp, "#endif\n"); + putl_code(fp, "#ifndef YYDESTRUCT_CALL\n"); + + puts_code(fp, "#define YYDESTRUCT_CALL(msg, psymb, val"); #if defined(YYBTYACC) if (locations) - putl_code(fp, - "#define YYDESTRUCT_CALL(msg, psymb, val, loc) yydestruct(msg, psymb, val, loc)\n"); - else + puts_code(fp, ", loc"); #endif - putl_code(fp, - "#define YYDESTRUCT_CALL(msg, psymb, val) yydestruct(msg, psymb, val)\n"); + puts_code(fp, ") yydestruct(msg, psymb, val"); +#if defined(YYBTYACC) + if (locations) + puts_code(fp, ", loc"); +#endif + if (parse_param) + { + puts_code(fp, ", "); + puts_param_names(fp, parse_param, 0); + } + putl_code(fp, ")\n"); + putl_code(fp, "#endif\n"); } |