blob: 6c92116f092984fc5780875e0630dd0e917335b3 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001/*
2//
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +00003// Copyright (c) 2002-2012 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//
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +000018// Copyright (c) 2012 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"
alokp@chromium.org73bc2982012-06-19 18:48:05 +000041#include "compiler/preprocessor/new/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
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000054static int string_input(char* buf, int max_size, yyscan_t yyscanner);
55static 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
alokp@chromium.org044a5cf2010-11-12 15:42:16 +000092"attribute" { return(ATTRIBUTE); }
93"const" { return(CONST_QUAL); }
94"uniform" { return(UNIFORM); }
95"varying" { return(VARYING); }
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); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000105
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000106"in" { return(IN_QUAL); }
107"out" { return(OUT_QUAL); }
108"inout" { return(INOUT_QUAL); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000110"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
111"int" { context->lexAfterType = true; return(INT_TYPE); }
112"void" { context->lexAfterType = true; return(VOID_TYPE); }
113"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
114"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
115"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000117"discard" { return(DISCARD); }
118"return" { return(RETURN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000120"mat2" { context->lexAfterType = true; return(MATRIX2); }
121"mat3" { context->lexAfterType = true; return(MATRIX3); }
122"mat4" { context->lexAfterType = true; return(MATRIX4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000124"vec2" { context->lexAfterType = true; return (VEC2); }
125"vec3" { context->lexAfterType = true; return (VEC3); }
126"vec4" { context->lexAfterType = true; return (VEC4); }
127"ivec2" { context->lexAfterType = true; return (IVEC2); }
128"ivec3" { context->lexAfterType = true; return (IVEC3); }
129"ivec4" { context->lexAfterType = true; return (IVEC4); }
130"bvec2" { context->lexAfterType = true; return (BVEC2); }
131"bvec3" { context->lexAfterType = true; return (BVEC3); }
132"bvec4" { context->lexAfterType = true; return (BVEC4); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000133
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000134"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
135"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
zmo@google.com09c323a2011-08-12 18:22:25 +0000136"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
kbr@chromium.org205fef32011-11-22 20:50:02 +0000137"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000139"struct" { context->lexAfterType = true; return(STRUCT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000141"asm" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000143"class" { return reserved_word(yyscanner); }
144"union" { return reserved_word(yyscanner); }
145"enum" { return reserved_word(yyscanner); }
146"typedef" { return reserved_word(yyscanner); }
147"template" { return reserved_word(yyscanner); }
148"this" { return reserved_word(yyscanner); }
149"packed" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000151"goto" { return reserved_word(yyscanner); }
152"switch" { return reserved_word(yyscanner); }
153"default" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000155"inline" { return reserved_word(yyscanner); }
156"noinline" { return reserved_word(yyscanner); }
157"volatile" { return reserved_word(yyscanner); }
158"public" { return reserved_word(yyscanner); }
159"static" { return reserved_word(yyscanner); }
160"extern" { return reserved_word(yyscanner); }
161"external" { return reserved_word(yyscanner); }
162"interface" { return reserved_word(yyscanner); }
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000163"flat" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000165"long" { return reserved_word(yyscanner); }
166"short" { return reserved_word(yyscanner); }
167"double" { return reserved_word(yyscanner); }
168"half" { return reserved_word(yyscanner); }
169"fixed" { return reserved_word(yyscanner); }
170"unsigned" { return reserved_word(yyscanner); }
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000171"superp" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000173"input" { return reserved_word(yyscanner); }
174"output" { return reserved_word(yyscanner); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000175
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000176"hvec2" { return reserved_word(yyscanner); }
177"hvec3" { return reserved_word(yyscanner); }
178"hvec4" { return reserved_word(yyscanner); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000179"dvec2" { return reserved_word(yyscanner); }
180"dvec3" { return reserved_word(yyscanner); }
181"dvec4" { return reserved_word(yyscanner); }
daniel@transgaming.combeadd5d2012-04-12 02:35:31 +0000182"fvec2" { return reserved_word(yyscanner); }
183"fvec3" { return reserved_word(yyscanner); }
184"fvec4" { return reserved_word(yyscanner); }
185
186"sampler1D" { return reserved_word(yyscanner); }
187"sampler3D" { return reserved_word(yyscanner); }
188
189"sampler1DShadow" { return reserved_word(yyscanner); }
190"sampler2DShadow" { return reserved_word(yyscanner); }
191
192"sampler3DRect" { return reserved_word(yyscanner); }
193"sampler2DRectShadow" { return reserved_word(yyscanner); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000194
195"sizeof" { return reserved_word(yyscanner); }
196"cast" { return reserved_word(yyscanner); }
197
198"namespace" { return reserved_word(yyscanner); }
199"using" { return reserved_word(yyscanner); }
200
201{L}({L}|{D})* {
202 yylval->lex.string = NewPoolTString(yytext);
203 return check_type(yyscanner);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000204}
205
alokp@chromium.org044a5cf2010-11-12 15:42:16 +00002060[xX]{H}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
2070{O}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +00002080{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000209{D}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000210
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000211{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
212{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
213"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000214
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000215"+=" { return(ADD_ASSIGN); }
216"-=" { return(SUB_ASSIGN); }
217"*=" { return(MUL_ASSIGN); }
218"/=" { return(DIV_ASSIGN); }
219"%=" { return(MOD_ASSIGN); }
220"<<=" { return(LEFT_ASSIGN); }
221">>=" { return(RIGHT_ASSIGN); }
222"&=" { return(AND_ASSIGN); }
223"^=" { return(XOR_ASSIGN); }
224"|=" { return(OR_ASSIGN); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000225
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000226"++" { return(INC_OP); }
227"--" { return(DEC_OP); }
228"&&" { return(AND_OP); }
229"||" { return(OR_OP); }
230"^^" { return(XOR_OP); }
231"<=" { return(LE_OP); }
232">=" { return(GE_OP); }
233"==" { return(EQ_OP); }
234"!=" { return(NE_OP); }
235"<<" { return(LEFT_OP); }
236">>" { return(RIGHT_OP); }
237";" { context->lexAfterType = false; return(SEMICOLON); }
238("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
239("}"|"%>") { return(RIGHT_BRACE); }
240"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
241":" { return(COLON); }
242"=" { context->lexAfterType = false; return(EQUAL); }
243"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
244")" { context->inTypeParen = false; return(RIGHT_PAREN); }
245("["|"<:") { return(LEFT_BRACKET); }
246("]"|":>") { return(RIGHT_BRACKET); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000247"." { BEGIN(FIELDS); return(DOT); }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000248"!" { return(BANG); }
249"-" { return(DASH); }
250"~" { return(TILDE); }
251"+" { return(PLUS); }
252"*" { return(STAR); }
253"/" { return(SLASH); }
254"%" { return(PERCENT); }
255"<" { return(LEFT_ANGLE); }
256">" { return(RIGHT_ANGLE); }
257"|" { return(VERTICAL_BAR); }
258"^" { return(CARET); }
259"&" { return(AMPERSAND); }
260"?" { return(QUESTION); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000261
262<FIELDS>{L}({L}|{D})* {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000263 BEGIN(INITIAL);
264 yylval->lex.string = NewPoolTString(yytext);
265 return FIELD_SELECTION;
266}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000267<FIELDS>[ \t\v\f\r] {}
268
269[ \t\v\n\f\r] { }
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000270<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
271<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000272
273%%
274
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000275#if !ANGLE_USE_NEW_PREPROCESSOR
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276extern "C" {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000277// Preprocessor interface.
278#include "compiler/preprocessor/preprocess.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000280extern int InitPreprocessor();
281extern int FinalizePreprocessor();
282extern void PredefineIntMacro(const char *name, int value);
283
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000284#define SETUP_CONTEXT(pp) \
285 TParseContext* context = (TParseContext*) pp->pC; \
286 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000288// Preprocessor callbacks.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000289void CPPDebugLogMsg(const char *msg)
290{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000291 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000292 context->trace(msg);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000293}
294
295void CPPWarningToInfoLog(const char *msg)
296{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000297 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000298 context->warning(yylineno, msg, "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000299}
300
301void CPPShInfoLogMsg(const char *msg)
302{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000303 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000304 context->error(yylineno, msg, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000305 context->recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306}
307
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000308void CPPErrorToInfoLog(const char *msg)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000309{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000310 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000311 context->error(yylineno, msg, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000312 context->recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000313}
314
315void SetLineNumber(int line)
316{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000317 SETUP_CONTEXT(cpp);
318 int string = 0;
319 DecodeSourceLoc(yylineno, &string, NULL);
320 yylineno = EncodeSourceLoc(string, line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000321}
322
323void SetStringNumber(int string)
324{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000325 SETUP_CONTEXT(cpp);
326 int line = 0;
327 DecodeSourceLoc(yylineno, NULL, &line);
328 yylineno = EncodeSourceLoc(string, line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000329}
330
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000331int GetStringNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000332{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000333 SETUP_CONTEXT(cpp);
334 int string = 0;
335 DecodeSourceLoc(yylineno, &string, NULL);
336 return string;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000337}
338
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000339int GetLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000340{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000341 SETUP_CONTEXT(cpp);
342 int line = 0;
343 DecodeSourceLoc(yylineno, NULL, &line);
344 return line;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000345}
346
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000347void IncLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000348{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000349 SETUP_CONTEXT(cpp);
350 int string = 0, line = 0;
351 DecodeSourceLoc(yylineno, &string, &line);
352 yylineno = EncodeSourceLoc(string, ++line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000353}
354
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000355void DecLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000356{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000357 SETUP_CONTEXT(cpp);
358 int string = 0, line = 0;
359 DecodeSourceLoc(yylineno, &string, &line);
360 yylineno = EncodeSourceLoc(string, --line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000361}
362
363void HandlePragma(const char **tokens, int numTokens)
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000364{
365 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000366
367 if (numTokens != 4) return;
368 if (strcmp(tokens[1], "(") != 0) return;
369 if (strcmp(tokens[3], ")") != 0) return;
370
371 context->handlePragmaDirective(yylineno, tokens[0], tokens[2]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372}
373
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000374void StoreStr(const char *string)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000375{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000376 SETUP_CONTEXT(cpp);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000377 TString strSrc;
378 strSrc = TString(string);
379
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000380 context->HashErrMsg = context->HashErrMsg + " " + strSrc;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000381}
382
383const char* GetStrfromTStr(void)
384{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000385 SETUP_CONTEXT(cpp);
386 cpp->ErrMsg = context->HashErrMsg.c_str();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000387 return cpp->ErrMsg;
388}
389
390void ResetTString(void)
391{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000392 SETUP_CONTEXT(cpp);
393 context->HashErrMsg = "";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000394}
395
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000396void updateExtensionBehavior(const char* extName, const char* behavior)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000397{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000398 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000399 context->handleExtensionDirective(yylineno, extName, behavior);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000400}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000401} // extern "C"
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000402#endif // !ANGLE_USE_NEW_PREPROCESSOR
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000403
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000404int string_input(char* buf, int max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000405 int len = 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000406
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000407#if ANGLE_USE_NEW_PREPROCESSOR
408 pp::Token token;
409 yyget_extra(yyscanner)->preprocessor.lex(&token);
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000410 len = token.type == pp::Token::LAST ? 0 : token.text.size();
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000411 if ((len > 0) && (len < max_size))
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000412 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000413 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
414#else
415 len = yylex_CPP(buf, max_size);
416#endif // ANGLE_USE_NEW_PREPROCESSOR
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000417
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000418 if (len >= max_size)
419 YY_FATAL_ERROR("Input buffer overflow");
420 else if (len > 0)
421 buf[len++] = ' ';
422 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000423}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000424
425int check_type(yyscan_t yyscanner) {
426 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
427
428 int token = IDENTIFIER;
429 TSymbol* symbol = yyextra->symbolTable.find(yytext);
430 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
431 TVariable* variable = static_cast<TVariable*>(symbol);
432 if (variable->isUserType()) {
433 yyextra->lexAfterType = true;
434 token = TYPE_NAME;
435 }
436 }
437 yylval->lex.symbol = symbol;
438 return token;
439}
440
441int reserved_word(yyscan_t yyscanner) {
442 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
443
444 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
445 yyextra->recover();
446 return 0;
447}
448
449void yyerror(TParseContext* context, const char* reason) {
450 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
451
452 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000453 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000454 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000455 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000456 }
457 context->recover();
458}
459
460int glslang_initialize(TParseContext* context) {
461 yyscan_t scanner = NULL;
462 if (yylex_init_extra(context, &scanner))
463 return 1;
464
465 context->scanner = scanner;
466 return 0;
467}
468
469int glslang_finalize(TParseContext* context) {
470 yyscan_t scanner = context->scanner;
471 if (scanner == NULL) return 0;
472
473 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000474 yylex_destroy(scanner);
475
476#if !ANGLE_USE_NEW_PREPROCESSOR
477 FinalizePreprocessor();
478#endif
479 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000480}
481
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000482int glslang_scan(int count, const char* const string[], const int length[],
483 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000484 yyrestart(NULL, context->scanner);
485 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
486 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000487
488 // Initialize preprocessor.
489#if ANGLE_USE_NEW_PREPROCESSOR
490 if (!context->preprocessor.init(count, string, length))
491 return 1;
492#else
493 if (InitPreprocessor())
494 return 1;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000495 cpp->pC = context;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000496 cpp->pastFirstStatement = 0;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000497 if (InitScannerInput(cpp, count, string, length))
498 return 1;
499#endif // ANGLE_USE_NEW_PREPROCESSOR
500
501 // Define extension macros.
502 const TExtensionBehavior& extBehavior = context->extensionBehavior();
503 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
504 iter != extBehavior.end(); ++iter) {
505#if ANGLE_USE_NEW_PREPROCESSOR
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000506 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000507#else
508 PredefineIntMacro(iter->first.c_str(), 1);
509#endif
510 }
511 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000512}
513