MySQL 8.4.0
Source Code Documentation
parse_location.h
Go to the documentation of this file.
1/* Copyright (c) 2013, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PARSE_LOCATION_INCLUDED
25#define PARSE_LOCATION_INCLUDED
26
27#include <cstdlib> // size_t
28
29/**
30 Helper class for the MY_SQL_PARSER_LTYPE
31*/
33 const char *start = nullptr; // token start
34 const char *end = nullptr; // the 1st byte after the token
35
36 bool is_empty() const { return length() == 0; }
37 size_t length() const { return static_cast<size_t>(end - start); }
38};
39
40/**
41 Bison "location" class
42*/
44 Symbol_location cpp; // token location in the preprocessed buffer
45 Symbol_location raw; // token location in the raw buffer
46
47 bool is_empty() const { return cpp.is_empty(); }
48};
49
50/*
51 Note: MY_SQL_PARSER_LTYPE doesn't overload a default constructor (as
52 well an underlying Symbol_location). OTOH if we need a
53 zero-initialized POS, MY_SQL_PARSER_LTYPE or Symbol_location object,
54 we can simply call POS(), MY_SQL_PARSER_LTYPE() or
55 Symbol_location(): C++ does value-initialization in that case.
56*/
58
59// signal Bison that we have our own MY_SQL_PARSER_LTYPE
60#define MY_SQL_PARSER_LTYPE_IS_DECLARED 1
61
62/**
63 Bison calls this macro:
64 1. each time a rule is matched and
65 2. to compute a syntax error location.
66
67 @param [out] Current location of the whole matched rule
68 @param Rhs locations of all right hand side elements in the rule
69 @param N number of right hand side elements in the rule
70*/
71#define YYLLOC_DEFAULT(Current, Rhs, N) \
72 do \
73 if (N) { \
74 (Current).cpp.start = YYRHSLOC(Rhs, 1).cpp.start; \
75 (Current).cpp.end = YYRHSLOC(Rhs, N).cpp.end; \
76 (Current).raw.start = YYRHSLOC(Rhs, 1).raw.start; \
77 (Current).raw.end = YYRHSLOC(Rhs, N).raw.end; \
78 } else { \
79 (Current).cpp.start = (Current).cpp.end = YYRHSLOC(Rhs, 0).cpp.end; \
80 (Current).raw.start = (Current).raw.end = YYRHSLOC(Rhs, 0).raw.end; \
81 } \
82 while (0)
83
84#endif /* PARSE_LOCATION_INCLUDED */
struct MY_SQL_PARSER_LTYPE MY_SQL_PARSER_LTYPE
Definition: sql_yacc.h:1686
Bison "location" class.
Definition: parse_location.h:43
bool is_empty() const
Definition: parse_location.h:47
Symbol_location cpp
Definition: parse_location.h:44
Symbol_location raw
Definition: parse_location.h:45
Helper class for the MY_SQL_PARSER_LTYPE.
Definition: parse_location.h:32
bool is_empty() const
Definition: parse_location.h:36
const char * start
Definition: parse_location.h:33
const char * end
Definition: parse_location.h:34
size_t length() const
Definition: parse_location.h:37