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
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 )
17 : Prototype( namespaceScopes, name )
[108]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 )
[90]31{
[4]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
[53]45 //静的メンバ
46 foreach( CMember *member, staticMembers ){
47 delete member;
[4]48 }
49}
[64]50
[131]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
[90]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}
[64]77bool CClass::IsStructure() const
78{
79 return classType == CClass::Structure;
80}
81
[131]82bool CClass::Inherits( const char *inheritNames, int nowLine ){
83 int i = 0;
84 bool isInheritsClass = false;
85 while( true ){
[29]86
[131]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
[90]145 //ループ継承でないかをチェック
146 if(pobj_LoopRefCheck->check(inheritsClass)){
[131]147 SetError(123,inheritsClass.GetName(),nowLine);
[90]148 return false;
149 }
150
151 if( inheritsClass.ppobj_Member == 0 ){
152 //継承先が読み取られていないとき
[131]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());
[90]156 }
157
[29]158 //メンバをコピー
159 ppobj_Member=(CMember **)HeapReAlloc(
160 hHeap,
161 0,
162 ppobj_Member,
[90]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] );
[29]166
[137]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 }
[90]174
175 iMemberNum++;
[29]176 }
177
178 //メソッドをコピー
[135]179 foreach( const CMethod *pBaseMethod, inheritsClass.methods ){
180 CMethod *pMethod = new DynamicMethod( *pBaseMethod );
[29]181
[137]182 // アクセシビリティ
183 if(pBaseMethod->GetAccessibility() == Prototype::Private){
184 pMethod->SetAccessibility( Prototype::None );
185 }
186 else{
187 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
188 }
[29]189
190 //pobj_Inherits
191 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
[135]192 if(pBaseMethod->GetInheritsClassPtr()==0){
193 pMethod->SetInheritsClassPtr( &inheritsClass );
194 }
195 else{
196 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
197 }
[51]198
[135]199 methods.push_back( pMethod );
[29]200 }
201
202 //仮想関数の数
[90]203 vtbl_num += inheritsClass.vtbl_num;
[29]204
205 //継承先のクラスをメンバとして保持する
[90]206 pobj_InheritsClass = &inheritsClass;
207
208 return true;
[29]209}
[114]210bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){
[90]211
212 //ループ継承でないかをチェック
213 if(pobj_LoopRefCheck->check(inheritsInterface)){
[131]214 SetError(123,inheritsInterface.GetName(),nowLine);
[90]215 return false;
216 }
217
218 if( inheritsInterface.ppobj_Member == 0 ){
219 //継承先が読み取られていないとき
[131]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());
[90]223 }
224
225 //メソッドをコピー
[135]226 foreach( const CMethod *pBaseMethod, inheritsInterface.methods ){
227 CMethod *pMethod = new DynamicMethod( *pBaseMethod );
[90]228
[137]229 // アクセシビリティ
230 if(pBaseMethod->GetAccessibility() == Prototype::Private){
231 pMethod->SetAccessibility( Prototype::None );
232 }
233 else{
234 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
235 }
[90]236
237 //pobj_Inherits
238 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
[135]239 if(pBaseMethod->GetInheritsClassPtr()==0){
240 pMethod->SetInheritsClassPtr( &inheritsInterface );
241 }
242 else{
243 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
244 }
[90]245
[135]246 methods.push_back( pMethod );
[90]247 }
248
[131]249 interfaces.push_back( InheritedInterface( const_cast<CClass *>(&inheritsInterface), vtbl_num ) );
250
[90]251 //仮想関数の数
252 vtbl_num += inheritsInterface.vtbl_num;
253
254 return true;
255}
[137]256void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer ){
[17]257 ppobj_Member = (CMember **)HeapReAlloc( hHeap, 0, ppobj_Member, ( iMemberNum + 1 ) * sizeof(CMember *) );
[137]258 ppobj_Member[iMemberNum] = new CMember( this, accessibility, isConst, isRef, buffer );
[4]259 iMemberNum++;
260}
[137]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 );
[53]263 staticMembers.push_back( member );
[4]264}
[46]265BOOL CClass::DupliCheckAll(const char *name){
[4]266 //重複チェック
267
268 //メンバ
269 if(DupliCheckMember(name)) return 1;
270
271 //メソッド
[135]272 foreach( const CMethod *pMethod, methods ){
273 if( lstrcmp( name, pMethod->pUserProc->GetName().c_str() ) == 0 ){
[4]274 return 1;
275 }
276 }
277
278 return 0;
279}
[46]280BOOL CClass::DupliCheckMember(const char *name){
[4]281 //重複チェック
282
283 //メンバ
[53]284 for( int i=0;i<iMemberNum;i++){
[135]285 if( GetName() == ppobj_Member[i]->GetName() ){
[4]286 return 1;
287 }
288 }
289
290 //静的メンバ
[53]291 foreach( CMember *member, staticMembers ){
[135]292 if( GetName() == member->GetName() ){
[4]293 return 1;
294 }
295 }
296
297 return 0;
298}
299
[51]300//デフォルト コンストラクタ メソッドを取得
[135]301const CMethod *CClass::GetConstructorMethod() const
[51]302{
303 if( ConstructorMemberSubIndex == -1 ) return NULL;
304 return methods[ConstructorMemberSubIndex];
305}
[50]306
[51]307//デストラクタ メソッドを取得
[135]308const CMethod *CClass::GetDestructorMethod() const
[51]309{
310 if( DestructorMemberSubIndex == -1 ) return NULL;
311 return methods[DestructorMemberSubIndex];
312}
313
[63]314//サイズを取得
315int CClass::GetSize() const
316{
317 return GetMemberOffset( NULL, NULL );
318}
[51]319
[63]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
[137]337 i2 = pMember->GetType().GetSize();
[63]338
339 //アラインメントを算出
340 int member_size;
[137]341 if( pMember->GetType().IsStruct() ){
[63]342 //メンバクラスのアラインメントを取得
[137]343 member_size=pMember->GetType().GetClass().GetAlignment();
[63]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 //メンバ指定がある場合は、オフセットを返す
[135]369 if( pMember->GetName() == memberName ){
[63]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
[137]404 if(pMember->GetType().IsStruct()){
[63]405 //メンバクラスのアラインメントを取得
[137]406 member_size=pMember->GetType().GetClass().GetAlignment();
[63]407 }
408 else{
409 //メンバサイズを取得
[137]410 member_size = pMember->GetType().GetSize();
[63]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
[75]426int CClass::GetFuncNumInVtbl( const UserProc *pUserProc ) const
[51]427{
428 int n = 0;
[135]429 foreach( const CMethod *pMethod, methods ){
430 if( pMethod->pUserProc == pUserProc ) break;
431 if( pMethod->IsVirtual() ) n++;
[51]432 }
433 return n;
434}
[114]435LONG_PTR CClass::GetVtblGlobalOffset(void) const
436{
[28]437
438 //既に存在する場合はそれを返す
[4]439 if(vtbl_offset!=-1) return vtbl_offset;
440
[28]441
[92]442
[28]443 //////////////////////////////////////
444 // 存在しないときは新たに生成する
445 //////////////////////////////////////
446
[75]447 UserProc **ppsi;
[100]448 ppsi=(UserProc **)HeapAlloc(hHeap,0,vtbl_num*sizeof(GlobalProc *));
[4]449
450 //関数テーブルに値をセット
[51]451 int i2 = 0;
[135]452 foreach( const CMethod *pMethod, methods ){
453 if(pMethod->IsVirtual()){
454 pMethod->pUserProc->Using();
[4]455
[135]456 if(pMethod->IsAbstract()){
[28]457 extern int cp;
458 SetError(300,NULL,cp);
[4]459
[28]460 ppsi[i2]=0;
[4]461 }
[92]462 else{
[135]463 ppsi[i2]=pMethod->pUserProc;
[92]464 }
[28]465 i2++;
[4]466 }
467 }
468
[56]469 vtbl_offset=dataTable.AddBinary((void *)ppsi,vtbl_num*sizeof(LONG_PTR));
[4]470
[28]471 for( int i=0; i < vtbl_num; i++ ){
[4]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;
[56]483 pVtbl=(LONG_PTR *)((char *)dataTable.GetPtr()+vtbl_offset);
[4]484
485 int i;
486 for(i=0;i<vtbl_num;i++){
[100]487 GlobalProc *pUserProc;
488 pUserProc=(GlobalProc *)pVtbl[i];
[75]489 if(!pUserProc) continue;
490 pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection;
[4]491 }
492}
[75]493bool CClass::IsAbstract() const
494{
[96]495 // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
[4]496
[135]497 foreach( const CMethod *pMethod, methods ){
498 if(pMethod->IsVirtual()){
499 if(pMethod->IsAbstract()){
[28]500 return true;
[4]501 }
502 }
503 }
504
[28]505 return false;
[4]506}
507
[17]508// コンストラクタのコンパイルを開始
[114]509void CClass::NotifyStartConstructorCompile() const
510{
[17]511 isCompilingConstructor = true;
512}
[4]513
[17]514//コンストラクタのコンパイルを終了
[114]515void CClass::NotifyFinishConstructorCompile() const
516{
[17]517 isCompilingConstructor = false;
518}
519
520//コンストラクタをコンパイル中かどうかを判別
[75]521bool CClass::IsCompilingConstructor() const
522{
[17]523 return isCompilingConstructor;
524}
525
[18]526//デストラクタのコンパイルを開始
[114]527void CClass::NotifyStartDestructorCompile() const{
[18]528 isCompilingDestructor = true;
529}
[17]530
[18]531//デストラクタのコンパイルを終了
[114]532void CClass::NotifyFinishDestructorCompile() const{
[18]533 isCompilingDestructor = false;
534}
535
536//デストラクタをコンパイル中かどうかを判別
[75]537bool CClass::IsCompilingDestructor() const
538{
[18]539 return isCompilingDestructor;
540}
541
[28]542//自身の派生クラスかどうかを確認
[75]543bool CClass::IsSubClass( const CClass *pClass ) const
544{
[28]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
[59]553//自身と等しいまたは派生クラスかどうかを確認
[75]554bool CClass::IsEqualsOrSubClass( const CClass *pClass ) const
555{
[59]556 if( IsEquals( pClass ) ) return true;
557 return IsSubClass( pClass );
558}
[28]559
[94]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}
[28]568
[59]569
[94]570
[102]571int CDBClass::hash(const char *name) const{
[4]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
[67]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 *) );
[4]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
[114]625const CClass *CDBClass::Find( const NamespaceScopes &namespaceScopes, const string &name ) const
[102]626{
[4]627 int key;
[114]628 key=hash(name.c_str());
[4]629
[117]630 if( namespaceScopes.size() == 0 && name == "Object" ){
631 return GetObjectClassPtr();
632 }
633 else if( namespaceScopes.size() == 0 && name == "String" ){
634 return GetStringClassPtr();
635 }
636
[4]637 if(pobj_ClassHash[key]){
638 CClass *pobj_c;
639 pobj_c=pobj_ClassHash[key];
640 while(1){
[114]641 if( pobj_c->IsEqualSymbol( namespaceScopes, name ) ){
[102]642 //名前空間とクラス名が一致した
[4]643 return pobj_c;
644 }
645
646 if(pobj_c->pobj_NextClass==0) break;
647 pobj_c=pobj_c->pobj_NextClass;
648 }
649 }
650
[114]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();
[102]657 }
658 }
[114]659
[102]660 return NULL;
661}
[114]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 );
[102]667
[114]668 return Find( NamespaceScopes( AreaName ), NestName );
669}
670
[108]671CClass *CDBClass::AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
[4]672 //////////////////////////////////////////////////////////////////////////
673 // クラスを追加
674 // ※名前のみを登録。その他の情報はSetClassメソッドで!
675 //////////////////////////////////////////////////////////////////////////
676
677 CClass *pobj_c;
[108]678 pobj_c=new CClass(namespaceScopes, importedNamespaces, name);
[4]679
680 if(lstrcmp(name,"String")==0){
681 //Stringクラス
[117]682 pStringClass=pobj_c;
[4]683 }
[67]684 if( lstrcmp( name, "Object" ) == 0 ){
685 pObjectClass = pobj_c;
686 }
[4]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){
[102]700 if( pobj_c2->IsEqualSymbol( namespaceScopes, name ) ){
701 //名前空間及びクラス名が重複した場合
[75]702 SetError(15,name,nowLine);
[4]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;
[101]720 int i, i2;
721 char temporary[VN_SIZE];
[4]722
[128]723 // Blittable型管理オブジェクトを初期化
724 Smoothie::Meta::blittableTypes.clear();
725
[101]726 // 名前空間管理
727 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
728 namespaceScopes.clear();
729
[108]730 // Importsされた名前空間の管理
731 NamespaceScopesCollection &importedNamespaces = Smoothie::Meta::importedNamespaces;
732 importedNamespaces.clear();
733
[4]734 for(i=0;;i++){
735 if(basbuf[i]=='\0') break;
736
[101]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 }
[108]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 );
[101]769
[108]770 continue;
771 }
772 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
773 importedNamespaces.clear();
774 continue;
775 }
776
[4]777 if(basbuf[i]==1&&(
778 basbuf[i+1]==ESC_CLASS||
779 basbuf[i+1]==ESC_TYPE||
780 basbuf[i+1]==ESC_INTERFACE
781 )){
[75]782 int nowLine;
783 nowLine=i;
[4]784
785 i+=2;
[128]786 Type blittableType;
[76]787 if(memicmp(basbuf+i,"Align(",6)==0){
[128]788 //アラインメント修飾子
[4]789 i+=6;
790 i=JumpStringInPare(basbuf,i)+1;
791 }
[128]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 }
[4]798
[92]799 bool isEnum = false;
800 if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM ){
801 // 列挙型の場合
802 isEnum = true;
803
804 i+=2;
805 }
806
[4]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 //クラスを追加
[108]818 CClass *pClass = pobj_DBClass->AddClass(namespaceScopes, importedNamespaces, temporary,nowLine);
[64]819 if( pClass ){
[75]820 if( basbuf[nowLine+1] == ESC_CLASS ){
[92]821 if( isEnum ){
822 pClass->classType = CClass::Enum;
823 }
824 else{
825 pClass->classType = CClass::Class;
826 }
[64]827 }
[75]828 else if( basbuf[nowLine+1] == ESC_INTERFACE ){
[64]829 pClass->classType = CClass::Interface;
830 }
831 else{
832 pClass->classType = CClass::Structure;
833 }
834 }
[128]835
836 // Blittable型の場合
837 if( !blittableType.IsNull() ){
838 pClass->SetBlittableType( blittableType );
839
840 // Blittable型として登録
841 Smoothie::Meta::blittableTypes.push_back( BlittableType( blittableType, pClass ) );
842 }
[4]843 }
844 }
845}
846
847
[137]848void CDBClass::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
[135]849 bool isVirtual, bool isOverride, char *buffer, int nowLine){
[4]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 //関数ハッシュへ登録
[100]864 GlobalProc *pUserProc;
[135]865 pUserProc=AddSubData( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0) );
[75]866 if(!pUserProc) return;
[4]867
868
869 ////////////////////////////////////////////////////////////
[18]870 // コンストラクタ、デストラクタの場合の処理
[4]871 ////////////////////////////////////////////////////////////
872 BOOL fConstructor=0,bDestructor=0;
873
[131]874 if(lstrcmp(temporary,pobj_c->GetName().c_str())==0){
[18]875 //コンストラクタの場合
876
877 //標準コンストラクタ(引数なし)
[75]878 if(pUserProc->Params().size()==0) fConstructor=1;
[18]879
880 //強制的にConst修飾子をつける
881 isConst = true;
[4]882 }
883 else if(temporary[0]=='~'){
884 //デストラクタの場合はその名前が正しいかチェックを行う
[131]885 if(lstrcmp(temporary+1,pobj_c->GetName().c_str())!=0)
[75]886 SetError(117,NULL,nowLine);
[4]887 else
888 bDestructor=1;
889 }
890 if(fConstructor||bDestructor){
[18]891 // コンストラクタ、デストラクタのアクセシビリティをチェック
892
893 //強制的にConst修飾子をつける
894 isConst = true;
[4]895 }
896
[18]897 if( fConstructor == 1 )
[51]898 pobj_c->ConstructorMemberSubIndex = (int)pobj_c->methods.size();
[18]899 else if( bDestructor )
[51]900 pobj_c->DestructorMemberSubIndex = (int)pobj_c->methods.size();
[4]901
902
903
904 //////////////////
905 // 重複チェック
906 //////////////////
907
908 if(pobj_c->DupliCheckMember(temporary)){
[75]909 SetError(15,temporary,nowLine);
[4]910 return;
911 }
912
[51]913 //メソッド
[135]914 foreach( const CMethod *pMethod, pobj_c->methods ){
[27]915 //基底クラスと重複する場合はオーバーライドを行う
[135]916 if( pMethod->GetInheritsClassPtr() ) continue;
[4]917
[135]918 if( pMethod->pUserProc->GetName() == temporary ){
919 if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){
[4]920 //関数名、パラメータ属性が合致したとき
[75]921 SetError(15,pUserProc->GetName().c_str(),nowLine);
[4]922 return;
923 }
924 }
925 }
926
927 //仮想関数の場合
[135]928 if( isAbstract ) pUserProc->CompleteCompile();
[4]929
[51]930 //メソッドのオーバーライド
[135]931 foreach( CMethod *pMethod, pobj_c->methods ){
932 if( pMethod->pUserProc->GetName() == temporary ){
933 if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){
[4]934
[135]935 if(pMethod->IsVirtual()){
[4]936 //メンバ関数を上書き
[135]937 pMethod->pUserProc=pUserProc;
938 pMethod->Override();
[4]939
[135]940 if( !isOverride ){
[75]941 SetError(127,NULL,nowLine);
[4]942 }
[137]943 if(pMethod->GetAccessibility() != accessibility ){
[75]944 SetError(128,NULL,nowLine);
[4]945 }
[75]946
[135]947 pUserProc->SetMethod( pMethod );
[4]948 return;
949 }
950 }
951 }
952 }
953
[135]954 if( isVirtual ){
[4]955 pobj_c->vtbl_num++;
956 }
957
[135]958 if( isOverride ){
[75]959 SetError(12,"Override",nowLine);
[4]960 }
961
962 if(bStatic){
[137]963 pobj_c->staticMethods.AddStatic( pUserProc, accessibility );
[4]964 }
965 else{
[137]966 pobj_c->methods.Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
[4]967 }
968}
969
[75]970BOOL CDBClass::MemberVar_LoopRefCheck(const CClass &objClass){
[4]971 int i,i2,bRet=1;
[75]972 for(i=0;i<objClass.iMemberNum;i++){
973 const CMember *pMember = objClass.ppobj_Member[i];
[137]974 if(pMember->GetType().IsStruct()){
[4]975 //循環参照でないかをチェック
[137]976 if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
[4]977 extern int cp;
[137]978 SetError(124,pMember->GetType().GetClass().GetName(),cp);
[4]979 return 0;
980 }
981
[131]982 pobj_LoopRefCheck->add(objClass.GetName().c_str());
[4]983
[137]984 i2=MemberVar_LoopRefCheck(pMember->GetType().GetClass());
[4]985 if(bRet==1) bRet=i2;
986
[131]987 pobj_LoopRefCheck->del(objClass.GetName().c_str());
[4]988 }
989 }
990
991 return bRet;
992}
993
[46]994void CDBClass::GetClass_recur(const char *lpszInheritsClass){
[4]995 extern char *basbuf;
996 int i,i2,i3,sub_address,top_pos;
997 char temporary[8192];
998
[102]999 // 名前空間管理
1000 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
1001 namespaceScopes.clear();
1002
[4]1003 for(i=0;;i++){
1004 if(basbuf[i]=='\0') break;
1005
1006
[102]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
[4]1034 if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
1035 //////////////////////////
1036 // インターフェイス
1037 //////////////////////////
1038
1039 top_pos=i;
1040
1041 i+=2;
1042
1043 //インターフェイス名を取得
[17]1044 GetIdentifierToken( temporary, basbuf, i );
[4]1045
[114]1046 CClass *pobj_c = const_cast<CClass *>( pobj_DBClass->Find(namespaceScopes, temporary) );
[4]1047 if(!pobj_c) continue;
1048
1049 if(lpszInheritsClass){
[131]1050 if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
[4]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
[131]1078 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
[4]1079 SetError(105,temporary,i);
1080 goto Interface_InheritsError;
1081 }
1082
1083 //継承元クラスを取得
[114]1084 const CClass *pInheritsClass = Find(temporary);
[29]1085 if( !pInheritsClass ){
[4]1086 SetError(106,temporary,i);
1087 goto Interface_InheritsError;
1088 }
1089
[90]1090 //継承させる
[131]1091 if( !pobj_c->InheritsClass( *pInheritsClass, i ) ){
[4]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 //メンバ関数を追加
[18]1149 AddMethod(pobj_c,
[137]1150 Prototype::Public, //Publicアクセス権
[18]1151 0, //Static指定なし
1152 false, //Constではない
1153 1, //Abstract
1154 1, //Virtual
1155 0,
1156 temporary,
1157 sub_address
1158 );
[4]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
[64]1169 const DWORD dwClassType=basbuf[i+1];
[4]1170
1171 i+=2;
1172
1173 int iAlign=0;
[76]1174 if(memicmp(basbuf+i,"Align(",6)==0){
[128]1175 //アラインメント修飾子
[4]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 }
[128]1183 else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
1184 // Blittable修飾子
1185 i+=10;
1186 i=JumpStringInPare(basbuf,i)+1;
1187 }
[4]1188
[92]1189 if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM ){
1190 // 列挙型の場合
1191 i+=2;
1192 }
[4]1193
1194 //クラス名を取得
[17]1195 GetIdentifierToken( temporary, basbuf, i );
[4]1196
[114]1197 CClass *pobj_c = const_cast<CClass *>( pobj_DBClass->Find(namespaceScopes, temporary) );
[4]1198 if(!pobj_c) continue;
1199
1200 if(lpszInheritsClass){
[131]1201 if( pobj_c->GetName() != lpszInheritsClass ){
[4]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 //アクセス制限の初期値をセット
[137]1222 Prototype::Accessibility accessibility;
1223 if(dwClassType==ESC_CLASS){
1224 accessibility = Prototype::Private;
1225 }
1226 else{
1227 accessibility = Prototype::Public;
1228 }
[4]1229
[131]1230 if( pobj_c->GetName() == "Object" || dwClassType == ESC_TYPE ){
1231 // 継承無し
1232 pobj_c->pobj_InheritsClass = NULL;
[29]1233
[131]1234 // 仮想関数の数を初期化
1235 pobj_c->vtbl_num = 0;
[29]1236 }
1237 else{
[127]1238 bool isInherits = false;
[29]1239 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
1240 //継承を行う場合
[127]1241 isInherits = true;
1242
[29]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];
[4]1249 }
1250
[131]1251 if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
[29]1252 SetError(105,temporary,i);
1253 goto InheritsError;
1254 }
[4]1255 }
[127]1256
1257 if( !isInherits ){
[29]1258 //Objectを継承する
1259 lstrcpy( temporary, "Object" );
1260 }
[4]1261
[131]1262 pobj_c->Inherits( temporary, i );
[4]1263 }
1264InheritsError:
1265
[18]1266 //メンバとメソッドを取得
[4]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
[17]1290 //Const修飾子
1291 bool isConst = false;
1292 if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
1293 isConst = true;
1294 i += 2;
1295 }
[40]1296
[4]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
[135]1306 bool isVirtual = false, isAbstract = false, isOverride = false;
[4]1307 if(i3==ESC_ABSTRACT){
[135]1308 isAbstract=1;
1309 isVirtual=1;
[4]1310 i+=2;
1311
1312 i3=basbuf[i+1];
1313 }
1314 else if(i3==ESC_VIRTUAL){
[135]1315 isAbstract=0;
1316 isVirtual=1;
[4]1317 i+=2;
1318
1319 i3=basbuf[i+1];
1320 }
1321 else if(i3==ESC_OVERRIDE){
[135]1322 isOverride=1;
1323 isVirtual=1;
[4]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){
[137]1357 accessibility = Prototype::Private;
[4]1358 continue;
1359 }
1360 if(lstrcmpi(temporary,"Public")==0){
[137]1361 accessibility = Prototype::Public;
[4]1362 continue;
1363 }
1364 if(lstrcmpi(temporary,"Protected")==0){
[137]1365 accessibility = Prototype::Protected;
[4]1366 continue;
1367 }
1368
1369 extern int cp;
1370 if(i3==0){
1371 if(bStatic){
1372 //静的メンバを追加
1373 cp=i; //エラー用
[137]1374 pobj_c->AddStaticMember( accessibility, isConst, false, temporary, i);
[4]1375 }
1376 else{
1377 //メンバを追加
1378 cp=i; //エラー用
[137]1379 pobj_c->AddMember( accessibility, isConst, false, temporary );
[4]1380
1381
[137]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){
[4]1384 //参照先が読み取られていないとき
[137]1385 GetClass_recur(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetType().GetClass().GetName().c_str());
[4]1386 }
1387 }
1388
1389
[137]1390 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetType().IsStruct()){
[4]1391 //循環参照のチェック
[131]1392 pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
[137]1393 if(!MemberVar_LoopRefCheck(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetType().GetClass())){
[4]1394 //エラー回避
[137]1395 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetType().SetBasicType( DEF_PTR_VOID );
[4]1396 }
[131]1397 pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
[4]1398 }
1399 }
1400 }
1401 else{
1402 //メソッドを追加
1403 cp=i; //エラー用
[18]1404 AddMethod(pobj_c,
[137]1405 accessibility,
[18]1406 bStatic,
1407 isConst,
[135]1408 isAbstract,
1409 isVirtual,
1410 isOverride,
[18]1411 temporary,
1412 sub_address);
[4]1413
[135]1414 if( isAbstract ) continue;
[4]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
[67]1444void CDBClass::GetAllClassInfo(void){
[4]1445 //ループ継承チェック用のクラス
1446 pobj_LoopRefCheck=new CLoopRefCheck();
1447
1448 //クラスを取得
1449 GetClass_recur(0);
1450
1451 delete pobj_LoopRefCheck;
1452 pobj_LoopRefCheck=0;
[89]1453
1454 // イテレータ用のデータを作る
1455 pobj_DBClass->Iterator_Init();
[4]1456}
1457
[89]1458void CDBClass::Compile_System_InitializeUserTypes(){
[90]1459 char temporary[VN_SIZE];
[89]1460
1461 ////////////////////////////////////////////////////////////////////
1462 // クラス登録
1463 ////////////////////////////////////////////////////////////////////
1464
1465 // イテレータをリセット
1466 Iterator_Reset();
1467
1468 while( Iterator_HasNext() ){
[91]1469 const CClass &objClass = *Iterator_GetNext();
[89]1470
[91]1471 if( !objClass.IsUsing() ){
1472 // 未使用のクラスは無視する
1473 continue;
1474 }
1475
[94]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
[137]1481 if( member.GetType().IsObject() || member.GetType().IsPointer() ){
[94]1482 if( referenceOffsetsBuffer[0] ){
1483 lstrcat( referenceOffsetsBuffer, "," );
1484 }
1485
1486 sprintf( referenceOffsetsBuffer + lstrlen( referenceOffsetsBuffer ),
1487 "%d",
[135]1488 objClass.GetMemberOffset( member.GetName().c_str() ) );
[94]1489
1490 numOfReference++;
1491 }
1492 }
1493
[89]1494 sprintf( temporary
[94]1495 , "Add(%c%c_System_TypeForClass(\"%s\",\"%s\",[%s],%d))"
[89]1496 , 1
1497 , ESC_NEW
[131]1498 , "" // 名前空間 (TODO: 実装)
1499 , objClass.GetName().c_str() // クラス名
1500 , referenceOffsetsBuffer // 参照メンバオフセット配列
1501 , numOfReference // 参照メンバの個数
[89]1502 );
1503
1504 // コンパイル
1505 ChangeOpcode( temporary );
1506
1507 // ネイティブコードバッファの再確保
1508 ReallocNativeCodeBuffer();
1509 }
1510
1511
1512 ////////////////////////////////////////////////////////////////////
[90]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() ){
[91]1528 const CClass &objClass = *Iterator_GetNext();
[90]1529
[91]1530 if( !objClass.IsUsing() ){
1531 // 未使用のクラスは無視する
1532 continue;
1533 }
1534
1535 if( objClass.pobj_InheritsClass ){
[90]1536 sprintf( temporary
1537 , "tempType=Search(\"%s\",\"%s\")"
[131]1538 , "" // 名前空間 (TODO: 実装)
1539 , objClass.GetName().c_str() // クラス名
[90]1540 );
1541
1542 // コンパイル
1543 ChangeOpcode( temporary );
1544
1545 sprintf( temporary
1546 , "tempType.SetBaseType(Search(\"%s\",\"%s\"))"
1547 , "" // 名前空間 (TODO: 実装)
[131]1548 , objClass.pobj_InheritsClass->GetName().c_str() // 基底クラス名
[90]1549 );
1550
1551 // コンパイル
1552 ChangeOpcode( temporary );
1553 }
1554
1555 // ネイティブコードバッファの再確保
1556 ReallocNativeCodeBuffer();
1557 }
1558
1559
1560
1561 ////////////////////////////////////////////////////////////////////
[89]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 }*/
[87]1585}
1586
1587
1588
[117]1589CClass *CDBClass::GetStringClassPtr() const
[67]1590{
1591 if( !pStringClass ){
1592 SetError();
1593 return NULL;
1594 }
1595 return pStringClass;
1596}
[117]1597CClass *CDBClass::GetObjectClassPtr() const
[67]1598{
1599 if( !pObjectClass ){
1600 SetError();
1601 return NULL;
1602 }
1603 return pObjectClass;
1604}
1605
[75]1606void CDBClass::StartCompile( UserProc *pUserProc ){
1607 pCompilingClass = pUserProc->GetParentClassPtr();
[18]1608 if( pCompilingClass ){
[91]1609 pCompilingClass->Using();
1610
[135]1611 pCompilingMethod = pCompilingClass->methods.GetMethodPtr( pUserProc );
[18]1612 if( !pCompilingMethod ){
[135]1613 pCompilingMethod = pCompilingClass->staticMethods.GetMethodPtr( pUserProc );
[18]1614 if( !pCompilingMethod ){
1615 SetError(300,NULL,cp);
1616 }
1617 }
1618 }
1619 else{
1620 pCompilingMethod = NULL;
1621 }
1622}
[114]1623const CClass *CDBClass::GetNowCompilingClass() const
1624{
[18]1625 return pCompilingClass;
1626}
[135]1627const CMethod *CDBClass::GetNowCompilingMethodInfo(){
[18]1628 return pCompilingMethod;
1629}
[4]1630
1631
1632
[18]1633
[4]1634//////////////////////
1635// イテレータ
1636//////////////////////
1637
[89]1638void CDBClass::Iterator_Init(void){
[4]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}
[89]1661void CDBClass::Iterator_Reset(void){
1662 iIteNextNum = 0;
1663}
[4]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.