source: dev/BasicCompiler_Common/Class.cpp@ 141

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

CClass::vtblNumをリファクタリングした。
インターフェイスを継承したとき、Objectクラスがインターフェイスの後ろに配置されてしまうバグを修正(どんなときも、Objectクラスが一番最初に継承されるべき)

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