]> git.saurik.com Git - bison.git/blame - src/location.h
bench: More use of the verbosity level.
[bison.git] / src / location.h
CommitLineData
0c15323d 1/* Locations for Bison
28e52c0d 2 Copyright (C) 2002, 2004, 2005, 2006, 2007 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. */
25typedef struct
0c15323d 26{
8f759107 27 /* The name of the file that contains the boundary. */
dca81a78 28 uniqstr file;
8f759107 29
4517da37
PE
30 /* The (origin-1) line that contains the boundary.
31 If this is INT_MAX, the line number has overflowed. */
8f759107
PE
32 int line;
33
34 /* The (origin-1) column just after the boundary. This is neither a
4517da37
PE
35 byte count, nor a character count; it is a column count.
36 If this is INT_MAX, the column number has overflowed. */
8f759107
PE
37 int column;
38
39} boundary;
40
e9071366
AD
41/* Set the position of \a a. */
42static inline void
43boundary_set (boundary *b, const char *f, int l, int c)
44{
db06f0ce
PE
45 b->file = f;
46 b->line = l;
47 b->column = c;
e9071366
AD
48}
49
8f759107
PE
50/* Return nonzero if A and B are equal boundaries. */
51static inline bool
52equal_boundaries (boundary a, boundary b)
53{
54 return (a.column == b.column
55 && a.line == b.line
dca81a78 56 && UNIQSTR_EQ (a.file, b.file));
8f759107
PE
57}
58
59/* A location, that is, a region of source code. */
60typedef struct
61{
62 /* Boundary just before the location starts. */
63 boundary start;
64
65 /* Boundary just after the location ends. */
66 boundary end;
67
69b8cc09 68} location;
8f759107 69
69b8cc09 70#define YYLTYPE location
0c15323d 71
28e52c0d 72#define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
69b8cc09 73extern location const empty_location;
8f759107 74
e9071366
AD
75/* Set *LOC and adjust scanner cursor to account for token TOKEN of
76 size SIZE. */
77void location_compute (location *loc,
78 boundary *cur, char const *token, size_t size);
79
6e0f8287 80void location_print (FILE *out, location loc);
8f759107 81
3fc65ead
JD
82/* LOC_STR must be formatted as `file:line.column', it will be modified. */
83void boundary_set_from_string (boundary *bound, char *loc_str);
84
8f759107 85#endif /* ! defined LOCATION_H_ */