| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | void Meta::Clear()
|
|---|
| 4 | {
|
|---|
| 5 | // 名前空間
|
|---|
| 6 | namespaceScopesCollection.clear();
|
|---|
| 7 |
|
|---|
| 8 | // 関数・メソッド
|
|---|
| 9 | userProcs.Clear();
|
|---|
| 10 |
|
|---|
| 11 | // DLL関数
|
|---|
| 12 | dllProcs.Clear();
|
|---|
| 13 |
|
|---|
| 14 | // クラス
|
|---|
| 15 | classesImpl.Clear();
|
|---|
| 16 |
|
|---|
| 17 | // グローバル変数
|
|---|
| 18 | globalVars.Clear();
|
|---|
| 19 |
|
|---|
| 20 | // グローバル定数
|
|---|
| 21 | globalConsts.Clear();
|
|---|
| 22 |
|
|---|
| 23 | // グローバル定数マクロ
|
|---|
| 24 | globalConstMacros.Clear();
|
|---|
| 25 |
|
|---|
| 26 | // blittable型
|
|---|
| 27 | blittableTypes.clear();
|
|---|
| 28 |
|
|---|
| 29 | // TypeDef
|
|---|
| 30 | typeDefs.clear();
|
|---|
| 31 |
|
|---|
| 32 | // 関数ポインタ
|
|---|
| 33 | procPointers.Clear();
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset, const std::vector<int> &relationTable )
|
|---|
| 37 | {
|
|---|
| 38 | // 名前空間
|
|---|
| 39 | BOOST_FOREACH( NamespaceScopes &namespaceScopes, meta.namespaceScopesCollection )
|
|---|
| 40 | {
|
|---|
| 41 | if( !this->namespaceScopesCollection.IsExist( namespaceScopes ) )
|
|---|
| 42 | {
|
|---|
| 43 | this->namespaceScopesCollection.push_back( namespaceScopes );
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | // 関数・メソッド
|
|---|
| 48 | meta.GetUserProcs().Iterator_Reset();
|
|---|
| 49 | while( meta.GetUserProcs().Iterator_HasNext() )
|
|---|
| 50 | {
|
|---|
| 51 | UserProc *pUserProc = meta.GetUserProcs().Iterator_GetNext();
|
|---|
| 52 | if( pUserProc->IsExternal() )
|
|---|
| 53 | {
|
|---|
| 54 | // 外部参照の場合は取り込まない
|
|---|
| 55 | continue;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | pUserProc->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 59 |
|
|---|
| 60 | pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 61 |
|
|---|
| 62 | this->userProcs.Put( pUserProc );
|
|---|
| 63 | }
|
|---|
| 64 | meta.GetUserProcs().PullOutAll();
|
|---|
| 65 |
|
|---|
| 66 | // DLL関数
|
|---|
| 67 | meta.GetDllProcs().Iterator_Reset();
|
|---|
| 68 | while( meta.GetDllProcs().Iterator_HasNext() )
|
|---|
| 69 | {
|
|---|
| 70 | DllProc *pDllProc = meta.GetDllProcs().Iterator_GetNext();
|
|---|
| 71 | if( pDllProc->IsExternal() )
|
|---|
| 72 | {
|
|---|
| 73 | // 外部参照の場合は取り込まない
|
|---|
| 74 | continue;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | pDllProc->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 78 | this->dllProcs.Put( pDllProc );
|
|---|
| 79 | }
|
|---|
| 80 | meta.GetDllProcs().PullOutAll();
|
|---|
| 81 |
|
|---|
| 82 | // クラス
|
|---|
| 83 | meta.GetClasses().Iterator_Reset();
|
|---|
| 84 | while( meta.GetClasses().Iterator_HasNext() )
|
|---|
| 85 | {
|
|---|
| 86 | CClass *pClass = meta.GetClasses().Iterator_GetNext();
|
|---|
| 87 | if( pClass->IsExternal() )
|
|---|
| 88 | {
|
|---|
| 89 | // 外部参照の場合は取り込まない
|
|---|
| 90 | continue;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | pClass->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 94 | pClass->Readed();
|
|---|
| 95 | this->GetClasses().Put( pClass );
|
|---|
| 96 | }
|
|---|
| 97 | meta.GetClasses().PullOutAll();
|
|---|
| 98 |
|
|---|
| 99 | // グローバル変数
|
|---|
| 100 | long initAreaBaseOffset = this->globalVars.initAreaBuffer.GetSize();
|
|---|
| 101 | BOOST_FOREACH( Variable *pVar, meta.globalVars )
|
|---|
| 102 | {
|
|---|
| 103 | if( pVar->IsExternal() )
|
|---|
| 104 | {
|
|---|
| 105 | // 外部参照の場合は取り込まない
|
|---|
| 106 | continue;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | // 基底スコープレベルのグローバル変数の生存値をオンにする
|
|---|
| 110 | if( pVar->GetScopeLevel() == 0 )
|
|---|
| 111 | {
|
|---|
| 112 | pVar->isLiving = true;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | bool isResetOffsetAddress = true;
|
|---|
| 116 | if( pVar->HasInitData() )
|
|---|
| 117 | {
|
|---|
| 118 | // 初期バッファがあるときはデータテーブルオフセットを適用する
|
|---|
| 119 | pVar->SetOffsetAddress( pVar->GetOffsetAddress() + initAreaBaseOffset );
|
|---|
| 120 |
|
|---|
| 121 | isResetOffsetAddress = false;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | pVar->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 125 | this->globalVars.Add( pVar, isResetOffsetAddress );
|
|---|
| 126 | }
|
|---|
| 127 | meta.globalVars.PullOutAll();
|
|---|
| 128 | this->globalVars.initAreaBuffer.Put(
|
|---|
| 129 | meta.globalVars.initAreaBuffer.GetBuffer(),
|
|---|
| 130 | meta.globalVars.initAreaBuffer.GetSize()
|
|---|
| 131 | );
|
|---|
| 132 |
|
|---|
| 133 | // グローバル定数
|
|---|
| 134 | meta.GetGlobalConsts().Iterator_Reset();
|
|---|
| 135 | while( meta.GetGlobalConsts().Iterator_HasNext() )
|
|---|
| 136 | {
|
|---|
| 137 | CConst *pConst = meta.GetGlobalConsts().Iterator_GetNext();
|
|---|
| 138 | if( pConst->IsExternal() )
|
|---|
| 139 | {
|
|---|
| 140 | // 外部参照の場合は取り込まない
|
|---|
| 141 | continue;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | pConst->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 145 | this->GetGlobalConsts().Put( pConst );
|
|---|
| 146 | }
|
|---|
| 147 | meta.GetGlobalConsts().PullOutAll();
|
|---|
| 148 |
|
|---|
| 149 | // グローバル定数マクロ
|
|---|
| 150 | meta.GetGlobalConstMacros().Iterator_Reset();
|
|---|
| 151 | while( meta.GetGlobalConstMacros().Iterator_HasNext() )
|
|---|
| 152 | {
|
|---|
| 153 | ConstMacro *pConstMacro = meta.GetGlobalConstMacros().Iterator_GetNext();
|
|---|
| 154 | if( pConstMacro->IsExternal() )
|
|---|
| 155 | {
|
|---|
| 156 | // 外部参照の場合は取り込まない
|
|---|
| 157 | continue;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | pConstMacro->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 161 | this->GetGlobalConstMacros().Put( pConstMacro );
|
|---|
| 162 | }
|
|---|
| 163 | meta.GetGlobalConstMacros().PullOutAll();
|
|---|
| 164 |
|
|---|
| 165 | // blittable型
|
|---|
| 166 | BOOST_FOREACH( BlittableType &blittableType, meta.blittableTypes )
|
|---|
| 167 | {
|
|---|
| 168 | // TODO: coreモジュール以外でもBlittable型用のクラスモジュールを定義できるようにすべき
|
|---|
| 169 | this->blittableTypes.push_back( blittableType );
|
|---|
| 170 | }
|
|---|
| 171 | meta.blittableTypes.clear();
|
|---|
| 172 |
|
|---|
| 173 | // TypeDef
|
|---|
| 174 | BOOST_FOREACH( TypeDef &typeDef, meta.typeDefs )
|
|---|
| 175 | {
|
|---|
| 176 | if( typeDef.IsExternal() )
|
|---|
| 177 | {
|
|---|
| 178 | // 外部参照の場合は取り込まない
|
|---|
| 179 | continue;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | typeDef.ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 183 | this->typeDefs.push_back( typeDef );
|
|---|
| 184 | }
|
|---|
| 185 | meta.typeDefs.clear();
|
|---|
| 186 |
|
|---|
| 187 | // 関数ポインタ
|
|---|
| 188 | BOOST_FOREACH( ProcPointer *pProcPointer, meta.procPointers )
|
|---|
| 189 | {
|
|---|
| 190 | if( pProcPointer->IsExternal() )
|
|---|
| 191 | {
|
|---|
| 192 | // 外部参照の場合は取り込まない
|
|---|
| 193 | continue;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | pProcPointer->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 197 | this->procPointers.push_back( pProcPointer );
|
|---|
| 198 | }
|
|---|
| 199 | meta.procPointers.PullOutAll();
|
|---|
| 200 |
|
|---|
| 201 | // デリゲート
|
|---|
| 202 | meta.GetDelegates().Iterator_Reset();
|
|---|
| 203 | while( meta.GetDelegates().Iterator_HasNext() )
|
|---|
| 204 | {
|
|---|
| 205 | Delegate *pDelegate = meta.GetDelegates().Iterator_GetNext();
|
|---|
| 206 | if( pDelegate->IsExternal() )
|
|---|
| 207 | {
|
|---|
| 208 | // 外部参照の場合は取り込まない
|
|---|
| 209 | continue;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | pDelegate->ResetRelationalObjectModuleIndex( relationTable );
|
|---|
| 213 | this->GetDelegates().Put( pDelegate );
|
|---|
| 214 | }
|
|---|
| 215 | meta.GetDelegates().PullOutAll();
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | const ::Delegate &Meta::ToDelegate( const CClass &_class )
|
|---|
| 219 | {
|
|---|
| 220 | const ::Delegate *dg = this->GetDelegates().GetHashArrayElement( _class.GetName().c_str() );
|
|---|
| 221 | while( dg )
|
|---|
| 222 | {
|
|---|
| 223 | if( dg->IsEqualSymbol( _class.GetNamespaceScopes(), _class.GetName() ) ){
|
|---|
| 224 | //名前空間とクラス名が一致した
|
|---|
| 225 | return *dg;
|
|---|
| 226 | }
|
|---|
| 227 | dg = dg->GetChainNext();
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | throw;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | const CClass *Meta::FindClassSupportedTypeDef( const Symbol &symbol )
|
|---|
| 234 | {
|
|---|
| 235 | const CClass *pClass = this->GetClasses().FindEx( symbol );
|
|---|
| 236 | if( pClass )
|
|---|
| 237 | {
|
|---|
| 238 | return pClass;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | // TypeDefも見る
|
|---|
| 242 | const TypeDef *pTypeDef = this->GetTypeDefs().Find( symbol );
|
|---|
| 243 | if( pTypeDef )
|
|---|
| 244 | {
|
|---|
| 245 | Type type = pTypeDef->GetBaseType();
|
|---|
| 246 | if( type.IsObject() )
|
|---|
| 247 | {
|
|---|
| 248 | return &type.GetClass();
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | return NULL;
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | void Meta::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
|---|
| 256 | {
|
|---|
| 257 | // 関数・メソッド
|
|---|
| 258 | this->GetUserProcs().Iterator_Init();
|
|---|
| 259 | this->GetUserProcs().Iterator_Reset();
|
|---|
| 260 | while( this->GetUserProcs().Iterator_HasNext() )
|
|---|
| 261 | {
|
|---|
| 262 | UserProc *pUserProc = this->GetUserProcs().Iterator_GetNext();
|
|---|
| 263 | pUserProc->Resolve( resolver, resolveErrors );
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | // DLL関数
|
|---|
| 267 | this->GetDllProcs().Iterator_Init();
|
|---|
| 268 | this->GetDllProcs().Iterator_Reset();
|
|---|
| 269 | while( this->GetDllProcs().Iterator_HasNext() )
|
|---|
| 270 | {
|
|---|
| 271 | DllProc *pDllProc = this->GetDllProcs().Iterator_GetNext();
|
|---|
| 272 | pDllProc->Resolve( resolver, resolveErrors );
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | // クラス
|
|---|
| 276 | this->GetClasses().Iterator_Init();
|
|---|
| 277 | this->GetClasses().Iterator_Reset();
|
|---|
| 278 | while( this->GetClasses().Iterator_HasNext() )
|
|---|
| 279 | {
|
|---|
| 280 | CClass *pClass = this->GetClasses().Iterator_GetNext();
|
|---|
| 281 | pClass->Resolve( resolver, resolveErrors );
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | // グローバル変数
|
|---|
| 285 | BOOST_FOREACH( Variable *pVar, globalVars )
|
|---|
| 286 | {
|
|---|
| 287 | pVar->Resolve( resolver, resolveErrors );
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | // グローバル定数
|
|---|
| 291 | this->GetGlobalConsts().Iterator_Init();
|
|---|
| 292 | this->GetGlobalConsts().Iterator_Reset();
|
|---|
| 293 | while( this->GetGlobalConsts().Iterator_HasNext() )
|
|---|
| 294 | {
|
|---|
| 295 | CConst *pConst = this->GetGlobalConsts().Iterator_GetNext();
|
|---|
| 296 | pConst->Resolve( resolver, resolveErrors );
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | // グローバル定数マクロ
|
|---|
| 300 | this->GetGlobalConstMacros().Iterator_Init();
|
|---|
| 301 | this->GetGlobalConstMacros().Iterator_Reset();
|
|---|
| 302 | while( this->GetGlobalConstMacros().Iterator_HasNext() )
|
|---|
| 303 | {
|
|---|
| 304 | ConstMacro *pConstMacro = this->GetGlobalConstMacros().Iterator_GetNext();
|
|---|
| 305 | pConstMacro->Resolve( resolver, resolveErrors );
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | // blittable型
|
|---|
| 309 | BOOST_FOREACH( BlittableType &blittableType, blittableTypes )
|
|---|
| 310 | {
|
|---|
| 311 | blittableType.Resolve( resolver, resolveErrors );
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | // TypeDef
|
|---|
| 315 | BOOST_FOREACH( TypeDef &typeDef, typeDefs )
|
|---|
| 316 | {
|
|---|
| 317 | typeDef.Resolve( resolver, resolveErrors );
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | // 関数ポインタ
|
|---|
| 321 | BOOST_FOREACH( ProcPointer *pProcPointer, procPointers )
|
|---|
| 322 | {
|
|---|
| 323 | pProcPointer->Resolve( resolver, resolveErrors );
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | // デリゲート
|
|---|
| 327 | this->GetDelegates().Iterator_Init();
|
|---|
| 328 | this->GetDelegates().Iterator_Reset();
|
|---|
| 329 | while( this->GetDelegates().Iterator_HasNext() )
|
|---|
| 330 | {
|
|---|
| 331 | Delegate *pDelegate = this->GetDelegates().Iterator_GetNext();
|
|---|
| 332 | pDelegate->Resolve( resolver, resolveErrors );
|
|---|
| 333 | }
|
|---|
| 334 | }
|
|---|