Module Name:    src
Committed By:   christos
Date:           Tue Oct 15 15:58:46 UTC 2019

Modified Files:
        src/external/bsd/byacc/dist: defs.h output.c reader.c

Log Message:
add %code bison extension (needed by acpica)


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/external/bsd/byacc/dist/defs.h \
    src/external/bsd/byacc/dist/reader.c
cvs rdiff -u -r1.20 -r1.21 src/external/bsd/byacc/dist/output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/byacc/dist/defs.h
diff -u src/external/bsd/byacc/dist/defs.h:1.16 src/external/bsd/byacc/dist/defs.h:1.17
--- src/external/bsd/byacc/dist/defs.h:1.16	Sun Oct  6 19:29:42 2019
+++ src/external/bsd/byacc/dist/defs.h	Tue Oct 15 11:58:46 2019
@@ -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 @@ extern void output(void);
 /* 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[]);
 
Index: src/external/bsd/byacc/dist/reader.c
diff -u src/external/bsd/byacc/dist/reader.c:1.16 src/external/bsd/byacc/dist/reader.c:1.17
--- src/external/bsd/byacc/dist/reader.c:1.16	Sun Dec 23 15:27:23 2018
+++ src/external/bsd/byacc/dist/reader.c	Tue Oct 15 11:58:46 2019
@@ -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 @@ char line_format[] = "#line %d \"%s\"\n"
 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 @@ static struct keyword
 }
 keywords[] = {
     { "binary",      NONASSOC },
+    { "code",        XCODE },
     { "debug",       XXXDEBUG },
 #if defined(YYBTYACC)
     { "destructor",  DESTRUCTOR },
@@ -666,6 +673,115 @@ copy_comment(void)
     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 @@ read_declarations(void)
 	    copy_ident();
 	    break;
 
+	case XCODE:
+	    copy_code();
+	    break;
+
 	case TEXT:
 	    copy_text();
 	    break;
@@ -2255,6 +2375,10 @@ advance_to_start(void)
 	s_cptr = cptr;
 	switch (keyword())
 	{
+	case XCODE:
+	    copy_code();
+	    break;
+
 	case MARK:
 	    no_grammar();
 

Index: src/external/bsd/byacc/dist/output.c
diff -u src/external/bsd/byacc/dist/output.c:1.20 src/external/bsd/byacc/dist/output.c:1.21
--- src/external/bsd/byacc/dist/output.c:1.20	Sun Dec 23 15:27:23 2018
+++ src/external/bsd/byacc/dist/output.c	Tue Oct 15 11:58:46 2019
@@ -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 int lowzero;
 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 @@ output_defines(FILE * fp)
     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 @@ output_defines(FILE * fp)
 	}
 #if defined(YYBTYACC)
 	if (locations)
+	{
 	    output_ltype(fp);
+	    fprintf(fp, "extern YYLTYPE %slloc;\n", symbol_prefix);
+	}
 #endif
     }
 }
@@ -2007,6 +2026,7 @@ output(void)
     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 @@ output(void)
     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)

Reply via email to