unit_part.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 Part of translation unit.
00030 
00031   Definition of unit_part class representing one part of the translation unit.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/std/file_info.hh>
00036 #include <lestes/lang/cplus/lex/unit_part.hh>
00037 #include <lestes/lang/cplus/lex/pp_token.hh>
00038 #include <lestes/lang/cplus/lex/encoder.hh>
00039 #include <lestes/lang/cplus/lex/pre_lex.hh>
00040 #include <lestes/lang/cplus/lex/data_source.hh>
00041 #include <lestes/lang/cplus/lex/pp_lex.hh>
00042 #include <lestes/lang/cplus/lex/condition_stack.hh>
00043 #include <lestes/lang/cplus/lex/macro_storage.hh>
00044 #include <lestes/lang/cplus/lex/expander.hh>
00045 #include <lestes/lang/cplus/lex/line_control.hh>
00046 
00047 package(lestes);
00048 package(lang);
00049 package(cplus);
00050 package(lex);
00051 
00052 using namespace ::std;
00053 
00054 /*!
00055   Creates the object.
00056   \pre a_file != NULL
00057   \pre a_data != NULL
00058   \pre a_encoder != NULL
00059   \pre a_macros != NULL
00060   \param a_file  The file information.
00061   \param a_data  The data source.
00062   \param a_encoder  The encoder for the source.
00063   \param a_macros  The defined macros.
00064 */
00065 unit_part::unit_part(const ptr<file_info> &a_file, const ptr<data_source> &a_data,
00066                 const ptr<encoder> &a_encoder, const ptr<macro_storage> &a_macros):
00067         start(false),
00068         conditions(condition_stack::create()),
00069         enc(checked(a_encoder)),
00070         ds(checked(a_data)),
00071         plx(pre_lex::create(ds,enc)),
00072         lic(line_control::create(checked(a_file))),
00073         ppl(pp_lex::create(plx,lic)),
00074         exp(expander::create(this,checked(a_macros)))
00075 {
00076 }
00077 
00078 // TODO pt remove
00079 #if 0
00080 void unit_part::activate(void)
00081 {
00082         ppl->activate();
00083 }
00084 #endif
00085 
00086 /*!
00087   Sets start of line flag to help pp_lex switch to read tokens within include.
00088   The flag is cleared automatically after first call to read().
00089 */
00090 void unit_part::start_of_line(void)
00091 {
00092         start = true;
00093 }
00094 
00095 /*!
00096   Returns associated condition stack.
00097   \return The condition stack.
00098 */
00099 ptr<condition_stack> unit_part::conditions_get(void) const
00100 {
00101         return conditions;
00102 }
00103 
00104 /*!
00105   Returns the associated expander.
00106   \return The expander connected to this unit part.
00107 */
00108 ptr<expander> unit_part::expander_get(void) const
00109 {
00110         return exp;
00111 }
00112 
00113 // TODO pt keep ??
00114 /*!
00115   Returns the associated line control.
00116   \return  The line control.
00117 */
00118 ptr<line_control> unit_part::line_control_get(void) const
00119 {
00120         return lic;
00121 }
00122 
00123 // TODO pt remove
00124 /*!
00125   Performs updates triggered by #line directive.
00126   \param file_name  The new name of the current file.
00127   \param a_line  The new line number of the next line.
00128 void unit_part::line_change(lstring file_name, ulint a_line)
00129 {
00130         // TODO pt rename ^^^^^^^^
00131         // TODO pt call the new style
00132         //ppl->line_change(file_name,a_line);
00133         //ptr<line_control> lines = ppl->lines_get();
00134         //lines->change_line(location,a_line);
00135         //lines->change_file(file_name);
00136 }
00137 */
00138 
00139 /*!
00140   Reads next token from the unit part.
00141   Updates token location by the relative location.
00142   \return  The next token in the unit part.
00143 */
00144 ptr<pp_token> unit_part::read(void)
00145 {
00146         // TODO pt check and emit errors, with changed locations
00147         // if (ppl->has_errors()) {
00148         // ppl->errors_get();
00149         // process
00150         // }
00151         
00152         ptr<pp_token> tok = ppl->read(start);
00153         start = false;
00154 
00155         // TODO pt update location
00156         // what the hell ???
00157         // this is obsolete
00158 
00159         return tok;
00160 }
00161 
00162 /*!
00163   Marks the object.
00164 */
00165 void unit_part::gc_mark(void)
00166 {
00167         conditions.gc_mark();
00168         enc.gc_mark();
00169         ds.gc_mark();
00170         plx.gc_mark();
00171         lic.gc_mark();
00172         ppl.gc_mark();
00173         exp.gc_mark();
00174         pp_filter::gc_mark();
00175 }
00176 
00177 /*!
00178   Returns new instance, initializes with file information, stream and encoding.
00179   \param a_file  The file information for the unit part.
00180   \param a_data  The data source.
00181   \param a_encoder  The encoder for the source.
00182   \param a_macros  The defined macros.
00183   \return New instance of the class.
00184 */
00185 ptr<unit_part> unit_part::create(const ptr<file_info> &a_file,
00186                 const ptr<data_source> &a_data, const ptr<encoder> &a_encoder,
00187                 const ptr<macro_storage> &a_macros)
00188 {
00189         return new unit_part(a_file,a_data,a_encoder,a_macros);
00190 }
00191 
00192 end_package(lex);
00193 end_package(cplus);
00194 end_package(lang);
00195 end_package(lestes);
00196 
00197 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:23:44 2007 for lestes by doxygen 1.5.1-20070107