source: dev/BasicCompiler_Common/Class.cpp@ 137

Last change on this file since 137 was 137, checked in by dai_9181, 17 years ago

アクセシビリティ周りをリファクタリングした。

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