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