Path: blob/main_old/src/compiler/preprocessor/preprocessor_tab_autogen.cpp
1693 views
/* A Bison parser, made by GNU Bison 3.3.2. */12/* Bison implementation for Yacc-like parsers in C34Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation,5Inc.67This program is free software: you can redistribute it and/or modify8it under the terms of the GNU General Public License as published by9the Free Software Foundation, either version 3 of the License, or10(at your option) any later version.1112This program is distributed in the hope that it will be useful,13but WITHOUT ANY WARRANTY; without even the implied warranty of14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with this program. If not, see <http://www.gnu.org/licenses/>. */1920/* As a special exception, you may create a larger work that contains21part or all of the Bison parser skeleton and distribute that work22under terms of your choice, so long as that work isn't itself a23parser generator using the skeleton or a modified version thereof24as a parser skeleton. Alternatively, if you modify or redistribute25the parser skeleton itself, you may (at your option) remove this26special exception, which will cause the skeleton and the resulting27Bison output files to be licensed under the GNU General Public28License without this special exception.2930This special exception was added by the Free Software Foundation in31version 2.2 of Bison. */3233/* C LALR(1) parser skeleton written by Richard Stallman, by34simplifying the original so-called "semantic" parser. */3536/* All symbols defined below should begin with yy or YY, to avoid37infringing on user name space. This should be done even for local38variables, as they might otherwise be expanded by user macros.39There are some unavoidable exceptions within include files to40define necessary library symbols; they are noted "INFRINGES ON41USER NAME SPACE" below. */4243/* Undocumented macros, especially those whose name start with YY_,44are private implementation details. Do not rely on them. */4546/* Identify Bison output. */47#define YYBISON 14849/* Bison version. */50#define YYBISON_VERSION "3.3.2"5152/* Skeleton name. */53#define YYSKELETON_NAME "yacc.c"5455/* Pure parsers. */56#define YYPURE 15758/* Push parsers. */59#define YYPUSH 06061/* Pull parsers. */62#define YYPULL 16364/* Substitute the variable and function names. */65#define yyparse ppparse66#define yylex pplex67#define yyerror pperror68#define yydebug ppdebug69#define yynerrs ppnerrs7071/* First part of user prologue. */7273// GENERATED FILE - DO NOT EDIT.74// Generated by generate_parser.py from preprocessor.y75//76// Copyright 2019 The ANGLE Project Authors. All rights reserved.77// Use of this source code is governed by a BSD-style license that can be78// found in the LICENSE file.79//80// preprocessor.y:81// Parser for the OpenGL shading language preprocessor.8283#if defined(__GNUC__)84// Triggered by the auto-generated pplval variable.85# if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))86# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"87# else88# pragma GCC diagnostic ignored "-Wuninitialized"89# endif90#elif defined(_MSC_VER)91# pragma warning(disable : 4065 4244 4701 4702)92#endif93#if defined(__clang__)94# pragma clang diagnostic ignored "-Wunreachable-code"95#endif9697#include "ExpressionParser.h"9899#if defined(_MSC_VER)100# include <malloc.h>101#else102# include <stdlib.h>103#endif104105#include <stdint.h>106#include <cassert>107#include <sstream>108109#include "DiagnosticsBase.h"110#include "Lexer.h"111#include "Token.h"112#include "common/mathutil.h"113114typedef int32_t YYSTYPE;115typedef uint32_t UNSIGNED_TYPE;116117#define YYENABLE_NLS 0118#define YYLTYPE_IS_TRIVIAL 1119#define YYSTYPE_IS_TRIVIAL 1120#define YYSTYPE_IS_DECLARED 1121122namespace123{124struct Context125{126angle::pp::Diagnostics *diagnostics;127angle::pp::Lexer *lexer;128angle::pp::Token *token;129int *result;130bool parsePresetToken;131132angle::pp::ExpressionParser::ErrorSettings errorSettings;133bool *valid;134135void startIgnoreErrors() { ++ignoreErrors; }136void endIgnoreErrors() { --ignoreErrors; }137138bool isIgnoringErrors() { return ignoreErrors > 0; }139140int ignoreErrors;141};142} // namespace143144static int yylex(YYSTYPE *lvalp, Context *context);145static void yyerror(Context *context, const char *reason);146147#ifndef YY_NULLPTR148# if defined __cplusplus149# if 201103L <= __cplusplus150# define YY_NULLPTR nullptr151# else152# define YY_NULLPTR 0153# endif154# else155# define YY_NULLPTR ((void *)0)156# endif157#endif158159/* Enabling verbose error messages. */160#ifdef YYERROR_VERBOSE161# undef YYERROR_VERBOSE162# define YYERROR_VERBOSE 1163#else164# define YYERROR_VERBOSE 0165#endif166167/* Debug traces. */168#ifndef YYDEBUG169# define YYDEBUG 0170#endif171#if YYDEBUG172extern int ppdebug;173#endif174175/* Token type. */176#ifndef YYTOKENTYPE177# define YYTOKENTYPE178enum yytokentype179{180TOK_CONST_INT = 258,181TOK_IDENTIFIER = 259,182TOK_OP_OR = 260,183TOK_OP_AND = 261,184TOK_OP_EQ = 262,185TOK_OP_NE = 263,186TOK_OP_LE = 264,187TOK_OP_GE = 265,188TOK_OP_LEFT = 266,189TOK_OP_RIGHT = 267,190TOK_UNARY = 268191};192#endif193194/* Value type. */195#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED196typedef int YYSTYPE;197# define YYSTYPE_IS_TRIVIAL 1198# define YYSTYPE_IS_DECLARED 1199#endif200201int ppparse(Context *context);202203#ifdef short204# undef short205#endif206207#ifdef YYTYPE_UINT8208typedef YYTYPE_UINT8 yytype_uint8;209#else210typedef unsigned char yytype_uint8;211#endif212213#ifdef YYTYPE_INT8214typedef YYTYPE_INT8 yytype_int8;215#else216typedef signed char yytype_int8;217#endif218219#ifdef YYTYPE_UINT16220typedef YYTYPE_UINT16 yytype_uint16;221#else222typedef unsigned short yytype_uint16;223#endif224225#ifdef YYTYPE_INT16226typedef YYTYPE_INT16 yytype_int16;227#else228typedef short yytype_int16;229#endif230231#ifndef YYSIZE_T232# ifdef __SIZE_TYPE__233# define YYSIZE_T __SIZE_TYPE__234# elif defined size_t235# define YYSIZE_T size_t236# elif !defined YYSIZE_T237# include <stddef.h> /* INFRINGES ON USER NAME SPACE */238# define YYSIZE_T size_t239# else240# define YYSIZE_T unsigned241# endif242#endif243244#define YYSIZE_MAXIMUM ((YYSIZE_T)-1)245246#ifndef YY_247# if defined YYENABLE_NLS && YYENABLE_NLS248# if ENABLE_NLS249# include <libintl.h> /* INFRINGES ON USER NAME SPACE */250# define YY_(Msgid) dgettext("bison-runtime", Msgid)251# endif252# endif253# ifndef YY_254# define YY_(Msgid) Msgid255# endif256#endif257258#ifndef YY_ATTRIBUTE259# if (defined __GNUC__ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \260defined __SUNPRO_C && 0x5110 <= __SUNPRO_C261# define YY_ATTRIBUTE(Spec) __attribute__(Spec)262# else263# define YY_ATTRIBUTE(Spec) /* empty */264# endif265#endif266267#ifndef YY_ATTRIBUTE_PURE268# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__))269#endif270271#ifndef YY_ATTRIBUTE_UNUSED272# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__))273#endif274275/* Suppress unused-variable warnings by "using" E. */276#if !defined lint || defined __GNUC__277# define YYUSE(E) ((void)(E))278#else279# define YYUSE(E) /* empty */280#endif281282#if defined __GNUC__ && !defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__283/* Suppress an incorrect diagnostic about yylval being uninitialized. */284# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \285_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \286_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")287# define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop")288#else289# define YY_INITIAL_VALUE(Value) Value290#endif291#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN292# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN293# define YY_IGNORE_MAYBE_UNINITIALIZED_END294#endif295#ifndef YY_INITIAL_VALUE296# define YY_INITIAL_VALUE(Value) /* Nothing. */297#endif298299#if !defined yyoverflow || YYERROR_VERBOSE300301/* The parser invokes alloca or malloc; define the necessary symbols. */302303# ifdef YYSTACK_USE_ALLOCA304# if YYSTACK_USE_ALLOCA305# ifdef __GNUC__306# define YYSTACK_ALLOC __builtin_alloca307# elif defined __BUILTIN_VA_ARG_INCR308# include <alloca.h> /* INFRINGES ON USER NAME SPACE */309# elif defined _AIX310# define YYSTACK_ALLOC __alloca311# elif defined _MSC_VER312# include <malloc.h> /* INFRINGES ON USER NAME SPACE */313# define alloca _alloca314# else315# define YYSTACK_ALLOC alloca316# if !defined _ALLOCA_H && !defined EXIT_SUCCESS317# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */318/* Use EXIT_SUCCESS as a witness for stdlib.h. */319# ifndef EXIT_SUCCESS320# define EXIT_SUCCESS 0321# endif322# endif323# endif324# endif325# endif326327# ifdef YYSTACK_ALLOC328/* Pacify GCC's 'empty if-body' warning. */329# define YYSTACK_FREE(Ptr) \330do \331{ /* empty */ \332; \333} while (0)334# ifndef YYSTACK_ALLOC_MAXIMUM335/* The OS might guarantee only one guard page at the bottom of the stack,336and a page size can be as small as 4096 bytes. So we cannot safely337invoke alloca (N) if N exceeds 4096. Use a slightly smaller number338to allow for a few compiler-allocated temporary stack slots. */339# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */340# endif341# else342# define YYSTACK_ALLOC YYMALLOC343# define YYSTACK_FREE YYFREE344# ifndef YYSTACK_ALLOC_MAXIMUM345# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM346# endif347# if (defined __cplusplus && !defined EXIT_SUCCESS && \348!((defined YYMALLOC || defined malloc) && (defined YYFREE || defined free)))349# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */350# ifndef EXIT_SUCCESS351# define EXIT_SUCCESS 0352# endif353# endif354# ifndef YYMALLOC355# define YYMALLOC malloc356# if !defined malloc && !defined EXIT_SUCCESS357void *malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */358# endif359# endif360# ifndef YYFREE361# define YYFREE free362# if !defined free && !defined EXIT_SUCCESS363void free(void *); /* INFRINGES ON USER NAME SPACE */364# endif365# endif366# endif367#endif /* ! defined yyoverflow || YYERROR_VERBOSE */368369#if (!defined yyoverflow && \370(!defined __cplusplus || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))371372/* A type that is properly aligned for any stack member. */373union yyalloc374{375yytype_int16 yyss_alloc;376YYSTYPE yyvs_alloc;377};378379/* The size of the maximum gap between one aligned stack and the next. */380# define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1)381382/* The size of an array large to enough to hold all stacks, each with383N elements. */384# define YYSTACK_BYTES(N) ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM)385386# define YYCOPY_NEEDED 1387388/* Relocate STACK from its old location to the new one. The389local variables YYSIZE and YYSTACKSIZE give the old and new number of390elements in the stack, and YYPTR gives the new location of the391stack. Advance YYPTR to a properly aligned location for the next392stack. */393# define YYSTACK_RELOCATE(Stack_alloc, Stack) \394do \395{ \396YYSIZE_T yynewbytes; \397YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \398Stack = &yyptr->Stack_alloc; \399yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \400yyptr += yynewbytes / sizeof(*yyptr); \401} while (0)402403#endif404405#if defined YYCOPY_NEEDED && YYCOPY_NEEDED406/* Copy COUNT objects from SRC to DST. The source and destination do407not overlap. */408# ifndef YYCOPY409# if defined __GNUC__ && 1 < __GNUC__410# define YYCOPY(Dst, Src, Count) __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src)))411# else412# define YYCOPY(Dst, Src, Count) \413do \414{ \415YYSIZE_T yyi; \416for (yyi = 0; yyi < (Count); yyi++) \417(Dst)[yyi] = (Src)[yyi]; \418} while (0)419# endif420# endif421#endif /* !YYCOPY_NEEDED */422423/* YYFINAL -- State number of the termination state. */424#define YYFINAL 15425/* YYLAST -- Last index in YYTABLE. */426#define YYLAST 176427428/* YYNTOKENS -- Number of terminals. */429#define YYNTOKENS 28430/* YYNNTS -- Number of nonterminals. */431#define YYNNTS 5432/* YYNRULES -- Number of rules. */433#define YYNRULES 29434/* YYNSTATES -- Number of states. */435#define YYNSTATES 55436437#define YYUNDEFTOK 2438#define YYMAXUTOK 268439440/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM441as returned by yylex, with out-of-bounds checking. */442#define YYTRANSLATE(YYX) ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)443444/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM445as returned by yylex. */446static const yytype_uint8 yytranslate[] = {4470, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4482, 2, 2, 2, 2, 2, 24, 2, 2, 2, 22, 9, 2, 26, 27, 20, 18, 2, 19, 2, 21, 2, 2, 2, 2, 2, 2,4492, 2, 2, 2, 2, 2, 12, 2, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4502, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4512, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 2, 25, 2, 2, 2, 2, 2, 2, 2, 2,4522, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4532, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4542, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4552, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,4562, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 10, 11, 14, 15, 16, 17, 23};457458#if YYDEBUG459/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */460static const yytype_uint16 yyrline[] = {0, 113, 113, 120, 121, 132, 132, 153, 153, 174,461177, 180, 183, 186, 189, 192, 195, 198, 201, 226,462248, 251, 254, 280, 307, 310, 313, 316, 328, 331};463#endif464465#if YYDEBUG || YYERROR_VERBOSE || 0466/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.467First, the terminals, then, starting at YYNTOKENS, nonterminals. */468static const char *const yytname[] = {469"$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",470"TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'",471"TOK_OP_EQ", "TOK_OP_NE", "'<'", "'>'", "TOK_OP_LE",472"TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT", "'+'", "'-'",473"'*'", "'/'", "'%'", "TOK_UNARY", "'!'",474"'~'", "'('", "')'", "$accept", "input",475"expression", "$@1", "$@2", YY_NULLPTR};476#endif477478#ifdef YYPRINT479/* YYTOKNUM[NUM] -- (External) token number corresponding to the480(internal) symbol number NUM (which must be that of a token). */481static const yytype_uint16 yytoknum[] = {0, 256, 257, 258, 259, 260, 261, 124, 94, 38,482262, 263, 60, 62, 264, 265, 266, 267, 43, 45,48342, 47, 37, 268, 33, 126, 40, 41};484#endif485486#define YYPACT_NINF -12487488#define yypact_value_is_default(Yystate) (!!((Yystate) == (-12)))489490#define YYTABLE_NINF -1491492#define yytable_value_is_error(Yytable_value) 0493494/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing495STATE-NUM. */496static const yytype_int16 yypact[] = {49731, -12, -12, 31, 31, 31, 31, 31, 51, 76, -12, -12, -12, -12, 53, -12, -12, -12, 31,49831, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, -12, 31, 31, 124,499138, 26, 149, 149, -11, -11, -11, -11, 154, 154, -8, -8, -12, -12, -12, 93, 109};500501/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.502Performed when YYTABLE does not specify something else to do. Zero503means the default is an error. */504static const yytype_uint8 yydefact[] = {0, 3, 4, 0, 0, 0, 0, 0, 0, 2, 28, 27, 25, 26,5050, 1, 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,5060, 0, 0, 0, 0, 0, 29, 0, 0, 9, 10, 11, 13, 12,50717, 16, 15, 14, 19, 18, 21, 20, 24, 23, 22, 6, 8};508509/* YYPGOTO[NTERM-NUM]. */510static const yytype_int8 yypgoto[] = {-12, -12, -3, -12, -12};511512/* YYDEFGOTO[NTERM-NUM]. */513static const yytype_int8 yydefgoto[] = {-1, 8, 9, 35, 36};514515/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If516positive, shift that token. If negative, reduce the rule whose517number is the opposite. If YYTABLE_NINF, syntax error. */518static const yytype_uint8 yytable[] = {51910, 11, 12, 13, 14, 27, 28, 29, 30, 31, 32, 33, 31, 32, 33, 37, 38, 39, 40, 41, 42, 43, 44,52045, 46, 47, 48, 49, 50, 51, 52, 0, 53, 54, 1, 2, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,52131, 32, 33, 3, 4, 15, 0, 0, 0, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,52227, 28, 29, 30, 31, 32, 33, 0, 0, 0, 0, 34, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,52327, 28, 29, 30, 31, 32, 33, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,52433, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 19, 20, 21, 22, 23, 24,52525, 26, 27, 28, 29, 30, 31, 32, 33, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,52623, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 29, 30, 31, 32, 33};527528static const yytype_int8 yycheck[] = {5293, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 20, 21, 22, 18, 19, 20, 21, 22, 23, 24, 25,53026, 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, 3, 4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,53120, 21, 22, 18, 19, 0, -1, -1, -1, 24, 25, 26, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,53216, 17, 18, 19, 20, 21, 22, -1, -1, -1, -1, 27, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,53316, 17, 18, 19, 20, 21, 22, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,53422, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 8, 9, 10, 11, 12, 13,53514, 15, 16, 17, 18, 19, 20, 21, 22, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,53612, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 18, 19, 20, 21, 22};537538/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing539symbol of state STATE-NUM. */540static const yytype_uint8 yystos[] = {0, 3, 4, 18, 19, 24, 25, 26, 29, 30, 30, 30, 30, 30,54130, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,54217, 18, 19, 20, 21, 22, 27, 31, 32, 30, 30, 30, 30, 30,54330, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30};544545/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */546static const yytype_uint8 yyr1[] = {0, 28, 29, 30, 30, 31, 30, 32, 30, 30, 30, 30, 30, 30, 30,54730, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30};548549/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */550static const yytype_uint8 yyr2[] = {0, 2, 1, 1, 1, 0, 4, 0, 4, 3, 3, 3, 3, 3, 3,5513, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 3};552553#define yyerrok (yyerrstatus = 0)554#define yyclearin (yychar = YYEMPTY)555#define YYEMPTY (-2)556#define YYEOF 0557558#define YYACCEPT goto yyacceptlab559#define YYABORT goto yyabortlab560#define YYERROR goto yyerrorlab561562#define YYRECOVERING() (!!yyerrstatus)563564#define YYBACKUP(Token, Value) \565do \566if (yychar == YYEMPTY) \567{ \568yychar = (Token); \569yylval = (Value); \570YYPOPSTACK(yylen); \571yystate = *yyssp; \572goto yybackup; \573} \574else \575{ \576yyerror(context, YY_("syntax error: cannot back up")); \577YYERROR; \578} \579while (0)580581/* Error token number */582#define YYTERROR 1583#define YYERRCODE 256584585/* Enable debugging if requested. */586#if YYDEBUG587588# ifndef YYFPRINTF589# include <stdio.h> /* INFRINGES ON USER NAME SPACE */590# define YYFPRINTF fprintf591# endif592593# define YYDPRINTF(Args) \594do \595{ \596if (yydebug) \597YYFPRINTF Args; \598} while (0)599600/* This macro is provided for backward compatibility. */601# ifndef YY_LOCATION_PRINT602# define YY_LOCATION_PRINT(File, Loc) ((void)0)603# endif604605# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \606do \607{ \608if (yydebug) \609{ \610YYFPRINTF(stderr, "%s ", Title); \611yy_symbol_print(stderr, Type, Value, context); \612YYFPRINTF(stderr, "\n"); \613} \614} while (0)615616/*-----------------------------------.617| Print this symbol's value on YYO. |618`-----------------------------------*/619620static void yy_symbol_value_print(FILE *yyo,621int yytype,622YYSTYPE const *const yyvaluep,623Context *context)624{625FILE *yyoutput = yyo;626YYUSE(yyoutput);627YYUSE(context);628if (!yyvaluep)629return;630# ifdef YYPRINT631if (yytype < YYNTOKENS)632YYPRINT(yyo, yytoknum[yytype], *yyvaluep);633# endif634YYUSE(yytype);635}636637/*---------------------------.638| Print this symbol on YYO. |639`---------------------------*/640641static void yy_symbol_print(FILE *yyo, int yytype, YYSTYPE const *const yyvaluep, Context *context)642{643YYFPRINTF(yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);644645yy_symbol_value_print(yyo, yytype, yyvaluep, context);646YYFPRINTF(yyo, ")");647}648649/*------------------------------------------------------------------.650| yy_stack_print -- Print the state stack from its BOTTOM up to its |651| TOP (included). |652`------------------------------------------------------------------*/653654static void yy_stack_print(yytype_int16 *yybottom, yytype_int16 *yytop)655{656YYFPRINTF(stderr, "Stack now");657for (; yybottom <= yytop; yybottom++)658{659int yybot = *yybottom;660YYFPRINTF(stderr, " %d", yybot);661}662YYFPRINTF(stderr, "\n");663}664665# define YY_STACK_PRINT(Bottom, Top) \666do \667{ \668if (yydebug) \669yy_stack_print((Bottom), (Top)); \670} while (0)671672/*------------------------------------------------.673| Report that the YYRULE is going to be reduced. |674`------------------------------------------------*/675676static void yy_reduce_print(yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, Context *context)677{678unsigned long yylno = yyrline[yyrule];679int yynrhs = yyr2[yyrule];680int yyi;681YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno);682/* The symbols being reduced. */683for (yyi = 0; yyi < yynrhs; yyi++)684{685YYFPRINTF(stderr, " $%d = ", yyi + 1);686yy_symbol_print(stderr, yystos[yyssp[yyi + 1 - yynrhs]], &yyvsp[(yyi + 1) - (yynrhs)],687context);688YYFPRINTF(stderr, "\n");689}690}691692# define YY_REDUCE_PRINT(Rule) \693do \694{ \695if (yydebug) \696yy_reduce_print(yyssp, yyvsp, Rule, context); \697} while (0)698699/* Nonzero means print parse trace. It is left uninitialized so that700multiple parsers can coexist. */701int yydebug;702#else /* !YYDEBUG */703# define YYDPRINTF(Args)704# define YY_SYMBOL_PRINT(Title, Type, Value, Location)705# define YY_STACK_PRINT(Bottom, Top)706# define YY_REDUCE_PRINT(Rule)707#endif /* !YYDEBUG */708709/* YYINITDEPTH -- initial size of the parser's stacks. */710#ifndef YYINITDEPTH711# define YYINITDEPTH 200712#endif713714/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only715if the built-in stack extension method is used).716717Do not make this value too large; the results are undefined if718YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)719evaluated with infinite-precision integer arithmetic. */720721#ifndef YYMAXDEPTH722# define YYMAXDEPTH 10000723#endif724725#if YYERROR_VERBOSE726727# ifndef yystrlen728# if defined __GLIBC__ && defined _STRING_H729# define yystrlen strlen730# else731/* Return the length of YYSTR. */732static YYSIZE_T yystrlen(const char *yystr)733{734YYSIZE_T yylen;735for (yylen = 0; yystr[yylen]; yylen++)736continue;737return yylen;738}739# endif740# endif741742# ifndef yystpcpy743# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE744# define yystpcpy stpcpy745# else746/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in747YYDEST. */748static char *yystpcpy(char *yydest, const char *yysrc)749{750char *yyd = yydest;751const char *yys = yysrc;752753while ((*yyd++ = *yys++) != '\0')754continue;755756return yyd - 1;757}758# endif759# endif760761# ifndef yytnamerr762/* Copy to YYRES the contents of YYSTR after stripping away unnecessary763quotes and backslashes, so that it's suitable for yyerror. The764heuristic is that double-quoting is unnecessary unless the string765contains an apostrophe, a comma, or backslash (other than766backslash-backslash). YYSTR is taken from yytname. If YYRES is767null, do not copy; instead, return the length of what the result768would have been. */769static YYSIZE_T yytnamerr(char *yyres, const char *yystr)770{771if (*yystr == '"')772{773YYSIZE_T yyn = 0;774char const *yyp = yystr;775776for (;;)777switch (*++yyp)778{779case '\'':780case ',':781goto do_not_strip_quotes;782783case '\\':784if (*++yyp != '\\')785goto do_not_strip_quotes;786else787goto append;788789append:790default:791if (yyres)792yyres[yyn] = *yyp;793yyn++;794break;795796case '"':797if (yyres)798yyres[yyn] = '\0';799return yyn;800}801do_not_strip_quotes:;802}803804if (!yyres)805return yystrlen(yystr);806807return (YYSIZE_T)(yystpcpy(yyres, yystr) - yyres);808}809# endif810811/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message812about the unexpected token YYTOKEN for the state stack whose top is813YYSSP.814815Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is816not large enough to hold the message. In that case, also set817*YYMSG_ALLOC to the required number of bytes. Return 2 if the818required number of bytes is too large to store. */819static int yysyntax_error(YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken)820{821YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]);822YYSIZE_T yysize = yysize0;823enum824{825YYERROR_VERBOSE_ARGS_MAXIMUM = 5826};827/* Internationalized format string. */828const char *yyformat = YY_NULLPTR;829/* Arguments of yyformat. */830char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];831/* Number of reported tokens (one for the "unexpected", one per832"expected"). */833int yycount = 0;834835/* There are many possibilities here to consider:836- If this state is a consistent state with a default action, then837the only way this function was invoked is if the default action838is an error action. In that case, don't check for expected839tokens because there are none.840- The only way there can be no lookahead present (in yychar) is if841this state is a consistent state with a default action. Thus,842detecting the absence of a lookahead is sufficient to determine843that there is no unexpected or expected token to report. In that844case, just report a simple "syntax error".845- Don't assume there isn't a lookahead just because this state is a846consistent state with a default action. There might have been a847previous inconsistent state, consistent state with a non-default848action, or user semantic action that manipulated yychar.849- Of course, the expected token list depends on states to have850correct lookahead information, and it depends on the parser not851to perform extra reductions after fetching a lookahead from the852scanner and before detecting a syntax error. Thus, state merging853(from LALR or IELR) and default reductions corrupt the expected854token list. However, the list is correct for canonical LR with855one exception: it will still contain any token that will not be856accepted due to an error action in a later state.857*/858if (yytoken != YYEMPTY)859{860int yyn = yypact[*yyssp];861yyarg[yycount++] = yytname[yytoken];862if (!yypact_value_is_default(yyn))863{864/* Start YYX at -YYN if negative to avoid negative indexes in865YYCHECK. In other words, skip the first -YYN actions for866this state because they are default actions. */867int yyxbegin = yyn < 0 ? -yyn : 0;868/* Stay within bounds of both yycheck and yytname. */869int yychecklim = YYLAST - yyn + 1;870int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;871int yyx;872873for (yyx = yyxbegin; yyx < yyxend; ++yyx)874if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR &&875!yytable_value_is_error(yytable[yyx + yyn]))876{877if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)878{879yycount = 1;880yysize = yysize0;881break;882}883yyarg[yycount++] = yytname[yyx];884{885YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]);886if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)887yysize = yysize1;888else889return 2;890}891}892}893}894895switch (yycount)896{897# define YYCASE_(N, S) \898case N: \899yyformat = S; \900break901default: /* Avoid compiler warnings. */902YYCASE_(0, YY_("syntax error"));903YYCASE_(1, YY_("syntax error, unexpected %s"));904YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));905YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));906YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));907YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));908# undef YYCASE_909}910911{912YYSIZE_T yysize1 = yysize + yystrlen(yyformat);913if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)914yysize = yysize1;915else916return 2;917}918919if (*yymsg_alloc < yysize)920{921*yymsg_alloc = 2 * yysize;922if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))923*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;924return 1;925}926927/* Avoid sprintf, as that infringes on the user's name space.928Don't have undefined behavior even if the translation929produced a string with the wrong number of "%s"s. */930{931char *yyp = *yymsg;932int yyi = 0;933while ((*yyp = *yyformat) != '\0')934if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)935{936yyp += yytnamerr(yyp, yyarg[yyi++]);937yyformat += 2;938}939else940{941yyp++;942yyformat++;943}944}945return 0;946}947#endif /* YYERROR_VERBOSE */948949/*-----------------------------------------------.950| Release the memory associated to this symbol. |951`-----------------------------------------------*/952953static void yydestruct(const char *yymsg, int yytype, YYSTYPE *yyvaluep, Context *context)954{955YYUSE(yyvaluep);956YYUSE(context);957if (!yymsg)958yymsg = "Deleting";959YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp);960961YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN962YYUSE(yytype);963YY_IGNORE_MAYBE_UNINITIALIZED_END964}965966/*----------.967| yyparse. |968`----------*/969970int yyparse(Context *context)971{972/* The lookahead symbol. */973int yychar;974975/* The semantic value of the lookahead symbol. */976/* Default value used for initialization, for pacifying older GCCs977or non-GCC compilers. */978YY_INITIAL_VALUE(static YYSTYPE yyval_default;)979YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default);980981/* Number of syntax errors so far. */982int yynerrs;983984int yystate;985/* Number of tokens to shift before error messages enabled. */986int yyerrstatus;987988/* The stacks and their tools:989'yyss': related to states.990'yyvs': related to semantic values.991992Refer to the stacks through separate pointers, to allow yyoverflow993to reallocate them elsewhere. */994995/* The state stack. */996yytype_int16 yyssa[YYINITDEPTH];997yytype_int16 *yyss;998yytype_int16 *yyssp;9991000/* The semantic value stack. */1001YYSTYPE yyvsa[YYINITDEPTH];1002YYSTYPE *yyvs;1003YYSTYPE *yyvsp;10041005YYSIZE_T yystacksize;10061007int yyn;1008int yyresult;1009/* Lookahead token as an internal (translated) token number. */1010int yytoken = 0;1011/* The variables used to return semantic value and location from the1012action routines. */1013YYSTYPE yyval;10141015#if YYERROR_VERBOSE1016/* Buffer for error messages, and its allocated size. */1017char yymsgbuf[128];1018char *yymsg = yymsgbuf;1019YYSIZE_T yymsg_alloc = sizeof yymsgbuf;1020#endif10211022#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))10231024/* The number of symbols on the RHS of the reduced rule.1025Keep to zero when no symbol should be popped. */1026int yylen = 0;10271028yyssp = yyss = yyssa;1029yyvsp = yyvs = yyvsa;1030yystacksize = YYINITDEPTH;10311032YYDPRINTF((stderr, "Starting parse\n"));10331034yystate = 0;1035yyerrstatus = 0;1036yynerrs = 0;1037yychar = YYEMPTY; /* Cause a token to be read. */1038goto yysetstate;10391040/*------------------------------------------------------------.1041| yynewstate -- push a new state, which is found in yystate. |1042`------------------------------------------------------------*/1043yynewstate:1044/* In all cases, when you get here, the value and location stacks1045have just been pushed. So pushing a state here evens the stacks. */1046yyssp++;10471048/*--------------------------------------------------------------------.1049| yynewstate -- set current state (the top of the stack) to yystate. |1050`--------------------------------------------------------------------*/1051yysetstate:1052*yyssp = (yytype_int16)yystate;10531054if (yyss + yystacksize - 1 <= yyssp)1055#if !defined yyoverflow && !defined YYSTACK_RELOCATE1056goto yyexhaustedlab;1057#else1058{1059/* Get the current used size of the three stacks, in elements. */1060YYSIZE_T yysize = (YYSIZE_T)(yyssp - yyss + 1);10611062# if defined yyoverflow1063{1064/* Give user a chance to reallocate the stack. Use copies of1065these so that the &'s don't force the real ones into1066memory. */1067YYSTYPE *yyvs1 = yyvs;1068yytype_int16 *yyss1 = yyss;10691070/* Each stack pointer address is followed by the size of the1071data in use in that stack, in bytes. This used to be a1072conditional around just the two extra args, but that might1073be undefined if yyoverflow is a macro. */1074yyoverflow(YY_("memory exhausted"), &yyss1, yysize * sizeof(*yyssp), &yyvs1,1075yysize * sizeof(*yyvsp), &yystacksize);1076yyss = yyss1;1077yyvs = yyvs1;1078}1079# else /* defined YYSTACK_RELOCATE */1080/* Extend the stack our own way. */1081if (YYMAXDEPTH <= yystacksize)1082goto yyexhaustedlab;1083yystacksize *= 2;1084if (YYMAXDEPTH < yystacksize)1085yystacksize = YYMAXDEPTH;10861087{1088yytype_int16 *yyss1 = yyss;1089union yyalloc *yyptr = (union yyalloc *)YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize));1090if (!yyptr)1091goto yyexhaustedlab;1092YYSTACK_RELOCATE(yyss_alloc, yyss);1093YYSTACK_RELOCATE(yyvs_alloc, yyvs);1094# undef YYSTACK_RELOCATE1095if (yyss1 != yyssa)1096YYSTACK_FREE(yyss1);1097}1098# endif10991100yyssp = yyss + yysize - 1;1101yyvsp = yyvs + yysize - 1;11021103YYDPRINTF((stderr, "Stack size increased to %lu\n", (unsigned long)yystacksize));11041105if (yyss + yystacksize - 1 <= yyssp)1106YYABORT;1107}1108#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */11091110YYDPRINTF((stderr, "Entering state %d\n", yystate));11111112if (yystate == YYFINAL)1113YYACCEPT;11141115goto yybackup;11161117/*-----------.1118| yybackup. |1119`-----------*/1120yybackup:1121/* Do appropriate processing given the current state. Read a1122lookahead token if we need one and don't already have one. */11231124/* First try to decide what to do without reference to lookahead token. */1125yyn = yypact[yystate];1126if (yypact_value_is_default(yyn))1127goto yydefault;11281129/* Not known => get a lookahead token if don't already have one. */11301131/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */1132if (yychar == YYEMPTY)1133{1134YYDPRINTF((stderr, "Reading a token: "));1135yychar = yylex(&yylval, context);1136}11371138if (yychar <= YYEOF)1139{1140yychar = yytoken = YYEOF;1141YYDPRINTF((stderr, "Now at end of input.\n"));1142}1143else1144{1145yytoken = YYTRANSLATE(yychar);1146YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc);1147}11481149/* If the proper action on seeing token YYTOKEN is to reduce or to1150detect an error, take that action. */1151yyn += yytoken;1152if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)1153goto yydefault;1154yyn = yytable[yyn];1155if (yyn <= 0)1156{1157if (yytable_value_is_error(yyn))1158goto yyerrlab;1159yyn = -yyn;1160goto yyreduce;1161}11621163/* Count tokens shifted since error; after three, turn off error1164status. */1165if (yyerrstatus)1166yyerrstatus--;11671168/* Shift the lookahead token. */1169YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc);11701171/* Discard the shifted token. */1172yychar = YYEMPTY;11731174yystate = yyn;1175YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN1176*++yyvsp = yylval;1177YY_IGNORE_MAYBE_UNINITIALIZED_END11781179goto yynewstate;11801181/*-----------------------------------------------------------.1182| yydefault -- do the default action for the current state. |1183`-----------------------------------------------------------*/1184yydefault:1185yyn = yydefact[yystate];1186if (yyn == 0)1187goto yyerrlab;1188goto yyreduce;11891190/*-----------------------------.1191| yyreduce -- do a reduction. |1192`-----------------------------*/1193yyreduce:1194/* yyn is the number of a rule to reduce with. */1195yylen = yyr2[yyn];11961197/* If YYLEN is nonzero, implement the default value of the action:1198'$$ = $1'.11991200Otherwise, the following line sets YYVAL to garbage.1201This behavior is undocumented and Bison1202users should not rely upon it. Assigning to YYVAL1203unconditionally makes the parser a bit smaller, and it avoids a1204GCC warning that YYVAL may be used uninitialized. */1205yyval = yyvsp[1 - yylen];12061207YY_REDUCE_PRINT(yyn);1208switch (yyn)1209{1210case 2:12111212{1213*(context->result) = static_cast<int>(yyvsp[0]);1214YYACCEPT;1215}12161217break;12181219case 4:12201221{1222if (!context->isIgnoringErrors())1223{1224// This rule should be applied right after the token is lexed, so we can1225// refer to context->token in the error message.1226context->diagnostics->report(context->errorSettings.unexpectedIdentifier,1227context->token->location, context->token->text);1228*(context->valid) = false;1229}1230yyval = yyvsp[0];1231}12321233break;12341235case 5:12361237{1238if (yyvsp[-1] != 0)1239{1240// Ignore errors in the short-circuited part of the expression.1241// ESSL3.00 section 3.4:1242// If an operand is not evaluated, the presence of undefined identifiers1243// in the operand will not cause an error.1244// Unevaluated division by zero should not cause an error either.1245context->startIgnoreErrors();1246}1247}12481249break;12501251case 6:12521253{1254if (yyvsp[-3] != 0)1255{1256context->endIgnoreErrors();1257yyval = static_cast<YYSTYPE>(1);1258}1259else1260{1261yyval = yyvsp[-3] || yyvsp[0];1262}1263}12641265break;12661267case 7:12681269{1270if (yyvsp[-1] == 0)1271{1272// Ignore errors in the short-circuited part of the expression.1273// ESSL3.00 section 3.4:1274// If an operand is not evaluated, the presence of undefined identifiers1275// in the operand will not cause an error.1276// Unevaluated division by zero should not cause an error either.1277context->startIgnoreErrors();1278}1279}12801281break;12821283case 8:12841285{1286if (yyvsp[-3] == 0)1287{1288context->endIgnoreErrors();1289yyval = static_cast<YYSTYPE>(0);1290}1291else1292{1293yyval = yyvsp[-3] && yyvsp[0];1294}1295}12961297break;12981299case 9:13001301{1302yyval = yyvsp[-2] | yyvsp[0];1303}13041305break;13061307case 10:13081309{1310yyval = yyvsp[-2] ^ yyvsp[0];1311}13121313break;13141315case 11:13161317{1318yyval = yyvsp[-2] & yyvsp[0];1319}13201321break;13221323case 12:13241325{1326yyval = yyvsp[-2] != yyvsp[0];1327}13281329break;13301331case 13:13321333{1334yyval = yyvsp[-2] == yyvsp[0];1335}13361337break;13381339case 14:13401341{1342yyval = yyvsp[-2] >= yyvsp[0];1343}13441345break;13461347case 15:13481349{1350yyval = yyvsp[-2] <= yyvsp[0];1351}13521353break;13541355case 16:13561357{1358yyval = yyvsp[-2] > yyvsp[0];1359}13601361break;13621363case 17:13641365{1366yyval = yyvsp[-2] < yyvsp[0];1367}13681369break;13701371case 18:13721373{1374if (yyvsp[0] < 0 || yyvsp[0] > 31)1375{1376if (!context->isIgnoringErrors())1377{1378std::ostringstream stream;1379stream << yyvsp[-2] << " >> " << yyvsp[0];1380std::string text = stream.str();1381context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,1382context->token->location, text.c_str());1383*(context->valid) = false;1384}1385yyval = static_cast<YYSTYPE>(0);1386}1387else if (yyvsp[-2] < 0)1388{1389// Logical shift right.1390yyval = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>(yyvsp[-2]) >> yyvsp[0]);1391}1392else1393{1394yyval = yyvsp[-2] >> yyvsp[0];1395}1396}13971398break;13991400case 19:14011402{1403if (yyvsp[0] < 0 || yyvsp[0] > 31)1404{1405if (!context->isIgnoringErrors())1406{1407std::ostringstream stream;1408stream << yyvsp[-2] << " << " << yyvsp[0];1409std::string text = stream.str();1410context->diagnostics->report(angle::pp::Diagnostics::PP_UNDEFINED_SHIFT,1411context->token->location, text.c_str());1412*(context->valid) = false;1413}1414yyval = static_cast<YYSTYPE>(0);1415}1416else1417{1418// Logical shift left. Casting to unsigned is needed to ensure there's no signed1419// integer overflow, which some tools treat as an error.1420yyval = static_cast<YYSTYPE>(static_cast<UNSIGNED_TYPE>(yyvsp[-2]) << yyvsp[0]);1421}1422}14231424break;14251426case 20:14271428{1429yyval = gl::WrappingDiff<YYSTYPE>(yyvsp[-2], yyvsp[0]);1430}14311432break;14331434case 21:14351436{1437yyval = gl::WrappingSum<YYSTYPE>(yyvsp[-2], yyvsp[0]);1438}14391440break;14411442case 22:14431444{1445if (yyvsp[0] == 0)1446{1447if (!context->isIgnoringErrors())1448{1449std::ostringstream stream;1450stream << yyvsp[-2] << " % " << yyvsp[0];1451std::string text = stream.str();1452context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,1453context->token->location, text.c_str());1454*(context->valid) = false;1455}1456yyval = static_cast<YYSTYPE>(0);1457}1458else if ((yyvsp[-2] == std::numeric_limits<YYSTYPE>::min()) && (yyvsp[0] == -1))1459{1460// Check for the special case where the minimum representable number is1461// divided by -1. If left alone this has undefined results.1462yyval = 0;1463}1464else1465{1466yyval = yyvsp[-2] % yyvsp[0];1467}1468}14691470break;14711472case 23:14731474{1475if (yyvsp[0] == 0)1476{1477if (!context->isIgnoringErrors())1478{1479std::ostringstream stream;1480stream << yyvsp[-2] << " / " << yyvsp[0];1481std::string text = stream.str();1482context->diagnostics->report(angle::pp::Diagnostics::PP_DIVISION_BY_ZERO,1483context->token->location, text.c_str());1484*(context->valid) = false;1485}1486yyval = static_cast<YYSTYPE>(0);1487}1488else if ((yyvsp[-2] == std::numeric_limits<YYSTYPE>::min()) && (yyvsp[0] == -1))1489{1490// Check for the special case where the minimum representable number is1491// divided by -1. If left alone this leads to integer overflow in C++, which1492// has undefined results.1493yyval = std::numeric_limits<YYSTYPE>::max();1494}1495else1496{1497yyval = yyvsp[-2] / yyvsp[0];1498}1499}15001501break;15021503case 24:15041505{1506yyval = gl::WrappingMul(yyvsp[-2], yyvsp[0]);1507}15081509break;15101511case 25:15121513{1514yyval = !yyvsp[0];1515}15161517break;15181519case 26:15201521{1522yyval = ~yyvsp[0];1523}15241525break;15261527case 27:15281529{1530// Check for negation of minimum representable integer to prevent undefined signed int1531// overflow.1532if (yyvsp[0] == std::numeric_limits<YYSTYPE>::min())1533{1534yyval = std::numeric_limits<YYSTYPE>::min();1535}1536else1537{1538yyval = -yyvsp[0];1539}1540}15411542break;15431544case 28:15451546{1547yyval = +yyvsp[0];1548}15491550break;15511552case 29:15531554{1555yyval = yyvsp[-1];1556}15571558break;15591560default:1561break;1562}1563/* User semantic actions sometimes alter yychar, and that requires1564that yytoken be updated with the new translation. We take the1565approach of translating immediately before every use of yytoken.1566One alternative is translating here after every semantic action,1567but that translation would be missed if the semantic action invokes1568YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or1569if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an1570incorrect destructor might then be invoked immediately. In the1571case of YYERROR or YYBACKUP, subsequent parser actions might lead1572to an incorrect destructor call or verbose syntax error message1573before the lookahead is translated. */1574YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc);15751576YYPOPSTACK(yylen);1577yylen = 0;1578YY_STACK_PRINT(yyss, yyssp);15791580*++yyvsp = yyval;15811582/* Now 'shift' the result of the reduction. Determine what state1583that goes to, based on the state we popped back to and the rule1584number reduced by. */1585{1586const int yylhs = yyr1[yyn] - YYNTOKENS;1587const int yyi = yypgoto[yylhs] + *yyssp;1588yystate =1589(0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp ? yytable[yyi] : yydefgoto[yylhs]);1590}15911592goto yynewstate;15931594/*--------------------------------------.1595| yyerrlab -- here on detecting error. |1596`--------------------------------------*/1597yyerrlab:1598/* Make sure we have latest lookahead translation. See comments at1599user semantic actions for why this is necessary. */1600yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar);16011602/* If not already recovering from an error, report this error. */1603if (!yyerrstatus)1604{1605++yynerrs;1606#if !YYERROR_VERBOSE1607yyerror(context, YY_("syntax error"));1608#else1609# define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken)1610{1611char const *yymsgp = YY_("syntax error");1612int yysyntax_error_status;1613yysyntax_error_status = YYSYNTAX_ERROR;1614if (yysyntax_error_status == 0)1615yymsgp = yymsg;1616else if (yysyntax_error_status == 1)1617{1618if (yymsg != yymsgbuf)1619YYSTACK_FREE(yymsg);1620yymsg = (char *)YYSTACK_ALLOC(yymsg_alloc);1621if (!yymsg)1622{1623yymsg = yymsgbuf;1624yymsg_alloc = sizeof yymsgbuf;1625yysyntax_error_status = 2;1626}1627else1628{1629yysyntax_error_status = YYSYNTAX_ERROR;1630yymsgp = yymsg;1631}1632}1633yyerror(context, yymsgp);1634if (yysyntax_error_status == 2)1635goto yyexhaustedlab;1636}1637# undef YYSYNTAX_ERROR1638#endif1639}16401641if (yyerrstatus == 3)1642{1643/* If just tried and failed to reuse lookahead token after an1644error, discard it. */16451646if (yychar <= YYEOF)1647{1648/* Return failure if at end of input. */1649if (yychar == YYEOF)1650YYABORT;1651}1652else1653{1654yydestruct("Error: discarding", yytoken, &yylval, context);1655yychar = YYEMPTY;1656}1657}16581659/* Else will try to reuse lookahead token after shifting the error1660token. */1661goto yyerrlab1;16621663/*---------------------------------------------------.1664| yyerrorlab -- error raised explicitly by YYERROR. |1665`---------------------------------------------------*/1666yyerrorlab:1667/* Pacify compilers when the user code never invokes YYERROR and the1668label yyerrorlab therefore never appears in user code. */1669if (0)1670YYERROR;16711672/* Do not reclaim the symbols of the rule whose action triggered1673this YYERROR. */1674YYPOPSTACK(yylen);1675yylen = 0;1676YY_STACK_PRINT(yyss, yyssp);1677yystate = *yyssp;1678goto yyerrlab1;16791680/*-------------------------------------------------------------.1681| yyerrlab1 -- common code for both syntax error and YYERROR. |1682`-------------------------------------------------------------*/1683yyerrlab1:1684yyerrstatus = 3; /* Each real token shifted decrements this. */16851686for (;;)1687{1688yyn = yypact[yystate];1689if (!yypact_value_is_default(yyn))1690{1691yyn += YYTERROR;1692if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)1693{1694yyn = yytable[yyn];1695if (0 < yyn)1696break;1697}1698}16991700/* Pop the current state because it cannot handle the error token. */1701if (yyssp == yyss)1702YYABORT;17031704yydestruct("Error: popping", yystos[yystate], yyvsp, context);1705YYPOPSTACK(1);1706yystate = *yyssp;1707YY_STACK_PRINT(yyss, yyssp);1708}17091710YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN1711*++yyvsp = yylval;1712YY_IGNORE_MAYBE_UNINITIALIZED_END17131714/* Shift the error token. */1715YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp);17161717yystate = yyn;1718goto yynewstate;17191720/*-------------------------------------.1721| yyacceptlab -- YYACCEPT comes here. |1722`-------------------------------------*/1723yyacceptlab:1724yyresult = 0;1725goto yyreturn;17261727/*-----------------------------------.1728| yyabortlab -- YYABORT comes here. |1729`-----------------------------------*/1730yyabortlab:1731yyresult = 1;1732goto yyreturn;17331734#if !defined yyoverflow || YYERROR_VERBOSE1735/*-------------------------------------------------.1736| yyexhaustedlab -- memory exhaustion comes here. |1737`-------------------------------------------------*/1738yyexhaustedlab:1739yyerror(context, YY_("memory exhausted"));1740yyresult = 2;1741/* Fall through. */1742#endif17431744/*-----------------------------------------------------.1745| yyreturn -- parsing is finished, return the result. |1746`-----------------------------------------------------*/1747yyreturn:1748if (yychar != YYEMPTY)1749{1750/* Make sure we have latest lookahead translation. See comments at1751user semantic actions for why this is necessary. */1752yytoken = YYTRANSLATE(yychar);1753yydestruct("Cleanup: discarding lookahead", yytoken, &yylval, context);1754}1755/* Do not reclaim the symbols of the rule whose action triggered1756this YYABORT or YYACCEPT. */1757YYPOPSTACK(yylen);1758YY_STACK_PRINT(yyss, yyssp);1759while (yyssp != yyss)1760{1761yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, context);1762YYPOPSTACK(1);1763}1764#ifndef yyoverflow1765if (yyss != yyssa)1766YYSTACK_FREE(yyss);1767#endif1768#if YYERROR_VERBOSE1769if (yymsg != yymsgbuf)1770YYSTACK_FREE(yymsg);1771#endif1772return yyresult;1773}17741775int yylex(YYSTYPE *lvalp, Context *context)1776{1777angle::pp::Token *token = context->token;1778if (!context->parsePresetToken)1779{1780context->lexer->lex(token);1781}1782context->parsePresetToken = false;17831784int type = 0;17851786switch (token->type)1787{1788case angle::pp::Token::CONST_INT:1789{1790unsigned int val = 0;1791int testVal = 0;1792if (!token->uValue(&val) ||1793(!token->iValue(&testVal) &&1794context->errorSettings.integerLiteralsMustFit32BitSignedRange))1795{1796context->diagnostics->report(angle::pp::Diagnostics::PP_INTEGER_OVERFLOW,1797token->location, token->text);1798*(context->valid) = false;1799}1800*lvalp = static_cast<YYSTYPE>(val);1801type = TOK_CONST_INT;1802break;1803}1804case angle::pp::Token::IDENTIFIER:1805*lvalp = static_cast<YYSTYPE>(-1);1806type = TOK_IDENTIFIER;1807break;1808case angle::pp::Token::OP_OR:1809type = TOK_OP_OR;1810break;1811case angle::pp::Token::OP_AND:1812type = TOK_OP_AND;1813break;1814case angle::pp::Token::OP_NE:1815type = TOK_OP_NE;1816break;1817case angle::pp::Token::OP_EQ:1818type = TOK_OP_EQ;1819break;1820case angle::pp::Token::OP_GE:1821type = TOK_OP_GE;1822break;1823case angle::pp::Token::OP_LE:1824type = TOK_OP_LE;1825break;1826case angle::pp::Token::OP_RIGHT:1827type = TOK_OP_RIGHT;1828break;1829case angle::pp::Token::OP_LEFT:1830type = TOK_OP_LEFT;1831break;1832case '|':1833case '^':1834case '&':1835case '>':1836case '<':1837case '-':1838case '+':1839case '%':1840case '/':1841case '*':1842case '!':1843case '~':1844case '(':1845case ')':1846type = token->type;1847break;18481849default:1850break;1851}18521853return type;1854}18551856void yyerror(Context *context, const char *reason)1857{1858context->diagnostics->report(angle::pp::Diagnostics::PP_INVALID_EXPRESSION,1859context->token->location, reason);1860}18611862namespace angle1863{18641865namespace pp1866{18671868ExpressionParser::ExpressionParser(Lexer *lexer, Diagnostics *diagnostics)1869: mLexer(lexer), mDiagnostics(diagnostics)1870{}18711872bool ExpressionParser::parse(Token *token,1873int *result,1874bool parsePresetToken,1875const ErrorSettings &errorSettings,1876bool *valid)1877{1878Context context;1879context.diagnostics = mDiagnostics;1880context.lexer = mLexer;1881context.token = token;1882context.result = result;1883context.ignoreErrors = 0;1884context.parsePresetToken = parsePresetToken;1885context.errorSettings = errorSettings;1886context.valid = valid;1887int ret = yyparse(&context);1888switch (ret)1889{1890case 0:1891case 1:1892break;18931894case 2:1895mDiagnostics->report(Diagnostics::PP_OUT_OF_MEMORY, token->location, "");1896break;18971898default:1899assert(false);1900mDiagnostics->report(Diagnostics::PP_INTERNAL_ERROR, token->location, "");1901break;1902}19031904return ret == 0;1905}19061907} // namespace pp19081909} // namespace angle191019111912