1 /* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 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 27 /** 28 Helper class for the YYLTYPE 29 */ 30 struct Symbol_location 31 { 32 const char *start; // token start 33 const char *end; // the 1st byte after the token 34 is_emptySymbol_location35 bool is_empty() const { return length() == 0; } lengthSymbol_location36 size_t length() const { return static_cast<size_t>(end - start); } 37 }; 38 39 40 /** 41 Bison "location" class 42 */ 43 typedef struct YYLTYPE 44 { 45 Symbol_location cpp; // token location in the preprocessed buffer 46 Symbol_location raw; // token location in the raw buffer 47 is_emptyYYLTYPE48 bool is_empty() const { return cpp.is_empty(); } 49 50 } YYLTYPE; 51 52 #define YYLTYPE_IS_DECLARED 1 // signal Bison that we have our own YYLTYPE 53 54 /** 55 Bison calls this macro: 56 1. each time a rule is matched and 57 2. to compute a syntax error location. 58 59 @param Current [out] location of the whole matched rule 60 @param Rhs locations of all right hand side elements in the rule 61 @param N number of right hand side elements in the rule 62 */ 63 #define YYLLOC_DEFAULT(Current, Rhs, N) \ 64 do \ 65 if (N) \ 66 { \ 67 (Current).cpp.start= YYRHSLOC(Rhs, 1).cpp.start; \ 68 (Current).cpp.end= YYRHSLOC(Rhs, N).cpp.end; \ 69 (Current).raw.start= YYRHSLOC(Rhs, 1).raw.start; \ 70 (Current).raw.end= YYRHSLOC(Rhs, N).raw.end; \ 71 } \ 72 else \ 73 { \ 74 (Current).cpp.start= \ 75 (Current).cpp.end= YYRHSLOC(Rhs, 0).cpp.end; \ 76 (Current).raw.start= \ 77 (Current).raw.end= YYRHSLOC(Rhs, 0).raw.end; \ 78 } \ 79 while (0) 80 81 #endif /* PARSE_LOCATION_INCLUDED */ 82