13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RSGTOKEN_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RSGTOKEN_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Random Shader Generator 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Token class. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rsg 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Token 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum Type 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IDENTIFIER, 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STRUCT, 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INVARIANT, 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PRECISION, 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VOID, 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BREAK, 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CONTINUE, 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DO, 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry WHILE, 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ELSE, 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR, 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IF, 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DISCARD, 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RETURN, 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INC_OP, 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DEC_OP, 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LEFT_PAREN, 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RIGHT_PAREN, 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LEFT_BRACKET, // [ 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RIGHT_BRACKET, // ] 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LEFT_BRACE, // { 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RIGHT_BRACE, // } 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DOT, 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry COMMA, 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry COLON, 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SEMICOLON, 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MINUS, 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PLUS, 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MUL, 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DIV, 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MOD, 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry QUESTION, 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BOOL, 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BVEC2, 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BVEC3, 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BVEC4, 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INT, 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVEC2, 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVEC3, 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVEC4, 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FLOAT, 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VEC2, 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VEC3, 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VEC4, 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAT2, 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAT3, 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MAT4, 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SAMPLER2D, 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SAMPLERCUBE, 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FLOAT_LITERAL, 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INT_LITERAL, 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BOOL_LITERAL, 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry EQUAL, 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MUL_ASSIGN, 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DIV_ASSIGN, 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ADD_ASSIGN, 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SUB_ASSIGN, 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_LT, 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_GT, 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_LE, 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_GE, 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_EQ, 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CMP_NE, 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOGICAL_AND, 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOGICAL_OR, 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOGICAL_NOT, 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOGICAL_XOR, 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ATTRIBUTE, 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry UNIFORM, 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VARYING, 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CONST, 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FLAT, 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry HIGH_PRECISION, 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry MEDIUM_PRECISION, 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOW_PRECISION, 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IN, 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry OUT, 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INOUT, 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LAYOUT, 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry LOCATION, 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Formatting only 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDENT_INC, 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry INDENT_DEC, 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NEWLINE, 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_LAST 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (void); 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (Type type); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (const char* identifier); 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (float value); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (int value); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (bool value); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token (const Token& other); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Token (void); 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry inline bool operator== (Type type) const { return m_type == type; } 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry inline bool operator!= (Type type) const { return m_type != type; } 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator== (const Token& other) const; 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator!= (const Token& other) const; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Token& operator= (const Token& other); 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry inline Type getType (void) const { return m_type; } 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getIdentifier (void) const; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float getFloat (void) const; 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getInt (void) const; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool getBool (void) const; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type m_type; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry char* identifier; 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float floatValue; 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int intValue; 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool boolValue; 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } m_arg; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Token::Token (void) 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(TYPE_LAST) 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_arg.identifier = DE_NULL; 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Token::Token (Type type) 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(type) 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(type != IDENTIFIER); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Token::Token (float value) 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(FLOAT_LITERAL) 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_arg.floatValue = value; 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Token::Token (int value) 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(INT_LITERAL) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_arg.intValue = value; 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline Token::Token (bool value) 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_type(BOOL_LITERAL) 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_arg.boolValue = value; 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool Token::operator== (const Token& other) const 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return !(*this != other); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline const char* Token::getIdentifier (void) const 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_type == IDENTIFIER); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_arg.identifier; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline float Token::getFloat (void) const 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_type == FLOAT_LITERAL); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_arg.floatValue; 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline int Token::getInt (void) const 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_type == INT_LITERAL); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_arg.intValue; 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool Token::getBool (void) const 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_type == BOOL_LITERAL); 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_arg.boolValue; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TokenStream 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TokenStream (void); 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~TokenStream (void); 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getSize (void) const { return (int)m_numTokens; } 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Token& operator[] (int ndx) const { return m_tokens[ndx]; } 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TokenStream& operator<< (const Token& token); 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ALLOC_SIZE = 64 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Token> m_tokens; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry size_t m_numTokens; 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline TokenStream& TokenStream::operator<< (const Token& token) 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_tokens.size() == m_numTokens) 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_tokens.resize(m_numTokens+ALLOC_SIZE); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_tokens[m_numTokens] = token; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_numTokens += 1; 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rsg 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RSGTOKEN_HPP 258