summaryrefslogtreecommitdiffstats
path: root/src/btparser/location.h
blob: 0d620205cbb9a0d66cb486785079e118e2da5296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
    location.h

    Copyright (C) 2010  Red Hat, Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef BTPARSER_LOCATION_H
#define BTPARSER_LOCATION_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * A location in the backtrace file with an attached message.
 * It's used for error reporting: the line and the column points to
 * the place where a parser error occurred, and the message explains
 * what the parser expected and didn't find on that place.
 */
struct btp_location
{
    /** Starts from 1. */
    int line;
    /** Starts from 0. */
    int column;
    /**
     * Error message related to the line and column.  Do not release
     * the memory this pointer points to.
     */
    const char *message;
};

/**
 * Initializes all members of the location struct to their default
 * values.  No memory is allocated or released by this function.
 */
void
btp_location_init(struct btp_location *location);

/**
 * Adds a line and a column to specific location.
 * @note
 * If the line is not 1 (meaning the first line), the column in the
 * location structure is overwritten by the provided add_column value.
 * Otherwise the add_column value is added to the column member of the
 * location structure.
 * @param location
 * The structure to be modified. It must be a valid pointer.
 * @param add_line
 * Starts from 1. It means that if add_line is 1, the line member of the
 * location structure is not changed.
 * @param add_column
 * Starts from 0.
 */
void
btp_location_add(struct btp_location *location,
                 int add_line,
                 int add_column);

/**
 * Adds a line column pair to another line column pair.
 * @note
 * If the add_line is not 1 (meaning the frist line), the column is
 * overwritten by the provided add_column value.  Otherwise the
 * add_column value is added to the column.
 * @param add_line
 * Starts from 1. It means that if add_line is 1, the line is not
 * changed.
 * @param add_column
 * Starts from 0.
 */
void
btp_location_add_ext(int *line,
                     int *column,
                     int add_line,
                     int add_column);

/**
 * Updates the line and column of the location by moving "after" the
 * char c. If c is a newline character, the line number is increased
 * and the column is set to 0. Otherwise the column is increased by 1.
 */
void
btp_location_eat_char(struct btp_location *location,
                      char c);

/**
 * Updates the line and the column by moving "after" the char c. If c
 * is a newline character, the line number is increased and the column
 * is set to 0. Otherwise the column is increased.
 * @param line
 * Must be a valid pointer.
 * @param column
 * Must be a valid pointer.
 */
void
btp_location_eat_char_ext(int *line,
                          int *column,
                          char c);

#ifdef __cplusplus
}
#endif

#endif