Ignore:
Timestamp:
Jan 22, 2013, 4:23:22 PM (12 years ago)
Author:
meunier
Message:

Code formatting in all source files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/sc_object.cc

    r27 r52  
    3939#include <string>
    4040#include <map>
    41 
    4241#include <cassert>
     42
    4343#include "sc_object.h"
    44 //#include "sc_port.h"
    4544#include "internal.h"
    4645#include "sc_signal.h"
    4746#include "module_hierarchy.h"
     47
    4848#ifdef HAVE_CONFIG_H
    4949#include "config.h"
    5050#endif
    5151
     52
    5253using namespace std;
    5354
    5455namespace sc_core {
    5556
    56 static void
    57 gen_name (const char *prefix, string &s)
    58 {
    59   s = prefix;
    60   static int i = 0;
    61   char ic[10];
    62   sprintf (ic,"%d",i++);
    63   s += ic;
    64 }
    65 // ----------------------------------------------------------------------------
    66 static void
    67 build_complete_name (const char *name, string &out)
    68 {
    69         out = "";
    70   module_name_stack_t::const_iterator i;
    71   for (i = module_name_stack.begin (); i != module_name_stack.end (); ++i) {
    72     const string &module_name = *i;
    73     out += (module_name + ".");
    74 //    out += ".";
    75   }
    76 //  assert(name != NULL);
    77   if (name)
    78     out += name;
    79   else
    80     out[out.length ()-1] = '\0';
    81 #if 0
    82   cerr << "complete_name = " << out << endl;
    83 #endif
    84 }
    85 
    86 #if 0
    87 static
    88 void
    89 build_full_name_r (string &out, const sc_object *obj)
    90 {
    91   if (obj == NULL)
    92   {
     57static void gen_name (const char *prefix, string &s) {
     58    s = prefix;
     59    static int i = 0;
     60    char ic[10];
     61    sprintf (ic,"%d",i++);
     62    s += ic;
     63}
     64
     65
     66static void build_complete_name (const char *name, string &out) {
    9367    out = "";
    94   } else {
    95     const sc_object *parent = obj->get_parent_object ();
    96     build_full_name_r (out, parent);
    97     out += obj->basename ();
    98     out += ".";
    99   }
    100 }
    101 
    102 static
    103 void
    104 build_full_name (string &out, const sc_object &obj)
    105 {
    106   const sc_object *parent = obj.get_parent_object ();
    107   build_full_name_r (out, parent);
    108   out += obj.basename ();
    109   cerr << "build_full_name = " << out << endl;
    110 }
    111 #endif
    112 
    113 typedef std::map<const sc_object* const,string> object2name_t;
     68    module_name_stack_t::const_iterator i;
     69    for (i = module_name_stack.begin (); i != module_name_stack.end (); ++i) {
     70        const string &module_name = *i;
     71        out += (module_name + ".");
     72    }
     73    if (name) {
     74        out += name;
     75    }
     76    else {
     77        out[out.length ()-1] = '\0';
     78    }
     79}
     80
     81
     82typedef std::map<const sc_object * const, string> object2name_t;
    11483static object2name_t object2basename;
    11584static object2name_t object2fullname;
    11685
    11786struct object_infos_t {
    118         const char *kind_string;
     87    const char * kind_string;
    11988};
    120 typedef std::map<const sc_object* const,object_infos_t> object2infos_t;
     89
     90typedef std::map<const sc_object * const, object_infos_t> object2infos_t;
    12191static object2infos_t object2infos;
     92
    12293
    12394// We initialize SC_BIND_PROXY_NIL there to make sure object2infos,
     
    12596// SC_BIND_PROXY_NIL should be declared into sc_module.cc but it prevents us
    12697// to force the initialization order.
    127 const char *SC_BIND_PROXY_NIL_string = "SC_BIND_PROXY_NIL";
    128 sc_bind_proxy SC_BIND_PROXY_NIL (SC_BIND_PROXY_NIL_string,NULL);
     98const char * SC_BIND_PROXY_NIL_string = "SC_BIND_PROXY_NIL";
     99sc_bind_proxy SC_BIND_PROXY_NIL(SC_BIND_PROXY_NIL_string, NULL);
     100
    129101
    130102// ----------------------------------------------------------------------------
     
    132104//                                               
    133105// ----------------------------------------------------------------------------
    134 
    135 const char *
    136 sc_gen_unique_name (const char *basename_)
    137 {
    138         string s;
    139         gen_name (basename_,s);
    140         return strdup (s.c_str ());
    141 }
     106const char * sc_gen_unique_name(const char * basename_) {
     107    string s;
     108    gen_name(basename_,s);
     109    return strdup (s.c_str());
     110}
     111
    142112
    143113// ----------------------------------------------------------------------------
     
    146116// ----------------------------------------------------------------------------
    147117
    148 const char* const sc_object::kind_string = "sc_object";
    149 
    150 void
    151 sc_object::set_kind (const char *k)
    152 {
    153         object2infos[this].kind_string = k;
    154 }
    155 
    156 void
    157 sc_object::init ()
    158 {
    159         set_kind ("sc_object");
    160   add_child (*this);
    161 }
    162 
    163 sc_object::sc_object()
    164 {
    165         string noname;
    166         gen_name ("noname_",noname);
    167 #if 0
    168   cerr << "object2basename[this] = " << noname << "\n";
    169 #endif
    170   object2basename[this] = noname;
    171   build_complete_name (noname.c_str(),object2fullname[this]);
    172         init ();
    173 }
    174 
    175 sc_object::sc_object(const char *name_)
    176 {
    177   const char *temp;
    178   if (name_ == NULL) {
    179     if (module_name_stack.empty())
    180     {
    181       cerr << "Internal error : module_name_stack is empty.";
    182       exit (21092005);
    183     }
    184     string &module_name = module_name_stack.back ();
    185     temp = module_name.c_str ();
    186   } else {
    187     temp = name_;
    188   }
    189 #if 0
    190   cerr << "object2basename[this] = " << temp << "\n";
    191   cerr << "name temp = " << temp << endl;
    192 #endif
    193   object2basename[this] = temp;
    194   build_complete_name (name_,object2fullname[this]);
    195         init ();
    196 }
    197 
    198 const char *
    199 sc_object::basename () const
    200 {
    201   return object2basename[this].c_str ();
    202 }
    203 
    204 const char *
    205 sc_object::name () const
    206 {
    207         object2name_t::iterator i = object2fullname.find (this);
     118const char * const sc_object::kind_string = "sc_object";
     119
     120void sc_object::set_kind(const char * k) {
     121    object2infos[this].kind_string = k;
     122}
     123
     124
     125void sc_object::init() {
     126    set_kind("sc_object");
     127    add_child(*this);
     128}
     129
     130
     131sc_object::sc_object() {
     132    string noname;
     133    gen_name("noname_", noname);
     134    object2basename[this] = noname;
     135    build_complete_name(noname.c_str(), object2fullname[this]);
     136    init();
     137}
     138
     139
     140sc_object::sc_object(const char * name_) {
     141    const char * temp;
     142    if (name_ == NULL) {
    208143#ifdef CONFIG_DEBUG
    209         if (i == object2fullname.end ()) {
    210                 cerr << "Internal error : can't find name of " << this << "\n";
    211                 exit (90);
    212         }
    213 #endif
    214   return i->second.c_str ();
    215 }
    216  
    217 void
    218 sc_object::rename (const char* newname) const
    219 {
     144        if (module_name_stack.empty()) {
     145            cerr << "Internal error : module_name_stack is empty.";
     146            exit(21092005);
     147        }
     148#endif
     149        string & module_name = module_name_stack.back();
     150        temp = module_name.c_str();
     151    }
     152    else {
     153        temp = name_;
     154    }
     155    object2basename[this] = temp;
     156    build_complete_name(name_, object2fullname[this]);
     157    init();
     158}
     159
     160
     161const char * sc_object::basename() const {
     162    return object2basename[this].c_str();
     163}
     164
     165
     166const char * sc_object::name() const {
     167    object2name_t::iterator i = object2fullname.find(this);
     168#ifdef CONFIG_DEBUG
     169    if (i == object2fullname.end()) {
     170        cerr << "Internal error : can't find name of " << this << "\n";
     171        exit (90);
     172    }
     173#endif
     174    return i->second.c_str();
     175}
     176
     177
     178void sc_object::rename(const char * newname) const {
     179    object2basename[this] = newname;
     180    build_complete_name (newname,object2fullname[this]);
     181}
     182
     183
     184const char * sc_object::kind() const {
     185    object2infos_t::iterator i = object2infos.find(this);
     186#ifdef CONFIG_DEBUG
     187    if (i == object2infos.end()) {
     188        cerr << "Internal error : can't find kind of " << this << "\n";
     189        exit(90);
     190    }
     191#endif
     192    return i->second.kind_string;
     193}
     194
     195
     196sc_object::~sc_object() {
     197    if (save_on_exit) {
     198        sc_save_simulation(save_on_exit);
     199        save_on_exit = NULL;
     200    }
     201    object2fullname.erase(this);
     202    object2basename.erase(this);
     203    object2infos.erase(this);
     204}
     205
     206
     207std::ostream & operator << (std::ostream & os, const sc_object & obj) {
     208    return os << obj.name ();
     209}
     210
     211
     212/* virtual */
     213const std::vector<sc_object *> & sc_object::get_child_objects() const {
     214    return sc_core::get_child_objects(*this);
     215}
     216
     217
     218sc_object * sc_object::get_parent_object() const {
     219    return sc_core::get_parent_object(*this);
     220}
     221
     222
     223} // end of sc_core namespace
     224
     225
    220226/*
    221         object2name_t::iterator i = object2fullname.find (this);
    222 #ifdef CONFIG_DEBUG
    223         if (i == object2fullname.end ()) {
    224                 cerr << "Internal error : can't find name of " << this << "\n";
    225                 exit (90);
    226         }
    227 #endif
    228   i->second = newname;
    229   object2basename[this] = newname;
     227# Local Variables:
     228# tab-width: 4;
     229# c-basic-offset: 4;
     230# c-file-offsets:((innamespace . 0)(inline-open . 0));
     231# indent-tabs-mode: nil;
     232# End:
     233#
     234# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    230235*/
    231   object2basename[this] = newname;
    232   build_complete_name (newname,object2fullname[this]);
    233 /*
    234   const std::vector<sc_object*>& childs = get_child_objects();
    235   std::vector<sc_object*>::const_iterator it;
    236   for (it = childs.begin (); it != childs.end (); ++it)
    237   {
    238     string     out;
    239     sc_object* obj = *it;
    240     assert(obj != NULL);
    241     build_full_name (out, *obj);
    242   }
    243 */
    244 }
    245 const char *sc_object::kind () const
    246 {
    247         object2infos_t::iterator i = object2infos.find (this);
    248 #ifdef CONFIG_DEBUG
    249         if (i == object2infos.end ()) {
    250                 cerr << "Internal error : can't find kind of " << this << "\n";
    251                 exit (90);
    252         }
    253 #endif
    254   return i->second.kind_string;
    255 }
    256 
    257 sc_object::~sc_object ()
    258 {
    259   if (save_on_exit)
    260   {
    261     sc_save_simulation (save_on_exit);
    262     save_on_exit = NULL;
    263   }
    264   object2fullname.erase (this);
    265   object2basename.erase (this);
    266   object2infos.erase    (this);
    267 }
    268 
    269 std::ostream&
    270 operator << (std::ostream& os, const sc_object& obj)
    271 {
    272         return os << obj.name ();
    273 }
    274 
    275 /* virtual */
    276 const std::vector<sc_object*>&
    277 sc_object::get_child_objects() const
    278 {
    279   return sc_core::get_child_objects (*this);
    280 }
    281 
    282 sc_object*
    283 sc_object::get_parent_object () const
    284 {
    285   return sc_core::get_parent_object (*this);
    286 }
    287 
    288 } // end of sc_core namespace
    289 
     236
Note: See TracChangeset for help on using the changeset viewer.