[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[632] | 3 |
|
---|
[637] | 4 | CClass::CClass( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces )
|
---|
| 5 | : ClassPrototype( symbol )
|
---|
[632] | 6 | , importedNamespaces( importedNamespaces )
|
---|
| 7 | , classType( Class )
|
---|
| 8 | , pSuperClass( NULL )
|
---|
| 9 | , blittableType( Type() )
|
---|
| 10 | , isReady( false )
|
---|
| 11 | , fixedAlignment( 0 )
|
---|
| 12 | , ConstructorMemberSubIndex( -1 )
|
---|
| 13 | , DestructorMemberSubIndex( -1 )
|
---|
| 14 | , vtblNum( 0 )
|
---|
| 15 | , vtbl_offset( -1 )
|
---|
| 16 | , comVtblOffset( 0 )
|
---|
| 17 | , isCompilingConstructor( false )
|
---|
| 18 | , isCompilingDestructor( false )
|
---|
| 19 | , cacheSize( 0 )
|
---|
| 20 | {
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[637] | 23 | CClass::CClass(
|
---|
| 24 | const Symbol &symbol,
|
---|
[632] | 25 | const NamespaceScopesCollection &importedNamespaces,
|
---|
| 26 | ClassType classType,
|
---|
| 27 | const GenericTypes &formalGenericTypes,
|
---|
| 28 | const Types &superClassActualTypeParameters,
|
---|
| 29 | int ConstructorMemberSubIndex,
|
---|
| 30 | int DestructorMemberSubIndex,
|
---|
| 31 | int vtblNum,
|
---|
| 32 | int fixedAlignment )
|
---|
[637] | 33 | : ClassPrototype( symbol )
|
---|
[632] | 34 | , importedNamespaces( importedNamespaces )
|
---|
| 35 | , classType( classType )
|
---|
| 36 | , formalGenericTypes( formalGenericTypes )
|
---|
| 37 | , pSuperClass( NULL )
|
---|
| 38 | , superClassActualTypeParameters( superClassActualTypeParameters )
|
---|
| 39 | , blittableType( Type() )
|
---|
| 40 | , isReady( false )
|
---|
| 41 | , ConstructorMemberSubIndex( ConstructorMemberSubIndex )
|
---|
| 42 | , DestructorMemberSubIndex( DestructorMemberSubIndex )
|
---|
| 43 | , vtblNum( vtblNum )
|
---|
| 44 | , fixedAlignment( fixedAlignment )
|
---|
| 45 | , vtbl_offset( -1 )
|
---|
| 46 | , comVtblOffset( 0 )
|
---|
| 47 | , isCompilingConstructor( false )
|
---|
| 48 | , isCompilingDestructor( false )
|
---|
| 49 | , cacheSize( 0 )
|
---|
| 50 | {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | CClass::CClass()
|
---|
| 54 | : ClassPrototype()
|
---|
| 55 | , importedNamespaces()
|
---|
| 56 | , classType()
|
---|
| 57 | , pSuperClass( NULL )
|
---|
| 58 | , blittableType( Type() )
|
---|
| 59 | , isReady( false )
|
---|
| 60 | , fixedAlignment( 0 )
|
---|
| 61 | , ConstructorMemberSubIndex( -1 )
|
---|
| 62 | , DestructorMemberSubIndex( -1 )
|
---|
| 63 | , vtblNum( 0 )
|
---|
| 64 | , vtbl_offset( -1 )
|
---|
| 65 | , comVtblOffset( 0 )
|
---|
| 66 | , isCompilingConstructor( false )
|
---|
| 67 | , isCompilingDestructor( false )
|
---|
| 68 | , cacheSize( 0 )
|
---|
| 69 | {
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | CClass::~CClass()
|
---|
| 73 | {
|
---|
| 74 | // 動的メンバ
|
---|
| 75 | BOOST_FOREACH( Member *member, dynamicMembers )
|
---|
| 76 | {
|
---|
| 77 | delete member;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | // 静的メンバ
|
---|
| 81 | BOOST_FOREACH( Member *member, staticMembers )
|
---|
| 82 | {
|
---|
| 83 | delete member;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | // インターフェイス
|
---|
| 87 | BOOST_FOREACH( ::Interface *pInterface, interfaces )
|
---|
| 88 | {
|
---|
| 89 | delete pInterface;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | // テンプレート展開済みのクラス
|
---|
| 93 | BOOST_FOREACH( ExpandedTemplateClass *pExpandedTemplateClass, expandedTemplateClasses )
|
---|
| 94 | {
|
---|
| 95 | delete pExpandedTemplateClass;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[540] | 99 | void CClass::Using() const
|
---|
| 100 | {
|
---|
| 101 | if( this->IsUsing() )
|
---|
| 102 | {
|
---|
| 103 | // 既に使用することになっている
|
---|
| 104 | return;
|
---|
| 105 | }
|
---|
[511] | 106 |
|
---|
[540] | 107 | Prototype::Using();
|
---|
| 108 |
|
---|
| 109 | // 仮想関数になるメソッドに使用チェックをつける
|
---|
| 110 | const CClass &objThis = *this;
|
---|
| 111 | BOOST_FOREACH( const CMethod *pMethod, objThis.GetDynamicMethods() )
|
---|
| 112 | {
|
---|
| 113 | if( pMethod->IsVirtual() )
|
---|
| 114 | {
|
---|
| 115 | pMethod->GetUserProc().Using();
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[206] | 120 | bool CClass::IsClass() const
|
---|
[193] | 121 | {
|
---|
[206] | 122 | return classType == CClass::Class;
|
---|
| 123 | }
|
---|
| 124 | bool CClass::IsInterface() const
|
---|
| 125 | {
|
---|
| 126 | return classType == CClass::Interface;
|
---|
| 127 | }
|
---|
[370] | 128 | bool CClass::IsComInterface() const
|
---|
| 129 | {
|
---|
| 130 | return classType == CClass::ComInterface;
|
---|
| 131 | }
|
---|
[206] | 132 | bool CClass::IsEnum() const
|
---|
| 133 | {
|
---|
| 134 | return classType == CClass::Enum;
|
---|
| 135 | }
|
---|
| 136 | bool CClass::IsDelegate() const
|
---|
| 137 | {
|
---|
| 138 | return classType == CClass::Delegate;
|
---|
| 139 | }
|
---|
| 140 | bool CClass::IsStructure() const
|
---|
| 141 | {
|
---|
| 142 | return classType == CClass::Structure;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | // コンストラクタのコンパイルを開始
|
---|
| 147 | void CClass::NotifyStartConstructorCompile() const
|
---|
| 148 | {
|
---|
| 149 | isCompilingConstructor = true;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | //コンストラクタのコンパイルを終了
|
---|
| 153 | void CClass::NotifyFinishConstructorCompile() const
|
---|
| 154 | {
|
---|
| 155 | isCompilingConstructor = false;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | //コンストラクタをコンパイル中かどうかを判別
|
---|
| 159 | bool CClass::IsCompilingConstructor() const
|
---|
| 160 | {
|
---|
| 161 | return isCompilingConstructor;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | //デストラクタのコンパイルを開始
|
---|
| 165 | void CClass::NotifyStartDestructorCompile() const{
|
---|
| 166 | isCompilingDestructor = true;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | //デストラクタのコンパイルを終了
|
---|
| 170 | void CClass::NotifyFinishDestructorCompile() const{
|
---|
| 171 | isCompilingDestructor = false;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | //デストラクタをコンパイル中かどうかを判別
|
---|
| 175 | bool CClass::IsCompilingDestructor() const
|
---|
| 176 | {
|
---|
| 177 | return isCompilingDestructor;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | //自身の派生クラスかどうかを確認
|
---|
[447] | 181 | bool CClass::IsSubClass( const CClass *pSubClass ) const
|
---|
[206] | 182 | {
|
---|
[447] | 183 | if( !pSubClass->HasSuperClass() )
|
---|
[206] | 184 | {
|
---|
[193] | 185 | return false;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[447] | 188 | const CClass *pTempClass = &pSubClass->GetSuperClass();
|
---|
[206] | 189 | while( pTempClass ){
|
---|
| 190 | if( this == pTempClass ) return true;
|
---|
| 191 | pTempClass = &pTempClass->GetSuperClass();
|
---|
| 192 | }
|
---|
| 193 | return false;
|
---|
[193] | 194 | }
|
---|
| 195 |
|
---|
[206] | 196 | //自身と等しいまたは派生クラスかどうかを確認
|
---|
[447] | 197 | bool CClass::IsEqualsOrSubClass( const CClass *pSubClass ) const
|
---|
[206] | 198 | {
|
---|
[447] | 199 | if( IsEquals( pSubClass ) ) return true;
|
---|
| 200 | return IsSubClass( pSubClass );
|
---|
[206] | 201 | }
|
---|
| 202 |
|
---|
| 203 | // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
|
---|
| 204 | bool CClass::IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const
|
---|
| 205 | {
|
---|
| 206 | if( IsEquals( &objClass ) ) return true;
|
---|
| 207 | if( IsSubClass( &objClass ) ) return true;
|
---|
| 208 | if( objClass.IsSubClass( this ) ) return true;
|
---|
| 209 | return false;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | bool CClass::IsInheritsInterface( const CClass *pInterfaceClass ) const
|
---|
| 213 | {
|
---|
[346] | 214 | BOOST_FOREACH( const ::Interface *pInterface, interfaces ){
|
---|
| 215 | if( pInterfaceClass == &pInterface->GetClass() ){
|
---|
[206] | 216 | return true;
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | return false;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[376] | 222 | bool CClass::InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine )
|
---|
| 223 | {
|
---|
[184] | 224 | //メソッドをコピー
|
---|
[342] | 225 | BOOST_FOREACH( const CMethod *pBaseMethod, inheritsClass.GetDynamicMethods() ){
|
---|
[184] | 226 | CMethod *pMethod = new DynamicMethod( *pBaseMethod );
|
---|
| 227 |
|
---|
| 228 | // アクセシビリティ
|
---|
| 229 | if(pBaseMethod->GetAccessibility() == Prototype::Private){
|
---|
| 230 | pMethod->SetAccessibility( Prototype::None );
|
---|
| 231 | }
|
---|
| 232 | else{
|
---|
| 233 | pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | //pobj_Inherits
|
---|
| 237 | // ※継承元のClassIndexをセット(入れ子継承を考慮する)
|
---|
| 238 | if(pBaseMethod->GetInheritsClassPtr()==0){
|
---|
| 239 | pMethod->SetInheritsClassPtr( &inheritsClass );
|
---|
| 240 | }
|
---|
| 241 | else{
|
---|
| 242 | pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[342] | 245 | GetDynamicMethods().push_back( pMethod );
|
---|
[184] | 246 | }
|
---|
| 247 |
|
---|
| 248 | //仮想関数の数
|
---|
| 249 | AddVtblNum( inheritsClass.GetVtblNum() );
|
---|
| 250 |
|
---|
| 251 | //継承先のクラスをメンバとして保持する
|
---|
[204] | 252 | SetSuperClass( &inheritsClass );
|
---|
[299] | 253 | SetSuperClassActualTypeParameters( actualTypeParameters );
|
---|
[184] | 254 |
|
---|
[351] | 255 | // インターフェイスを引き継ぐ
|
---|
| 256 | BOOST_FOREACH( ::Interface *pInterface, inheritsClass.GetInterfaces() )
|
---|
| 257 | {
|
---|
| 258 | interfaces.push_back( new ::Interface( *pInterface ) );
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[370] | 261 | if( this->IsInterface() && inheritsClass.IsComInterface() )
|
---|
| 262 | {
|
---|
| 263 | // COMインターフェイスを継承した場合はCOMインターフェイスにする
|
---|
| 264 | this->SetClassType( CClass::ComInterface );
|
---|
[184] | 265 | }
|
---|
| 266 |
|
---|
| 267 | return true;
|
---|
| 268 | }
|
---|
[340] | 269 |
|
---|
[561] | 270 | void CClass::AddDynamicMember( Member *pMember )
|
---|
[184] | 271 | {
|
---|
[561] | 272 | dynamicMembers.push_back( pMember );
|
---|
[184] | 273 | }
|
---|
[561] | 274 | void CClass::AddStaticMember( Member *pMember )
|
---|
| 275 | {
|
---|
| 276 | staticMembers.push_back( pMember );
|
---|
[184] | 277 | }
|
---|
| 278 |
|
---|
[409] | 279 | bool CClass::DupliCheckAll(const char *name) const
|
---|
| 280 | {
|
---|
[206] | 281 | //重複チェック
|
---|
| 282 |
|
---|
| 283 | //メンバ
|
---|
| 284 | if(DupliCheckMember(name)) return 1;
|
---|
| 285 |
|
---|
| 286 | //メソッド
|
---|
[342] | 287 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
[206] | 288 | if( lstrcmp( name, pMethod->GetUserProc().GetName().c_str() ) == 0 ){
|
---|
| 289 | return 1;
|
---|
| 290 | }
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | return 0;
|
---|
| 294 | }
|
---|
[409] | 295 | bool CClass::DupliCheckMember(const char *name) const
|
---|
| 296 | {
|
---|
[206] | 297 | //重複チェック
|
---|
| 298 |
|
---|
[409] | 299 | if( this->HasSuperClass() )
|
---|
| 300 | {
|
---|
| 301 | if( this->GetSuperClass().DupliCheckMember( name ) )
|
---|
| 302 | {
|
---|
| 303 | // 基底クラスで重複が発見された
|
---|
| 304 | return true;
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[206] | 308 | // 動的メンバ
|
---|
[561] | 309 | BOOST_FOREACH( Member *pMember, dynamicMembers )
|
---|
[409] | 310 | {
|
---|
| 311 | if( GetName() == pMember->GetName() )
|
---|
| 312 | {
|
---|
| 313 | return true;
|
---|
[206] | 314 | }
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | // 静的メンバ
|
---|
[561] | 318 | BOOST_FOREACH( Member *pMember, staticMembers ){
|
---|
[206] | 319 | if( GetName() == pMember->GetName() ){
|
---|
[409] | 320 | return true;
|
---|
[206] | 321 | }
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[409] | 324 | return false;
|
---|
[206] | 325 | }
|
---|
| 326 |
|
---|
[561] | 327 | const Member *CClass::FindDynamicMember( const char *memberName ) const
|
---|
[409] | 328 | {
|
---|
| 329 | if( this->HasSuperClass() )
|
---|
| 330 | {
|
---|
| 331 | // 基底クラスで検索
|
---|
[561] | 332 | const Member *result = this->GetSuperClass().FindDynamicMember( memberName );
|
---|
[409] | 333 | if( result )
|
---|
| 334 | {
|
---|
| 335 | return result;
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
[561] | 339 | BOOST_FOREACH( Member *pMember, GetDynamicMembers() )
|
---|
[409] | 340 | {
|
---|
| 341 | if( pMember->GetName() == memberName )
|
---|
| 342 | {
|
---|
| 343 | return pMember;
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 | return NULL;
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[350] | 349 | void CClass::EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const
|
---|
[347] | 350 | {
|
---|
| 351 | // 動的メソッド
|
---|
| 352 | GetDynamicMethods().Enum( methodName, subs );
|
---|
| 353 |
|
---|
| 354 | // インターフェイス メソッド
|
---|
| 355 | BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
|
---|
| 356 | {
|
---|
| 357 | pInterface->GetDynamicMethods().Enum( methodName, subs );
|
---|
| 358 | }
|
---|
| 359 | }
|
---|
[350] | 360 | const CMethod *CClass::GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const
|
---|
[347] | 361 | {
|
---|
| 362 | // 動的メソッド
|
---|
| 363 | const CMethod *result = GetDynamicMethods().GetMethodPtr( pUserProc );
|
---|
| 364 |
|
---|
| 365 | if( !result )
|
---|
| 366 | {
|
---|
| 367 | // インターフェイス メソッド
|
---|
| 368 | BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
|
---|
| 369 | {
|
---|
| 370 | result = pInterface->GetDynamicMethods().GetMethodPtr( pUserProc );
|
---|
[350] | 371 | if( result )
|
---|
| 372 | {
|
---|
| 373 | return result;
|
---|
| 374 | }
|
---|
[347] | 375 | }
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | return result;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[206] | 381 | //サイズを取得
|
---|
| 382 | int CClass::GetSize() const
|
---|
[184] | 383 | {
|
---|
[409] | 384 | int resultSize = 0;
|
---|
| 385 |
|
---|
| 386 | int alignment = 1;
|
---|
| 387 | if( this->IsStructure() )
|
---|
| 388 | {
|
---|
| 389 | // 構造体のとき
|
---|
| 390 |
|
---|
| 391 | if( this->GetFixedAlignment() )
|
---|
| 392 | {
|
---|
| 393 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 394 | alignment = this->GetFixedAlignment();
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 | else
|
---|
| 398 | {
|
---|
| 399 | // それ以外
|
---|
| 400 |
|
---|
| 401 | if( this->HasSuperClass() )
|
---|
| 402 | {
|
---|
| 403 | // 基底クラスのサイズを追加
|
---|
| 404 | resultSize += this->GetSuperClass().GetSize();
|
---|
| 405 |
|
---|
| 406 | // 基底クラスのアラインメントを取得
|
---|
| 407 | alignment = this->GetSuperClass().GetAlignment();
|
---|
| 408 | }
|
---|
| 409 | else
|
---|
| 410 | {
|
---|
| 411 | // 基底クラスが存在しないとき
|
---|
| 412 |
|
---|
| 413 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 414 | resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
|
---|
| 415 | }
|
---|
| 416 | }
|
---|
| 417 |
|
---|
[561] | 418 | BOOST_FOREACH( Member *pMember, dynamicMembers )
|
---|
[409] | 419 | {
|
---|
| 420 | // メンバサイズ
|
---|
| 421 | int tempMemberSize = pMember->GetType().GetSize();
|
---|
| 422 |
|
---|
| 423 | // 一時アラインメントを算出
|
---|
| 424 | int tempAlignment = tempMemberSize;
|
---|
| 425 | if( pMember->GetType().IsStruct() )
|
---|
| 426 | {
|
---|
| 427 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 428 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | // アラインメントを考慮してパディングを追加
|
---|
| 432 | if( GetFixedAlignment() && alignment < tempAlignment )
|
---|
| 433 | {
|
---|
| 434 | if( resultSize % alignment )
|
---|
| 435 | {
|
---|
| 436 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 | else
|
---|
| 440 | {
|
---|
| 441 | if( alignment < tempAlignment )
|
---|
| 442 | {
|
---|
| 443 | // 最大アラインメントを更新
|
---|
| 444 | alignment = tempAlignment;
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | if( tempMemberSize == 0 )
|
---|
| 448 | {
|
---|
| 449 | if( !pMember->GetType().IsStruct() )
|
---|
| 450 | {
|
---|
[563] | 451 | throw;
|
---|
[409] | 452 | }
|
---|
| 453 |
|
---|
| 454 | //メンバを持たない構造体
|
---|
| 455 | //※何もしない(オフセットの計算をしない)
|
---|
| 456 | }
|
---|
| 457 | else{
|
---|
| 458 | if( resultSize % tempAlignment )
|
---|
| 459 | {
|
---|
| 460 | resultSize += tempAlignment - ( resultSize % tempAlignment );
|
---|
| 461 | }
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | // メンバサイズを加算(配列を考慮)
|
---|
| 466 | resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | if( alignment )
|
---|
| 470 | {
|
---|
| 471 | // 末尾アラインメントを考慮してパディングを追加
|
---|
| 472 | if( resultSize % alignment )
|
---|
| 473 | {
|
---|
| 474 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 475 | }
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | return resultSize;
|
---|
[206] | 479 | }
|
---|
[184] | 480 |
|
---|
[206] | 481 | //メンバのオフセットを取得
|
---|
[409] | 482 | int CClass::GetMemberOffset( const char *memberName ) const
|
---|
[206] | 483 | {
|
---|
[409] | 484 | int resultSize = 0;
|
---|
[206] | 485 |
|
---|
[232] | 486 | int alignment = 1;
|
---|
[409] | 487 | if( this->IsStructure() )
|
---|
[232] | 488 | {
|
---|
[409] | 489 | // 構造体のとき
|
---|
| 490 |
|
---|
| 491 | if( this->GetFixedAlignment() )
|
---|
| 492 | {
|
---|
| 493 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 494 | alignment = this->GetFixedAlignment();
|
---|
| 495 | }
|
---|
[232] | 496 | }
|
---|
[409] | 497 | else
|
---|
| 498 | {
|
---|
| 499 | // それ以外
|
---|
[206] | 500 |
|
---|
[409] | 501 | if( this->HasSuperClass() )
|
---|
| 502 | {
|
---|
| 503 | if( this->GetSuperClass().HasDynamicMember( memberName ) )
|
---|
| 504 | {
|
---|
| 505 | // 基底クラスのメンバを取得
|
---|
| 506 | return this->GetSuperClass().GetMemberOffset( memberName );
|
---|
| 507 | }
|
---|
[206] | 508 |
|
---|
[409] | 509 | // 基底クラスのサイズを追加
|
---|
| 510 | resultSize += this->GetSuperClass().GetSize();
|
---|
[206] | 511 |
|
---|
[409] | 512 | // 基底クラスのアラインメントを取得
|
---|
| 513 | alignment = this->GetSuperClass().GetAlignment();
|
---|
[206] | 514 | }
|
---|
[409] | 515 | else
|
---|
| 516 | {
|
---|
| 517 | // 基底クラスが存在しないとき
|
---|
| 518 |
|
---|
| 519 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 520 | resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
|
---|
[206] | 521 | }
|
---|
[409] | 522 | }
|
---|
[206] | 523 |
|
---|
[561] | 524 | BOOST_FOREACH( Member *pMember, dynamicMembers )
|
---|
[409] | 525 | {
|
---|
| 526 | // メンバサイズ
|
---|
| 527 | int tempMemberSize = pMember->GetType().GetSize();
|
---|
| 528 |
|
---|
| 529 | // 一時アラインメントを算出
|
---|
| 530 | int tempAlignment = tempMemberSize;
|
---|
| 531 | if( pMember->GetType().IsStruct() )
|
---|
| 532 | {
|
---|
| 533 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 534 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
[206] | 535 | }
|
---|
| 536 |
|
---|
[409] | 537 | // アラインメントを考慮してパディングを追加
|
---|
| 538 | if( GetFixedAlignment() && alignment < tempAlignment )
|
---|
| 539 | {
|
---|
| 540 | if( resultSize % alignment )
|
---|
| 541 | {
|
---|
| 542 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
| 545 | else
|
---|
| 546 | {
|
---|
| 547 | if( alignment < tempAlignment )
|
---|
| 548 | {
|
---|
| 549 | // 最大アラインメントを更新
|
---|
| 550 | alignment = tempAlignment;
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | if( tempMemberSize == 0 )
|
---|
| 554 | {
|
---|
| 555 | if( !pMember->GetType().IsStruct() )
|
---|
| 556 | {
|
---|
[563] | 557 | throw;
|
---|
[409] | 558 | }
|
---|
| 559 |
|
---|
| 560 | //メンバを持たない構造体
|
---|
[206] | 561 | //※何もしない(オフセットの計算をしない)
|
---|
| 562 | }
|
---|
| 563 | else{
|
---|
[409] | 564 | if( resultSize % tempAlignment )
|
---|
| 565 | {
|
---|
| 566 | resultSize += tempAlignment - ( resultSize % tempAlignment );
|
---|
| 567 | }
|
---|
[206] | 568 | }
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | if(memberName){
|
---|
| 572 | //メンバ指定がある場合は、オフセットを返す
|
---|
[409] | 573 | if( pMember->GetName() == memberName )
|
---|
| 574 | {
|
---|
| 575 | return resultSize;
|
---|
[206] | 576 | }
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[409] | 579 | // メンバサイズを加算(配列を考慮)
|
---|
| 580 | resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
|
---|
[206] | 581 | }
|
---|
| 582 |
|
---|
[409] | 583 | if( alignment )
|
---|
| 584 | {
|
---|
| 585 | // 末尾アラインメントを考慮してパディングを追加
|
---|
| 586 | if( resultSize % alignment )
|
---|
| 587 | {
|
---|
| 588 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 589 | }
|
---|
[206] | 590 | }
|
---|
| 591 |
|
---|
[409] | 592 | return resultSize;
|
---|
[206] | 593 | }
|
---|
| 594 | int CClass::GetAlignment() const
|
---|
| 595 | {
|
---|
[409] | 596 | int alignment = 1;
|
---|
| 597 | if( this->IsStructure() )
|
---|
| 598 | {
|
---|
| 599 | // 構造体のとき
|
---|
[206] | 600 |
|
---|
[409] | 601 | if( this->GetFixedAlignment() )
|
---|
| 602 | {
|
---|
| 603 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 604 | return this->GetFixedAlignment();
|
---|
[206] | 605 | }
|
---|
[409] | 606 | }
|
---|
| 607 | else
|
---|
| 608 | {
|
---|
| 609 | // それ以外
|
---|
| 610 |
|
---|
| 611 | if( this->HasSuperClass() )
|
---|
| 612 | {
|
---|
| 613 | // 基底クラスのアラインメントを取得
|
---|
| 614 | alignment = this->GetSuperClass().GetAlignment();
|
---|
[206] | 615 | }
|
---|
[409] | 616 | else
|
---|
| 617 | {
|
---|
| 618 | // 基底クラスが存在しないとき
|
---|
[206] | 619 |
|
---|
[409] | 620 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 621 | alignment = PTR_SIZE;
|
---|
| 622 | }
|
---|
[206] | 623 | }
|
---|
| 624 |
|
---|
[561] | 625 | BOOST_FOREACH( Member *pMember, dynamicMembers )
|
---|
[409] | 626 | {
|
---|
| 627 | int tempAlignment = pMember->GetType().GetSize();
|
---|
| 628 | if( pMember->GetType().IsStruct() )
|
---|
| 629 | {
|
---|
| 630 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 631 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
| 632 | }
|
---|
[206] | 633 |
|
---|
[409] | 634 | if( alignment < tempAlignment )
|
---|
| 635 | {
|
---|
| 636 | // 最大アラインメントを更新
|
---|
| 637 | alignment = tempAlignment;
|
---|
| 638 | }
|
---|
| 639 | }
|
---|
[206] | 640 |
|
---|
| 641 | return alignment;
|
---|
| 642 | }
|
---|
[342] | 643 |
|
---|
[348] | 644 | void CClass::GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const
|
---|
[342] | 645 | {
|
---|
[348] | 646 | vtblMasterListIndex = 0;
|
---|
| 647 |
|
---|
| 648 | vtblIndex = 0;
|
---|
[342] | 649 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
| 650 | if( &pMethod->GetUserProc() == pUserProc )
|
---|
| 651 | {
|
---|
[348] | 652 | return;
|
---|
[342] | 653 | }
|
---|
[348] | 654 |
|
---|
| 655 | if( pMethod->IsVirtual() )
|
---|
| 656 | {
|
---|
| 657 | vtblIndex++;
|
---|
| 658 | }
|
---|
[342] | 659 | }
|
---|
| 660 |
|
---|
[346] | 661 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
[342] | 662 | {
|
---|
[348] | 663 | vtblMasterListIndex++;
|
---|
[342] | 664 |
|
---|
[348] | 665 | vtblIndex = 0;
|
---|
[347] | 666 | BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
|
---|
[342] | 667 | if( &pMethod->GetUserProc() == pUserProc )
|
---|
| 668 | {
|
---|
[348] | 669 | return;
|
---|
[342] | 670 | }
|
---|
[348] | 671 |
|
---|
| 672 | if( pMethod->IsVirtual() )
|
---|
| 673 | {
|
---|
| 674 | vtblIndex++;
|
---|
| 675 | }
|
---|
[342] | 676 | }
|
---|
| 677 | }
|
---|
| 678 |
|
---|
[636] | 679 | _ASSERT( false );
|
---|
[563] | 680 | throw;
|
---|
[342] | 681 | }
|
---|
[350] | 682 | int CClass::GetVtblMasterListIndex( const CClass *pClass ) const
|
---|
| 683 | {
|
---|
| 684 | int result = 0;
|
---|
| 685 |
|
---|
| 686 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
| 687 | {
|
---|
| 688 | result++;
|
---|
| 689 |
|
---|
| 690 | if( &pInterface->GetClass() == pClass )
|
---|
| 691 | {
|
---|
| 692 | return result;
|
---|
| 693 | }
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[636] | 696 | _ASSERT( false );
|
---|
[563] | 697 | throw;
|
---|
[350] | 698 | }
|
---|
[345] | 699 | long CClass::GetVtblMasterListOffset() const
|
---|
[206] | 700 | {
|
---|
[342] | 701 | if( vtblMasterListOffset == -1 )
|
---|
| 702 | {
|
---|
[636] | 703 | _ASSERT( false );
|
---|
[563] | 704 | throw;
|
---|
[342] | 705 | }
|
---|
[184] | 706 |
|
---|
[342] | 707 | return vtblMasterListOffset;
|
---|
| 708 | }
|
---|
[206] | 709 | bool CClass::IsAbstract() const
|
---|
| 710 | {
|
---|
| 711 | // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
|
---|
[184] | 712 |
|
---|
[342] | 713 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
[206] | 714 | if(pMethod->IsVirtual()){
|
---|
| 715 | if(pMethod->IsAbstract()){
|
---|
| 716 | return true;
|
---|
| 717 | }
|
---|
| 718 | }
|
---|
| 719 | }
|
---|
| 720 |
|
---|
[351] | 721 | // インターフェイスのvtbl
|
---|
| 722 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
| 723 | {
|
---|
| 724 | BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
|
---|
| 725 | if(pMethod->IsVirtual()){
|
---|
| 726 | if(pMethod->IsAbstract()){
|
---|
| 727 | return true;
|
---|
| 728 | }
|
---|
| 729 | }
|
---|
| 730 | }
|
---|
| 731 | }
|
---|
| 732 |
|
---|
[206] | 733 | return false;
|
---|
[184] | 734 | }
|
---|
| 735 |
|
---|
[598] | 736 | const CClass *Classes::FindEx( const Symbol &symbol ) const
|
---|
[193] | 737 | {
|
---|
[598] | 738 | if( symbol.GetNamespaceScopes().size() == 0 && symbol.GetName() == "Object" )
|
---|
[566] | 739 | {
|
---|
[193] | 740 | return GetObjectClassPtr();
|
---|
| 741 | }
|
---|
[598] | 742 | else if( symbol.GetNamespaceScopes().size() == 0 && symbol.GetName() == "String" )
|
---|
[566] | 743 | {
|
---|
[193] | 744 | return GetStringClassPtr();
|
---|
| 745 | }
|
---|
| 746 |
|
---|
[380] | 747 | std::vector<const CClass *> classes;
|
---|
[598] | 748 | const CClass *pClass = GetHashArrayElement( symbol.GetName().c_str() );
|
---|
[270] | 749 | while( pClass )
|
---|
| 750 | {
|
---|
[598] | 751 | if( pClass->IsEqualSymbol( symbol.GetNamespaceScopes(), symbol.GetName() ) ){
|
---|
[270] | 752 | //名前空間とクラス名が一致した
|
---|
[380] | 753 | classes.push_back( pClass );
|
---|
[193] | 754 | }
|
---|
[270] | 755 | pClass = pClass->GetChainNext();
|
---|
[193] | 756 | }
|
---|
[380] | 757 | if( classes.size() > 0 )
|
---|
| 758 | {
|
---|
| 759 | // 複数の名前空間の中に同一のクラス名が存在する場合があるので、アクセス可能で尚且つ階層が一番深いものをチョイスする
|
---|
| 760 | pClass = classes.front();
|
---|
[193] | 761 |
|
---|
[380] | 762 | BOOST_FOREACH( const CClass *pTempClass, classes )
|
---|
| 763 | {
|
---|
| 764 | if( pClass->GetNamespaceScopes().size() < pTempClass->GetNamespaceScopes().size() )
|
---|
| 765 | {
|
---|
| 766 | pClass = pTempClass;
|
---|
| 767 | }
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | return pClass;
|
---|
| 771 | }
|
---|
| 772 |
|
---|
[193] | 773 | return NULL;
|
---|
| 774 | }
|
---|
[206] | 775 |
|
---|
[272] | 776 | const CClass *Classes::GetStringClassPtr() const
|
---|
[206] | 777 | {
|
---|
[567] | 778 | if( !pStringClass )
|
---|
| 779 | {
|
---|
[272] | 780 | // キャッシュしておく
|
---|
[598] | 781 | pStringClass = this->FindEx( Symbol( NamespaceScopes( "System" ), "String" ) );
|
---|
[206] | 782 | }
|
---|
| 783 | return pStringClass;
|
---|
| 784 | }
|
---|
[272] | 785 | const CClass *Classes::GetObjectClassPtr() const
|
---|
[206] | 786 | {
|
---|
[567] | 787 | if( !pObjectClass )
|
---|
| 788 | {
|
---|
[272] | 789 | // キャッシュしておく
|
---|
[598] | 790 | pObjectClass = this->FindEx( Symbol( NamespaceScopes( "System" ), "Object" ) );
|
---|
[206] | 791 | }
|
---|
| 792 | return pObjectClass;
|
---|
| 793 | }
|
---|
[349] | 794 | const CClass *Classes::GetInterfaceInfoClassPtr() const
|
---|
| 795 | {
|
---|
[567] | 796 | if( !pInterfaceInfo )
|
---|
| 797 | {
|
---|
[349] | 798 | // キャッシュしておく
|
---|
[598] | 799 | pInterfaceInfo = this->FindEx( Symbol( NamespaceScopes( "ActiveBasic.Core" ), "InterfaceInfo" ) );
|
---|
[349] | 800 | }
|
---|
| 801 | return pInterfaceInfo;
|
---|
| 802 | }
|
---|
[387] | 803 |
|
---|
| 804 | std::string CClass::GetStaticDefiningStringAsMemberNames() const
|
---|
| 805 | {
|
---|
| 806 | std::string result;
|
---|
| 807 |
|
---|
[561] | 808 | BOOST_FOREACH( const Member *pMember, dynamicMembers )
|
---|
[387] | 809 | {
|
---|
| 810 | if( result.size() )
|
---|
| 811 | {
|
---|
| 812 | result += ",";
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | result += "\"" + pMember->GetName() + "\"";
|
---|
| 816 | }
|
---|
| 817 |
|
---|
| 818 | return result;
|
---|
| 819 | }
|
---|
[412] | 820 | std::string CClass::GetStaticDefiningStringAsMemberOffsets() const
|
---|
| 821 | {
|
---|
| 822 | std::string result;
|
---|
[387] | 823 |
|
---|
[561] | 824 | BOOST_FOREACH( const Member *pMember, dynamicMembers )
|
---|
[412] | 825 | {
|
---|
| 826 | if( result.size() )
|
---|
| 827 | {
|
---|
| 828 | result += ",";
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | int offset = this->GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 832 |
|
---|
| 833 | char temporary[255];
|
---|
| 834 | itoa( offset, temporary, 16 );
|
---|
| 835 |
|
---|
| 836 | result += (std::string)"&H" + temporary;
|
---|
| 837 | }
|
---|
| 838 |
|
---|
| 839 | return result;
|
---|
| 840 | }
|
---|
[417] | 841 |
|
---|
| 842 | void CClass::GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset ) const
|
---|
| 843 | {
|
---|
| 844 | const CClass &thisClass = *this;
|
---|
[561] | 845 | BOOST_FOREACH( const Member *pMember, thisClass.GetDynamicMembers() )
|
---|
[417] | 846 | {
|
---|
| 847 | if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() )
|
---|
| 848 | {
|
---|
| 849 | if( referenceOffsetsBuffer.size() )
|
---|
| 850 | {
|
---|
| 851 | referenceOffsetsBuffer += ",";
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | char temp[255];
|
---|
| 855 | sprintf( temp, "%d", baseOffset + thisClass.GetMemberOffset( pMember->GetName().c_str() ) );
|
---|
| 856 | referenceOffsetsBuffer += temp;
|
---|
| 857 |
|
---|
| 858 | numOfReference++;
|
---|
| 859 | }
|
---|
| 860 | if( pMember->GetType().IsStruct() && !pMember->GetType().IsPointer() )
|
---|
| 861 | {
|
---|
| 862 | // 構造体の実体をメンバに持つとき
|
---|
| 863 | int baseOffset = thisClass.GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 864 |
|
---|
| 865 | // 構造体メンバでGCによるチェックが必要な参照位置を追加
|
---|
| 866 | pMember->GetType().GetClass().GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference, baseOffset );
|
---|
| 867 | }
|
---|
| 868 | }
|
---|
| 869 | }
|
---|
[637] | 870 |
|
---|
[640] | 871 | bool CClass::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 872 | {
|
---|
[639] | 873 | // 型パラメータ
|
---|
| 874 | BOOST_FOREACH( GenericType &genericType, formalGenericTypes )
|
---|
| 875 | {
|
---|
[640] | 876 | genericType.GetType().Resolve( resolver, resolveErrors );
|
---|
[639] | 877 | }
|
---|
| 878 |
|
---|
| 879 | // 基底クラス
|
---|
| 880 | if( this->pSuperClass )
|
---|
| 881 | {
|
---|
| 882 | if( this->pSuperClass->IsNeedResolve() )
|
---|
| 883 | {
|
---|
[640] | 884 | const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pSuperClass );
|
---|
| 885 | if( pTempClass )
|
---|
| 886 | {
|
---|
| 887 | this->pSuperClass = pTempClass;
|
---|
| 888 | }
|
---|
| 889 | else
|
---|
| 890 | {
|
---|
| 891 | resolveErrors.Add( ResolveError( this->pSuperClass->GetRelationalObjectModuleIndex(), this->pSuperClass->GetFullName() ) );
|
---|
| 892 | }
|
---|
[639] | 893 | }
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | // 基底クラスの型パラメータ(実パラメータ)
|
---|
| 897 | BOOST_FOREACH( Type &superClassActualTypeParameter, superClassActualTypeParameters )
|
---|
| 898 | {
|
---|
[640] | 899 | superClassActualTypeParameter.Resolve( resolver, resolveErrors );
|
---|
[639] | 900 | }
|
---|
| 901 |
|
---|
| 902 | // Blittable型情報
|
---|
[640] | 903 | blittableType.Resolve( resolver, resolveErrors );
|
---|
[639] | 904 |
|
---|
| 905 | // 実装するインターフェイス
|
---|
| 906 | BOOST_FOREACH( ::Interface *pInterface, interfaces )
|
---|
| 907 | {
|
---|
[640] | 908 | pInterface->Resolve( resolver, resolveErrors );
|
---|
[639] | 909 | }
|
---|
| 910 |
|
---|
| 911 | // 動的メンバ
|
---|
| 912 | BOOST_FOREACH( Member *pMember, dynamicMembers )
|
---|
| 913 | {
|
---|
[640] | 914 | pMember->Resolve( resolver, resolveErrors );
|
---|
[639] | 915 | }
|
---|
| 916 |
|
---|
| 917 | // 静的メンバ
|
---|
| 918 | BOOST_FOREACH( Member *pMember, staticMembers )
|
---|
| 919 | {
|
---|
[640] | 920 | pMember->Resolve( resolver, resolveErrors );
|
---|
[639] | 921 | }
|
---|
| 922 |
|
---|
| 923 | // 動的メソッド
|
---|
| 924 | BOOST_FOREACH( CMethod *pMethod, GetDynamicMethods() )
|
---|
| 925 | {
|
---|
[640] | 926 | pMethod->Resolve( resolver, resolveErrors );
|
---|
[639] | 927 | }
|
---|
| 928 |
|
---|
| 929 | // 静的メソッド
|
---|
| 930 | BOOST_FOREACH( CMethod *pMethod, staticMethods )
|
---|
| 931 | {
|
---|
[640] | 932 | pMethod->Resolve( resolver, resolveErrors );
|
---|
[639] | 933 | }
|
---|
| 934 |
|
---|
| 935 | // テンプレート展開後のクラス
|
---|
| 936 | BOOST_FOREACH( ActiveBasic::Common::Lexical::ExpandedTemplateClass *pExpandedTemplateClass, expandedTemplateClasses )
|
---|
| 937 | {
|
---|
[640] | 938 | pExpandedTemplateClass->Resolve( resolver, resolveErrors );
|
---|
[639] | 939 | }
|
---|
| 940 |
|
---|
[637] | 941 | return true;
|
---|
| 942 | }
|
---|