Home | History | Annotate | Download | only in randomshaders
      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 
     31 Token::Token (const char* identifier)
     32 	: m_type(IDENTIFIER)
     33 {
     34 	m_arg.identifier = deStrdup(identifier);
     35 	if (!m_arg.identifier)
     36 		throw std::bad_alloc();
     37 }
     38 
     39 Token::~Token (void)
     40 {
     41 	if (m_type == IDENTIFIER)
     42 		deFree(m_arg.identifier);
     43 }
     44 
     45 Token& Token::operator= (const Token& other)
     46 {
     47 	if (m_type == IDENTIFIER)
     48 	{
     49 		deFree(m_arg.identifier);
     50 		m_arg.identifier = DE_NULL;
     51 	}
     52 
     53 	m_type = other.m_type;
     54 
     55 	if (m_type == IDENTIFIER)
     56 	{
     57 		m_arg.identifier = deStrdup(other.m_arg.identifier);
     58 		if (!m_arg.identifier)
     59 			throw std::bad_alloc();
     60 	}
     61 	else if (m_type == FLOAT_LITERAL)
     62 		m_arg.floatValue = other.m_arg.floatValue;
     63 	else if (m_type == INT_LITERAL)
     64 		m_arg.intValue = other.m_arg.intValue;
     65 	else if (m_type == BOOL_LITERAL)
     66 		m_arg.boolValue = other.m_arg.boolValue;
     67 
     68 	return *this;
     69 }
     70 
     71 Token::Token (const Token& other)
     72 	: m_type(TYPE_LAST)
     73 {
     74 	*this = other;
     75 }
     76 
     77 bool Token::operator!= (const Token& other) const
     78 {
     79 	if (m_type != other.m_type)
     80 		return false;
     81 
     82 	if (m_type == IDENTIFIER && !deStringEqual(m_arg.identifier, other.m_arg.identifier))
     83 		return false;
     84 	else if (m_type == FLOAT_LITERAL && m_arg.floatValue != other.m_arg.floatValue)
     85 		return false;
     86 	else if (m_type == INT_LITERAL && m_arg.intValue != other.m_arg.intValue)
     87 		return false;
     88 	else if (m_type == BOOL_LITERAL && m_arg.boolValue != other.m_arg.boolValue)
     89 		return false;
     90 
     91 	return true;
     92 }
     93 
     94 TokenStream::TokenStream (void)
     95 	: m_tokens		(ALLOC_SIZE)
     96 	, m_numTokens	(0)
     97 {
     98 }
     99 
    100 TokenStream::~TokenStream (void)
    101 {
    102 }
    103 
    104 } // rsg
    105