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 #include <lestes/common.hh> 00029 #include <lestes/std/source_location.hh> 00030 #include <lestes/std/map.hh> 00031 #include <lestes/lang/cplus/lex/preprocessor.hh> 00032 #include <lestes/lang/cplus/lex/cpp_token.hh> 00033 #include <lestes/lang/cplus/lex/token_value.hh> 00034 #include <lestes/lang/cplus/lex/file_system.hh> 00035 #include <lestes/lang/cplus/lex/lex_literal.g.hh> 00036 #include <lestes/lang/cplus/lex/lex_loggers.hh> 00037 #include <lestes/msg/report_end.hh> 00038 #include <lestes/msg/report_error_flag.hh> 00039 #include <lestes/msg/report_origin_filter.hh> 00040 #include <lestes/msg/report_ostream.hh> 00041 #include <lestes/msg/reporter.hh> 00042 00043 #include <iostream> 00044 #include <fstream> 00045 #include <utility> 00046 00047 package(lestes); 00048 package(lang); 00049 package(cplus); 00050 package(lex); 00051 00052 void run(void) 00053 { 00054 ::lestes::msg::reporter::instance()->filter_set( 00055 ::lestes::msg::report_origin_filter::create( 00056 ::lestes::msg::report_ostream::create( 00057 ::lestes::msg::report_end::create(), 00058 ostream_wrapper::create(&::std::cerr,false)))); 00059 00060 ptr<file_system> fs = file_system::create(); 00061 if (!fs->add_search_path("/usr/include")) { 00062 ::std::cout << "could not add path\n"; 00063 } 00064 ptr<preprocessor> pp = preprocessor::create(fs,""); 00065 00066 ptr<cpp_token> tok; 00067 ptr<source_location> loc; 00068 cpp_token::type_type type; 00069 ptr<token_value> tv; 00070 ptr<lex_literal> literal; 00071 00072 do { 00073 tok = pp->read(); 00074 loc = tok->location_get(); 00075 type = tok->type_get(); 00076 tv = tok->value_get(); 00077 literal = type == cpp_token::TOK_LITERAL ? tok->literal_get() : ptr<lex_literal>(NULL); 00078 00079 ::std::cout << loc->file_get()->name_get() << ':' << loc->line_get() << ':' << loc->column_get(); 00080 ::std::cout << ' ' << tok->description_get(); 00081 00082 if (tv) { 00083 ::std::cout << ' '; 00084 00085 ucn_string str(tv->content_get()); 00086 for (ucn_string::iterator it = str.begin(), end = str.end(); it != end; ++it) { 00087 ::std::cout << static_cast<ulint>(*it); 00088 } 00089 ::std::cout << ' ' << tv->content_get(); 00090 } 00091 00092 if (literal) { 00093 ::std::cout << ' ' << "LINFO"; 00094 } 00095 00096 ::std::cout << ::std::endl; 00097 00098 } while (tok->type_get() != cpp_token::TOK_EOF); 00099 00100 if (pp->pragma_flag_get()) ::std::cout << "saw pragma\n"; 00101 } 00102 00103 end_package(lex); 00104 end_package(cplus); 00105 end_package(lang); 00106 end_package(lestes); 00107 00108 00109 int main(int argc, const char **argv) 00110 { 00111 bool log_finish = false; 00112 if (argc == 1) { 00113 // okay 00114 } else if (argc != 3) { 00115 ::std::cerr << "Invalid arguments\n"; 00116 return 1; 00117 } else if (!strcmp(argv[1],"-s")) { 00118 ::std::ofstream of(argv[2]); 00119 ::lestes::msg::logger::dump_skeleton(of); 00120 } else if (!strcmp(argv[1],"-l")) { 00121 log_finish = ::lestes::msg::logger::init(argv[2]); 00122 if (!log_finish) ::std::cerr << "Unable to init logger\n"; 00123 } else { 00124 ::std::cerr << "Invalid arguments\n"; 00125 return 1; 00126 } 00127 00128 ::lestes::lang::cplus::lex::run(); 00129 00130 if (log_finish) { 00131 ::lestes::msg::logger::finish(); 00132 } 00133 00134 return 0; 00135 } 00136 00137 /* vim: set ft=lestes : */
1.5.1-20070107