]>
git.saurik.com Git - bison.git/blob - src/location.h
3 Copyright (C) 2002, 2004-2014 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
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.
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.
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/>. */
25 # include <string.h> /* strcmp */
29 /* A boundary between two characters. */
32 /* The name of the file that contains the boundary. */
35 /* If nonnegative, the (origin-1) line that contains the boundary.
36 If this is INT_MAX, the line number has overflowed.
38 Meaningless and not displayed if negative.
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
47 Meaningless and not displayed if negative.
53 /* Set the position of \a a. */
55 boundary_set (boundary
*b
, const char *f
, int l
, int c
)
62 /* Return -1, 0, 1, depending whether a is before, equal, or
65 boundary_cmp (boundary a
, boundary b
)
67 int res
= strcmp (a
.file
, b
.file
);
69 res
= a
.line
- b
.line
;
71 res
= a
.column
- b
.column
;
75 /* Return nonzero if A and B are equal boundaries. */
77 equal_boundaries (boundary a
, boundary b
)
79 return (a
.column
== b
.column
81 && UNIQSTR_EQ (a
.file
, b
.file
));
84 /* A location, that is, a region of source code. */
87 /* Boundary just before the location starts. */
90 /* Boundary just after the location ends. */
95 # define GRAM_LTYPE location
97 # define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
98 extern location
const empty_location
;
100 /* Set *LOC and adjust scanner cursor to account for token TOKEN of
102 void location_compute (location
*loc
,
103 boundary
*cur
, char const *token
, size_t size
);
105 /* Print location to file.
106 Return number of actually printed characters.
107 Warning: uses quotearg's slot 3. */
108 unsigned location_print (location loc
, FILE *out
);
110 /* Free any allocated ressources and close any open file handles that are
111 left-over by the usage of location_caret. */
112 void cleanup_caret (void);
114 /* Output to OUT the line and caret corresponding to location LOC. */
115 void location_caret (location loc
, FILE *out
);
117 /* Return -1, 0, 1, depending whether a is before, equal, or
120 location_cmp (location a
, location b
)
122 int res
= boundary_cmp (a
.start
, b
.start
);
124 res
= boundary_cmp (a
.end
, b
.end
);
128 /* LOC_STR must be formatted as 'file:line.column', it will be modified. */
129 void boundary_set_from_string (boundary
*bound
, char *loc_str
);
131 #endif /* ! defined LOCATION_H_ */