1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  sc_module_name.h -- An object used to help manage object names
23                      and hierarchy.
24
25  Original Author: Stan Y. Liao, Synopsys, Inc.
26
27  CHANGE LOG AT THE END OF THE FILE
28 *****************************************************************************/
29
30// $Log: sc_module_name.h,v $
31// Revision 1.5  2011/08/26 20:46:10  acg
32//  Andy Goodrich: moved the modification log to the end of the file to
33//  eliminate source line number skew when check-ins are done.
34//
35
36#ifndef SC_MODULE_NAME_H
37#define SC_MODULE_NAME_H
38
39
40namespace sc_core {
41
42class sc_module;
43class sc_simcontext;
44
45
46// ----------------------------------------------------------------------------
47//  CLASS : sc_module_name
48//
49//  Module name class.
50// ----------------------------------------------------------------------------
51
52class sc_module_name
53{
54    friend class sc_module;
55    friend class sc_object_manager;
56
57public:
58
59    sc_module_name( const char* );
60    sc_module_name( const sc_module_name& );
61
62    ~sc_module_name();
63
64    operator const char*() const;
65
66protected:
67    inline void clear_module( sc_module* module_p );
68    inline void set_module( sc_module* module_p );
69
70private:
71
72    const char*     m_name;
73    sc_module*      m_module_p;
74    sc_module_name* m_next;
75    sc_simcontext*  m_simc;
76    bool            m_pushed;
77
78private:
79
80    // disabled
81    sc_module_name();
82    sc_module_name& operator = ( const sc_module_name& );
83};
84
85inline void sc_module_name::clear_module( sc_module* module_p )
86{
87    assert( m_module_p == module_p );
88    m_module_p = 0;
89}
90
91inline void sc_module_name::set_module( sc_module* module_p )
92{
93    m_module_p = module_p;
94}
95
96} // namespace sc_core
97
98// Revision 1.4  2011/02/18 20:27:14  acg
99//  Andy Goodrich: Updated Copyrights.
100//
101// Revision 1.3  2011/02/13 21:47:37  acg
102//  Andy Goodrich: update copyright notice.
103//
104// Revision 1.2  2008/05/22 17:06:26  acg
105//  Andy Goodrich: updated copyright notice to include 2008.
106//
107// Revision 1.1.1.1  2006/12/15 20:20:05  acg
108// SystemC 2.3
109//
110// Revision 1.4  2006/03/14 23:56:58  acg
111//   Andy Goodrich: This fixes a bug when an exception is thrown in
112//   sc_module::sc_module() for a dynamically allocated sc_module
113//   object. We are calling sc_module::end_module() on a module that has
114//   already been deleted. The scenario runs like this:
115//
116//   a) the sc_module constructor is entered
117//   b) the exception is thrown
118//   c) the exception processor deletes the storage for the sc_module
119//   d) the stack is unrolled causing the sc_module_name instance to be deleted
120//   e) ~sc_module_name() calls end_module() with its pointer to the sc_module
121//   f) because the sc_module has been deleted its storage is corrupted,
122//      either by linking it to a free space chain, or by reuse of some sort
123//   g) the m_simc field is garbage
124//   h) the m_object_manager field is also garbage
125//   i) an exception occurs
126//
127//   This does not happen for automatic sc_module instances since the
128//   storage for the module is not reclaimed its just part of the stack.
129//
130//   I am fixing this by having the destructor for sc_module clear the
131//   module pointer in its sc_module_name instance. That cuts things at
132//   step (e) above, since the pointer will be null if the module has
133//   already been deleted. To make sure the module stack is okay, I call
134//   end-module() in ~sc_module in the case where there is an
135//   sc_module_name pointer lying around.
136//
137// Revision 1.3  2006/01/13 18:44:30  acg
138// Added $Log to record CVS changes into the source.
139
140#endif
141