]>
Commit | Line | Data |
---|---|---|
0c15323d | 1 | /* Locations for Bison |
580c075d JD |
2 | Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software |
3 | Foundation, Inc. | |
0c15323d AD |
4 | |
5 | This file is part of Bison, the GNU Compiler Compiler. | |
6 | ||
f16b0819 | 7 | This program is free software: you can redistribute it and/or modify |
0c15323d | 8 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
0c15323d | 11 | |
f16b0819 | 12 | This program is distributed in the hope that it will be useful, |
0c15323d AD |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
f16b0819 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0c15323d AD |
19 | |
20 | #ifndef LOCATION_H_ | |
21 | # define LOCATION_H_ | |
22 | ||
dca81a78 PE |
23 | # include "uniqstr.h" |
24 | ||
8f759107 PE |
25 | /* A boundary between two characters. */ |
26 | typedef struct | |
0c15323d | 27 | { |
8f759107 | 28 | /* The name of the file that contains the boundary. */ |
dca81a78 | 29 | uniqstr file; |
8f759107 | 30 | |
580c075d JD |
31 | /* If nonnegative, the (origin-1) line that contains the boundary. |
32 | If this is INT_MAX, the line number has overflowed. | |
33 | ||
34 | Meaningless and not displayed if negative. | |
35 | */ | |
8f759107 PE |
36 | int line; |
37 | ||
5d3a1ecb AD |
38 | /* If nonnegative, the (origin-1) column just after the boundary. |
39 | This is neither a byte count, nor a character count; it is a | |
40 | column count. If this is INT_MAX, the column number has | |
41 | overflowed. | |
42 | ||
43 | Meaningless and not displayed if negative. | |
44 | */ | |
8f759107 PE |
45 | int column; |
46 | ||
47 | } boundary; | |
48 | ||
e9071366 AD |
49 | /* Set the position of \a a. */ |
50 | static inline void | |
51 | boundary_set (boundary *b, const char *f, int l, int c) | |
52 | { | |
db06f0ce PE |
53 | b->file = f; |
54 | b->line = l; | |
55 | b->column = c; | |
e9071366 AD |
56 | } |
57 | ||
8f759107 PE |
58 | /* Return nonzero if A and B are equal boundaries. */ |
59 | static inline bool | |
60 | equal_boundaries (boundary a, boundary b) | |
61 | { | |
62 | return (a.column == b.column | |
63 | && a.line == b.line | |
dca81a78 | 64 | && UNIQSTR_EQ (a.file, b.file)); |
8f759107 PE |
65 | } |
66 | ||
67 | /* A location, that is, a region of source code. */ | |
68 | typedef struct | |
69 | { | |
70 | /* Boundary just before the location starts. */ | |
71 | boundary start; | |
72 | ||
73 | /* Boundary just after the location ends. */ | |
74 | boundary end; | |
75 | ||
69b8cc09 | 76 | } location; |
8f759107 | 77 | |
69b8cc09 | 78 | #define YYLTYPE location |
0c15323d | 79 | |
28e52c0d | 80 | #define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}} |
69b8cc09 | 81 | extern location const empty_location; |
8f759107 | 82 | |
e9071366 AD |
83 | /* Set *LOC and adjust scanner cursor to account for token TOKEN of |
84 | size SIZE. */ | |
85 | void location_compute (location *loc, | |
86 | boundary *cur, char const *token, size_t size); | |
87 | ||
6e0f8287 | 88 | void location_print (FILE *out, location loc); |
8f759107 | 89 | |
3fc65ead JD |
90 | /* LOC_STR must be formatted as `file:line.column', it will be modified. */ |
91 | void boundary_set_from_string (boundary *bound, char *loc_str); | |
92 | ||
8f759107 | 93 | #endif /* ! defined LOCATION_H_ */ |