sa_param_declaration_empty.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 Empty parameter declaration test.
00030 
00031   Checking whether a parameter declaration is a special case equivalent to empty list.
00032 */
00033 #include <lestes/common.hh>
00034 #include <lestes/lang/cplus/sem/sa_param_declaration_empty.g.hh>
00035 #include <lestes/lang/cplus/sem/as_declaration_specifier2is_void.g.hh>
00036 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00037 #include <lestes/lang/cplus/sem/sa_loggers.hh>
00038 #include <lestes/msg/logger.hh>
00039 #include <lestes/msg/logger_util.hh>
00040 
00041 package(lestes);
00042 package(lang);
00043 package(cplus);
00044 package(sem);
00045 
00046 /*!
00047   Tests whether a parameter declaration contains only void declaration specifier
00048   and nothing else, no declarator specifiers and no name, so that it can be considered
00049   as a (void) parameter, designating empty paramter list.
00050   Does not report any error, only checks the conditions. Errors are reported in
00051   the parameter declaration itself.
00052 
00053   \pre decl != NULL
00054   \param decl  The parameter declaration to test.
00055   \return true  If the declaration designates empty parameter list.
00056 */
00057 bool sa_param_declaration_empty::process(ptr<as_param_declaration> decl)
00058 {
00059         typedef list< srp<as_declaration_specifier> > as_declaration_specifier_list;
00060 
00061         sa_param_declaration_empty_logger << "sa_param_declaration::process()\n" << msg::eolog;
00062 
00063         lassert(decl);
00064 
00065         bool correct = false;
00066         
00067         do {
00068                 sa_param_declaration_empty_logger << "checking declaration specifiers\n" << msg::eolog;
00069                 
00070                 // analyse the declaration specifiers
00071                 ptr<as_declaration_specifier_list> adsl = decl->declaration_specifiers_get();
00072                 // TODO pt BUGBUG must test the actual type, perhaps typedefed!!!!
00073 
00074                 // must be only specifier
00075                 if (adsl->size() != 1) break;
00076 
00077                 sa_param_declaration_empty_logger << "has single specifier\n" << msg::eolog;
00078                 
00079                 // must be void
00080                 if (!as_declaration_specifier2is_void::create()->process(adsl->front())) break;
00081                 
00082                 sa_param_declaration_empty_logger << "the specifier is void\n" << msg::eolog;
00083                 
00084                 sa_param_declaration_empty_logger << "checking the declarator\n" << msg::eolog;
00085 
00086                 // analyse declarator
00087                 ptr<as_declarator> asd = decl->declarator_get();
00088                 // must have no ops
00089                 if (asd->declarator_ops_get()->size() != 0) break;
00090                 
00091                 sa_param_declaration_empty_logger << "has no declarator ops\n" << msg::eolog;
00092                 
00093                 // must have no name
00094                 if (asd->name_get()) break;
00095 
00096                 sa_param_declaration_empty_logger << "has no name\n" << msg::eolog;
00097                 
00098                 // all checks passed
00099                 correct = true;
00100 
00101                 sa_param_declaration_empty_logger << "all checks passed\n" << msg::eolog;
00102         } while (false);
00103 
00104         sa_param_declaration_empty_logger << "sa_param_declaration::process() end\n" << msg::eolog;
00105 
00106         return correct;
00107 }
00108 
00109 end_package(sem);
00110 end_package(cplus);
00111 end_package(lang);
00112 end_package(lestes);
00113 

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