source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp@ 507

Last change on this file since 507 was 507, checked in by dai_9181, 16 years ago

NamespaceSupporterクラスをab_commonプロジェクトに移動した。

File size: 40.0 KB
Line 
1#include "stdafx.h"
2
3#include <Source.h>
4#include <Class.h>
5#include <Compiler.h>
6
7#include "../common.h"
8#ifdef _AMD64_
9#include "../../compiler_x64/opcode.h"
10#else
11#include "../../compiler_x86/opcode.h"
12#endif
13
14
15Interface::Interface( const CClass *pInterfaceClass, const Types &actualTypeParameters )
16 : DynamicMethodsPrototype()
17 , pInterfaceClass( pInterfaceClass )
18 , vtblOffset( -1 )
19 , actualTypeParameters( actualTypeParameters )
20{
21 //メソッドをコピー
22 BOOST_FOREACH( const CMethod *pBaseMethod, pInterfaceClass->GetDynamicMethods() )
23 {
24 CMethod *pMethod = new DynamicMethod( *pBaseMethod );
25
26 // アクセシビリティ
27 if(pBaseMethod->GetAccessibility() == Prototype::Private){
28 pMethod->SetAccessibility( Prototype::None );
29 }
30 else{
31 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
32 }
33
34 //pobj_Inherits
35 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
36 if(pBaseMethod->GetInheritsClassPtr()==0){
37 pMethod->SetInheritsClassPtr( pInterfaceClass );
38 }
39 else{
40 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
41 }
42
43 AddDynamicMethods( pMethod );
44 }
45}
46
47std::string Interface::GetFullNameWithActualGenericTypeParameters() const
48{
49 std::string interfaceName = this->GetClass().GetFullName();
50 if( actualTypeParameters.size() )
51 {
52 std::string actualGenericTypesName;
53 BOOST_FOREACH( const Type &typeParameter, actualTypeParameters )
54 {
55 if( actualGenericTypesName.size() )
56 {
57 actualGenericTypesName += ",";
58 }
59 actualGenericTypesName += typeParameter.ToString();
60 }
61
62 interfaceName += "<" + actualGenericTypesName + ">";
63 }
64 return interfaceName;
65}
66
67bool CClass::IsClass() const
68{
69 return classType == CClass::Class;
70}
71bool CClass::IsInterface() const
72{
73 return classType == CClass::Interface;
74}
75bool CClass::IsComInterface() const
76{
77 return classType == CClass::ComInterface;
78}
79bool CClass::IsEnum() const
80{
81 return classType == CClass::Enum;
82}
83bool CClass::IsDelegate() const
84{
85 return classType == CClass::Delegate;
86}
87bool CClass::IsStructure() const
88{
89 return classType == CClass::Structure;
90}
91
92
93// コンストラクタのコンパイルを開始
94void CClass::NotifyStartConstructorCompile() const
95{
96 isCompilingConstructor = true;
97}
98
99//コンストラクタのコンパイルを終了
100void CClass::NotifyFinishConstructorCompile() const
101{
102 isCompilingConstructor = false;
103}
104
105//コンストラクタをコンパイル中かどうかを判別
106bool CClass::IsCompilingConstructor() const
107{
108 return isCompilingConstructor;
109}
110
111//デストラクタのコンパイルを開始
112void CClass::NotifyStartDestructorCompile() const{
113 isCompilingDestructor = true;
114}
115
116//デストラクタのコンパイルを終了
117void CClass::NotifyFinishDestructorCompile() const{
118 isCompilingDestructor = false;
119}
120
121//デストラクタをコンパイル中かどうかを判別
122bool CClass::IsCompilingDestructor() const
123{
124 return isCompilingDestructor;
125}
126
127//自身の派生クラスかどうかを確認
128bool CClass::IsSubClass( const CClass *pSubClass ) const
129{
130 if( !pSubClass->HasSuperClass() )
131 {
132 return false;
133 }
134
135 const CClass *pTempClass = &pSubClass->GetSuperClass();
136 while( pTempClass ){
137 if( this == pTempClass ) return true;
138 pTempClass = &pTempClass->GetSuperClass();
139 }
140 return false;
141}
142
143//自身と等しいまたは派生クラスかどうかを確認
144bool CClass::IsEqualsOrSubClass( const CClass *pSubClass ) const
145{
146 if( IsEquals( pSubClass ) ) return true;
147 return IsSubClass( pSubClass );
148}
149
150// 自身と等しいまたは派生クラス、基底クラスかどうかを確認
151bool CClass::IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const
152{
153 if( IsEquals( &objClass ) ) return true;
154 if( IsSubClass( &objClass ) ) return true;
155 if( objClass.IsSubClass( this ) ) return true;
156 return false;
157}
158
159bool CClass::IsInheritsInterface( const CClass *pInterfaceClass ) const
160{
161 BOOST_FOREACH( const ::Interface *pInterface, interfaces ){
162 if( pInterfaceClass == &pInterface->GetClass() ){
163 return true;
164 }
165 }
166 return false;
167}
168
169bool CClass::Inherits( const char *inheritNames, int nowLine ){
170 int i = 0;
171 bool isInheritsClass = false;
172 while( true ){
173
174 char temporary[VN_SIZE];
175 for( int i2=0;; i++, i2++ ){
176 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
177 temporary[i2] = 0;
178 break;
179 }
180 temporary[i2] = inheritNames[i];
181 }
182
183 // ジェネリクス構文を分解
184 char className[VN_SIZE];
185 Jenga::Common::Strings typeParameterStrings;
186 SplitGenericClassInstance( temporary, className, typeParameterStrings );
187
188 // 型パラメータ文字列から型データを取得
189 Types actualTypeParameters;
190 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
191 {
192 Type type;
193 compiler.StringToType( typeParameterStr, type );
194 actualTypeParameters.push_back( type );
195 }
196
197 //継承元クラスを取得
198 const CClass *pInheritsClass = compiler.GetObjectModule().meta.GetClasses().Find(className);
199 if( !pInheritsClass ){
200 compiler.errorMessenger.Output(106,className,nowLine);
201 return false;
202 }
203
204 if( pInheritsClass->IsClass() ){
205 // クラスを継承する
206 isInheritsClass = true;
207
208 if( !InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
209 return false;
210 }
211 }
212 else{
213 compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine);
214 return false;
215 }
216
217 if( inheritNames[i] == '\0' ){
218 break;
219 }
220 i++;
221 }
222
223 if( !isInheritsClass ){
224 // クラスを一つも継承していないとき
225 if( !InheritsClass( *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr(), Types(), nowLine ) ){
226 return false;
227 }
228 }
229
230 return true;
231}
232bool CClass::InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine )
233{
234 //ループ継承でないかをチェック
235 if( !compiler.GetObjectModule().meta.GetClasses().LoopRefCheck(inheritsClass) )
236 {
237 compiler.errorMessenger.Output(123,inheritsClass.GetName(),nowLine);
238 return false;
239 }
240
241 if( !inheritsClass.IsReady() ){
242 //継承先が読み取られていないとき
243 compiler.GetObjectModule().meta.GetClasses().LookaheadClass(inheritsClass.GetName().c_str());
244 }
245
246 //メソッドをコピー
247 BOOST_FOREACH( const CMethod *pBaseMethod, inheritsClass.GetDynamicMethods() ){
248 CMethod *pMethod = new DynamicMethod( *pBaseMethod );
249
250 // アクセシビリティ
251 if(pBaseMethod->GetAccessibility() == Prototype::Private){
252 pMethod->SetAccessibility( Prototype::None );
253 }
254 else{
255 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
256 }
257
258 //pobj_Inherits
259 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
260 if(pBaseMethod->GetInheritsClassPtr()==0){
261 pMethod->SetInheritsClassPtr( &inheritsClass );
262 }
263 else{
264 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
265 }
266
267 GetDynamicMethods().push_back( pMethod );
268 }
269
270 //仮想関数の数
271 AddVtblNum( inheritsClass.GetVtblNum() );
272
273 //継承先のクラスをメンバとして保持する
274 SetSuperClass( &inheritsClass );
275 SetSuperClassActualTypeParameters( actualTypeParameters );
276
277 // インターフェイスを引き継ぐ
278 BOOST_FOREACH( ::Interface *pInterface, inheritsClass.GetInterfaces() )
279 {
280 interfaces.push_back( new ::Interface( *pInterface ) );
281 }
282
283 if( this->IsInterface() && inheritsClass.IsComInterface() )
284 {
285 // COMインターフェイスを継承した場合はCOMインターフェイスにする
286 this->SetClassType( CClass::ComInterface );
287 }
288
289 return true;
290}
291
292bool CClass::Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine )
293{
294 if( !interfaceClass.IsInterface() && !interfaceClass.IsComInterface() )
295 {
296 // インターフェイスではないとき
297 compiler.errorMessenger.Output(138,interfaceClass.GetName().c_str(),nowLine );
298 return false;
299 }
300
301 if( !interfaceClass.IsReady() ){
302 // インターフェイスが未解析のとき
303 compiler.GetObjectModule().meta.GetClasses().LookaheadClass( interfaceClass.GetName().c_str() );
304 }
305
306 ::Interface *pDestInterface = new ::Interface( &interfaceClass, actualTypeParameters );
307
308 interfaces.push_back( pDestInterface );
309
310
311 /////////////////////////////////////////////////////////////////
312 // 基底クラスのメソッドからインターフェイスメソッドを再実装する
313 /////////////////////////////////////////////////////////////////
314 BOOST_FOREACH( CMethod *pMethod, GetDynamicMethods() )
315 {
316 CMethod *pMethodForOverride = pDestInterface->GetDynamicMethods().FindForOverride( pDestInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );
317 if( pMethodForOverride )
318 {
319 pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false );
320
321 // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する)
322 pMethod->SetNotUseMark( true );
323 }
324 }
325
326
327 /////////////////////////////////////////////////////////////////
328 // キャストメソッドを追加(内部コードは自動生成すること)
329 /////////////////////////////////////////////////////////////////
330 if( interfaceClass.IsInterface() )
331 {
332 // Function Operator() As ITest
333
334 char temporary[1024];
335 sprintf(temporary,"%c%c%c%c()%c%c%s",
336 1, ESC_FUNCTION,
337 1, ESC_OPERATOR,
338 1, ESC_AS,
339 pDestInterface->GetFullNameWithActualGenericTypeParameters().c_str()
340 );
341
342 this->AddMethod(this,
343 Prototype::Public,
344 0,
345 false, // isConst
346 false, // isAbstract
347 false, // isVirtual
348 false, // isOverride
349 true, // isAutoGeneration
350 temporary,
351 -1
352 );
353 }
354
355
356 return true;
357}
358bool CClass::Implements( const char *interfaceNames, int nowLine )
359{
360 Jenga::Common::Strings paramStrs;
361 SplitParameter( interfaceNames, paramStrs );
362
363 BOOST_FOREACH( const std::string &paramStr, paramStrs )
364 {
365 char className[VN_SIZE];
366 Jenga::Common::Strings typeParameterStrings;
367 SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings );
368
369 Types actualTypeParameters;
370 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
371 {
372 Type type;
373 compiler.StringToType( typeParameterStr, type );
374 actualTypeParameters.push_back( type );
375 }
376
377 //継承元クラスを取得
378 const CClass *pInterfaceClass = compiler.GetObjectModule().meta.GetClasses().Find( className );
379 if( !pInterfaceClass ){
380 compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine);
381 continue;
382 }
383
384 // インターフェイスを継承する
385 Implements( *pInterfaceClass, actualTypeParameters, nowLine );
386 }
387
388 return true;
389}
390
391CMember *CClass::CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine )
392{
393 extern int cp;
394
395 //構文を解析
396 char VarName[VN_SIZE];
397 char initBuffer[VN_SIZE];
398 char lpszConstructParameter[VN_SIZE];
399 Subscripts subscripts;
400 Type type;
401 GetDimentionFormat(buffer,VarName,subscripts,type,initBuffer,lpszConstructParameter);
402
403 //重複チェック
404 if(this->DupliCheckAll(VarName)){
405 compiler.errorMessenger.Output(15,VarName,cp);
406 }
407
408 CMember *pMember = new CMember( accessibility, VarName, type, isConst, subscripts, initBuffer, lpszConstructParameter );
409 pMember->source_code_address = nowLine;
410 return pMember;
411}
412void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
413 dynamicMembers.push_back(
414 CreateMember( accessibility, isConst, isRef, buffer, nowLine )
415 );
416}
417void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
418 staticMembers.push_back(
419 CreateMember( accessibility, isConst, isRef, buffer, nowLine )
420 );
421}
422
423void CClass::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
424 bool isVirtual, bool isOverride, bool isAutoGeneration, char *buffer, int nowLine){
425 int i,i2;
426 char temporary[VN_SIZE];
427
428 i=2;
429 for(i2=0;;i++,i2++){
430 if(buffer[i]=='('||buffer[i]=='\0'){
431 temporary[i2]=0;
432 break;
433 }
434 temporary[i2]=buffer[i];
435 }
436
437
438 //関数ハッシュへ登録
439 char interfaceName[VN_SIZE] = "";
440 UserProc *pUserProc = compiler.GetObjectModule().meta.GetUserProcs().AddUserProc( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0), interfaceName );
441 if(!pUserProc) return;
442
443 if( isAutoGeneration )
444 {
445 // コード自動生成
446 pUserProc->ThisIsAutoGenerationProc();
447 }
448
449
450 ////////////////////////////////////////////////////////////
451 // コンストラクタ、デストラクタの場合の処理
452 ////////////////////////////////////////////////////////////
453 BOOL fConstructor=0,bDestructor=0;
454
455 if(lstrcmp(temporary,pobj_c->GetName().c_str())==0){
456 //コンストラクタの場合
457
458 //標準コンストラクタ(引数なし)
459 if(pUserProc->Params().size()==0) fConstructor=1;
460
461 //強制的にConst修飾子をつける
462 isConst = true;
463 }
464 else if(temporary[0]=='~'){
465 //デストラクタの場合はその名前が正しいかチェックを行う
466 if(lstrcmp(temporary+1,pobj_c->GetName().c_str())!=0)
467 compiler.errorMessenger.Output(117,NULL,nowLine);
468 else
469 bDestructor=1;
470 }
471 if(fConstructor||bDestructor){
472 // コンストラクタ、デストラクタのアクセシビリティをチェック
473
474 //強制的にConst修飾子をつける
475 isConst = true;
476 }
477
478 if( fConstructor == 1 )
479 pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
480 else if( bDestructor )
481 pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
482
483
484
485 //////////////////
486 // 重複チェック
487 //////////////////
488
489 if(pobj_c->DupliCheckMember(temporary)){
490 compiler.errorMessenger.Output(15,temporary,nowLine);
491 return;
492 }
493
494 //メソッド
495 BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() )
496 {
497 //基底クラスと重複する場合はオーバーライドを行う
498 if( pMethod->GetInheritsClassPtr() ) continue;
499
500 if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) )
501 {
502 //関数名、パラメータ、戻り値が合致したとき
503 compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);
504 return;
505 }
506 }
507
508 //仮想関数の場合
509 if( isAbstract ) pUserProc->CompleteCompile();
510
511 // メソッドのオーバーライド
512 CMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );
513 if( pMethodForOverride )
514 {
515 pMethodForOverride->Override( pUserProc, accessibility, isOverride );
516 pUserProc->SetMethod( pMethodForOverride );
517 return;
518 }
519 else
520 {
521 // インターフェイス メソッドのオーバーライド
522 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )
523 {
524 if( interfaceName[0] )
525 {
526 if( pInterface->GetClass().GetName() != interfaceName )
527 {
528 // 指定されたインターフェイス名と整合しないとき
529 continue;
530 }
531 }
532
533 if( !pInterface->GetClass().IsReady() ){
534 // インターフェイスが未解析のとき
535 compiler.GetObjectModule().meta.GetClasses().LookaheadClass( pInterface->GetClass().GetName().c_str() );
536 }
537
538 CMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );
539 if( pMethodForOverride )
540 {
541 pMethodForOverride->Override( pUserProc, accessibility, isOverride );
542 pUserProc->SetMethod( pMethodForOverride );
543 return;
544 }
545 }
546 }
547
548 if( interfaceName[0] )
549 {
550 compiler.errorMessenger.Output(139,interfaceName,nowLine);
551 }
552
553 if( isVirtual ){
554 pobj_c->AddVtblNum( 1 );
555 }
556
557 if( isOverride ){
558 compiler.errorMessenger.Output(12,"Override",nowLine);
559 }
560
561 if(bStatic){
562 pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility );
563 }
564 else{
565 pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
566 }
567}
568
569bool CClass::DupliCheckAll(const char *name) const
570{
571 //重複チェック
572
573 //メンバ
574 if(DupliCheckMember(name)) return 1;
575
576 //メソッド
577 BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
578 if( lstrcmp( name, pMethod->GetUserProc().GetName().c_str() ) == 0 ){
579 return 1;
580 }
581 }
582
583 return 0;
584}
585bool CClass::DupliCheckMember(const char *name) const
586{
587 //重複チェック
588
589 if( this->HasSuperClass() )
590 {
591 if( this->GetSuperClass().DupliCheckMember( name ) )
592 {
593 // 基底クラスで重複が発見された
594 return true;
595 }
596 }
597
598 // 動的メンバ
599 BOOST_FOREACH( CMember *pMember, dynamicMembers )
600 {
601 if( GetName() == pMember->GetName() )
602 {
603 return true;
604 }
605 }
606
607 // 静的メンバ
608 BOOST_FOREACH( CMember *pMember, staticMembers ){
609 if( GetName() == pMember->GetName() ){
610 return true;
611 }
612 }
613
614 return false;
615}
616
617const CMember *CClass::FindDynamicMember( const char *memberName ) const
618{
619 if( this->HasSuperClass() )
620 {
621 // 基底クラスで検索
622 const CMember *result = this->GetSuperClass().FindDynamicMember( memberName );
623 if( result )
624 {
625 return result;
626 }
627 }
628
629 BOOST_FOREACH( CMember *pMember, GetDynamicMembers() )
630 {
631 if( pMember->GetName() == memberName )
632 {
633 return pMember;
634 }
635 }
636 return NULL;
637}
638
639void CClass::EnumDynamicMethodsOrInterfaceMethods( const char *methodName, std::vector<const UserProc *> &subs ) const
640{
641 // 動的メソッド
642 GetDynamicMethods().Enum( methodName, subs );
643
644 // インターフェイス メソッド
645 BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
646 {
647 pInterface->GetDynamicMethods().Enum( methodName, subs );
648 }
649}
650const CMethod *CClass::GetDynamicMethodOrInterfaceMethod( const UserProc *pUserProc ) const
651{
652 // 動的メソッド
653 const CMethod *result = GetDynamicMethods().GetMethodPtr( pUserProc );
654
655 if( !result )
656 {
657 // インターフェイス メソッド
658 BOOST_FOREACH( ::Interface *pInterface, GetInterfaces() )
659 {
660 result = pInterface->GetDynamicMethods().GetMethodPtr( pUserProc );
661 if( result )
662 {
663 return result;
664 }
665 }
666 }
667
668 return result;
669}
670
671const ::Delegate &CClass::GetDelegate() const
672{
673 const ::Delegate *dg = compiler.GetObjectModule().meta.GetDelegates().GetHashArrayElement( GetName().c_str() );
674 while( dg )
675 {
676 if( dg->IsEqualSymbol( GetNamespaceScopes(), GetName() ) ){
677 //名前空間とクラス名が一致した
678 return *dg;
679 }
680 dg = dg->GetChainNext();
681 }
682
683 Jenga::Throw( "CClass::GetDelegateメソッドに失敗" );
684 static ::Delegate dummy;
685 return dummy;
686}
687
688//サイズを取得
689int CClass::GetSize() const
690{
691 int resultSize = 0;
692
693 int alignment = 1;
694 if( this->IsStructure() )
695 {
696 // 構造体のとき
697
698 if( this->GetFixedAlignment() )
699 {
700 // アラインメントの固定値が指定されていた場合はそれを取得
701 alignment = this->GetFixedAlignment();
702 }
703 }
704 else
705 {
706 // それ以外
707
708 if( this->HasSuperClass() )
709 {
710 // 基底クラスのサイズを追加
711 resultSize += this->GetSuperClass().GetSize();
712
713 // 基底クラスのアラインメントを取得
714 alignment = this->GetSuperClass().GetAlignment();
715 }
716 else
717 {
718 // 基底クラスが存在しないとき
719
720 // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
721 resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
722 }
723 }
724
725 BOOST_FOREACH( CMember *pMember, dynamicMembers )
726 {
727 // メンバサイズ
728 int tempMemberSize = pMember->GetType().GetSize();
729
730 // 一時アラインメントを算出
731 int tempAlignment = tempMemberSize;
732 if( pMember->GetType().IsStruct() )
733 {
734 // メンバが構造体の場合は、メンバのアラインメントを取得
735 tempAlignment = pMember->GetType().GetClass().GetAlignment();
736 }
737
738 // アラインメントを考慮してパディングを追加
739 if( GetFixedAlignment() && alignment < tempAlignment )
740 {
741 if( resultSize % alignment )
742 {
743 resultSize += alignment - ( resultSize % alignment );
744 }
745 }
746 else
747 {
748 if( alignment < tempAlignment )
749 {
750 // 最大アラインメントを更新
751 alignment = tempAlignment;
752 }
753
754 if( tempMemberSize == 0 )
755 {
756 if( !pMember->GetType().IsStruct() )
757 {
758 compiler.errorMessenger.OutputFatalError();
759 }
760
761 //メンバを持たない構造体
762 //※何もしない(オフセットの計算をしない)
763 }
764 else{
765 if( resultSize % tempAlignment )
766 {
767 resultSize += tempAlignment - ( resultSize % tempAlignment );
768 }
769 }
770 }
771
772 // メンバサイズを加算(配列を考慮)
773 resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
774 }
775
776 if( alignment )
777 {
778 // 末尾アラインメントを考慮してパディングを追加
779 if( resultSize % alignment )
780 {
781 resultSize += alignment - ( resultSize % alignment );
782 }
783 }
784
785 return resultSize;
786}
787
788//メンバのオフセットを取得
789int CClass::GetMemberOffset( const char *memberName ) const
790{
791 int resultSize = 0;
792
793 int alignment = 1;
794 if( this->IsStructure() )
795 {
796 // 構造体のとき
797
798 if( this->GetFixedAlignment() )
799 {
800 // アラインメントの固定値が指定されていた場合はそれを取得
801 alignment = this->GetFixedAlignment();
802 }
803 }
804 else
805 {
806 // それ以外
807
808 if( this->HasSuperClass() )
809 {
810 if( this->GetSuperClass().HasDynamicMember( memberName ) )
811 {
812 // 基底クラスのメンバを取得
813 return this->GetSuperClass().GetMemberOffset( memberName );
814 }
815
816 // 基底クラスのサイズを追加
817 resultSize += this->GetSuperClass().GetSize();
818
819 // 基底クラスのアラインメントを取得
820 alignment = this->GetSuperClass().GetAlignment();
821 }
822 else
823 {
824 // 基底クラスが存在しないとき
825
826 // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
827 resultSize += IsExistVirtualFunctions() ? PTR_SIZE*2 : 0;
828 }
829 }
830
831 BOOST_FOREACH( CMember *pMember, dynamicMembers )
832 {
833 // メンバサイズ
834 int tempMemberSize = pMember->GetType().GetSize();
835
836 // 一時アラインメントを算出
837 int tempAlignment = tempMemberSize;
838 if( pMember->GetType().IsStruct() )
839 {
840 // メンバが構造体の場合は、メンバのアラインメントを取得
841 tempAlignment = pMember->GetType().GetClass().GetAlignment();
842 }
843
844 // アラインメントを考慮してパディングを追加
845 if( GetFixedAlignment() && alignment < tempAlignment )
846 {
847 if( resultSize % alignment )
848 {
849 resultSize += alignment - ( resultSize % alignment );
850 }
851 }
852 else
853 {
854 if( alignment < tempAlignment )
855 {
856 // 最大アラインメントを更新
857 alignment = tempAlignment;
858 }
859
860 if( tempMemberSize == 0 )
861 {
862 if( !pMember->GetType().IsStruct() )
863 {
864 compiler.errorMessenger.OutputFatalError();
865 }
866
867 //メンバを持たない構造体
868 //※何もしない(オフセットの計算をしない)
869 }
870 else{
871 if( resultSize % tempAlignment )
872 {
873 resultSize += tempAlignment - ( resultSize % tempAlignment );
874 }
875 }
876 }
877
878 if(memberName){
879 //メンバ指定がある場合は、オフセットを返す
880 if( pMember->GetName() == memberName )
881 {
882 return resultSize;
883 }
884 }
885
886 // メンバサイズを加算(配列を考慮)
887 resultSize += tempMemberSize * Variable::GetSubScriptCounts( pMember->GetSubscripts() );
888 }
889
890 if( alignment )
891 {
892 // 末尾アラインメントを考慮してパディングを追加
893 if( resultSize % alignment )
894 {
895 resultSize += alignment - ( resultSize % alignment );
896 }
897 }
898
899 return resultSize;
900}
901int CClass::GetAlignment() const
902{
903 int alignment = 1;
904 if( this->IsStructure() )
905 {
906 // 構造体のとき
907
908 if( this->GetFixedAlignment() )
909 {
910 // アラインメントの固定値が指定されていた場合はそれを取得
911 return this->GetFixedAlignment();
912 }
913 }
914 else
915 {
916 // それ以外
917
918 if( this->HasSuperClass() )
919 {
920 // 基底クラスのアラインメントを取得
921 alignment = this->GetSuperClass().GetAlignment();
922 }
923 else
924 {
925 // 基底クラスが存在しないとき
926
927 // 仮想関数が存在する場合はvtbl及びvtblMasterListへのポインタのサイズを追加
928 alignment = PTR_SIZE;
929 }
930 }
931
932 BOOST_FOREACH( CMember *pMember, dynamicMembers )
933 {
934 int tempAlignment = pMember->GetType().GetSize();
935 if( pMember->GetType().IsStruct() )
936 {
937 // メンバが構造体の場合は、メンバのアラインメントを取得
938 tempAlignment = pMember->GetType().GetClass().GetAlignment();
939 }
940
941 if( alignment < tempAlignment )
942 {
943 // 最大アラインメントを更新
944 alignment = tempAlignment;
945 }
946 }
947
948 return alignment;
949}
950
951void CClass::GetVtblMasterListIndexAndVtblIndex( const UserProc *pUserProc, int &vtblMasterListIndex, int &vtblIndex ) const
952{
953 vtblMasterListIndex = 0;
954
955 vtblIndex = 0;
956 BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
957 if( &pMethod->GetUserProc() == pUserProc )
958 {
959 return;
960 }
961
962 if( pMethod->IsVirtual() )
963 {
964 vtblIndex++;
965 }
966 }
967
968 BOOST_FOREACH( const ::Interface *pInterface, interfaces )
969 {
970 vtblMasterListIndex++;
971
972 vtblIndex = 0;
973 BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
974 if( &pMethod->GetUserProc() == pUserProc )
975 {
976 return;
977 }
978
979 if( pMethod->IsVirtual() )
980 {
981 vtblIndex++;
982 }
983 }
984 }
985
986 compiler.errorMessenger.OutputFatalError();
987 return;
988}
989int CClass::GetVtblMasterListIndex( const CClass *pClass ) const
990{
991 int result = 0;
992
993 BOOST_FOREACH( const ::Interface *pInterface, interfaces )
994 {
995 result++;
996
997 if( &pInterface->GetClass() == pClass )
998 {
999 return result;
1000 }
1001 }
1002
1003 compiler.errorMessenger.OutputFatalError();
1004 return 0;
1005}
1006long CClass::GetComVtblOffset() const
1007{
1008 return comVtblOffset;
1009}
1010long CClass::GetVtblMasterListOffset() const
1011{
1012 //既に存在する場合はそれを返す
1013 if( vtblMasterListOffset == -1 )
1014 {
1015 compiler.errorMessenger.OutputFatalError();
1016 }
1017
1018 return vtblMasterListOffset;
1019}
1020void CClass::GenerateVTableMasterList( const std::vector<long> &vtableMasterList, long &offset )
1021{
1022 offset = compiler.GetObjectModule().dataTable.AddBinary(
1023 (void *)&vtableMasterList[0],
1024 static_cast<int>(vtableMasterList.size()*sizeof(LONG_PTR))
1025 );
1026}
1027void CClass::GenerateFullVTables()
1028{
1029 if( IsAbstract() )
1030 {
1031 // 抽象クラスは無視
1032 return;
1033 }
1034 if( !IsUsing() )
1035 {
1036 // 使われていないクラスは無視
1037 return;
1038 }
1039
1040 // vtblマスターリストの元データに不要なデータが含まれていたらエラー
1041 if( vtblMasterList.size() )
1042 {
1043 compiler.errorMessenger.OutputFatalError();
1044 }
1045
1046 // 自身のクラスのvtblを生成
1047 GetDynamicMethods().GenerateVTablePart( this->vtbl_offset );
1048 vtblMasterList.push_back( this->vtbl_offset );
1049
1050 // インターフェイスのvtblを生成
1051 BOOST_FOREACH( const ::Interface *pInterface, interfaces )
1052 {
1053 long tempVtblOffset;
1054 pInterface->GetDynamicMethods().GenerateVTablePart( tempVtblOffset );
1055 vtblMasterList.push_back( tempVtblOffset );
1056
1057 pInterface->SetVtblOffset( tempVtblOffset );
1058
1059 if( pInterface->GetClass().IsComInterface() )
1060 {
1061 if( this->comVtblOffset )
1062 {
1063 compiler.errorMessenger.OutputFatalError();
1064 }
1065 this->comVtblOffset = tempVtblOffset;
1066 }
1067 }
1068
1069 // vtblマスターリストを生成
1070 GenerateVTableMasterList( vtblMasterList, this->vtblMasterListOffset );
1071}
1072void CClass::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection )
1073{
1074 if( IsAbstract() )
1075 {
1076 // 抽象クラスは無視
1077 return;
1078 }
1079 if( !IsUsing() )
1080 {
1081 // 使われていないクラスは無視
1082 return;
1083 }
1084 if(vtbl_offset==-1) return;
1085
1086 // 自身のクラスのvtbl
1087 {
1088 LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtbl_offset);
1089
1090 for( int i=0; i<GetVtblNum(); i++ ){
1091 const UserProc *pUserProc = (UserProc *)pVtbl[i];
1092 if(!pUserProc) continue;
1093
1094 if( pUserProc->GetBeginOpAddress() == 0
1095 && pUserProc->GetEndOpAddress() == 0 )
1096 {
1097 Jenga::Throw( "未解決の仮想関数が存在する" );
1098 }
1099
1100 pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
1101 }
1102 }
1103
1104 // インターフェイスのvtbl
1105 BOOST_FOREACH( const ::Interface *pInterface, interfaces )
1106 {
1107 LONG_PTR *pVtbl = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + pInterface->GetVtblOffset());
1108
1109 for( int i=0; i<pInterface->GetClass().GetVtblNum(); i++ ){
1110 const UserProc *pUserProc = (UserProc *)pVtbl[i];
1111 if(!pUserProc) continue;
1112
1113 if( pUserProc->GetBeginOpAddress() == 0
1114 && pUserProc->GetEndOpAddress() == 0 )
1115 {
1116 Jenga::Throw( "未解決の仮想関数が存在する" );
1117 }
1118
1119 pVtbl[i] = pUserProc->GetBeginOpAddress() + ImageBase + MemPos_CodeSection;
1120 }
1121 }
1122
1123 // vtblマスターリスト
1124 LONG_PTR *pVtblMasterList = (LONG_PTR *)((char *)compiler.GetObjectModule().dataTable.GetPtr() + vtblMasterListOffset );
1125 for( int i=0; i<static_cast<int>(vtblMasterList.size()); i++ )
1126 {
1127 pVtblMasterList[i] = vtblMasterList[i] + ImageBase + MemPos_DataSection;
1128 }
1129}
1130bool CClass::IsAbstract() const
1131{
1132 // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
1133
1134 BOOST_FOREACH( const CMethod *pMethod, GetDynamicMethods() ){
1135 if(pMethod->IsVirtual()){
1136 if(pMethod->IsAbstract()){
1137 return true;
1138 }
1139 }
1140 }
1141
1142 // インターフェイスのvtbl
1143 BOOST_FOREACH( const ::Interface *pInterface, interfaces )
1144 {
1145 BOOST_FOREACH( const CMethod *pMethod, pInterface->GetDynamicMethods() ){
1146 if(pMethod->IsVirtual()){
1147 if(pMethod->IsAbstract()){
1148 return true;
1149 }
1150 }
1151 }
1152 }
1153
1154 return false;
1155}
1156
1157CClass *Classes::Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name){
1158 return new CClass(namespaceScopes, importedNamespaces, name);
1159}
1160bool Classes::Insert( CClass *pClass, int nowLine )
1161{
1162 /////////////////////////////////
1163 // ハッシュデータに追加
1164 /////////////////////////////////
1165
1166 if( !Put( pClass ) )
1167 {
1168 compiler.errorMessenger.Output(15,pClass->GetName(), nowLine);
1169 return false;
1170 }
1171 return true;
1172}
1173CClass *Classes::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
1174 //////////////////////////////////////////////////////////////////////////
1175 // クラスを追加
1176 // ※名前のみを登録。その他の情報はSetClassメソッドで!
1177 //////////////////////////////////////////////////////////////////////////
1178
1179 CClass *pClass = Create(namespaceScopes, importedNamespaces, name);
1180
1181 if( !Insert( pClass, nowLine ) )
1182 {
1183 return NULL;
1184 }
1185
1186 return pClass;
1187}
1188
1189void Classes::GenerateVTables()
1190{
1191 Iterator_Reset();
1192 while( Iterator_HasNext() )
1193 {
1194 CClass *pClass = Iterator_GetNext();
1195 pClass->GenerateFullVTables();
1196 }
1197}
1198
1199void Classes::ActionVtblSchedule( LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection, LONG_PTR MemPos_DataSection ){
1200 Iterator_Reset();
1201 while( Iterator_HasNext() )
1202 {
1203 CClass *pClass = Iterator_GetNext();
1204 pClass->ActionVtblSchedule( ImageBase, MemPos_CodeSection, MemPos_DataSection);
1205 }
1206}
1207
1208
1209void Classes::InitStaticMember(){
1210 //静的メンバをグローバル領域に作成
1211
1212 //イテレータをリセット
1213
1214 extern int cp;
1215 int back_cp=cp;
1216
1217 this->Iterator_Reset();
1218 while(this->Iterator_HasNext()){
1219 CClass &objClass = *this->Iterator_GetNext();
1220 if( objClass.isTargetObjectModule == false )
1221 {
1222 // 静的リンクライブラリの場合は飛ばす(既にインスタンスが定義済みであるため)
1223 continue;
1224 }
1225
1226 // 名前空間をセット
1227 compiler.GetNamespaceSupporter().GetLivingNamespaceScopes() = objClass.GetNamespaceScopes();
1228
1229 DWORD dwFlags = 0;
1230 if( objClass.GetName() == "_System_TypeBase" )
1231 {
1232 // _System_TypeBaseクラスはグローバル、スタティック領域を初期化するためのクラスなのでここでの初期化は除外する
1233 dwFlags |= DIMFLAG_NONCALL_CONSTRACTOR;
1234 }
1235
1236 // コンパイル中クラスとしてセット
1237 compiler.pCompilingClass = &objClass;
1238
1239 const EnumInfo *pEnumInfo = NULL;
1240 if( objClass.IsEnum() )
1241 {
1242 pEnumInfo = compiler.enumInfoCollection.Find( objClass );
1243 }
1244
1245 int i=0;
1246 BOOST_FOREACH( CMember *member, objClass.GetStaticMembers() )
1247 {
1248 if( pEnumInfo )
1249 {
1250 cp = pEnumInfo->GetEnumMember( member->GetName() ).GetSourceIndex();
1251 }
1252
1253 char temporary[VN_SIZE];
1254 sprintf(temporary,"%s.%s",objClass.GetName().c_str(),member->GetName().c_str());
1255 dim(
1256 temporary,
1257 member->GetSubscripts(),
1258 member->GetType(),
1259 member->GetInitializeExpression().c_str(),
1260 member->GetConstructParameter().c_str(),
1261 dwFlags);
1262
1263 i++;
1264 }
1265
1266 compiler.pCompilingClass = NULL;
1267 }
1268
1269 compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().clear();
1270
1271 cp=back_cp;
1272}
1273
1274void Classes::Compile_System_InitializeUserTypes(){
1275 char temporary[VN_SIZE];
1276
1277 ////////////////////////////////////////////////////////////////////
1278 // クラス登録
1279 ////////////////////////////////////////////////////////////////////
1280
1281 // イテレータをリセット
1282 Iterator_Reset();
1283
1284 while( Iterator_HasNext() ){
1285 const CClass &objClass = *Iterator_GetNext();
1286
1287 if( !objClass.IsUsing() ){
1288 // 未使用のクラスは無視する
1289 continue;
1290 }
1291
1292 std::string referenceOffsetsBuffer;
1293 int numOfReference = 0;
1294 objClass.GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference );
1295
1296 sprintf( temporary
1297 , "Add(%c%c_System_TypeForClass[strNamespace=\"%s\",name=\"%s\",fullName=\"%s\",referenceOffsets=[%s],numOfReference=%d])"
1298 , 1
1299 , ESC_SYSTEM_STATIC_NEW
1300 , objClass.GetNamespaceScopes().ToString().c_str() // 名前空間
1301 , objClass.GetName().c_str() // クラス名
1302 , objClass.GetFullName().c_str() // フルネーム
1303 , referenceOffsetsBuffer.c_str() // 参照メンバオフセット配列
1304 , numOfReference // 参照メンバの個数
1305 );
1306
1307 // コンパイル
1308 ChangeOpcode( temporary );
1309
1310 objClass.SetTypeInfoDataTableOffset(
1311 compiler.GetObjectModule().dataTable.GetLastMadeConstObjectDataTableOffset()
1312 );
1313 }
1314}
1315void Classes::Compile_System_InitializeUserTypesForBaseType()
1316{
1317 extern int cp;
1318 cp = -1;
1319 ////////////////////////////////////////////////////////////////////
1320 // 基底クラスを登録
1321 ////////////////////////////////////////////////////////////////////
1322
1323 char temporary[8192];
1324 sprintf(temporary, "%c%ctempType=Nothing%c%c_System_TypeForClass"
1325 , HIBYTE( COM_DIM )
1326 , LOBYTE( COM_DIM )
1327 , 1
1328 , ESC_AS
1329 );
1330 ChangeOpcode( temporary );
1331
1332 // イテレータをリセット
1333 Iterator_Reset();
1334
1335 while( Iterator_HasNext() ){
1336 const CClass &objClass = *Iterator_GetNext();
1337
1338 if( !objClass.IsUsing() ){
1339 // 未使用のクラスは無視する
1340 continue;
1341 }
1342
1343 if( objClass.HasSuperClass() || objClass.GetDynamicMembers().size() ){
1344 sprintf( temporary
1345 , "tempType=Search(\"%s\") As ActiveBasic.Core._System_TypeForClass"
1346 , objClass.GetFullName().c_str()
1347 );
1348
1349 // コンパイル
1350 MakeMiddleCode( temporary );
1351 ChangeOpcode( temporary );
1352
1353 sprintf( temporary
1354 , "tempType.SetClassInfo(%d,_System_GetComVtbl(%s),_System_GetVtblList(%s),_System_GetDefaultConstructor(%s),_System_GetDestructor(%s))"
1355 , objClass.GetSize()
1356 , objClass.GetFullName().c_str()
1357 , objClass.GetFullName().c_str()
1358 , objClass.GetFullName().c_str()
1359 , objClass.GetFullName().c_str()
1360 , objClass.GetName().c_str()
1361 );
1362
1363 // コンパイル
1364 ChangeOpcode( temporary );
1365
1366 if( objClass.HasSuperClass() )
1367 {
1368 sprintf( temporary
1369 , "tempType.SetBaseType(Search(\"%s\"))"
1370 , objClass.GetSuperClass().GetFullName().c_str()
1371 );
1372
1373 // コンパイル
1374 ChangeOpcode( temporary );
1375 }
1376
1377 if( objClass.GetDynamicMembers().size() )
1378 {
1379 // メンバの型を示すTypeInfoオブジェクトへのDataOffset配列の静的データ定義文字列を取得
1380 sprintf(
1381 temporary,
1382 "tempType.SetMembers([%s],[%s],[%s],%d)",
1383 objClass.GetStaticDefiningStringAsMemberNames().c_str(),
1384 objClass.GetStaticDefiningStringAsMemberTypeInfoNames().c_str(),
1385 objClass.GetStaticDefiningStringAsMemberOffsets().c_str(),
1386 objClass.GetDynamicMembers().size()
1387 );
1388 ChangeOpcode( temporary );
1389 }
1390 }
1391 }
1392}
1393
1394const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const string &name ) const
1395{
1396 if( namespaceScopes.size() == 0 && name == "Object" ){
1397 return GetObjectClassPtr();
1398 }
1399 else if( namespaceScopes.size() == 0 && name == "String" ){
1400 return GetStringClassPtr();
1401 }
1402
1403 std::vector<const CClass *> classes;
1404 const CClass *pClass = GetHashArrayElement( name.c_str() );
1405 while( pClass )
1406 {
1407 if( pClass->IsEqualSymbol( namespaceScopes, name ) ){
1408 //名前空間とクラス名が一致した
1409 classes.push_back( pClass );
1410 }
1411 pClass = pClass->GetChainNext();
1412 }
1413 if( classes.size() > 0 )
1414 {
1415 // 複数の名前空間の中に同一のクラス名が存在する場合があるので、アクセス可能で尚且つ階層が一番深いものをチョイスする
1416 pClass = classes.front();
1417
1418 BOOST_FOREACH( const CClass *pTempClass, classes )
1419 {
1420 if( pClass->GetNamespaceScopes().size() < pTempClass->GetNamespaceScopes().size() )
1421 {
1422 pClass = pTempClass;
1423 }
1424 }
1425
1426 return pClass;
1427 }
1428
1429 // TypeDefも見る
1430 int index = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( namespaceScopes, name );
1431 if( index != -1 ){
1432 Type type = compiler.GetObjectModule().meta.GetTypeDefs()[index].GetBaseType();
1433 if( type.IsObject() ){
1434 return &type.GetClass();
1435 }
1436 }
1437
1438 return NULL;
1439}
1440const CClass *Classes::Find( const string &fullName ) const
1441{
1442 char AreaName[VN_SIZE] = ""; //オブジェクト変数
1443 char NestName[VN_SIZE] = ""; //入れ子メンバ
1444 bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
1445
1446 return Find( NamespaceScopes( AreaName ), NestName );
1447}
1448void Classes::StartCompile( const UserProc *pUserProc ){
1449 const CClass *pParentClass = pUserProc->GetParentClassPtr();
1450 if( pParentClass ){
1451 pParentClass->Using();
1452
1453 // 仮想関数になるメソッドに使用チェックをつける
1454 BOOST_FOREACH( const CMethod *pMethod, pParentClass->GetDynamicMethods() )
1455 {
1456 if( pMethod->IsVirtual() )
1457 {
1458 pMethod->GetUserProc().Using();
1459 }
1460 }
1461
1462 pCompilingMethod = pParentClass->GetDynamicMethodOrInterfaceMethod( pUserProc );
1463 if( !pCompilingMethod ){
1464 pCompilingMethod = pParentClass->GetStaticMethods().GetMethodPtr( pUserProc );
1465 if( !pCompilingMethod ){
1466 compiler.errorMessenger.OutputFatalError();
1467 }
1468 }
1469 }
1470 else{
1471 pCompilingMethod = NULL;
1472 }
1473}
1474
1475const CClass *Classes::GetStringClassPtr() const
1476{
1477 if( !pStringClass ){
1478 // キャッシュしておく
1479 pStringClass = this->Find( NamespaceScopes( "System" ), "String" );
1480
1481 if( !pStringClass )
1482 {
1483 compiler.errorMessenger.Output(400, "System.String", cp);
1484 static CClass dummy;
1485 return &dummy;
1486 }
1487 return pStringClass;
1488 }
1489 return pStringClass;
1490}
1491const CClass *Classes::GetObjectClassPtr() const
1492{
1493 if( !pObjectClass ){
1494 // キャッシュしておく
1495 pObjectClass = this->Find( NamespaceScopes( "System" ), "Object" );
1496
1497 if( !pObjectClass )
1498 {
1499 compiler.errorMessenger.Output(400, "System.Object", cp);
1500 static CClass dummy;
1501 return &dummy;
1502 }
1503 return pObjectClass;
1504 }
1505 return pObjectClass;
1506}
1507const CClass *Classes::GetInterfaceInfoClassPtr() const
1508{
1509 if( !pInterfaceInfo ){
1510 // キャッシュしておく
1511 pInterfaceInfo = this->Find( "ActiveBasic.Core.InterfaceInfo" );
1512
1513 if( !pInterfaceInfo )
1514 {
1515 compiler.errorMessenger.Output(400, "ActiveBasic.Core.InterfaceInfo", cp);
1516 static CClass dummy;
1517 return &dummy;
1518 }
1519 return pInterfaceInfo;
1520 }
1521 return pInterfaceInfo;
1522}
1523
1524std::string CClass::GetStaticDefiningStringAsMemberNames() const
1525{
1526 std::string result;
1527
1528 BOOST_FOREACH( const CMember *pMember, dynamicMembers )
1529 {
1530 if( result.size() )
1531 {
1532 result += ",";
1533 }
1534
1535 result += "\"" + pMember->GetName() + "\"";
1536 }
1537
1538 return result;
1539}
1540std::string CClass::GetStaticDefiningStringAsMemberTypeInfoNames() const
1541{
1542 std::string result;
1543
1544 BOOST_FOREACH( const CMember *pMember, dynamicMembers )
1545 {
1546 if( result.size() )
1547 {
1548 result += ",";
1549 }
1550
1551 result += "\"" + compiler.TypeToString( pMember->GetType() ) + "\"";
1552 }
1553
1554 return result;
1555}
1556std::string CClass::GetStaticDefiningStringAsMemberOffsets() const
1557{
1558 std::string result;
1559
1560 BOOST_FOREACH( const CMember *pMember, dynamicMembers )
1561 {
1562 if( result.size() )
1563 {
1564 result += ",";
1565 }
1566
1567 int offset = this->GetMemberOffset( pMember->GetName().c_str() );
1568
1569 char temporary[255];
1570 itoa( offset, temporary, 16 );
1571
1572 result += (std::string)"&H" + temporary;
1573 }
1574
1575 return result;
1576}
1577
1578void CClass::GetReferenceOffsetsInitializeBuffer( std::string &referenceOffsetsBuffer, int &numOfReference, int baseOffset ) const
1579{
1580 const CClass &thisClass = *this;
1581 BOOST_FOREACH( const CMember *pMember, thisClass.GetDynamicMembers() )
1582 {
1583 if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() )
1584 {
1585 if( referenceOffsetsBuffer.size() )
1586 {
1587 referenceOffsetsBuffer += ",";
1588 }
1589
1590 char temp[255];
1591 sprintf( temp, "%d", baseOffset + thisClass.GetMemberOffset( pMember->GetName().c_str() ) );
1592 referenceOffsetsBuffer += temp;
1593
1594 numOfReference++;
1595 }
1596 if( pMember->GetType().IsStruct() && !pMember->GetType().IsPointer() )
1597 {
1598 // 構造体の実体をメンバに持つとき
1599 int baseOffset = thisClass.GetMemberOffset( pMember->GetName().c_str() );
1600
1601 // 構造体メンバでGCによるチェックが必要な参照位置を追加
1602 pMember->GetType().GetClass().GetReferenceOffsetsInitializeBuffer( referenceOffsetsBuffer, numOfReference, baseOffset );
1603 }
1604 }
1605}
Note: See TracBrowser for help on using the repository browser.