sa_param_declaration.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 Parameter declaration analyser.
00030 
00031   Definition of classes performing parameter declaration structural analysis.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/sem/sa_param_declaration.g.hh>
00036 #include <lestes/std/source_location.hh>
00037 #include <lestes/lang/cplus/sem/as_id_to_ss_decl_name.g.hh>
00038 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00039 #include <lestes/lang/cplus/sem/sa_declarator_type.g.hh>
00040 #include <lestes/lang/cplus/sem/sa_declaration_specifiers.g.hh>
00041 #include <lestes/lang/cplus/sem/sa_declaration_specifier_list.g.hh>
00042 #include <lestes/lang/cplus/sem/ss_misc.g.hh>
00043 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00044 #include <lestes/lang/cplus/sem/ss_type.g.hh>
00045 #include <lestes/lang/cplus/sem/ss_decl_name.g.hh>
00046 #include <lestes/lang/cplus/sem/or_or.g.hh>
00047 #include <lestes/lang/cplus/sem/sa_loggers.hh>
00048 #include <lestes/msg/logger.hh>
00049 #include <lestes/msg/logger_util.hh>
00050 /*
00051 #include <lestes/lang/cplus/sem/ss_expression.g.hh>
00052 #include <lestes/lang/cplus/sem/sa_declarator.g.hh>
00053 #include <lestes/lang/cplus/sem/as_other.g.hh>
00054 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00055 */
00056 
00057 package(lestes);
00058 package(lang);
00059 package(cplus);
00060 package(sem);
00061 
00062 // TODO pt remove
00063 #if 0
00064 /*!
00065   Returns as_declarator_op visitor for parameter type analyser.
00066   \pre type != NULL
00067   \param type  The type to start building from.
00068   \return A visitor appropriate for the context.
00069 */
00070 ptr<as_declarator_op2ss_type> sa_param_type_context::create_as_declarator_op2ss_type(ptr<ss_type> type)
00071 {
00072         lassert(type);
00073 
00074         return as_declarator_op2ss_type_param::create(type);
00075 }
00076 
00077 /*!
00078   Returns as_declarator_op visitor for parameter declaration analyser.
00079   \pre type != NULL
00080   \param type  The type to start building from.
00081   \return A visitor appropriate for the context.
00082 */
00083 ptr<as_declarator_op2ss_type> sa_param_decl_context::create_as_declarator_op2ss_type(ptr<ss_type> type)
00084 {
00085         lassert(type);
00086 
00087         return as_declarator_op2ss_type_param::create(type);
00088 }
00089 #endif
00090 
00091 /*!
00092   Processes the parameter declaration within the given context.
00093   Creates the ss_parameter_declaration and inserts it in the given scope.
00094   TODO pt sads
00095   \pre decl != NULL
00096   \param decl  The parameter declaration to process.
00097 */
00098 void sa_param_declaration::process(/*ptr<sa_declaration_specifiers> sads,*/ ptr<as_param_declaration> decl)
00099 {
00100         sa_param_declaration_logger << "sa_param_declaration::process()\n" << msg::eolog;
00101 
00102         lassert(decl);
00103 
00104         // decl specs will be coming from somewhere else???
00105         // TODO
00106 #if 1
00107 
00108         // analyse the declaration specifiers
00109         ptr<sa_declaration_specifiers> sads =
00110                 sa_declaration_specifier_list::create()->process(decl->location_get(),decl->declaration_specifiers_get());
00111         
00112         sa_param_declaration_logger << "checking specifiers\n" << msg::eolog;
00113         // check disallowed declaration specifiers
00114         if (sads->virtual_flag_get() || sads->explicit_flag_get() || sads->friend_flag_get() ||
00115                  sads->inline_flag_get()) {
00116                 // TODO pt report error: invalid specifier
00117                 sa_param_declaration_logger << "invalid specifier flag\n" << msg::eolog;
00118         }
00119 #endif
00120                  
00121         // check correct storage specifier
00122         ss_storage_class::type storage_class = sads->storage_class_get();
00123         switch (storage_class) {
00124                 case ss_storage_class::ST_NONE:
00125                         break;
00126                 case ss_storage_class::ST_AUTO:
00127                 case ss_storage_class::ST_REGISTER:
00128                         sa_param_declaration_logger << "got storage class\n" << msg::eolog;
00129                         break;
00130                 case ss_storage_class::ST_STATIC:
00131                 case ss_storage_class::ST_EXTERN:
00132                 case ss_storage_class::ST_MUTABLE:
00133                 case ss_storage_class::ST_TYPEDEF:
00134                         // TODO pt report error: invalid storage specifiers
00135                         sa_param_declaration_logger << "got invalid storage class specifier\n" << msg::eolog;
00136                         break;
00137                 default:
00138                         lassert2(false,"You should never get here");
00139         }
00140 
00141         sa_param_declaration_logger << "analysing the declarator\n" << msg::eolog;
00142   
00143         ptr<as_declarator> declarator = decl->declarator_get();
00144         // get the type from the declarator
00145         ptr<sa_declarator_type> sadt = sa_declarator_type::create();
00146         ptr<ss_type> type = sadt->process(sads->type_get(),declarator);
00147 
00148 
00149         ptr<source_location> loc = declarator->location_get();
00150         ptr<ss_declaration_time> tm = ss_declaration_time::create(loc->order_get());
00151 
00152         ptr<as_name> name = declarator->name_get();
00153 
00154         ptr<ss_decl_name> decl_name;
00155 
00156         if (name)
00157                 decl_name = as_id_to_ss_decl_name::instance()->process(name->identifier_get());
00158         else 
00159                 decl_name = ss_dummy_name::create(loc);
00160         
00161         /*
00162                 TODO pt by tma
00163         we do not yet know the type of ss_object_declaration::initializer
00164         
00165         ptr<typeof(ss_object_declaration::initializer)> init = jikos->process(decl->initializer_get());
00166 
00167         if (typeof(ss_object_declaration::initializer) == ss_expression)
00168                 init0 = (*init)(psp,nsp);
00169         else
00170                 init0 = init;
00171 
00172         */
00173 
00174         // the scope for the parameters
00175         ptr<ss_decl_seq> param_scope = scope_get();
00176 
00177         sa_param_declaration_logger << "creating the parameter declaration\n" << msg::eolog;
00178 
00179         ptr<ss_declaration> declaration = ss_parameter_declaration::create(
00180                 loc, // location
00181                 tm, // visible since
00182                 tm, // declaration time 
00183                 decl_name, // decl name
00184                 param_scope, // contained in
00185                 type, // type 
00186                 // TODO ??
00187                 ss_linkage::create("C++",ss_linkage::LINKAGE_NO), // linkage 
00188                 ss_access_specifier::ACCESS_PUBLIC, // access specifier
00189                 storage_class, // storage
00190                 // TODO pt : tm/infinity() depends on initializer presence
00191                 ss_declaration_time::infinity(), // initialized since
00192                 // TODO pt fill initializer
00193                 NULL, // initializer
00194                 index++ // position
00195                 );
00196         
00197         sa_param_declaration_logger << "adding the parameter\n" << msg::eolog;
00198 
00199         param_scope->contents_get()->push_back(declaration);
00200 
00201         sa_param_declaration_logger << "sa_param_declaration::process() end\n" << msg::eolog;
00202 }
00203 
00204 // TODO pt remove
00205 #if 0
00206         // create the appropriate visitor 
00207         ptr<as_declarator_op2ss_type> v = context->create_as_declarator_op2ss_type(sads->type_get());
00208 
00209         ptr<as_declarator> declarator = decl->declarator_get();
00210 
00211         typedef ::lestes::std::list< srp<as_declarator_op> > as_declarator_op_list_type;
00212         ptr<as_declarator_op_list_type> lst = declarator->declarator_ops_get();
00213         
00214         {
00215                 as_declarator_op_list_type::reverse_iterator rit = lst->rbegin(), rend = lst->rend(),
00216                         tit = lst->rbegin();
00217 
00218                 ++tit;
00219                 
00220                 // walk through all declarator ops in reverse direction
00221                 for ( ; tit != rend; ++rit, ++tit) {
00222                         // classify individual declarator ops
00223                         v->process(*rit,false);
00224                 }
00225                 
00226                 // classify the first declarator op
00227                 v->process(*rit,true);
00228         }
00229 #endif
00230 
00231 
00232 #if 0
00233 /*!
00234   Processes the parameter declaration within the given context.
00235   Creates the ss_type.
00236   \pre decl != NULL
00237   \param decl  The parameter declaration to process.
00238 */
00239 void sa_param_type::process(ptr<as_param_declaration> decl)
00240 {
00241         
00242         lassert(decl);
00243 
00244         ptr<sa_decl_spec_context> sadsc = sa_decl_spec_context::create(declaration_context::CTX_PARAMETER);
00245         ptr<sa_decl_spec> sads = sa_decl_spec::create(sadsc);
00246 
00247         sads->process(decl->declaration_specifiers_get());
00248 
00249         // create the appropriate visitor 
00250         ptr<as_declarator_op2ss_type> v = context->create_as_declarator_op2ss_type(sads->type_get());
00251 
00252         ptr<as_declarator> declarator = decl->declarator_get();
00253 
00254         typedef ::lestes::std::list< srp<as_declarator_op> > as_declarator_op_list_type;
00255         ptr<as_declarator_op_list_type> lst = declarator->declarator_ops_get();
00256         
00257         {
00258                 as_declarator_op_list_type::reverse_iterator rit = lst->rbegin(), rend = lst->rend(),
00259                         tit = lst->rbegin();
00260                 ++tit;
00261                 
00262                 // walk through all declarator ops in reverse direction
00263                 for ( ; tit != rend; ++rit, ++tit) {
00264                         // classify individual declarator ops
00265                         v->process(*rit,false);
00266                 }
00267                 
00268                 // classify the first declarator op
00269                 v->process(*rit,true);
00270         }
00271 
00272         if (sads->virtual_flag_get() ||
00273                  sads->explicit_flag_get() ||
00274                  sads->inline_flag_get()) {
00275                 // TODO pt report error: invalid specifiers
00276         }
00277 
00278         ss_storage_class::type stc = sads->storage_class_get();
00279         
00280         switch (stc) {
00281                 case ss_storage_class::ST_NONE:
00282                 case ss_storage_class::ST_AUTO:
00283                 case ss_storage_class::ST_REGISTER:
00284                         // TODO pt ignore ???
00285                         break;
00286                 case ss_storage_class::ST_STATIC:
00287                 case ss_storage_class::ST_EXTERN:
00288                 case ss_storage_class::ST_MUTABLE:
00289                 case ss_storage_class::ST_TYPEDEF:
00290                         // TODO pt report error: invalid storage specifiers
00291                         break;
00292                 default:
00293                         lassert2(false,"You should never get here");
00294         }
00295 
00296         type = v->type_get();
00297 }
00298 #endif
00299 
00300 end_package(sem);
00301 end_package(cplus);
00302 end_package(lang);
00303 end_package(lestes);
00304 /* vim: set ft=lestes : */

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