source_location.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 location.
00030 
00031   Definition of location class representing token location.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/equality.hh>
00036 #include <lestes/std/source_location.hh>
00037 #include <lestes/std/file_info.hh>
00038 #include <lestes/std/reflect.hh>
00039 #include <lestes/std/list.hh>
00040 #include <lestes/std/pair.hh>
00041 
00042 package(lestes);
00043 package(std);
00044 
00045 using namespace ::std;
00046 
00047 /*!
00048   Creates new object, initializes with file information and position.
00049   \pre a_file != NULL
00050   \param a_file  The file information.
00051   \param a_line  The line in the file.
00052   \param a_column  The column on the line.
00053   \param a_order  The order in the translation unit.
00054 */
00055 source_location::source_location(const ptr<file_info> &a_file,
00056                 ulint a_line, ulint a_column, ulint a_order):
00057         file((lassert(a_file), a_file)),
00058         line(a_line),
00059         column(a_column),
00060         order(a_order)
00061 {
00062 }
00063 
00064 /*!
00065  * Standard marking routine, called by the garbage collector.
00066  */
00067 void source_location::gc_mark(void)
00068 {
00069         file.gc_mark();
00070         object::gc_mark();
00071 }
00072 
00073 /*!
00074   Returns file information.
00075   \return The file information.
00076 */
00077 ptr<file_info> source_location::file_get(void) const
00078 {
00079         return file;
00080 }
00081 
00082 /*!
00083   Returns position in the file.
00084   \return The line number.
00085 */
00086 ulint source_location::line_get(void) const
00087 {
00088         return line;
00089 }
00090 
00091 /*!
00092   Returns position on the line.
00093   \return The column number.
00094 */
00095 ulint source_location::column_get(void) const
00096 {
00097         return column;
00098 }
00099 
00100 /*!
00101   Tests equality to other source_location.
00102   \param rhs  The location to compare to.
00103 */
00104 bool source_location::equals(const ptr<source_location> &rhs) const
00105 {
00106         return rhs && is_equal(file,rhs->file_get()) &&
00107           is_equal(line,rhs->line_get()) &&
00108           is_equal(column,rhs->column_get());
00109 }
00110 
00111 /*!
00112   Returns order in translation unit.
00113   \return  The order.
00114 */
00115 ulint source_location::order_get() const
00116 {
00117         return order;
00118 }
00119 
00120 /*!
00121   Clones the location with new order.
00122   \param a_order  The order for the new location.
00123   \return The location with changed order.
00124 */
00125 ptr<source_location> source_location::clone_order(ulint a_order) const
00126 {
00127         return new source_location(file_get(),line_get(),column_get(),a_order);
00128 }
00129 
00130 /*!
00131   Clones the location with new file information.
00132   \param a_file  The file_information for the new location.
00133   \return The location with changed file information.
00134 */
00135 ptr<source_location> source_location::clone_file(const ptr<file_info> &a_file) const
00136 {
00137         return new source_location(a_file,line_get(),column_get(),order_get());
00138 }
00139 
00140 /*!
00141   Returns new instance, initializes with file information and position.
00142   \pre a_file != NULL
00143   \param a_file  The file information.
00144   \param a_line  The line in the file.
00145   \param a_column  The column on the line.
00146   \return The location.
00147 */
00148 ptr<source_location> source_location::create(const ptr<file_info> &a_file,
00149                 ulint a_line, ulint a_column)
00150 {
00151         return new source_location(a_file,a_line,a_column,0);
00152 }
00153 
00154 /*!
00155   Returns new instance, initializes with file information, position and order.
00156   \pre a_file != NULL
00157   \param a_file  The file information.
00158   \param a_line  The line in the file.
00159   \param a_column  The column on the line.
00160   \param a_order  The order in the translation unit.
00161   \return The location.
00162 */
00163 ptr<source_location> source_location::create(const ptr<file_info> &a_file,
00164                 ulint a_line, ulint a_column, ulint a_order)
00165 {
00166         return new source_location(a_file,a_line,a_column,a_order);
00167 }
00168 
00169 /*!
00170   Returns location at the beginning of the translation unit.
00171   \return The zero location.
00172 */
00173 ptr<source_location> source_location::zero(void)
00174 {
00175         if (!zero_instance) {
00176                 zero_instance = new source_location(file_info::create("<internal>",NULL),1,1,0);
00177         }
00178         return zero_instance;
00179 }
00180 
00181 /*!
00182   Returns reflection list for source location.
00183   \return The reflection list.
00184 */
00185 ptr< object::reflection_list > source_location::reflection_get(void) const
00186 {
00187         if (!reflection) {
00188                 typedef class_reflection::field_metadata md;
00189                 typedef class_reflection::field_metadata_list mdlist;
00190                 ptr<mdlist> mdl = mdlist::create();
00191                 mdl->push_back(md::create("file","lstring"));
00192                 mdl->push_back(md::create("line","ulint"));
00193                 mdl->push_back(md::create("column","ulint"));
00194                 mdl->push_back(md::create("order","ulint"));
00195                 reflection = reflection_list::create(object::reflection_get());
00196                 reflection->push_back(class_reflection::create("source_location",mdl));
00197         }
00198         return reflection;
00199 }
00200 
00201 /*!
00202   Returns values of the fields.
00203   \return List of field values.
00204 */
00205 ptr< object::field_list_list > source_location::field_values_get(void) const
00206 {
00207         ptr<field_list_list> result = object::field_values_get();
00208         result->push_back(value_list::create());
00209         result->back()->push_back(objectize<lstring>::create(file_get()->name_get()));
00210         result->push_back(value_list::create());
00211         result->back()->push_back(objectize<ulint>::create(line_get()));
00212         result->push_back(value_list::create());
00213         result->back()->push_back(objectize<ulint>::create(column_get()));
00214         result->push_back(value_list::create());
00215         result->back()->push_back(objectize<ulint>::create(order_get()));
00216         return result;
00217 }
00218 
00219 /*!
00220   The zero location instance at the beginning of the translation unit.
00221 */
00222 ptr<source_location> source_location::zero_instance = zero_instance;
00223 
00224 /*!
00225   Reflection list for source location.
00226 */
00227 ptr<object::reflection_list> source_location::reflection = reflection;
00228 
00229 end_package(std);
00230 end_package(lestes);
00231 /* vim: set ft=lestes : */

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