]> git.saurik.com Git - bison.git/blame - src/location.h
tests: skip C++ tests that are too demanding for some compilers
[bison.git] / src / location.h
CommitLineData
0c15323d 1/* Locations for Bison
7d424de1 2
7d6bad19 3 Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
0c15323d
AD
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
f16b0819 7 This program is free software: you can redistribute it and/or modify
0c15323d 8 it under the terms of the GNU General Public License as published by
f16b0819
PE
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
0c15323d 11
f16b0819 12 This program is distributed in the hope that it will be useful,
0c15323d
AD
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
f16b0819 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0c15323d
AD
19
20#ifndef LOCATION_H_
21# define LOCATION_H_
22
3f21a394
AD
23# include <stdbool.h>
24# include <stdio.h>
25# include <string.h> /* strcmp */
26
dca81a78
PE
27# include "uniqstr.h"
28
8f759107
PE
29/* A boundary between two characters. */
30typedef struct
0c15323d 31{
8f759107 32 /* The name of the file that contains the boundary. */
dca81a78 33 uniqstr file;
8f759107 34
92822aff
JD
35 /* If nonnegative, the (origin-1) line that contains the boundary.
36 If this is INT_MAX, the line number has overflowed.
37
38 Meaningless and not displayed if negative.
39 */
8f759107
PE
40 int line;
41
56c5eca9
AD
42 /* If nonnegative, the (origin-1) column just after the boundary.
43 This is neither a byte count, nor a character count; it is a
44 column count. If this is INT_MAX, the column number has
45 overflowed.
46
47 Meaningless and not displayed if negative.
48 */
8f759107
PE
49 int column;
50
51} boundary;
52
e9071366
AD
53/* Set the position of \a a. */
54static inline void
55boundary_set (boundary *b, const char *f, int l, int c)
56{
db06f0ce
PE
57 b->file = f;
58 b->line = l;
59 b->column = c;
e9071366
AD
60}
61
12cf133f
AD
62/* Return -1, 0, 1, depending whether a is before, equal, or
63 after b. */
64static inline int
65boundary_cmp (boundary a, boundary b)
66{
67 int res = strcmp (a.file, b.file);
68 if (!res)
69 res = a.line - b.line;
70 if (!res)
71 res = a.column - b.column;
72 return res;
73}
74
8f759107
PE
75/* Return nonzero if A and B are equal boundaries. */
76static inline bool
77equal_boundaries (boundary a, boundary b)
78{
79 return (a.column == b.column
e9690142
JD
80 && a.line == b.line
81 && UNIQSTR_EQ (a.file, b.file));
8f759107
PE
82}
83
84/* A location, that is, a region of source code. */
85typedef struct
86{
87 /* Boundary just before the location starts. */
88 boundary start;
89
90 /* Boundary just after the location ends. */
91 boundary end;
92
69b8cc09 93} location;
8f759107 94
a99ec53e 95# define GRAM_LTYPE location
0c15323d 96
a99ec53e 97# define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
69b8cc09 98extern location const empty_location;
8f759107 99
e9071366
AD
100/* Set *LOC and adjust scanner cursor to account for token TOKEN of
101 size SIZE. */
102void location_compute (location *loc,
e9690142 103 boundary *cur, char const *token, size_t size);
e9071366 104
ec6dc437
AD
105/* Print location to file.
106 Return number of actually printed characters.
107 Warning: uses quotearg's slot 3. */
b805eca7 108unsigned location_print (location loc, FILE *out);
8f759107 109
3f5d1b2c
TR
110/* Free any allocated ressources and close any open file handles that are
111 left-over by the usage of location_caret. */
112void cleanup_caret (void);
113
114/* Output to OUT the line and caret corresponding to location LOC. */
b805eca7 115void location_caret (location loc, FILE *out);
3f5d1b2c 116
12cf133f
AD
117/* Return -1, 0, 1, depending whether a is before, equal, or
118 after b. */
119static inline int
120location_cmp (location a, location b)
121{
122 int res = boundary_cmp (a.start, b.start);
123 if (!res)
124 res = boundary_cmp (a.end, b.end);
125 return res;
126}
127
45eebca4 128/* LOC_STR must be formatted as 'file:line.column', it will be modified. */
3fc65ead
JD
129void boundary_set_from_string (boundary *bound, char *loc_str);
130
8f759107 131#endif /* ! defined LOCATION_H_ */