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 Macro argument list. 00030 00031 Definition of macro_arguments class representing list of macro arguments. 00032 \author pt 00033 */ 00034 #include <lestes/common.hh> 00035 #include <lestes/lang/cplus/lex/macro_arguments.hh> 00036 #include <lestes/lang/cplus/lex/macro_argument.hh> 00037 #include <lestes/lang/cplus/lex/pp_token.hh> 00038 #include <lestes/lang/cplus/lex/token_sequence.hh> 00039 00040 package(lestes); 00041 package(lang); 00042 package(cplus); 00043 package(lex); 00044 00045 /*! 00046 Creates empty list. 00047 \post state == BEGIN 00048 \post length() == 0 00049 */ 00050 macro_arguments::macro_arguments(void): 00051 state(BEGIN), 00052 arguments(arguments_type::create()) 00053 { 00054 } 00055 00056 /*! 00057 Parses macro argument list in parentheses. 00058 \pre state == BEGIN 00059 \param input The source for arguments, starting with '(' token. 00060 \return false In case of parse error. 00061 */ 00062 bool macro_arguments::parse(const ptr<token_input> &input) 00063 { 00064 lassert(state == BEGIN); 00065 00066 ptr<pp_token> t; 00067 t = input->read_front(); 00068 00069 lassert(t->type_get() == pp_token::TOK_LEFT_PAR); 00070 00071 bool first = true; 00072 macro_argument::result_type result; 00073 00074 do { 00075 ptr<macro_argument> ma = macro_argument::create(); 00076 result = ma->parse(input,first); 00077 first = false; 00078 00079 arguments->push_back(ma); 00080 00081 if (result == macro_argument::EMPTY) { 00082 state = PARSED_EMPTY; 00083 return true; 00084 } 00085 00086 } while (result == macro_argument::CONTINUE); 00087 00088 if (result == macro_argument::LAST) { 00089 state = PARSED; 00090 return true; 00091 } 00092 00093 // else result == macro_argument::ERROR 00094 state = DEAD; 00095 return false; 00096 } 00097 00098 /*! 00099 Returns length of the argument list. 00100 \pre state == PARSED || state == PARSED_EMPTY 00101 \return Length of the argument list. 00102 */ 00103 ulint macro_arguments::length(void) const 00104 { 00105 lassert(state == PARSED || state == PARSED_EMPTY); 00106 return arguments->size(); 00107 } 00108 00109 /*! 00110 Checks whether the arguments match the length of a parameter list. 00111 Either the lengths are the same, or there is no parameters and the argument list is empty. 00112 \pre state == PARSED || state == PARSED_EMPTY 00113 \par pars_length The length of the checked parameter list. 00114 \return true If the length matches or state == PARSED_EMPTY and pars_length == 0. 00115 */ 00116 bool macro_arguments::check(ulint pars_length) const 00117 { 00118 lassert(state == PARSED || state == PARSED_EMPTY); 00119 return length() == pars_length || (pars_length == 0 && state == PARSED_EMPTY); 00120 } 00121 00122 /*! 00123 Returns argument at specified position. 00124 \pre state == PARSED || state == PARSED_EMPTY 00125 \pre index < length() 00126 \param index The index of the desired argument. 00127 \return The argument at specified index. 00128 */ 00129 ptr<macro_argument> macro_arguments::argument_get(ulint index) const 00130 { 00131 lassert(state == PARSED || state == PARSED_EMPTY); 00132 lassert(index < length()); 00133 return arguments->at(index); 00134 } 00135 00136 /*! 00137 Marks the object. 00138 */ 00139 void macro_arguments::gc_mark(void) 00140 { 00141 arguments.gc_mark(); 00142 ::lestes::std::object::gc_mark(); 00143 } 00144 00145 /*! 00146 Returns new empty argument list. 00147 \post state == BEGIN 00148 \post length() == 0 00149 */ 00150 ptr<macro_arguments> macro_arguments::create(void) 00151 { 00152 return new macro_arguments(); 00153 } 00154 00155 end_package(lex); 00156 end_package(cplus); 00157 end_package(lang); 00158 end_package(lestes); 00159 /* vim: set ft=lestes : */
1.5.1-20070107