encoder_host.cc

Go to the documentation of this file.
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   \brief Host chacter set encoder.
00030 
00031   Declaration of encoder_host class performing host character set encoding.
00032   \author pt
00033 */
00034 
00035 #include <lestes/common.hh>
00036 #include <lestes/lang/cplus/lex/encoder_host.hh>
00037 // TODO
00038 // #include lestes/lang/cplus/lex/encoder_host.lmd>
00039 #include <lestes/msg/message.hh>
00040 
00041 // TODO#include <iostream>
00042 
00043 package(lestes);
00044 package(lang);
00045 package(cplus);
00046 package(lex);
00047 
00048 using namespace ::std;
00049 
00050 /*!
00051   Creates the encoder.
00052 */
00053 encoder_host::encoder_host(void)
00054 {
00055 }
00056 
00057 /*!
00058   Reads next token. Performs encoding from host character set.
00059   Checks whether the input contains valid characters, for which the encoding into ucn is known.
00060   If error is encountered, it returns token with type ucn_token::TOK_ERROR.
00061   \pre  Input into the filter is set.
00062   \return  The next token encoded from host character.
00063   \return  Token with type ucn_token::TOK_ERROR if the source character is invalid (out of range).
00064   \return  Token with type ucn_token::TOK_EOF in case of previous error.
00065 */
00066 ptr<ucn_token> encoder_host::read(void)
00067 {
00068         // TODO remove return the eof token in case of previous error if (bad) return bad;
00069         
00070         ptr<ucn_token> t = input_read();
00071         ucn u = t->value_get();
00072         ucn_token_type utt = t->type_get();
00073 
00074         if (utt == ucn_token::TOK_NOT_EOF) {
00075                 // check that the character is can be converted to internal
00076                 if (character::is_encodable_host(u)) {
00077                         ulint x = character::extract_value(u);
00078                         // encode value in source charset
00079                         // TODO t->value_set(character::create_from_host(static_cast<hchar>(x)));
00080                         t = t->clone_value(character::create_from_host(static_cast<hchar>(x))); 
00081                 } else {
00082                         // TODO report error: value out of range for ASCII
00083                         //t->type_set(ucn_token::TOK_ERROR);
00084                         // TODO pt remove set flag for next calls
00085                         //bad = ucn_token::create(ucn_token::TOK_EOF);
00086                         // TODO pt
00087                         t = ucn_token::create_error(::lestes::msg::message::create(0xdada,"TODO encoder_host",::lestes::msg::message::FLG_ERROR));
00088                 }
00089         }
00090 
00091         return t;
00092 }
00093 
00094 /*!
00095   Marks the object.
00096 */
00097 void encoder_host::gc_mark(void)
00098 {
00099         encoder::gc_mark();
00100 }
00101 
00102 /*!
00103   Returns new instance of the encoder.
00104   \return  The new instance.
00105 */
00106 ptr<encoder_host> encoder_host::create(void)
00107 {
00108         return new encoder_host();
00109 }
00110 
00111 end_package(lex);
00112 end_package(cplus);
00113 end_package(lang);
00114 end_package(lestes);
00115 
00116 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:33 2007 for lestes by doxygen 1.5.1-20070107