00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_PARSER_LINKER_HPP
00017 #define TORC_GENERIC_PARSER_LINKER_HPP
00018
00019 #include <algorithm>
00020 #include <string>
00021 #include <vector>
00022
00023
00024 #include <boost/shared_ptr.hpp>
00025
00026 #include "torc/generic/om/PointerTypes.hpp"
00027 #include "torc/generic/parser/ParserPointerTypes.hpp"
00028 #include "torc/generic/util/Error.hpp"
00029 #include "torc/generic/om/SymTab.hpp"
00030
00031 namespace torc { namespace generic { class View; } }
00032 namespace torc { namespace generic { class Instance; } }
00033 namespace torc { namespace generic { class Root; } }
00034
00035 namespace torc {
00036
00037 namespace generic {
00038
00039
00040
00041
00042
00043
00044
00045
00046 class Linker
00047 {
00048 public:
00049
00050
00051
00052 class NameSpec
00053 {
00054 public:
00055 NameSpec();
00056
00057 NameSpec( const std::string &inLibraryName,
00058 const std::string &inCellName,
00059 const std::string &inViewName );
00060
00061 ~NameSpec() throw();
00062
00063 NameSpec(const NameSpec &inSource);
00064
00065 NameSpec & operator=(const NameSpec &inSource) throw();
00066
00067 inline bool
00068 operator <(const NameSpec &inRhs) const throw();
00069
00070 inline std::string
00071 getLibraryName() const throw();
00072
00073 void
00074 setLibraryName(const std::string &inValue) throw();
00075
00076 inline std::string
00077 getCellName() const throw();
00078
00079 void
00080 setCellName(const std::string &inValue) throw();
00081
00082 inline std::string
00083 getViewName() const throw();
00084
00085 void
00086 setViewName(const std::string &inValue) throw();
00087
00088 private:
00089 std::string mLibraryName;
00090 std::string mCellName;
00091 std::string mViewName;
00092
00093 };
00094
00095
00096
00097
00098 class UnresolvedInstances
00099 {
00100 public:
00101 inline const ViewSharedPtr
00102 getExternView() const throw();
00103
00104 void
00105 setExternView(const ViewSharedPtr &inValue) throw();
00106
00107 void
00108 addInstance(const InstanceSharedPtr &inInstance) throw();
00109
00110 inline const std::vector< InstanceSharedPtr > &
00111 getInstances() const throw();
00112
00113 void
00114 setInstances(
00115 const std::vector< InstanceSharedPtr > & value
00116 ) throw();
00117
00118 template<typename _Tp> void
00119 applyActionOnInstances( const _Tp &action ) {
00120 std::vector< InstanceSharedPtr >::iterator first
00121 = mInstances.begin();
00122 std::vector< InstanceSharedPtr >::iterator last
00123 = mInstances.end();
00124 for(; first != last; ++first )
00125 {
00126 try
00127 {
00128 action( *first );
00129 }
00130 catch(Error &e)
00131 {
00132 e.setCurrentLocation(
00133 __FUNCTION__, __FILE__, __LINE__ );
00134 throw;
00135 }
00136 }
00137 }
00138
00139
00140 UnresolvedInstances();
00141
00142 ~UnresolvedInstances() throw();
00143
00144 UnresolvedInstances(const UnresolvedInstances &inSource);
00145
00146 UnresolvedInstances & operator=(
00147 const UnresolvedInstances &inSource) throw();
00148
00149 private:
00150 ViewSharedPtr mExternView;
00151 std::vector< InstanceSharedPtr > mInstances;
00152 };
00153
00154 typedef boost::shared_ptr<UnresolvedInstances> UnresolvedInstancesPtr;
00155
00156 typedef SymTab<NameSpec,UnresolvedInstancesPtr> UnresolvedInfoMap;
00157
00158 public:
00159
00160
00161
00162
00163
00164
00165
00166 ViewSharedPtr
00167 findExternView(const NameSpec &inNameSpec) throw();
00168
00169
00170
00171
00172
00173
00174
00175 void
00176 setExternView(const NameSpec &inNameSpec,
00177 const ViewSharedPtr &inExternView) throw();
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 bool
00188 findUnresolvedInstances(const NameSpec &inNameSpec,
00189 UnresolvedInstancesPtr &outInstances) throw(Error);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 void registerUnresolvedInstance(const NameSpec &inNameSpec,
00200 const InstanceSharedPtr &inInstance) throw(Error);
00201
00202
00203
00204
00205
00206
00207 void
00208 removeUnresolvedInstances(
00209 const NameSpec &inNameSpec) throw(Error);
00210
00211
00212
00213
00214
00215
00216
00217 void
00218 linkUnresolved(const NameSpec &inNameSpec,
00219 ViewSharedPtr &inView) throw(Error);
00220
00221
00222
00223
00224
00225
00226 Linker(const RootSharedPtr & root);
00227
00228 ~Linker() throw();
00229
00230 Linker(const Linker & source);
00231
00232 Linker &
00233 operator=(const Linker &inSource) throw();
00234
00235 private:
00236 RootSharedPtr mRoot;
00237 UnresolvedInfoMap mInfos;
00238 };
00239
00240 inline bool
00241 Linker::NameSpec::operator <(
00242 const Linker::NameSpec &inRhs) const throw() {
00243 return mLibraryName < inRhs.mLibraryName
00244 || ( mLibraryName == inRhs.mLibraryName
00245 && mCellName < inRhs.mCellName )
00246 || ( mLibraryName == inRhs.mLibraryName
00247 && mCellName == inRhs.mCellName
00248 && mViewName < inRhs.mViewName );
00249 }
00250
00251 inline std::string
00252 Linker::NameSpec::getLibraryName() const throw() {
00253 return mLibraryName;
00254 }
00255
00256 inline std::string
00257 Linker::NameSpec::getCellName() const throw() {
00258 return mCellName;
00259 }
00260
00261 inline std::string
00262 Linker::NameSpec::getViewName() const throw() {
00263 return mViewName;
00264 }
00265
00266 inline const ViewSharedPtr
00267 Linker::UnresolvedInstances::getExternView() const throw() {
00268 return mExternView;
00269 }
00270
00271 inline const std::vector< InstanceSharedPtr > &
00272 Linker::UnresolvedInstances::getInstances() const throw() {
00273 return mInstances;
00274 }
00275
00276 }
00277
00278 }
00279 #endif // TORC_GENERIC_PARSER_LINKER_HPP