blob: ace2f2f8efb59c928850b802b1b45ff50d06b238 [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);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061%}
62
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000063%option noyywrap nounput never-interactive
64%option yylineno reentrant bison-bridge
65%option stack
66%option extra-type="TParseContext*"
67%x COMMENT 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
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000081 /* Single-line comments */
82"//"[^\n]* ;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000083
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000084 /* Multi-line comments */
85"/*" { yy_push_state(COMMENT, yyscanner); }
86<COMMENT>. |
87<COMMENT>\n ;
88<COMMENT>"*/" { yy_pop_state(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000090"invariant" { return(INVARIANT); }
91"highp" { return(HIGH_PRECISION); }
92"mediump" { return(MEDIUM_PRECISION); }
93"lowp" { return(LOW_PRECISION); }
94"precision" { return(PRECISION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000096"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000097"const" { return(CONST_QUAL); }
98"uniform" { return(UNIFORM); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +000099"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000100
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000101"break" { return(BREAK); }
102"continue" { return(CONTINUE); }
103"do" { return(DO); }
104"for" { return(FOR); }
105"while" { return(WHILE); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000106
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000107"if" { return(IF); }
108"else" { return(ELSE); }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000109"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
110"case" { return ES2_reserved_ES3_keyword(context, CASE); }
111"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000112
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000113"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
114"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
115"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000117"in" { return(IN_QUAL); }
118"out" { return(OUT_QUAL); }
119"inout" { return(INOUT_QUAL); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000121"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
122"int" { context->lexAfterType = true; return(INT_TYPE); }
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000123"uint" { return ES2_ident_ES3_keyword(context, UINT_TYPE); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000124"void" { context->lexAfterType = true; return(VOID_TYPE); }
125"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
126"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
127"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000128
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000129"discard" { return(DISCARD); }
130"return" { return(RETURN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000132"mat2" { context->lexAfterType = true; return(MATRIX2); }
133"mat3" { context->lexAfterType = true; return(MATRIX3); }
134"mat4" { context->lexAfterType = true; return(MATRIX4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
shannonwoods@chromium.org9bd22fa2013-05-30 00:18:47 +0000136"mat2x2" { return ES2_ident_ES3_keyword(context, MATRIX2); }
137"mat3x3" { return ES2_ident_ES3_keyword(context, MATRIX3); }
138"mat4x4" { return ES2_ident_ES3_keyword(context, MATRIX4); }
139
140"mat2x3" { return ES2_ident_ES3_keyword(context, MATRIX2x3); }
141"mat3x2" { return ES2_ident_ES3_keyword(context, MATRIX3x2); }
142"mat2x4" { return ES2_ident_ES3_keyword(context, MATRIX2x4); }
143"mat4x2" { return ES2_ident_ES3_keyword(context, MATRIX4x2); }
144"mat3x4" { return ES2_ident_ES3_keyword(context, MATRIX3x4); }
145"mat4x3" { return ES2_ident_ES3_keyword(context, MATRIX4x3); }
146
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000147"vec2" { context->lexAfterType = true; return (VEC2); }
148"vec3" { context->lexAfterType = true; return (VEC3); }
149"vec4" { context->lexAfterType = true; return (VEC4); }
150"ivec2" { context->lexAfterType = true; return (IVEC2); }
151"ivec3" { context->lexAfterType = true; return (IVEC3); }
152"ivec4" { context->lexAfterType = true; return (IVEC4); }
shannonwoods@chromium.org8c788e82013-05-30 00:20:21 +0000153"uvec2" { return ES2_ident_ES3_keyword(context, UVEC2); }
154"uvec3" { return ES2_ident_ES3_keyword(context, UVEC3); }
155"uvec4" { return ES2_ident_ES3_keyword(context, UVEC4); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000156"bvec2" { context->lexAfterType = true; return (BVEC2); }
157"bvec3" { context->lexAfterType = true; return (BVEC3); }
158"bvec4" { context->lexAfterType = true; return (BVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000160"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
161"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000162"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000163"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
164"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
165"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000166"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000167
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000168"struct" { context->lexAfterType = true; return(STRUCT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000170"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
171
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000172 /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
173"coherent" |
174"restrict" |
175"readonly" |
176"writeonly" |
177"resource" |
178"atomic_uint" |
179"noperspective" |
180"patch" |
181"sample" |
182"subroutine" |
183"common" |
184"partition" |
185"active" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000186
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000187"filter" |
188"image1D" |
189"image2D" |
190"image3D" |
191"imageCube" |
192"iimage1D" |
193"iimage2D" |
194"iimage3D" |
195"iimageCube" |
196"uimage1D" |
197"uimage2D" |
198"uimage3D" |
199"uimageCube" |
200"image1DArray" |
201"image2DArray" |
202"iimage1DArray" |
203"iimage2DArray" |
204"uimage1DArray" |
205"uimage2DArray" |
206"image1DShadow" |
207"image2DShadow" |
208"image1DArrayShadow" |
209"image2DArrayShadow" |
210"imageBuffer" |
211"iimageBuffer" |
212"uimageBuffer" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000213
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000214"sampler1DArray" |
215"sampler1DArrayShadow" |
216"isampler1D" |
217"isampler1DArray" |
218"usampler1D" |
219"usampler1DArray" |
220"isampler2DRect" |
221"usampler2DRect" |
222"samplerBuffer" |
223"isamplerBuffer" |
224"usamplerBuffer" |
225"sampler2DMS" |
226"isampler2DMS" |
227"usampler2DMS" |
228"sampler2DMSArray" |
229"isampler2DMSArray" |
230"usampler2DMSArray" {
231 if (context->shaderVersion < 300) {
232 yylval->lex.string = NewPoolTString(yytext);
233 return check_type(yyscanner);
234 }
235 return reserved_word(yyscanner);
236}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000237
shannonwoods@chromium.org302adfe2013-05-30 00:21:06 +0000238 /* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
239"packed" {
240 if (context->shaderVersion >= 300)
241 {
242 yylval->lex.string = NewPoolTString(yytext);
243 return check_type(yyscanner);
244 }
245
246 return reserved_word(yyscanner);
247}
248
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000249 /* Reserved keywords */
250"asm" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000252"class" |
253"union" |
254"enum" |
255"typedef" |
256"template" |
257"this" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000259"goto" |
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000261"inline" |
262"noinline" |
263"volatile" |
264"public" |
265"static" |
266"extern" |
267"external" |
268"interface" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000269
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000270"long" |
271"short" |
272"double" |
273"half" |
274"fixed" |
275"unsigned" |
276"superp" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000277
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000278"input" |
279"output" |
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000280
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000281"hvec2" |
282"hvec3" |
283"hvec4" |
284"dvec2" |
285"dvec3" |
286"dvec4" |
287"fvec2" |
288"fvec3" |
289"fvec4" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000290
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000291"sampler1D" |
292"sampler1DShadow" |
293"sampler2DRectShadow" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000294
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000295"sizeof" |
296"cast" |
297
298"namespace" |
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000299"using" { return reserved_word(yyscanner); }
300
301{L}({L}|{D})* {
302 yylval->lex.string = NewPoolTString(yytext);
303 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000304}
305
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +00003060[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
3070{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00003080{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000309{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +00003100[xX]{H}+[uU] { return uint_constant(context); }
3110{O}+[uU] { return uint_constant(context); }
312{D}+[uU] { return uint_constant(context); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000313
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000314{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
315{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
316"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000317
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000318"+=" { return(ADD_ASSIGN); }
319"-=" { return(SUB_ASSIGN); }
320"*=" { return(MUL_ASSIGN); }
321"/=" { return(DIV_ASSIGN); }
322"%=" { return(MOD_ASSIGN); }
323"<<=" { return(LEFT_ASSIGN); }
324">>=" { return(RIGHT_ASSIGN); }
325"&=" { return(AND_ASSIGN); }
326"^=" { return(XOR_ASSIGN); }
327"|=" { return(OR_ASSIGN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000329"++" { return(INC_OP); }
330"--" { return(DEC_OP); }
331"&&" { return(AND_OP); }
332"||" { return(OR_OP); }
333"^^" { return(XOR_OP); }
334"<=" { return(LE_OP); }
335">=" { return(GE_OP); }
336"==" { return(EQ_OP); }
337"!=" { return(NE_OP); }
338"<<" { return(LEFT_OP); }
339">>" { return(RIGHT_OP); }
340";" { context->lexAfterType = false; return(SEMICOLON); }
341("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
342("}"|"%>") { return(RIGHT_BRACE); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000343"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
344":" { return(COLON); }
345"=" { context->lexAfterType = false; return(EQUAL); }
346"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
347")" { context->inTypeParen = false; return(RIGHT_PAREN); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000348("["|"<:") { return(LEFT_BRACKET); }
349("]"|":>") { return(RIGHT_BRACKET); }
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000350"." { BEGIN(FIELDS); return(DOT); }
351"!" { return(BANG); }
352"-" { return(DASH); }
353"~" { return(TILDE); }
354"+" { return(PLUS); }
355"*" { return(STAR); }
356"/" { return(SLASH); }
357"%" { return(PERCENT); }
358"<" { return(LEFT_ANGLE); }
359">" { return(RIGHT_ANGLE); }
360"|" { return(VERTICAL_BAR); }
361"^" { return(CARET); }
362"&" { return(AMPERSAND); }
363"?" { return(QUESTION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000364
365<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000366 BEGIN(INITIAL);
367 yylval->lex.string = NewPoolTString(yytext);
368 return FIELD_SELECTION;
369}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000370<FIELDS>[ \t\v\f\r] {}
371
372[ \t\v\n\f\r] { }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000373<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
374<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000375
376%%
377
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000378yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000379 pp::Token token;
380 yyget_extra(yyscanner)->preprocessor.lex(&token);
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000381 yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
382 if (len < max_size)
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000383 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000384 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000385
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000386 if (len >= max_size)
387 YY_FATAL_ERROR("Input buffer overflow");
388 else if (len > 0)
389 buf[len++] = ' ';
390 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000391}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000392
393int check_type(yyscan_t yyscanner) {
394 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
395
396 int token = IDENTIFIER;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000397 TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000398 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
399 TVariable* variable = static_cast<TVariable*>(symbol);
400 if (variable->isUserType()) {
401 yyextra->lexAfterType = true;
402 token = TYPE_NAME;
403 }
404 }
405 yylval->lex.symbol = symbol;
406 return token;
407}
408
409int reserved_word(yyscan_t yyscanner) {
410 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
411
412 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
413 yyextra->recover();
414 return 0;
415}
416
shannonwoods@chromium.org35f156d2013-05-30 00:18:04 +0000417int ES2_reserved_ES3_keyword(TParseContext *context, int token)
418{
419 yyscan_t yyscanner = (yyscan_t) context->scanner;
420
421 if (context->shaderVersion < 300)
422 {
423 return reserved_word(yyscanner);
424 }
425
426 return token;
427}
428
429int ES2_keyword_ES3_reserved(TParseContext *context, int token)
430{
431 yyscan_t yyscanner = (yyscan_t) context->scanner;
432
433 if (context->shaderVersion >= 300)
434 {
435 return reserved_word(yyscanner);
436 }
437
438 return token;
439}
440
shannonwoods@chromium.org16242ef2013-05-30 00:18:11 +0000441int ES2_ident_ES3_keyword(TParseContext *context, int token)
442{
443 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
444 yyscan_t yyscanner = (yyscan_t) context->scanner;
445
446 // not a reserved word in GLSL ES 1.00, so could be used as an identifier/type name
447 if (context->shaderVersion < 300)
448 {
449 yylval->lex.string = NewPoolTString(yytext);
450 return check_type(yyscanner);
451 }
452
453 return token;
454}
455
shannonwoods@chromium.orgc8100b82013-05-30 00:20:34 +0000456int uint_constant(TParseContext *context)
457{
458 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
459 yyscan_t yyscanner = (yyscan_t) context->scanner;
460
461 if (context->shaderVersion < 300)
462 {
463 context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
464 context->recover();
465 return 0;
466 }
467
468 yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
469 return UINTCONSTANT;
470}
471
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000472void yyerror(TParseContext* context, const char* reason) {
473 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
474
475 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000476 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000477 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000478 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000479 }
480 context->recover();
481}
482
483int glslang_initialize(TParseContext* context) {
484 yyscan_t scanner = NULL;
485 if (yylex_init_extra(context, &scanner))
486 return 1;
487
488 context->scanner = scanner;
489 return 0;
490}
491
492int glslang_finalize(TParseContext* context) {
493 yyscan_t scanner = context->scanner;
494 if (scanner == NULL) return 0;
495
496 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000497 yylex_destroy(scanner);
498
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000499 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000500}
501
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000502int glslang_scan(size_t count, const char* const string[], const int length[],
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000503 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000504 yyrestart(NULL, context->scanner);
505 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
506 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000507
508 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000509 if (!context->preprocessor.init(count, string, length))
510 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000511
512 // Define extension macros.
513 const TExtensionBehavior& extBehavior = context->extensionBehavior();
514 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
515 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000516 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000517 }
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000518 if (context->fragmentPrecisionHigh)
519 context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
520
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000521 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000522}
523