[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02-locations.patch
From: |
Akim Demaille |
Subject: |
02-locations.patch |
Date: |
Fri, 14 Jun 2002 19:28:28 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* src/location.h: New, extracted from...
* src/reader.h: here.
* src/Makefile.am (noinst_HEADERS): Merge into
(bison_SOURCES): this.
Add location.h.
* src/parse-gram.y: Use location_t instead of Bison's.
* src/reader.h, src/reader.c (prologue_augment, epilogue_set):
Use location_t instead of ints.
Index: src/parse-gram.y
--- src/parse-gram.y Wed, 12 Jun 2002 00:00:36 +0200 akim
+++ src/parse-gram.y Fri, 14 Jun 2002 17:48:18 +0200 akim
@@ -38,6 +38,7 @@
#include "reader.h"
#include "conflicts.h"
+/* Produce verbose parse errors. */
#define YYERROR_VERBOSE 1
/* Pass the control structure to YYPARSE and YYLEX. */
@@ -57,7 +58,7 @@
of the tokens. */
#define YYPRINT(File, Type, Value) \
yyprint (File, &yylloc, Type, &Value)
-static void yyprint (FILE *file, const yyltype *loc,
+static void yyprint (FILE *file, const location_t *loc,
int type, const yystype *value);
symbol_class current_class = unknown_sym;
@@ -132,7 +133,7 @@ input: { LOCATION_RESET (yylloc); }
directives "%%" gram epilogue.opt
{
yycontrol->errcode = 0;
- epilogue_set ($5, @5.first_line);
+ epilogue_set ($5, @5);
}
;
@@ -145,7 +146,7 @@ directive:
grammar_directives
| PROLOGUE
{
- prologue_augment ($1, @1.first_line);
+ prologue_augment ($1, @1);
}
| "%debug" { debug_flag = 1; }
| "%define" string_content string_content { muscle_insert ($2, $3); }
@@ -348,7 +349,7 @@ epilogue.opt:
static void
yyprint (FILE *file,
- const yyltype *loc, int type, const yystype *value)
+ const location_t *loc, int type, const yystype *value)
{
fputs (" (", file);
LOCATION_PRINT (file, *loc);
@@ -385,7 +386,7 @@ epilogue.opt:
void
gram_error (gram_control_t *control ATTRIBUTE_UNUSED,
- yyltype *yylloc, const char *msg)
+ location_t *yylloc, const char *msg)
{
LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": %s\n", msg);
Index: src/Makefile.am
--- src/Makefile.am Tue, 11 Jun 2002 21:16:20 +0200 akim
+++ src/Makefile.am Fri, 14 Jun 2002 17:51:08 +0200 akim
@@ -35,27 +35,41 @@
bin_PROGRAMS = bison
-bison_SOURCES = LR0.c closure.c complain.c conflicts.c \
- parse-gram.y parse-gram.h \
- scan-gram.c \
- derives.c \
- files.c getargs.c gram.c lalr.c main.c nullable.c \
- output.h output.c \
- state.h state.c \
- print_graph.h print_graph.c \
- muscle_tab.h muscle_tab.c \
- options.h options.c \
- print.c reader.c reduce.c symtab.c vcg.c \
- scan-skel.l
+bison_SOURCES = \
+ LR0.c LR0.h \
+ closure.c closure.h \
+ complain.c complain.h \
+ conflicts.c conflicts.h \
+ derives.c derives.h \
+ files.c files.h \
+ getargs.c getargs.h \
+ gram.c gram.h \
+ lalr.h lalr.c \
+ location.h \
+ main.c \
+ muscle_tab.c muscle_tab.h \
+ nullable.c nullable.h \
+ options.c options.h \
+ output.c output.h \
+ parse-gram.h parse-gram.y \
+ print.c print.h \
+ print_graph.c print_graph.h \
+ reader.c reader.h \
+ reduce.c reduce.h \
+ scan-gram.l \
+ scan-skel.l \
+ state.c state.h \
+ symtab.c symtab.h \
+ system.h \
+ types.h \
+ vcg.c vcg.h \
+ vcg_defaults.h
BUILT_SOURCES = scan-skel.c scan-gram.c parse-gram.c parse-gram.h
EXTRA_bison_SOURCES = vmsgetargs.c
-noinst_HEADERS = LR0.h closure.h complain.h conflicts.h \
- derives.h \
- files.h getargs.h gram.h lalr.h nullable.h \
- print.h reader.h reduce.h symtab.h system.h \
- types.h vcg.h vcg_defaults.h
-
EXTRA_DIST = build.com bison.cld vmshlp.mar
+
+echo:
+ echo $(bison_SOURCES) $(noinst_HEADERS)
Index: src/reader.c
--- src/reader.c Tue, 11 Jun 2002 23:39:15 +0200 akim
+++ src/reader.c Thu, 13 Jun 2002 18:58:26 +0200 akim
@@ -113,7 +113,7 @@
`----------------------------------------------------------------*/
void
-prologue_augment (const char *prologue, int location)
+prologue_augment (const char *prologue, location_t location)
{
struct obstack *oout =
!typed ? &pre_prologue_obstack : &post_prologue_obstack;
@@ -121,8 +121,9 @@
if (!no_lines_flag)
{
obstack_fgrow2 (oout, muscle_find ("linef"),
- location, quotearg_style (c_quoting_style,
- muscle_find ("filename")));
+ location.first_line,
+ quotearg_style (c_quoting_style,
+ muscle_find ("filename")));
}
obstack_sgrow (oout, prologue);
}
@@ -135,7 +136,7 @@
`----------------------*/
void
-epilogue_set (const char *epilogue, int location)
+epilogue_set (const char *epilogue, location_t location)
{
struct obstack el_obstack;
obstack_init (&el_obstack);
@@ -143,8 +144,9 @@
if (!no_lines_flag)
{
obstack_fgrow2 (&el_obstack, muscle_find ("linef"),
- location, quotearg_style (c_quoting_style,
- muscle_find ("filename")));
+ location.first_line,
+ quotearg_style (c_quoting_style,
+ muscle_find ("filename")));
}
obstack_sgrow (&el_obstack, epilogue);
obstack_1grow (&el_obstack, 0);
Index: src/reader.h
--- src/reader.h Tue, 11 Jun 2002 23:39:15 +0200 akim
+++ src/reader.h Thu, 13 Jun 2002 20:14:49 +0200 akim
@@ -21,6 +21,8 @@
#ifndef READER_H_
# define READER_H_
+# include "location.h"
+
typedef struct symbol_list
{
struct symbol_list *next;
@@ -36,40 +38,6 @@
# include "parse-gram.h"
-typedef int location_t;
-
-/* Initialize LOC. */
-# define LOCATION_RESET(Loc) \
- (Loc).first_column = (Loc).first_line = 1; \
- (Loc).last_column = (Loc).last_line = 1;
-
-/* Advance of NUM columns. */
-# define LOCATION_COLUMNS(Loc, Num) \
- (Loc).last_column += Num;
-
-/* Advance of NUM lines. */
-# define LOCATION_LINES(Loc, Num) \
- (Loc).last_column = 1; \
- (Loc).last_line += Num;
-
-/* Restart: move the first cursor to the last position. */
-# define LOCATION_STEP(Loc) \
- (Loc).first_column = (Loc).last_column; \
- (Loc).first_line = (Loc).last_line;
-
-/* Output LOC on the stream OUT. */
-# define LOCATION_PRINT(Out, Loc) \
- fprintf (stderr, "%s:", infile); \
- if ((Loc).first_line != (Loc).last_line) \
- fprintf (Out, "%d.%d-%d.%d", \
- (Loc).first_line, (Loc).first_column, \
- (Loc).last_line, (Loc).last_column - 1); \
- else if ((Loc).first_column < (Loc).last_column - 1) \
- fprintf (Out, "%d.%d-%d", (Loc).first_line, \
- (Loc).first_column, (Loc).last_column - 1); \
- else \
- fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column)
-
typedef struct gram_control_s
{
int errcode;
@@ -83,7 +51,7 @@
void scanner_free PARAMS ((void));
# define YY_DECL \
- int gram_lex (yystype *yylval, yyltype *yylloc, \
+ int gram_lex (yystype *yylval, location_t *yylloc, \
gram_control_t *yycontrol)
YY_DECL;
@@ -91,7 +59,7 @@
/* From the parser. */
extern int gram_debug;
void gram_error (gram_control_t *control,
- yyltype *loc, const char *msg);
+ location_t *loc, const char *msg);
int gram_parse (void *control);
char *get_type_name PARAMS ((int n, symbol_list *rule));
Index: src/location.h
--- src/location.h Fri, 14 Jun 2002 17:58:00 +0200 akim
+++ src/location.h Thu, 13 Jun 2002 20:12:18 +0200 akim
@@ -0,0 +1,65 @@
+/* Locations for Bison
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ Bison is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Bison is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bison; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef LOCATION_H_
+# define LOCATION_H_
+
+typedef struct location_s
+{
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+} location_t;
+#define YYLTYPE location_t
+
+/* Initialize LOC. */
+# define LOCATION_RESET(Loc) \
+ (Loc).first_column = (Loc).first_line = 1; \
+ (Loc).last_column = (Loc).last_line = 1;
+
+/* Advance of NUM columns. */
+# define LOCATION_COLUMNS(Loc, Num) \
+ (Loc).last_column += Num;
+
+/* Advance of NUM lines. */
+# define LOCATION_LINES(Loc, Num) \
+ (Loc).last_column = 1; \
+ (Loc).last_line += Num;
+
+/* Restart: move the first cursor to the last position. */
+# define LOCATION_STEP(Loc) \
+ (Loc).first_column = (Loc).last_column; \
+ (Loc).first_line = (Loc).last_line;
+
+/* Output LOC on the stream OUT. */
+# define LOCATION_PRINT(Out, Loc) \
+ fprintf (stderr, "%s:", infile); \
+ if ((Loc).first_line != (Loc).last_line) \
+ fprintf (Out, "%d.%d-%d.%d", \
+ (Loc).first_line, (Loc).first_column, \
+ (Loc).last_line, (Loc).last_column - 1); \
+ else if ((Loc).first_column < (Loc).last_column - 1) \
+ fprintf (Out, "%d.%d-%d", (Loc).first_line, \
+ (Loc).first_column, (Loc).last_column - 1); \
+ else \
+ fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column)
+
+#endif /* !LOCATION_H_ */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 02-locations.patch,
Akim Demaille <=