]>
Commit | Line | Data |
---|---|---|
0c15323d | 1 | /* Locations for Bison |
1462fcee | 2 | Copyright (C) 2002, 2004-2010 Free Software Foundation, Inc. |
0c15323d AD |
3 | |
4 | This file is part of Bison, the GNU Compiler Compiler. | |
5 | ||
f16b0819 | 6 | This program is free software: you can redistribute it and/or modify |
0c15323d | 7 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. | |
0c15323d | 10 | |
f16b0819 | 11 | This program is distributed in the hope that it will be useful, |
0c15323d AD |
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 | |
f16b0819 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0c15323d AD |
18 | |
19 | #ifndef LOCATION_H_ | |
20 | # define LOCATION_H_ | |
21 | ||
dca81a78 PE |
22 | # include "uniqstr.h" |
23 | ||
8f759107 PE |
24 | /* A boundary between two characters. */ |
25 | typedef struct | |
0c15323d | 26 | { |
8f759107 | 27 | /* The name of the file that contains the boundary. */ |
dca81a78 | 28 | uniqstr file; |
8f759107 | 29 | |
580c075d JD |
30 | /* If nonnegative, the (origin-1) line that contains the boundary. |
31 | If this is INT_MAX, the line number has overflowed. | |
32 | ||
33 | Meaningless and not displayed if negative. | |
34 | */ | |
8f759107 PE |
35 | int line; |
36 | ||
5d3a1ecb AD |
37 | /* If nonnegative, the (origin-1) column just after the boundary. |
38 | This is neither a byte count, nor a character count; it is a | |
39 | column count. If this is INT_MAX, the column number has | |
40 | overflowed. | |
41 | ||
42 | Meaningless and not displayed if negative. | |
43 | */ | |
8f759107 PE |
44 | int column; |
45 | ||
46 | } boundary; | |
47 | ||
e9071366 AD |
48 | /* Set the position of \a a. */ |
49 | static inline void | |
50 | boundary_set (boundary *b, const char *f, int l, int c) | |
51 | { | |
db06f0ce PE |
52 | b->file = f; |
53 | b->line = l; | |
54 | b->column = c; | |
e9071366 AD |
55 | } |
56 | ||
95d176ff AD |
57 | /* Return -1, 0, 1, depending whether a is before, equal, or |
58 | after b. */ | |
59 | static inline int | |
60 | boundary_cmp (boundary a, boundary b) | |
61 | { | |
62 | int res = strcmp (a.file, b.file); | |
63 | if (!res) | |
64 | res = a.line - b.line; | |
65 | if (!res) | |
66 | res = a.column - b.column; | |
67 | return res; | |
68 | } | |
69 | ||
8f759107 PE |
70 | /* Return nonzero if A and B are equal boundaries. */ |
71 | static inline bool | |
72 | equal_boundaries (boundary a, boundary b) | |
73 | { | |
74 | return (a.column == b.column | |
75 | && a.line == b.line | |
dca81a78 | 76 | && UNIQSTR_EQ (a.file, b.file)); |
8f759107 PE |
77 | } |
78 | ||
79 | /* A location, that is, a region of source code. */ | |
80 | typedef struct | |
81 | { | |
82 | /* Boundary just before the location starts. */ | |
83 | boundary start; | |
84 | ||
85 | /* Boundary just after the location ends. */ | |
86 | boundary end; | |
87 | ||
69b8cc09 | 88 | } location; |
8f759107 | 89 | |
69b8cc09 | 90 | #define YYLTYPE location |
0c15323d | 91 | |
28e52c0d | 92 | #define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}} |
69b8cc09 | 93 | extern location const empty_location; |
8f759107 | 94 | |
e9071366 AD |
95 | /* Set *LOC and adjust scanner cursor to account for token TOKEN of |
96 | size SIZE. */ | |
97 | void location_compute (location *loc, | |
98 | boundary *cur, char const *token, size_t size); | |
99 | ||
348f5608 AR |
100 | /* Print location to file. Return number of actually printed |
101 | characters. */ | |
102 | unsigned location_print (FILE *out, location loc); | |
8f759107 | 103 | |
95d176ff AD |
104 | /* Return -1, 0, 1, depending whether a is before, equal, or |
105 | after b. */ | |
106 | static inline int | |
107 | location_cmp (location a, location b) | |
108 | { | |
109 | int res = boundary_cmp (a.start, b.start); | |
110 | if (!res) | |
111 | res = boundary_cmp (a.end, b.end); | |
112 | return res; | |
113 | } | |
114 | ||
3fc65ead JD |
115 | /* LOC_STR must be formatted as `file:line.column', it will be modified. */ |
116 | void boundary_set_from_string (boundary *bound, char *loc_str); | |
117 | ||
8f759107 | 118 | #endif /* ! defined LOCATION_H_ */ |