[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 | }
|
---|
[370] | 726 | long CClass::GetComVtblOffset() const
|
---|
| 727 | {
|
---|
| 728 | return comVtblOffset;
|
---|
| 729 | }
|
---|
[345] | 730 | long CClass::GetVtblMasterListOffset() const
|
---|
[206] | 731 | {
|
---|
[184] | 732 | //既に存在する場合はそれを返す
|
---|
[342] | 733 | if( vtblMasterListOffset == -1 )
|
---|
| 734 | {
|
---|
[465] | 735 | compiler.errorMessenger.OutputFatalError();
|
---|
[342] | 736 | }
|
---|
[184] | 737 |
|
---|
[342] | 738 | return vtblMasterListOffset;
|
---|
| 739 | }
|
---|
[345] | 740 | void CClass::GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset )
|
---|
[282] | 741 | {
|
---|
[342] | 742 | offset = compiler.GetObjectModule().dataTable.AddBinary(
|
---|
| 743 | (void *)&vtableMasterList[0],
|
---|
[345] | 744 | static_cast<int>(vtableMasterList.size()*sizeof(LONG_PTR))
|
---|
[342] | 745 | );
|
---|
| 746 | }
|
---|
| 747 | void CClass::GenerateFullVTables()
|
---|
| 748 | {
|
---|
[282] | 749 | if( IsAbstract() )
|
---|
| 750 | {
|
---|
| 751 | // 抽象クラスは無視
|
---|
| 752 | return;
|
---|
| 753 | }
|
---|
| 754 | if( !IsUsing() )
|
---|
| 755 | {
|
---|
| 756 | // 使われていないクラスは無視
|
---|
| 757 | return;
|
---|
| 758 | }
|
---|
| 759 |
|
---|
[342] | 760 | // vtblマスターリストの元データに不要なデータが含まれていたらエラー
|
---|
| 761 | if( vtblMasterList.size() )
|
---|
| 762 | {
|
---|
[465] | 763 | compiler.errorMessenger.OutputFatalError();
|
---|
[342] | 764 | }
|
---|
[282] | 765 |
|
---|
[342] | 766 | // 自身のクラスのvtblを生成
|
---|
[347] | 767 | GetDynamicMethods().GenerateVTablePart( this->vtbl_offset );
|
---|
[342] | 768 | vtblMasterList.push_back( this->vtbl_offset );
|
---|
[282] | 769 |
|
---|
[342] | 770 | // インターフェイスのvtblを生成
|
---|
[346] | 771 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
[342] | 772 | {
|
---|
[345] | 773 | long tempVtblOffset;
|
---|
[347] | 774 | pInterface->GetDynamicMethods().GenerateVTablePart( tempVtblOffset );
|
---|
[342] | 775 | vtblMasterList.push_back( tempVtblOffset );
|
---|
[282] | 776 |
|
---|
[346] | 777 | pInterface->SetVtblOffset( tempVtblOffset );
|
---|
[370] | 778 |
|
---|
| 779 | if( pInterface->GetClass().IsComInterface() )
|
---|
| 780 | {
|
---|
| 781 | if( this->comVtblOffset )
|
---|
| 782 | {
|
---|
[465] | 783 | compiler.errorMessenger.OutputFatalError();
|
---|
[370] | 784 | }
|
---|
| 785 | this->comVtblOffset = tempVtblOffset;
|
---|
| 786 | }
|
---|
[282] | 787 | }
|
---|
| 788 |
|
---|
[342] | 789 | // vtblマスターリストを生成
|
---|
| 790 | GenerateVTableMasterList( vtblMasterList, this->vtblMasterListOffset );
|
---|
[282] | 791 | }
|
---|
[342] | 792 | void CClass::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection )
|
---|
| 793 | {
|
---|
[282] | 794 | if( IsAbstract() )
|
---|
| 795 | {
|
---|
| 796 | // 抽象クラスは無視
|
---|
| 797 | return;
|
---|
| 798 | }
|
---|
| 799 | if( !IsUsing() )
|
---|
| 800 | {
|
---|
| 801 | // 使われていないクラスは無視
|
---|
| 802 | return;
|
---|
| 803 | }
|
---|
[184] | 804 | if(vtbl_offset==-1) return;
|
---|
| 805 |
|
---|
[342] | 806 | // 自身のクラスのvtbl
|
---|
| 807 | {
|
---|
| 808 | LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtbl_offset);
|
---|
[184] | 809 |
|
---|
[342] | 810 | for( int i=0; i<GetVtblNum(); i++ ){
|
---|
| 811 | const UserProc *pUserProc = (UserProc *)pVtbl[i];
|
---|
| 812 | if(!pUserProc) continue;
|
---|
[263] | 813 |
|
---|
[342] | 814 | if( pUserProc->GetBeginOpAddress() == 0
|
---|
| 815 | && pUserProc->GetEndOpAddress() == 0 )
|
---|
| 816 | {
|
---|
| 817 | Jenga::Throw( "未解決の仮想関数が存在する" );
|
---|
| 818 | }
|
---|
| 819 |
|
---|
| 820 | pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
|
---|
[282] | 821 | }
|
---|
[342] | 822 | }
|
---|
[282] | 823 |
|
---|
[342] | 824 | // インターフェイスのvtbl
|
---|
[346] | 825 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
[342] | 826 | {
|
---|
[347] | 827 | LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + pInterface->GetVtblOffset());
|
---|
[342] | 828 |
|
---|
[346] | 829 | for( int i=0; i<pInterface->GetClass().GetVtblNum(); i++ ){
|
---|
[342] | 830 | const UserProc *pUserProc = (UserProc *)pVtbl[i];
|
---|
| 831 | if(!pUserProc) continue;
|
---|
| 832 |
|
---|
| 833 | if( pUserProc->GetBeginOpAddress() == 0
|
---|
| 834 | && pUserProc->GetEndOpAddress() == 0 )
|
---|
| 835 | {
|
---|
| 836 | Jenga::Throw( "未解決の仮想関数が存在する" );
|
---|
| 837 | }
|
---|
| 838 |
|
---|
| 839 | pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
|
---|
| 840 | }
|
---|
[184] | 841 | }
|
---|
[342] | 842 |
|
---|
| 843 | // vtblマスターリスト
|
---|
| 844 | LONG_PTR *pVtblMasterList = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtblMasterListOffset );
|
---|
| 845 | for( int i=0; i<static_cast<int>(vtblMasterList.size()); i++ )
|
---|
| 846 | {
|
---|
| 847 | pVtblMasterList[i] = vtblMasterList[i] + ImageBase + MemPos_DataSection;
|
---|
| 848 | }
|
---|
[184] | 849 | }
|
---|
[206] | 850 | bool CClass::IsAbstract() const
|
---|
| 851 | {
|
---|
| 852 | // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
|
---|
[184] | 853 |
|
---|
[342] | 854 | BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
|
---|
[206] | 855 | if(pMethod->IsVirtual()){
|
---|
| 856 | if(pMethod->IsAbstract()){
|
---|
| 857 | return true;
|
---|
| 858 | }
|
---|
| 859 | }
|
---|
| 860 | }
|
---|
| 861 |
|
---|
[351] | 862 | // インターフェイスのvtbl
|
---|
| 863 | BOOST_FOREACH( const ::Interface *pInterface, interfaces )
|
---|
| 864 | {
|
---|
| 865 | BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
|
---|
| 866 | if(pMethod->IsVirtual()){
|
---|
| 867 | if(pMethod->IsAbstract()){
|
---|
| 868 | return true;
|
---|
| 869 | }
|
---|
| 870 | }
|
---|
| 871 | }
|
---|
| 872 | }
|
---|
| 873 |
|
---|
[206] | 874 | return false;
|
---|
[184] | 875 | }
|
---|
| 876 |
|
---|
[206] | 877 | CClass *Classes::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){
|
---|
| 878 | return new CClass(namespaceScopes, importedNamespaces, name);
|
---|
| 879 | }
|
---|
[369] | 880 | bool Classes::Insert( CClass *pClass, int nowLine )
|
---|
[206] | 881 | {
|
---|
| 882 | /////////////////////////////////
|
---|
| 883 | // ハッシュデータに追加
|
---|
| 884 | /////////////////////////////////
|
---|
| 885 |
|
---|
[270] | 886 | if( !Put( pClass ) )
|
---|
| 887 | {
|
---|
[465] | 888 | compiler.errorMessenger.Output(15,pClass->GetName(), nowLine);
|
---|
[270] | 889 | return false;
|
---|
[206] | 890 | }
|
---|
| 891 | return true;
|
---|
| 892 | }
|
---|
| 893 | CClass *Classes::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
|
---|
| 894 | //////////////////////////////////////////////////////////////////////////
|
---|
| 895 | // クラスを追加
|
---|
| 896 | // ※名前のみを登録。その他の情報はSetClassメソッドで!
|
---|
| 897 | //////////////////////////////////////////////////////////////////////////
|
---|
| 898 |
|
---|
| 899 | CClass *pClass = Create(namespaceScopes, importedNamespaces, name);
|
---|
| 900 |
|
---|
[369] | 901 | if( !Insert( pClass, nowLine ) )
|
---|
[206] | 902 | {
|
---|
| 903 | return NULL;
|
---|
| 904 | }
|
---|
| 905 |
|
---|
| 906 | return pClass;
|
---|
| 907 | }
|
---|
| 908 |
|
---|
[282] | 909 | void Classes::GenerateVTables()
|
---|
| 910 | {
|
---|
| 911 | Iterator_Reset();
|
---|
| 912 | while( Iterator_HasNext() )
|
---|
| 913 | {
|
---|
| 914 | CClass *pClass = Iterator_GetNext();
|
---|
[342] | 915 | pClass->GenerateFullVTables();
|
---|
[282] | 916 | }
|
---|
| 917 | }
|
---|
| 918 |
|
---|
[342] | 919 | void Classes::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection ){
|
---|
[270] | 920 | Iterator_Reset();
|
---|
| 921 | while( Iterator_HasNext() )
|
---|
| 922 | {
|
---|
| 923 | CClass *pClass = Iterator_GetNext();
|
---|
[342] | 924 | pClass->ActionVtblSchedule( ImageBase, MemPos_CodeSection, MemPos_DataSection);
|
---|
[206] | 925 | }
|
---|
| 926 | }
|
---|
| 927 |
|
---|
| 928 |
|
---|
| 929 | void Classes::InitStaticMember(){
|
---|
[184] | 930 | //静的メンバをグローバル領域に作成
|
---|
| 931 |
|
---|
| 932 | //イテレータをリセット
|
---|
| 933 |
|
---|
| 934 | extern int cp;
|
---|
| 935 | int back_cp=cp;
|
---|
| 936 |
|
---|
[270] | 937 | this->Iterator_Reset();
|
---|
[184] | 938 | while(this->Iterator_HasNext()){
|
---|
| 939 | CClass &objClass = *this->Iterator_GetNext();
|
---|
[272] | 940 | if( objClass.isTargetObjectModule == false )
|
---|
| 941 | {
|
---|
| 942 | // 静的リンクライブラリの場合は飛ばす(既にインスタンスが定義済みであるため)
|
---|
| 943 | continue;
|
---|
| 944 | }
|
---|
[184] | 945 |
|
---|
| 946 | // 名前空間をセット
|
---|
[199] | 947 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = objClass.GetNamespaceScopes();
|
---|
[184] | 948 |
|
---|
[355] | 949 | DWORD dwFlags = 0;
|
---|
| 950 | if( objClass.GetName() == "_System_TypeBase" )
|
---|
| 951 | {
|
---|
| 952 | // _System_TypeBaseクラスはグローバル、スタティック領域を初期化するためのクラスなのでここでの初期化は除外する
|
---|
| 953 | dwFlags |= DIMFLAG_NONCALL_CONSTRACTOR;
|
---|
| 954 | }
|
---|
| 955 |
|
---|
[406] | 956 | // コンパイル中クラスとしてセット
|
---|
[536] | 957 | compiler.SetCompilingClass( &objClass );
|
---|
[406] | 958 |
|
---|
| 959 | const EnumInfo *pEnumInfo = NULL;
|
---|
| 960 | if( objClass.IsEnum() )
|
---|
| 961 | {
|
---|
| 962 | pEnumInfo = compiler.enumInfoCollection.Find( objClass );
|
---|
| 963 | }
|
---|
| 964 |
|
---|
[184] | 965 | int i=0;
|
---|
[406] | 966 | BOOST_FOREACH( CMember *member, objClass.GetStaticMembers() )
|
---|
| 967 | {
|
---|
| 968 | if( pEnumInfo )
|
---|
| 969 | {
|
---|
| 970 | cp = pEnumInfo->GetEnumMember( member->GetName() ).GetSourceIndex();
|
---|
| 971 | }
|
---|
| 972 |
|
---|
[184] | 973 | char temporary[VN_SIZE];
|
---|
| 974 | sprintf(temporary,"%s.%s",objClass.GetName().c_str(),member->GetName().c_str());
|
---|
| 975 | dim(
|
---|
| 976 | temporary,
|
---|
[206] | 977 | member->GetSubscripts(),
|
---|
[184] | 978 | member->GetType(),
|
---|
| 979 | member->GetInitializeExpression().c_str(),
|
---|
| 980 | member->GetConstructParameter().c_str(),
|
---|
[355] | 981 | dwFlags);
|
---|
[184] | 982 |
|
---|
| 983 | i++;
|
---|
| 984 | }
|
---|
[406] | 985 |
|
---|
[536] | 986 | compiler.SetCompilingClass( NULL );
|
---|
[184] | 987 | }
|
---|
| 988 |
|
---|
[199] | 989 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().clear();
|
---|
[184] | 990 |
|
---|
| 991 | cp=back_cp;
|
---|
| 992 | }
|
---|
| 993 |
|
---|
[206] | 994 | void Classes::Compile_System_InitializeUserTypes(){
|
---|
[184] | 995 | char temporary[VN_SIZE];
|
---|
| 996 |
|
---|
| 997 | ////////////////////////////////////////////////////////////////////
|
---|
| 998 | // クラス登録
|
---|
| 999 | ////////////////////////////////////////////////////////////////////
|
---|
| 1000 |
|
---|
| 1001 | // イテレータをリセット
|
---|
| 1002 | Iterator_Reset();
|
---|
| 1003 |
|
---|
| 1004 | while( Iterator_HasNext() ){
|
---|
| 1005 | const CClass &objClass = *Iterator_GetNext();
|
---|
| 1006 |
|
---|
| 1007 | if( !objClass.IsUsing() ){
|
---|
| 1008 | // 未使用のクラスは無視する
|
---|
| 1009 | continue;
|
---|
[417] | 1010 | }
|
---|
[184] | 1011 |
|
---|
[417] | 1012 | std::string referenceOffsetsBuffer;
|
---|
[184] | 1013 | int numOfReference = 0;
|
---|
[417] | 1014 | objClass.GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference );
|
---|
[184] | 1015 |
|
---|
| 1016 | sprintf( temporary
|
---|
[355] | 1017 | , "Add(%c%c_System_TypeForClass[strNamespace=\"%s\",name=\"%s\",fullName=\"%s\",referenceOffsets=[%s],numOfReference=%d])"
|
---|
[184] | 1018 | , 1
|
---|
[355] | 1019 | , ESC_SYSTEM_STATIC_NEW
|
---|
| 1020 | , objClass.GetNamespaceScopes().ToString().c_str() // 名前空間
|
---|
| 1021 | , objClass.GetName().c_str() // クラス名
|
---|
| 1022 | , objClass.GetFullName().c_str() // フルネーム
|
---|
[417] | 1023 | , referenceOffsetsBuffer.c_str() // 参照メンバオフセット配列
|
---|
[355] | 1024 | , numOfReference // 参照メンバの個数
|
---|
[184] | 1025 | );
|
---|
| 1026 |
|
---|
| 1027 | // コンパイル
|
---|
| 1028 | ChangeOpcode( temporary );
|
---|
[355] | 1029 |
|
---|
| 1030 | objClass.SetTypeInfoDataTableOffset(
|
---|
| 1031 | compiler.GetObjectModule().dataTable.GetLastMadeConstObjectDataTableOffset()
|
---|
| 1032 | );
|
---|
[184] | 1033 | }
|
---|
[355] | 1034 | }
|
---|
| 1035 | void Classes::Compile_System_InitializeUserTypesForBaseType()
|
---|
| 1036 | {
|
---|
| 1037 | extern int cp;
|
---|
| 1038 | cp = -1;
|
---|
[184] | 1039 | ////////////////////////////////////////////////////////////////////
|
---|
| 1040 | // 基底クラスを登録
|
---|
| 1041 | ////////////////////////////////////////////////////////////////////
|
---|
| 1042 |
|
---|
[387] | 1043 | char temporary[8192];
|
---|
[431] | 1044 | sprintf(temporary, "%c%ctempType=Nothing%c%c_System_TypeForClass"
|
---|
[184] | 1045 | , HIBYTE( COM_DIM )
|
---|
| 1046 | , LOBYTE( COM_DIM )
|
---|
| 1047 | , 1
|
---|
| 1048 | , ESC_AS
|
---|
| 1049 | );
|
---|
| 1050 | ChangeOpcode( temporary );
|
---|
| 1051 |
|
---|
| 1052 | // イテレータをリセット
|
---|
| 1053 | Iterator_Reset();
|
---|
| 1054 |
|
---|
| 1055 | while( Iterator_HasNext() ){
|
---|
| 1056 | const CClass &objClass = *Iterator_GetNext();
|
---|
| 1057 |
|
---|
| 1058 | if( !objClass.IsUsing() ){
|
---|
| 1059 | // 未使用のクラスは無視する
|
---|
| 1060 | continue;
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
[409] | 1063 | if( objClass.HasSuperClass() || objClass.GetDynamicMembers().size() ){
|
---|
[184] | 1064 | sprintf( temporary
|
---|
[431] | 1065 | , "tempType=Search(\"%s\") As ActiveBasic.Core._System_TypeForClass"
|
---|
[355] | 1066 | , objClass.GetFullName().c_str()
|
---|
[387] | 1067 | );
|
---|
[184] | 1068 |
|
---|
| 1069 | // コンパイル
|
---|
[431] | 1070 | MakeMiddleCode( temporary );
|
---|
[184] | 1071 | ChangeOpcode( temporary );
|
---|
| 1072 |
|
---|
[431] | 1073 | sprintf( temporary
|
---|
| 1074 | , "tempType.SetClassInfo(%d,_System_GetComVtbl(%s),_System_GetVtblList(%s),_System_GetDefaultConstructor(%s),_System_GetDestructor(%s))"
|
---|
| 1075 | , objClass.GetSize()
|
---|
| 1076 | , objClass.GetFullName().c_str()
|
---|
| 1077 | , objClass.GetFullName().c_str()
|
---|
| 1078 | , objClass.GetFullName().c_str()
|
---|
| 1079 | , objClass.GetFullName().c_str()
|
---|
| 1080 | , objClass.GetName().c_str()
|
---|
| 1081 | );
|
---|
| 1082 |
|
---|
| 1083 | // コンパイル
|
---|
| 1084 | ChangeOpcode( temporary );
|
---|
| 1085 |
|
---|
[409] | 1086 | if( objClass.HasSuperClass() )
|
---|
| 1087 | {
|
---|
| 1088 | sprintf( temporary
|
---|
| 1089 | , "tempType.SetBaseType(Search(\"%s\"))"
|
---|
| 1090 | , objClass.GetSuperClass().GetFullName().c_str()
|
---|
| 1091 | );
|
---|
[184] | 1092 |
|
---|
[409] | 1093 | // コンパイル
|
---|
| 1094 | ChangeOpcode( temporary );
|
---|
| 1095 | }
|
---|
[184] | 1096 |
|
---|
[409] | 1097 | if( objClass.GetDynamicMembers().size() )
|
---|
| 1098 | {
|
---|
| 1099 | // メンバの型を示すTypeInfoオブジェクトへのDataOffset配列の静的データ定義文字列を取得
|
---|
| 1100 | sprintf(
|
---|
| 1101 | temporary,
|
---|
[412] | 1102 | "tempType.SetMembers([%s],[%s],[%s],%d)",
|
---|
[409] | 1103 | objClass.GetStaticDefiningStringAsMemberNames().c_str(),
|
---|
| 1104 | objClass.GetStaticDefiningStringAsMemberTypeInfoNames().c_str(),
|
---|
[412] | 1105 | objClass.GetStaticDefiningStringAsMemberOffsets().c_str(),
|
---|
[409] | 1106 | objClass.GetDynamicMembers().size()
|
---|
| 1107 | );
|
---|
| 1108 | ChangeOpcode( temporary );
|
---|
| 1109 | }
|
---|
[184] | 1110 | }
|
---|
[387] | 1111 | }
|
---|
[184] | 1112 | }
|
---|
[193] | 1113 |
|
---|
[523] | 1114 | const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const std::string &name ) const
|
---|
[193] | 1115 | {
|
---|
| 1116 | if( namespaceScopes.size() == 0 && name == "Object" ){
|
---|
| 1117 | return GetObjectClassPtr();
|
---|
| 1118 | }
|
---|
| 1119 | else if( namespaceScopes.size() == 0 && name == "String" ){
|
---|
| 1120 | return GetStringClassPtr();
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
[380] | 1123 | std::vector<const CClass *> classes;
|
---|
[270] | 1124 | const CClass *pClass = GetHashArrayElement( name.c_str() );
|
---|
| 1125 | while( pClass )
|
---|
| 1126 | {
|
---|
| 1127 | if( pClass->IsEqualSymbol( namespaceScopes, name ) ){
|
---|
| 1128 | //名前空間とクラス名が一致した
|
---|
[380] | 1129 | classes.push_back( pClass );
|
---|
[193] | 1130 | }
|
---|
[270] | 1131 | pClass = pClass->GetChainNext();
|
---|
[193] | 1132 | }
|
---|
[380] | 1133 | if( classes.size() > 0 )
|
---|
| 1134 | {
|
---|
| 1135 | // 複数の名前空間の中に同一のクラス名が存在する場合があるので、アクセス可能で尚且つ階層が一番深いものをチョイスする
|
---|
| 1136 | pClass = classes.front();
|
---|
[193] | 1137 |
|
---|
[380] | 1138 | BOOST_FOREACH( const CClass *pTempClass, classes )
|
---|
| 1139 | {
|
---|
| 1140 | if( pClass->GetNamespaceScopes().size() < pTempClass->GetNamespaceScopes().size() )
|
---|
| 1141 | {
|
---|
| 1142 | pClass = pTempClass;
|
---|
| 1143 | }
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 | return pClass;
|
---|
| 1147 | }
|
---|
| 1148 |
|
---|
[193] | 1149 | // TypeDefも見る
|
---|
[265] | 1150 | int index = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( namespaceScopes, name );
|
---|
[193] | 1151 | if( index != -1 ){
|
---|
[265] | 1152 | Type type = compiler.GetObjectModule().meta.GetTypeDefs()[index].GetBaseType();
|
---|
[193] | 1153 | if( type.IsObject() ){
|
---|
| 1154 | return &type.GetClass();
|
---|
| 1155 | }
|
---|
| 1156 | }
|
---|
| 1157 |
|
---|
| 1158 | return NULL;
|
---|
| 1159 | }
|
---|
[523] | 1160 | const CClass *Classes::Find( const std::string &fullName ) const
|
---|
[206] | 1161 | {
|
---|
| 1162 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
| 1163 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
| 1164 | bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
|
---|
| 1165 |
|
---|
| 1166 | return Find( NamespaceScopes( AreaName ), NestName );
|
---|
| 1167 | }
|
---|
| 1168 |
|
---|
[272] | 1169 | const CClass *Classes::GetStringClassPtr() const
|
---|
[206] | 1170 | {
|
---|
| 1171 | if( !pStringClass ){
|
---|
[272] | 1172 | // キャッシュしておく
|
---|
| 1173 | pStringClass = this->Find( NamespaceScopes( "System" ), "String" );
|
---|
| 1174 |
|
---|
| 1175 | if( !pStringClass )
|
---|
| 1176 | {
|
---|
[465] | 1177 | compiler.errorMessenger.Output(400, "System.String", cp);
|
---|
[351] | 1178 | static CClass dummy;
|
---|
| 1179 | return &dummy;
|
---|
[272] | 1180 | }
|
---|
| 1181 | return pStringClass;
|
---|
[206] | 1182 | }
|
---|
| 1183 | return pStringClass;
|
---|
| 1184 | }
|
---|
[272] | 1185 | const CClass *Classes::GetObjectClassPtr() const
|
---|
[206] | 1186 | {
|
---|
| 1187 | if( !pObjectClass ){
|
---|
[272] | 1188 | // キャッシュしておく
|
---|
| 1189 | pObjectClass = this->Find( NamespaceScopes( "System" ), "Object" );
|
---|
| 1190 |
|
---|
| 1191 | if( !pObjectClass )
|
---|
| 1192 | {
|
---|
[465] | 1193 | compiler.errorMessenger.Output(400, "System.Object", cp);
|
---|
[351] | 1194 | static CClass dummy;
|
---|
| 1195 | return &dummy;
|
---|
[272] | 1196 | }
|
---|
| 1197 | return pObjectClass;
|
---|
[206] | 1198 | }
|
---|
| 1199 | return pObjectClass;
|
---|
| 1200 | }
|
---|
[349] | 1201 | const CClass *Classes::GetInterfaceInfoClassPtr() const
|
---|
| 1202 | {
|
---|
| 1203 | if( !pInterfaceInfo ){
|
---|
| 1204 | // キャッシュしておく
|
---|
| 1205 | pInterfaceInfo = this->Find( "ActiveBasic.Core.InterfaceInfo" );
|
---|
| 1206 |
|
---|
| 1207 | if( !pInterfaceInfo )
|
---|
| 1208 | {
|
---|
[465] | 1209 | compiler.errorMessenger.Output(400, "ActiveBasic.Core.InterfaceInfo", cp);
|
---|
[351] | 1210 | static CClass dummy;
|
---|
| 1211 | return &dummy;
|
---|
[349] | 1212 | }
|
---|
| 1213 | return pInterfaceInfo;
|
---|
| 1214 | }
|
---|
| 1215 | return pInterfaceInfo;
|
---|
| 1216 | }
|
---|
[387] | 1217 |
|
---|
| 1218 | std::string CClass::GetStaticDefiningStringAsMemberNames() const
|
---|
| 1219 | {
|
---|
| 1220 | std::string result;
|
---|
| 1221 |
|
---|
| 1222 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1223 | {
|
---|
| 1224 | if( result.size() )
|
---|
| 1225 | {
|
---|
| 1226 | result += ",";
|
---|
| 1227 | }
|
---|
| 1228 |
|
---|
| 1229 | result += "\"" + pMember->GetName() + "\"";
|
---|
| 1230 | }
|
---|
| 1231 |
|
---|
| 1232 | return result;
|
---|
| 1233 | }
|
---|
| 1234 | std::string CClass::GetStaticDefiningStringAsMemberTypeInfoNames() const
|
---|
| 1235 | {
|
---|
| 1236 | std::string result;
|
---|
| 1237 |
|
---|
| 1238 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1239 | {
|
---|
| 1240 | if( result.size() )
|
---|
| 1241 | {
|
---|
| 1242 | result += ",";
|
---|
| 1243 | }
|
---|
| 1244 |
|
---|
| 1245 | result += "\"" + compiler.TypeToString( pMember->GetType() ) + "\"";
|
---|
| 1246 | }
|
---|
| 1247 |
|
---|
| 1248 | return result;
|
---|
| 1249 | }
|
---|
[412] | 1250 | std::string CClass::GetStaticDefiningStringAsMemberOffsets() const
|
---|
| 1251 | {
|
---|
| 1252 | std::string result;
|
---|
[387] | 1253 |
|
---|
[412] | 1254 | BOOST_FOREACH( const CMember *pMember, dynamicMembers )
|
---|
| 1255 | {
|
---|
| 1256 | if( result.size() )
|
---|
| 1257 | {
|
---|
| 1258 | result += ",";
|
---|
| 1259 | }
|
---|
| 1260 |
|
---|
| 1261 | int offset = this->GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 1262 |
|
---|
| 1263 | char temporary[255];
|
---|
| 1264 | itoa( offset, temporary, 16 );
|
---|
| 1265 |
|
---|
| 1266 | result += (std::string)"&H" + temporary;
|
---|
| 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | return result;
|
---|
| 1270 | }
|
---|
[417] | 1271 |
|
---|
| 1272 | void CClass::GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset ) const
|
---|
| 1273 | {
|
---|
| 1274 | const CClass &thisClass = *this;
|
---|
| 1275 | BOOST_FOREACH( const CMember *pMember, thisClass.GetDynamicMembers() )
|
---|
| 1276 | {
|
---|
| 1277 | if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() )
|
---|
| 1278 | {
|
---|
| 1279 | if( referenceOffsetsBuffer.size() )
|
---|
| 1280 | {
|
---|
| 1281 | referenceOffsetsBuffer += ",";
|
---|
| 1282 | }
|
---|
| 1283 |
|
---|
| 1284 | char temp[255];
|
---|
| 1285 | sprintf( temp, "%d", baseOffset + thisClass.GetMemberOffset( pMember->GetName().c_str() ) );
|
---|
| 1286 | referenceOffsetsBuffer += temp;
|
---|
| 1287 |
|
---|
| 1288 | numOfReference++;
|
---|
| 1289 | }
|
---|
| 1290 | if( pMember->GetType().IsStruct() && !pMember->GetType().IsPointer() )
|
---|
| 1291 | {
|
---|
| 1292 | // 構造体の実体をメンバに持つとき
|
---|
| 1293 | int baseOffset = thisClass.GetMemberOffset( pMember->GetName().c_str() );
|
---|
| 1294 |
|
---|
| 1295 | // 構造体メンバでGCによるチェックが必要な参照位置を追加
|
---|
| 1296 | pMember->GetType().GetClass().GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference, baseOffset );
|
---|
| 1297 | }
|
---|
| 1298 | }
|
---|
| 1299 | }
|
---|