sa_declarator.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 Declarator analyser.
00030 
00031   Definition of classes performing declarator structural analysis.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/std/source_location.hh>
00036 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00037 #include <lestes/lang/cplus/sem/as_declarator_op2ss_type.g.hh>
00038 #include <lestes/lang/cplus/sem/sa_declarator.g.hh>
00039 #include <lestes/lang/cplus/sem/sa_decl_spec.g.hh>
00040 #include <lestes/lang/cplus/sem/as_other.g.hh>
00041 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00042 #include <lestes/lang/cplus/sem/ss_type.g.hh>
00043 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00044 #include <lestes/lang/cplus/sem/ss_misc.g.hh>
00045 #include <lestes/lang/cplus/sem/ss_decl_name.g.hh>
00046 #include <lestes/lang/cplus/sem/ss_expression.g.hh>
00047 #include <lestes/lang/cplus/sem/or_or.g.hh>
00048 #include <lestes/lang/cplus/sem/ss_statement.g.hh>
00049 
00050 #include <iostream>
00051 
00052 package(lestes);
00053 package(lang);
00054 package(cplus);
00055 package(sem);
00056 
00057 /*!
00058   Returns as_declarator_op visitor.
00059   \return A visitor appropriate for the context.
00060 */
00061 ptr<as_declarator_op2ss_type> sa_declarator_context::create_as_declarator_op2ss_type(void)
00062 {
00063         return as_declarator_op2ss_type::create(decl_specs->type_get()
00064         // FIXME , decl_specs->storage_class_get() != ss_storage_class::ST_TYPEDEF
00065         
00066         );
00067 }
00068 
00069 /*!
00070   Processes the declarator within the given context.
00071   Creates the ss_declaration.
00072   \pre declarator != NULL
00073   \param declarator  The the declarator to process.
00074 */
00075 void sa_declarator::process(ptr<as_declarator> declarator)
00076 {
00077         lassert(declarator);
00078         
00079         // create the appropriate visitor 
00080         ptr<as_declarator_op2ss_type> v = context->create_as_declarator_op2ss_type();
00081 
00082         typedef ::lestes::std::list< srp<as_declarator_op> > as_declarator_op_list_type;
00083         ptr<as_declarator_op_list_type> lst = declarator->declarator_ops_get();
00084         
00085         {
00086                 as_declarator_op_list_type::reverse_iterator rit = lst->rbegin(), 
00087                         rend = lst->rend(), tit = lst->rbegin();
00088                         ++tit;
00089                 
00090                 // walk through all declarator ops in reverse direction
00091                 for ( ; tit != rend; ++rit, ++tit) {
00092                         // classify individual declarator ops
00093                         v->process(*rit,false);
00094                 }
00095                 
00096                 // classify the first declarator op
00097                 v->process(*rit,true);
00098         }
00099 
00100         // TODO pt enable after declarator has correct location type
00101         //ptr<source_location> loc = declarator->location_get();
00102         ptr<source_location> loc = source_location::create(file_info::create("",NULL),1,1);
00103         ptr<ss_type> type = v->type_get();
00104         ptr<ss_decl_seq> parent_scope = context->parent_scope_get();
00105         ptr<sa_decl_spec> decl_specs = context->decl_specs_get();
00106         
00107         // create the appropriate ss_declaration
00108         // check specifiers with knowledge of context
00109         if (v->parameters_get()) {
00110                 // TODO decl_seq_compound_pair 
00111 #if 0
00112                 ptr<ss_sp> psp = ss_sp::create(loc,NULL,NULL,0);
00113                 ptr<ss_sp> nsp = ss_sp::create(loc,NULL,NULL,0);
00114                 ptr<ss_sp> dsp = ss_sp::create(loc,NULL,NULL,0);
00115                 psp->nsp_set(dsp);
00116                 dsp->nsp_set(nsp);
00117                 dsp->psp_set(psp);
00118                 nsp->psp_set(dsp);
00119                 
00120                 ptr<ss_decl_seq> decl_seq = ss_decl_seq::create(
00121                         loc, // location 
00122                         v->parameters_get(), // parameter declarations 
00123                         context->parent_scope_get(), // parent
00124                         NULL, // compound
00125                         list< srp<ss_using_directive> >::create(), // using directives
00126                         NULL // declared by
00127                         );
00128  
00129                 ptr<ss_compound_stmt> stmt = ss_compound_stmt::create(
00130                         loc, list< srp<ss_label> >::create(),
00131                         // FIXME parent_stmt,
00132                         NULL,
00133                         psp,nsp,list< srp<ss_sp> >::create(),
00134                         decl_seq,
00135                         list< srp<ss_statement> >::create(), dsp);
00136                         
00137                 decl_seq->compound_stmt_set(stmt);
00138                 decl_seq->declared_by_set(declaration);
00139         decl_seq->contents_get()->push_back(class_decl_alias);
00140         parent_scope->contents_get()->push_back(class_decl);
00141 #endif
00142 
00143                 // TODO method declaration separately
00144         
00145                 declaration = ss_function_declaration::create(
00146                         loc, // location 
00147                         // TODO
00148                         ss_declaration_time::create(loc->order_get()), // visible time
00149                         ss_declaration_time::create(loc->order_get()), // declaration time
00150                         // TODO see sa_param_decl
00151                         NULL, // declaration name
00152                         parent_scope, // parent_scope scope
00153                         v->type_get(), // type
00154                         // TODO pt fill
00155                         ss_linkage::create("C++",ss_linkage::LINKAGE_EXTERNAL), // linkage
00156                         // TODO params
00157                         NULL, // parameters
00158                         NULL // ptr< ss_compound_stmt > a__ss_function_declaration__body
00159                         );
00160 
00161         } else {
00162                 if (decl_specs->virtual_flag_get() ||
00163                          decl_specs->explicit_flag_get() ||
00164                          decl_specs->inline_flag_get()) {
00165                         // TODO pt report error: invalid specifiers
00166                 }
00167                 
00168                 if (decl_specs->storage_class_get() == ss_storage_class::ST_TYPEDEF) {
00169                 //if (specifiers->storage_get() == ss_storage_class::ST_TYPEDEF) {
00170                         ptr < ss_declaration_time > dt = ss_declaration_time::create(loc->order_get());
00171                         
00172                         declaration = ss_typedef_definition::create(
00173                                 loc,
00174                                 dt, // visible since
00175                                 dt, // declaration time
00176                                 // TODO see sa_param_decl
00177                                 NULL, // declaration name
00178                                 parent_scope, // parent_scope scope
00179                                 type, // ss type
00180                                 ss_linkage::create("C++",ss_linkage::LINKAGE_NO), // linkage
00181                                 context->access_specifier_get(), // access specifier
00182                                 ss_storage_class::ST_TYPEDEF // storage class
00183                                 );
00184 
00185                 } else {
00186                         ptr < ss_declaration_time > dt = ss_declaration_time::create(loc->order_get());
00187                         declaration = ss_object_declaration::create(
00188                                 loc,
00189                                 dt, // visible since
00190                                 dt, // declaration time
00191                                 // TODO
00192                                 NULL, // declaration name
00193                                 parent_scope, // parent_scope scope
00194                                 type, // ss type
00195                                 // TODO from context
00196                                 NULL, // linkage
00197                                 ss_access_specifier::ACCESS_PUBLIC,
00198                                 // TODO from context
00199                                 ss_storage_class::ST_NONE, // storage class
00200                                 ss_declaration_time::infinity(), // initialized since
00201                                 NULL // initializer
00202                                 );
00203                 }
00204         }
00205 
00206         // add the declaration into the parent_scope scope
00207         parent_scope->contents_get()->push_back(declaration);
00208 }
00209 
00210 end_package(sem);
00211 end_package(cplus);
00212 end_package(lang);
00213 end_package(lestes);
00214 /* vim: set ft=lestes : */

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