]>
Commit | Line | Data |
---|---|---|
0c15323d | 1 | /* Locations for Bison |
6e0f8287 | 2 | Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. |
0c15323d AD |
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 | |
0fb669f9 PE |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. */ | |
0c15323d AD |
20 | |
21 | #ifndef LOCATION_H_ | |
22 | # define LOCATION_H_ | |
23 | ||
0c8e079f | 24 | # include <stdbool.h> |
dca81a78 PE |
25 | # include "uniqstr.h" |
26 | ||
8f759107 PE |
27 | /* A boundary between two characters. */ |
28 | typedef struct | |
0c15323d | 29 | { |
8f759107 | 30 | /* The name of the file that contains the boundary. */ |
dca81a78 | 31 | uniqstr file; |
8f759107 | 32 | |
4517da37 PE |
33 | /* The (origin-1) line that contains the boundary. |
34 | If this is INT_MAX, the line number has overflowed. */ | |
8f759107 PE |
35 | int line; |
36 | ||
37 | /* The (origin-1) column just after the boundary. This is neither a | |
4517da37 PE |
38 | byte count, nor a character count; it is a column count. |
39 | If this is INT_MAX, the column number has overflowed. */ | |
8f759107 PE |
40 | int column; |
41 | ||
42 | } boundary; | |
43 | ||
e9071366 AD |
44 | /* Set the position of \a a. */ |
45 | static inline void | |
46 | boundary_set (boundary *b, const char *f, int l, int c) | |
47 | { | |
48 | b->file = f; | |
49 | b->line = l; | |
50 | b->column = c; | |
51 | } | |
52 | ||
8f759107 PE |
53 | /* Return nonzero if A and B are equal boundaries. */ |
54 | static inline bool | |
55 | equal_boundaries (boundary a, boundary b) | |
56 | { | |
57 | return (a.column == b.column | |
58 | && a.line == b.line | |
dca81a78 | 59 | && UNIQSTR_EQ (a.file, b.file)); |
8f759107 PE |
60 | } |
61 | ||
62 | /* A location, that is, a region of source code. */ | |
63 | typedef struct | |
64 | { | |
65 | /* Boundary just before the location starts. */ | |
66 | boundary start; | |
67 | ||
68 | /* Boundary just after the location ends. */ | |
69 | boundary end; | |
70 | ||
69b8cc09 | 71 | } location; |
8f759107 | 72 | |
69b8cc09 | 73 | #define YYLTYPE location |
0c15323d | 74 | |
69b8cc09 | 75 | extern location const empty_location; |
8f759107 | 76 | |
e9071366 AD |
77 | /* Set *LOC and adjust scanner cursor to account for token TOKEN of |
78 | size SIZE. */ | |
79 | void location_compute (location *loc, | |
80 | boundary *cur, char const *token, size_t size); | |
81 | ||
6e0f8287 | 82 | void location_print (FILE *out, location loc); |
8f759107 PE |
83 | |
84 | #endif /* ! defined LOCATION_H_ */ |