line_numbers.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 Token numbering filter.
00030 
00031   Definition of line_numbers class performing token numbering.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/lex/line_numbers.hh>
00036 #include <lestes/lang/cplus/lex/ucn_filter.hh>
00037 #include <lestes/lang/cplus/lex/simple_location.hh>
00038 
00039 package(lestes);
00040 package(lang);
00041 package(cplus);
00042 package(lex);
00043 
00044 /*!
00045   Creates the object, initializes with first line and column.
00046   \post line == 1
00047   \post column == 1
00048 */
00049 line_numbers::line_numbers(void):
00050         line(1),
00051         column(1)
00052 {
00053 }
00054 
00055 /*!
00056   Reads next token, assigns line and column numbers.
00057   The line number is relative to the physical start of the file.
00058   It does not reflect the #line directives yet.
00059 */
00060 ptr<ucn_token> line_numbers::read(void)
00061 {
00062         ptr<simple_location> loc = simple_location::create(line,column);
00063         ptr<ucn_token> t = input_read();
00064         ucn_token_type utt = t->type_get();
00065         t = t->clone_location(loc);
00066 
00067         switch (utt) {
00068                 case ucn_token::TOK_BASIC:
00069                         // line end
00070                         if (t->value_get() == character::ascii_new_line) {
00071                                 // reset column
00072                                 column = 1;
00073                                 // update line
00074                                 line++;
00075                                 break;
00076                         }
00077                         // fall through
00078                 case ucn_token::TOK_TRANSLATED:
00079                         // update column
00080                         column++;
00081                         break;
00082                 case ucn_token::TOK_ERROR:
00083                 case ucn_token::TOK_EOF:
00084                         // no need to update line or column
00085                         break;
00086                 default:
00087                         // TODO pt ICE
00088                         lassert(false);
00089                         break;
00090         }
00091         return t;
00092 }
00093 
00094 /*!
00095   Returns new instance.
00096   \return New instance of this class.
00097 */
00098 ptr<line_numbers> line_numbers::create(void)
00099 {
00100         return new line_numbers();
00101 }
00102 
00103 end_package(lex);
00104 end_package(cplus);
00105 end_package(lang);
00106 end_package(lestes);
00107 
00108 /* vim: set ft=lestes : */

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