]> git.saurik.com Git - bison.git/blob - src/location.h
* src/files.c (compute_base_names): When computing the output file
[bison.git] / src / location.h
1 /* Locations for Bison
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4 This file is part of Bison, the GNU Compiler Compiler.
5
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #ifndef LOCATION_H_
22 # define LOCATION_H_
23
24 typedef struct location_s
25 {
26 int first_line;
27 int first_column;
28 int last_line;
29 int last_column;
30 } location_t;
31 #define YYLTYPE location_t
32
33 /* Initialize LOC. */
34 # define LOCATION_RESET(Loc) \
35 (Loc).first_column = (Loc).first_line = 1; \
36 (Loc).last_column = (Loc).last_line = 1;
37
38 /* Advance of NUM columns. */
39 # define LOCATION_COLUMNS(Loc, Num) \
40 (Loc).last_column += Num;
41
42 /* Advance of NUM lines. */
43 # define LOCATION_LINES(Loc, Num) \
44 (Loc).last_column = 1; \
45 (Loc).last_line += Num;
46
47 /* Restart: move the first cursor to the last position. */
48 # define LOCATION_STEP(Loc) \
49 (Loc).first_column = (Loc).last_column; \
50 (Loc).first_line = (Loc).last_line;
51
52 /* Output LOC on the stream OUT. */
53 # define LOCATION_PRINT(Out, Loc) \
54 fprintf (stderr, "%s:", infile); \
55 if ((Loc).first_line != (Loc).last_line) \
56 fprintf (Out, "%d.%d-%d.%d", \
57 (Loc).first_line, (Loc).first_column, \
58 (Loc).last_line, (Loc).last_column - 1); \
59 else if ((Loc).first_column < (Loc).last_column - 1) \
60 fprintf (Out, "%d.%d-%d", (Loc).first_line, \
61 (Loc).first_column, (Loc).last_column - 1); \
62 else \
63 fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column)
64
65
66 extern location_t empty_location;
67 #endif /* !LOCATION_H_ */