]>
Commit | Line | Data |
---|---|---|
0c15323d AD |
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_ | |
1a715ef2 | 23 | # include "quotearg.h" |
0c15323d AD |
24 | |
25 | typedef struct location_s | |
26 | { | |
1a715ef2 | 27 | const char *file; |
0c15323d AD |
28 | int first_line; |
29 | int first_column; | |
30 | int last_line; | |
31 | int last_column; | |
32 | } location_t; | |
33 | #define YYLTYPE location_t | |
34 | ||
35 | /* Initialize LOC. */ | |
1a715ef2 AD |
36 | # define LOCATION_RESET(Loc) \ |
37 | do { \ | |
38 | (Loc).file = NULL; \ | |
39 | (Loc).first_column = (Loc).first_line = 1; \ | |
40 | (Loc).last_column = (Loc).last_line = 1; \ | |
41 | } while (0) | |
0c15323d | 42 | |
0c15323d AD |
43 | |
44 | /* Restart: move the first cursor to the last position. */ | |
1a715ef2 AD |
45 | # define LOCATION_STEP(Loc) \ |
46 | do { \ | |
47 | (Loc).first_column = (Loc).last_column; \ | |
48 | (Loc).first_line = (Loc).last_line; \ | |
49 | } while (0) | |
50 | ||
0c15323d | 51 | |
c4d720cd AD |
52 | /* Output LOC on the stream OUT. |
53 | Warning: it uses quotearg's slot 3. */ | |
1a715ef2 AD |
54 | # define LOCATION_PRINT(Out, Loc) \ |
55 | do { \ | |
b1ae9233 | 56 | fprintf (stderr, "%s:", quotearg_n_style (3, escape_quoting_style, \ |
c4d720cd | 57 | (Loc).file)); \ |
b1ae9233 AD |
58 | if ((Loc).first_line) \ |
59 | { \ | |
60 | if ((Loc).first_line != (Loc).last_line) \ | |
61 | fprintf (Out, "%d.%d-%d.%d", \ | |
62 | (Loc).first_line, (Loc).first_column, \ | |
63 | (Loc).last_line, (Loc).last_column - 1); \ | |
64 | else if ((Loc).first_column < (Loc).last_column - 1) \ | |
65 | fprintf (Out, "%d.%d-%d", (Loc).first_line, \ | |
66 | (Loc).first_column, (Loc).last_column - 1); \ | |
67 | else \ | |
68 | fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column); \ | |
69 | } \ | |
1a715ef2 AD |
70 | } while (0) |
71 | ||
0c15323d | 72 | |
8efe435c | 73 | extern location_t empty_location; |
b1ae9233 | 74 | |
0c15323d | 75 | #endif /* !LOCATION_H_ */ |