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