blob: 8ab4ee1f0cef5c60e0a946893b80d0dafd9456da [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);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000057%}
58
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000059%option noyywrap nounput never-interactive
60%option yylineno reentrant bison-bridge
61%option stack
62%option extra-type="TParseContext*"
63%x COMMENT FIELDS
alokp@chromium.org29d56fb2010-04-06 15:42:22 +000064
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000065D [0-9]
66L [a-zA-Z_]
67H [a-fA-F0-9]
68E [Ee][+-]?{D}+
69O [0-7]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000070
71%%
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000073%{
74 TParseContext* context = yyextra;
75%}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000077 /* Single-line comments */
78"//"[^\n]* ;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000079
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000080 /* Multi-line comments */
81"/*" { yy_push_state(COMMENT, yyscanner); }
82<COMMENT>. |
83<COMMENT>\n ;
84<COMMENT>"*/" { yy_pop_state(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000085
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000086"invariant" { return(INVARIANT); }
87"highp" { return(HIGH_PRECISION); }
88"mediump" { return(MEDIUM_PRECISION); }
89"lowp" { return(LOW_PRECISION); }
90"precision" { return(PRECISION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000091
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +000092"attribute" { if (context->shaderVersion < 300) return(ATTRIBUTE); return reserved_word(yyscanner); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000093"const" { return(CONST_QUAL); }
94"uniform" { return(UNIFORM); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +000095"varying" { if (context->shaderVersion < 300) return(VARYING); return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000097"break" { return(BREAK); }
98"continue" { return(CONTINUE); }
99"do" { return(DO); }
100"for" { return(FOR); }
101"while" { return(WHILE); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000102
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000103"if" { return(IF); }
104"else" { return(ELSE); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000105"switch" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SWITCH); }
106"case" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CASE); }
107"default" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(DEFAULT); }
108
109"centroid" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CENTROID); }
110"flat" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(FLAT); }
111"smooth" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000113"in" { return(IN_QUAL); }
114"out" { return(OUT_QUAL); }
115"inout" { return(INOUT_QUAL); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000117"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
118"int" { context->lexAfterType = true; return(INT_TYPE); }
119"void" { context->lexAfterType = true; return(VOID_TYPE); }
120"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
121"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
122"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000124"discard" { return(DISCARD); }
125"return" { return(RETURN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000127"mat2" { context->lexAfterType = true; return(MATRIX2); }
128"mat3" { context->lexAfterType = true; return(MATRIX3); }
129"mat4" { context->lexAfterType = true; return(MATRIX4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000130
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000131"vec2" { context->lexAfterType = true; return (VEC2); }
132"vec3" { context->lexAfterType = true; return (VEC3); }
133"vec4" { context->lexAfterType = true; return (VEC4); }
134"ivec2" { context->lexAfterType = true; return (IVEC2); }
135"ivec3" { context->lexAfterType = true; return (IVEC3); }
136"ivec4" { context->lexAfterType = true; return (IVEC4); }
137"bvec2" { context->lexAfterType = true; return (BVEC2); }
138"bvec3" { context->lexAfterType = true; return (BVEC3); }
139"bvec4" { context->lexAfterType = true; return (BVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000141"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
142"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000143"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000144"sampler3D" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3D; }
145"sampler3DRect" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3DRECT; }
146"sampler2DShadow" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER2DSHADOW; }
147"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000149"struct" { context->lexAfterType = true; return(STRUCT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000151 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
152"coherent" |
153"restrict" |
154"readonly" |
155"writeonly" |
156"resource" |
157"atomic_uint" |
158"noperspective" |
159"patch" |
160"sample" |
161"subroutine" |
162"common" |
163"partition" |
164"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000165
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000166"filter" |
167"image1D" |
168"image2D" |
169"image3D" |
170"imageCube" |
171"iimage1D" |
172"iimage2D" |
173"iimage3D" |
174"iimageCube" |
175"uimage1D" |
176"uimage2D" |
177"uimage3D" |
178"uimageCube" |
179"image1DArray" |
180"image2DArray" |
181"iimage1DArray" |
182"iimage2DArray" |
183"uimage1DArray" |
184"uimage2DArray" |
185"image1DShadow" |
186"image2DShadow" |
187"image1DArrayShadow" |
188"image2DArrayShadow" |
189"imageBuffer" |
190"iimageBuffer" |
191"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000192
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000193"sampler1DArray" |
194"sampler1DArrayShadow" |
195"isampler1D" |
196"isampler1DArray" |
197"usampler1D" |
198"usampler1DArray" |
199"isampler2DRect" |
200"usampler2DRect" |
201"samplerBuffer" |
202"isamplerBuffer" |
203"usamplerBuffer" |
204"sampler2DMS" |
205"isampler2DMS" |
206"usampler2DMS" |
207"sampler2DMSArray" |
208"isampler2DMSArray" |
209"usampler2DMSArray" {
210 if (context->shaderVersion < 300) {
211 yylval->lex.string = NewPoolTString(yytext);
212 return check_type(yyscanner);
213 }
214 return reserved_word(yyscanner);
215}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000217 /* Reserved keywords */
218"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000219
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000220"class" |
221"union" |
222"enum" |
223"typedef" |
224"template" |
225"this" |
226"packed" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000228"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000229
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000230"inline" |
231"noinline" |
232"volatile" |
233"public" |
234"static" |
235"extern" |
236"external" |
237"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000238
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000239"long" |
240"short" |
241"double" |
242"half" |
243"fixed" |
244"unsigned" |
245"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000246
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000247"input" |
248"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000249
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000250"hvec2" |
251"hvec3" |
252"hvec4" |
253"dvec2" |
254"dvec3" |
255"dvec4" |
256"fvec2" |
257"fvec3" |
258"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000259
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000260"sampler1D" |
261"sampler1DShadow" |
262"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000263
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000264"sizeof" |
265"cast" |
266
267"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000268"using" { return reserved_word(yyscanner); }
269
270{L}({L}|{D})* {
271 yylval->lex.string = NewPoolTString(yytext);
272 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000273}
274
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00002750[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
2760{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002770{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000278{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000280{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
281{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
282"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000284"+=" { return(ADD_ASSIGN); }
285"-=" { return(SUB_ASSIGN); }
286"*=" { return(MUL_ASSIGN); }
287"/=" { return(DIV_ASSIGN); }
288"%=" { return(MOD_ASSIGN); }
289"<<=" { return(LEFT_ASSIGN); }
290">>=" { return(RIGHT_ASSIGN); }
291"&=" { return(AND_ASSIGN); }
292"^=" { return(XOR_ASSIGN); }
293"|=" { return(OR_ASSIGN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000294
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000295"++" { return(INC_OP); }
296"--" { return(DEC_OP); }
297"&&" { return(AND_OP); }
298"||" { return(OR_OP); }
299"^^" { return(XOR_OP); }
300"<=" { return(LE_OP); }
301">=" { return(GE_OP); }
302"==" { return(EQ_OP); }
303"!=" { return(NE_OP); }
304"<<" { return(LEFT_OP); }
305">>" { return(RIGHT_OP); }
306";" { context->lexAfterType = false; return(SEMICOLON); }
307("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
308("}"|"%>") { return(RIGHT_BRACE); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000309"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
310":" { return(COLON); }
311"=" { context->lexAfterType = false; return(EQUAL); }
312"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
313")" { context->inTypeParen = false; return(RIGHT_PAREN); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000314("["|"<:") { return(LEFT_BRACKET); }
315("]"|":>") { return(RIGHT_BRACKET); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000316"." { BEGIN(FIELDS); return(DOT); }
317"!" { return(BANG); }
318"-" { return(DASH); }
319"~" { return(TILDE); }
320"+" { return(PLUS); }
321"*" { return(STAR); }
322"/" { return(SLASH); }
323"%" { return(PERCENT); }
324"<" { return(LEFT_ANGLE); }
325">" { return(RIGHT_ANGLE); }
326"|" { return(VERTICAL_BAR); }
327"^" { return(CARET); }
328"&" { return(AMPERSAND); }
329"?" { return(QUESTION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000330
331<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000332 BEGIN(INITIAL);
333 yylval->lex.string = NewPoolTString(yytext);
334 return FIELD_SELECTION;
335}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336<FIELDS>[ \t\v\f\r] {}
337
338[ \t\v\n\f\r] { }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000339<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
340<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000341
342%%
343
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000344yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000345 pp::Token token;
346 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000347 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
348 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000349 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000350 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000351
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000352 if (len >= max_size)
353 YY_FATAL_ERROR("Input buffer overflow");
354 else if (len > 0)
355 buf[len++] = ' ';
356 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000357}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000358
359int check_type(yyscan_t yyscanner) {
360 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
361
362 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000363 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000364 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
365 TVariable* variable = static_cast<TVariable*>(symbol);
366 if (variable->isUserType()) {
367 yyextra->lexAfterType = true;
368 token = TYPE_NAME;
369 }
370 }
371 yylval->lex.symbol = symbol;
372 return token;
373}
374
375int reserved_word(yyscan_t yyscanner) {
376 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
377
378 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
379 yyextra->recover();
380 return 0;
381}
382
383void yyerror(TParseContext* context, const char* reason) {
384 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
385
386 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000387 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000388 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000389 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000390 }
391 context->recover();
392}
393
394int glslang_initialize(TParseContext* context) {
395 yyscan_t scanner = NULL;
396 if (yylex_init_extra(context, &scanner))
397 return 1;
398
399 context->scanner = scanner;
400 return 0;
401}
402
403int glslang_finalize(TParseContext* context) {
404 yyscan_t scanner = context->scanner;
405 if (scanner == NULL) return 0;
406
407 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000408 yylex_destroy(scanner);
409
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000410 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000411}
412
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000413int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000414 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000415 yyrestart(NULL, context->scanner);
416 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
417 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000418
419 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000420 if (!context->preprocessor.init(count, string, length))
421 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000422
423 // Define extension macros.
424 const TExtensionBehavior& extBehavior = context->extensionBehavior();
425 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
426 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000427 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000428 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000429 if (context->fragmentPrecisionHigh)
430 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
431
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000432 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000433}
434