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