blob: 3e37db0d889e746934d000110038ebf71495df7d [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
Jamie Madill075edd82013-07-08 13:30:19 -040050#define YY_USER_ACTION \
51 yylloc->first_file = yylloc->last_file = yycolumn; \
52 yylloc->first_line = yylloc->last_line = yylineno;
53
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000054#define YY_INPUT(buf, result, max_size) \
55 result = string_input(buf, max_size, yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +000057static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000058static int check_type(yyscan_t yyscanner);
59static int reserved_word(yyscan_t yyscanner);
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000060static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
61static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +000062static int ES2_ident_ES3_keyword(TParseContext *context, int token);
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +000063static int uint_constant(TParseContext *context);
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +000064static int floatsuffix_check(TParseContext* context);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000065%}
66
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000067%option noyywrap nounput never-interactive
Jamie Madill075edd82013-07-08 13:30:19 -040068%option yylineno reentrant bison-bridge bison-locations
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000069%option extra-type="TParseContext*"
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000070
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000071D [0-9]
72L [a-zA-Z_]
73H [a-fA-F0-9]
74E [Ee][+-]?{D}+
75O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076
77%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000079%{
80 TParseContext* context = yyextra;
81%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082
Jamie Madill56b06512013-05-24 16:34:04 -040083"invariant" { return INVARIANT; }
84"highp" { return HIGH_PRECISION; }
85"mediump" { return MEDIUM_PRECISION; }
86"lowp" { return LOW_PRECISION; }
87"precision" { return PRECISION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000088
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000089"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
Jamie Madill56b06512013-05-24 16:34:04 -040090"const" { return CONST_QUAL; }
91"uniform" { return UNIFORM; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000092"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000093
Jamie Madill56b06512013-05-24 16:34:04 -040094"break" { return BREAK; }
95"continue" { return CONTINUE; }
96"do" { return DO; }
97"for" { return FOR; }
98"while" { return WHILE; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
Jamie Madill56b06512013-05-24 16:34:04 -0400100"if" { return IF; }
101"else" { return ELSE; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000102"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
103"case" { return ES2_reserved_ES3_keyword(context, CASE); }
104"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000105
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000106"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
107"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
108"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109
Jamie Madill56b06512013-05-24 16:34:04 -0400110"in" { return IN_QUAL; }
111"out" { return OUT_QUAL; }
112"inout" { return INOUT_QUAL; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000113
Jamie Madill78eb5df2013-05-24 16:34:05 -0400114"float" { return FLOAT_TYPE; }
115"int" { return INT_TYPE; }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000116"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400117"void" { return VOID_TYPE; }
118"bool" { return BOOL_TYPE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400119"true" { yylval->lex.b = true; return BOOLCONSTANT; }
120"false" { yylval->lex.b = false; return BOOLCONSTANT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121
Jamie Madill56b06512013-05-24 16:34:04 -0400122"discard" { return DISCARD; }
123"return" { return RETURN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124
Jamie Madill78eb5df2013-05-24 16:34:05 -0400125"mat2" { return MATRIX2; }
126"mat3" { return MATRIX3; }
127"mat4" { return MATRIX4; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000128
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000129"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
130"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
131"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
132
133"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
134"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
135"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
136"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
137"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
138"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
139
Jamie Madill78eb5df2013-05-24 16:34:05 -0400140"vec2" { return VEC2; }
141"vec3" { return VEC3; }
142"vec4" { return VEC4; }
143"ivec2" { return IVEC2; }
144"ivec3" { return IVEC3; }
145"ivec4" { return IVEC4; }
146"bvec2" { return BVEC2; }
147"bvec3" { return BVEC3; }
148"bvec4" { return BVEC4; }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000149"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
150"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
151"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000152
Nicolas Capens2a1d8a32013-07-18 11:49:40 -0400153"sampler2D" { return SAMPLER2D; }
154"samplerCube" { return SAMPLERCUBE; }
155"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
156"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
157"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
158"sampler2DRect" { return SAMPLER2DRECT; }
159"sampler2DArray" { return ES2_ident_ES3_keyword(context, SAMPLER2DARRAY); }
160"isampler2D" { return ES2_ident_ES3_keyword(context, ISAMPLER2D); }
161"isampler3D" { return ES2_ident_ES3_keyword(context, ISAMPLER3D); }
162"isamplerCube" { return ES2_ident_ES3_keyword(context, ISAMPLERCUBE); }
163"isampler2DArray" { return ES2_ident_ES3_keyword(context, ISAMPLER2DARRAY); }
164"usampler2D" { return ES2_ident_ES3_keyword(context, USAMPLER2D); }
165"usampler3D" { return ES2_ident_ES3_keyword(context, USAMPLER3D); }
166"usamplerCube" { return ES2_ident_ES3_keyword(context, USAMPLERCUBE); }
167"usampler2DArray" { return ES2_ident_ES3_keyword(context, USAMPLER2DARRAY); }
168"sampler2DShadow" { return ES2_ident_ES3_keyword(context, SAMPLER2DSHADOW); }
169"samplerCubeShadow" { return ES2_ident_ES3_keyword(context, SAMPLERCUBESHADOW); }
170"sampler2DArrayShadow" { return ES2_ident_ES3_keyword(context, SAMPLER2DARRAYSHADOW); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000171
Jamie Madill78eb5df2013-05-24 16:34:05 -0400172"struct" { return STRUCT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000173
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000174"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
175
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000176 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
177"coherent" |
178"restrict" |
179"readonly" |
180"writeonly" |
181"resource" |
182"atomic_uint" |
183"noperspective" |
184"patch" |
185"sample" |
186"subroutine" |
187"common" |
188"partition" |
189"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000190
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000191"filter" |
192"image1D" |
193"image2D" |
194"image3D" |
195"imageCube" |
196"iimage1D" |
197"iimage2D" |
198"iimage3D" |
199"iimageCube" |
200"uimage1D" |
201"uimage2D" |
202"uimage3D" |
203"uimageCube" |
204"image1DArray" |
205"image2DArray" |
206"iimage1DArray" |
207"iimage2DArray" |
208"uimage1DArray" |
209"uimage2DArray" |
210"image1DShadow" |
211"image2DShadow" |
212"image1DArrayShadow" |
213"image2DArrayShadow" |
214"imageBuffer" |
215"iimageBuffer" |
216"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000217
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000218"sampler1DArray" |
219"sampler1DArrayShadow" |
220"isampler1D" |
221"isampler1DArray" |
222"usampler1D" |
223"usampler1DArray" |
224"isampler2DRect" |
225"usampler2DRect" |
226"samplerBuffer" |
227"isamplerBuffer" |
228"usamplerBuffer" |
229"sampler2DMS" |
230"isampler2DMS" |
231"usampler2DMS" |
232"sampler2DMSArray" |
233"isampler2DMSArray" |
234"usampler2DMSArray" {
235 if (context->shaderVersion < 300) {
236 yylval->lex.string = NewPoolTString(yytext);
237 return check_type(yyscanner);
238 }
239 return reserved_word(yyscanner);
240}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000242 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
243"packed" {
244 if (context->shaderVersion >= 300)
245 {
246 yylval->lex.string = NewPoolTString(yytext);
247 return check_type(yyscanner);
248 }
249
250 return reserved_word(yyscanner);
251}
252
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000253 /* Reserved keywords */
254"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000255
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000256"class" |
257"union" |
258"enum" |
259"typedef" |
260"template" |
261"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000263"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000265"inline" |
266"noinline" |
267"volatile" |
268"public" |
269"static" |
270"extern" |
271"external" |
272"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000273
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000274"long" |
275"short" |
276"double" |
277"half" |
278"fixed" |
279"unsigned" |
280"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000281
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000282"input" |
283"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000284
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000285"hvec2" |
286"hvec3" |
287"hvec4" |
288"dvec2" |
289"dvec3" |
290"dvec4" |
291"fvec2" |
292"fvec3" |
293"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000294
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000295"sampler1D" |
296"sampler1DShadow" |
297"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000298
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000299"sizeof" |
300"cast" |
301
302"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000303"using" { return reserved_word(yyscanner); }
304
305{L}({L}|{D})* {
306 yylval->lex.string = NewPoolTString(yytext);
307 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308}
309
Jamie Madill56b06512013-05-24 16:34:04 -04003100[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
3110{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400312{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
313
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003140[xX]{H}+[uU] { return uint_constant(context); }
3150{O}+[uU] { return uint_constant(context); }
316{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000317
Jamie Madill56b06512013-05-24 16:34:04 -0400318{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
319{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
320"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
321
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000322{D}+{E}[fF] { return floatsuffix_check(context); }
323{D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); }
324"."{D}+({E})?[fF] { return floatsuffix_check(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000325
Jamie Madill56b06512013-05-24 16:34:04 -0400326"+=" { return ADD_ASSIGN; }
327"-=" { return SUB_ASSIGN; }
328"*=" { return MUL_ASSIGN; }
329"/=" { return DIV_ASSIGN; }
330"%=" { return MOD_ASSIGN; }
331"<<=" { return LEFT_ASSIGN; }
332">>=" { return RIGHT_ASSIGN; }
333"&=" { return AND_ASSIGN; }
334"^=" { return XOR_ASSIGN; }
335"|=" { return OR_ASSIGN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336
Jamie Madill56b06512013-05-24 16:34:04 -0400337"++" { return INC_OP; }
338"--" { return DEC_OP; }
339"&&" { return AND_OP; }
340"||" { return OR_OP; }
341"^^" { return XOR_OP; }
342"<=" { return LE_OP; }
343">=" { return GE_OP; }
344"==" { return EQ_OP; }
345"!=" { return NE_OP; }
346"<<" { return LEFT_OP; }
347">>" { return RIGHT_OP; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400348";" { return SEMICOLON; }
349("{"|"<%") { return LEFT_BRACE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400350("}"|"%>") { return RIGHT_BRACE; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400351"," { return COMMA; }
Jamie Madill56b06512013-05-24 16:34:04 -0400352":" { return COLON; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400353"=" { return EQUAL; }
354"(" { return LEFT_PAREN; }
355")" { return RIGHT_PAREN; }
Jamie Madill56b06512013-05-24 16:34:04 -0400356("["|"<:") { return LEFT_BRACKET; }
357("]"|":>") { return RIGHT_BRACKET; }
Jamie Madillf8dc4fb2013-05-24 16:34:06 -0400358"." { return DOT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400359"!" { return BANG; }
360"-" { return DASH; }
361"~" { return TILDE; }
362"+" { return PLUS; }
363"*" { return STAR; }
364"/" { return SLASH; }
365"%" { return PERCENT; }
366"<" { return LEFT_ANGLE; }
367">" { return RIGHT_ANGLE; }
368"|" { return VERTICAL_BAR; }
369"^" { return CARET; }
370"&" { return AMPERSAND; }
371"?" { return QUESTION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372
Jamie Madill39a8ce62013-06-13 10:30:38 -0400373[ \t\v\n\f\r] { }
Jamie Madillf8dc4fb2013-05-24 16:34:06 -0400374<<EOF>> { yyterminate(); }
375. { assert(false); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000376
377%%
378
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000379yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000380 pp::Token token;
381 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000382 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
383 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000384 memcpy(buf, token.text.c_str(), len);
Jamie Madill075edd82013-07-08 13:30:19 -0400385 yyset_column(token.location.file, yyscanner);
386 yyset_lineno(token.location.line, yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000387
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000388 if (len >= max_size)
389 YY_FATAL_ERROR("Input buffer overflow");
390 else if (len > 0)
391 buf[len++] = ' ';
392 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000393}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000394
395int check_type(yyscan_t yyscanner) {
396 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
397
398 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000399 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
Jamie Madill78eb5df2013-05-24 16:34:05 -0400400 if (symbol && symbol->isVariable()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000401 TVariable* variable = static_cast<TVariable*>(symbol);
402 if (variable->isUserType()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000403 token = TYPE_NAME;
404 }
405 }
406 yylval->lex.symbol = symbol;
407 return token;
408}
409
410int reserved_word(yyscan_t yyscanner) {
411 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
412
Jamie Madill075edd82013-07-08 13:30:19 -0400413 yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000414 yyextra->recover();
415 return 0;
416}
417
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000418int ES2_reserved_ES3_keyword(TParseContext *context, int token)
419{
420 yyscan_t yyscanner = (yyscan_t) context->scanner;
421
422 if (context->shaderVersion < 300)
423 {
424 return reserved_word(yyscanner);
425 }
426
427 return token;
428}
429
430int ES2_keyword_ES3_reserved(TParseContext *context, int token)
431{
432 yyscan_t yyscanner = (yyscan_t) context->scanner;
433
434 if (context->shaderVersion >= 300)
435 {
436 return reserved_word(yyscanner);
437 }
438
439 return token;
440}
441
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000442int ES2_ident_ES3_keyword(TParseContext *context, int token)
443{
444 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
445 yyscan_t yyscanner = (yyscan_t) context->scanner;
446
447 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
448 if (context->shaderVersion < 300)
449 {
450 yylval->lex.string = NewPoolTString(yytext);
451 return check_type(yyscanner);
452 }
453
454 return token;
455}
456
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000457int uint_constant(TParseContext *context)
458{
459 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
460 yyscan_t yyscanner = (yyscan_t) context->scanner;
461
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000462 yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
463
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000464 if (context->shaderVersion < 300)
465 {
Jamie Madill075edd82013-07-08 13:30:19 -0400466 context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000467 context->recover();
468 return 0;
469 }
470
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000471 return UINTCONSTANT;
472}
473
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000474int floatsuffix_check(TParseContext* context)
475{
476 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
477
478 yylval->lex.f = static_cast<float>(atof_dot(yytext));
479
480 if (context->shaderVersion < 300)
481 {
Jamie Madill075edd82013-07-08 13:30:19 -0400482 context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000483 context->recover();
484 return 0;
485 }
486
487 return(FLOATCONSTANT);
488}
489
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000490int glslang_initialize(TParseContext* context) {
491 yyscan_t scanner = NULL;
492 if (yylex_init_extra(context, &scanner))
493 return 1;
494
495 context->scanner = scanner;
496 return 0;
497}
498
499int glslang_finalize(TParseContext* context) {
500 yyscan_t scanner = context->scanner;
501 if (scanner == NULL) return 0;
502
503 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000504 yylex_destroy(scanner);
505
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000506 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000507}
508
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000509int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000510 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000511 yyrestart(NULL, context->scanner);
Jamie Madill075edd82013-07-08 13:30:19 -0400512 yyset_column(0, context->scanner);
513 yyset_lineno(1, context->scanner);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000514
515 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000516 if (!context->preprocessor.init(count, string, length))
517 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000518
519 // Define extension macros.
520 const TExtensionBehavior& extBehavior = context->extensionBehavior();
521 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
522 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000523 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000524 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000525 if (context->fragmentPrecisionHigh)
526 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
527
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000528 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000529}
530