-/* $Id: output.c,v 1.76 2016/06/07 00:14:34 tom Exp $ */
+/* $Id: output.c,v 1.81 2017/04/30 23:23:32 tom Exp $ */
#include "defs.h"
}
static void
+output_stype(FILE * fp)
+{
+ if (!unionized && ntags == 0)
+ {
+ putc_code(fp, '\n');
+ putl_code(fp, "#if "
+ "! defined(YYSTYPE) && "
+ "! defined(YYSTYPE_IS_DECLARED)\n");
+ putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n");
+ putl_code(fp, "typedef int YYSTYPE;\n");
+ putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n");
+ putl_code(fp, "#endif\n");
+ }
+}
+
+#if defined(YYBTYACC)
+static void
+output_ltype(FILE * fp)
+{
+ putc_code(fp, '\n');
+ putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n");
+ putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n");
+ putl_code(fp, "typedef struct YYLTYPE\n");
+ putl_code(fp, "{\n");
+ putl_code(fp, " int first_line;\n");
+ putl_code(fp, " int first_column;\n");
+ putl_code(fp, " int last_line;\n");
+ putl_code(fp, " int last_column;\n");
+ putl_code(fp, " unsigned source;\n");
+ putl_code(fp, "} YYLTYPE;\n");
+ putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n");
+ putl_code(fp, "#endif\n");
+ putl_code(fp, "#define YYRHSLOC(rhs, k) ((rhs)[k])\n");
+}
+#endif
+
+static void
output_YYINT_typedef(FILE * fp)
{
/* generate the type used to index the various parser tables */
translate[i] = symbol_pval[gsymb];
}
+ putl_code(output_file,
+ "#if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)\n");
/* yystos[] may be unused, depending on compile-time defines */
start_int_table("stos", translate[0]);
end_table();
FREE(translate);
+ putl_code(output_file,
+ "#endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */\n");
}
}
}
fprintf(fp, "extern YYSTYPE %slval;\n", symbol_prefix);
}
+#if defined(YYBTYACC)
+ if (locations)
+ output_ltype(fp);
+#endif
}
}
putc_code(fp, '\n');
}
+#if defined(YY_NO_LEAKS)
static void
-output_stype(FILE * fp)
+output_no_leaks(FILE * fp)
{
- if (!unionized && ntags == 0)
- {
- putc_code(fp, '\n');
- putl_code(fp, "#if "
- "! defined(YYSTYPE) && "
- "! defined(YYSTYPE_IS_DECLARED)\n");
- putl_code(fp, "/* Default: YYSTYPE is the semantic value type. */\n");
- putl_code(fp, "typedef int YYSTYPE;\n");
- putl_code(fp, "# define YYSTYPE_IS_DECLARED 1\n");
- putl_code(fp, "#endif\n");
- }
-}
+ putc_code(fp, '\n');
-#if defined(YYBTYACC)
-static void
-output_ltype(FILE * fp)
-{
+ if (fp == code_file)
+ ++outline;
+ fputs("#define YY_NO_LEAKS 1\n", fp);
putc_code(fp, '\n');
- putl_code(fp, "#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED\n");
- putl_code(fp, "/* Default: YYLTYPE is the text position type. */\n");
- putl_code(fp, "typedef struct YYLTYPE\n");
- putl_code(fp, "{\n");
- putl_code(fp, " int first_line;\n");
- putl_code(fp, " int first_column;\n");
- putl_code(fp, " int last_line;\n");
- putl_code(fp, " int last_column;\n");
- putl_code(fp, "} YYLTYPE;\n");
- putl_code(fp, "#define YYLTYPE_IS_DECLARED 1\n");
- putl_code(fp, "#endif\n");
}
#endif
puts_code(fp, "#define YYERROR_DECL() yyerror(");
#if defined(YYBTYACC)
if (locations)
- puts_code(fp, "YYLTYPE loc, ");
+ puts_code(fp, "YYLTYPE *loc, ");
#endif
puts_param_types(fp, parse_param, 1);
putl_code(fp, "const char *s)\n");
puts_code(fp, "#define YYERROR_CALL(msg) yyerror(");
#if defined(YYBTYACC)
if (locations)
- puts_code(fp, "yylloc, ");
+ puts_code(fp, "&yylloc, ");
#endif
puts_param_names(fp, parse_param, 1);
putl_code(fp, "msg)\n");
}
static void
+output_initial_action(void)
+{
+ if (initial_action)
+ fprintf(code_file, "%s\n", initial_action);
+}
+
+static void
output_yydestruct_impl(void)
{
int i;
output_prefix(fp);
output_pure_parser(fp);
+#if defined(YY_NO_LEAKS)
+ output_no_leaks(fp);
+#endif
output_stored_text(fp);
output_stype(fp);
#if defined(YYBTYACC)
write_section(code_file, body_vars);
}
write_section(code_file, body_2);
+ if (pure_parser)
+ {
+ write_section(code_file, init_vars);
+ }
+#if defined(YYBTYACC)
+ if (initial_action)
+ output_initial_action();
+#endif
+ write_section(code_file, body_3);
output_semantic_actions();
write_section(code_file, trailer);
}