blob: 5f10f0e6cabd278a22efb4045c1d108d14f364e8 [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*"
Jamie Madill7eeb9b62013-05-24 16:34:05 -040067%x FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000068
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000069D [0-9]
70L [a-zA-Z_]
71H [a-fA-F0-9]
72E [Ee][+-]?{D}+
73O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000074
75%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000077%{
78 TParseContext* context = yyextra;
79%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000080
Jamie Madill56b06512013-05-24 16:34:04 -040081"invariant" { return INVARIANT; }
82"highp" { return HIGH_PRECISION; }
83"mediump" { return MEDIUM_PRECISION; }
84"lowp" { return LOW_PRECISION; }
85"precision" { return PRECISION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000086
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000087"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
Jamie Madill56b06512013-05-24 16:34:04 -040088"const" { return CONST_QUAL; }
89"uniform" { return UNIFORM; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000090"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000091
Jamie Madill56b06512013-05-24 16:34:04 -040092"break" { return BREAK; }
93"continue" { return CONTINUE; }
94"do" { return DO; }
95"for" { return FOR; }
96"while" { return WHILE; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000097
Jamie Madill56b06512013-05-24 16:34:04 -040098"if" { return IF; }
99"else" { return ELSE; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000100"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
101"case" { return ES2_reserved_ES3_keyword(context, CASE); }
102"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000103
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000104"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
105"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
106"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000107
Jamie Madill56b06512013-05-24 16:34:04 -0400108"in" { return IN_QUAL; }
109"out" { return OUT_QUAL; }
110"inout" { return INOUT_QUAL; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111
Jamie Madill78eb5df2013-05-24 16:34:05 -0400112"float" { return FLOAT_TYPE; }
113"int" { return INT_TYPE; }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000114"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400115"void" { return VOID_TYPE; }
116"bool" { return BOOL_TYPE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400117"true" { yylval->lex.b = true; return BOOLCONSTANT; }
118"false" { yylval->lex.b = false; return BOOLCONSTANT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119
Jamie Madill56b06512013-05-24 16:34:04 -0400120"discard" { return DISCARD; }
121"return" { return RETURN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000122
Jamie Madill78eb5df2013-05-24 16:34:05 -0400123"mat2" { return MATRIX2; }
124"mat3" { return MATRIX3; }
125"mat4" { return MATRIX4; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000127"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
128"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
129"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
130
131"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
132"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
133"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
134"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
135"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
136"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
137
Jamie Madill78eb5df2013-05-24 16:34:05 -0400138"vec2" { return VEC2; }
139"vec3" { return VEC3; }
140"vec4" { return VEC4; }
141"ivec2" { return IVEC2; }
142"ivec3" { return IVEC3; }
143"ivec4" { return IVEC4; }
144"bvec2" { return BVEC2; }
145"bvec3" { return BVEC3; }
146"bvec4" { return BVEC4; }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000147"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
148"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
149"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150
Jamie Madill78eb5df2013-05-24 16:34:05 -0400151"sampler2D" { return SAMPLER2D; }
152"samplerCube" { return SAMPLERCUBE; }
153"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000154"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
155"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
156"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400157"sampler2DRect" { return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158
Jamie Madill78eb5df2013-05-24 16:34:05 -0400159"struct" { return STRUCT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000161"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
162
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000163 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
164"coherent" |
165"restrict" |
166"readonly" |
167"writeonly" |
168"resource" |
169"atomic_uint" |
170"noperspective" |
171"patch" |
172"sample" |
173"subroutine" |
174"common" |
175"partition" |
176"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000177
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000178"filter" |
179"image1D" |
180"image2D" |
181"image3D" |
182"imageCube" |
183"iimage1D" |
184"iimage2D" |
185"iimage3D" |
186"iimageCube" |
187"uimage1D" |
188"uimage2D" |
189"uimage3D" |
190"uimageCube" |
191"image1DArray" |
192"image2DArray" |
193"iimage1DArray" |
194"iimage2DArray" |
195"uimage1DArray" |
196"uimage2DArray" |
197"image1DShadow" |
198"image2DShadow" |
199"image1DArrayShadow" |
200"image2DArrayShadow" |
201"imageBuffer" |
202"iimageBuffer" |
203"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000204
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000205"sampler1DArray" |
206"sampler1DArrayShadow" |
207"isampler1D" |
208"isampler1DArray" |
209"usampler1D" |
210"usampler1DArray" |
211"isampler2DRect" |
212"usampler2DRect" |
213"samplerBuffer" |
214"isamplerBuffer" |
215"usamplerBuffer" |
216"sampler2DMS" |
217"isampler2DMS" |
218"usampler2DMS" |
219"sampler2DMSArray" |
220"isampler2DMSArray" |
221"usampler2DMSArray" {
222 if (context->shaderVersion < 300) {
223 yylval->lex.string = NewPoolTString(yytext);
224 return check_type(yyscanner);
225 }
226 return reserved_word(yyscanner);
227}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000229 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
230"packed" {
231 if (context->shaderVersion >= 300)
232 {
233 yylval->lex.string = NewPoolTString(yytext);
234 return check_type(yyscanner);
235 }
236
237 return reserved_word(yyscanner);
238}
239
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000240 /* Reserved keywords */
241"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000242
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000243"class" |
244"union" |
245"enum" |
246"typedef" |
247"template" |
248"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000249
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000250"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000252"inline" |
253"noinline" |
254"volatile" |
255"public" |
256"static" |
257"extern" |
258"external" |
259"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000260
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000261"long" |
262"short" |
263"double" |
264"half" |
265"fixed" |
266"unsigned" |
267"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000268
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000269"input" |
270"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000271
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000272"hvec2" |
273"hvec3" |
274"hvec4" |
275"dvec2" |
276"dvec3" |
277"dvec4" |
278"fvec2" |
279"fvec3" |
280"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000281
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000282"sampler1D" |
283"sampler1DShadow" |
284"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000285
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000286"sizeof" |
287"cast" |
288
289"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000290"using" { return reserved_word(yyscanner); }
291
292{L}({L}|{D})* {
293 yylval->lex.string = NewPoolTString(yytext);
294 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295}
296
Jamie Madill56b06512013-05-24 16:34:04 -04002970[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
2980{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
Jamie Madill56b06512013-05-24 16:34:04 -0400299{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
300
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003010[xX]{H}+[uU] { return uint_constant(context); }
3020{O}+[uU] { return uint_constant(context); }
303{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000304
Jamie Madill56b06512013-05-24 16:34:04 -0400305{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
306{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
307"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
308
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000309{D}+{E}[fF] { return floatsuffix_check(context); }
310{D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); }
311"."{D}+({E})?[fF] { return floatsuffix_check(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000312
Jamie Madill56b06512013-05-24 16:34:04 -0400313"+=" { return ADD_ASSIGN; }
314"-=" { return SUB_ASSIGN; }
315"*=" { return MUL_ASSIGN; }
316"/=" { return DIV_ASSIGN; }
317"%=" { return MOD_ASSIGN; }
318"<<=" { return LEFT_ASSIGN; }
319">>=" { return RIGHT_ASSIGN; }
320"&=" { return AND_ASSIGN; }
321"^=" { return XOR_ASSIGN; }
322"|=" { return OR_ASSIGN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323
Jamie Madill56b06512013-05-24 16:34:04 -0400324"++" { return INC_OP; }
325"--" { return DEC_OP; }
326"&&" { return AND_OP; }
327"||" { return OR_OP; }
328"^^" { return XOR_OP; }
329"<=" { return LE_OP; }
330">=" { return GE_OP; }
331"==" { return EQ_OP; }
332"!=" { return NE_OP; }
333"<<" { return LEFT_OP; }
334">>" { return RIGHT_OP; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400335";" { return SEMICOLON; }
336("{"|"<%") { return LEFT_BRACE; }
Jamie Madill56b06512013-05-24 16:34:04 -0400337("}"|"%>") { return RIGHT_BRACE; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400338"," { return COMMA; }
Jamie Madill56b06512013-05-24 16:34:04 -0400339":" { return COLON; }
Jamie Madill78eb5df2013-05-24 16:34:05 -0400340"=" { return EQUAL; }
341"(" { return LEFT_PAREN; }
342")" { return RIGHT_PAREN; }
Jamie Madill56b06512013-05-24 16:34:04 -0400343("["|"<:") { return LEFT_BRACKET; }
344("]"|":>") { return RIGHT_BRACKET; }
345"." { BEGIN(FIELDS); return DOT; }
346"!" { return BANG; }
347"-" { return DASH; }
348"~" { return TILDE; }
349"+" { return PLUS; }
350"*" { return STAR; }
351"/" { return SLASH; }
352"%" { return PERCENT; }
353"<" { return LEFT_ANGLE; }
354">" { return RIGHT_ANGLE; }
355"|" { return VERTICAL_BAR; }
356"^" { return CARET; }
357"&" { return AMPERSAND; }
358"?" { return QUESTION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000359
360<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000361 BEGIN(INITIAL);
362 yylval->lex.string = NewPoolTString(yytext);
363 return FIELD_SELECTION;
364}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000365<FIELDS>[ \t\v\f\r] {}
366
Jamie Madill39a8ce62013-06-13 10:30:38 -0400367[ \t\v\n\f\r] { }
368<*><<EOF>> { yyterminate(); }
369<*>. { assert(false); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000370
371%%
372
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000373yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000374 pp::Token token;
375 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000376 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
377 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000378 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000379 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000380
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000381 if (len >= max_size)
382 YY_FATAL_ERROR("Input buffer overflow");
383 else if (len > 0)
384 buf[len++] = ' ';
385 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000386}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000387
388int check_type(yyscan_t yyscanner) {
389 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
390
391 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000392 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
Jamie Madill78eb5df2013-05-24 16:34:05 -0400393 if (symbol && symbol->isVariable()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000394 TVariable* variable = static_cast<TVariable*>(symbol);
395 if (variable->isUserType()) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000396 token = TYPE_NAME;
397 }
398 }
399 yylval->lex.symbol = symbol;
400 return token;
401}
402
403int reserved_word(yyscan_t yyscanner) {
404 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
405
406 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
407 yyextra->recover();
408 return 0;
409}
410
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000411int ES2_reserved_ES3_keyword(TParseContext *context, int token)
412{
413 yyscan_t yyscanner = (yyscan_t) context->scanner;
414
415 if (context->shaderVersion < 300)
416 {
417 return reserved_word(yyscanner);
418 }
419
420 return token;
421}
422
423int ES2_keyword_ES3_reserved(TParseContext *context, int token)
424{
425 yyscan_t yyscanner = (yyscan_t) context->scanner;
426
427 if (context->shaderVersion >= 300)
428 {
429 return reserved_word(yyscanner);
430 }
431
432 return token;
433}
434
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000435int ES2_ident_ES3_keyword(TParseContext *context, int token)
436{
437 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
438 yyscan_t yyscanner = (yyscan_t) context->scanner;
439
440 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
441 if (context->shaderVersion < 300)
442 {
443 yylval->lex.string = NewPoolTString(yytext);
444 return check_type(yyscanner);
445 }
446
447 return token;
448}
449
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000450int uint_constant(TParseContext *context)
451{
452 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
453 yyscan_t yyscanner = (yyscan_t) context->scanner;
454
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000455 yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
456
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000457 if (context->shaderVersion < 300)
458 {
459 context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
460 context->recover();
461 return 0;
462 }
463
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000464 return UINTCONSTANT;
465}
466
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000467int floatsuffix_check(TParseContext* context)
468{
469 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
470
471 yylval->lex.f = static_cast<float>(atof_dot(yytext));
472
473 if (context->shaderVersion < 300)
474 {
475 context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
476 context->recover();
477 return 0;
478 }
479
480 return(FLOATCONSTANT);
481}
482
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000483void yyerror(TParseContext* context, const char* reason) {
484 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
485
Jamie Madillfe345bf2013-05-24 16:34:04 -0400486 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000487 context->recover();
488}
489
490int 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);
512 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000513
514 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000515 if (!context->preprocessor.init(count, string, length))
516 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000517
518 // Define extension macros.
519 const TExtensionBehavior& extBehavior = context->extensionBehavior();
520 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
521 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000522 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000523 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000524 if (context->fragmentPrecisionHigh)
525 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
526
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000527 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000528}
529