[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 |
|
---|
[558] | 187 | void CClass::Implements( const CClass &interfaceClass, const Types &actualTypeParameters, std::vector<DynamicMethod::OverrideResult> &overrideResults )
|
---|
[342] | 188 | {
|
---|
[376] | 189 | ::Interface *pDestInterface = new ::Interface( &interfaceClass, actualTypeParameters );
|
---|
[342] | 190 |
|
---|
[351] | 191 | interfaces.push_back( pDestInterface );
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /////////////////////////////////////////////////////////////////
|
---|
[352] | 195 | // 基底クラスのメソッドからインターフェイスメソッドを再実装する
|
---|
[351] | 196 | /////////////////////////////////////////////////////////////////
|
---|
| 197 | BOOST_FOREACH( CMethod *pMethod, GetDynamicMethods() )
|
---|
| 198 | {
|
---|
[558] | 199 | DynamicMethod *pMethodForOverride = pDestInterface->GetDynamicMethods().FindForOverride( pDestInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
|
---|
[351] | 200 | if( pMethodForOverride )
|
---|
| 201 | {
|
---|
[558] | 202 | DynamicMethod::OverrideResult result;
|
---|
| 203 | result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
|
---|
| 204 | result.pMethod = pMethod;
|
---|
| 205 | overrideResults.push_back( result );
|
---|
[352] | 206 |
|
---|
| 207 | // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
|
---|
| 208 | pMethod->SetNotUseMark( true );
|
---|
[351] | 209 | }
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | /////////////////////////////////////////////////////////////////
|
---|
[350] | 214 | // キャストメソッドを追加(内部コードは自動生成すること)
|
---|
[351] | 215 | /////////////////////////////////////////////////////////////////
|
---|
[370] | 216 | if( interfaceClass.IsInterface() )
|
---|
[350] | 217 | {
|
---|
| 218 | // Function Operator() As ITest
|
---|
| 219 |
|
---|
[511] | 220 | char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' };
|
---|
[350] | 221 |
|
---|
[511] | 222 | //関数ハッシュへ登録
|
---|
| 223 | UserProc *pUserProc = new UserProc(
|
---|
| 224 | NamespaceScopes(),
|
---|
| 225 | NamespaceScopesCollection(),
|
---|
| 226 | methodName,
|
---|
| 227 | Procedure::Function,
|
---|
| 228 | false,
|
---|
| 229 | false,
|
---|
| 230 | false );
|
---|
| 231 | pUserProc->SetParentClass( this );
|
---|
| 232 |
|
---|
| 233 | Parameters params;
|
---|
| 234 | params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
|
---|
| 235 | pUserProc->SetRealParams( params );
|
---|
| 236 |
|
---|
| 237 | pUserProc->SetReturnType( Type( DEF_OBJECT, interfaceClass ) );
|
---|
| 238 | pUserProc->_paramStr = "";
|
---|
| 239 | pUserProc->Using();
|
---|
| 240 | compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, -1 );
|
---|
| 241 |
|
---|
| 242 | LexicalAnalyzer::AddMethod(this,
|
---|
| 243 | pUserProc,
|
---|
[350] | 244 | Prototype::Public,
|
---|
| 245 | 0,
|
---|
| 246 | false, // isConst
|
---|
| 247 | false, // isAbstract
|
---|
| 248 | false, // isVirtual
|
---|
| 249 | false, // isOverride
|
---|
[511] | 250 | "",
|
---|
[350] | 251 | true, // isAutoGeneration
|
---|
| 252 | -1
|
---|
| 253 | );
|
---|
| 254 | }
|
---|
[342] | 255 | }
|
---|
[375] | 256 |
|
---|
[206] | 257 | CMember *CClass::CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine )
|
---|
[184] | 258 | {
|
---|
| 259 | extern int cp;
|
---|
| 260 |
|
---|
| 261 | //構文を解析
|
---|
| 262 | char VarName[VN_SIZE];
|
---|
| 263 | char initBuffer[VN_SIZE];
|
---|
| 264 | char lpszConstructParameter[VN_SIZE];
|
---|
[206] | 265 | Subscripts subscripts;
|
---|
[184] | 266 | Type type;
|
---|
[206] | 267 | GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter);
|
---|
[184] | 268 |
|
---|
| 269 | //重複チェック
|
---|
| 270 | if(this->DupliCheckAll(VarName)){
|
---|
[465] | 271 | compiler.errorMessenger.Output(15,VarName,cp);
|
---|
[184] | 272 | }
|
---|
| 273 |
|
---|
[206] | 274 | CMember *pMember = new CMember( accessibility, VarName, type, isConst, subscripts, initBuffer, lpszConstructParameter );
|
---|
[184] | 275 | pMember->source_code_address = nowLine;
|
---|
| 276 | return pMember;
|
---|
| 277 | }
|
---|
[206] | 278 | void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
|
---|
[184] | 279 | dynamicMembers.push_back(
|
---|
| 280 | CreateMember( accessibility, isConst, isRef, buffer, nowLine )
|
---|
| 281 | );
|
---|
| 282 | }
|
---|
[206] | 283 | void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
|
---|
[184] | 284 | staticMembers.push_back(
|
---|
| 285 | CreateMember( accessibility, isConst, isRef, buffer, nowLine )
|
---|
| 286 | );
|
---|
| 287 | }
|
---|
| 288 |
|
---|
[409] | 289 | bool CClass::DupliCheckAll(const char *name) const
|
---|
| 290 | {
|
---|
[206] | 291 | //重複チェック
|
---|
| 292 |
|
---|
| 293 | //メンバ
|
---|
| 294 | if(DupliCheckMember(name)) return 1;
|
---|
| 295 |
|
---|
| 296 | //メソッド
|
---|
[342] | 297 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
[206] | 298 | if( lstrcmp( name, pMethod->GetUserProc().GetName().c_str() ) == 0 ){
|
---|
| 299 | return 1;
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | return 0;
|
---|
| 304 | }
|
---|
[409] | 305 | bool CClass::DupliCheckMember(const char *name) const
|
---|
| 306 | {
|
---|
[206] | 307 | //重複チェック
|
---|
| 308 |
|
---|
[409] | 309 | if( this->HasSuperClass() )
|
---|
| 310 | {
|
---|
| 311 | if( this->GetSuperClass().DupliCheckMember( name ) )
|
---|
| 312 | {
|
---|
| 313 | // 基底クラスで重複が発見された
|
---|
| 314 | return true;
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[206] | 318 | // 動的メンバ
|
---|
[409] | 319 | BOOST_FOREACH( CMember *pMember, dynamicMembers )
|
---|
| 320 | {
|
---|
| 321 | if( GetName() == pMember->GetName() )
|
---|
| 322 | {
|
---|
| 323 | return true;
|
---|
[206] | 324 | }
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | // 静的メンバ
|
---|
| 328 | BOOST_FOREACH( CMember *pMember, staticMembers ){
|
---|
| 329 | if( GetName() == pMember->GetName() ){
|
---|
[409] | 330 | return true;
|
---|
[206] | 331 | }
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[409] | 334 | return false;
|
---|
[206] | 335 | }
|
---|
| 336 |
|
---|
[409] | 337 | const CMember *CClass::FindDynamicMember( const char *memberName ) const
|
---|
| 338 | {
|
---|
| 339 | if( this->HasSuperClass() )
|
---|
| 340 | {
|
---|
| 341 | // 基底クラスで検索
|
---|
| 342 | const CMember *result = this->GetSuperClass().FindDynamicMember( memberName );
|
---|
| 343 | if( result )
|
---|
| 344 | {
|
---|
| 345 | return result;
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | BOOST_FOREACH( CMember *pMember, GetDynamicMembers() )
|
---|
| 350 | {
|
---|
| 351 | if( pMember->GetName() == memberName )
|
---|
| 352 | {
|
---|
| 353 | return pMember;
|
---|
| 354 | }
|
---|
| 355 | }
|
---|
| 356 | return NULL;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
[350] | 359 | void CClass::EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const
|
---|
[347] | 360 | {
|
---|
| 361 | // 動的メソッド
|
---|
| 362 | GetDynamicMethods().Enum( methodName, subs );
|
---|
| 363 |
|
---|
| 364 | // インターフェイス メソッド
|
---|
| 365 | BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
|
---|
| 366 | {
|
---|
| 367 | pInterface->GetDynamicMethods().Enum( methodName, subs );
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
[350] | 370 | const CMethod *CClass::GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const
|
---|
[347] | 371 | {
|
---|
| 372 | // 動的メソッド
|
---|
| 373 | const CMethod *result = GetDynamicMethods().GetMethodPtr( pUserProc );
|
---|
| 374 |
|
---|
| 375 | if( !result )
|
---|
| 376 | {
|
---|
| 377 | // インターフェイス メソッド
|
---|
| 378 | BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
|
---|
| 379 | {
|
---|
| 380 | result = pInterface->GetDynamicMethods().GetMethodPtr( pUserProc );
|
---|
[350] | 381 | if( result )
|
---|
| 382 | {
|
---|
| 383 | return result;
|
---|
| 384 | }
|
---|
[347] | 385 | }
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | return result;
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[325] | 391 | const ::Delegate &CClass::GetDelegate() const
|
---|
| 392 | {
|
---|
| 393 | const ::Delegate *dg = compiler.GetObjectModule().meta.GetDelegates().GetHashArrayElement( GetName().c_str() );
|
---|
| 394 | while( dg )
|
---|
| 395 | {
|
---|
| 396 | if( dg->IsEqualSymbol( GetNamespaceScopes(), GetName() ) ){
|
---|
| 397 | //名前空間とクラス名が一致した
|
---|
| 398 | return *dg;
|
---|
| 399 | }
|
---|
| 400 | dg = dg->GetChainNext();
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | Jenga::Throw( "CClass::GetDelegateメソッドに失敗" );
|
---|
| 404 | static ::Delegate dummy;
|
---|
| 405 | return dummy;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
[206] | 408 | //サイズを取得
|
---|
| 409 | int CClass::GetSize() const
|
---|
[184] | 410 | {
|
---|
[409] | 411 | int resultSize = 0;
|
---|
| 412 |
|
---|
| 413 | int alignment = 1;
|
---|
| 414 | if( this->IsStructure() )
|
---|
| 415 | {
|
---|
| 416 | // 構造体のとき
|
---|
| 417 |
|
---|
| 418 | if( this->GetFixedAlignment() )
|
---|
| 419 | {
|
---|
| 420 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 421 | alignment = this->GetFixedAlignment();
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 | else
|
---|
| 425 | {
|
---|
| 426 | // それ以外
|
---|
| 427 |
|
---|
| 428 | if( this->HasSuperClass() )
|
---|
| 429 | {
|
---|
| 430 | // 基底クラスのサイズを追加
|
---|
| 431 | resultSize += this->GetSuperClass().GetSize();
|
---|
| 432 |
|
---|
| 433 | // 基底クラスのアラインメントを取得
|
---|
| 434 | alignment = this->GetSuperClass().GetAlignment();
|
---|
| 435 | }
|
---|
| 436 | else
|
---|
| 437 | {
|
---|
| 438 | // 基底クラスが存在しないとき
|
---|
| 439 |
|
---|
| 440 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 441 | resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | BOOST_FOREACH( CMember *pMember, dynamicMembers )
|
---|
| 446 | {
|
---|
| 447 | // メンバサイズ
|
---|
| 448 | int tempMemberSize = pMember->GetType().GetSize();
|
---|
| 449 |
|
---|
| 450 | // 一時アラインメントを算出
|
---|
| 451 | int tempAlignment = tempMemberSize;
|
---|
| 452 | if( pMember->GetType().IsStruct() )
|
---|
| 453 | {
|
---|
| 454 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 455 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | // アラインメントを考慮してパディングを追加
|
---|
| 459 | if( GetFixedAlignment() && alignment < tempAlignment )
|
---|
| 460 | {
|
---|
| 461 | if( resultSize % alignment )
|
---|
| 462 | {
|
---|
| 463 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 464 | }
|
---|
| 465 | }
|
---|
| 466 | else
|
---|
| 467 | {
|
---|
| 468 | if( alignment < tempAlignment )
|
---|
| 469 | {
|
---|
| 470 | // 最大アラインメントを更新
|
---|
| 471 | alignment = tempAlignment;
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if( tempMemberSize == 0 )
|
---|
| 475 | {
|
---|
| 476 | if( !pMember->GetType().IsStruct() )
|
---|
| 477 | {
|
---|
[465] | 478 | compiler.errorMessenger.OutputFatalError();
|
---|
[409] | 479 | }
|
---|
| 480 |
|
---|
| 481 | //メンバを持たない構造体
|
---|
| 482 | //※何もしない(オフセットの計算をしない)
|
---|
| 483 | }
|
---|
| 484 | else{
|
---|
| 485 | if( resultSize % tempAlignment )
|
---|
| 486 | {
|
---|
| 487 | resultSize += tempAlignment - ( resultSize % tempAlignment );
|
---|
| 488 | }
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | // メンバサイズを加算(配列を考慮)
|
---|
| 493 | resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | if( alignment )
|
---|
| 497 | {
|
---|
| 498 | // 末尾アラインメントを考慮してパディングを追加
|
---|
| 499 | if( resultSize % alignment )
|
---|
| 500 | {
|
---|
| 501 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | return resultSize;
|
---|
[206] | 506 | }
|
---|
[184] | 507 |
|
---|
[206] | 508 | //メンバのオフセットを取得
|
---|
[409] | 509 | int CClass::GetMemberOffset( const char *memberName ) const
|
---|
[206] | 510 | {
|
---|
[409] | 511 | int resultSize = 0;
|
---|
[206] | 512 |
|
---|
[232] | 513 | int alignment = 1;
|
---|
[409] | 514 | if( this->IsStructure() )
|
---|
[232] | 515 | {
|
---|
[409] | 516 | // 構造体のとき
|
---|
| 517 |
|
---|
| 518 | if( this->GetFixedAlignment() )
|
---|
| 519 | {
|
---|
| 520 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 521 | alignment = this->GetFixedAlignment();
|
---|
| 522 | }
|
---|
[232] | 523 | }
|
---|
[409] | 524 | else
|
---|
| 525 | {
|
---|
| 526 | // それ以外
|
---|
[206] | 527 |
|
---|
[409] | 528 | if( this->HasSuperClass() )
|
---|
| 529 | {
|
---|
| 530 | if( this->GetSuperClass().HasDynamicMember( memberName ) )
|
---|
| 531 | {
|
---|
| 532 | // 基底クラスのメンバを取得
|
---|
| 533 | return this->GetSuperClass().GetMemberOffset( memberName );
|
---|
| 534 | }
|
---|
[206] | 535 |
|
---|
[409] | 536 | // 基底クラスのサイズを追加
|
---|
| 537 | resultSize += this->GetSuperClass().GetSize();
|
---|
[206] | 538 |
|
---|
[409] | 539 | // 基底クラスのアラインメントを取得
|
---|
| 540 | alignment = this->GetSuperClass().GetAlignment();
|
---|
[206] | 541 | }
|
---|
[409] | 542 | else
|
---|
| 543 | {
|
---|
| 544 | // 基底クラスが存在しないとき
|
---|
| 545 |
|
---|
| 546 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 547 | resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
|
---|
[206] | 548 | }
|
---|
[409] | 549 | }
|
---|
[206] | 550 |
|
---|
[409] | 551 | BOOST_FOREACH( CMember *pMember, dynamicMembers )
|
---|
| 552 | {
|
---|
| 553 | // メンバサイズ
|
---|
| 554 | int tempMemberSize = pMember->GetType().GetSize();
|
---|
| 555 |
|
---|
| 556 | // 一時アラインメントを算出
|
---|
| 557 | int tempAlignment = tempMemberSize;
|
---|
| 558 | if( pMember->GetType().IsStruct() )
|
---|
| 559 | {
|
---|
| 560 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 561 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
[206] | 562 | }
|
---|
| 563 |
|
---|
[409] | 564 | // アラインメントを考慮してパディングを追加
|
---|
| 565 | if( GetFixedAlignment() && alignment < tempAlignment )
|
---|
| 566 | {
|
---|
| 567 | if( resultSize % alignment )
|
---|
| 568 | {
|
---|
| 569 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 | else
|
---|
| 573 | {
|
---|
| 574 | if( alignment < tempAlignment )
|
---|
| 575 | {
|
---|
| 576 | // 最大アラインメントを更新
|
---|
| 577 | alignment = tempAlignment;
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | if( tempMemberSize == 0 )
|
---|
| 581 | {
|
---|
| 582 | if( !pMember->GetType().IsStruct() )
|
---|
| 583 | {
|
---|
[465] | 584 | compiler.errorMessenger.OutputFatalError();
|
---|
[409] | 585 | }
|
---|
| 586 |
|
---|
| 587 | //メンバを持たない構造体
|
---|
[206] | 588 | //※何もしない(オフセットの計算をしない)
|
---|
| 589 | }
|
---|
| 590 | else{
|
---|
[409] | 591 | if( resultSize % tempAlignment )
|
---|
| 592 | {
|
---|
| 593 | resultSize += tempAlignment - ( resultSize % tempAlignment );
|
---|
| 594 | }
|
---|
[206] | 595 | }
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | if(memberName){
|
---|
| 599 | //メンバ指定がある場合は、オフセットを返す
|
---|
[409] | 600 | if( pMember->GetName() == memberName )
|
---|
| 601 | {
|
---|
| 602 | return resultSize;
|
---|
[206] | 603 | }
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[409] | 606 | // メンバサイズを加算(配列を考慮)
|
---|
| 607 | resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
|
---|
[206] | 608 | }
|
---|
| 609 |
|
---|
[409] | 610 | if( alignment )
|
---|
| 611 | {
|
---|
| 612 | // 末尾アラインメントを考慮してパディングを追加
|
---|
| 613 | if( resultSize % alignment )
|
---|
| 614 | {
|
---|
| 615 | resultSize += alignment - ( resultSize % alignment );
|
---|
| 616 | }
|
---|
[206] | 617 | }
|
---|
| 618 |
|
---|
[409] | 619 | return resultSize;
|
---|
[206] | 620 | }
|
---|
| 621 | int CClass::GetAlignment() const
|
---|
| 622 | {
|
---|
[409] | 623 | int alignment = 1;
|
---|
| 624 | if( this->IsStructure() )
|
---|
| 625 | {
|
---|
| 626 | // 構造体のとき
|
---|
[206] | 627 |
|
---|
[409] | 628 | if( this->GetFixedAlignment() )
|
---|
| 629 | {
|
---|
| 630 | // アラインメントの固定値が指定されていた場合はそれを取得
|
---|
| 631 | return this->GetFixedAlignment();
|
---|
[206] | 632 | }
|
---|
[409] | 633 | }
|
---|
| 634 | else
|
---|
| 635 | {
|
---|
| 636 | // それ以外
|
---|
| 637 |
|
---|
| 638 | if( this->HasSuperClass() )
|
---|
| 639 | {
|
---|
| 640 | // 基底クラスのアラインメントを取得
|
---|
| 641 | alignment = this->GetSuperClass().GetAlignment();
|
---|
[206] | 642 | }
|
---|
[409] | 643 | else
|
---|
| 644 | {
|
---|
| 645 | // 基底クラスが存在しないとき
|
---|
[206] | 646 |
|
---|
[409] | 647 | // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
|
---|
| 648 | alignment = PTR_SIZE;
|
---|
| 649 | }
|
---|
[206] | 650 | }
|
---|
| 651 |
|
---|
[409] | 652 | BOOST_FOREACH( CMember *pMember, dynamicMembers )
|
---|
| 653 | {
|
---|
| 654 | int tempAlignment = pMember->GetType().GetSize();
|
---|
| 655 | if( pMember->GetType().IsStruct() )
|
---|
| 656 | {
|
---|
| 657 | // メンバが構造体の場合は、メンバのアラインメントを取得
|
---|
| 658 | tempAlignment = pMember->GetType().GetClass().GetAlignment();
|
---|
| 659 | }
|
---|
[206] | 660 |
|
---|
[409] | 661 | if( alignment < tempAlignment )
|
---|
| 662 | {
|
---|
| 663 | // 最大アラインメントを更新
|
---|
| 664 | alignment = tempAlignment;
|
---|
| 665 | }
|
---|
| 666 | }
|
---|
[206] | 667 |
|
---|
| 668 | return alignment;
|
---|
| 669 | }
|
---|
[342] | 670 |
|
---|
[348] | 671 | void CClass::GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const
|
---|
[342] | 672 | {
|
---|
[348] | 673 | vtblMasterListIndex = 0;
|
---|
| 674 |
|
---|
| 675 | vtblIndex = 0;
|
---|
[342] | 676 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
| 677 | if( &pMethod->GetUserProc() == pUserProc )
|
---|
| 678 | {
|
---|
[348] | 679 | return;
|
---|
[342] | 680 | }
|
---|
[348] | 681 |
|
---|
| 682 | if( pMethod->IsVirtual() )
|
---|
| 683 | {
|
---|
| 684 | vtblIndex++;
|
---|
| 685 | }
|
---|
[342] | 686 | }
|
---|
| 687 |
|
---|
[346] | 688 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
[342] | 689 | {
|
---|
[348] | 690 | vtblMasterListIndex++;
|
---|
[342] | 691 |
|
---|
[348] | 692 | vtblIndex = 0;
|
---|
[347] | 693 | BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
|
---|
[342] | 694 | if( &pMethod->GetUserProc() == pUserProc )
|
---|
| 695 | {
|
---|
[348] | 696 | return;
|
---|
[342] | 697 | }
|
---|
[348] | 698 |
|
---|
| 699 | if( pMethod->IsVirtual() )
|
---|
| 700 | {
|
---|
| 701 | vtblIndex++;
|
---|
| 702 | }
|
---|
[342] | 703 | }
|
---|
| 704 | }
|
---|
| 705 |
|
---|
[465] | 706 | compiler.errorMessenger.OutputFatalError();
|
---|
[348] | 707 | return;
|
---|
[342] | 708 | }
|
---|
[350] | 709 | int CClass::GetVtblMasterListIndex( const CClass *pClass ) const
|
---|
| 710 | {
|
---|
| 711 | int result = 0;
|
---|
| 712 |
|
---|
| 713 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
| 714 | {
|
---|
| 715 | result++;
|
---|
| 716 |
|
---|
| 717 | if( &pInterface->GetClass() == pClass )
|
---|
| 718 | {
|
---|
| 719 | return result;
|
---|
| 720 | }
|
---|
| 721 | }
|
---|
| 722 |
|
---|
[465] | 723 | compiler.errorMessenger.OutputFatalError();
|
---|
[350] | 724 | return 0;
|
---|
| 725 | }
|
---|
[345] | 726 | long CClass::GetVtblMasterListOffset() const
|
---|
[206] | 727 | {
|
---|
[184] | 728 | //既に存在する場合はそれを返す
|
---|
[342] | 729 | if( vtblMasterListOffset == -1 )
|
---|
| 730 | {
|
---|
[465] | 731 | compiler.errorMessenger.OutputFatalError();
|
---|
[342] | 732 | }
|
---|
[184] | 733 |
|
---|
[342] | 734 | return vtblMasterListOffset;
|
---|
| 735 | }
|
---|
[206] | 736 | bool CClass::IsAbstract() const
|
---|
| 737 | {
|
---|
| 738 | // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
|
---|
[184] | 739 |
|
---|
[342] | 740 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
[206] | 741 | if(pMethod->IsVirtual()){
|
---|
| 742 | if(pMethod->IsAbstract()){
|
---|
| 743 | return true;
|
---|
| 744 | }
|
---|
| 745 | }
|
---|
| 746 | }
|
---|
| 747 |
|
---|
[351] | 748 | // インターフェイスのvtbl
|
---|
| 749 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
| 750 | {
|
---|
| 751 | BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
|
---|
| 752 | if(pMethod->IsVirtual()){
|
---|
| 753 | if(pMethod->IsAbstract()){
|
---|
| 754 | return true;
|
---|
| 755 | }
|
---|
| 756 | }
|
---|
| 757 | }
|
---|
| 758 | }
|
---|
| 759 |
|
---|
[206] | 760 | return false;
|
---|
[184] | 761 | }
|
---|
| 762 |
|
---|
[206] | 763 | CClass *Classes::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){
|
---|
| 764 | return new CClass(namespaceScopes, importedNamespaces, name);
|
---|
| 765 | }
|
---|
[369] | 766 | bool Classes::Insert( CClass *pClass, int nowLine )
|
---|
[206] | 767 | {
|
---|
| 768 | /////////////////////////////////
|
---|
| 769 | // ハッシュデータに追加
|
---|
| 770 | /////////////////////////////////
|
---|
| 771 |
|
---|
[270] | 772 | if( !Put( pClass ) )
|
---|
| 773 | {
|
---|
[465] | 774 | compiler.errorMessenger.Output(15,pClass->GetName(), nowLine);
|
---|
[270] | 775 | return false;
|
---|
[206] | 776 | }
|
---|
| 777 | return true;
|
---|
| 778 | }
|
---|
| 779 | CClass *Classes::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
|
---|
| 780 | //////////////////////////////////////////////////////////////////////////
|
---|
| 781 | // クラスを追加
|
---|
| 782 | // ※名前のみを登録。その他の情報はSetClassメソッドで!
|
---|
| 783 | //////////////////////////////////////////////////////////////////////////
|
---|
| 784 |
|
---|
| 785 | CClass *pClass = Create(namespaceScopes, importedNamespaces, name);
|
---|
| 786 |
|
---|
[369] | 787 | if( !Insert( pClass, nowLine ) )
|
---|
[206] | 788 | {
|
---|
| 789 | return NULL;
|
---|
| 790 | }
|
---|
| 791 |
|
---|
| 792 | return pClass;
|
---|
| 793 | }
|
---|
| 794 |
|
---|
[282] | 795 |
|
---|
[206] | 796 | void Classes::InitStaticMember(){
|
---|
[184] | 797 | //静的メンバをグローバル領域に作成
|
---|
| 798 |
|
---|
| 799 | //イテレータをリセット
|
---|
| 800 |
|
---|
| 801 | extern int cp;
|
---|
| 802 | int back_cp=cp;
|
---|
| 803 |
|
---|
[270] | 804 | this->Iterator_Reset();
|
---|
[184] | 805 | while(this->Iterator_HasNext()){
|
---|
| 806 | CClass &objClass = *this->Iterator_GetNext();
|
---|
[272] | 807 | if( objClass.isTargetObjectModule == false )
|
---|
| 808 | {
|
---|
| 809 | // 静的リンクライブラリの場合は飛ばす(既にインスタンスが定義済みであるため)
|
---|
| 810 | continue;
|
---|
| 811 | }
|
---|
[184] | 812 |
|
---|
| 813 | // 名前空間をセット
|
---|
[199] | 814 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = objClass.GetNamespaceScopes();
|
---|
[184] | 815 |
|
---|
[355] | 816 | DWORD dwFlags = 0;
|
---|
| 817 | if( objClass.GetName() == "_System_TypeBase" )
|
---|
| 818 | {
|
---|
| 819 | // _System_TypeBaseクラスはグローバル、スタティック領域を初期化するためのクラスなのでここでの初期化は除外する
|
---|
| 820 | dwFlags |= DIMFLAG_NONCALL_CONSTRACTOR;
|
---|
| 821 | }
|
---|
| 822 |
|
---|
[406] | 823 | // コンパイル中クラスとしてセット
|
---|
[536] | 824 | compiler.SetCompilingClass( &objClass );
|
---|
[406] | 825 |
|
---|
| 826 | const EnumInfo *pEnumInfo = NULL;
|
---|
| 827 | if( objClass.IsEnum() )
|
---|
| 828 | {
|
---|
| 829 | pEnumInfo = compiler.enumInfoCollection.Find( objClass );
|
---|
| 830 | }
|
---|
| 831 |
|
---|
[184] | 832 | int i=0;
|
---|
[406] | 833 | BOOST_FOREACH( CMember *member, objClass.GetStaticMembers() )
|
---|
| 834 | {
|
---|
| 835 | if( pEnumInfo )
|
---|
| 836 | {
|
---|
| 837 | cp = pEnumInfo->GetEnumMember( member->GetName() ).GetSourceIndex();
|
---|
| 838 | }
|
---|
| 839 |
|
---|
[184] | 840 | char temporary[VN_SIZE];
|
---|
| 841 | sprintf(temporary,"%s.%s",objClass.GetName().c_str(),member->GetName().c_str());
|
---|
| 842 | dim(
|
---|
| 843 | temporary,
|
---|
[206] | 844 | member->GetSubscripts(),
|
---|
[184] | 845 | member->GetType(),
|
---|
| 846 | member->GetInitializeExpression().c_str(),
|
---|
| 847 | member->GetConstructParameter().c_str(),
|
---|
[355] | 848 | dwFlags);
|
---|
[184] | 849 |
|
---|
| 850 | i++;
|
---|
| 851 | }
|
---|
[406] | 852 |
|
---|
[536] | 853 | compiler.SetCompilingClass( NULL );
|
---|
[184] | 854 | }
|
---|
| 855 |
|
---|
[199] | 856 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().clear();
|
---|
[184] | 857 |
|
---|
| 858 | cp=back_cp;
|
---|
| 859 | }
|
---|
| 860 |
|
---|
[206] | 861 | void Classes::Compile_System_InitializeUserTypes(){
|
---|
[184] | 862 | char temporary[VN_SIZE];
|
---|
| 863 |
|
---|
| 864 | ////////////////////////////////////////////////////////////////////
|
---|
| 865 | // クラス登録
|
---|
| 866 | ////////////////////////////////////////////////////////////////////
|
---|
| 867 |
|
---|
| 868 | // イテレータをリセット
|
---|
| 869 | Iterator_Reset();
|
---|
| 870 |
|
---|
| 871 | while( Iterator_HasNext() ){
|
---|
| 872 | const CClass &objClass = *Iterator_GetNext();
|
---|
| 873 |
|
---|
| 874 | if( !objClass.IsUsing() ){
|
---|
| 875 | // 未使用のクラスは無視する
|
---|
| 876 | continue;
|
---|
[417] | 877 | }
|
---|
[184] | 878 |
|
---|
[417] | 879 | std::string referenceOffsetsBuffer;
|
---|
[184] | 880 | int numOfReference = 0;
|
---|
[417] | 881 | objClass.GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference );
|
---|
[184] | 882 |
|
---|
| 883 | sprintf( temporary
|
---|
[355] | 884 | , "Add(%c%c_System_TypeForClass[strNamespace=\"%s\",name=\"%s\",fullName=\"%s\",referenceOffsets=[%s],numOfReference=%d])"
|
---|
[184] | 885 | , 1
|
---|
[355] | 886 | , ESC_SYSTEM_STATIC_NEW
|
---|
| 887 | , objClass.GetNamespaceScopes().ToString().c_str() // 名前空間
|
---|
| 888 | , objClass.GetName().c_str() // クラス名
|
---|
| 889 | , objClass.GetFullName().c_str() // フルネーム
|
---|
[417] | 890 | , referenceOffsetsBuffer.c_str() // 参照メンバオフセット配列
|
---|
[355] | 891 | , numOfReference // 参照メンバの個数
|
---|
[184] | 892 | );
|
---|
| 893 |
|
---|
| 894 | // コンパイル
|
---|
| 895 | ChangeOpcode( temporary );
|
---|
[355] | 896 |
|
---|
| 897 | objClass.SetTypeInfoDataTableOffset(
|
---|
| 898 | compiler.GetObjectModule().dataTable.GetLastMadeConstObjectDataTableOffset()
|
---|
| 899 | );
|
---|
[184] | 900 | }
|
---|
[355] | 901 | }
|
---|
| 902 | void Classes::Compile_System_InitializeUserTypesForBaseType()
|
---|
| 903 | {
|
---|
| 904 | extern int cp;
|
---|
| 905 | cp = -1;
|
---|
[184] | 906 | ////////////////////////////////////////////////////////////////////
|
---|
| 907 | // 基底クラスを登録
|
---|
| 908 | ////////////////////////////////////////////////////////////////////
|
---|
| 909 |
|
---|
[387] | 910 | char temporary[8192];
|
---|
[431] | 911 | sprintf(temporary, "%c%ctempType=Nothing%c%c_System_TypeForClass"
|
---|
[184] | 912 | , HIBYTE( COM_DIM )
|
---|
| 913 | , LOBYTE( COM_DIM )
|
---|
| 914 | , 1
|
---|
| 915 | , ESC_AS
|
---|
| 916 | );
|
---|
| 917 | ChangeOpcode( temporary );
|
---|
| 918 |
|
---|
| 919 | // イテレータをリセット
|
---|
| 920 | Iterator_Reset();
|
---|
| 921 |
|
---|
| 922 | while( Iterator_HasNext() ){
|
---|
| 923 | const CClass &objClass = *Iterator_GetNext();
|
---|
| 924 |
|
---|
| 925 | if( !objClass.IsUsing() ){
|
---|
| 926 | // 未使用のクラスは無視する
|
---|
| 927 | continue;
|
---|
| 928 | }
|
---|
| 929 |
|
---|
[409] | 930 | if( objClass.HasSuperClass() || objClass.GetDynamicMembers().size() ){
|
---|
[184] | 931 | sprintf( temporary
|
---|
[431] | 932 | , "tempType=Search(\"%s\") As ActiveBasic.Core._System_TypeForClass"
|
---|
[355] | 933 | , objClass.GetFullName().c_str()
|
---|
[387] | 934 | );
|
---|
[184] | 935 |
|
---|
| 936 | // コンパイル
|
---|
[431] | 937 | MakeMiddleCode( temporary );
|
---|
[184] | 938 | ChangeOpcode( temporary );
|
---|
| 939 |
|
---|
[431] | 940 | sprintf( temporary
|
---|
| 941 | , "tempType.SetClassInfo(%d,_System_GetComVtbl(%s),_System_GetVtblList(%s),_System_GetDefaultConstructor(%s),_System_GetDestructor(%s))"
|
---|
| 942 | , objClass.GetSize()
|
---|
| 943 | , objClass.GetFullName().c_str()
|
---|
| 944 | , objClass.GetFullName().c_str()
|
---|
| 945 | , objClass.GetFullName().c_str()
|
---|
| 946 | , objClass.GetFullName().c_str()
|
---|
| 947 | , objClass.GetName().c_str()
|
---|
| 948 | );
|
---|
| 949 |
|
---|
| 950 | // コンパイル
|
---|
| 951 | ChangeOpcode( temporary );
|
---|
| 952 |
|
---|
[409] | 953 | if( objClass.HasSuperClass() )
|
---|
| 954 | {
|
---|
| 955 | sprintf( temporary
|
---|
| 956 | , "tempType.SetBaseType(Search(\"%s\"))"
|
---|
| 957 | , objClass.GetSuperClass().GetFullName().c_str()
|
---|
| 958 | );
|
---|
[184] | 959 |
|
---|
[409] | 960 | // コンパイル
|
---|
| 961 | ChangeOpcode( temporary );
|
---|
| 962 | }
|
---|
[184] | 963 |
|
---|
[409] | 964 | if( objClass.GetDynamicMembers().size() )
|
---|
| 965 | {
|
---|
| 966 | // メンバの型を示すTypeInfoオブジェクトへのDataOffset配列の静的データ定義文字列を取得
|
---|
| 967 | sprintf(
|
---|
| 968 | temporary,
|
---|
[412] | 969 | "tempType.SetMembers([%s],[%s],[%s],%d)",
|
---|
[409] | 970 | objClass.GetStaticDefiningStringAsMemberNames().c_str(),
|
---|
| 971 | objClass.GetStaticDefiningStringAsMemberTypeInfoNames().c_str(),
|
---|
[412] | 972 | objClass.GetStaticDefiningStringAsMemberOffsets().c_str(),
|
---|
[409] | 973 | objClass.GetDynamicMembers().size()
|
---|
| 974 | );
|
---|
| 975 | ChangeOpcode( temporary );
|
---|
| 976 | }
|
---|
[184] | 977 | }
|
---|
[387] | 978 | }
|
---|
[184] | 979 | }
|
---|
[193] | 980 |
|
---|
[523] | 981 | const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const std::string &name ) const
|
---|
[193] | 982 | {
|
---|
| 983 | if( namespaceScopes.size() == 0 && name == "Object" ){
|
---|
| 984 | return GetObjectClassPtr();
|
---|
| 985 | }
|
---|
| 986 | else if( namespaceScopes.size() == 0 && name == "String" ){
|
---|
| 987 | return GetStringClassPtr();
|
---|
| 988 | }
|
---|
| 989 |
|
---|
[380] | 990 | std::vector<const CClass *> classes;
|
---|
[270] | 991 | const CClass *pClass = GetHashArrayElement( name.c_str() );
|
---|
| 992 | while( pClass )
|
---|
| 993 | {
|
---|
| 994 | if( pClass->IsEqualSymbol( namespaceScopes, name ) ){
|
---|
| 995 | //名前空間とクラス名が一致した
|
---|
[380] | 996 | classes.push_back( pClass );
|
---|
[193] | 997 | }
|
---|
[270] | 998 | pClass = pClass->GetChainNext();
|
---|
[193] | 999 | }
|
---|
[380] | 1000 | if( classes.size() > 0 )
|
---|
| 1001 | {
|
---|
| 1002 | // 複数の名前空間の中に同一のクラス名が存在する場合があるので、アクセス可能で尚且つ階層が一番深いものをチョイスする
|
---|
| 1003 | pClass = classes.front();
|
---|
[193] | 1004 |
|
---|
[380] | 1005 | BOOST_FOREACH( const CClass *pTempClass, classes )
|
---|
| 1006 | {
|
---|
| 1007 | if( pClass->GetNamespaceScopes().size() < pTempClass->GetNamespaceScopes().size() )
|
---|
| 1008 | {
|
---|
| 1009 | pClass = pTempClass;
|
---|
| 1010 | }
|
---|
| 1011 | }
|
---|
| 1012 |
|
---|
| 1013 | return pClass;
|
---|
| 1014 | }
|
---|
| 1015 |
|
---|
[193] | 1016 | // TypeDefも見る
|
---|
[265] | 1017 | int index = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( namespaceScopes, name );
|
---|
[193] | 1018 | if( index != -1 ){
|
---|
[265] | 1019 | Type type = compiler.GetObjectModule().meta.GetTypeDefs()[index].GetBaseType();
|
---|
[193] | 1020 | if( type.IsObject() ){
|
---|
| 1021 | return &type.GetClass();
|
---|
| 1022 | }
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
| 1025 | return NULL;
|
---|
| 1026 | }
|
---|
[523] | 1027 | const CClass *Classes::Find( const std::string &fullName ) const
|
---|
[206] | 1028 | {
|
---|
| 1029 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
| 1030 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
| 1031 | bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
|
---|
| 1032 |
|
---|
| 1033 | return Find( NamespaceScopes( AreaName ), NestName );
|
---|
| 1034 | }
|
---|
| 1035 |
|
---|
[272] | 1036 | const CClass *Classes::GetStringClassPtr() const
|
---|
[206] | 1037 | {
|
---|
| 1038 | if( !pStringClass ){
|
---|
[272] | 1039 | // キャッシュしておく
|
---|
| 1040 | pStringClass = this->Find( NamespaceScopes( "System" ), "String" );
|
---|
| 1041 |
|
---|
| 1042 | if( !pStringClass )
|
---|
| 1043 | {
|
---|
[465] | 1044 | compiler.errorMessenger.Output(400, "System.String", cp);
|
---|
[351] | 1045 | static CClass dummy;
|
---|
| 1046 | return &dummy;
|
---|
[272] | 1047 | }
|
---|
| 1048 | return pStringClass;
|
---|
[206] | 1049 | }
|
---|
| 1050 | return pStringClass;
|
---|
| 1051 | }
|
---|
[272] | 1052 | const CClass *Classes::GetObjectClassPtr() const
|
---|
[206] | 1053 | {
|
---|
| 1054 | if( !pObjectClass ){
|
---|
[272] | 1055 | // キャッシュしておく
|
---|
| 1056 | pObjectClass = this->Find( NamespaceScopes( "System" ), "Object" );
|
---|
| 1057 |
|
---|
| 1058 | if( !pObjectClass )
|
---|
| 1059 | {
|
---|
[465] | 1060 | compiler.errorMessenger.Output(400, "System.Object", cp);
|
---|
[351] | 1061 | static CClass dummy;
|
---|
| 1062 | return &dummy;
|
---|
[272] | 1063 | }
|
---|
| 1064 | return pObjectClass;
|
---|
[206] | 1065 | }
|
---|
| 1066 | return pObjectClass;
|
---|
| 1067 | }
|
---|
[349] | 1068 | const CClass *Classes::GetInterfaceInfoClassPtr() const
|
---|
| 1069 | {
|
---|
| 1070 | if( !pInterfaceInfo ){
|
---|
| 1071 | // キャッシュしておく
|
---|
| 1072 | pInterfaceInfo = this->Find( "ActiveBasic.Core.InterfaceInfo" );
|
---|
| 1073 |
|
---|
| 1074 | if( !pInterfaceInfo )
|
---|
| 1075 | {
|
---|
[465] | 1076 | compiler.errorMessenger.Output(400, "ActiveBasic.Core.InterfaceInfo", cp);
|
---|
[351] | 1077 | static CClass dummy;
|
---|
| 1078 | return &dummy;
|
---|
[349] | 1079 | }
|
---|
| 1080 | return pInterfaceInfo;
|
---|
| 1081 | }
|
---|
| 1082 | return pInterfaceInfo;
|
---|
| 1083 | }
|
---|
[387] | 1084 |
|
---|
| 1085 | std::string CClass::GetStaticDefiningStringAsMemberNames() const
|
---|
| 1086 | {
|
---|
| 1087 | std::string result;
|
---|
| 1088 |
|
---|
| 1089 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1090 | {
|
---|
| 1091 | if( result.size() )
|
---|
| 1092 | {
|
---|
| 1093 | result += ",";
|
---|
| 1094 | }
|
---|
| 1095 |
|
---|
| 1096 | result += "\"" + pMember->GetName() + "\"";
|
---|
| 1097 | }
|
---|
| 1098 |
|
---|
| 1099 | return result;
|
---|
| 1100 | }
|
---|
| 1101 | std::string CClass::GetStaticDefiningStringAsMemberTypeInfoNames() const
|
---|
| 1102 | {
|
---|
| 1103 | std::string result;
|
---|
| 1104 |
|
---|
| 1105 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1106 | {
|
---|
| 1107 | if( result.size() )
|
---|
| 1108 | {
|
---|
| 1109 | result += ",";
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
| 1112 | result += "\"" + compiler.TypeToString( pMember->GetType() ) + "\"";
|
---|
| 1113 | }
|
---|
| 1114 |
|
---|
| 1115 | return result;
|
---|
| 1116 | }
|
---|
[412] | 1117 | std::string CClass::GetStaticDefiningStringAsMemberOffsets() const
|
---|
| 1118 | {
|
---|
| 1119 | std::string result;
|
---|
[387] | 1120 |
|
---|
[412] | 1121 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1122 | {
|
---|
| 1123 | if( result.size() )
|
---|
| 1124 | {
|
---|
| 1125 | result += ",";
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | int offset = this->GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 1129 |
|
---|
| 1130 | char temporary[255];
|
---|
| 1131 | itoa( offset, temporary, 16 );
|
---|
| 1132 |
|
---|
| 1133 | result += (std::string)"&H" + temporary;
|
---|
| 1134 | }
|
---|
| 1135 |
|
---|
| 1136 | return result;
|
---|
| 1137 | }
|
---|
[417] | 1138 |
|
---|
| 1139 | void CClass::GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset ) const
|
---|
| 1140 | {
|
---|
| 1141 | const CClass &thisClass = *this;
|
---|
| 1142 | BOOST_FOREACH( const CMember *pMember, thisClass.GetDynamicMembers() )
|
---|
| 1143 | {
|
---|
| 1144 | if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() )
|
---|
| 1145 | {
|
---|
| 1146 | if( referenceOffsetsBuffer.size() )
|
---|
| 1147 | {
|
---|
| 1148 | referenceOffsetsBuffer += ",";
|
---|
| 1149 | }
|
---|
| 1150 |
|
---|
| 1151 | char temp[255];
|
---|
| 1152 | sprintf( temp, "%d", baseOffset + thisClass.GetMemberOffset( pMember->GetName().c_str() ) );
|
---|
| 1153 | referenceOffsetsBuffer += temp;
|
---|
| 1154 |
|
---|
| 1155 | numOfReference++;
|
---|
| 1156 | }
|
---|
| 1157 | if( pMember->GetType().IsStruct() && !pMember->GetType().IsPointer() )
|
---|
| 1158 | {
|
---|
| 1159 | // 構造体の実体をメンバに持つとき
|
---|
| 1160 | int baseOffset = thisClass.GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 1161 |
|
---|
| 1162 | // 構造体メンバでGCによるチェックが必要な参照位置を追加
|
---|
| 1163 | pMember->GetType().GetClass().GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference, baseOffset );
|
---|
| 1164 | }
|
---|
| 1165 | }
|
---|
| 1166 | }
|
---|