sa_declaration_specifier_list.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 Declaration specifier sequence analyser.
00030 
00031   Definition of classes performing declaration specifier analysis.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/sem/sa_declaration_specifier_list.g.hh>
00036 #include <lestes/lang/cplus/sem/sa_declaration_specifier_list.m.hh>
00037 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00038 #include <lestes/lang/cplus/sem/sa_declaration_specifiers.g.hh>
00039 #include <lestes/lang/cplus/sem/as_declaration_specifier2properties.g.hh>
00040 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00041 #include <lestes/lang/cplus/sem/ss_type.g.hh>
00042 
00043 package(lestes);
00044 package(lang);
00045 package(cplus);
00046 package(sem);
00047 
00048 /*!
00049   Processes the declaration specifier sequence within the given context.
00050   Fills all properties of the sequence into the fields.
00051   \pre lst != NULL
00052   \param lst  The list of specifiers to process.
00053   
00054 */
00055 ptr<sa_declaration_specifiers> sa_declaration_specifier_list::process(ptr<source_location> loc, ptr<as_declaration_specifier_list_type> lst)
00056 {
00057         // create the appropriate visitor 
00058         ptr<as_declaration_specifier2properties> v = as_declaration_specifier2properties::create();
00059         
00060         // walk through all specifiers
00061         for (as_declaration_specifier_list_type::iterator it = lst->begin(), end = lst->end();
00062                         it != end; ++it) {
00063                 // classify individual specifiers
00064                 v->process(*it);
00065         }
00066 
00067         ptr<ss_type> type;
00068 
00069         // gather nonexclusive specifiers and form the ss_type
00070         switch (v->type_specifier_get()) {
00071                 case as_declaration_specifier2properties::TS_NONE:
00072                         // implicitly int
00073                         if (!v->short_flag_get() && !v->long_flag_get() &&
00074                                  !v->signed_flag_get() && !v->unsigned_flag_get()) {
00075                                 // TODO pt report error: type defaults to int
00076                                 report << declaration_without_type << loc;
00077                         }
00078                         // fall through
00079                 case as_declaration_specifier2properties::TS_INT:
00080                         if (v->unsigned_flag_get()) {
00081                                 if (v->short_flag_get()) {
00082                                         type = ss_type_ushort::instance();
00083                                 } else if (v->long_flag_get()) {
00084                                         type = ss_type_ulong::instance();
00085                                 } else {
00086                                         type = ss_type_uint::instance();
00087                                 }
00088                         } else {
00089                                 // int type is implicitly signed, also for bitfields
00090                                 if (v->short_flag_get()) {
00091                                         type = ss_type_sshort::instance();
00092                                 } else if (v->long_flag_get()) {
00093                                         type = ss_type_slong::instance();
00094                                 } else {
00095                                         type = ss_type_sint::instance();
00096                                 }
00097                         }
00098                         break;
00099                 case as_declaration_specifier2properties::TS_CHAR:
00100                         if (v->short_flag_get() || v->long_flag_get()) {
00101                                 // report error: sh/lo invalid for char
00102                                 report << invalid_char_specifier << loc;
00103                         }
00104                         if (v->signed_flag_get()) {
00105                                 type = ss_type_schar::instance();
00106                         } else if (v->unsigned_flag_get()) {
00107                                 type = ss_type_uchar::instance();
00108                         } else {
00109                                 type = ss_type_pchar::instance();
00110                         }
00111                         break;
00112                 case as_declaration_specifier2properties::TS_DOUBLE:
00113                         if (v->signed_flag_get() || v->unsigned_flag_get() || v->short_flag_get()) {
00114                                 // report error: s/u/sh invalid for double
00115                                 report << invalid_double_specifier << loc;
00116                         }
00117                         if (v->long_flag_get()) {
00118                                 type = ss_type_ldouble::instance();
00119                         } else {
00120                                 type = ss_type_double::instance();
00121                         }
00122                         break;
00123                 case as_declaration_specifier2properties::TS_OTHER:
00124                         if (v->signed_flag_get() || v->unsigned_flag_get() || v->short_flag_get() || v->long_flag_get()) {
00125                                 // pt report error: s/u/sh/lo invalid for the specifier
00126                         }
00127                         type = v->other_type_get();
00128                         break;
00129                 default:
00130                         lassert(false);
00131                         break;
00132         }
00133 
00134         // add cv-qualifier to the type
00135         if (v->const_flag_get()) type = ss_const::instance(type);
00136         if (v->volatile_flag_get()) type = ss_volatile::instance(type);
00137 
00138         // return the result
00139         return sa_declaration_specifiers::create(type,v->storage_class_get(), v->explicit_flag_get(),
00140                 v->inline_flag_get(), v->virtual_flag_get(), v->friend_flag_get());
00141 }
00142 
00143 end_package(sem);
00144 end_package(cplus);
00145 end_package(lang);
00146 end_package(lestes);
00147 /* vim: set ft=lestes : */

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