Canola
0.8.D001
|
00001 // 00002 // canola - canon canola 1614p emulator 00003 // Copyright (C) 2011 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License, version 3, as 00007 // published by the Free Software Foundation. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License along 00015 // with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include <lib/location.h> 00019 #include <lib/std_string_printf.h> 00020 00021 00022 location::~location() 00023 { 00024 } 00025 00026 00027 location::location( 00028 const std::string &a_filename, 00029 int a_line_number, 00030 size_t a_byte_start, 00031 size_t a_byte_length 00032 ) : 00033 filename(a_filename), 00034 line_number(a_line_number), 00035 byte_start(a_byte_start), 00036 byte_length(a_byte_length) 00037 { 00038 } 00039 00040 00041 location::pointer 00042 location::create(const std::string &a_filename, int a_line_number, 00043 size_t a_byte_start, size_t a_byte_length) 00044 { 00045 return 00046 pointer 00047 ( 00048 new location(a_filename, a_line_number, a_byte_start, a_byte_length) 00049 ); 00050 } 00051 00052 00053 location::pointer 00054 location::span(const location::pointer &from, const location::pointer &to) 00055 { 00056 if (!from) 00057 return to; 00058 if (!to) 00059 return from; 00060 return 00061 create 00062 ( 00063 from->filename, 00064 from->line_number, 00065 from->byte_start, 00066 to->byte_start + to->byte_length - from->byte_start 00067 ); 00068 } 00069 00070 00071 std::string 00072 location::representation(void) 00073 const 00074 { 00075 return 00076 std_string_printf 00077 ( 00078 "{ filename = \"%s\", line_number = %d, byte_start = %zd, " 00079 "byte_length = %zd }", 00080 filename.c_str(), 00081 line_number, 00082 byte_start, 00083 byte_length 00084 ); 00085 }