1*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Random Shader Generator 3*35238bceSAndroid Build Coastguard Worker * ---------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker * 5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 6*35238bceSAndroid Build Coastguard Worker * 7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at 10*35238bceSAndroid Build Coastguard Worker * 11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 12*35238bceSAndroid Build Coastguard Worker * 13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 17*35238bceSAndroid Build Coastguard Worker * limitations under the License. 18*35238bceSAndroid Build Coastguard Worker * 19*35238bceSAndroid Build Coastguard Worker *//*! 20*35238bceSAndroid Build Coastguard Worker * \file 21*35238bceSAndroid Build Coastguard Worker * \brief Token class. 22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 23*35238bceSAndroid Build Coastguard Worker 24*35238bceSAndroid Build Coastguard Worker #include "rsgToken.hpp" 25*35238bceSAndroid Build Coastguard Worker #include "deMemory.h" 26*35238bceSAndroid Build Coastguard Worker #include "deString.h" 27*35238bceSAndroid Build Coastguard Worker 28*35238bceSAndroid Build Coastguard Worker namespace rsg 29*35238bceSAndroid Build Coastguard Worker { 30*35238bceSAndroid Build Coastguard Worker Token(const char * identifier)31*35238bceSAndroid Build Coastguard WorkerToken::Token(const char *identifier) : m_type(IDENTIFIER) 32*35238bceSAndroid Build Coastguard Worker { 33*35238bceSAndroid Build Coastguard Worker m_arg.identifier = deStrdup(identifier); 34*35238bceSAndroid Build Coastguard Worker if (!m_arg.identifier) 35*35238bceSAndroid Build Coastguard Worker throw std::bad_alloc(); 36*35238bceSAndroid Build Coastguard Worker } 37*35238bceSAndroid Build Coastguard Worker ~Token(void)38*35238bceSAndroid Build Coastguard WorkerToken::~Token(void) 39*35238bceSAndroid Build Coastguard Worker { 40*35238bceSAndroid Build Coastguard Worker if (m_type == IDENTIFIER) 41*35238bceSAndroid Build Coastguard Worker deFree(m_arg.identifier); 42*35238bceSAndroid Build Coastguard Worker } 43*35238bceSAndroid Build Coastguard Worker operator =(const Token & other)44*35238bceSAndroid Build Coastguard WorkerToken &Token::operator=(const Token &other) 45*35238bceSAndroid Build Coastguard Worker { 46*35238bceSAndroid Build Coastguard Worker if (m_type == IDENTIFIER) 47*35238bceSAndroid Build Coastguard Worker { 48*35238bceSAndroid Build Coastguard Worker deFree(m_arg.identifier); 49*35238bceSAndroid Build Coastguard Worker m_arg.identifier = DE_NULL; 50*35238bceSAndroid Build Coastguard Worker } 51*35238bceSAndroid Build Coastguard Worker 52*35238bceSAndroid Build Coastguard Worker m_type = other.m_type; 53*35238bceSAndroid Build Coastguard Worker 54*35238bceSAndroid Build Coastguard Worker if (m_type == IDENTIFIER) 55*35238bceSAndroid Build Coastguard Worker { 56*35238bceSAndroid Build Coastguard Worker m_arg.identifier = deStrdup(other.m_arg.identifier); 57*35238bceSAndroid Build Coastguard Worker if (!m_arg.identifier) 58*35238bceSAndroid Build Coastguard Worker throw std::bad_alloc(); 59*35238bceSAndroid Build Coastguard Worker } 60*35238bceSAndroid Build Coastguard Worker else if (m_type == FLOAT_LITERAL) 61*35238bceSAndroid Build Coastguard Worker m_arg.floatValue = other.m_arg.floatValue; 62*35238bceSAndroid Build Coastguard Worker else if (m_type == INT_LITERAL) 63*35238bceSAndroid Build Coastguard Worker m_arg.intValue = other.m_arg.intValue; 64*35238bceSAndroid Build Coastguard Worker else if (m_type == BOOL_LITERAL) 65*35238bceSAndroid Build Coastguard Worker m_arg.boolValue = other.m_arg.boolValue; 66*35238bceSAndroid Build Coastguard Worker 67*35238bceSAndroid Build Coastguard Worker return *this; 68*35238bceSAndroid Build Coastguard Worker } 69*35238bceSAndroid Build Coastguard Worker Token(const Token & other)70*35238bceSAndroid Build Coastguard WorkerToken::Token(const Token &other) : m_type(TYPE_LAST) 71*35238bceSAndroid Build Coastguard Worker { 72*35238bceSAndroid Build Coastguard Worker *this = other; 73*35238bceSAndroid Build Coastguard Worker } 74*35238bceSAndroid Build Coastguard Worker operator !=(const Token & other) const75*35238bceSAndroid Build Coastguard Workerbool Token::operator!=(const Token &other) const 76*35238bceSAndroid Build Coastguard Worker { 77*35238bceSAndroid Build Coastguard Worker if (m_type != other.m_type) 78*35238bceSAndroid Build Coastguard Worker return false; 79*35238bceSAndroid Build Coastguard Worker 80*35238bceSAndroid Build Coastguard Worker if (m_type == IDENTIFIER && !deStringEqual(m_arg.identifier, other.m_arg.identifier)) 81*35238bceSAndroid Build Coastguard Worker return false; 82*35238bceSAndroid Build Coastguard Worker else if (m_type == FLOAT_LITERAL && m_arg.floatValue != other.m_arg.floatValue) 83*35238bceSAndroid Build Coastguard Worker return false; 84*35238bceSAndroid Build Coastguard Worker else if (m_type == INT_LITERAL && m_arg.intValue != other.m_arg.intValue) 85*35238bceSAndroid Build Coastguard Worker return false; 86*35238bceSAndroid Build Coastguard Worker else if (m_type == BOOL_LITERAL && m_arg.boolValue != other.m_arg.boolValue) 87*35238bceSAndroid Build Coastguard Worker return false; 88*35238bceSAndroid Build Coastguard Worker 89*35238bceSAndroid Build Coastguard Worker return true; 90*35238bceSAndroid Build Coastguard Worker } 91*35238bceSAndroid Build Coastguard Worker TokenStream(void)92*35238bceSAndroid Build Coastguard WorkerTokenStream::TokenStream(void) : m_tokens(ALLOC_SIZE), m_numTokens(0) 93*35238bceSAndroid Build Coastguard Worker { 94*35238bceSAndroid Build Coastguard Worker } 95*35238bceSAndroid Build Coastguard Worker ~TokenStream(void)96*35238bceSAndroid Build Coastguard WorkerTokenStream::~TokenStream(void) 97*35238bceSAndroid Build Coastguard Worker { 98*35238bceSAndroid Build Coastguard Worker } 99*35238bceSAndroid Build Coastguard Worker 100*35238bceSAndroid Build Coastguard Worker } // namespace rsg 101