ss_misc.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/ss_misc.g.hh>
00029 #include <lestes/lang/cplus/sem/ss_statement.g.hh>
00030 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00031 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00032 #include <lestes/lang/cplus/sem/ss_decl_name.g.hh>
00033 #include <lestes/lang/cplus/sem/ss_decl_name_matcher.g.hh>
00034 #include <lestes/std/source_location.hh>
00035 
00036 package(lestes);
00037 package(lang);
00038 package(cplus);
00039 package(sem);
00040 
00041 /*!
00042   Tells whether this declaration time is before other declaration time.
00043   \pre other != NULL
00044   \param other  The declaration time to compare to.
00045   \return true  If this declaration is earlier.
00046 */
00047 bool ss_declaration_time::is_before(ptr<ss_declaration_time> other)
00048 {
00049         lassert( other );
00050         return time < other->time;
00051 }
00052 
00053 /*!
00054   The infinity value shall be larger than any regular value.
00055  */
00056 ptr < ss_declaration_time > ss_declaration_time::infinity()
00057 {
00058         if (!infinity_instance)
00059                 infinity_instance = ss_declaration_time::create(static_cast < ulint > (-1));
00060         return infinity_instance;
00061 }
00062 
00063 /*!
00064  * When called for the first time, constructs the grandparent of all instances
00065  * of ss_decl_seq. This means that you can simply recognize it, just compare
00066  * your ptr to the return value of this method.
00067  *
00068  * Note that the instance is its own parent. Also note that when creating it,
00069  * root ss_compound_stmt must be created too. This is achieved by calling
00070  * ss_compound_stmt::root_instance(), which might in turn call us back. The
00071  * code is prepared for this. You can choose which of the two methods you call
00072  * first.
00073  *
00074  * \return  Pointer to the instance of root ss_decl_seq.
00075  */
00076 ptr<ss_decl_seq> ss_decl_seq::root_instance()
00077 {
00078         if (!the_root_instance) {
00079                 /* FIXME: non-null location needed */
00080                 ptr < source_location > loc = source_location::create(file_info::create("",NULL),1,1);
00081                 the_root_instance = new ss_decl_seq(loc,
00082                                 list< srp<ss_declaration> >::create(),
00083                                 NULL, NULL, list< srp<ss_using_directive> >::create(), NULL );
00084                 /* there is no setter for the parent field... */
00085                 the_root_instance->parent = the_root_instance;
00086                 /* FIXME: non-null location needed _twice_ */
00087                 /* FIXME: non-null ss_declaration_time needed */
00088                 /* FIXME: non-null ss_linkage needed */
00089                 ptr<ss_declaration> gl_decl = ss_namespace_definition::create(
00090                                 loc, ss_declaration_time::infinity(), ss_declaration_time::create(0),
00091                                 ss_dummy_name::create(loc), the_root_instance,
00092                                 ss_void::instance(), ss_linkage::create("C++", ss_linkage::LINKAGE_NO),
00093                                 the_root_instance );
00094                 the_root_instance->declared_by_set( gl_decl );
00095                 the_root_instance->contents_get()->push_back( gl_decl );
00096                 /* calls this method again; luckily, we have the_root_instance already set up ;-) */
00097                 the_root_instance->compound_stmt = ss_compound_stmt::root_instance();
00098         }
00099         return the_root_instance;
00100 }
00101 
00102 /*!
00103   Check whether the current function is entry point of the translation unit.
00104   
00105   This function has to be maintained by semantic part, because backend
00106   should be independet on current language, which defines entry point(main)[].
00107                                               
00108 */
00109 bool ss_function_declaration::is_entry_point()
00110 {
00111         if (contained_in_get() != ss_decl_seq::root_instance())                 //has to be on global scope
00112                 return false;
00113         ptr<ss_decl_name> main_name = ss_ordinary_name::create( name_get()->location_get(), "main" );
00114         if (main_name->matches(name_get()))                                     //has to be main
00115                 return true;
00116 
00117         return false;
00118 }
00119 
00120 
00121 end_package(sem);
00122 end_package(cplus);
00123 end_package(lang);
00124 end_package(lestes);

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