[270] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[272] | 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 |
|
---|
[636] | 36 | void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset, const std::vector<int> &relationTable )
|
---|
[270] | 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();
|
---|
[637] | 52 | if( pUserProc->IsExternal() )
|
---|
| 53 | {
|
---|
| 54 | // 外部参照の場合は取り込まない
|
---|
| 55 | continue;
|
---|
| 56 | }
|
---|
[273] | 57 |
|
---|
[637] | 58 | pUserProc->ResetRelationalObjectModuleIndex( relationTable );
|
---|
| 59 |
|
---|
[273] | 60 | pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 61 |
|
---|
[270] | 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();
|
---|
[637] | 71 | if( pDllProc->IsExternal() )
|
---|
| 72 | {
|
---|
| 73 | // 外部参照の場合は取り込まない
|
---|
| 74 | continue;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | pDllProc->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[270] | 78 | this->dllProcs.Put( pDllProc );
|
---|
| 79 | }
|
---|
| 80 | meta.GetDllProcs().PullOutAll();
|
---|
| 81 |
|
---|
| 82 | // クラス
|
---|
[271] | 83 | meta.GetClasses().Iterator_Reset();
|
---|
| 84 | while( meta.GetClasses().Iterator_HasNext() )
|
---|
| 85 | {
|
---|
| 86 | CClass *pClass = meta.GetClasses().Iterator_GetNext();
|
---|
[637] | 87 | if( pClass->IsExternal() )
|
---|
| 88 | {
|
---|
| 89 | // 外部参照の場合は取り込まない
|
---|
| 90 | continue;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | pClass->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[636] | 94 | pClass->Readed();
|
---|
[271] | 95 | this->GetClasses().Put( pClass );
|
---|
| 96 | }
|
---|
| 97 | meta.GetClasses().PullOutAll();
|
---|
[270] | 98 |
|
---|
| 99 | // グローバル変数
|
---|
[288] | 100 | long initAreaBaseOffset = this->globalVars.initAreaBuffer.GetSize();
|
---|
[750] | 101 | foreach( Variable *pVar, meta.globalVars )
|
---|
[271] | 102 | {
|
---|
[637] | 103 | if( pVar->IsExternal() )
|
---|
| 104 | {
|
---|
| 105 | // 外部参照の場合は取り込まない
|
---|
| 106 | continue;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[283] | 109 | // 基底スコープレベルのグローバル変数の生存値をオンにする
|
---|
| 110 | if( pVar->GetScopeLevel() == 0 )
|
---|
| 111 | {
|
---|
[392] | 112 | pVar->isLiving = true;
|
---|
[283] | 113 | }
|
---|
| 114 |
|
---|
[287] | 115 | bool isResetOffsetAddress = true;
|
---|
| 116 | if( pVar->HasInitData() )
|
---|
| 117 | {
|
---|
| 118 | // 初期バッファがあるときはデータテーブルオフセットを適用する
|
---|
[288] | 119 | pVar->SetOffsetAddress( pVar->GetOffsetAddress() + initAreaBaseOffset );
|
---|
[287] | 120 |
|
---|
| 121 | isResetOffsetAddress = false;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[637] | 124 | pVar->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[287] | 125 | this->globalVars.Add( pVar, isResetOffsetAddress );
|
---|
[271] | 126 | }
|
---|
| 127 | meta.globalVars.PullOutAll();
|
---|
[288] | 128 | this->globalVars.initAreaBuffer.Put(
|
---|
| 129 | meta.globalVars.initAreaBuffer.GetBuffer(),
|
---|
| 130 | meta.globalVars.initAreaBuffer.GetSize()
|
---|
| 131 | );
|
---|
[270] | 132 |
|
---|
| 133 | // グローバル定数
|
---|
[271] | 134 | meta.GetGlobalConsts().Iterator_Reset();
|
---|
| 135 | while( meta.GetGlobalConsts().Iterator_HasNext() )
|
---|
| 136 | {
|
---|
| 137 | CConst *pConst = meta.GetGlobalConsts().Iterator_GetNext();
|
---|
[637] | 138 | if( pConst->IsExternal() )
|
---|
| 139 | {
|
---|
| 140 | // 外部参照の場合は取り込まない
|
---|
| 141 | continue;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | pConst->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[271] | 145 | this->GetGlobalConsts().Put( pConst );
|
---|
| 146 | }
|
---|
| 147 | meta.GetGlobalConsts().PullOutAll();
|
---|
[270] | 148 |
|
---|
| 149 | // グローバル定数マクロ
|
---|
[271] | 150 | meta.GetGlobalConstMacros().Iterator_Reset();
|
---|
| 151 | while( meta.GetGlobalConstMacros().Iterator_HasNext() )
|
---|
| 152 | {
|
---|
| 153 | ConstMacro *pConstMacro = meta.GetGlobalConstMacros().Iterator_GetNext();
|
---|
[637] | 154 | if( pConstMacro->IsExternal() )
|
---|
| 155 | {
|
---|
| 156 | // 外部参照の場合は取り込まない
|
---|
| 157 | continue;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | pConstMacro->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[271] | 161 | this->GetGlobalConstMacros().Put( pConstMacro );
|
---|
| 162 | }
|
---|
| 163 | meta.GetGlobalConstMacros().PullOutAll();
|
---|
[270] | 164 |
|
---|
| 165 | // blittable型
|
---|
[271] | 166 | BOOST_FOREACH( BlittableType &blittableType, meta.blittableTypes )
|
---|
| 167 | {
|
---|
[637] | 168 | // TODO: coreモジュール以外でもBlittable型用のクラスモジュールを定義できるようにすべき
|
---|
[271] | 169 | this->blittableTypes.push_back( blittableType );
|
---|
| 170 | }
|
---|
| 171 | meta.blittableTypes.clear();
|
---|
[270] | 172 |
|
---|
| 173 | // TypeDef
|
---|
[271] | 174 | BOOST_FOREACH( TypeDef &typeDef, meta.typeDefs )
|
---|
| 175 | {
|
---|
[637] | 176 | if( typeDef.IsExternal() )
|
---|
| 177 | {
|
---|
| 178 | // 外部参照の場合は取り込まない
|
---|
| 179 | continue;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | typeDef.ResetRelationalObjectModuleIndex( relationTable );
|
---|
[271] | 183 | this->typeDefs.push_back( typeDef );
|
---|
| 184 | }
|
---|
| 185 | meta.typeDefs.clear();
|
---|
[270] | 186 |
|
---|
| 187 | // 関数ポインタ
|
---|
[750] | 188 | foreach( ProcPointer *pProcPointer, meta.procPointers )
|
---|
[271] | 189 | {
|
---|
[637] | 190 | if( pProcPointer->IsExternal() )
|
---|
| 191 | {
|
---|
| 192 | // 外部参照の場合は取り込まない
|
---|
| 193 | continue;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | pProcPointer->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[271] | 197 | this->procPointers.push_back( pProcPointer );
|
---|
| 198 | }
|
---|
| 199 | meta.procPointers.PullOutAll();
|
---|
[448] | 200 |
|
---|
| 201 | // デリゲート
|
---|
| 202 | meta.GetDelegates().Iterator_Reset();
|
---|
| 203 | while( meta.GetDelegates().Iterator_HasNext() )
|
---|
| 204 | {
|
---|
| 205 | Delegate *pDelegate = meta.GetDelegates().Iterator_GetNext();
|
---|
[637] | 206 | if( pDelegate->IsExternal() )
|
---|
| 207 | {
|
---|
| 208 | // 外部参照の場合は取り込まない
|
---|
| 209 | continue;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | pDelegate->ResetRelationalObjectModuleIndex( relationTable );
|
---|
[448] | 213 | this->GetDelegates().Put( pDelegate );
|
---|
| 214 | }
|
---|
| 215 | meta.GetDelegates().PullOutAll();
|
---|
[270] | 216 | }
|
---|
[562] | 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 | }
|
---|
[566] | 232 |
|
---|
[598] | 233 | const CClass *Meta::FindClassSupportedTypeDef( const Symbol &symbol )
|
---|
[566] | 234 | {
|
---|
[598] | 235 | const CClass *pClass = this->GetClasses().FindEx( symbol );
|
---|
[566] | 236 | if( pClass )
|
---|
| 237 | {
|
---|
| 238 | return pClass;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | // TypeDefも見る
|
---|
[632] | 242 | const TypeDef *pTypeDef = this->GetTypeDefs().Find( symbol );
|
---|
| 243 | if( pTypeDef )
|
---|
| 244 | {
|
---|
| 245 | Type type = pTypeDef->GetBaseType();
|
---|
| 246 | if( type.IsObject() )
|
---|
| 247 | {
|
---|
[566] | 248 | return &type.GetClass();
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | return NULL;
|
---|
| 253 | }
|
---|
[637] | 254 |
|
---|
[640] | 255 | void Meta::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 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();
|
---|
[640] | 263 | pUserProc->Resolve( resolver, resolveErrors );
|
---|
[637] | 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();
|
---|
[640] | 272 | pDllProc->Resolve( resolver, resolveErrors );
|
---|
[637] | 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();
|
---|
[640] | 281 | pClass->Resolve( resolver, resolveErrors );
|
---|
[637] | 282 | }
|
---|
| 283 |
|
---|
| 284 | // グローバル変数
|
---|
[750] | 285 | foreach( Variable *pVar, globalVars )
|
---|
[637] | 286 | {
|
---|
[640] | 287 | pVar->Resolve( resolver, resolveErrors );
|
---|
[637] | 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();
|
---|
[640] | 296 | pConst->Resolve( resolver, resolveErrors );
|
---|
[637] | 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();
|
---|
[640] | 305 | pConstMacro->Resolve( resolver, resolveErrors );
|
---|
[637] | 306 | }
|
---|
| 307 |
|
---|
[640] | 308 | // blittable型
|
---|
| 309 | BOOST_FOREACH( BlittableType &blittableType, blittableTypes )
|
---|
| 310 | {
|
---|
| 311 | blittableType.Resolve( resolver, resolveErrors );
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[637] | 314 | // TypeDef
|
---|
| 315 | BOOST_FOREACH( TypeDef &typeDef, typeDefs )
|
---|
| 316 | {
|
---|
[640] | 317 | typeDef.Resolve( resolver, resolveErrors );
|
---|
[637] | 318 | }
|
---|
| 319 |
|
---|
| 320 | // 関数ポインタ
|
---|
[750] | 321 | foreach( ProcPointer *pProcPointer, procPointers )
|
---|
[637] | 322 | {
|
---|
[640] | 323 | pProcPointer->Resolve( resolver, resolveErrors );
|
---|
[637] | 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();
|
---|
[640] | 332 | pDelegate->Resolve( resolver, resolveErrors );
|
---|
[637] | 333 | }
|
---|
| 334 | }
|
---|