Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2002-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 Lex specification for GLSL ES. |
michael@0 | 9 | Based on ANSI C grammar, Lex specification: |
michael@0 | 10 | http://www.lysator.liu.se/c/ANSI-C-grammar-l.html |
michael@0 | 11 | |
michael@0 | 12 | IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh, |
michael@0 | 13 | WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | %top{ |
michael@0 | 17 | // |
michael@0 | 18 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 19 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 20 | // found in the LICENSE file. |
michael@0 | 21 | // |
michael@0 | 22 | |
michael@0 | 23 | // This file is auto-generated by generate_parser.sh. DO NOT EDIT! |
michael@0 | 24 | |
michael@0 | 25 | // Ignore errors in auto-generated code. |
michael@0 | 26 | #if defined(__GNUC__) |
michael@0 | 27 | #pragma GCC diagnostic ignored "-Wunused-function" |
michael@0 | 28 | #pragma GCC diagnostic ignored "-Wunused-variable" |
michael@0 | 29 | #pragma GCC diagnostic ignored "-Wswitch-enum" |
michael@0 | 30 | #elif defined(_MSC_VER) |
michael@0 | 31 | #pragma warning(disable: 4065) |
michael@0 | 32 | #pragma warning(disable: 4189) |
michael@0 | 33 | #pragma warning(disable: 4505) |
michael@0 | 34 | #pragma warning(disable: 4701) |
michael@0 | 35 | #endif |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | %{ |
michael@0 | 39 | #include "compiler/glslang.h" |
michael@0 | 40 | #include "compiler/ParseHelper.h" |
michael@0 | 41 | #include "compiler/preprocessor/Token.h" |
michael@0 | 42 | #include "compiler/util.h" |
michael@0 | 43 | #include "glslang_tab.h" |
michael@0 | 44 | |
michael@0 | 45 | /* windows only pragma */ |
michael@0 | 46 | #ifdef _MSC_VER |
michael@0 | 47 | #pragma warning(disable : 4102) |
michael@0 | 48 | #endif |
michael@0 | 49 | |
michael@0 | 50 | #define YY_USER_ACTION \ |
michael@0 | 51 | yylloc->first_file = yylloc->last_file = yycolumn; \ |
michael@0 | 52 | yylloc->first_line = yylloc->last_line = yylineno; |
michael@0 | 53 | |
michael@0 | 54 | #define YY_INPUT(buf, result, max_size) \ |
michael@0 | 55 | result = string_input(buf, max_size, yyscanner); |
michael@0 | 56 | |
michael@0 | 57 | static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner); |
michael@0 | 58 | static int check_type(yyscan_t yyscanner); |
michael@0 | 59 | static int reserved_word(yyscan_t yyscanner); |
michael@0 | 60 | %} |
michael@0 | 61 | |
michael@0 | 62 | %option noyywrap nounput never-interactive |
michael@0 | 63 | %option yylineno reentrant bison-bridge bison-locations |
michael@0 | 64 | %option extra-type="TParseContext*" |
michael@0 | 65 | |
michael@0 | 66 | D [0-9] |
michael@0 | 67 | L [a-zA-Z_] |
michael@0 | 68 | H [a-fA-F0-9] |
michael@0 | 69 | E [Ee][+-]?{D}+ |
michael@0 | 70 | O [0-7] |
michael@0 | 71 | |
michael@0 | 72 | %% |
michael@0 | 73 | |
michael@0 | 74 | "invariant" { return INVARIANT; } |
michael@0 | 75 | "highp" { return HIGH_PRECISION; } |
michael@0 | 76 | "mediump" { return MEDIUM_PRECISION; } |
michael@0 | 77 | "lowp" { return LOW_PRECISION; } |
michael@0 | 78 | "precision" { return PRECISION; } |
michael@0 | 79 | |
michael@0 | 80 | "attribute" { return ATTRIBUTE; } |
michael@0 | 81 | "const" { return CONST_QUAL; } |
michael@0 | 82 | "uniform" { return UNIFORM; } |
michael@0 | 83 | "varying" { return VARYING; } |
michael@0 | 84 | |
michael@0 | 85 | "break" { return BREAK; } |
michael@0 | 86 | "continue" { return CONTINUE; } |
michael@0 | 87 | "do" { return DO; } |
michael@0 | 88 | "for" { return FOR; } |
michael@0 | 89 | "while" { return WHILE; } |
michael@0 | 90 | |
michael@0 | 91 | "if" { return IF; } |
michael@0 | 92 | "else" { return ELSE; } |
michael@0 | 93 | |
michael@0 | 94 | "in" { return IN_QUAL; } |
michael@0 | 95 | "out" { return OUT_QUAL; } |
michael@0 | 96 | "inout" { return INOUT_QUAL; } |
michael@0 | 97 | |
michael@0 | 98 | "float" { return FLOAT_TYPE; } |
michael@0 | 99 | "int" { return INT_TYPE; } |
michael@0 | 100 | "void" { return VOID_TYPE; } |
michael@0 | 101 | "bool" { return BOOL_TYPE; } |
michael@0 | 102 | "true" { yylval->lex.b = true; return BOOLCONSTANT; } |
michael@0 | 103 | "false" { yylval->lex.b = false; return BOOLCONSTANT; } |
michael@0 | 104 | |
michael@0 | 105 | "discard" { return DISCARD; } |
michael@0 | 106 | "return" { return RETURN; } |
michael@0 | 107 | |
michael@0 | 108 | "mat2" { return MATRIX2; } |
michael@0 | 109 | "mat3" { return MATRIX3; } |
michael@0 | 110 | "mat4" { return MATRIX4; } |
michael@0 | 111 | |
michael@0 | 112 | "vec2" { return VEC2; } |
michael@0 | 113 | "vec3" { return VEC3; } |
michael@0 | 114 | "vec4" { return VEC4; } |
michael@0 | 115 | "ivec2" { return IVEC2; } |
michael@0 | 116 | "ivec3" { return IVEC3; } |
michael@0 | 117 | "ivec4" { return IVEC4; } |
michael@0 | 118 | "bvec2" { return BVEC2; } |
michael@0 | 119 | "bvec3" { return BVEC3; } |
michael@0 | 120 | "bvec4" { return BVEC4; } |
michael@0 | 121 | |
michael@0 | 122 | "sampler2D" { return SAMPLER2D; } |
michael@0 | 123 | "samplerCube" { return SAMPLERCUBE; } |
michael@0 | 124 | "samplerExternalOES" { return SAMPLER_EXTERNAL_OES; } |
michael@0 | 125 | "sampler2DRect" { return SAMPLER2DRECT; } |
michael@0 | 126 | |
michael@0 | 127 | "struct" { return STRUCT; } |
michael@0 | 128 | |
michael@0 | 129 | "asm" { return reserved_word(yyscanner); } |
michael@0 | 130 | |
michael@0 | 131 | "class" { return reserved_word(yyscanner); } |
michael@0 | 132 | "union" { return reserved_word(yyscanner); } |
michael@0 | 133 | "enum" { return reserved_word(yyscanner); } |
michael@0 | 134 | "typedef" { return reserved_word(yyscanner); } |
michael@0 | 135 | "template" { return reserved_word(yyscanner); } |
michael@0 | 136 | "this" { return reserved_word(yyscanner); } |
michael@0 | 137 | "packed" { return reserved_word(yyscanner); } |
michael@0 | 138 | |
michael@0 | 139 | "goto" { return reserved_word(yyscanner); } |
michael@0 | 140 | "switch" { return reserved_word(yyscanner); } |
michael@0 | 141 | "default" { return reserved_word(yyscanner); } |
michael@0 | 142 | |
michael@0 | 143 | "inline" { return reserved_word(yyscanner); } |
michael@0 | 144 | "noinline" { return reserved_word(yyscanner); } |
michael@0 | 145 | "volatile" { return reserved_word(yyscanner); } |
michael@0 | 146 | "public" { return reserved_word(yyscanner); } |
michael@0 | 147 | "static" { return reserved_word(yyscanner); } |
michael@0 | 148 | "extern" { return reserved_word(yyscanner); } |
michael@0 | 149 | "external" { return reserved_word(yyscanner); } |
michael@0 | 150 | "interface" { return reserved_word(yyscanner); } |
michael@0 | 151 | "flat" { return reserved_word(yyscanner); } |
michael@0 | 152 | |
michael@0 | 153 | "long" { return reserved_word(yyscanner); } |
michael@0 | 154 | "short" { return reserved_word(yyscanner); } |
michael@0 | 155 | "double" { return reserved_word(yyscanner); } |
michael@0 | 156 | "half" { return reserved_word(yyscanner); } |
michael@0 | 157 | "fixed" { return reserved_word(yyscanner); } |
michael@0 | 158 | "unsigned" { return reserved_word(yyscanner); } |
michael@0 | 159 | "superp" { return reserved_word(yyscanner); } |
michael@0 | 160 | |
michael@0 | 161 | "input" { return reserved_word(yyscanner); } |
michael@0 | 162 | "output" { return reserved_word(yyscanner); } |
michael@0 | 163 | |
michael@0 | 164 | "hvec2" { return reserved_word(yyscanner); } |
michael@0 | 165 | "hvec3" { return reserved_word(yyscanner); } |
michael@0 | 166 | "hvec4" { return reserved_word(yyscanner); } |
michael@0 | 167 | "dvec2" { return reserved_word(yyscanner); } |
michael@0 | 168 | "dvec3" { return reserved_word(yyscanner); } |
michael@0 | 169 | "dvec4" { return reserved_word(yyscanner); } |
michael@0 | 170 | "fvec2" { return reserved_word(yyscanner); } |
michael@0 | 171 | "fvec3" { return reserved_word(yyscanner); } |
michael@0 | 172 | "fvec4" { return reserved_word(yyscanner); } |
michael@0 | 173 | |
michael@0 | 174 | "sampler1D" { return reserved_word(yyscanner); } |
michael@0 | 175 | "sampler3D" { return reserved_word(yyscanner); } |
michael@0 | 176 | "sampler1DShadow" { return reserved_word(yyscanner); } |
michael@0 | 177 | "sampler2DShadow" { return reserved_word(yyscanner); } |
michael@0 | 178 | "sampler3DRect" { return reserved_word(yyscanner); } |
michael@0 | 179 | "sampler2DRectShadow" { return reserved_word(yyscanner); } |
michael@0 | 180 | |
michael@0 | 181 | "sizeof" { return reserved_word(yyscanner); } |
michael@0 | 182 | "cast" { return reserved_word(yyscanner); } |
michael@0 | 183 | |
michael@0 | 184 | "namespace" { return reserved_word(yyscanner); } |
michael@0 | 185 | "using" { return reserved_word(yyscanner); } |
michael@0 | 186 | |
michael@0 | 187 | {L}({L}|{D})* { |
michael@0 | 188 | yylval->lex.string = NewPoolTString(yytext); |
michael@0 | 189 | return check_type(yyscanner); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | 0[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
michael@0 | 193 | 0{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
michael@0 | 194 | {D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; } |
michael@0 | 195 | |
michael@0 | 196 | {D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
michael@0 | 197 | {D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
michael@0 | 198 | "."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; } |
michael@0 | 199 | |
michael@0 | 200 | "+=" { return ADD_ASSIGN; } |
michael@0 | 201 | "-=" { return SUB_ASSIGN; } |
michael@0 | 202 | "*=" { return MUL_ASSIGN; } |
michael@0 | 203 | "/=" { return DIV_ASSIGN; } |
michael@0 | 204 | "%=" { return MOD_ASSIGN; } |
michael@0 | 205 | "<<=" { return LEFT_ASSIGN; } |
michael@0 | 206 | ">>=" { return RIGHT_ASSIGN; } |
michael@0 | 207 | "&=" { return AND_ASSIGN; } |
michael@0 | 208 | "^=" { return XOR_ASSIGN; } |
michael@0 | 209 | "|=" { return OR_ASSIGN; } |
michael@0 | 210 | |
michael@0 | 211 | "++" { return INC_OP; } |
michael@0 | 212 | "--" { return DEC_OP; } |
michael@0 | 213 | "&&" { return AND_OP; } |
michael@0 | 214 | "||" { return OR_OP; } |
michael@0 | 215 | "^^" { return XOR_OP; } |
michael@0 | 216 | "<=" { return LE_OP; } |
michael@0 | 217 | ">=" { return GE_OP; } |
michael@0 | 218 | "==" { return EQ_OP; } |
michael@0 | 219 | "!=" { return NE_OP; } |
michael@0 | 220 | "<<" { return LEFT_OP; } |
michael@0 | 221 | ">>" { return RIGHT_OP; } |
michael@0 | 222 | ";" { return SEMICOLON; } |
michael@0 | 223 | ("{"|"<%") { return LEFT_BRACE; } |
michael@0 | 224 | ("}"|"%>") { return RIGHT_BRACE; } |
michael@0 | 225 | "," { return COMMA; } |
michael@0 | 226 | ":" { return COLON; } |
michael@0 | 227 | "=" { return EQUAL; } |
michael@0 | 228 | "(" { return LEFT_PAREN; } |
michael@0 | 229 | ")" { return RIGHT_PAREN; } |
michael@0 | 230 | ("["|"<:") { return LEFT_BRACKET; } |
michael@0 | 231 | ("]"|":>") { return RIGHT_BRACKET; } |
michael@0 | 232 | "." { return DOT; } |
michael@0 | 233 | "!" { return BANG; } |
michael@0 | 234 | "-" { return DASH; } |
michael@0 | 235 | "~" { return TILDE; } |
michael@0 | 236 | "+" { return PLUS; } |
michael@0 | 237 | "*" { return STAR; } |
michael@0 | 238 | "/" { return SLASH; } |
michael@0 | 239 | "%" { return PERCENT; } |
michael@0 | 240 | "<" { return LEFT_ANGLE; } |
michael@0 | 241 | ">" { return RIGHT_ANGLE; } |
michael@0 | 242 | "|" { return VERTICAL_BAR; } |
michael@0 | 243 | "^" { return CARET; } |
michael@0 | 244 | "&" { return AMPERSAND; } |
michael@0 | 245 | "?" { return QUESTION; } |
michael@0 | 246 | |
michael@0 | 247 | [ \t\v\n\f\r] { } |
michael@0 | 248 | <<EOF>> { yyterminate(); } |
michael@0 | 249 | . { assert(false); return 0; } |
michael@0 | 250 | |
michael@0 | 251 | %% |
michael@0 | 252 | |
michael@0 | 253 | yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) { |
michael@0 | 254 | pp::Token token; |
michael@0 | 255 | yyget_extra(yyscanner)->preprocessor.lex(&token); |
michael@0 | 256 | yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size(); |
michael@0 | 257 | if (len < max_size) |
michael@0 | 258 | memcpy(buf, token.text.c_str(), len); |
michael@0 | 259 | yyset_column(token.location.file, yyscanner); |
michael@0 | 260 | yyset_lineno(token.location.line, yyscanner); |
michael@0 | 261 | |
michael@0 | 262 | if (len >= max_size) |
michael@0 | 263 | YY_FATAL_ERROR("Input buffer overflow"); |
michael@0 | 264 | else if (len > 0) |
michael@0 | 265 | buf[len++] = ' '; |
michael@0 | 266 | return len; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | int check_type(yyscan_t yyscanner) { |
michael@0 | 270 | struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; |
michael@0 | 271 | |
michael@0 | 272 | int token = IDENTIFIER; |
michael@0 | 273 | TSymbol* symbol = yyextra->symbolTable.find(yytext); |
michael@0 | 274 | if (symbol && symbol->isVariable()) { |
michael@0 | 275 | TVariable* variable = static_cast<TVariable*>(symbol); |
michael@0 | 276 | if (variable->isUserType()) |
michael@0 | 277 | token = TYPE_NAME; |
michael@0 | 278 | } |
michael@0 | 279 | yylval->lex.symbol = symbol; |
michael@0 | 280 | return token; |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | int reserved_word(yyscan_t yyscanner) { |
michael@0 | 284 | struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; |
michael@0 | 285 | |
michael@0 | 286 | yyextra->error(*yylloc, "Illegal use of reserved word", yytext, ""); |
michael@0 | 287 | yyextra->recover(); |
michael@0 | 288 | return 0; |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | int glslang_initialize(TParseContext* context) { |
michael@0 | 292 | yyscan_t scanner = NULL; |
michael@0 | 293 | if (yylex_init_extra(context, &scanner)) |
michael@0 | 294 | return 1; |
michael@0 | 295 | |
michael@0 | 296 | context->scanner = scanner; |
michael@0 | 297 | return 0; |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | int glslang_finalize(TParseContext* context) { |
michael@0 | 301 | yyscan_t scanner = context->scanner; |
michael@0 | 302 | if (scanner == NULL) return 0; |
michael@0 | 303 | |
michael@0 | 304 | context->scanner = NULL; |
michael@0 | 305 | yylex_destroy(scanner); |
michael@0 | 306 | |
michael@0 | 307 | return 0; |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | int glslang_scan(size_t count, const char* const string[], const int length[], |
michael@0 | 311 | TParseContext* context) { |
michael@0 | 312 | yyrestart(NULL, context->scanner); |
michael@0 | 313 | yyset_column(0, context->scanner); |
michael@0 | 314 | yyset_lineno(1, context->scanner); |
michael@0 | 315 | |
michael@0 | 316 | // Initialize preprocessor. |
michael@0 | 317 | if (!context->preprocessor.init(count, string, length)) |
michael@0 | 318 | return 1; |
michael@0 | 319 | |
michael@0 | 320 | // Define extension macros. |
michael@0 | 321 | const TExtensionBehavior& extBehavior = context->extensionBehavior(); |
michael@0 | 322 | for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); |
michael@0 | 323 | iter != extBehavior.end(); ++iter) { |
michael@0 | 324 | context->preprocessor.predefineMacro(iter->first.c_str(), 1); |
michael@0 | 325 | } |
michael@0 | 326 | if (context->fragmentPrecisionHigh) |
michael@0 | 327 | context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1); |
michael@0 | 328 | |
michael@0 | 329 | return 0; |
michael@0 | 330 | } |
michael@0 | 331 |