blob: 93ebb4490bdeecb79f131a1dd555b9406af11d0f [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
66%option stack
67%option extra-type="TParseContext*"
68%x COMMENT FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000069
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000070D [0-9]
71L [a-zA-Z_]
72H [a-fA-F0-9]
73E [Ee][+-]?{D}+
74O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075
76%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000078%{
79 TParseContext* context = yyextra;
80%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000081
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000082 /* Single-line comments */
83"//"[^\n]* ;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000084
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000085 /* Multi-line comments */
86"/*" { yy_push_state(COMMENT, yyscanner); }
87<COMMENT>. |
88<COMMENT>\n ;
89<COMMENT>"*/" { yy_pop_state(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090
Jamie Madill56b06512013-05-24 16:34:04 -040091"invariant" { return INVARIANT; }
92"highp" { return HIGH_PRECISION; }
93"mediump" { return MEDIUM_PRECISION; }
94"lowp" { return LOW_PRECISION; }
95"precision" { return PRECISION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000097"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
Jamie Madill56b06512013-05-24 16:34:04 -040098"const" { return CONST_QUAL; }
99"uniform" { return UNIFORM; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000100"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101
Jamie Madill56b06512013-05-24 16:34:04 -0400102"break" { return BREAK; }
103"continue" { return CONTINUE; }
104"do" { return DO; }
105"for" { return FOR; }
106"while" { return WHILE; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000107
Jamie Madill56b06512013-05-24 16:34:04 -0400108"if" { return IF; }
109"else" { return ELSE; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000110"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
111"case" { return ES2_reserved_ES3_keyword(context, CASE); }
112"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000113
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000114"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
115"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
116"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000117
Jamie Madill56b06512013-05-24 16:34:04 -0400118"in" { return IN_QUAL; }
119"out" { return OUT_QUAL; }
120"inout" { return INOUT_QUAL; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121
Jamie Madill56b06512013-05-24 16:34:04 -0400122"float" { context->lexAfterType = true; return FLOAT_TYPE; }
123"int" { context->lexAfterType = true; return INT_TYPE; }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000124"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
Jamie Madill56b06512013-05-24 16:34:04 -0400125"void" { context->lexAfterType = true; return VOID_TYPE; }
126"bool" { context->lexAfterType = true; return BOOL_TYPE; }
127"true" { yylval->lex.b = true; return BOOLCONSTANT; }
128"false" { yylval->lex.b = false; return BOOLCONSTANT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000129
Jamie Madill56b06512013-05-24 16:34:04 -0400130"discard" { return DISCARD; }
131"return" { return RETURN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132
Jamie Madill56b06512013-05-24 16:34:04 -0400133"mat2" { context->lexAfterType = true; return MATRIX2; }
134"mat3" { context->lexAfterType = true; return MATRIX3; }
135"mat4" { context->lexAfterType = true; return MATRIX4; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000136
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000137"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
138"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
139"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
140
141"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
142"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
143"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
144"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
145"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
146"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
147
Jamie Madill56b06512013-05-24 16:34:04 -0400148"vec2" { context->lexAfterType = true; return VEC2; }
149"vec3" { context->lexAfterType = true; return VEC3; }
150"vec4" { context->lexAfterType = true; return VEC4; }
151"ivec2" { context->lexAfterType = true; return IVEC2; }
152"ivec3" { context->lexAfterType = true; return IVEC3; }
153"ivec4" { context->lexAfterType = true; return IVEC4; }
154"bvec2" { context->lexAfterType = true; return BVEC2; }
155"bvec3" { context->lexAfterType = true; return BVEC3; }
156"bvec4" { context->lexAfterType = true; return BVEC4; }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000157"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
158"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
159"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000160
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000161"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
162"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000163"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000164"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
165"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
166"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000167"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000168
Jamie Madill56b06512013-05-24 16:34:04 -0400169"struct" { context->lexAfterType = true; return STRUCT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000170
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000171"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
172
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000173 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
174"coherent" |
175"restrict" |
176"readonly" |
177"writeonly" |
178"resource" |
179"atomic_uint" |
180"noperspective" |
181"patch" |
182"sample" |
183"subroutine" |
184"common" |
185"partition" |
186"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000188"filter" |
189"image1D" |
190"image2D" |
191"image3D" |
192"imageCube" |
193"iimage1D" |
194"iimage2D" |
195"iimage3D" |
196"iimageCube" |
197"uimage1D" |
198"uimage2D" |
199"uimage3D" |
200"uimageCube" |
201"image1DArray" |
202"image2DArray" |
203"iimage1DArray" |
204"iimage2DArray" |
205"uimage1DArray" |
206"uimage2DArray" |
207"image1DShadow" |
208"image2DShadow" |
209"image1DArrayShadow" |
210"image2DArrayShadow" |
211"imageBuffer" |
212"iimageBuffer" |
213"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000215"sampler1DArray" |
216"sampler1DArrayShadow" |
217"isampler1D" |
218"isampler1DArray" |
219"usampler1D" |
220"usampler1DArray" |
221"isampler2DRect" |
222"usampler2DRect" |
223"samplerBuffer" |
224"isamplerBuffer" |
225"usamplerBuffer" |
226"sampler2DMS" |
227"isampler2DMS" |
228"usampler2DMS" |
229"sampler2DMSArray" |
230"isampler2DMSArray" |
231"usampler2DMSArray" {
232 if (context->shaderVersion < 300) {
233 yylval->lex.string = NewPoolTString(yytext);
234 return check_type(yyscanner);
235 }
236 return reserved_word(yyscanner);
237}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000238
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000239 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
240"packed" {
241 if (context->shaderVersion >= 300)
242 {
243 yylval->lex.string = NewPoolTString(yytext);
244 return check_type(yyscanner);
245 }
246
247 return reserved_word(yyscanner);
248}
249
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000250 /* Reserved keywords */
251"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000252
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000253"class" |
254"union" |
255"enum" |
256"typedef" |
257"template" |
258"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000259
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000260"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000261
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000262"inline" |
263"noinline" |
264"volatile" |
265"public" |
266"static" |
267"extern" |
268"external" |
269"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000270
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000271"long" |
272"short" |
273"double" |
274"half" |
275"fixed" |
276"unsigned" |
277"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000278
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000279"input" |
280"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000281
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000282"hvec2" |
283"hvec3" |
284"hvec4" |
285"dvec2" |
286"dvec3" |
287"dvec4" |
288"fvec2" |
289"fvec3" |
290"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000291
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000292"sampler1D" |
293"sampler1DShadow" |
294"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000295
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000296"sizeof" |
297"cast" |
298
299"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000300"using" { return reserved_word(yyscanner); }
301
302{L}({L}|{D})* {
303 yylval->lex.string = NewPoolTString(yytext);
304 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305}
306
Jamie Madill56b06512013-05-24 16:34:04 -04003070[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
3080{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00003090{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
Jamie Madill56b06512013-05-24 16:34:04 -0400310{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
311
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003120[xX]{H}+[uU] { return uint_constant(context); }
3130{O}+[uU] { return uint_constant(context); }
314{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000315
Jamie Madill56b06512013-05-24 16:34:04 -0400316{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
317{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
318"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
319
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000320{D}+{E}[fF] { return floatsuffix_check(context); }
321{D}+"."{D}*({E})?[fF] { return floatsuffix_check(context); }
322"."{D}+({E})?[fF] { return floatsuffix_check(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323
Jamie Madill56b06512013-05-24 16:34:04 -0400324"+=" { return ADD_ASSIGN; }
325"-=" { return SUB_ASSIGN; }
326"*=" { return MUL_ASSIGN; }
327"/=" { return DIV_ASSIGN; }
328"%=" { return MOD_ASSIGN; }
329"<<=" { return LEFT_ASSIGN; }
330">>=" { return RIGHT_ASSIGN; }
331"&=" { return AND_ASSIGN; }
332"^=" { return XOR_ASSIGN; }
333"|=" { return OR_ASSIGN; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334
Jamie Madill56b06512013-05-24 16:34:04 -0400335"++" { return INC_OP; }
336"--" { return DEC_OP; }
337"&&" { return AND_OP; }
338"||" { return OR_OP; }
339"^^" { return XOR_OP; }
340"<=" { return LE_OP; }
341">=" { return GE_OP; }
342"==" { return EQ_OP; }
343"!=" { return NE_OP; }
344"<<" { return LEFT_OP; }
345">>" { return RIGHT_OP; }
346";" { context->lexAfterType = false; return SEMICOLON; }
347("{"|"<%") { context->lexAfterType = false; return LEFT_BRACE; }
348("}"|"%>") { return RIGHT_BRACE; }
349"," { if (context->inTypeParen) context->lexAfterType = false; return COMMA; }
350":" { return COLON; }
351"=" { context->lexAfterType = false; return EQUAL; }
352"(" { context->lexAfterType = false; context->inTypeParen = true; return LEFT_PAREN; }
353")" { context->inTypeParen = false; return RIGHT_PAREN; }
354("["|"<:") { return LEFT_BRACKET; }
355("]"|":>") { return RIGHT_BRACKET; }
356"." { BEGIN(FIELDS); return DOT; }
357"!" { return BANG; }
358"-" { return DASH; }
359"~" { return TILDE; }
360"+" { return PLUS; }
361"*" { return STAR; }
362"/" { return SLASH; }
363"%" { return PERCENT; }
364"<" { return LEFT_ANGLE; }
365">" { return RIGHT_ANGLE; }
366"|" { return VERTICAL_BAR; }
367"^" { return CARET; }
368"&" { return AMPERSAND; }
369"?" { return QUESTION; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000370
371<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000372 BEGIN(INITIAL);
373 yylval->lex.string = NewPoolTString(yytext);
374 return FIELD_SELECTION;
375}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000376<FIELDS>[ \t\v\f\r] {}
377
378[ \t\v\n\f\r] { }
Jamie Madillfe345bf2013-05-24 16:34:04 -0400379<*><<EOF>> { yyterminate(); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000380<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000381
382%%
383
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000384yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000385 pp::Token token;
386 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000387 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
388 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000389 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000390 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000391
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000392 if (len >= max_size)
393 YY_FATAL_ERROR("Input buffer overflow");
394 else if (len > 0)
395 buf[len++] = ' ';
396 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000398
399int check_type(yyscan_t yyscanner) {
400 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
401
402 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000403 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000404 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
405 TVariable* variable = static_cast<TVariable*>(symbol);
406 if (variable->isUserType()) {
407 yyextra->lexAfterType = true;
408 token = TYPE_NAME;
409 }
410 }
411 yylval->lex.symbol = symbol;
412 return token;
413}
414
415int reserved_word(yyscan_t yyscanner) {
416 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
417
418 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
419 yyextra->recover();
420 return 0;
421}
422
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000423int ES2_reserved_ES3_keyword(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
435int ES2_keyword_ES3_reserved(TParseContext *context, int token)
436{
437 yyscan_t yyscanner = (yyscan_t) context->scanner;
438
439 if (context->shaderVersion >= 300)
440 {
441 return reserved_word(yyscanner);
442 }
443
444 return token;
445}
446
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000447int ES2_ident_ES3_keyword(TParseContext *context, int token)
448{
449 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
450 yyscan_t yyscanner = (yyscan_t) context->scanner;
451
452 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
453 if (context->shaderVersion < 300)
454 {
455 yylval->lex.string = NewPoolTString(yytext);
456 return check_type(yyscanner);
457 }
458
459 return token;
460}
461
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000462int uint_constant(TParseContext *context)
463{
464 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
465 yyscan_t yyscanner = (yyscan_t) context->scanner;
466
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000467 yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
468
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000469 if (context->shaderVersion < 300)
470 {
471 context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
472 context->recover();
473 return 0;
474 }
475
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000476 return UINTCONSTANT;
477}
478
shannonwoods@chromium.org4d20a842013-05-30 00:21:48 +0000479int floatsuffix_check(TParseContext* context)
480{
481 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
482
483 yylval->lex.f = static_cast<float>(atof_dot(yytext));
484
485 if (context->shaderVersion < 300)
486 {
487 context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
488 context->recover();
489 return 0;
490 }
491
492 return(FLOATCONSTANT);
493}
494
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000495void yyerror(TParseContext* context, const char* reason) {
496 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
497
Jamie Madillfe345bf2013-05-24 16:34:04 -0400498 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000499 context->recover();
500}
501
502int glslang_initialize(TParseContext* context) {
503 yyscan_t scanner = NULL;
504 if (yylex_init_extra(context, &scanner))
505 return 1;
506
507 context->scanner = scanner;
508 return 0;
509}
510
511int glslang_finalize(TParseContext* context) {
512 yyscan_t scanner = context->scanner;
513 if (scanner == NULL) return 0;
514
515 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000516 yylex_destroy(scanner);
517
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000518 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000519}
520
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000521int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000522 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000523 yyrestart(NULL, context->scanner);
524 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000525
526 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000527 if (!context->preprocessor.init(count, string, length))
528 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000529
530 // Define extension macros.
531 const TExtensionBehavior& extBehavior = context->extensionBehavior();
532 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
533 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000534 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000535 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000536 if (context->fragmentPrecisionHigh)
537 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
538
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000539 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000540}
541