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