blob: 785b688b6b64b6ef045ae28efdee9b6e97448e3c [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001/*
2//
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +00003// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00007
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00008This file contains the Lex specification for GLSL ES.
9Based on ANSI C grammar, Lex specification:
10http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
alokp@chromium.org75fe6b72011-08-14 05:31:22 +000012IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh,
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000013WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000014*/
15
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000016%top{
17//
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +000018// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000019// Use of this source code is governed by a BSD-style license that can be
20// found in the LICENSE file.
21//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
alokp@chromium.org75fe6b72011-08-14 05:31:22 +000023// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
apatrick@chromium.org536888b2012-01-25 02:10:25 +000024
25// Ignore errors in auto-generated code.
26#if defined(__GNUC__)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000027#pragma GCC diagnostic ignored "-Wunused-function"
apatrick@chromium.org536888b2012-01-25 02:10:25 +000028#pragma GCC diagnostic ignored "-Wunused-variable"
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +000029#pragma GCC diagnostic ignored "-Wswitch-enum"
apatrick@chromium.org536888b2012-01-25 02:10:25 +000030#elif defined(_MSC_VER)
31#pragma warning(disable: 4065)
apatrick@chromium.orga1d80592012-01-25 21:52:10 +000032#pragma warning(disable: 4189)
33#pragma warning(disable: 4505)
34#pragma warning(disable: 4701)
apatrick@chromium.org536888b2012-01-25 02:10:25 +000035#endif
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000036}
37
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038%{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000039#include "compiler/glslang.h"
daniel@transgaming.come6842292010-04-20 18:52:50 +000040#include "compiler/ParseHelper.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000041#include "compiler/preprocessor/Token.h"
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000042#include "compiler/util.h"
alokp@chromium.orgeab1ef12010-04-23 17:33:49 +000043#include "glslang_tab.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044
45/* windows only pragma */
46#ifdef _MSC_VER
47#pragma warning(disable : 4102)
48#endif
49
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000050#define YY_USER_ACTION yylval->lex.line = yylineno;
51#define YY_INPUT(buf, result, max_size) \
52 result = string_input(buf, max_size, yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000054static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000055static int check_type(yyscan_t yyscanner);
56static int reserved_word(yyscan_t yyscanner);
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000057static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
58static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +000059static int ES2_ident_ES3_keyword(TParseContext *context, int token);
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +000060static int uint_constant(TParseContext *context);
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +000061static int floatsuffix_check(TParseContext* context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062%}
63
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000064%option noyywrap nounput never-interactive
65%option yylineno reentrant bison-bridge
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000066%option extra-type="TParseContext*"
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000067
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000068D [0-9]
69L [a-zA-Z_]
70H [a-fA-F0-9]
71E [Ee][+-]?{D}+
72O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073
74%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000076%{
77 TParseContext* context = yyextra;
78%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000079
Jamie Madill56b06512013-05-24 16:34:04 -040080"invariant" { return INVARIANT; }
81"highp" { return HIGH_PRECISION; }
82"mediump" { return MEDIUM_PRECISION; }
83"lowp" { return LOW_PRECISION; }
84"precision" { return PRECISION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000085
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000086"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
Jamie Madill56b06512013-05-24 16:34:04 -040087"const" { return CONST_QUAL; }
88"uniform" { return UNIFORM; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000089"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090
Jamie Madill56b06512013-05-24 16:34:04 -040091"break" { return BREAK; }
92"continue" { return CONTINUE; }
93"do" { return DO; }
94"for" { return FOR; }
95"while" { return WHILE; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
Jamie Madill56b06512013-05-24 16:34:04 -040097"if" { return IF; }
98"else" { return ELSE; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000099"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
100"case" { return ES2_reserved_ES3_keyword(context, CASE); }
101"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000102
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000103"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
104"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
105"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000106
Jamie Madill56b06512013-05-24 16:34:04 -0400107"in" { return IN_QUAL; }
108"out" { return OUT_QUAL; }
109"inout" { return INOUT_QUAL; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110
Jamie Madill78eb5df2013-05-24 16:34:05 -0400111"float" { return FLOAT_TYPE; }
112"int" { return INT_TYPE; }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000113"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400114"void" { return VOID_TYPE; }
115"bool" { return BOOL_TYPE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400116"true" { yylval->lex.b = true; return BOOLCONSTANT; }
117"false" { yylval->lex.b = false; return BOOLCONSTANT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
Jamie Madill56b06512013-05-24 16:34:04 -0400119"discard" { return DISCARD; }
120"return" { return RETURN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121
Jamie Madill78eb5df2013-05-24 16:34:05 -0400122"mat2" { return MATRIX2; }
123"mat3" { return MATRIX3; }
124"mat4" { return MATRIX4; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000126"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
127"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
128"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
129
130"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
131"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
132"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
133"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
134"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
135"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
136
Jamie Madill78eb5df2013-05-24 16:34:05 -0400137"vec2" { return VEC2; }
138"vec3" { return VEC3; }
139"vec4" { return VEC4; }
140"ivec2" { return IVEC2; }
141"ivec3" { return IVEC3; }
142"ivec4" { return IVEC4; }
143"bvec2" { return BVEC2; }
144"bvec3" { return BVEC3; }
145"bvec4" { return BVEC4; }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000146"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
147"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
148"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149
Jamie Madill78eb5df2013-05-24 16:34:05 -0400150"sampler2D" { return SAMPLER2D; }
151"samplerCube" { return SAMPLERCUBE; }
152"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000153"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
154"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
155"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400156"sampler2DRect" { return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000157
Jamie Madill78eb5df2013-05-24 16:34:05 -0400158"struct" { return STRUCT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000160"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
161
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000162 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
163"coherent" |
164"restrict" |
165"readonly" |
166"writeonly" |
167"resource" |
168"atomic_uint" |
169"noperspective" |
170"patch" |
171"sample" |
172"subroutine" |
173"common" |
174"partition" |
175"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000176
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000177"filter" |
178"image1D" |
179"image2D" |
180"image3D" |
181"imageCube" |
182"iimage1D" |
183"iimage2D" |
184"iimage3D" |
185"iimageCube" |
186"uimage1D" |
187"uimage2D" |
188"uimage3D" |
189"uimageCube" |
190"image1DArray" |
191"image2DArray" |
192"iimage1DArray" |
193"iimage2DArray" |
194"uimage1DArray" |
195"uimage2DArray" |
196"image1DShadow" |
197"image2DShadow" |
198"image1DArrayShadow" |
199"image2DArrayShadow" |
200"imageBuffer" |
201"iimageBuffer" |
202"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000203
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000204"sampler1DArray" |
205"sampler1DArrayShadow" |
206"isampler1D" |
207"isampler1DArray" |
208"usampler1D" |
209"usampler1DArray" |
210"isampler2DRect" |
211"usampler2DRect" |
212"samplerBuffer" |
213"isamplerBuffer" |
214"usamplerBuffer" |
215"sampler2DMS" |
216"isampler2DMS" |
217"usampler2DMS" |
218"sampler2DMSArray" |
219"isampler2DMSArray" |
220"usampler2DMSArray" {
221 if (context->shaderVersion < 300) {
222 yylval->lex.string = NewPoolTString(yytext);
223 return check_type(yyscanner);
224 }
225 return reserved_word(yyscanner);
226}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000228 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
229"packed" {
230 if (context->shaderVersion >= 300)
231 {
232 yylval->lex.string = NewPoolTString(yytext);
233 return check_type(yyscanner);
234 }
235
236 return reserved_word(yyscanner);
237}
238
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000239 /* Reserved keywords */
240"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000242"class" |
243"union" |
244"enum" |
245"typedef" |
246"template" |
247"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000249"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000250
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000251"inline" |
252"noinline" |
253"volatile" |
254"public" |
255"static" |
256"extern" |
257"external" |
258"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000259
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000260"long" |
261"short" |
262"double" |
263"half" |
264"fixed" |
265"unsigned" |
266"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000267
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000268"input" |
269"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000270
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000271"hvec2" |
272"hvec3" |
273"hvec4" |
274"dvec2" |
275"dvec3" |
276"dvec4" |
277"fvec2" |
278"fvec3" |
279"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000280
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000281"sampler1D" |
282"sampler1DShadow" |
283"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000284
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000285"sizeof" |
286"cast" |
287
288"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000289"using" { return reserved_word(yyscanner); }
290
291{L}({L}|{D})* {
292 yylval->lex.string = NewPoolTString(yytext);
293 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000294}
295
Jamie Madill56b06512013-05-24 16:34:04 -04002960[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
2970{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400298{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
299
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003000[xX]{H}+[uU] { return uint_constant(context); }
3010{O}+[uU] { return uint_constant(context); }
302{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000303
Jamie Madill56b06512013-05-24 16:34:04 -0400304{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
305{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
306"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
307
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000308{D}+{E}[fF] { return floatsuffix_check(context); }
309{D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); }
310"."{D}+({E})?[fF] { return floatsuffix_check(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000311
Jamie Madill56b06512013-05-24 16:34:04 -0400312"+=" { return ADD_ASSIGN; }
313"-=" { return SUB_ASSIGN; }
314"*=" { return MUL_ASSIGN; }
315"/=" { return DIV_ASSIGN; }
316"%=" { return MOD_ASSIGN; }
317"<<=" { return LEFT_ASSIGN; }
318">>=" { return RIGHT_ASSIGN; }
319"&=" { return AND_ASSIGN; }
320"^=" { return XOR_ASSIGN; }
321"|=" { return OR_ASSIGN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000322
Jamie Madill56b06512013-05-24 16:34:04 -0400323"++" { return INC_OP; }
324"--" { return DEC_OP; }
325"&&" { return AND_OP; }
326"||" { return OR_OP; }
327"^^" { return XOR_OP; }
328"<=" { return LE_OP; }
329">=" { return GE_OP; }
330"==" { return EQ_OP; }
331"!=" { return NE_OP; }
332"<<" { return LEFT_OP; }
333">>" { return RIGHT_OP; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400334";" { return SEMICOLON; }
335("{"|"<%") { return LEFT_BRACE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400336("}"|"%>") { return RIGHT_BRACE; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400337"," { return COMMA; }
Jamie Madill56b06512013-05-24 16:34:04 -0400338":" { return COLON; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400339"=" { return EQUAL; }
340"(" { return LEFT_PAREN; }
341")" { return RIGHT_PAREN; }
Jamie Madill56b06512013-05-24 16:34:04 -0400342("["|"<:") { return LEFT_BRACKET; }
343("]"|":>") { return RIGHT_BRACKET; }
Jamie Madillf8dc4fb2013-05-24 16:34:06 -0400344"." { return DOT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400345"!" { return BANG; }
346"-" { return DASH; }
347"~" { return TILDE; }
348"+" { return PLUS; }
349"*" { return STAR; }
350"/" { return SLASH; }
351"%" { return PERCENT; }
352"<" { return LEFT_ANGLE; }
353">" { return RIGHT_ANGLE; }
354"|" { return VERTICAL_BAR; }
355"^" { return CARET; }
356"&" { return AMPERSAND; }
357"?" { return QUESTION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000358
Jamie Madill39a8ce62013-06-13 10:30:38 -0400359[ \t\v\n\f\r] { }
Jamie Madillf8dc4fb2013-05-24 16:34:06 -0400360<<EOF>> { yyterminate(); }
361. { assert(false); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000362
363%%
364
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000365yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000366 pp::Token token;
367 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000368 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
369 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000370 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000371 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000372
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000373 if (len >= max_size)
374 YY_FATAL_ERROR("Input buffer overflow");
375 else if (len > 0)
376 buf[len++] = ' ';
377 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000378}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000379
380int check_type(yyscan_t yyscanner) {
381 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
382
383 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000384 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
Jamie Madill78eb5df2013-05-24 16:34:05 -0400385 if (symbol && symbol->isVariable()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000386 TVariable* variable = static_cast<TVariable*>(symbol);
387 if (variable->isUserType()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000388 token = TYPE_NAME;
389 }
390 }
391 yylval->lex.symbol = symbol;
392 return token;
393}
394
395int reserved_word(yyscan_t yyscanner) {
396 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
397
398 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
399 yyextra->recover();
400 return 0;
401}
402
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000403int ES2_reserved_ES3_keyword(TParseContext *context, int token)
404{
405 yyscan_t yyscanner = (yyscan_t) context->scanner;
406
407 if (context->shaderVersion < 300)
408 {
409 return reserved_word(yyscanner);
410 }
411
412 return token;
413}
414
415int ES2_keyword_ES3_reserved(TParseContext *context, int token)
416{
417 yyscan_t yyscanner = (yyscan_t) context->scanner;
418
419 if (context->shaderVersion >= 300)
420 {
421 return reserved_word(yyscanner);
422 }
423
424 return token;
425}
426
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000427int ES2_ident_ES3_keyword(TParseContext *context, int token)
428{
429 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
430 yyscan_t yyscanner = (yyscan_t) context->scanner;
431
432 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
433 if (context->shaderVersion < 300)
434 {
435 yylval->lex.string = NewPoolTString(yytext);
436 return check_type(yyscanner);
437 }
438
439 return token;
440}
441
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000442int uint_constant(TParseContext *context)
443{
444 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
445 yyscan_t yyscanner = (yyscan_t) context->scanner;
446
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000447 yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
448
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000449 if (context->shaderVersion < 300)
450 {
451 context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
452 context->recover();
453 return 0;
454 }
455
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000456 return UINTCONSTANT;
457}
458
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000459int floatsuffix_check(TParseContext* context)
460{
461 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
462
463 yylval->lex.f = static_cast<float>(atof_dot(yytext));
464
465 if (context->shaderVersion < 300)
466 {
467 context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
468 context->recover();
469 return 0;
470 }
471
472 return(FLOATCONSTANT);
473}
474
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000475void yyerror(TParseContext* context, const char* reason) {
476 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
477
Jamie Madillfe345bf2013-05-24 16:34:04 -0400478 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000479 context->recover();
480}
481
482int glslang_initialize(TParseContext* context) {
483 yyscan_t scanner = NULL;
484 if (yylex_init_extra(context, &scanner))
485 return 1;
486
487 context->scanner = scanner;
488 return 0;
489}
490
491int glslang_finalize(TParseContext* context) {
492 yyscan_t scanner = context->scanner;
493 if (scanner == NULL) return 0;
494
495 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000496 yylex_destroy(scanner);
497
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000498 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000499}
500
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000501int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000502 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000503 yyrestart(NULL, context->scanner);
504 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000505
506 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000507 if (!context->preprocessor.init(count, string, length))
508 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000509
510 // Define extension macros.
511 const TExtensionBehavior& extBehavior = context->extensionBehavior();
512 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
513 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000514 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000515 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000516 if (context->fragmentPrecisionHigh)
517 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
518
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000519 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000520}
521