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 #ifndef lestes__lang__cplus__lex___token_value_hh___included 00029 #define lestes__lang__cplus__lex___token_value_hh___included 00030 00031 /*! \file 00032 \brief Token value. 00033 00034 Declaration of token_value class representing values of tokens. 00035 \author pt 00036 */ 00037 #include <lestes/common.hh> 00038 #include <lestes/std/map.hh> 00039 #include <lestes/std/ucn_string.hh> 00040 00041 package(lestes); 00042 package(lang); 00043 package(cplus); 00044 package(lex); 00045 00046 /*! 00047 \brief Token value. 00048 00049 Represents token value, wrapping ucn_string. The object is constant and shared. 00050 */ 00051 class token_value: public ::lestes::std::object { 00052 public: 00053 //! Type of content. 00054 typedef ucn_string content_type; 00055 //! Returns object initialized with content. 00056 static ptr<token_value> create(const content_type &a_content); 00057 //! Returns content. 00058 ucn_string content_get(void) const; 00059 //! Tests equality. 00060 bool equals(const ptr<token_value> &other) const; 00061 //! Tests inequality. 00062 bool less_than(const ptr<token_value> &other) const; 00063 //! returns hash of the content 00064 ulint hash(void) const; 00065 //! Less than comparator for token_value. 00066 struct compare_less { 00067 //! Compares two token values. 00068 bool operator()(const ptr<token_value> &left, const ptr<token_value> &right) const; 00069 }; 00070 private: 00071 //! Creates object with content. 00072 token_value(const content_type &a_content); 00073 //! The representation of the value. 00074 content_type content; 00075 //! Less than comparator. 00076 struct compare_content { 00077 bool operator()(const content_type &left, const content_type &right) const; 00078 }; 00079 //! Type of structure for sharing instances. 00080 typedef ::lestes::std::map<content_type,srp<token_value>,compare_content> shared_type; 00081 //! Structure for sharing instances. 00082 // TODO pt make weak, or mark only the object itself and not its entries 00083 static ptr<shared_type> shared; 00084 }; 00085 00086 end_package(lex); 00087 end_package(cplus); 00088 end_package(lang); 00089 end_package(lestes); 00090 00091 #endif 00092 /* vim: set ft=lestes : */
1.5.1-20070107