Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 4 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | // found in the LICENSE file. |
michael@0 | 6 | // |
michael@0 | 7 | |
michael@0 | 8 | This file contains the Yacc grammar for GLSL ES preprocessor expression. |
michael@0 | 9 | |
michael@0 | 10 | IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh, |
michael@0 | 11 | WHICH GENERATES THE GLSL ES preprocessor expression parser. |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | %{ |
michael@0 | 15 | // |
michael@0 | 16 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 17 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 18 | // found in the LICENSE file. |
michael@0 | 19 | // |
michael@0 | 20 | |
michael@0 | 21 | // This file is auto-generated by generate_parser.sh. DO NOT EDIT! |
michael@0 | 22 | |
michael@0 | 23 | #if defined(__GNUC__) |
michael@0 | 24 | // Triggered by the auto-generated pplval variable. |
michael@0 | 25 | #if !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) |
michael@0 | 26 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
michael@0 | 27 | #else |
michael@0 | 28 | #pragma GCC diagnostic ignored "-Wuninitialized" |
michael@0 | 29 | #endif |
michael@0 | 30 | #elif defined(_MSC_VER) |
michael@0 | 31 | #pragma warning(disable: 4065 4701) |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | #include "ExpressionParser.h" |
michael@0 | 35 | |
michael@0 | 36 | #include <cassert> |
michael@0 | 37 | #include <sstream> |
michael@0 | 38 | |
michael@0 | 39 | #include "DiagnosticsBase.h" |
michael@0 | 40 | #include "Lexer.h" |
michael@0 | 41 | #include "Token.h" |
michael@0 | 42 | |
michael@0 | 43 | #if defined(_MSC_VER) |
michael@0 | 44 | typedef __int64 YYSTYPE; |
michael@0 | 45 | #else |
michael@0 | 46 | #include <stdint.h> |
michael@0 | 47 | typedef intmax_t YYSTYPE; |
michael@0 | 48 | #endif // _MSC_VER |
michael@0 | 49 | #define YYENABLE_NLS 0 |
michael@0 | 50 | #define YYLTYPE_IS_TRIVIAL 1 |
michael@0 | 51 | #define YYSTYPE_IS_TRIVIAL 1 |
michael@0 | 52 | #define YYSTYPE_IS_DECLARED 1 |
michael@0 | 53 | |
michael@0 | 54 | namespace { |
michael@0 | 55 | struct Context |
michael@0 | 56 | { |
michael@0 | 57 | pp::Diagnostics* diagnostics; |
michael@0 | 58 | pp::Lexer* lexer; |
michael@0 | 59 | pp::Token* token; |
michael@0 | 60 | int* result; |
michael@0 | 61 | }; |
michael@0 | 62 | } // namespace |
michael@0 | 63 | %} |
michael@0 | 64 | |
michael@0 | 65 | %pure-parser |
michael@0 | 66 | %name-prefix="pp" |
michael@0 | 67 | %parse-param {Context *context} |
michael@0 | 68 | %lex-param {Context *context} |
michael@0 | 69 | |
michael@0 | 70 | %{ |
michael@0 | 71 | static int yylex(YYSTYPE* lvalp, Context* context); |
michael@0 | 72 | static void yyerror(Context* context, const char* reason); |
michael@0 | 73 | %} |
michael@0 | 74 | |
michael@0 | 75 | %token TOK_CONST_INT |
michael@0 | 76 | %left TOK_OP_OR |
michael@0 | 77 | %left TOK_OP_AND |
michael@0 | 78 | %left '|' |
michael@0 | 79 | %left '^' |
michael@0 | 80 | %left '&' |
michael@0 | 81 | %left TOK_OP_EQ TOK_OP_NE |
michael@0 | 82 | %left '<' '>' TOK_OP_LE TOK_OP_GE |
michael@0 | 83 | %left TOK_OP_LEFT TOK_OP_RIGHT |
michael@0 | 84 | %left '+' '-' |
michael@0 | 85 | %left '*' '/' '%' |
michael@0 | 86 | %right TOK_UNARY |
michael@0 | 87 | |
michael@0 | 88 | %% |
michael@0 | 89 | |
michael@0 | 90 | input |
michael@0 | 91 | : expression { |
michael@0 | 92 | *(context->result) = static_cast<int>($1); |
michael@0 | 93 | YYACCEPT; |
michael@0 | 94 | } |
michael@0 | 95 | ; |
michael@0 | 96 | |
michael@0 | 97 | expression |
michael@0 | 98 | : TOK_CONST_INT |
michael@0 | 99 | | expression TOK_OP_OR expression { |
michael@0 | 100 | $$ = $1 || $3; |
michael@0 | 101 | } |
michael@0 | 102 | | expression TOK_OP_AND expression { |
michael@0 | 103 | $$ = $1 && $3; |
michael@0 | 104 | } |
michael@0 | 105 | | expression '|' expression { |
michael@0 | 106 | $$ = $1 | $3; |
michael@0 | 107 | } |
michael@0 | 108 | | expression '^' expression { |
michael@0 | 109 | $$ = $1 ^ $3; |
michael@0 | 110 | } |
michael@0 | 111 | | expression '&' expression { |
michael@0 | 112 | $$ = $1 & $3; |
michael@0 | 113 | } |
michael@0 | 114 | | expression TOK_OP_NE expression { |
michael@0 | 115 | $$ = $1 != $3; |
michael@0 | 116 | } |
michael@0 | 117 | | expression TOK_OP_EQ expression { |
michael@0 | 118 | $$ = $1 == $3; |
michael@0 | 119 | } |
michael@0 | 120 | | expression TOK_OP_GE expression { |
michael@0 | 121 | $$ = $1 >= $3; |
michael@0 | 122 | } |
michael@0 | 123 | | expression TOK_OP_LE expression { |
michael@0 | 124 | $$ = $1 <= $3; |
michael@0 | 125 | } |
michael@0 | 126 | | expression '>' expression { |
michael@0 | 127 | $$ = $1 > $3; |
michael@0 | 128 | } |
michael@0 | 129 | | expression '<' expression { |
michael@0 | 130 | $$ = $1 < $3; |
michael@0 | 131 | } |
michael@0 | 132 | | expression TOK_OP_RIGHT expression { |
michael@0 | 133 | $$ = $1 >> $3; |
michael@0 | 134 | } |
michael@0 | 135 | | expression TOK_OP_LEFT expression { |
michael@0 | 136 | $$ = $1 << $3; |
michael@0 | 137 | } |
michael@0 | 138 | | expression '-' expression { |
michael@0 | 139 | $$ = $1 - $3; |
michael@0 | 140 | } |
michael@0 | 141 | | expression '+' expression { |
michael@0 | 142 | $$ = $1 + $3; |
michael@0 | 143 | } |
michael@0 | 144 | | expression '%' expression { |
michael@0 | 145 | if ($3 == 0) { |
michael@0 | 146 | std::ostringstream stream; |
michael@0 | 147 | stream << $1 << " % " << $3; |
michael@0 | 148 | std::string text = stream.str(); |
michael@0 | 149 | context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO, |
michael@0 | 150 | context->token->location, |
michael@0 | 151 | text.c_str()); |
michael@0 | 152 | YYABORT; |
michael@0 | 153 | } else { |
michael@0 | 154 | $$ = $1 % $3; |
michael@0 | 155 | } |
michael@0 | 156 | } |
michael@0 | 157 | | expression '/' expression { |
michael@0 | 158 | if ($3 == 0) { |
michael@0 | 159 | std::ostringstream stream; |
michael@0 | 160 | stream << $1 << " / " << $3; |
michael@0 | 161 | std::string text = stream.str(); |
michael@0 | 162 | context->diagnostics->report(pp::Diagnostics::DIVISION_BY_ZERO, |
michael@0 | 163 | context->token->location, |
michael@0 | 164 | text.c_str()); |
michael@0 | 165 | YYABORT; |
michael@0 | 166 | } else { |
michael@0 | 167 | $$ = $1 / $3; |
michael@0 | 168 | } |
michael@0 | 169 | } |
michael@0 | 170 | | expression '*' expression { |
michael@0 | 171 | $$ = $1 * $3; |
michael@0 | 172 | } |
michael@0 | 173 | | '!' expression %prec TOK_UNARY { |
michael@0 | 174 | $$ = ! $2; |
michael@0 | 175 | } |
michael@0 | 176 | | '~' expression %prec TOK_UNARY { |
michael@0 | 177 | $$ = ~ $2; |
michael@0 | 178 | } |
michael@0 | 179 | | '-' expression %prec TOK_UNARY { |
michael@0 | 180 | $$ = - $2; |
michael@0 | 181 | } |
michael@0 | 182 | | '+' expression %prec TOK_UNARY { |
michael@0 | 183 | $$ = + $2; |
michael@0 | 184 | } |
michael@0 | 185 | | '(' expression ')' { |
michael@0 | 186 | $$ = $2; |
michael@0 | 187 | } |
michael@0 | 188 | ; |
michael@0 | 189 | |
michael@0 | 190 | %% |
michael@0 | 191 | |
michael@0 | 192 | int yylex(YYSTYPE* lvalp, Context* context) |
michael@0 | 193 | { |
michael@0 | 194 | int type = 0; |
michael@0 | 195 | |
michael@0 | 196 | pp::Token* token = context->token; |
michael@0 | 197 | switch (token->type) |
michael@0 | 198 | { |
michael@0 | 199 | case pp::Token::CONST_INT: |
michael@0 | 200 | { |
michael@0 | 201 | unsigned int val = 0; |
michael@0 | 202 | if (!token->uValue(&val)) |
michael@0 | 203 | { |
michael@0 | 204 | context->diagnostics->report(pp::Diagnostics::INTEGER_OVERFLOW, |
michael@0 | 205 | token->location, token->text); |
michael@0 | 206 | } |
michael@0 | 207 | *lvalp = static_cast<YYSTYPE>(val); |
michael@0 | 208 | type = TOK_CONST_INT; |
michael@0 | 209 | break; |
michael@0 | 210 | } |
michael@0 | 211 | case pp::Token::OP_OR: type = TOK_OP_OR; break; |
michael@0 | 212 | case pp::Token::OP_AND: type = TOK_OP_AND; break; |
michael@0 | 213 | case pp::Token::OP_NE: type = TOK_OP_NE; break; |
michael@0 | 214 | case pp::Token::OP_EQ: type = TOK_OP_EQ; break; |
michael@0 | 215 | case pp::Token::OP_GE: type = TOK_OP_GE; break; |
michael@0 | 216 | case pp::Token::OP_LE: type = TOK_OP_LE; break; |
michael@0 | 217 | case pp::Token::OP_RIGHT: type = TOK_OP_RIGHT; break; |
michael@0 | 218 | case pp::Token::OP_LEFT: type = TOK_OP_LEFT; break; |
michael@0 | 219 | case '|': type = '|'; break; |
michael@0 | 220 | case '^': type = '^'; break; |
michael@0 | 221 | case '&': type = '&'; break; |
michael@0 | 222 | case '>': type = '>'; break; |
michael@0 | 223 | case '<': type = '<'; break; |
michael@0 | 224 | case '-': type = '-'; break; |
michael@0 | 225 | case '+': type = '+'; break; |
michael@0 | 226 | case '%': type = '%'; break; |
michael@0 | 227 | case '/': type = '/'; break; |
michael@0 | 228 | case '*': type = '*'; break; |
michael@0 | 229 | case '!': type = '!'; break; |
michael@0 | 230 | case '~': type = '~'; break; |
michael@0 | 231 | case '(': type = '('; break; |
michael@0 | 232 | case ')': type = ')'; break; |
michael@0 | 233 | |
michael@0 | 234 | default: break; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | // Advance to the next token if the current one is valid. |
michael@0 | 238 | if (type != 0) context->lexer->lex(token); |
michael@0 | 239 | |
michael@0 | 240 | return type; |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | void yyerror(Context* context, const char* reason) |
michael@0 | 244 | { |
michael@0 | 245 | context->diagnostics->report(pp::Diagnostics::INVALID_EXPRESSION, |
michael@0 | 246 | context->token->location, |
michael@0 | 247 | reason); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | namespace pp { |
michael@0 | 251 | |
michael@0 | 252 | ExpressionParser::ExpressionParser(Lexer* lexer, Diagnostics* diagnostics) : |
michael@0 | 253 | mLexer(lexer), |
michael@0 | 254 | mDiagnostics(diagnostics) |
michael@0 | 255 | { |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | bool ExpressionParser::parse(Token* token, int* result) |
michael@0 | 259 | { |
michael@0 | 260 | Context context; |
michael@0 | 261 | context.diagnostics = mDiagnostics; |
michael@0 | 262 | context.lexer = mLexer; |
michael@0 | 263 | context.token = token; |
michael@0 | 264 | context.result = result; |
michael@0 | 265 | int ret = yyparse(&context); |
michael@0 | 266 | switch (ret) |
michael@0 | 267 | { |
michael@0 | 268 | case 0: |
michael@0 | 269 | case 1: |
michael@0 | 270 | break; |
michael@0 | 271 | |
michael@0 | 272 | case 2: |
michael@0 | 273 | mDiagnostics->report(Diagnostics::OUT_OF_MEMORY, token->location, ""); |
michael@0 | 274 | break; |
michael@0 | 275 | |
michael@0 | 276 | default: |
michael@0 | 277 | assert(false); |
michael@0 | 278 | mDiagnostics->report(Diagnostics::INTERNAL_ERROR, token->location, ""); |
michael@0 | 279 | break; |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | return ret == 0; |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | } // namespace pp |