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 Line number control. 00030 00031 Definition of class line_control responsible for creating full location information 00032 from physical location and effects of #line directives. 00033 \author pt 00034 */ 00035 #include <lestes/common.hh> 00036 #include <lestes/lang/cplus/lex/line_control.hh> 00037 #include <lestes/lang/cplus/lex/simple_location.hh> 00038 #include <lestes/std/file_info.hh> 00039 #include <lestes/std/source_location.hh> 00040 00041 package(lestes); 00042 package(lang); 00043 package(cplus); 00044 package(lex); 00045 00046 /*! 00047 Creates line control, initializes with file information. 00048 \pre a_file != NULL 00049 \param a_file The file information for the created locations. 00050 */ 00051 line_control::line_control(const ptr<file_info> &a_file): 00052 file(checked(a_file)), 00053 delta(0) 00054 { 00055 } 00056 00057 /*! 00058 Changes line numbering so that the line after \a location will be to \a line_number. 00059 The behaviour is as through the #line directive. 00060 \param before Location on line just before the change to take effect, due to multiline 00061 comments, it has to be the location of the newline at the end of the #line directive. 00062 \param line_number The new line number for the next line after the #line directive. 00063 */ 00064 void line_control::change_line(const ptr<source_location> &before, ulint line_number) 00065 { 00066 // the new delta is a correction of line_number by physical line number of the next line 00067 delta = line_number - (before->line_get() + 1 - delta); 00068 } 00069 00070 /*! 00071 Changes current file name, so that the location will contain the new file name. 00072 The inclusion chain is left intact, only the most nested entry is affected. 00073 \param file_name The new file name for the current file. 00074 */ 00075 void line_control::change_file(const lstring &file_name) 00076 { 00077 // TODO pt make this a clone on file_info ??? 00078 file = file_info::create(file_name,file->origin_get()); 00079 } 00080 00081 /*! 00082 Translates physical location to full source location considering changes of file names. 00083 \param physical The physical location to translate. 00084 \return The location with current file information and line number transformed appropriately. 00085 */ 00086 ptr<source_location> line_control::translate_location(const ptr<simple_location> &physical) const 00087 { 00088 return source_location::create(file,physical->line_get() + delta,physical->column_get()); 00089 } 00090 00091 /*! 00092 Marks the object. 00093 */ 00094 void line_control::gc_mark(void) 00095 { 00096 file.gc_mark(); 00097 object::gc_mark(); 00098 } 00099 00100 /*! 00101 Returns new instance, initializes with file information. 00102 \param a_file The file information for the created locations. 00103 */ 00104 ptr<line_control> line_control::create(const ptr<file_info> &a_file) 00105 { 00106 return new line_control(a_file); 00107 } 00108 00109 end_package(lex); 00110 end_package(cplus); 00111 end_package(lang); 00112 end_package(lestes); 00113 /* vim: set ft=lestes : */
1.5.1-20070107