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