source: dev/BasicCompiler_Common/Class.cpp@ 117

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

String/ObjectをSystem名前空間に依存しない特殊型として扱うようにした

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