ucrtbase: Export _o_to{lower, upper}() as to{lower, upper}().
[wine.git] / dlls / d3dcompiler_43 / hlsl.l
blob2994c7dea6296824621ee8272c35bba8083c0154
1 /*
2  * HLSL parser
3  *
4  * Copyright 2008 Stefan Dösinger
5  * Copyright 2012 Matteo Bruni for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
23 #include "wine/debug.h"
25 #define YY_NO_UNISTD_H
26 #include "d3dcompiler_private.h"
27 #include "hlsl.tab.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
31 #define YY_USER_ACTION                               \
32    do {                                              \
33       hlsl_lloc.first_column = hlsl_ctx.column;      \
34       hlsl_lloc.first_line = hlsl_ctx.line_no;       \
35       hlsl_ctx.column += yyleng;                     \
36    } while(0);
40 %option noyywrap nounput noinput never-interactive
41 %option prefix="hlsl_"
43 %x pp pp_line pp_pragma pp_ignore
45 RESERVED1               auto|case|catch|char|class|const_cast|default|delete|dynamic_cast|enum
46 RESERVED2               explicit|friend|goto|long|mutable|new|operator|private|protected|public
47 RESERVED3               reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
48 RESERVED4               typename|union|unsigned|using|virtual
50 WS                      [ \t]
51 NEWLINE                 (\n)|(\r\n)
52 DOUBLESLASHCOMMENT      "//"[^\n]*
53 STRING                  \"[^\"]*\"
54 IDENTIFIER              [A-Za-z_][A-Za-z0-9_]*
56 ANY                     (.)
59 {RESERVED1}             {
60                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
61                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
62                         }
63 {RESERVED2}             {
64                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
65                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
66                         }
67 {RESERVED3}             {
68                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
69                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
70                         }
71 {RESERVED4}             {
72                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
73                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
74                         }
76 BlendState              {return KW_BLENDSTATE;          }
77 break                   {return KW_BREAK;               }
78 Buffer                  {return KW_BUFFER;              }
79 cbuffer                 {return KW_CBUFFER;             }
80 compile                 {return KW_COMPILE;             }
81 const                   {return KW_CONST;               }
82 continue                {return KW_CONTINUE;            }
83 DepthStencilState       {return KW_DEPTHSTENCILSTATE;   }
84 DepthStencilView        {return KW_DEPTHSTENCILVIEW;    }
85 discard                 {return KW_DISCARD;             }
86 do                      {return KW_DO;                  }
87 double                  {return KW_DOUBLE;              }
88 else                    {return KW_ELSE;                }
89 extern                  {return KW_EXTERN;              }
90 false                   {return KW_FALSE;               }
91 for                     {return KW_FOR;                 }
92 GeometryShader          {return KW_GEOMETRYSHADER;      }
93 groupshared             {return KW_GROUPSHARED;         }
94 if                      {return KW_IF;                  }
95 in                      {return KW_IN;                  }
96 inline                  {return KW_INLINE;              }
97 inout                   {return KW_INOUT;               }
98 matrix                  {return KW_MATRIX;              }
99 namespace               {return KW_NAMESPACE;           }
100 nointerpolation         {return KW_NOINTERPOLATION;     }
101 out                     {return KW_OUT;                 }
102 pass                    {return KW_PASS;                }
103 PixelShader             {return KW_PIXELSHADER;         }
104 precise                 {return KW_PRECISE;             }
105 RasterizerState         {return KW_RASTERIZERSTATE;     }
106 RenderTargetView        {return KW_RENDERTARGETVIEW;    }
107 return                  {return KW_RETURN;              }
108 register                {return KW_REGISTER;            }
109 sampler                 {return KW_SAMPLER;             }
110 sampler1D               {return KW_SAMPLER1D;           }
111 sampler2D               {return KW_SAMPLER2D;           }
112 sampler3D               {return KW_SAMPLER3D;           }
113 samplerCUBE             {return KW_SAMPLERCUBE;         }
114 sampler_state           {return KW_SAMPLER_STATE;       }
115 SamplerComparisonState  {return KW_SAMPLERCOMPARISONSTATE;}
116 shared                  {return KW_SHARED;              }
117 stateblock              {return KW_STATEBLOCK;          }
118 stateblock_state        {return KW_STATEBLOCK_STATE;    }
119 static                  {return KW_STATIC;              }
120 string                  {return KW_STRING;              }
121 struct                  {return KW_STRUCT;              }
122 switch                  {return KW_SWITCH;              }
123 tbuffer                 {return KW_TBUFFER;             }
124 technique               {return KW_TECHNIQUE;           }
125 technique10             {return KW_TECHNIQUE10;         }
126 texture                 {return KW_TEXTURE;             }
127 texture1D               {return KW_TEXTURE1D;           }
128 Texture1DArray          {return KW_TEXTURE1DARRAY;      }
129 texture2D               {return KW_TEXTURE2D;           }
130 Texture2DArray          {return KW_TEXTURE2DARRAY;      }
131 Texture2DMS             {return KW_TEXTURE2DMS;         }
132 Texture2DMSArray        {return KW_TEXTURE2DMSARRAY;    }
133 texture3D               {return KW_TEXTURE3D;           }
134 Texture3DArray          {return KW_TEXTURE3DARRAY;      }
135 textureCUBE             {return KW_TEXTURECUBE;         }
136 true                    {return KW_TRUE;                }
137 typedef                 {return KW_TYPEDEF;             }
138 uniform                 {return KW_UNIFORM;             }
139 vector                  {return KW_VECTOR;              }
140 VertexShader            {return KW_VERTEXSHADER;        }
141 void                    {return KW_VOID;                }
142 volatile                {return KW_VOLATILE;            }
143 while                   {return KW_WHILE;               }
145 \+\+                    {return OP_INC;                 }
146 \-\-                    {return OP_DEC;                 }
147 &&                      {return OP_AND;                 }
148 \|\|                    {return OP_OR;                  }
149 ==                      {return OP_EQ;                  }
150 \<\<                    {return OP_LEFTSHIFT;           }
151 \<\<=                   {return OP_LEFTSHIFTASSIGN;     }
152 \>\>                    {return OP_RIGHTSHIFT;          }
153 \>\>=                   {return OP_RIGHTSHIFTASSIGN;    }
154 \.\.\.                  {return OP_ELLIPSIS;            }
155 \<=                     {return OP_LE;                  }
156 \>=                     {return OP_GE;                  }
157 !=                      {return OP_NE;                  }
158 \+=                     {return OP_ADDASSIGN;           }
159 \-=                     {return OP_SUBASSIGN;           }
160 \*=                     {return OP_MULASSIGN;           }
161 \/=                     {return OP_DIVASSIGN;           }
162 %=                      {return OP_MODASSIGN;           }
163 &=                      {return OP_ANDASSIGN;           }
164 \|=                     {return OP_ORASSIGN;            }
165 ^=                      {return OP_XORASSIGN;           }
166 ##                      {return OP_UNKNOWN1;            }
167 #@                      {return OP_UNKNOWN2;            }
168 ::                      {return OP_UNKNOWN3;            }
169 \-\>                    {return OP_UNKNOWN4;            }
171 column_major            {return KW_COLUMN_MAJOR;        }
172 row_major               {return KW_ROW_MAJOR;           }
174 {IDENTIFIER}            {
175                             hlsl_lval.name = d3dcompiler_strdup(yytext);
176                             if (get_variable(hlsl_ctx.cur_scope, yytext)
177                                     || find_function(yytext))
178                                 return VAR_IDENTIFIER;
179                             else if (get_type(hlsl_ctx.cur_scope, yytext, TRUE))
180                                 return TYPE_IDENTIFIER;
181                             else
182                                 return NEW_IDENTIFIER;
183                         }
185 [0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F]? {
186                             hlsl_lval.floatval = atof(yytext);
187                             return C_FLOAT;
188                         }
189 [0-9]+\.([eE][+-]?[0-9]+)?[h|H|f|F]? {
190                             hlsl_lval.floatval = atof(yytext);
191                             return C_FLOAT;
192                         }
193 [0-9]+([eE][+-]?[0-9]+)?[h|H|f|F] {
194                             hlsl_lval.floatval = atof(yytext);
195                             return C_FLOAT;
196                         }
197 0x[0-9a-fA-F]+          {
198                             sscanf(yytext, "0x%x", &hlsl_lval.intval);
199                             return C_INTEGER;
200                         }
201 0[0-7]+                 {
202                             sscanf(yytext, "0%o", &hlsl_lval.intval);
203                             return C_INTEGER;
204                         }
205 [0-9]+                  {
206                             hlsl_lval.intval = (atoi(yytext));
207                             return C_INTEGER;
208                         }
210 {DOUBLESLASHCOMMENT}    {}
212 {WS}+                   {}
213 {NEWLINE}               {
214                             hlsl_ctx.line_no++;
215                             hlsl_ctx.column = 1;
216                         }
218 ^#                      {
219                             BEGIN pp;
220                         }
222 <pp>pragma{WS}+         {
223                             TRACE("Got a #pragma.\n");
224                             BEGIN pp_pragma;
225                         }
226 <pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
227                             TRACE("#pragma setting row_major mode.\n");
228                             hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
229                             BEGIN pp_ignore;
230                         }
231 <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
232                             TRACE("#pragma setting column_major mode.\n");
233                             hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
234                             BEGIN pp_ignore;
235                         }
236 <pp_pragma>{NEWLINE}    {
237                             FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
238                             BEGIN INITIAL;
239                         }
240 <pp_pragma>{ANY}        {}
241 <pp>[0-9]+              {
242                             TRACE("Preprocessor line info.\n");
243                             BEGIN pp_line;
244                             hlsl_lval.intval = (atoi(yytext));
245                             return PRE_LINE;
246                         }
247 <pp_line>{STRING}       {
248                             char *string = d3dcompiler_strdup(yytext + 1);
250                             BEGIN pp_ignore;
251                             string[strlen(string) - 1] = 0;
252                             hlsl_lval.name = string;
253                             return STRING;
254                         }
255 <pp_line>{WS}+          {}
256 <pp_line>{NEWLINE}      {
257                             FIXME("Malformed preprocessor line directive?\n");
258                             BEGIN INITIAL;
259                         }
260 <pp_ignore>{NEWLINE}    {
261                             BEGIN INITIAL;
262                         }
263 <pp_ignore>{ANY}        {}
264 <pp>{NEWLINE}           {
265                             FIXME("Unexpected preprocessor directive.\n");
266                             BEGIN INITIAL;
267                         }
268 <pp>{ANY}               {}
270 {ANY}                   {
271                             return yytext[0];
272                         }
276 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD minor,
277         const char *entrypoint, char **messages);
279 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD major, DWORD minor,
280         const char *entrypoint, char **messages)
282     struct bwriter_shader *ret = NULL;
283     YY_BUFFER_STATE buffer;
285     buffer = hlsl__scan_string(text);
286     hlsl__switch_to_buffer(buffer);
288     ret = parse_hlsl(type, major, minor, entrypoint, messages);
290     hlsl__delete_buffer(buffer);
291     return ret;