sa_deconstruct_spse.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  * Overload resolution for operators is needed to determine if builtin or 
00030  * non-builtin operator will be done. After selecting best function the resulting
00031  * best function call creating functional is applied to yield the resulting ss_expression
00032  *
00033  * This file contains implementation of handling all builtin operators.
00034  *
00035  * \author tma
00036  * \author jikos
00037  */
00038 
00039 #include <lestes/lang/cplus/sem/or_or.g.hh>
00040 #include <lestes/lang/cplus/sem/visitor.v.g.hh>
00041 #include <lestes/lang/cplus/sem/ss_decl_name.g.hh>
00042 #include <lestes/lang/cplus/sem/sa_deconstruct_spse.g.hh>
00043 #include <lestes/lang/cplus/sem/or_ics.g.hh>
00044 #include <lestes/lang/cplus/sem/or_ics_actual_visitors.g.hh>
00045 #include <lestes/lang/cplus/sem/or_ics.hh>
00046 #include <lestes/std/source_location.hh>
00047 #include <lestes/lang/cplus/sem/ss_expr_binary_op.g.hh>
00048 #include <lestes/lang/cplus/sem/sa_deconstruct_spse.m.hh>
00049 #include <lestes/lang/cplus/sem/as_expr.g.hh>
00050 #include <lestes/std/source_location.hh>
00051 #include <lestes/lang/cplus/sem/as_id_to_declaration_set.g.hh>
00052 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00053 #include <lestes/lang/cplus/sem/sa_statements.g.hh>
00054 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00055 #include <lestes/lang/cplus/sem/or_actual_visitors.g.hh>
00056 #include <lestes/lang/cplus/sem/ss_literal_info.g.hh>
00057 #include <lestes/lang/cplus/lex/cpp_token.hh>
00058 #include <lestes/lang/cplus/sem/lex_literal_to_ss_literal_info.g.hh>
00059 #include <lestes/lang/cplus/sem/sa_declarator_type.g.hh>
00060 #include <lestes/lang/cplus/sem/sa_declaration_specifier_list.g.hh>
00061 #include <lestes/lang/cplus/sem/sa_declaration_specifiers.g.hh>
00062 #include <lestes/md/types/ss_type_size_evaluator.g.hh>
00063 #include <lestes/md/types/type_info.g.hh>
00064 #include <algorithm>
00065 #include <iterator>
00066 
00067 package(lestes);
00068 package(lang);
00069 package(cplus);
00070 package(sem);
00071 
00072 using namespace ::lestes::md::types;
00073 
00074 typedef ::lestes::std::list< srp< or_or_functional > > exprlist;
00075 typedef ::lestes::std::set< srp< ss_function_declaration > > func_decl_set;
00076 
00077 ptr< or_or_functional > overload_resolution (ptr< exprlist > exprs, ptr< ss_operator > func_name);
00078 ptr< or_or_functional > overload_resolution (ptr< exprlist > exprs, ptr< func_decl_set > candidates);
00079 
00080 /*!
00081  * This template convers AS expressions/operators, having the for of binary op
00082  *
00083  * It doesn't matter here if creation of new sequence point is needed ('&&', '||', ',') or not.
00084  * This is done later, when creating the actual ss_expression, in operator() of the creator.
00085  * This also covers some op + equal operators. (which has sideeffect, this is also handled later, 
00086  * in the creator)
00087  *
00088  * \param AS visited as expression (concrete type)
00089  * \param OP determines the operator type for as function id
00090  */
00091 template <typename AS, typename OP> void sa_deconstruct_spse::construct_bin_op(ptr< AS > as)
00092 {
00093         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00094         ptr< sa_deconstruct_spse > vr = sa_deconstruct_spse::create();
00095         ptr< or_or_functional > l, r;
00096         ptr< ss_operator > op_name; 
00097         ptr< ::lestes::std::source_location > loc = as->location_get();
00098         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00099 
00100         /* recursively on arguments */
00101         as->left_get()->accept_as_expr_visitor(vl);
00102         l = vl->result_get();
00103         
00104         as->right_get()->accept_as_expr_visitor(vr);
00105         r = vr->result_get();
00106 
00107         expr_list->push_back(l);
00108         expr_list->push_back(r);
00109 
00110         /* perform overload resolution on the name of the op and return the obtained creator */ 
00111         op_name = OP::create(loc);
00112 
00113         /* this returns the creator of the expression */
00114         result_set(overload_resolution(expr_list, op_name));
00115         if(!(result_get())) {
00116                 report << no_viable_found << loc;
00117                 exit(1);
00118         }
00119 }
00120 
00121 /*!
00122  * This template covers operators which have form of unuary operator.
00123  * 
00124  * This includes handling not only prefix and postfix {in|de}rement, but also
00125  * handling unary plus and minus (which are handled in the same way as _prefix_
00126  * operators). 
00127  * 
00128  * Prefix and postfix themselves differ only in the number of parameters (see [13.5.7]
00129  * for more detailed explanation). In short: in the postfix case, we have to create the
00130  * second parameter as literal manually (postfix operators have only the left operand), 
00131  * in opposition to prefix situation, which is having just one parameter (the left one).
00132  *
00133  * AS - visited as expression (concrete type)
00134  * OP - determines the operator type for as function id
00135  */
00136 template <typename AS, typename OP> void sa_deconstruct_spse::construct_unary_op_nocreate(ptr< AS > as)
00137 {
00138         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00139         ptr< or_or_functional > l, e;
00140         ptr< ::lestes::std::source_location > loc = as->location_get();
00141         ptr< ss_operator > op_name; 
00142         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00143         
00144         as->expr_get()->accept_as_expr_visitor(vl);
00145         /* result of the visitor stored in the result field */
00146         l = vl->result_get();
00147 
00148         expr_list->push_back(l);
00149 
00150         /* perform overload resolution on the name of the op */
00151         op_name = OP::create(loc);
00152 
00153         /* this returns the creator of the expression */
00154         result_set(overload_resolution(expr_list, op_name));
00155         if(!(result_get())) {
00156                 report << no_viable_found << loc;
00157                 exit(1);
00158         }
00159 }
00160 template <typename AS, typename OP> void sa_deconstruct_spse::construct_unary_op_create(ptr< AS > as)
00161 {
00162         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00163         ptr< or_or_functional > l, r;
00164         ptr< ::lestes::std::source_location > loc = as->location_get();
00165         ptr< ss_operator > op_name; 
00166         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00167         
00168         as->expr_get()->accept_as_expr_visitor(vl);
00169 
00170         l = vl->result_get();
00171         /* create the literal representing int 1 */
00172         r = or_or_functional_literal::create(ss_type_sint::instance(), ss_integral_literal_info::create_from_number(ss_type_sint::instance(), 1));
00173 
00174         expr_list->push_back(l);
00175         expr_list->push_back(r);
00176 
00177         /* perform overload resolution on the name of the op */
00178         op_name = OP::create(loc);
00179 
00180         /* this returns the creator of the expression */
00181         result_set(overload_resolution(expr_list, op_name));
00182         if(!(result_get())) {
00183                 report << no_viable_found << loc;
00184                 exit(1);
00185         }
00186 }
00187 
00188 /*!
00189  * This function handles the case of '=' as expression. There is need to create new 
00190  * sideeffect, which will be handled later in the operator() of the creator. So, for 
00191  * the deconstruct itself, the equal is basically the same as any other binary op. This
00192  * is left here just not to forget for the new SE.
00193  */
00194 void sa_deconstruct_spse::visit_as_expression_equal( ptr< as_expression_equal > as)
00195 {
00196         ptr< sa_deconstruct_spse > v = sa_deconstruct_spse::create();;
00197         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00198         ptr< ::lestes::std::source_location > loc = as->location_get();
00199         ptr< or_or_functional > l, r;
00200         ptr< ss_operator > op_name;     
00201 
00202         as->left_get()->accept_as_expr_visitor(v);
00203         /* result of the visitor stored in the result field */
00204         l = v->result_get();
00205         as->right_get()->accept_as_expr_visitor(v);
00206         r = v->result_get();
00207 
00208         expr_list->push_back(l);
00209         expr_list->push_back(r);
00210 
00211         /* perform overload resolution on the name of the op */
00212         op_name = ss_operator_assign::create(loc);
00213         
00214         /* the result of the op will be l, which will be set later, in the creator */
00215         result_set(overload_resolution(expr_list, op_name));
00216         if(!(result_get())) {
00217                 report << no_viable_found << loc;
00218                 exit(1);
00219         }
00220 }
00221 
00222 void sa_deconstruct_spse::visit_as_expression_comma( ptr< as_expression_comma > as)
00223 {
00224         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00225         ptr< sa_deconstruct_spse > vr = sa_deconstruct_spse::create();
00226         ptr< or_or_functional > l, r;
00227         ptr< ss_operator > op_name; 
00228         ptr< ::lestes::std::source_location > loc = as->location_get();
00229         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00230 
00231         /* recursively on arguments */
00232         as->left_get()->accept_as_expr_visitor(vl);
00233         l = vl->result_get();
00234         
00235         as->right_get()->accept_as_expr_visitor(vr);
00236         r = vr->result_get();
00237 
00238         expr_list->push_back(l);
00239         expr_list->push_back(r);
00240 
00241         /* perform overload resolution on the name of the op and return the obtained creator */ 
00242         op_name = ss_operator_comma::create(loc);
00243 
00244         /* this returns the creator of the expression */
00245         result_set(overload_resolution(expr_list, op_name));
00246         if(!(result_get())) {
00247                 /* there was no either builtin ([13.3.1.2/3]) or user-defined operator, */
00248                 result_set(or_or_functional_comma::create(r->type_get(), expr_list));
00249         }
00250 }
00251 
00252 void sa_deconstruct_spse::visit_as_empty_expression( ptr< as_empty_expression > )
00253 {
00254         /* there is no such thing */
00255         lassert2(false, "BUG: hit empty expression in expression transformation");
00256 }
00257 void sa_deconstruct_spse::visit_as_expression_plus_equal( ptr< as_expression_plus_equal > as )
00258 {
00259         construct_bin_op<as_expression_plus_equal, ss_operator_assign_add>(as);
00260 }
00261 void sa_deconstruct_spse::visit_as_expression_minus_equal( ptr< as_expression_minus_equal > as )
00262 {
00263         construct_bin_op<as_expression_minus_equal, ss_operator_assign_sub>(as);
00264 }
00265 void sa_deconstruct_spse::visit_as_expression_star_equal( ptr< as_expression_star_equal > as )
00266 {
00267         construct_bin_op<as_expression_star_equal, ss_operator_assign_mul>(as);
00268 }
00269 void sa_deconstruct_spse::visit_as_expression_slash_equal( ptr< as_expression_slash_equal > as )
00270 {
00271         construct_bin_op<as_expression_slash_equal, ss_operator_assign_div>(as);
00272 }
00273 void sa_deconstruct_spse::visit_as_expression_percent_equal( ptr< as_expression_percent_equal > as )
00274 {
00275         construct_bin_op<as_expression_percent_equal, ss_operator_assign_mod>(as);
00276 }
00277 void sa_deconstruct_spse::visit_as_expression_hat_equal( ptr< as_expression_hat_equal > as )
00278 {
00279         construct_bin_op<as_expression_hat_equal, ss_operator_assign_bxor>(as);
00280 }
00281 void sa_deconstruct_spse::visit_as_expression_amp_equal( ptr< as_expression_amp_equal > as )
00282 {
00283         construct_bin_op<as_expression_amp_equal, ss_operator_assign_band>(as);
00284 }
00285 void sa_deconstruct_spse::visit_as_expression_vbar_equal( ptr< as_expression_vbar_equal > as )
00286 {
00287         construct_bin_op<as_expression_vbar_equal, ss_operator_assign_bor>(as);
00288 }
00289 void sa_deconstruct_spse::visit_as_expression_less_less_equal( ptr< as_expression_less_less_equal > as )
00290 {
00291         construct_bin_op<as_expression_less_less_equal, ss_operator_assign_shl>(as);
00292 }
00293 void sa_deconstruct_spse::visit_as_expression_greater_greater_equal( ptr< as_expression_greater_greater_equal > as )
00294 {
00295         construct_bin_op<as_expression_greater_greater_equal, ss_operator_assign_shr>(as);
00296 }
00297 void sa_deconstruct_spse::visit_as_expression_equal_equal( ptr< as_expression_equal_equal > as )
00298 {
00299         construct_bin_op<as_expression_equal_equal, ss_operator_sbe>(as);
00300 }
00301 void sa_deconstruct_spse::visit_as_expression_exclam_equal( ptr< as_expression_exclam_equal > as )
00302 {
00303         construct_bin_op<as_expression_exclam_equal, ss_operator_sbne>(as);
00304 }
00305 void sa_deconstruct_spse::visit_as_expression_less_equal( ptr< as_expression_less_equal > as )
00306 {
00307         construct_bin_op<as_expression_less_equal, ss_operator_sbng>(as);
00308 }
00309 void sa_deconstruct_spse::visit_as_expression_greater_equal( ptr< as_expression_greater_equal > as )
00310 {
00311         construct_bin_op<as_expression_greater_equal, ss_operator_sbnl>(as);
00312 }
00313 void sa_deconstruct_spse::visit_as_expression_less( ptr< as_expression_less > as )
00314 {
00315         construct_bin_op<as_expression_less, ss_operator_sbl>(as);
00316 }
00317 void sa_deconstruct_spse::visit_as_expression_greater( ptr< as_expression_greater > as )
00318 {
00319         construct_bin_op<as_expression_greater, ss_operator_sbg>(as);
00320 }
00321 void sa_deconstruct_spse::visit_as_expression_vbar( ptr< as_expression_vbar > as )
00322 {
00323         construct_bin_op<as_expression_vbar, ss_operator_bor>(as);
00324 }
00325 void sa_deconstruct_spse::visit_as_expression_amp( ptr< as_expression_amp > as )
00326 {
00327         construct_bin_op<as_expression_amp, ss_operator_band>(as);
00328 }
00329 void sa_deconstruct_spse::visit_as_expression_hat( ptr< as_expression_hat > as )
00330 {
00331         construct_bin_op<as_expression_hat, ss_operator_bxor>(as);
00332 }
00333 void sa_deconstruct_spse::visit_as_expression_less_less( ptr< as_expression_less_less > as )
00334 {
00335         construct_bin_op<as_expression_less_less, ss_operator_shl>(as);
00336 }
00337 void sa_deconstruct_spse::visit_as_expression_greater_greater( ptr< as_expression_greater_greater > as )
00338 {
00339         construct_bin_op<as_expression_greater_greater, ss_operator_shr>(as);
00340 }
00341 void sa_deconstruct_spse::visit_as_expression_plus( ptr< as_expression_plus > as )
00342 {
00343         construct_bin_op<as_expression_plus, ss_operator_add>(as);
00344 }
00345 void sa_deconstruct_spse::visit_as_expression_minus( ptr< as_expression_minus > as )
00346 {
00347         construct_bin_op<as_expression_minus, ss_operator_sub>(as);
00348 }
00349 void sa_deconstruct_spse::visit_as_expression_star( ptr< as_expression_star > as )
00350 {
00351         construct_bin_op<as_expression_star, ss_operator_mul>(as);
00352 }
00353 void sa_deconstruct_spse::visit_as_expression_slash( ptr< as_expression_slash > as )
00354 {
00355         construct_bin_op<as_expression_slash, ss_operator_div>(as);
00356 }
00357 void sa_deconstruct_spse::visit_as_expression_percent( ptr< as_expression_percent > as )
00358 {
00359         construct_bin_op<as_expression_percent, ss_operator_mod>(as);
00360 }
00361 void sa_deconstruct_spse::visit_as_expression_vbar_vbar( ptr< as_expression_vbar_vbar > as )
00362 {
00363         construct_bin_op<as_expression_vbar_vbar, ss_operator_lor>(as);
00364 }
00365 void sa_deconstruct_spse::visit_as_expression_amp_amp( ptr< as_expression_amp_amp > as )
00366 {
00367         construct_bin_op<as_expression_amp_amp, ss_operator_land>(as);
00368 }
00369 void sa_deconstruct_spse::visit_as_expression_dot_star( ptr< as_expression_dot_star >)
00370 {
00371         lassert2(false, ".* expression not supported yet\n");
00372 }
00373 void sa_deconstruct_spse::visit_as_expression_minus_greater_star( ptr< as_expression_minus_greater_star > as )
00374 {
00375         construct_bin_op<as_expression_minus_greater_star, ss_operator_access_member>(as);
00376 }
00377 void sa_deconstruct_spse::visit_as_expression_brackets( ptr< as_expression_brackets > )
00378 {
00379         lassert2(false, "as_expression_brackets\n");
00380         //construct_bin_op<as_expression_brackets, ss_operator_function_call>(as);
00381 }
00382 void sa_deconstruct_spse::visit_as_expression_plus_plus_pre( ptr< as_expression_plus_plus_pre > as )
00383 {
00384         construct_unary_op_nocreate<as_expression_plus_plus_pre, ss_operator_inc>(as);
00385 }
00386 void sa_deconstruct_spse::visit_as_expression_plus_plus_post( ptr< as_expression_plus_plus_post > as )
00387 {
00388         construct_unary_op_create<as_expression_plus_plus_post, ss_operator_inc>(as);
00389 }
00390 void sa_deconstruct_spse::visit_as_expression_minus_minus_pre( ptr< as_expression_minus_minus_pre > as )
00391 {
00392         construct_unary_op_nocreate<as_expression_minus_minus_pre, ss_operator_dec>(as);
00393 }
00394 void sa_deconstruct_spse::visit_as_expression_minus_minus_post( ptr< as_expression_minus_minus_post > as )
00395 {
00396         construct_unary_op_create<as_expression_minus_minus_post, ss_operator_dec>(as);
00397 }
00398 /* The following unary operators can be handled in the very same way as prefix in/decrement,
00399  * because they have one parameter and sideffect doesn't matter here
00400  */ 
00401 void sa_deconstruct_spse::visit_as_expression_unary_amp( ptr< as_expression_unary_amp > as )
00402 {
00403         /* this is not binary and, but the ss_operator is the same (it is not distinguishable
00404          * here, whether we hold binary (bit) and, or address_of operator - it can be 
00405          * distinguished later according to number of arguments
00406          */
00407         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00408         ptr< or_or_functional > l;
00409         ptr< ss_operator > op_name; 
00410         ptr< ::lestes::std::source_location > loc = as->location_get();
00411         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00412 
00413         /* recursively on arguments */
00414         as->expr_get()->accept_as_expr_visitor(vl);
00415         l = vl->result_get();
00416         
00417         expr_list->push_back(l);
00418 
00419         /* perform overload resolution on the name of the op and return the obtained creator */ 
00420         op_name = ss_operator_band::create(loc);
00421 
00422         /* this returns the creator of the expression */
00423         result_set(overload_resolution(expr_list, op_name));
00424         if(!(result_get())) {
00425                 /* there was no either builtin ([13.3.1.2/3]) or user-defined operator, */
00426                 /* The the type of l must be de-referenced and de-pseudoreferenced and then pointerized, so that for example
00427                  *
00428                  *      int *;
00429                  *      int x;
00430                  *      i = &x;
00431                  *
00432                  * will work (the candidate function in this case for assignment is taking two
00433                  * int* arguments
00434                  */
00435                 ptr< or_ics_visitor_cv > v = or_ics_visitor_cv::create();
00436                 /* pseudoreference for reference is possible
00437                  * pseudoreference for pseudoreference is strange thing, not handled FIXME
00438                  * reference for (pseudo)reference is not supported
00439                  */
00440                 if(l->type_get()->accept_or_ics_base_cv(v) == OR_CV_PSEUDOREFERENCE) {
00441                         if(l->type_get().dncast<ss_pseudoreference>()->what_get()->accept_or_ics_base_cv(v) == OR_CV_REFERENCE)
00442                                 result_set(or_or_functional_addrof::create(ss_pointer::instance(l->type_get().dncast<ss_pseudoreference>()->what_get().dncast<ss_reference>()->what_get()), expr_list));
00443                         else
00444                                 result_set(or_or_functional_addrof::create(ss_pointer::instance(l->type_get().dncast<ss_pseudoreference>()->what_get()), expr_list));
00445                 } else if(l->type_get()->accept_or_ics_base_cv(v) == OR_CV_REFERENCE) {
00446                         result_set(or_or_functional_addrof::create(ss_pointer::instance(l->type_get().dncast<ss_reference>()->what_get()), expr_list));
00447                 } else {
00448                         report << non_lvalue_in_unary_amp << loc;
00449                         exit(1);
00450                 }
00451         }
00452 
00453 }
00454 void sa_deconstruct_spse::visit_as_expression_unary_plus( ptr< as_expression_unary_plus > as )
00455 {
00456         construct_unary_op_nocreate<as_expression_unary_plus, ss_operator_add>(as);
00457 }
00458 void sa_deconstruct_spse::visit_as_expression_unary_minus( ptr< as_expression_unary_minus > as )
00459 {
00460         construct_unary_op_nocreate<as_expression_unary_minus, ss_operator_sub>(as);
00461 }
00462 void sa_deconstruct_spse::visit_as_expression_unary_star( ptr< as_expression_unary_star > as )
00463 {
00464         construct_unary_op_nocreate<as_expression_unary_star, ss_operator_mul>(as);
00465 }
00466 void sa_deconstruct_spse::visit_as_expression_tilde( ptr< as_expression_tilde > as )
00467 {
00468         construct_unary_op_nocreate<as_expression_tilde, ss_operator_bnot>(as);
00469 }
00470 void sa_deconstruct_spse::visit_as_expression_exclam( ptr< as_expression_exclam > as )
00471 {
00472         construct_unary_op_nocreate<as_expression_exclam, ss_operator_lnot>(as);
00473 }
00474 /* It is enough for now to handle it whis way */
00475 void sa_deconstruct_spse::visit_as_constant_expression( ptr< as_constant_expression > as)
00476 {
00477         /* this is enough for now, but should be later FIXME */
00478         ptr< sa_deconstruct_spse > v = sa_deconstruct_spse::create();
00479         as->expr_get()->accept_as_expr_visitor(v);
00480         result_set(v->result_get());
00481         
00482 }
00483 /*!
00484  * This function handles the case of function call expression
00485  */
00486 void sa_deconstruct_spse::visit_as_expression_function_call( ptr< as_expression_function_call > as )
00487 {
00488         ptr< or_or_functional > l, pref_res;
00489         ptr< as_expression > pref = as->prefix_get();
00490         ptr< ::lestes::std::source_location > loc = as->location_get();
00491         ptr< ::lestes::std::list< srp< or_or_functional > > > expr_list = ::lestes::std::list< srp< or_or_functional > >::create();
00492         ::lestes::std::list< srp< as_expression > >::iterator it = as->arguments_get()->begin();
00493 
00494         /* recursion on the arguments */        
00495         for(; it != as->arguments_get()->end(); *it++) {
00496                 ptr< sa_deconstruct_spse > v = sa_deconstruct_spse::create();
00497 
00498                 (*it)->accept_as_expr_visitor(v);
00499                 l = v->result_get();
00500                 expr_list->push_back(l);
00501         }
00502         
00503         /* on the prefix */
00504         ptr< sa_deconstruct_spse > v = sa_deconstruct_spse::create();
00505         pref->accept_as_expr_visitor(v);
00506         pref_res = v->result_get();
00507 
00508         /* let's see what is the type of the returned or_or_functional */
00509         ptr< or_or_functional_to_enum > v_f = or_or_functional_to_enum::create();
00510         pref_res->accept_or_or_functional_visitor(v_f);
00511         or_or_functional_enum e = v_f->result_get();
00512         
00513         /* the first two cases mean that prefix is as_name */
00514         if (e == OR_OR_FUNCTIONAL_FUNC_DECL_SET) {
00515                 /* "unpack" the declarations and let the overload resolution (by it's second interface)
00516                  * choose the right function
00517                  */
00518                 ptr< ::lestes::std::set< srp< ss_function_declaration > > > fl = ::lestes::std::set< srp< ss_function_declaration > >::create();
00519                 ptr< ::lestes::std::set< srp< ss_declaration > > > dl = pref_res.dncast<or_or_functional_func_decl_set>()->declarations_get();
00520                 ::lestes::std::set< srp< ss_declaration > >::iterator it = dl->begin();
00521                 
00522                 for (; it != dl->end(); it++)
00523                         fl->insert((*it).dncast<ss_function_declaration>());
00524                 result_set(overload_resolution(expr_list, fl));
00525         } else if (e == OR_OR_FUNCTIONAL_DECL) {
00526                 /* in case of object declaration - lookup the operator() in it
00527                  * in case of function declaration - create or_or_functional representing functionl call expr
00528                  * in case of typename we are in functional-style-cast situation. This is TODO for someone in future
00529                  * ...
00530                  */
00531                 ptr< ss_decl_to_enum > v_d = ss_decl_to_enum::create();
00532                 ss_decl_enum e_d;
00533                 
00534                 pref_res.dncast<or_or_functional_decl>()->declaration_get()->accept_ss_declaration_visitor(v_d);
00535                 e_d = v_d->result_get();
00536 
00537                 if (e_d == FUNCTION_DECLARATION) {
00538                         /* this is basically the same situation as in OR_OR_FUNCTIONAL_FUNC_DECL_SET case */
00539                         result_set(or_or_functional_concrete::create(pref_res.dncast<or_or_functional_decl>()->declaration_get()->type_get().dncast<ss_function>()->returns_get(),
00540                                                 expr_list, pref_res.dncast<or_or_functional_decl>()->declaration_get()));
00541                 } else if (e_d == OBJECT_DECLARATION || e_d == STRUCTURE_DECLARATION) {
00542                         /* lookup operator(), chose the proper one by overload and create funcall */
00543                 } else if (e_d == NAMESPACE_DEFINITION || e_d == USING_DECLARATION) {
00544                         /* this definitely shouldn't happen, as the test is already in or_or_functional_decl::operator() */
00545                         lassert2(false, "Impossible thing occured, the test should be already done");
00546                 } else if (e_d == METHOD_DECLARATION) {
00547                         /* create mfuncall */
00548                         lassert2(false, "Method declaration in operator (). To be implemented");
00549                 } else if (e_d == BUILTIN_OPERATOR_DECLARATION) {
00550                         /* can this happen? */
00551                         lassert2(false, "This shouldn't happen, we can't distinguish between builtin and non-builtin here");
00552                 } else {
00553                         lassert2(false, "Unimplemented or impossible function call prefix hit");
00554                 }
00555                 
00556         }
00557         /* this means that prefix is expression */
00558         else if (e == OR_OR_FUNCTIONAL_CONCRETE) {
00559                 /* the prefix is expression. quite a lot of cases to handle ... */
00560         }
00561         /* prefix is ambiguous */
00562         else if (e == OR_OR_FUNCTIONAL_AMBIGUOUS) {
00563                 /* FIXME do not lassert, report using lmd */
00564                 report << ambiguous_function_prefix << as->location_get();
00565                 exit(1);;
00566         }
00567 }
00568 void sa_deconstruct_spse::visit_as_name_expression( ptr< as_name_expression > as)
00569 {
00570         /* use tma's visitor on as_id (as_name->identifier_get()). This returns (set of)
00571          * declaration(s). If the declaration is typename, it is an error (-> lassert/lmd).
00572          * If the declaration is declration of object/variable, create pseudoreference for this.
00573          * If the set contains declarations of functions, just create functional which will hold the
00574          * set of functions for later use.
00575          */
00576         ptr< as_id_to_declaration_set > v = as_id_to_declaration_set::instance();
00577         ptr< ::lestes::std::set< srp< ss_declaration > > > decls;
00578         decls = v->process(as->name_get()->identifier_get());
00579         ::lestes::std::set< srp< ss_declaration > >::iterator it = decls->begin();
00580 
00581         if (!decls || decls->size() == 0) {
00582                 report << unrecognized_identifier << as->location_get();
00583                 exit(1);
00584         }
00585         
00586         /* now check if we received typename, declaration of variable or declaration of function */
00587         if (decls->size() > 1) {
00588                 /* this is the case that we can be (I hope :) ) sure that what we got is list of functions.
00589                  * successor of or_or_functional, containing the list of function declaration has to be created
00590                  */
00591                 ptr< or_or_functional_func_decl_set > funcial = or_or_functional_func_decl_set::create((*it)->type_get(), decls);
00592                 result_set(funcial);
00593         } else {
00594                 /* here we have just to create the appropriate functional which will later be used to create
00595                  * ss_expression according to obtained declaration
00596                  */
00597                 result_set(or_or_functional_decl::create(ss_pseudoreference::instance((*it)->type_get()), (*it)));
00598         }
00599 }
00600 /*! 
00601  * This handles the case of literal constant. Only integral constant is now
00602  * supported, adding other should be straightforward, as the type can be
00603  * obtained from ss_literal_info::type_get()
00604  * \bug doesn't support other than integral literals so far
00605  */
00606   
00607 void sa_deconstruct_spse::visit_as_literal( ptr< as_literal > as)
00608 {
00609         ptr< ss_literal_info > info = lex_literal_to_ss_literal_info::process_token(as->value_get());
00610         result_set(or_or_functional_literal::create(info->type_get(), info));
00611 }
00612 
00613 void sa_deconstruct_spse::visit_as_this_expression( ptr< as_this_expression >)
00614 {
00615         result_set(or_or_functional_this::create(
00616                                 sa_statements::instance()->current_function_get()->type_get().dncast<ss_member_function>()->this_type_get()));
00617 }
00618 
00619 void sa_deconstruct_spse::visit_as_expression_pseudo_destruct_dot( ptr< as_expression_pseudo_destruct_dot > as)
00620 {
00621         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00622         ptr< or_or_functional > l;
00623 
00624         /* recursively on argument */
00625         as->prefix_get()->accept_as_expr_visitor(vl);
00626         l = vl->result_get();
00627 
00628         /* nothing else (maybe some check) can be done here */
00629         result_set(l);
00630 }
00631 void sa_deconstruct_spse::visit_as_expression_pseudo_destruct_arrow( ptr< as_expression_pseudo_destruct_arrow > as)
00632 {
00633         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00634         ptr< or_or_functional > l;
00635 
00636         /* recursively on argument */
00637         as->prefix_get()->accept_as_expr_visitor(vl);
00638         l = vl->result_get();
00639 
00640         /* nothing else (maybe some check) can be done here */
00641         result_set(l);
00642 }
00643 
00644 /*!
00645  * This is helper function for the sizeof type for converting list of type specifiers
00646  * to declaration specifiers
00647  */
00648 ptr< ::lestes::std::list< srp<as_declaration_specifier> > > ts2ds(ptr< ::lestes::std::list< srp<as_type_specifier> > > tsl)
00649 {
00650         ptr< list< srp<as_declaration_specifier> > > dsl = ::lestes::std::list< srp<as_declaration_specifier> >::create();
00651         ::std::copy(tsl->begin(),tsl->end(),::std::back_inserter(*dsl));
00652         return dsl;
00653 }
00654         
00655 /*! 
00656  * This function handles sizeof(type)
00657  */
00658 void sa_deconstruct_spse::visit_as_expression_sizeof_type( ptr< as_expression_sizeof_type > a)
00659 {
00660         /* first, get the real size from ss_type_size_evaluator and the create
00661          * and return the corresponding literal. 
00662          */
00663         
00664         ptr< as_type_id > as = a->type_id_get();
00665         ptr< ss_type > t = sa_declarator_type::create()->process(sa_declaration_specifier_list::create()->process(
00666             a->location_get(),ts2ds(as->type_specifiers_get()))->type_get(),
00667                         as->declarator_get());
00668 
00669         ptr < ss_type > size_t_type_rep = 
00670                 type_info::instance()->get_size_t_type();
00671                  
00672         result_set(or_or_functional_literal::create(
00673                                 size_t_type_rep,
00674                                 ss_integral_literal_info::create_from_number(
00675                                         size_t_type_rep,
00676                                         ss_type_size_evaluator::instance()->size_get(t)/8)));
00677 
00678 }
00679 void sa_deconstruct_spse::visit_as_expression_sizeof_expr( ptr< as_expression_sizeof_expr > a)
00680 {
00681         ptr< sa_deconstruct_spse > vl = sa_deconstruct_spse::create();
00682         ptr< or_or_functional > l;
00683 
00684         /* recursively on arguments */
00685         a->expr_get()->accept_as_expr_visitor(vl);
00686         l = vl->result_get();
00687         
00688         ptr < ss_type > size_t_type_rep = 
00689                 type_info::instance()->get_size_t_type();
00690 
00691         result_set(or_or_functional_literal::create(
00692                                 size_t_type_rep,
00693                                 ss_integral_literal_info::create_from_number(
00694                                         size_t_type_rep,
00695                                         ss_type_size_evaluator::instance()->size_get(l->type_get())/8)));;
00696 }
00697 void sa_deconstruct_spse::visit_as_expression_typeid_expr( ptr< as_expression_typeid_expr >)
00698 {
00699         lassert2(false, "typeid expression not implemented yet\n");
00700 }
00701 void sa_deconstruct_spse::visit_as_expression_delete_base( ptr< as_expression_delete_base >)
00702 {
00703         lassert2(false, "delete base not implemented yet\n");
00704 }
00705 void sa_deconstruct_spse::visit_as_expression_delete( ptr< as_expression_delete >)
00706 {
00707         lassert2(false, "delete not implemented yet\n");
00708 }
00709 void sa_deconstruct_spse::visit_as_expression_delete_array( ptr< as_expression_delete_array >)
00710 {
00711         lassert2(false, "delete array not implemented yet\n");
00712 }
00713 void sa_deconstruct_spse::visit_as_expression_throw( ptr< as_expression_throw >)
00714 {
00715         lassert2(false, "throw not implemented yet\n");
00716 }
00717 void sa_deconstruct_spse::visit_as_expression_typeid_type( ptr< as_expression_typeid_type >)
00718 {
00719         lassert2(false, "typeid_type not implemented yet\n");
00720 }
00721 void sa_deconstruct_spse::visit_as_expression_new( ptr< as_expression_new >)
00722 {
00723         lassert2(false, "new not implemented yet\n");
00724 }
00725 void sa_deconstruct_spse::visit_as_expression_reinterpret_cast( ptr< as_expression_reinterpret_cast >)
00726 {
00727         lassert2(false, "reinterpret cast not implemented yet\n");
00728 }
00729 void sa_deconstruct_spse::visit_as_expression_dynamic_cast( ptr< as_expression_dynamic_cast >)
00730 {
00731         lassert2(false, "dynamic cast not implemented yet\n");
00732 }
00733 void sa_deconstruct_spse::visit_as_expression_static_cast( ptr< as_expression_static_cast >)
00734 {
00735         lassert2(false, "static cast not implemented yet\n");
00736 }
00737 void sa_deconstruct_spse::visit_as_expression_const_cast( ptr< as_expression_const_cast >)
00738 {
00739         lassert2(false, "const cast not implemented yet\n");
00740 }
00741 void sa_deconstruct_spse::visit_as_expression_old_style_cast( ptr< as_expression_old_style_cast >)
00742 {
00743         lassert2(false, "old-style cast not implemented yet\n");
00744 }
00745 void sa_deconstruct_spse::visit_as_expression_functional_style_cast( ptr< as_expression_functional_style_cast >)
00746 {
00747         lassert2(false, "functional-style cast not implemented yet\n");
00748 }
00749 void sa_deconstruct_spse::visit_as_expression_member_access_dot( ptr< as_expression_member_access_dot >)
00750 {
00751         lassert2(false, "member access not implemented yet\n");
00752 }
00753 void sa_deconstruct_spse::visit_as_expression_member_access_arrow( ptr< as_expression_member_access_arrow >)
00754 {
00755         lassert2(false, "member access not implemented yet\n");
00756 }
00757 void sa_deconstruct_spse::visit_as_expression_qmark( ptr< as_expression_qmark >)
00758 {
00759         lassert2(false, "qmark not implemented yet\n");
00760 }
00761 
00762 /* the following contains visitor converting as_declaration to enum. This is used to determine if
00763  * we are holding the type declaration, variable declaration or function declaration (in 
00764  * sa_deconstruct_spse::visit_as_name above
00765  */
00766 
00767 void ss_decl_to_enum::visit_ss_injected_class_declaration( ptr< ss_injected_class_declaration >)
00768 {
00769         result_set(INJECTED_CLASS_DECLARATION);
00770 }
00771 
00772 void ss_decl_to_enum::visit_ss_structure_declaration( ptr< ss_structure_declaration >)
00773 {
00774         result_set(STRUCTURE_DECLARATION);
00775 }
00776 
00777 void ss_decl_to_enum::visit_ss_namespace_definition( ptr< ss_namespace_definition >)
00778 {
00779         result_set(NAMESPACE_DEFINITION);;
00780 }
00781 
00782 void ss_decl_to_enum::visit_ss_object_declaration( ptr< ss_object_declaration >)
00783 {
00784         result_set(OBJECT_DECLARATION);
00785 }
00786 
00787 void ss_decl_to_enum::visit_ss_bitfield_declaration( ptr< ss_bitfield_declaration >)
00788 {
00789         result_set(BITFIELD_DECLARATION);
00790 }
00791 
00792 void ss_decl_to_enum::visit_ss_parameter_declaration( ptr< ss_parameter_declaration >)
00793 {
00794         result_set(PARAMETER_DECLARATION);
00795 }
00796 
00797 void ss_decl_to_enum::visit_ss_enumerator_declaration( ptr< ss_enumerator_declaration >)
00798 {
00799         result_set(ENUMERATOR_DECLARATION);
00800 }
00801 
00802 void ss_decl_to_enum::visit_ss_enum_definition( ptr< ss_enum_definition >)
00803 {
00804         result_set(ENUM_DEFINITION);
00805 }
00806 
00807 void ss_decl_to_enum::visit_ss_typedef_definition( ptr< ss_typedef_definition >)
00808 {
00809         result_set(TYPEDEF_DEFINITION);
00810 }
00811 
00812 void ss_decl_to_enum::visit_ss_using_declaration( ptr< ss_using_declaration >)
00813 {
00814         result_set(USING_DECLARATION);
00815 }
00816 
00817 void ss_decl_to_enum::visit_ss_compound_stmt_declaration( ptr< ss_compound_stmt_declaration >)
00818 {
00819         result_set(COMPOUND_STMT_DECLARATION);
00820 }
00821 void ss_decl_to_enum::visit_ss_function_declaration( ptr< ss_function_declaration >)
00822 {
00823         result_set(FUNCTION_DECLARATION);
00824 }
00825 void ss_decl_to_enum::visit_ss_method_declaration( ptr< ss_method_declaration >)
00826 {
00827         result_set(METHOD_DECLARATION);
00828 }
00829 void ss_decl_to_enum::visit_ss_builtin_operator_declaration( ptr< ss_builtin_operator_declaration >)
00830 {
00831         result_set(BUILTIN_OPERATOR_DECLARATION);
00832 }
00833 void ss_decl_to_enum::visit_ss_fake_declaration( ptr< ss_fake_declaration >)
00834 {
00835         result_set(FAKE_DECLARATION);
00836 }
00837 
00838 
00839 end_package(sem);
00840 end_package(cplus);
00841 end_package(lang);
00842 end_package(lestes);
00843 

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