Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/byacc/dist add %code bison extension (needed by...
details: https://anonhg.NetBSD.org/src/rev/0367462a7ba2
branches: trunk
changeset: 464637:0367462a7ba2
user: christos <christos%NetBSD.org@localhost>
date: Tue Oct 15 15:58:46 2019 +0000
description:
add %code bison extension (needed by acpica)
diffstat:
external/bsd/byacc/dist/defs.h | 20 ++++-
external/bsd/byacc/dist/output.c | 27 +++++++-
external/bsd/byacc/dist/reader.c | 128 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 167 insertions(+), 8 deletions(-)
diffs (295 lines):
diff -r 1081cf42c10b -r 0367462a7ba2 external/bsd/byacc/dist/defs.h
--- a/external/bsd/byacc/dist/defs.h Tue Oct 15 15:56:26 2019 +0000
+++ b/external/bsd/byacc/dist/defs.h Tue Oct 15 15:58:46 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.16 2019/10/06 23:29:42 christos Exp $ */
+/* $NetBSD: defs.h,v 1.17 2019/10/15 15:58:46 christos Exp $ */
/* Id: defs.h,v 1.61 2019/06/16 15:07:51 tom Exp */
@@ -126,11 +126,12 @@
#define TOKEN_TABLE 16
#define ERROR_VERBOSE 17
#define XXXDEBUG 18
+#define XCODE 19
#if defined(YYBTYACC)
-#define LOCATIONS 19
-#define DESTRUCTOR 20
-#define INITIAL_ACTION 21
+#define LOCATIONS 20
+#define DESTRUCTOR 21
+#define INITIAL_ACTION 22
#endif
/* symbol classes */
@@ -580,6 +581,17 @@
/* reader.c */
extern void reader(void);
+#define CODE_HEADER 0
+#define CODE_REQUIRES 1
+#define CODE_PROVIDES 2
+#define CODE_TOP 3
+#define CODE_IMPORTS 4
+#define CODE_MAX 5
+struct code_lines {
+ char *lines;
+ size_t num;
+} code_lines[CODE_MAX];
+
/* skeleton.c (generated by skel2c) */
extern void write_section(FILE * fp, const char *const section[]);
diff -r 1081cf42c10b -r 0367462a7ba2 external/bsd/byacc/dist/output.c
--- a/external/bsd/byacc/dist/output.c Tue Oct 15 15:56:26 2019 +0000
+++ b/external/bsd/byacc/dist/output.c Tue Oct 15 15:58:46 2019 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: output.c,v 1.20 2018/12/23 20:27:23 jakllsch Exp $ */
+/* $NetBSD: output.c,v 1.21 2019/10/15 15:58:46 christos Exp $ */
/* Id: output.c,v 1.87 2018/05/10 09:08:46 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
-__RCSID("$NetBSD: output.c,v 1.20 2018/12/23 20:27:23 jakllsch Exp $");
+__RCSID("$NetBSD: output.c,v 1.21 2019/10/15 15:58:46 christos Exp $");
#define StaticOrR (rflag ? "" : "static ")
#define CountLine(fp) (!rflag || ((fp) == code_file))
@@ -37,6 +37,16 @@
static long high;
static void
+output_code_lines(FILE *fp, int cl)
+{
+ if (code_lines[cl].lines == NULL)
+ return;
+ if (fp == code_file)
+ outline += code_lines[cl].num;
+ fputs(code_lines[cl].lines, fp);
+}
+
+static void
putc_code(FILE * fp, int c)
{
if ((c == '\n') && (fp == code_file))
@@ -1244,6 +1254,12 @@
if (fp != defines_file || iflag)
fprintf(fp, "#define YYERRCODE %d\n", symbol_value[1]);
+ if (fp == defines_file)
+ {
+ output_code_lines(fp, CODE_REQUIRES);
+ output_code_lines(fp, CODE_PROVIDES);
+ }
+
if (token_table && rflag && fp != externs_file)
{
if (fp == code_file)
@@ -1269,7 +1285,10 @@
}
#if defined(YYBTYACC)
if (locations)
+ {
output_ltype(fp);
+ fprintf(fp, "extern YYLTYPE %slloc;\n", symbol_prefix);
+ }
#endif
}
}
@@ -2007,6 +2026,7 @@
free_shifts();
free_reductions();
+ output_code_lines(code_file, CODE_TOP);
#if defined(YYBTYACC)
output_backtracking_parser(output_file);
if (rflag)
@@ -2023,6 +2043,9 @@
else
fp = code_file;
+ output_code_lines(code_file, CODE_REQUIRES);
+ output_code_lines(code_file, CODE_PROVIDES);
+
output_prefix(fp);
output_pure_parser(fp);
#if defined(YY_NO_LEAKS)
diff -r 1081cf42c10b -r 0367462a7ba2 external/bsd/byacc/dist/reader.c
--- a/external/bsd/byacc/dist/reader.c Tue Oct 15 15:56:26 2019 +0000
+++ b/external/bsd/byacc/dist/reader.c Tue Oct 15 15:58:46 2019 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: reader.c,v 1.16 2018/12/23 20:27:23 jakllsch Exp $ */
+/* $NetBSD: reader.c,v 1.17 2019/10/15 15:58:46 christos Exp $ */
/* Id: reader.c,v 1.74 2017/12/04 17:50:02 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
-__RCSID("$NetBSD: reader.c,v 1.16 2018/12/23 20:27:23 jakllsch Exp $");
+__RCSID("$NetBSD: reader.c,v 1.17 2019/10/15 15:58:46 christos Exp $");
/* The line size must be a positive integer. One hundred was chosen */
/* because few lines in Yacc input grammars exceed 100 characters. */
@@ -67,6 +67,12 @@
param *lex_param;
param *parse_param;
+static const char *code_keys[] = {
+ "", "requires", "provides", "top", "imports",
+};
+
+struct code_lines code_lines[CODE_MAX];
+
#if defined(YYBTYACC)
int destructor = 0; /* =1 if at least one %destructor */
@@ -447,6 +453,7 @@
}
keywords[] = {
{ "binary", NONASSOC },
+ { "code", XCODE },
{ "debug", XXXDEBUG },
#if defined(YYBTYACC)
{ "destructor", DESTRUCTOR },
@@ -666,6 +673,115 @@
return msdone(temp);
}
+static int
+check_key(int pos)
+{
+ const char *key = code_keys[pos];
+ while (*cptr && *key)
+ if (*key++ != *cptr++)
+ return 0;
+ if (*key || (!isspace(UCH(*cptr)) && *cptr != L_CURL))
+ return 0;
+ cptr--;
+ return 1;
+}
+
+
+static void
+copy_code(void)
+{
+ int c;
+ int curl;
+ int cline = 0;
+ int pos = CODE_HEADER;
+ struct mstring *code_mstr;
+
+ /* read %code <keyword> { */
+ for (;;)
+ {
+ c = *++cptr;
+ if (c == EOF)
+ unexpected_EOF();
+ if (isspace(UCH(c)))
+ continue;
+
+ if (c == L_CURL)
+ break;
+
+ if (pos == CODE_HEADER)
+ {
+ switch (UCH(c))
+ {
+ case 'r':
+ pos = CODE_REQUIRES;
+ break;
+ case 'p':
+ pos = CODE_PROVIDES;
+ break;
+ case 't':
+ pos = CODE_TOP;
+ break;
+ case 'i':
+ pos = CODE_IMPORTS;
+ break;
+ default:
+ break;
+ }
+
+ if (pos == -1 || !check_key(pos))
+ {
+ syntax_error(lineno, line, cptr);
+ return;
+ }
+ }
+ }
+
+ cptr++; /* skip initial curl */
+ while (*cptr && isspace(UCH(*cptr))) /* skip space */
+ cptr++;
+ curl = 1; /* nesting count */
+
+ /* gather text */
+ code_mstr = msnew();
+ cline++;
+ msprintf(code_mstr, "/* %%code %s block start */\n", code_keys[pos]);
+ for (;;)
+ {
+ c = *cptr++;
+ switch (c)
+ {
+ case '\0':
+ get_line();
+ if (line == NULL)
+ {
+ unexpected_EOF();
+ return;
+ }
+ continue;
+ case '\n':
+ cline++;
+ break;
+ case L_CURL:
+ curl++;
+ break;
+ case R_CURL:
+ if (--curl == 0)
+ {
+ cline++;
+ msprintf(code_mstr, "/* %%code %s block end */\n",
+ code_keys[pos]);
+ code_lines[pos].lines = msdone(code_mstr);
+ code_lines[pos].num = cline;
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ mputc(code_mstr, c);
+ }
+}
+
static void
copy_text(void)
{
@@ -1691,6 +1807,10 @@
copy_ident();
break;
+ case XCODE:
+ copy_code();
+ break;
+
case TEXT:
copy_text();
break;
@@ -2255,6 +2375,10 @@
s_cptr = cptr;
switch (keyword())
{
+ case XCODE:
+ copy_code();
+ break;
+
case MARK:
no_grammar();
Home |
Main Index |
Thread Index |
Old Index