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