blob: 78c9643bbcf0d0d227a64adcd10530aed739e3eb [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.org68b3e912012-07-09 18:39:32 +0000275// Old preprocessor interface.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276extern "C" {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000277#include "compiler/preprocessor/preprocess.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000279extern int InitPreprocessor();
280extern int FinalizePreprocessor();
281extern void PredefineIntMacro(const char *name, int value);
282
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000283#define SETUP_CONTEXT(pp) \
284 TParseContext* context = (TParseContext*) pp->pC; \
285 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000287// Preprocessor callbacks.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288void CPPDebugLogMsg(const char *msg)
289{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000290 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000291 context->trace(msg);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000292}
293
294void CPPWarningToInfoLog(const char *msg)
295{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000296 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000297 context->warning(yylineno, msg, "");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298}
299
300void CPPShInfoLogMsg(const char *msg)
301{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000302 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000303 context->error(yylineno, msg, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000304 context->recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000305}
306
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000307void CPPErrorToInfoLog(const char *msg)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000309 SETUP_CONTEXT(cpp);
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000310 context->error(yylineno, msg, "");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000311 context->recover();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000312}
313
314void SetLineNumber(int line)
315{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000316 SETUP_CONTEXT(cpp);
317 int string = 0;
318 DecodeSourceLoc(yylineno, &string, NULL);
319 yylineno = EncodeSourceLoc(string, line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000320}
321
322void SetStringNumber(int string)
323{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000324 SETUP_CONTEXT(cpp);
325 int line = 0;
326 DecodeSourceLoc(yylineno, NULL, &line);
327 yylineno = EncodeSourceLoc(string, line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328}
329
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000330int GetStringNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000331{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000332 SETUP_CONTEXT(cpp);
333 int string = 0;
334 DecodeSourceLoc(yylineno, &string, NULL);
335 return string;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336}
337
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000338int GetLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000339{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000340 SETUP_CONTEXT(cpp);
341 int line = 0;
342 DecodeSourceLoc(yylineno, NULL, &line);
343 return line;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344}
345
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000346void IncLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000347{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000348 SETUP_CONTEXT(cpp);
349 int string = 0, line = 0;
350 DecodeSourceLoc(yylineno, &string, &line);
351 yylineno = EncodeSourceLoc(string, ++line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000352}
353
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000354void DecLineNumber()
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000356 SETUP_CONTEXT(cpp);
357 int string = 0, line = 0;
358 DecodeSourceLoc(yylineno, &string, &line);
359 yylineno = EncodeSourceLoc(string, --line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000360}
361
362void HandlePragma(const char **tokens, int numTokens)
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000363{
364 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000365
366 if (numTokens != 4) return;
367 if (strcmp(tokens[1], "(") != 0) return;
368 if (strcmp(tokens[3], ")") != 0) return;
369
370 context->handlePragmaDirective(yylineno, tokens[0], tokens[2]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000371}
372
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000373void StoreStr(const char *string)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000374{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000375 SETUP_CONTEXT(cpp);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000376 TString strSrc;
377 strSrc = TString(string);
378
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000379 context->HashErrMsg = context->HashErrMsg + " " + strSrc;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000380}
381
382const char* GetStrfromTStr(void)
383{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000384 SETUP_CONTEXT(cpp);
385 cpp->ErrMsg = context->HashErrMsg.c_str();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000386 return cpp->ErrMsg;
387}
388
389void ResetTString(void)
390{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000391 SETUP_CONTEXT(cpp);
392 context->HashErrMsg = "";
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000393}
394
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000395void updateExtensionBehavior(const char* extName, const char* behavior)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000396{
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000397 SETUP_CONTEXT(cpp);
alokp@chromium.org8b851c62012-06-15 16:25:11 +0000398 context->handleExtensionDirective(yylineno, extName, behavior);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000399}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000400} // extern "C"
401
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000402int string_input(char* buf, int max_size, yyscan_t yyscanner) {
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000403 pp::Token token;
404 yyget_extra(yyscanner)->preprocessor.lex(&token);
daniel@transgaming.coma646c912012-10-26 18:58:12 +0000405 int len = token.type == pp::Token::LAST ? 0 : token.text.size();
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000406 if ((len > 0) && (len < max_size))
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +0000407 memcpy(buf, token.text.c_str(), len);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000408 yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000409
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000410 if (len >= max_size)
411 YY_FATAL_ERROR("Input buffer overflow");
412 else if (len > 0)
413 buf[len++] = ' ';
414 return len;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000415}
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000416
417int check_type(yyscan_t yyscanner) {
418 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
419
420 int token = IDENTIFIER;
421 TSymbol* symbol = yyextra->symbolTable.find(yytext);
422 if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
423 TVariable* variable = static_cast<TVariable*>(symbol);
424 if (variable->isUserType()) {
425 yyextra->lexAfterType = true;
426 token = TYPE_NAME;
427 }
428 }
429 yylval->lex.symbol = symbol;
430 return token;
431}
432
433int reserved_word(yyscan_t yyscanner) {
434 struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
435
436 yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
437 yyextra->recover();
438 return 0;
439}
440
441void yyerror(TParseContext* context, const char* reason) {
442 struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
443
444 if (context->AfterEOF) {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000445 context->error(yylineno, reason, "unexpected EOF");
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000446 } else {
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000447 context->error(yylineno, reason, yytext);
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000448 }
449 context->recover();
450}
451
452int glslang_initialize(TParseContext* context) {
453 yyscan_t scanner = NULL;
454 if (yylex_init_extra(context, &scanner))
455 return 1;
456
457 context->scanner = scanner;
458 return 0;
459}
460
461int glslang_finalize(TParseContext* context) {
462 yyscan_t scanner = context->scanner;
463 if (scanner == NULL) return 0;
464
465 context->scanner = NULL;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000466 yylex_destroy(scanner);
467
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000468 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000469}
470
alokp@chromium.org408c45e2012-04-05 15:54:43 +0000471int glslang_scan(int count, const char* const string[], const int length[],
472 TParseContext* context) {
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000473 yyrestart(NULL, context->scanner);
474 yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
475 context->AfterEOF = false;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000476
477 // Initialize preprocessor.
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000478 if (!context->preprocessor.init(count, string, length))
479 return 1;
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000480
481 // Define extension macros.
482 const TExtensionBehavior& extBehavior = context->extensionBehavior();
483 for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
484 iter != extBehavior.end(); ++iter) {
alokp@chromium.orge3043b12012-06-19 19:40:52 +0000485 context->preprocessor.predefineMacro(iter->first.c_str(), 1);
alokp@chromium.org73bc2982012-06-19 18:48:05 +0000486 }
487 return 0;
alokp@chromium.org044a5cf2010-11-12 15:42:16 +0000488}
489