00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 /*! \file 00029 Definiton of token_value class representing values of tokens. 00030 \author pt 00031 */ 00032 #include <lestes/common.hh> 00033 #include <lestes/equality.hh> 00034 #include <lestes/lang/cplus/lex/token_value.hh> 00035 00036 package(lestes); 00037 package(lang); 00038 package(cplus); 00039 package(lex); 00040 00041 /*! 00042 Constructs object, initializes with a_content. 00043 \post is_equal(content,a_content) 00044 \param a_content The initialization value. 00045 */ 00046 token_value::token_value(const content_type &a_content): 00047 content(a_content) 00048 { 00049 } 00050 00051 00052 /*! 00053 Returns new token value, initializes with a_content. 00054 \param a_content The initialization value. 00055 */ 00056 ptr<token_value> token_value::create(const content_type &a_content) 00057 { 00058 // singleton-like factory 00059 shared_type::iterator it = shared->find(a_content); 00060 if (it != shared->end()) return (*it).second; 00061 ptr<token_value> nju = new token_value(a_content); 00062 shared->insert(shared_type::value_type(a_content,nju)); 00063 return nju; 00064 // TODO pt remove return ptr<token_value>(new token_value(a_content)); 00065 } 00066 00067 /*! 00068 Tests equality. Because of sharing instances, only pointers are compared. 00069 \param other The token value to compare to. 00070 \return true If both contents are equal. 00071 */ 00072 bool token_value::equals(const ptr<token_value> &other) const 00073 { 00074 return other == this; 00075 } 00076 00077 /*! 00078 Returns content of value object. 00079 \return The content of the object. 00080 */ 00081 token_value::content_type token_value::content_get(void) const 00082 { 00083 return content; 00084 } 00085 00086 /*! 00087 Returns hash value of content. 00088 \return The hash value. 00089 */ 00090 ulint token_value::hash(void) const 00091 { 00092 // TODO compute hash from content 00093 return 0; 00094 } 00095 00096 /*! 00097 Compares to other token value. The content is compared with < operator. 00098 \param other The token value to compare. 00099 \return true If the other is not null and the content compares less. 00100 */ 00101 bool token_value::less_than(const ptr<token_value> &other) const 00102 { 00103 return other && is_less(content_get(),other->content_get()); 00104 } 00105 00106 /*! 00107 Compares two token values. Null is less than everything else. 00108 Otherwise content is compared with < operator. 00109 \param left The left operand for the comparator. 00110 \param right The right operand for the comparator. 00111 \return true If only left operand is null or left->less_than(right). 00112 */ 00113 bool token_value::compare_less::operator()(const ptr<token_value> &left, const ptr<token_value> &right) const 00114 { 00115 return is_less(left,right); 00116 } 00117 00118 /*! 00119 Compares two token value contents with < operator. 00120 \param left The left operand for the comparator. 00121 \param right The right operand for the comparator. 00122 \return true If left operand < right operand. 00123 */ 00124 bool token_value::compare_content::operator()(const content_type &left, const content_type &right) const 00125 { 00126 return is_less(left,right); 00127 } 00128 00129 /*! 00130 Structure for sharing instances of token value having the same content. 00131 */ 00132 ptr<token_value::shared_type> token_value::shared = token_value::shared_type::create(); 00133 00134 end_package(lex); 00135 end_package(cplus); 00136 end_package(lang); 00137 end_package(lestes); 00138 /* vim: set ft=lestes : */
1.5.1-20070107