sa_namespace.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 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00029 #include <lestes/lang/cplus/sem/as_id_to_declaration_set.g.hh>
00030 #include <lestes/lang/cplus/sem/as_id_to_ss_decl_name.g.hh>
00031 #include <lestes/lang/cplus/sem/li_by_name_in_single_scope.g.hh>
00032 #include <lestes/lang/cplus/sem/lu_typedef.hh>
00033 #include <lestes/lang/cplus/sem/sa_context.g.hh>
00034 #include <lestes/lang/cplus/sem/sa_decl_seq_compound_pair_creator.g.hh>
00035 #include <lestes/lang/cplus/sem/sa_namespace.g.hh>
00036 #include <lestes/lang/cplus/sem/sa_namespace.m.hh>
00037 #include <lestes/lang/cplus/sem/ss_decl_name.g.hh>
00038 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00039 #include <lestes/lang/cplus/sem/ss_enums.g.hh>
00040 #include <lestes/lang/cplus/sem/ss_misc.g.hh>
00041 #include <lestes/lang/cplus/sem/ss_statement.g.hh>
00042 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00043 #include <lestes/std/source_location.hh>
00044 
00045 package(lestes);
00046 package(lang);
00047 package(cplus);
00048 package(sem);
00049 
00050 void sa_namespace_definition::process_named( ptr<as_name> name )
00051 {
00052         ptr<source_location> loc = name->location_get();
00053         ptr<ss_declaration_time> time = ss_declaration_time::create( loc->order_get() );
00054         ptr<ss_decl_seq> curr_scope =
00055                 sa_context_manager::instance()->current()->ss_get()->scope_get();
00056         ptr<ss_decl_name> decl_name =
00057                 as_id_to_ss_decl_name::instance()->process( name->identifier_get() );
00058 
00059         /*
00060          * we MUST NOT rely on the lookup performed by the hinter,
00061          * as that processes using directives (which we want to ignore)
00062          */
00063         ptr<declaration_set_type> decls =
00064                 li_by_name_in_single_scope::instance()->process( decl_name, curr_scope );
00065 
00066         bool is_new = true;
00067         if (!decls->empty()) {
00068                 if (error_check( *decls->begin() )) {
00069                         /* something with the same name is already declared and it is not a namespace...
00070                          * scream, but create the namespace anyway; with a dummy name, that is ;-)
00071                          */
00072                         report << name_already_declared << name->identifier_get() << loc;
00073                         for ( declaration_set_type::iterator it = decls->begin(); it != decls->end(); ++it )
00074                                 report << declared_here << (*it)->location_get();
00075                         decl_name = ss_dummy_name::create( loc );
00076                 } else {
00077                         lassert( decls->size() == 1 );
00078                         /* there is only one declaration with that name in current scope AND
00079                          * it is a namespace definition, therefore it must be the one to extend
00080                          */
00081                         is_new = false;
00082                 }
00083         }
00084         if (is_new) {
00085                 ptr<ss_decl_seq> new_scope =
00086                         sa_decl_seq_compound_pair_creator::instance()->process(
00087                                 loc, curr_scope, curr_scope->compound_stmt_get() )->first;
00088                 ptr<ss_declaration> decl = ss_namespace_definition::create(
00089                                 loc, time, time, decl_name, curr_scope, ss_void::instance(),
00090                                 ss_linkage::create( "C++", ss_linkage::LINKAGE_EXTERNAL ), new_scope );
00091                 curr_scope->contents_get()->push_back( decl );
00092                 new_scope->declared_by_set( decl );
00093 
00094                 sa_context_manager::instance()->push(
00095                         sa_context::create(
00096                                 sa_as_context::create( name,
00097                                         as_access_specifier_public::create(loc) ),
00098                                 sa_ss_context::create( new_scope,
00099                                         ss_access_specifier::ACCESS_PUBLIC ),
00100                                 sa_sa_context::create()
00101                         )
00102                 );
00103         } else {
00104                 ptr<ss_namespace_definition> nsd = decls->begin()->dncast<ss_namespace_definition>();
00105 
00106                 sa_context_manager::instance()->push(
00107                         sa_context::create(
00108                                 sa_as_context::create( name,
00109                                         as_access_specifier_public::create(loc) ),
00110                                 sa_ss_context::create( nsd->body_get(),
00111                                         ss_access_specifier::ACCESS_PUBLIC ),
00112                                 sa_sa_context::create()
00113                         )
00114                 );
00115         }
00116 }
00117 
00118 void sa_namespace_definition::process_unnamed( ptr<source_location> loc )
00119 {
00120         report << unnamed_not_yet << loc;
00121         ptr<sa_context> ctx = sa_context_manager::instance()->current();
00122         /* for now, just copy the context */
00123         sa_context_manager::instance()->push(
00124                 sa_context::create(
00125                         sa_as_context::create( ctx->as_get()->scope_get(),
00126                                 as_access_specifier_public::create(loc) ),
00127                         sa_ss_context::create( ctx->ss_get()->scope_get(),
00128                                 ss_access_specifier::ACCESS_PUBLIC ),
00129                         sa_sa_context::create()
00130                 )
00131         );
00132 }
00133 
00134 void sa_namespace_definition::process_end()
00135 {
00136         sa_context_manager::instance()->pop();
00137 }
00138 
00139 void sa_namespace_definition::default_action( ptr<ss_declaration> )
00140 {
00141         result_set( true );
00142 }
00143 
00144 void sa_namespace_definition::visit_ss_namespace_definition( ptr<ss_namespace_definition> )
00145 {
00146         result_set( false );
00147 }
00148 
00149 end_package(sem);
00150 end_package(cplus);
00151 end_package(lang);
00152 end_package(lestes);

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