source: dev/BasicCompiler_Common/Class.cpp@ 14

Last change on this file since 14 was 5, checked in by dai_9181, 18 years ago
File size: 29.8 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
11CClass *pobj_CompilingClass;
12CClass *pobj_StringClass;
13
14int AddDataTable(char *buffer,int length);
15
16
17
18CMember::CMember(CClass *pobj_c,DWORD access,char *buffer,int NowLine){
19 extern int cp;
20
21 //構文を解析
22 char VarName[VN_SIZE];
23 char init_buf[VN_SIZE];
24 char constract_parameter[VN_SIZE];
25 if(!GetDimentionFormat(buffer,VarName,SubScripts,&TypeInfo,init_buf,constract_parameter))
26 return;
27
28 //重複チェック
29 if(pobj_c->DupliCheckAll(VarName)){
30 SetError(15,VarName,cp);
31 return;
32 }
33
34 if(TypeInfo.type==DEF_OBJECT){
35 if(TypeInfo.u.pobj_Class->IsHoldAbstractFunction()){
36 //抽象クラスだったとき
37 SetError(125,TypeInfo.u.pobj_Class->name,cp);
38 }
39 }
40
41 //メンバ名
42 name=(char *)HeapAlloc(hHeap,0,lstrlen(VarName)+1);
43 lstrcpy(name,VarName);
44
45 //アクセス権
46 dwAccess=access;
47
48 //初期データ
49 InitBuf=(char *)HeapAlloc(hHeap,0,lstrlen(init_buf)+1);
50 lstrcpy(InitBuf,init_buf);
51
52 //コンストラクタ用のパラメータ
53 ConstractParameter=(char *)HeapAlloc(hHeap,0,lstrlen(constract_parameter)+1);
54 lstrcpy(ConstractParameter,constract_parameter);
55
56 //ソースコードの位置
57 source_code_address=NowLine;
58}
59CMember::CMember(CMember *pobj){
60 //コピーコンストラクタ
61 memset(this,0,sizeof(CMember));
62
63 //name
64 name=(char *)HeapAlloc(hHeap,0,lstrlen(pobj->name)+1);
65 lstrcpy(name,pobj->name);
66
67 //SubScripts
68 memcpy(SubScripts,pobj->SubScripts,MAX_ARRAYDIM*sizeof(int));
69
70 //TypeInfo
71 TypeInfo=pobj->TypeInfo;
72
73 //ソースコードの位置
74 source_code_address=pobj->source_code_address;
75}
76CMember::CMember(){
77 memset(this,0,sizeof(CMember));
78}
79CMember::~CMember(){
80 HeapDefaultFree(name);
81 if(InitBuf) HeapDefaultFree(InitBuf);
82 if(ConstractParameter) HeapDefaultFree(ConstractParameter);
83}
84
85void CMember::InitStaticMember(void){
86 //静的メンバをグローバル領域に作成
87
88 //イテレータをリセット
89 extern CDBClass *pobj_DBClass;
90 pobj_DBClass->Iterator_Reset();
91
92 int back_cp=cp;
93
94 while(pobj_DBClass->Iterator_HasNext()){
95 CClass *pobj_c;
96 pobj_c=pobj_DBClass->Iterator_GetNext();
97
98 int i;
99 char temporary[VN_SIZE];
100 for(i=0;i<pobj_c->iStaticMemberNum;i++){
101 sprintf(temporary,"%s.%s",pobj_c->name,pobj_c->ppobj_StaticMember[i]->name);
102 AddGlobalVariable(
103 temporary,
104 pobj_c->ppobj_StaticMember[i]->SubScripts,
105 &pobj_c->ppobj_StaticMember[i]->TypeInfo,
106 GetTypeSize(pobj_c->ppobj_StaticMember[i]->TypeInfo.type,pobj_c->ppobj_StaticMember[i]->TypeInfo.u.lpIndex),
107 pobj_c->ppobj_StaticMember[i]->InitBuf,
108 pobj_c->ppobj_StaticMember[i]->ConstractParameter,
109 0);
110
111 if(pobj_c->ppobj_StaticMember[i]->TypeInfo.type==DEF_OBJECT){
112 //エラー用
113 cp=pobj_c->ppobj_StaticMember[i]->source_code_address;
114
115 CallConstractor(temporary,
116 pobj_c->ppobj_StaticMember[i]->SubScripts,
117 pobj_c->ppobj_StaticMember[i]->TypeInfo,
118 pobj_c->ppobj_StaticMember[i]->ConstractParameter);
119 }
120
121 //ネイティブコードバッファの再確保
122 extern int obp_AllocSize;
123 if(obp_AllocSize<obp+8192){
124 obp_AllocSize+=8192;
125 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea
126 }
127 }
128 }
129
130 cp=back_cp;
131}
132
133
134
135CMethod::CMethod(CMethod *pobj){
136 //コピーコンストラクタ
137 memset(this,0,sizeof(CMethod));
138
139 psi=pobj->psi;
140
141 bAbstract=pobj->bAbstract;
142
143 bVirtual=pobj->bVirtual;
144}
145CMethod::CMethod(){
146 memset(this,0,sizeof(CMethod));
147}
148CMethod::~CMethod(){
149}
150
151
152
153
154CClass::CClass(char *name){
155 memset(this,0,sizeof(CClass));
156
157 vtbl_offset=-1;
158
159 this->name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
160 lstrcpy(this->name,name);
161}
162CClass::~CClass(){
163 int i;
164
165 //クラス名
166 HeapDefaultFree(name);
167
168 if(ppobj_Member){
169 //メンバ
170 for(i=0;i<iMemberNum;i++){
171 delete ppobj_Member[i];
172 }
173 HeapDefaultFree(ppobj_Member);
174 ppobj_Member=0;
175 }
176
177 if(ppobj_Method){
178 //メソッド
179 for(i=0;i<iMethodNum;i++){
180 delete ppobj_Method[i];
181 }
182 HeapDefaultFree(ppobj_Method);
183 ppobj_Method=0;
184 }
185
186 if(ppobj_StaticMember){
187 //静的メンバ
188 for(i=0;i<iStaticMemberNum;i++){
189 delete ppobj_StaticMember[i];
190 }
191 HeapDefaultFree(ppobj_StaticMember);
192 ppobj_StaticMember=0;
193 }
194
195 if(ppobj_StaticMethod){
196 //静的メソッド
197 for(i=0;i<iStaticMethodNum;i++){
198 delete ppobj_StaticMethod[i];
199 }
200 HeapDefaultFree(ppobj_StaticMethod);
201 ppobj_StaticMethod=0;
202 }
203}
204void CClass::AddMember(DWORD dwAccess,char *buffer){
205 ppobj_Member=(CMember **)HeapReAlloc(hHeap,0,ppobj_Member,(iMemberNum+1)*sizeof(CMember *));
206 ppobj_Member[iMemberNum]=new CMember(this,dwAccess,buffer);
207 iMemberNum++;
208}
209void CClass::AddStaticMember(DWORD dwAccess,char *buffer,int NowLine){
210 ppobj_StaticMember=(CMember **)HeapReAlloc(hHeap,0,ppobj_StaticMember,(iStaticMemberNum+1)*sizeof(CMember *));
211 ppobj_StaticMember[iStaticMemberNum]=new CMember(this,dwAccess,buffer,NowLine);
212 iStaticMemberNum++;
213}
214void CClass::AddMethod(SUBINFO *psi,DWORD dwAccess,BOOL bAbstract,BOOL bVirtual){
215 ppobj_Method=(CMethod **)HeapReAlloc(hHeap,0,ppobj_Method,(iMethodNum+1)*sizeof(CMethod *));
216 ppobj_Method[iMethodNum]=new CMethod();
217 ppobj_Method[iMethodNum]->psi=psi;
218 ppobj_Method[iMethodNum]->dwAccess=dwAccess;
219 ppobj_Method[iMethodNum]->bAbstract=bAbstract;
220 ppobj_Method[iMethodNum]->bVirtual=bVirtual;
221 ppobj_Method[iMethodNum]->pobj_InheritsClass=0;
222
223 iMethodNum++;
224}
225void CClass::AddStaticMethod(SUBINFO *psi,DWORD dwAccess){
226 ppobj_StaticMethod=(CMethod **)HeapReAlloc(hHeap,0,ppobj_StaticMethod,(iStaticMethodNum+1)*sizeof(CMethod *));
227 ppobj_StaticMethod[iStaticMethodNum]=new CMethod();
228 ppobj_StaticMethod[iStaticMethodNum]->psi=psi;
229 ppobj_StaticMethod[iStaticMethodNum]->dwAccess=dwAccess;
230 ppobj_StaticMethod[iStaticMethodNum]->bAbstract=0;
231 ppobj_StaticMethod[iStaticMethodNum]->bVirtual=0;
232 ppobj_StaticMethod[iStaticMethodNum]->pobj_InheritsClass=0;
233
234 iStaticMethodNum++;
235}
236BOOL CClass::DupliCheckAll(char *name){
237 //重複チェック
238
239 int i;
240
241 //メンバ
242 if(DupliCheckMember(name)) return 1;
243
244 //メソッド
245 for(i=0;i<iMethodNum;i++){
246 if(lstrcmp(name,ppobj_Method[i]->psi->name)==0){
247 return 1;
248 }
249 }
250
251 return 0;
252}
253BOOL CClass::DupliCheckMember(char *name){
254 //重複チェック
255
256 int i;
257
258 //メンバ
259 for(i=0;i<iMemberNum;i++){
260 if(lstrcmp(name,ppobj_Member[i]->name)==0){
261 return 1;
262 }
263 }
264
265 //静的メンバ
266 for(i=0;i<iStaticMemberNum;i++){
267 if(lstrcmp(name,ppobj_StaticMember[i]->name)==0){
268 return 1;
269 }
270 }
271
272 return 0;
273}
274
275LONG_PTR CClass::AddVtblDataTable(SUBINFO **ppsi,int length){
276 return AddDataTable((char *)ppsi,length);
277}
278LONG_PTR CClass::GetVtblGlobalOffset(void){
279 if(vtbl_offset!=-1) return vtbl_offset;
280
281 SUBINFO **ppsi;
282 ppsi=(SUBINFO **)HeapAlloc(hHeap,0,vtbl_num*sizeof(SUBINFO *));
283
284 //関数テーブルに値をセット
285 int i,i2,i3=0;
286 for(i=0;i < iMethodNum;i++){
287 if(ppobj_Method[i]->bVirtual){
288 for(i2=iMethodNum-1; i2>=i; i2--){
289 if(lstrcmp(ppobj_Method[i]->psi->name,ppobj_Method[i2]->psi->name)==0){
290 pobj_CompilingClass->ppobj_Method[i2]->psi->bUse=1;
291
292 if(ppobj_Method[i2]->bAbstract){
293 extern int cp;
294 SetError(300,NULL,cp);
295
296 ppsi[i3]=0;
297 }
298 else ppsi[i3]=pobj_CompilingClass->ppobj_Method[i2]->psi;
299 i3++;
300
301 break;
302 }
303 }
304 }
305 }
306
307 vtbl_offset=AddDataTable((char *)ppsi,vtbl_num*sizeof(LONG_PTR));
308
309 for(i=0;i<vtbl_num;i++){
310 pobj_Reloc->AddSchedule_DataSection(vtbl_offset+i*sizeof(LONG_PTR));
311 }
312
313 HeapDefaultFree(ppsi);
314
315 return vtbl_offset;
316}
317void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
318 if(vtbl_offset==-1) return;
319
320 extern char *DataTable;
321 LONG_PTR *pVtbl;
322 pVtbl=(LONG_PTR *)(DataTable+vtbl_offset);
323
324 int i;
325 for(i=0;i<vtbl_num;i++){
326 SUBINFO *psi;
327 psi=(SUBINFO *)pVtbl[i];
328 if(!psi) continue;
329 pVtbl[i]=psi->CompileAddress+ImageBase+MemPos_CodeSection;
330 }
331}
332BOOL CClass::IsHoldAbstractFunction(void){
333 //未実装の仮想関数を持つ場合は1を返す
334
335 int i,i2,i3=0;
336 for(i=0;i < iMethodNum;i++){
337 if(ppobj_Method[i]->bVirtual){
338 for(i2=iMethodNum-1; i2>=i; i2--){
339 if(lstrcmp(ppobj_Method[i]->psi->name,ppobj_Method[i2]->psi->name)==0){
340
341 if(ppobj_Method[i2]->bAbstract){
342 return 1;
343 }
344
345 break;
346 }
347 }
348 }
349 }
350
351 //コンポジションの関係にあるメンバも検査する
352 for(i=0;i < iMemberNum;i++){
353 if(ppobj_Member[i]->TypeInfo.type==DEF_OBJECT){
354 if(ppobj_Member[i]->TypeInfo.u.pobj_Class->IsHoldAbstractFunction())
355 return 1;
356 }
357 }
358
359 return 0;
360}
361
362
363SUBINFO **CClass::GetOperatorSubInfo(BYTE idCalc,int &num){
364 //格納のための構造体配列を用意
365 SUBINFO **ppArray_si;
366 ppArray_si=(SUBINFO **)HeapAlloc(hHeap,0,sizeof(SUBINFO *)*1024);
367 num=0;
368
369 int i;
370 for(i=0;i<iMethodNum;i++){
371 char *temp;
372 temp=ppobj_Method[i]->psi->name;
373 if(temp[0]==1&&temp[1]==ESC_OPERATOR){
374 if((BYTE)temp[2]==idCalc){
375 ppArray_si[num]=ppobj_Method[i]->psi;
376 num++;
377 }
378 }
379 }
380
381 return ppArray_si;
382}
383
384
385int CDBClass::hash(char *name){
386 int key;
387
388 for(key=0;*name!='\0';name++){
389 key=((key<<8)+ *name )%MAX_CLASS_HASH;
390 }
391
392 return key;
393}
394
395void CDBClass::DestroyClass(CClass *pobj_c){
396 if(pobj_c->pobj_NextClass){
397 DestroyClass(pobj_c->pobj_NextClass);
398 }
399
400 delete pobj_c;
401}
402
403CDBClass::CDBClass(){
404 memset(this,0,sizeof(CDBClass));
405}
406CDBClass::~CDBClass(){
407 int i;
408 for(i=0;i<MAX_CLASS_HASH;i++){
409 if(pobj_ClassHash[i]) DestroyClass(pobj_ClassHash[i]);
410 }
411
412 if(ppobj_IteClass) HeapDefaultFree(ppobj_IteClass);
413}
414
415void CDBClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
416 int i;
417 for(i=0;i<MAX_CLASS_HASH;i++){
418 if(pobj_ClassHash[i]){
419 CClass *pobj_c;
420 pobj_c=pobj_ClassHash[i];
421 while(1){
422 pobj_c->ActionVtblSchedule(ImageBase,MemPos_CodeSection);
423
424 if(pobj_c->pobj_NextClass==0) break;
425 pobj_c=pobj_c->pobj_NextClass;
426 }
427 }
428 }
429}
430
431CClass *CDBClass::check(char *name){
432 int key;
433 key=hash(name);
434
435 if(pobj_ClassHash[key]){
436 CClass *pobj_c;
437 pobj_c=pobj_ClassHash[key];
438 while(1){
439 if(lstrcmp(name,pobj_c->name)==0){
440 //重複した場合
441 return pobj_c;
442 }
443
444 if(pobj_c->pobj_NextClass==0) break;
445 pobj_c=pobj_c->pobj_NextClass;
446 }
447 }
448 return 0;
449}
450
451CClass *CDBClass::AddClass(char *name,int NowLine){
452 //////////////////////////////////////////////////////////////////////////
453 // クラスを追加
454 // ※名前のみを登録。その他の情報はSetClassメソッドで!
455 //////////////////////////////////////////////////////////////////////////
456
457 CClass *pobj_c;
458 pobj_c=new CClass(name);
459
460 if(lstrcmp(name,"String")==0){
461 //Stringクラス
462 pobj_StringClass=pobj_c;
463 }
464
465
466 /////////////////////////////////
467 // ハッシュデータに追加
468 /////////////////////////////////
469
470 int key;
471 key=hash(name);
472
473 if(pobj_ClassHash[key]){
474 CClass *pobj_c2;
475 pobj_c2=pobj_ClassHash[key];
476 while(1){
477 if(lstrcmp(name,pobj_c2->name)==0){
478 //重複した場合
479 SetError(15,name,NowLine);
480 return 0;
481 }
482
483 if(pobj_c2->pobj_NextClass==0) break;
484 pobj_c2=pobj_c2->pobj_NextClass;
485 }
486 pobj_c2->pobj_NextClass=pobj_c;
487 }
488 else{
489 pobj_ClassHash[key]=pobj_c;
490 }
491
492 return pobj_c;
493}
494
495void CDBClass::InitNames(void){
496 extern char *basbuf;
497 int i;
498
499 for(i=0;;i++){
500 if(basbuf[i]=='\0') break;
501
502 if(basbuf[i]==1&&(
503 basbuf[i+1]==ESC_CLASS||
504 basbuf[i+1]==ESC_TYPE||
505 basbuf[i+1]==ESC_INTERFACE
506 )){
507 int NowLine;
508 NowLine=i;
509
510 i+=2;
511 //アラインメント修飾子
[5]512 if(_memicmp(basbuf+i,"Align(",6)==0){
[4]513 i+=6;
514 i=JumpStringInPare(basbuf,i)+1;
515 }
516
517 int i2;
518 char temporary[VN_SIZE];
519 for(i2=0;;i++,i2++){
520 if(!IsVariableChar(basbuf[i])){
521 temporary[i2]=0;
522 break;
523 }
524 temporary[i2]=basbuf[i];
525 }
526
527 //クラスを追加
528 pobj_DBClass->AddClass(temporary,NowLine);
529 }
530 }
531}
532
533
534void CDBClass::AddMemberSub(CClass *pobj_c,DWORD dwAccess,BOOL bStatic,BOOL bAbstract,BOOL bVirtual,BOOL bOverride,char *buffer,int NowLine){
535 int i,i2;
536 char temporary[VN_SIZE];
537
538 i=2;
539 for(i2=0;;i++,i2++){
540 if(buffer[i]=='('||buffer[i]=='\0'){
541 temporary[i2]=0;
542 break;
543 }
544 temporary[i2]=buffer[i];
545 }
546
547
548 //関数ハッシュへ登録
549 SUBINFO *psi;
550 psi=AddSubData(buffer,NowLine,bVirtual,pobj_c,bStatic);
551 if(!psi) return;
552
553
554 ////////////////////////////////////////////////////////////
555 // コンストラクタ、デストラクタのアクセシビリティをチェック
556 ////////////////////////////////////////////////////////////
557 BOOL fConstructor=0,bDestructor=0;
558
559 if(lstrcmp(temporary,pobj_c->name)==0){
560 if(psi->ParmNum==1) fConstructor=1;
561 if(psi->ParmNum==2){
562 if(psi->pParmInfo[1].type==DEF_OBJECT&&
563 psi->pParmInfo[1].u.pobj_c==pobj_c) fConstructor=2;
564 }
565 }
566 else if(temporary[0]=='~'){
567 //デストラクタの場合はその名前が正しいかチェックを行う
568 if(lstrcmp(temporary+1,pobj_c->name)!=0)
569 SetError(117,NULL,NowLine);
570 else
571 bDestructor=1;
572 }
573 if(fConstructor||bDestructor){
574 if(dwAccess!=ACCESS_PUBLIC){
575 SetError(116,NULL,NowLine);
576 dwAccess=ACCESS_PUBLIC;
577 }
578 }
579
580
581 if(fConstructor==1) pobj_c->ConstructorMemberSubIndex=pobj_c->iMethodNum;
582 else if(fConstructor==2) pobj_c->CopyConstructorMemberSubIndex=pobj_c->iMethodNum;
583 else if(bDestructor) pobj_c->DestructorMemberSubIndex=pobj_c->iMethodNum;
584
585
586
587 //////////////////
588 // 重複チェック
589 //////////////////
590
591 if(pobj_c->DupliCheckMember(temporary)){
592 SetError(15,temporary,NowLine);
593 return;
594 }
595
596 //メンバ関数
597 for(i=0;i<pobj_c->iMethodNum;i++){
598 //スーパークラスと重複する場合はオーバーライドを行う
599 if(pobj_c->ppobj_Method[i]->pobj_InheritsClass) continue;
600
601 if(lstrcmp(temporary,pobj_c->ppobj_Method[i]->psi->name)==0){
602 if(CompareParameter(
603 pobj_c->ppobj_Method[i]->psi->pParmInfo,pobj_c->ppobj_Method[i]->psi->ParmNum,
604 psi->pParmInfo,psi->ParmNum
605 )==0){
606 //関数名、パラメータ属性が合致したとき
607 SetError(15,psi->name,NowLine);
608 return;
609 }
610 }
611 }
612
613 //仮想関数の場合
614 if(bAbstract) psi->bCompile=1;
615
616
617 for(i=0;i<pobj_c->iMethodNum;i++){
618 if(lstrcmp(temporary,pobj_c->ppobj_Method[i]->psi->name)==0){
619 if(CompareParameter(
620 pobj_c->ppobj_Method[i]->psi->pParmInfo,pobj_c->ppobj_Method[i]->psi->ParmNum,
621 psi->pParmInfo,psi->ParmNum
622 )==0){
623
624 if(pobj_c->ppobj_Method[i]->psi->bVirtual){
625 //メンバ関数を上書き
626 pobj_c->ppobj_Method[i]->psi=psi;
627 pobj_c->ppobj_Method[i]->bAbstract=0;
628
629 if(!bOverride){
630 SetError(127,NULL,NowLine);
631 }
632 if(pobj_c->ppobj_Method[i]->dwAccess!=dwAccess){
633 SetError(128,NULL,NowLine);
634 }
635 return;
636 }
637 }
638 }
639 }
640
641 if(psi->bVirtual){
642 pobj_c->vtbl_num++;
643 }
644
645 if(bOverride){
646 SetError(12,"Override",NowLine);
647 }
648
649 if(bStatic){
650 pobj_c->AddStaticMethod(psi,dwAccess);
651 }
652 else{
653 pobj_c->AddMethod(psi,dwAccess,bAbstract,bVirtual);
654 }
655}
656
657BOOL CDBClass::MemberVar_LoopRefCheck(CClass *pobj_c){
658 int i,i2,bRet=1;
659 for(i=0;i<pobj_c->iMemberNum;i++){
660 if(pobj_c->ppobj_Member[i]->TypeInfo.type==DEF_OBJECT){
661 //循環参照でないかをチェック
662 if(pobj_LoopRefCheck->check(pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class->name)){
663 extern int cp;
664 SetError(123,pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class->name,cp);
665 return 0;
666 }
667
668 pobj_LoopRefCheck->add(pobj_c->name);
669
670 i2=MemberVar_LoopRefCheck(pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class);
671 if(bRet==1) bRet=i2;
672
673 pobj_LoopRefCheck->del(pobj_c->name);
674 }
675 }
676
677 return bRet;
678}
679
680void CDBClass::GetClass_recur(char *lpszInheritsClass){
681 extern char *basbuf;
682 int i,i2,i3,sub_address,top_pos;
683 DWORD dwClassType;
684 DWORD dwAccess;
685 char temporary[8192];
686
687 for(i=0;;i++){
688 if(basbuf[i]=='\0') break;
689
690 CClass *pobj_c;
691
692 if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
693 //////////////////////////
694 // インターフェイス
695 //////////////////////////
696
697 top_pos=i;
698
699 i+=2;
700
701 //インターフェイス名を取得
702 for(i2=0;;i++,i2++){
703 if(IsCommandDelimitation(basbuf[i])){
704 temporary[i2]=0;
705 break;
706 }
707 temporary[i2]=basbuf[i];
708 }
709
710 pobj_c=pobj_DBClass->check(temporary);
711 if(!pobj_c) continue;
712
713 if(lpszInheritsClass){
714 if(lstrcmp(lpszInheritsClass,pobj_c->name)!=0){
715 //継承先先読み用
716 continue;
717 }
718 }
719
720 if(pobj_c->ppobj_Member){
721 //既に先読みされているとき
722 continue;
723 }
724
725 //メンバ用メモリを初期化
726 pobj_c->ppobj_Member=(CMember **)HeapAlloc(hHeap,0,1);
727 pobj_c->iMemberNum=0;
728 pobj_c->ppobj_StaticMember=(CMember **)HeapAlloc(hHeap,0,1);
729 pobj_c->iStaticMemberNum=0;
730 pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
731 pobj_c->iMethodNum=0;
732 pobj_c->ppobj_StaticMethod=(CMethod **)HeapAlloc(hHeap,0,1);
733 pobj_c->iStaticMethodNum=0;
734
735 pobj_c->ConstructorMemberSubIndex=-1;
736 pobj_c->CopyConstructorMemberSubIndex=-1;
737 pobj_c->DestructorMemberSubIndex=-1;
738
739 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
740 //継承を行う場合
741 for(i+=3,i2=0;;i++,i2++){
742 if(IsCommandDelimitation(basbuf[i])){
743 temporary[i2]=0;
744 break;
745 }
746 temporary[i2]=basbuf[i];
747 }
748
749 if(lstrcmpi(temporary,pobj_c->name)==0){
750 SetError(105,temporary,i);
751 goto Interface_InheritsError;
752 }
753
754 //継承元クラスを取得
755 pobj_c->pobj_InheritsClass=check(temporary);
756 if(!pobj_c->pobj_InheritsClass){
757 SetError(106,temporary,i);
758 goto Interface_InheritsError;
759 }
760
761 //ループ継承でないかをチェック
762 if(pobj_LoopRefCheck->check(temporary)){
763 SetError(123,temporary,i);
764 goto Interface_InheritsError;
765 }
766
767 if(pobj_c->pobj_InheritsClass->ppobj_Member==0){
768 //継承先が読み取られていないとき
769 pobj_LoopRefCheck->add(pobj_c->name);
770 GetClass_recur(temporary);
771 pobj_LoopRefCheck->del(pobj_c->name);
772 }
773
774 //メンバ変数をコピー
775 pobj_c->ppobj_Member=(CMember **)HeapReAlloc(
776 hHeap,
777 0,
778 pobj_c->ppobj_Member,
779 pobj_c->pobj_InheritsClass->iMemberNum*sizeof(CMember *));
780 pobj_c->iMemberNum=pobj_c->pobj_InheritsClass->iMemberNum;
781 for(i3=0;i3<pobj_c->pobj_InheritsClass->iMemberNum;i3++){
782 pobj_c->ppobj_Member[i3]=new CMember(pobj_c->pobj_InheritsClass->ppobj_Member[i3]);
783
784 //dwAccess
785 if(pobj_c->pobj_InheritsClass->ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE)
786 pobj_c->ppobj_Member[i3]->dwAccess=ACCESS_NON;
787 else pobj_c->ppobj_Member[i3]->dwAccess=pobj_c->pobj_InheritsClass->ppobj_Member[i3]->dwAccess;
788 }
789
790 //メンバ関数をコピー
791 pobj_c->ppobj_Method=(CMethod **)HeapReAlloc(
792 hHeap,
793 0,
794 pobj_c->ppobj_Method,
795 pobj_c->pobj_InheritsClass->iMethodNum*sizeof(CMethod *));
796 pobj_c->iMethodNum=pobj_c->pobj_InheritsClass->iMethodNum;
797 for(i3=0;i3<pobj_c->pobj_InheritsClass->iMethodNum;i3++){
798 pobj_c->ppobj_Method[i3]=new CMethod(pobj_c->pobj_InheritsClass->ppobj_Method[i3]);
799
800 //dwAccess
801 if(pobj_c->pobj_InheritsClass->ppobj_Method[i3]->dwAccess==ACCESS_PRIVATE)
802 pobj_c->ppobj_Method[i3]->dwAccess=ACCESS_NON;
803 else pobj_c->ppobj_Method[i3]->dwAccess=pobj_c->pobj_InheritsClass->ppobj_Method[i3]->dwAccess;
804
805 //pobj_Inherits
806 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
807 if(pobj_c->pobj_InheritsClass->ppobj_Method[i3]->pobj_InheritsClass==0)
808 pobj_c->ppobj_Method[i3]->pobj_InheritsClass=pobj_c->pobj_InheritsClass;
809 else
810 pobj_c->ppobj_Method[i3]->pobj_InheritsClass=
811 pobj_c->pobj_InheritsClass->ppobj_Method[i3]->pobj_InheritsClass;
812 }
813
814 //仮想関数の数
815 pobj_c->vtbl_num=pobj_c->pobj_InheritsClass->vtbl_num;
816 }
817 else{
818 //継承無し
819 pobj_c->pobj_InheritsClass=0;
820
821 //仮想関数の数を初期化
822 pobj_c->vtbl_num=0;
823 }
824Interface_InheritsError:
825
826 //メンバ変数、関数を取得
827 while(1){
828 i++;
829
830 //エラー
831 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
832 SetError(22,"Interface",i);
833 i--;
834 break;
835 }
836
837 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
838 SetError(111,NULL,i);
839 break;
840 }
841
842 sub_address=i;
843
844 for(i2=0;;i++,i2++){
845 if(IsCommandDelimitation(basbuf[i])){
846 temporary[i2]=0;
847 break;
848 }
849 temporary[i2]=basbuf[i];
850 }
851 if(temporary[0]=='\0'){
852 if(basbuf[i]=='\0'){
853 i--;
854 SetError(22,"Interface",top_pos);
855 break;
856 }
857 continue;
858 }
859
860 //End Interface記述の場合
861 if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
862
863 if(!(temporary[0]==1&&(
864 temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
865 ))){
866 SetError(1,NULL,i);
867 break;
868 }
869
870 //メンバ関数を追加
871 AddMemberSub(pobj_c,ACCESS_PUBLIC,0,1,1,0,temporary,sub_address);
872 }
873 }
874
875 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
876 //////////////////////////
877 // クラス
878 //////////////////////////
879
880 top_pos=i;
881
882 dwClassType=basbuf[i+1];
883
884 i+=2;
885
886 //アラインメント修飾子
887 int iAlign=0;
[5]888 if(_memicmp(basbuf+i,"Align(",6)==0){
[4]889 i+=6;
890 i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
891 iAlign=atoi(temporary);
892
893 if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
894 SetError(51,NULL,i);
895 }
896
897
898 //クラス名を取得
899 for(i2=0;;i++,i2++){
900 if(IsCommandDelimitation(basbuf[i])){
901 temporary[i2]=0;
902 break;
903 }
904 temporary[i2]=basbuf[i];
905 }
906
907 pobj_c=pobj_DBClass->check(temporary);
908 if(!pobj_c) continue;
909
910 if(lpszInheritsClass){
911 if(lstrcmp(lpszInheritsClass,pobj_c->name)!=0){
912 //継承先先読み用
913 continue;
914 }
915 }
916
917 if(pobj_c->ppobj_Member){
918 //既に先読みされているとき
919 continue;
920 }
921
922 pobj_c->iAlign=iAlign;
923
924 //メンバ用メモリを初期化
925 pobj_c->ppobj_Member=(CMember **)HeapAlloc(hHeap,0,1);
926 pobj_c->iMemberNum=0;
927 pobj_c->ppobj_StaticMember=(CMember **)HeapAlloc(hHeap,0,1);
928 pobj_c->iStaticMemberNum=0;
929 pobj_c->ppobj_Method=(CMethod **)HeapAlloc(hHeap,0,1);
930 pobj_c->iMethodNum=0;
931 pobj_c->ppobj_StaticMethod=(CMethod **)HeapAlloc(hHeap,0,1);
932 pobj_c->iStaticMethodNum=0;
933
934 pobj_c->ConstructorMemberSubIndex=-1;
935 pobj_c->CopyConstructorMemberSubIndex=-1;
936 pobj_c->DestructorMemberSubIndex=-1;
937
938 //アクセス制限の初期値をセット
939 if(dwClassType==ESC_CLASS) dwAccess=ACCESS_PRIVATE;
940 else dwAccess=ACCESS_PUBLIC;
941
942 if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
943 //継承を行う場合
944 for(i+=3,i2=0;;i++,i2++){
945 if(IsCommandDelimitation(basbuf[i])){
946 temporary[i2]=0;
947 break;
948 }
949 temporary[i2]=basbuf[i];
950 }
951
952 if(lstrcmpi(temporary,pobj_c->name)==0){
953 SetError(105,temporary,i);
954 goto InheritsError;
955 }
956
957 //継承元クラスを取得
958 pobj_c->pobj_InheritsClass=check(temporary);
959 if(!pobj_c->pobj_InheritsClass){
960 SetError(106,temporary,i);
961 goto InheritsError;
962 }
963
964 //ループ継承でないかをチェック
965 if(pobj_LoopRefCheck->check(temporary)){
966 SetError(123,temporary,i);
967 goto InheritsError;
968 }
969
970 if(pobj_c->pobj_InheritsClass->ppobj_Member==0){
971 //継承先が読み取られていないとき
972 pobj_LoopRefCheck->add(pobj_c->name);
973 GetClass_recur(temporary);
974 pobj_LoopRefCheck->del(pobj_c->name);
975 }
976
977 //メンバ変数をコピー
978 pobj_c->ppobj_Member=(CMember **)HeapReAlloc(
979 hHeap,
980 0,
981 pobj_c->ppobj_Member,
982 pobj_c->pobj_InheritsClass->iMemberNum*sizeof(CMember *));
983 pobj_c->iMemberNum=pobj_c->pobj_InheritsClass->iMemberNum;
984 for(i3=0;i3<pobj_c->pobj_InheritsClass->iMemberNum;i3++){
985 pobj_c->ppobj_Member[i3]=new CMember(pobj_c->pobj_InheritsClass->ppobj_Member[i3]);
986
987 //dwAccess
988 if(pobj_c->pobj_InheritsClass->ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE)
989 pobj_c->ppobj_Member[i3]->dwAccess=ACCESS_NON;
990 else pobj_c->ppobj_Member[i3]->dwAccess=pobj_c->pobj_InheritsClass->ppobj_Member[i3]->dwAccess;
991 }
992
993 //メンバ関数をコピー
994 pobj_c->ppobj_Method=(CMethod **)HeapReAlloc(
995 hHeap,
996 0,
997 pobj_c->ppobj_Method,
998 pobj_c->pobj_InheritsClass->iMethodNum*sizeof(CMethod *));
999 pobj_c->iMethodNum=pobj_c->pobj_InheritsClass->iMethodNum;
1000 for(i3=0;i3<pobj_c->pobj_InheritsClass->iMethodNum;i3++){
1001 pobj_c->ppobj_Method[i3]=new CMethod(pobj_c->pobj_InheritsClass->ppobj_Method[i3]);
1002
1003 //dwAccess
1004 if(pobj_c->pobj_InheritsClass->ppobj_Method[i3]->dwAccess==ACCESS_PRIVATE)
1005 pobj_c->ppobj_Method[i3]->dwAccess=ACCESS_NON;
1006 else pobj_c->ppobj_Method[i3]->dwAccess=pobj_c->pobj_InheritsClass->ppobj_Method[i3]->dwAccess;
1007
1008 //pobj_Inherits
1009 // ※継承元のClassIndexをセット(入れ子継承を考慮する)
1010 if(pobj_c->pobj_InheritsClass->ppobj_Method[i3]->pobj_InheritsClass==0)
1011 pobj_c->ppobj_Method[i3]->pobj_InheritsClass=pobj_c->pobj_InheritsClass;
1012 else
1013 pobj_c->ppobj_Method[i3]->pobj_InheritsClass=
1014 pobj_c->pobj_InheritsClass->ppobj_Method[i3]->pobj_InheritsClass;
1015 }
1016
1017 //仮想関数の数
1018 pobj_c->vtbl_num=pobj_c->pobj_InheritsClass->vtbl_num;
1019 }
1020 else{
1021 //継承無し
1022 pobj_c->pobj_InheritsClass=0;
1023
1024 //仮想関数の数を初期化
1025 pobj_c->vtbl_num=0;
1026 }
1027InheritsError:
1028
1029 //メンバ変数、関数を取得
1030 while(1){
1031 i++;
1032
1033 //エラー
1034 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
1035 SetError(22,"Class",i);
1036 i--;
1037 break;
1038 }
1039
1040 if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
1041 SetError(111,NULL,i);
1042 break;
1043 }
1044
1045 //Static修飾子
1046 BOOL bStatic;
1047 if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
1048 bStatic=1;
1049 i+=2;
1050 }
1051 else bStatic=0;
1052
1053 if(basbuf[i]==1&&(
1054 basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
1055 basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
1056 )){
1057 i3=basbuf[i+1];
1058 sub_address=i;
1059 }
1060 else i3=0;
1061
1062 BOOL bVirtual=0,bAbstract=0,bOverride=0;
1063 if(i3==ESC_ABSTRACT){
1064 bAbstract=1;
1065 bVirtual=1;
1066 i+=2;
1067
1068 i3=basbuf[i+1];
1069 }
1070 else if(i3==ESC_VIRTUAL){
1071 bAbstract=0;
1072 bVirtual=1;
1073 i+=2;
1074
1075 i3=basbuf[i+1];
1076 }
1077 else if(i3==ESC_OVERRIDE){
1078 bOverride=1;
1079 bVirtual=1;
1080
1081 i+=2;
1082
1083 i3=basbuf[i+1];
1084 }
1085
1086 for(i2=0;;i++,i2++){
1087 if(IsCommandDelimitation(basbuf[i])){
1088 temporary[i2]=0;
1089 break;
1090 }
1091 temporary[i2]=basbuf[i];
1092 }
1093 if(temporary[0]=='\0'){
1094 if(basbuf[i]=='\0'){
1095
1096 if(dwClassType==ESC_CLASS)
1097 SetError(22,"Class",top_pos);
1098 else
1099 SetError(22,"Type",top_pos);
1100
1101 i--;
1102 break;
1103 }
1104 continue;
1105 }
1106
1107 //End Class記述の場合
1108 if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
1109 if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
1110
1111 //アクセスを変更
1112 if(lstrcmpi(temporary,"Private")==0){
1113 dwAccess=ACCESS_PRIVATE;
1114 continue;
1115 }
1116 if(lstrcmpi(temporary,"Public")==0){
1117 dwAccess=ACCESS_PUBLIC;
1118 continue;
1119 }
1120 if(lstrcmpi(temporary,"Protected")==0){
1121 dwAccess=ACCESS_PROTECTED;
1122 continue;
1123 }
1124
1125 extern int cp;
1126 if(i3==0){
1127 if(bStatic){
1128 //静的メンバを追加
1129 cp=i; //エラー用
1130 pobj_c->AddStaticMember(dwAccess,temporary,i);
1131 }
1132 else{
1133 //メンバを追加
1134 cp=i; //エラー用
1135 pobj_c->AddMember(dwAccess,temporary);
1136
1137
1138 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.type==DEF_OBJECT){
1139 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.u.pobj_Class->ppobj_Member==0){
1140 //参照先が読み取られていないとき
1141 GetClass_recur(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.u.pobj_Class->name);
1142 }
1143 }
1144
1145
1146 if(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.type==DEF_OBJECT){
1147 //循環参照のチェック
1148 pobj_LoopRefCheck->add(pobj_c->name);
1149 if(!MemberVar_LoopRefCheck(pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.u.pobj_Class)){
1150 //エラー回避
1151 pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->TypeInfo.type=DEF_PTR_VOID;
1152 }
1153 pobj_LoopRefCheck->del(pobj_c->name);
1154 }
1155 }
1156 }
1157 else{
1158 //メソッドを追加
1159 cp=i; //エラー用
1160 AddMemberSub(pobj_c,dwAccess,bStatic,bAbstract,bVirtual,bOverride,temporary,sub_address);
1161
1162 if(bAbstract) continue;
1163
1164 for(;;i++){
1165 if(basbuf[i]=='\0'){
1166 i--;
1167 break;
1168 }
1169 if(basbuf[i-1]!='*'&&
1170 basbuf[i]==1&&(
1171 basbuf[i+1]==ESC_SUB||
1172 basbuf[i+1]==ESC_FUNCTION||
1173 basbuf[i+1]==ESC_MACRO||
1174 basbuf[i+1]==ESC_TYPE||
1175 basbuf[i+1]==ESC_CLASS||
1176 basbuf[i+1]==ESC_INTERFACE||
1177 basbuf[i+1]==ESC_ENUM)){
1178 GetDefaultNameFromES(i3,temporary);
1179 SetError(22,temporary,i);
1180 }
1181 if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
1182 i+=2;
1183 break;
1184 }
1185 }
1186 }
1187 }
1188 }
1189 }
1190}
1191
1192void CDBClass::GetObjectClassInfo(void){
1193 //ループ継承チェック用のクラス
1194 pobj_LoopRefCheck=new CLoopRefCheck();
1195
1196 //クラスを取得
1197 GetClass_recur(0);
1198
1199 delete pobj_LoopRefCheck;
1200 pobj_LoopRefCheck=0;
1201}
1202
1203
1204
1205
1206//////////////////////
1207// イテレータ
1208//////////////////////
1209
1210void CDBClass::Iterator_Reset(void){
1211 if(ppobj_IteClass) HeapDefaultFree(ppobj_IteClass);
1212
1213 iIteMaxNum=0;
1214 iIteNextNum=0;
1215 ppobj_IteClass=(CClass **)HeapAlloc(hHeap,0,1);
1216
1217 int i;
1218 for(i=0;i<MAX_CLASS_HASH;i++){
1219 if(pobj_ClassHash[i]){
1220 CClass *pobj_c;
1221 pobj_c=pobj_ClassHash[i];
1222 while(1){
1223 ppobj_IteClass=(CClass **)HeapReAlloc(hHeap,0,ppobj_IteClass,(iIteMaxNum+1)*sizeof(CClass *));
1224 ppobj_IteClass[iIteMaxNum]=pobj_c;
1225 iIteMaxNum++;
1226
1227 if(pobj_c->pobj_NextClass==0) break;
1228 pobj_c=pobj_c->pobj_NextClass;
1229 }
1230 }
1231 }
1232}
1233BOOL CDBClass::Iterator_HasNext(void){
1234 if(iIteNextNum<iIteMaxNum) return 1;
1235 return 0;
1236}
1237CClass *CDBClass::Iterator_GetNext(void){
1238 CClass *pobj_c;
1239 pobj_c=ppobj_IteClass[iIteNextNum];
1240 iIteNextNum++;
1241 return pobj_c;
1242}
1243int CDBClass::Iterator_GetMaxCount(void){
1244 return iIteMaxNum;
1245}
Note: See TracBrowser for help on using the repository browser.