gfx/angle/src/compiler/glslang.l

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/glslang.l	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,331 @@
     1.4 +/*
     1.5 +//
     1.6 +// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
     1.7 +// Use of this source code is governed by a BSD-style license that can be
     1.8 +// found in the LICENSE file.
     1.9 +//
    1.10 +
    1.11 +This file contains the Lex specification for GLSL ES.
    1.12 +Based on ANSI C grammar, Lex specification:
    1.13 +http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
    1.14 +
    1.15 +IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh,
    1.16 +WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
    1.17 +*/
    1.18 +
    1.19 +%top{
    1.20 +//
    1.21 +// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
    1.22 +// Use of this source code is governed by a BSD-style license that can be
    1.23 +// found in the LICENSE file.
    1.24 +//
    1.25 +
    1.26 +// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
    1.27 +
    1.28 +// Ignore errors in auto-generated code.
    1.29 +#if defined(__GNUC__)
    1.30 +#pragma GCC diagnostic ignored "-Wunused-function"
    1.31 +#pragma GCC diagnostic ignored "-Wunused-variable"
    1.32 +#pragma GCC diagnostic ignored "-Wswitch-enum"
    1.33 +#elif defined(_MSC_VER)
    1.34 +#pragma warning(disable: 4065)
    1.35 +#pragma warning(disable: 4189)
    1.36 +#pragma warning(disable: 4505)
    1.37 +#pragma warning(disable: 4701)
    1.38 +#endif
    1.39 +}
    1.40 +
    1.41 +%{
    1.42 +#include "compiler/glslang.h"
    1.43 +#include "compiler/ParseHelper.h"
    1.44 +#include "compiler/preprocessor/Token.h"
    1.45 +#include "compiler/util.h"
    1.46 +#include "glslang_tab.h"
    1.47 +
    1.48 +/* windows only pragma */
    1.49 +#ifdef _MSC_VER
    1.50 +#pragma warning(disable : 4102)
    1.51 +#endif
    1.52 +
    1.53 +#define YY_USER_ACTION                                 \
    1.54 +    yylloc->first_file = yylloc->last_file = yycolumn; \
    1.55 +    yylloc->first_line = yylloc->last_line = yylineno;
    1.56 +
    1.57 +#define YY_INPUT(buf, result, max_size) \
    1.58 +    result = string_input(buf, max_size, yyscanner);
    1.59 +
    1.60 +static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
    1.61 +static int check_type(yyscan_t yyscanner);
    1.62 +static int reserved_word(yyscan_t yyscanner);
    1.63 +%}
    1.64 +
    1.65 +%option noyywrap nounput never-interactive
    1.66 +%option yylineno reentrant bison-bridge bison-locations
    1.67 +%option extra-type="TParseContext*"
    1.68 +
    1.69 +D           [0-9]
    1.70 +L           [a-zA-Z_]
    1.71 +H           [a-fA-F0-9]
    1.72 +E           [Ee][+-]?{D}+
    1.73 +O           [0-7]
    1.74 +
    1.75 +%%
    1.76 +
    1.77 +"invariant"    { return INVARIANT; }
    1.78 +"highp"        { return HIGH_PRECISION; }
    1.79 +"mediump"      { return MEDIUM_PRECISION; }
    1.80 +"lowp"         { return LOW_PRECISION; }
    1.81 +"precision"    { return PRECISION; }
    1.82 +
    1.83 +"attribute"    { return ATTRIBUTE; }
    1.84 +"const"        { return CONST_QUAL; }
    1.85 +"uniform"      { return UNIFORM; }
    1.86 +"varying"      { return VARYING; }
    1.87 +
    1.88 +"break"        { return BREAK; }
    1.89 +"continue"     { return CONTINUE; }
    1.90 +"do"           { return DO; }
    1.91 +"for"          { return FOR; }
    1.92 +"while"        { return WHILE; }
    1.93 +
    1.94 +"if"           { return IF; }
    1.95 +"else"         { return ELSE; }
    1.96 +
    1.97 +"in"           { return IN_QUAL; }
    1.98 +"out"          { return OUT_QUAL; }
    1.99 +"inout"        { return INOUT_QUAL; }
   1.100 +
   1.101 +"float"        { return FLOAT_TYPE; }
   1.102 +"int"          { return INT_TYPE; }
   1.103 +"void"         { return VOID_TYPE; }
   1.104 +"bool"         { return BOOL_TYPE; }
   1.105 +"true"         { yylval->lex.b = true;  return BOOLCONSTANT; }
   1.106 +"false"        { yylval->lex.b = false; return BOOLCONSTANT; }
   1.107 +
   1.108 +"discard"      { return DISCARD; }
   1.109 +"return"       { return RETURN; }
   1.110 +
   1.111 +"mat2"         { return MATRIX2; }
   1.112 +"mat3"         { return MATRIX3; }
   1.113 +"mat4"         { return MATRIX4; }
   1.114 +
   1.115 +"vec2"         { return VEC2; }
   1.116 +"vec3"         { return VEC3; }
   1.117 +"vec4"         { return VEC4; }
   1.118 +"ivec2"        { return IVEC2; }
   1.119 +"ivec3"        { return IVEC3; }
   1.120 +"ivec4"        { return IVEC4; }
   1.121 +"bvec2"        { return BVEC2; }
   1.122 +"bvec3"        { return BVEC3; }
   1.123 +"bvec4"        { return BVEC4; }
   1.124 +
   1.125 +"sampler2D"          { return SAMPLER2D; }
   1.126 +"samplerCube"        { return SAMPLERCUBE; }
   1.127 +"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
   1.128 +"sampler2DRect"      { return SAMPLER2DRECT; }
   1.129 +
   1.130 +"struct"       { return STRUCT; }
   1.131 +
   1.132 +"asm"          { return reserved_word(yyscanner); }
   1.133 +
   1.134 +"class"        { return reserved_word(yyscanner); }
   1.135 +"union"        { return reserved_word(yyscanner); }
   1.136 +"enum"         { return reserved_word(yyscanner); }
   1.137 +"typedef"      { return reserved_word(yyscanner); }
   1.138 +"template"     { return reserved_word(yyscanner); }
   1.139 +"this"         { return reserved_word(yyscanner); }
   1.140 +"packed"       { return reserved_word(yyscanner); }
   1.141 +
   1.142 +"goto"         { return reserved_word(yyscanner); }
   1.143 +"switch"       { return reserved_word(yyscanner); }
   1.144 +"default"      { return reserved_word(yyscanner); }
   1.145 +
   1.146 +"inline"       { return reserved_word(yyscanner); }
   1.147 +"noinline"     { return reserved_word(yyscanner); }
   1.148 +"volatile"     { return reserved_word(yyscanner); }
   1.149 +"public"       { return reserved_word(yyscanner); }
   1.150 +"static"       { return reserved_word(yyscanner); }
   1.151 +"extern"       { return reserved_word(yyscanner); }
   1.152 +"external"     { return reserved_word(yyscanner); }
   1.153 +"interface"    { return reserved_word(yyscanner); }
   1.154 +"flat"         { return reserved_word(yyscanner); }
   1.155 +
   1.156 +"long"         { return reserved_word(yyscanner); }
   1.157 +"short"        { return reserved_word(yyscanner); }
   1.158 +"double"       { return reserved_word(yyscanner); }
   1.159 +"half"         { return reserved_word(yyscanner); }
   1.160 +"fixed"        { return reserved_word(yyscanner); }
   1.161 +"unsigned"     { return reserved_word(yyscanner); }
   1.162 +"superp"       { return reserved_word(yyscanner); }
   1.163 +
   1.164 +"input"        { return reserved_word(yyscanner); }
   1.165 +"output"       { return reserved_word(yyscanner); }
   1.166 +
   1.167 +"hvec2"        { return reserved_word(yyscanner); }
   1.168 +"hvec3"        { return reserved_word(yyscanner); }
   1.169 +"hvec4"        { return reserved_word(yyscanner); }
   1.170 +"dvec2"        { return reserved_word(yyscanner); }
   1.171 +"dvec3"        { return reserved_word(yyscanner); }
   1.172 +"dvec4"        { return reserved_word(yyscanner); }
   1.173 +"fvec2"        { return reserved_word(yyscanner); }
   1.174 +"fvec3"        { return reserved_word(yyscanner); }
   1.175 +"fvec4"        { return reserved_word(yyscanner); }
   1.176 +
   1.177 +"sampler1D"           { return reserved_word(yyscanner); }
   1.178 +"sampler3D"           { return reserved_word(yyscanner); }
   1.179 +"sampler1DShadow"     { return reserved_word(yyscanner); }
   1.180 +"sampler2DShadow"     { return reserved_word(yyscanner); }
   1.181 +"sampler3DRect"       { return reserved_word(yyscanner); }
   1.182 +"sampler2DRectShadow" { return reserved_word(yyscanner); }
   1.183 +
   1.184 +"sizeof"       { return reserved_word(yyscanner); }
   1.185 +"cast"         { return reserved_word(yyscanner); }
   1.186 +
   1.187 +"namespace"    { return reserved_word(yyscanner); }
   1.188 +"using"        { return reserved_word(yyscanner); }
   1.189 +
   1.190 +{L}({L}|{D})*       {
   1.191 +   yylval->lex.string = NewPoolTString(yytext); 
   1.192 +   return check_type(yyscanner);
   1.193 +}
   1.194 +
   1.195 +0[xX]{H}+         { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
   1.196 +0{O}+             { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
   1.197 +{D}+              { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return INTCONSTANT; }
   1.198 +
   1.199 +{D}+{E}           { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
   1.200 +{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
   1.201 +"."{D}+({E})?     { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return FLOATCONSTANT; }
   1.202 +
   1.203 +"+="            { return ADD_ASSIGN; }
   1.204 +"-="            { return SUB_ASSIGN; }
   1.205 +"*="            { return MUL_ASSIGN; }
   1.206 +"/="            { return DIV_ASSIGN; }
   1.207 +"%="            { return MOD_ASSIGN; }
   1.208 +"<<="           { return LEFT_ASSIGN; }
   1.209 +">>="           { return RIGHT_ASSIGN; }
   1.210 +"&="            { return AND_ASSIGN; }
   1.211 +"^="            { return XOR_ASSIGN; }
   1.212 +"|="            { return OR_ASSIGN; }
   1.213 +
   1.214 +"++"            { return INC_OP; }
   1.215 +"--"            { return DEC_OP; }
   1.216 +"&&"            { return AND_OP; }
   1.217 +"||"            { return OR_OP; }
   1.218 +"^^"            { return XOR_OP; }
   1.219 +"<="            { return LE_OP; }
   1.220 +">="            { return GE_OP; }
   1.221 +"=="            { return EQ_OP; }
   1.222 +"!="            { return NE_OP; }
   1.223 +"<<"            { return LEFT_OP; }
   1.224 +">>"            { return RIGHT_OP; }
   1.225 +";"             { return SEMICOLON; }
   1.226 +("{"|"<%")      { return LEFT_BRACE; }
   1.227 +("}"|"%>")      { return RIGHT_BRACE; }
   1.228 +","         { return COMMA; }
   1.229 +":"         { return COLON; }
   1.230 +"="         { return EQUAL; }
   1.231 +"("         { return LEFT_PAREN; }
   1.232 +")"         { return RIGHT_PAREN; }
   1.233 +("["|"<:")  { return LEFT_BRACKET; }
   1.234 +("]"|":>")  { return RIGHT_BRACKET; }
   1.235 +"."         { return DOT; }
   1.236 +"!"         { return BANG; }
   1.237 +"-"         { return DASH; }
   1.238 +"~"         { return TILDE; }
   1.239 +"+"         { return PLUS; }
   1.240 +"*"         { return STAR; }
   1.241 +"/"         { return SLASH; }
   1.242 +"%"         { return PERCENT; }
   1.243 +"<"         { return LEFT_ANGLE; }
   1.244 +">"         { return RIGHT_ANGLE; }
   1.245 +"|"         { return VERTICAL_BAR; }
   1.246 +"^"         { return CARET; }
   1.247 +"&"         { return AMPERSAND; }
   1.248 +"?"         { return QUESTION; }
   1.249 +
   1.250 +[ \t\v\n\f\r] { }
   1.251 +<<EOF>>    { yyterminate(); }
   1.252 +.          { assert(false); return 0; }
   1.253 +
   1.254 +%%
   1.255 +
   1.256 +yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
   1.257 +    pp::Token token;
   1.258 +    yyget_extra(yyscanner)->preprocessor.lex(&token);
   1.259 +    yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
   1.260 +    if (len < max_size)
   1.261 +        memcpy(buf, token.text.c_str(), len);
   1.262 +    yyset_column(token.location.file, yyscanner);
   1.263 +    yyset_lineno(token.location.line, yyscanner);
   1.264 +
   1.265 +    if (len >= max_size)
   1.266 +        YY_FATAL_ERROR("Input buffer overflow");
   1.267 +    else if (len > 0)
   1.268 +        buf[len++] = ' ';
   1.269 +    return len;
   1.270 +}
   1.271 +
   1.272 +int check_type(yyscan_t yyscanner) {
   1.273 +    struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
   1.274 +    
   1.275 +    int token = IDENTIFIER;
   1.276 +    TSymbol* symbol = yyextra->symbolTable.find(yytext);
   1.277 +    if (symbol && symbol->isVariable()) {
   1.278 +        TVariable* variable = static_cast<TVariable*>(symbol);
   1.279 +        if (variable->isUserType())
   1.280 +            token = TYPE_NAME;
   1.281 +    }
   1.282 +    yylval->lex.symbol = symbol;
   1.283 +    return token;
   1.284 +}
   1.285 +
   1.286 +int reserved_word(yyscan_t yyscanner) {
   1.287 +    struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
   1.288 +
   1.289 +    yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
   1.290 +    yyextra->recover();
   1.291 +    return 0;
   1.292 +}
   1.293 +
   1.294 +int glslang_initialize(TParseContext* context) {
   1.295 +    yyscan_t scanner = NULL;
   1.296 +    if (yylex_init_extra(context, &scanner))
   1.297 +        return 1;
   1.298 +
   1.299 +    context->scanner = scanner;
   1.300 +    return 0;
   1.301 +}
   1.302 +
   1.303 +int glslang_finalize(TParseContext* context) {
   1.304 +    yyscan_t scanner = context->scanner;
   1.305 +    if (scanner == NULL) return 0;
   1.306 +    
   1.307 +    context->scanner = NULL;
   1.308 +    yylex_destroy(scanner);
   1.309 +
   1.310 +    return 0;
   1.311 +}
   1.312 +
   1.313 +int glslang_scan(size_t count, const char* const string[], const int length[],
   1.314 +                 TParseContext* context) {
   1.315 +    yyrestart(NULL, context->scanner);
   1.316 +    yyset_column(0, context->scanner);
   1.317 +    yyset_lineno(1, context->scanner);
   1.318 +
   1.319 +    // Initialize preprocessor.
   1.320 +    if (!context->preprocessor.init(count, string, length))
   1.321 +        return 1;
   1.322 +
   1.323 +    // Define extension macros.
   1.324 +    const TExtensionBehavior& extBehavior = context->extensionBehavior();
   1.325 +    for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
   1.326 +         iter != extBehavior.end(); ++iter) {
   1.327 +        context->preprocessor.predefineMacro(iter->first.c_str(), 1);
   1.328 +    }
   1.329 +    if (context->fragmentPrecisionHigh)
   1.330 +        context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
   1.331 +
   1.332 +    return 0;
   1.333 +}
   1.334 +

mercurial