]>
Commit | Line | Data |
---|---|---|
1 | /* Locations for Bison | |
2 | Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of Bison, the GNU Compiler Compiler. | |
5 | ||
6 | This program 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 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #ifndef LOCATION_H_ | |
20 | # define LOCATION_H_ | |
21 | ||
22 | # include "uniqstr.h" | |
23 | ||
24 | /* A boundary between two characters. */ | |
25 | typedef struct | |
26 | { | |
27 | /* The name of the file that contains the boundary. */ | |
28 | uniqstr file; | |
29 | ||
30 | /* The (origin-1) line that contains the boundary. | |
31 | If this is INT_MAX, the line number has overflowed. */ | |
32 | int line; | |
33 | ||
34 | /* If nonnegative, the (origin-1) column just after the boundary. | |
35 | This is neither a byte count, nor a character count; it is a | |
36 | column count. If this is INT_MAX, the column number has | |
37 | overflowed. | |
38 | ||
39 | Meaningless and not displayed if negative. | |
40 | */ | |
41 | int column; | |
42 | ||
43 | } boundary; | |
44 | ||
45 | /* Set the position of \a a. */ | |
46 | static inline void | |
47 | boundary_set (boundary *b, const char *f, int l, int c) | |
48 | { | |
49 | b->file = f; | |
50 | b->line = l; | |
51 | b->column = c; | |
52 | } | |
53 | ||
54 | /* Return nonzero if A and B are equal boundaries. */ | |
55 | static inline bool | |
56 | equal_boundaries (boundary a, boundary b) | |
57 | { | |
58 | return (a.column == b.column | |
59 | && a.line == b.line | |
60 | && UNIQSTR_EQ (a.file, b.file)); | |
61 | } | |
62 | ||
63 | /* A location, that is, a region of source code. */ | |
64 | typedef struct | |
65 | { | |
66 | /* Boundary just before the location starts. */ | |
67 | boundary start; | |
68 | ||
69 | /* Boundary just after the location ends. */ | |
70 | boundary end; | |
71 | ||
72 | } location; | |
73 | ||
74 | #define YYLTYPE location | |
75 | ||
76 | #define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}} | |
77 | extern location const empty_location; | |
78 | ||
79 | /* Set *LOC and adjust scanner cursor to account for token TOKEN of | |
80 | size SIZE. */ | |
81 | void location_compute (location *loc, | |
82 | boundary *cur, char const *token, size_t size); | |
83 | ||
84 | void location_print (FILE *out, location loc); | |
85 | ||
86 | /* LOC_STR must be formatted as `file:line.column', it will be modified. */ | |
87 | void boundary_set_from_string (boundary *bound, char *loc_str); | |
88 | ||
89 | #endif /* ! defined LOCATION_H_ */ |