blob: 78eb570fe5c20fd5b9465c691188bca5da7e7c35 [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);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059%}
60
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000061%option noyywrap nounput never-interactive
62%option yylineno reentrant bison-bridge
63%option stack
64%option extra-type="TParseContext*"
65%x COMMENT FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000066
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000067D [0-9]
68L [a-zA-Z_]
69H [a-fA-F0-9]
70E [Ee][+-]?{D}+
71O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072
73%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000074
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000075%{
76 TParseContext* context = yyextra;
77%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000079 /* Single-line comments */
80"//"[^\n]* ;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000081
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000082 /* Multi-line comments */
83"/*" { yy_push_state(COMMENT, yyscanner); }
84<COMMENT>. |
85<COMMENT>\n ;
86<COMMENT>"*/" { yy_pop_state(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000087
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000088"invariant" { return(INVARIANT); }
89"highp" { return(HIGH_PRECISION); }
90"mediump" { return(MEDIUM_PRECISION); }
91"lowp" { return(LOW_PRECISION); }
92"precision" { return(PRECISION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000093
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000094"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000095"const" { return(CONST_QUAL); }
96"uniform" { return(UNIFORM); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000097"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000099"break" { return(BREAK); }
100"continue" { return(CONTINUE); }
101"do" { return(DO); }
102"for" { return(FOR); }
103"while" { return(WHILE); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000104
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000105"if" { return(IF); }
106"else" { return(ELSE); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000107"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
108"case" { return ES2_reserved_ES3_keyword(context, CASE); }
109"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000110
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000111"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
112"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
113"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000115"in" { return(IN_QUAL); }
116"out" { return(OUT_QUAL); }
117"inout" { return(INOUT_QUAL); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000118
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000119"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
120"int" { context->lexAfterType = true; return(INT_TYPE); }
121"void" { context->lexAfterType = true; return(VOID_TYPE); }
122"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
123"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
124"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000126"discard" { return(DISCARD); }
127"return" { return(RETURN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000128
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000129"mat2" { context->lexAfterType = true; return(MATRIX2); }
130"mat3" { context->lexAfterType = true; return(MATRIX3); }
131"mat4" { context->lexAfterType = true; return(MATRIX4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000133"vec2" { context->lexAfterType = true; return (VEC2); }
134"vec3" { context->lexAfterType = true; return (VEC3); }
135"vec4" { context->lexAfterType = true; return (VEC4); }
136"ivec2" { context->lexAfterType = true; return (IVEC2); }
137"ivec3" { context->lexAfterType = true; return (IVEC3); }
138"ivec4" { context->lexAfterType = true; return (IVEC4); }
139"bvec2" { context->lexAfterType = true; return (BVEC2); }
140"bvec3" { context->lexAfterType = true; return (BVEC3); }
141"bvec4" { context->lexAfterType = true; return (BVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000143"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
144"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000145"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000146"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
147"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
148"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000149"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000151"struct" { context->lexAfterType = true; return(STRUCT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000152
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000153 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
154"coherent" |
155"restrict" |
156"readonly" |
157"writeonly" |
158"resource" |
159"atomic_uint" |
160"noperspective" |
161"patch" |
162"sample" |
163"subroutine" |
164"common" |
165"partition" |
166"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000167
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000168"filter" |
169"image1D" |
170"image2D" |
171"image3D" |
172"imageCube" |
173"iimage1D" |
174"iimage2D" |
175"iimage3D" |
176"iimageCube" |
177"uimage1D" |
178"uimage2D" |
179"uimage3D" |
180"uimageCube" |
181"image1DArray" |
182"image2DArray" |
183"iimage1DArray" |
184"iimage2DArray" |
185"uimage1DArray" |
186"uimage2DArray" |
187"image1DShadow" |
188"image2DShadow" |
189"image1DArrayShadow" |
190"image2DArrayShadow" |
191"imageBuffer" |
192"iimageBuffer" |
193"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000194
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000195"sampler1DArray" |
196"sampler1DArrayShadow" |
197"isampler1D" |
198"isampler1DArray" |
199"usampler1D" |
200"usampler1DArray" |
201"isampler2DRect" |
202"usampler2DRect" |
203"samplerBuffer" |
204"isamplerBuffer" |
205"usamplerBuffer" |
206"sampler2DMS" |
207"isampler2DMS" |
208"usampler2DMS" |
209"sampler2DMSArray" |
210"isampler2DMSArray" |
211"usampler2DMSArray" {
212 if (context->shaderVersion < 300) {
213 yylval->lex.string = NewPoolTString(yytext);
214 return check_type(yyscanner);
215 }
216 return reserved_word(yyscanner);
217}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000219 /* Reserved keywords */
220"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000221
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000222"class" |
223"union" |
224"enum" |
225"typedef" |
226"template" |
227"this" |
228"packed" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000229
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000230"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000231
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000232"inline" |
233"noinline" |
234"volatile" |
235"public" |
236"static" |
237"extern" |
238"external" |
239"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000240
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000241"long" |
242"short" |
243"double" |
244"half" |
245"fixed" |
246"unsigned" |
247"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000248
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000249"input" |
250"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000251
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000252"hvec2" |
253"hvec3" |
254"hvec4" |
255"dvec2" |
256"dvec3" |
257"dvec4" |
258"fvec2" |
259"fvec3" |
260"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000261
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000262"sampler1D" |
263"sampler1DShadow" |
264"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000265
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000266"sizeof" |
267"cast" |
268
269"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000270"using" { return reserved_word(yyscanner); }
271
272{L}({L}|{D})* {
273 yylval->lex.string = NewPoolTString(yytext);
274 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000275}
276
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00002770[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
2780{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002790{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000280{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000281
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000282{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
283{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
284"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000285
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000286"+=" { return(ADD_ASSIGN); }
287"-=" { return(SUB_ASSIGN); }
288"*=" { return(MUL_ASSIGN); }
289"/=" { return(DIV_ASSIGN); }
290"%=" { return(MOD_ASSIGN); }
291"<<=" { return(LEFT_ASSIGN); }
292">>=" { return(RIGHT_ASSIGN); }
293"&=" { return(AND_ASSIGN); }
294"^=" { return(XOR_ASSIGN); }
295"|=" { return(OR_ASSIGN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000296
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000297"++" { return(INC_OP); }
298"--" { return(DEC_OP); }
299"&&" { return(AND_OP); }
300"||" { return(OR_OP); }
301"^^" { return(XOR_OP); }
302"<=" { return(LE_OP); }
303">=" { return(GE_OP); }
304"==" { return(EQ_OP); }
305"!=" { return(NE_OP); }
306"<<" { return(LEFT_OP); }
307">>" { return(RIGHT_OP); }
308";" { context->lexAfterType = false; return(SEMICOLON); }
309("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
310("}"|"%>") { return(RIGHT_BRACE); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000311"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
312":" { return(COLON); }
313"=" { context->lexAfterType = false; return(EQUAL); }
314"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
315")" { context->inTypeParen = false; return(RIGHT_PAREN); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000316("["|"<:") { return(LEFT_BRACKET); }
317("]"|":>") { return(RIGHT_BRACKET); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000318"." { BEGIN(FIELDS); return(DOT); }
319"!" { return(BANG); }
320"-" { return(DASH); }
321"~" { return(TILDE); }
322"+" { return(PLUS); }
323"*" { return(STAR); }
324"/" { return(SLASH); }
325"%" { return(PERCENT); }
326"<" { return(LEFT_ANGLE); }
327">" { return(RIGHT_ANGLE); }
328"|" { return(VERTICAL_BAR); }
329"^" { return(CARET); }
330"&" { return(AMPERSAND); }
331"?" { return(QUESTION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000332
333<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000334 BEGIN(INITIAL);
335 yylval->lex.string = NewPoolTString(yytext);
336 return FIELD_SELECTION;
337}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338<FIELDS>[ \t\v\f\r] {}
339
340[ \t\v\n\f\r] { }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000341<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
342<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000343
344%%
345
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000346yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000347 pp::Token token;
348 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000349 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
350 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000351 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000352 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000353
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000354 if (len >= max_size)
355 YY_FATAL_ERROR("Input buffer overflow");
356 else if (len > 0)
357 buf[len++] = ' ';
358 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000359}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000360
361int check_type(yyscan_t yyscanner) {
362 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
363
364 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000365 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000366 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
367 TVariable* variable = static_cast<TVariable*>(symbol);
368 if (variable->isUserType()) {
369 yyextra->lexAfterType = true;
370 token = TYPE_NAME;
371 }
372 }
373 yylval->lex.symbol = symbol;
374 return token;
375}
376
377int reserved_word(yyscan_t yyscanner) {
378 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
379
380 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
381 yyextra->recover();
382 return 0;
383}
384
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000385int ES2_reserved_ES3_keyword(TParseContext *context, int token)
386{
387 yyscan_t yyscanner = (yyscan_t) context->scanner;
388
389 if (context->shaderVersion < 300)
390 {
391 return reserved_word(yyscanner);
392 }
393
394 return token;
395}
396
397int ES2_keyword_ES3_reserved(TParseContext *context, int token)
398{
399 yyscan_t yyscanner = (yyscan_t) context->scanner;
400
401 if (context->shaderVersion >= 300)
402 {
403 return reserved_word(yyscanner);
404 }
405
406 return token;
407}
408
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000409void yyerror(TParseContext* context, const char* reason) {
410 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
411
412 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000413 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000414 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000415 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000416 }
417 context->recover();
418}
419
420int glslang_initialize(TParseContext* context) {
421 yyscan_t scanner = NULL;
422 if (yylex_init_extra(context, &scanner))
423 return 1;
424
425 context->scanner = scanner;
426 return 0;
427}
428
429int glslang_finalize(TParseContext* context) {
430 yyscan_t scanner = context->scanner;
431 if (scanner == NULL) return 0;
432
433 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000434 yylex_destroy(scanner);
435
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000436 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000437}
438
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000439int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000440 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000441 yyrestart(NULL, context->scanner);
442 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
443 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000444
445 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000446 if (!context->preprocessor.init(count, string, length))
447 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000448
449 // Define extension macros.
450 const TExtensionBehavior& extBehavior = context->extensionBehavior();
451 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
452 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000453 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000454 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000455 if (context->fragmentPrecisionHigh)
456 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
457
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000458 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000459}
460