Add tracking for extension based warnings
[mesa.git] / glsl_lexer.lpp
1 %{
2 /*
3 * Copyright © 2008, 2009 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24 #include "ast.h"
25 #include "glsl_parser_extras.h"
26 #include "glsl_parser.h"
27
28 #define YY_USER_ACTION \
29 do { \
30 yylloc->source = 0; \
31 yylloc->first_column = yycolumn + 1; \
32 yylloc->first_line = yylineno + 1; \
33 yycolumn += yyleng; \
34 } while(0);
35
36 %}
37
38 %option bison-bridge bison-locations reentrant noyywrap
39 %option never-interactive
40 %option prefix="_mesa_glsl_"
41 %option extra-type="struct _mesa_glsl_parse_state *"
42 %option stack
43
44 %x PP COMMENT
45
46 %%
47
48 "/*" { yy_push_state(COMMENT, yyscanner); }
49 <COMMENT>[^*\n]*
50 <COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; }
51 <COMMENT>"*"+[^*/\n]*
52 <COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; }
53 <COMMENT>"*"+"/" { yy_pop_state(yyscanner); }
54
55 \/\/.*\n { yylineno++; yycolumn = 0; }
56 [ \r\t]+ ;
57
58 /* Preprocessor tokens. */
59 ^[ \t]*#[ \t]*$ ;
60 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
61 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
62 ^[ \t]*#[ \t]*line { BEGIN PP; return LINE; }
63 ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
64 <PP>\/\/[^\n]* { }
65 <PP>[ \t\r]* { }
66 <PP>: return COLON;
67 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
68 yylval->identifier = strdup(yytext);
69 return IDENTIFIER;
70 }
71 <PP>[1-9][0-9]* {
72 yylval->n = strtol(yytext, NULL, 10);
73 return INTCONSTANT;
74 }
75 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
76
77 \n { yylineno++; yycolumn = 0; }
78
79 attribute return ATTRIBUTE;
80 const return CONST;
81 bool return BOOL;
82 float return FLOAT;
83 int return INT;
84
85 break return BREAK;
86 continue return CONTINUE;
87 do return DO;
88 while return WHILE;
89 else return ELSE;
90 for return FOR;
91 if return IF;
92 discard return DISCARD;
93 return return RETURN;
94
95 bvec2 return BVEC2;
96 bvec3 return BVEC3;
97 bvec4 return BVEC4;
98 ivec2 return IVEC2;
99 ivec3 return IVEC3;
100 ivec4 return IVEC4;
101 vec2 return VEC2;
102 vec3 return VEC3;
103 vec4 return VEC4;
104 mat2 return MAT2;
105 mat3 return MAT3;
106 mat4 return MAT4;
107 mat2x2 return MAT2X2;
108 mat2x3 return MAT2X3;
109 mat2x4 return MAT2X4;
110 mat3x2 return MAT3X2;
111 mat3x3 return MAT3X3;
112 mat3x4 return MAT3X4;
113 mat4x2 return MAT4X2;
114 mat4x3 return MAT4X3;
115 mat4x4 return MAT4X4;
116
117 in return IN;
118 out return OUT;
119 inout return INOUT;
120 uniform return UNIFORM;
121 varying return VARYING;
122 centroid return CENTROID;
123 invariant return INVARIANT;
124
125 sampler1D return SAMPLER1D;
126 sampler2D return SAMPLER2D;
127 sampler3D return SAMPLER3D;
128 samplerCube return SAMPLERCUBE;
129 sampler1DShadow return SAMPLER1DSHADOW;
130 sampler2DShadow return SAMPLER2DSHADOW;
131
132 struct return STRUCT;
133 void return VOID;
134
135 \+\+ return INC_OP;
136 -- return DEC_OP;
137 \<= return LE_OP;
138 >= return GE_OP;
139 == return EQ_OP;
140 != return NE_OP;
141 && return AND_OP;
142 \|\| return OR_OP;
143 "^^" return XOR_OP;
144
145 \*= return MUL_ASSIGN;
146 \/= return DIV_ASSIGN;
147 \+= return ADD_ASSIGN;
148 \%= return MOD_ASSIGN;
149 \<\<= return LEFT_ASSIGN;
150 >>= return RIGHT_ASSIGN;
151 &= return AND_ASSIGN;
152 ^= return XOR_ASSIGN;
153 \|= return OR_ASSIGN;
154 -= return SUB_ASSIGN;
155
156 [1-9][0-9]* {
157 yylval->n = strtol(yytext, NULL, 10);
158 return INTCONSTANT;
159 }
160 0[xX][0-9a-fA-F]+ {
161 yylval->n = strtol(yytext + 2, NULL, 16);
162 return INTCONSTANT;
163 }
164 0[0-7]* {
165 yylval->n = strtol(yytext + 2, NULL, 8);
166 return INTCONSTANT;
167 }
168
169 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
170 yylval->real = strtod(yytext, NULL);
171 return FLOATCONSTANT;
172 }
173 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? {
174 yylval->real = strtod(yytext, NULL);
175 return FLOATCONSTANT;
176 }
177 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? {
178 yylval->real = strtod(yytext, NULL);
179 return FLOATCONSTANT;
180 }
181 [0-9]+[eE][+-]?[0-9]+[fF]? {
182 yylval->real = strtod(yytext, NULL);
183 return FLOATCONSTANT;
184 }
185
186 true {
187 yylval->n = 1;
188 return BOOLCONSTANT;
189 }
190 false {
191 yylval->n = 0;
192 return BOOLCONSTANT;
193 }
194
195
196 /* Reserved words in GLSL 1.10. */
197 asm return ASM;
198 class return CLASS;
199 union return UNION;
200 enum return ENUM;
201 typedef return TYPEDEF;
202 template return TEMPLATE;
203 this return THIS;
204 packed return PACKED;
205 goto return GOTO;
206 switch return SWITCH;
207 default return DEFAULT;
208 inline return INLINE;
209 noinline return NOINLINE;
210 volatile return VOLATILE;
211 public return PUBLIC;
212 static return STATIC;
213 extern return EXTERN;
214 external return EXTERNAL;
215 interface return INTERFACE;
216 long return LONG;
217 short return SHORT;
218 double return DOUBLE;
219 half return HALF;
220 fixed return FIXED;
221 unsigned return UNSIGNED;
222 input return INPUT;
223 output return OUTPUT;
224 hvec2 return HVEC2;
225 hvec3 return HVEC3;
226 hvec4 return HVEC4;
227 dvec2 return DVEC2;
228 dvec3 return DVEC3;
229 dvec4 return DVEC4;
230 fvec2 return FVEC2;
231 fvec3 return FVEC3;
232 fvec4 return FVEC4;
233 sampler2DRect return SAMPLER2DRECT;
234 sampler3DRect return SAMPLER3DRECT;
235 sampler2DRectShadow return SAMPLER2DRECTSHADOW;
236 sizeof return SIZEOF;
237 cast return CAST;
238 namespace return NAMESPACE;
239 using return USING;
240
241 /* Additional reserved words in GLSL 1.20. */
242 lowp return LOWP;
243 mediump return MEDIUMP;
244 highp return HIGHP;
245 precision return PRECISION;
246
247 [_a-zA-Z][_a-zA-Z0-9]* {
248 yylval->identifier = strdup(yytext);
249 return IDENTIFIER;
250 }
251
252 . { return yytext[0]; }
253
254 %%
255
256 void
257 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
258 const char *string, size_t len)
259 {
260 yylex_init_extra(state, & state->scanner);
261 yy_scan_bytes(string, len, state->scanner);
262 }
263
264 void
265 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
266 {
267 yylex_destroy(state->scanner);
268 }