source: dev/BasicCompiler_Common/Subroutine.cpp@ 52

Last change on this file since 52 was 50, checked in by dai_9181, 18 years ago

オーバーロード解決用の関数保持リストを "SUBINFO " ではなく、"vector<SUBINFO *>" に変更した。

File size: 34.3 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
6#include "../BasicCompiler32/opcode.h"
7#endif
8
9//コンパイル中の関数情報
10SUBINFO *pCompilingSubInfo;
11
12int GetCallProcName(char *buffer,char *name){
13 int i2,i3,IsStr=0;
14
15 for(i2=0;;i2++){
16 if(buffer[i2]=='\"') IsStr^=1;
17 if(IsDBCSLeadByte(buffer[i2])){
18 name[i2]=buffer[i2];
19 i2++;
20 name[i2]=buffer[i2];
21 continue;
22 }
23 if(buffer[i2]=='['&&IsStr==0){
24 i3=GetStringInBracket(name+i2,buffer+i2);
25 i2+=i3-1;
26 continue;
27 }
28 if(buffer[i2]=='('&&IsStr==0){
29 name[i2]=0;
30 break;
31 }
32 if(buffer[i2]=='='&&IsStr==0){
33 name[i2]=0;
34 break;
35 }
36
37 name[i2]=buffer[i2];
38 if(buffer[i2]=='\0') break;
39 }
40 return i2;
41}
42
43int GetProc(char *name,void **ppInfo){
44
45 //ユーザー定義関数
46 *ppInfo=(void *)GetSubHash(name);
47 if(*ppInfo) return PROC_DEFAULT;
48
49 //DLL関数
50 *ppInfo=(void *)GetDeclareHash(name);
51 if(*ppInfo) return PROC_DLL;
52
53 //コンパイラ埋め込み型
54 *ppInfo=(void *)(_int64)GetFunctionFromName(name);
55 if(*ppInfo) return PROC_BUILTIN;
56
57 //関数ポインタ
58 int type;
59 LONG_PTR lpIndex;
60 type=GetVarType(name,&lpIndex,0);
61 if(type==DEF_PTR_PROC) return PROC_PTR;
62
63 return 0;
64}
65
66void SplitObjectName(const char *name,char *ObjectName,int *pRefType){
67 int i4;
68 for(i4=lstrlen(name)-1;i4>=0;i4--){
69 if(name[i4]=='.'||(name[i4]==1&&name[i4+1]==ESC_PSMEM))
70 break;
71 }
72 if(i4==-1) ObjectName[0]=0;
73 else{
74 //参照タイプを判別
75 if(name[i4]=='.') *pRefType=DEF_OBJECT;
76 else *pRefType=DEF_PTR_OBJECT;
77
78 if(i4==0) GetWithName(ObjectName);
79 else{
80 memcpy(ObjectName,name,i4);
81 ObjectName[i4]=0;
82 }
83 }
84}
85bool SplitMemberName( const char *desc, char *object, char *member ){
86 int i;
87 for(i=lstrlen(desc)-1;i>=0;i--){
88 if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM))
89 break;
90 }
91 if(i==-1) return false;
92 else{
93 if(desc[i]=='.')
94 lstrcpy(member,desc+i+1);
95 else
96 lstrcpy(member,desc+i+2);
97
98 if( object ){
99 lstrcpy( object, desc );
100 object[i]=0;
101 }
102 }
103
104 return true;
105}
106
107
108int CallProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
109 int ret_type;
110
111 if(idProc==PROC_DEFAULT){
112 /////////////////////
113 // ユーザー定義関数
114 /////////////////////
115
116 SUBINFO *psi;
117 psi=(SUBINFO *)pInfo;
118
119 //GetSubHash内でエラー提示が行われた場合
120 if(psi==(SUBINFO *)-1) return -1;
121
122
123 //オブジェクト名を取得
124 char ObjectName[VN_SIZE];
125 int RefType;
126 SplitObjectName(name,ObjectName,&RefType);
127
128
129 ////////////////////////
130 // オーバーロードを解決
131 ////////////////////////
132
133 std::vector<SUBINFO *> subs;
134 GetOverloadSubHash(name,subs);
135 if(subs.size()){
136 //オーバーロードを解決
137 psi=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
138
139 if(!psi) return 0;
140 }
141
142
143 Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);
144 if( plpRetIndex ){
145 *plpRetIndex = psi->u.ReturnIndex;
146 }
147 return psi->ReturnType;
148 }
149 else if(idProc==PROC_DLL){
150 /////////////////////////
151 // DLL関数
152 /////////////////////////
153 DECLAREINFO *pdi;
154 pdi=(DECLAREINFO *)pInfo;
155
156 ret_type=Opcode_CallDllProc(Parameter,pdi,plpRetIndex);
157 }
158 else if(idProc==PROC_BUILTIN){
159 /////////////////////////
160 // 組み込み関数
161 /////////////////////////
162 int FuncId;
163 FuncId=(int)(_int64)pInfo;
164
165 TYPEINFO ReturnTypeInfo = { DEF_LONG, NULL };
166 Opcode_CallFunc( Parameter, FuncId, ReturnTypeInfo );
167 if( plpRetIndex ){
168 *plpRetIndex = ReturnTypeInfo.u.lpIndex;
169 }
170 return ReturnTypeInfo.type;
171 }
172 else if(idProc==PROC_PTR){
173 /////////////////
174 // 関数ポインタ
175 /////////////////
176
177 LONG_PTR lpIndex;
178 GetVarType(name,&lpIndex,0);
179
180 extern PROCPTRINFO *pProcPtrInfo;
181 ret_type=Opcode_CallProcPtr(name,Parameter,&pProcPtrInfo[lpIndex],plpRetIndex);
182 }
183
184 return ret_type;
185}
186BOOL CallPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
187 //プロパティ用のメソッドを呼び出す
188
189 //配列要素を取得
190 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
191 GetArrayElement(variable,VarName,ArrayElements);
192
193 //オブジェクト名を取得
194 char ObjectName[VN_SIZE];
195 int RefType;
196 SplitObjectName(VarName,ObjectName,&RefType);
197
198 //オーバーロード用の関数リストを作成
199 std::vector<SUBINFO *> subs;
200 GetOverloadSubHash(VarName,subs);
201 if(subs.size()==0){
202 return 0;
203 }
204
205 //パラメータを整備
206 char *Parameter;
207 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);
208 lstrcpy(Parameter,ArrayElements);
209 if(RightSide){
210 if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");
211 lstrcat(Parameter,RightSide);
212 }
213
214 //オーバーロードを解決
215 SUBINFO *psi;
216 psi=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
217
218 if(psi){
219 //呼び出し
220 Opcode_CallProc(Parameter,psi,0,ObjectName,RefType);
221
222 if( pRetTypeInfo ){
223 pRetTypeInfo->type = psi->ReturnType;
224 pRetTypeInfo->u.lpIndex = psi->u.ReturnIndex;
225 }
226 }
227
228 HeapDefaultFree(Parameter);
229
230 return 1;
231}
232
233
234int GetReturnTypeOfProc(int idProc,void *pInfo,char *name,char *Parameter,LONG_PTR *plpRetIndex){
235 int ret_type;
236
237 if(idProc==PROC_DEFAULT){
238 /////////////////////
239 // ユーザー定義関数
240 /////////////////////
241
242 SUBINFO *psi;
243 psi=(SUBINFO *)pInfo;
244
245 //GetSubHash内でエラー提示が行われた場合
246 if(psi==(SUBINFO *)-1) return -1;
247
248
249 //オブジェクト名を取得
250 char ObjectName[VN_SIZE];
251 int RefType;
252 SplitObjectName(name,ObjectName,&RefType);
253
254
255 ////////////////////////
256 // オーバーロードを解決
257 ////////////////////////
258
259 std::vector<SUBINFO *> subs;
260 GetOverloadSubHash(name,subs);
261 if( subs.size() > 0 ){
262 //オーバーロードを解決
263 psi=OverloadSolutionWithStrParam(name,subs,Parameter,ObjectName,NULL);
264
265 if(!psi) return 0;
266 }
267
268
269 ret_type=psi->ReturnType;
270 *plpRetIndex=psi->u.ReturnIndex;
271 }
272 else if(idProc==PROC_DLL){
273 /////////////////////////
274 // DLL関数
275 /////////////////////////
276 DECLAREINFO *pdi;
277 pdi=(DECLAREINFO *)pInfo;
278
279 ret_type=pdi->ReturnType;
280 *plpRetIndex=pdi->u.ReturnIndex;
281 }
282 else if(idProc==PROC_BUILTIN){
283 /////////////////////////
284 // 組み込み関数
285 /////////////////////////
286 int FuncId;
287 FuncId=(int)(_int64)pInfo;
288
289 ret_type=GetFunctionType(FuncId);
290 *plpRetIndex=-1;
291 }
292 else if(idProc==PROC_PTR){
293 /////////////////
294 // 関数ポインタ
295 /////////////////
296
297 LONG_PTR lpIndex;
298 GetVarType(name,&lpIndex,0);
299
300 extern PROCPTRINFO *pProcPtrInfo;
301 ret_type=pProcPtrInfo[lpIndex].ReturnType;
302 *plpRetIndex=pProcPtrInfo[lpIndex].u.ReturnIndex;
303 }
304
305 return ret_type;
306}
307BOOL GetReturnTypeOfPropertyMethod(char *variable,char *RightSide,TYPEINFO *pRetTypeInfo){
308 //プロパティ用のメソッドを呼び出す
309
310 //配列要素を取得
311 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
312 GetArrayElement(variable,VarName,ArrayElements);
313
314 //オブジェクト名を取得
315 char ObjectName[VN_SIZE];
316 int RefType;
317 SplitObjectName(VarName,ObjectName,&RefType);
318
319 //オーバーロード用の関数リストを作成
320 std::vector<SUBINFO *> subs;
321 GetOverloadSubHash(VarName,subs);
322 if(subs.size()==0){
323 return 0;
324 }
325
326 //パラメータを整備
327 char *Parameter;
328 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(RightSide)+32);
329 lstrcpy(Parameter,ArrayElements);
330 if(RightSide){
331 if(Parameter[0]&&RightSide[0]) lstrcat(Parameter,",");
332 lstrcat(Parameter,RightSide);
333 }
334
335 //オーバーロードを解決
336 SUBINFO *psi;
337 psi=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName,NULL);
338
339 if(psi){
340 if(pRetTypeInfo){
341 pRetTypeInfo->type=psi->ReturnType;
342 pRetTypeInfo->u.lpIndex=psi->u.ReturnIndex;
343 }
344 }
345
346 return 1;
347}
348
349//インデクサ(getter)の戻り値を取得
350bool GetReturnTypeOfIndexerGetterProc(CClass *pobj_Class,TYPEINFO &RetTypeInfo){
351 std::vector<SUBINFO *> subs;
352 pobj_Class->EnumMethod( CALC_ARRAY_GET, subs );
353 if( subs.size() == 0 ){
354 return false;
355 }
356
357 RetTypeInfo.type = subs[0]->ReturnType;
358 RetTypeInfo.u.lpIndex = subs[0]->u.ReturnIndex;
359
360 return true;
361}
362
363
364void AddDeclareData(char *buffer,int NowLine){
365 extern HANDLE hHeap;
366 int i,i2,i3,i4,sw,IsFunction;
367 char temporary[VN_SIZE];
368
369 i=0;
370
371 DWORD dwType;
372 BOOL bCdecl=0;
373
374 //Static/Dynamic
375 if(buffer[i]==ESC_STATIC){
376 dwType=DECLARE_STATIC;
377 i++;
378 }
379 else dwType=DECLARE_DYNAMIC;
380
381 //Sub/Function
382 if(buffer[i]==ESC_SUB) IsFunction=0;
383 else if(buffer[i]==ESC_FUNCTION) IsFunction=1;
384 else{
385 SetError(1,NULL,NowLine);
386 return;
387 }
388 i++;
389
390 //プロシージャ名
391 for(i2=0;;i++,i2++){
392 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL){
393 bCdecl=1;
394
395 i+=2;
396 temporary[i2]=0;
397 break;
398 }
399 if(buffer[i]==','){
400 temporary[i2]=0;
401 break;
402 }
403 if(buffer[i]=='\0'){
404 SetError(1,NULL,NowLine);
405 return;
406 }
407 temporary[i2]=buffer[i];
408 }
409
410 //ユーザー定義関数との重複チェック
411 if(GetSubHash(temporary)){
412 SetError(15,temporary,NowLine);
413 return;
414 }
415
416
417 /////////////////////////////////
418 // 格納位置を計算してpciにセット
419 /////////////////////////////////
420
421 //ハッシュ値を取得
422 int key;
423 key=hash_default(temporary);
424
425 extern DECLAREINFO **ppDeclareHash;
426 DECLAREINFO *pdi;
427 if(ppDeclareHash[key]){
428 pdi=ppDeclareHash[key];
429 while(1){
430 if(lstrcmpi(pdi->name,temporary)==0){
431 //重複エラー
432 SetError(15,temporary,NowLine);
433 return;
434 }
435
436 if(pdi->pNextData==0){
437 pdi->pNextData=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO));
438 break;
439 }
440 pdi=pdi->pNextData;
441 }
442 pdi=pdi->pNextData;
443 }
444 else{
445 ppDeclareHash[key]=(DECLAREINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(DECLAREINFO));
446 pdi=ppDeclareHash[key];
447 }
448
449 pdi->dwType=dwType;
450 pdi->bCdecl=bCdecl;
451
452 pdi->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
453 lstrcpy(pdi->name,temporary);
454 i++;
455
456 //ライブラリ
457 if(buffer[i]!='\"'){
458 SetError(1,NULL,NowLine);
459 return;
460 }
461 for(i++,i2=0;;i++,i2++){
462 if(buffer[i]=='\"'){
463 temporary[i2]=0;
464 break;
465 }
466 if(buffer[i]=='\0'){
467 SetError(1,NULL,NowLine);
468 return;
469 }
470 temporary[i2]=buffer[i];
471 }
472 CharUpper(temporary);
473 if(!strstr(temporary,".")){
474 if(pdi->dwType==DECLARE_STATIC) lstrcat(temporary,".LIB");
475 else{
476 lstrcat(temporary,".DLL");
477 if(lstrlen(temporary)>=16){
478 SetError(7,NULL,NowLine);
479 return;
480 }
481 }
482 }
483 pdi->file=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
484 lstrcpy(pdi->file,temporary);
485 i++;
486
487 if(buffer[i]==','){
488 i++;
489 if(buffer[i]!='\"'){
490 SetError(1,NULL,NowLine);
491 return;
492 }
493 for(i++,i2=0;;i++,i2++){
494 if(buffer[i]=='\"'){
495 temporary[i2]=0;
496 break;
497 }
498 if(buffer[i]=='\0'){
499 SetError(1,NULL,NowLine);
500 return;
501 }
502 temporary[i2]=buffer[i];
503 }
504 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
505 lstrcpy(pdi->alias,temporary);
506 i++;
507 }
508 else{
509 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(pdi->name)+1);
510 lstrcpy(pdi->alias,pdi->name);
511 }
512
513 //パラメータの始めのカッコ
514 if(buffer[i]!='('){
515 SetError(1,NULL,NowLine);
516 return;
517 }
518 i++;
519
520 pdi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
521
522 //各パラメータ
523 for(i3=0;;i3++){
524 if(buffer[i]==')') break;
525
526 pdi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pdi->pParmInfo,(i3+1)*sizeof(PARAMETER_INFO));
527
528 //ByVal
529 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
530 pdi->pParmInfo[i3].bByVal=1;
531 i+=2;
532 }
533 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
534 pdi->pParmInfo[i3].bByVal=0;
535 i+=2;
536 }
537 else pdi->pParmInfo[i3].bByVal=1;
538
539 //変数名は無視(temporaryの変数名は型宣言文字判断のため)
540 sw=0;
541 for(i2=0;;i++,i2++){
542 if(buffer[i]=='('){
543 if(!sw) sw=1;
544
545 i4=GetStringInPare(temporary+i2,buffer+i);
546 i2+=i4-1;
547 i+=i4-1;
548 continue;
549 }
550 if(buffer[i]=='['){
551 if(!sw) sw=1;
552
553 i4=GetStringInBracket(temporary+i2,buffer+i);
554 i2+=i4-1;
555 i+=i4-1;
556 continue;
557 }
558 if(!IsVariableChar(buffer[i])){
559 temporary[i2]=0;
560 break;
561 }
562 temporary[i2]=buffer[i];
563 }
564 if(lstrcmp(temporary,"...")==0) pdi->pParmInfo[i3].type=DEF_ELLIPSE;
565 else{
566 //型
567 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
568 i+=2;
569 for(i2=0;;i++,i2++){
570 if(!(IsVariableChar(buffer[i])||buffer[i]=='*')){
571 temporary[i2]=0;
572 break;
573 }
574 temporary[i2]=buffer[i];
575 }
576 pdi->pParmInfo[i3].type=GetTypeFixed(temporary,&pdi->pParmInfo[i3].u.index);
577 }
578 else{
579 pdi->pParmInfo[i3].type=GetTypeFromSimpleName(temporary);
580 SetError(-103,temporary,NowLine);
581 }
582
583 if(sw){
584 //配列ポインタを引き渡すとき
585 pdi->pParmInfo[i3].type=GetPtrType(pdi->pParmInfo[i3].type,pdi->pParmInfo[i3].u.index);
586 }
587 }
588
589 //名前はダミー(使用しないため)
590 pdi->pParmInfo[i3].name="";
591
592 //構造体の場合はエラーチェック
593 if(pdi->pParmInfo[i3].type==-1) SetError(3,temporary,NowLine);
594 if(pdi->pParmInfo[i3].type==DEF_OBJECT){
595 if(pdi->pParmInfo[i3].bByVal) pdi->pParmInfo[i3].type=DEF_LONG;//SetError(28,temporary,NowLine);
596 }
597
598 //構造体アドレスの空白部
599 while(buffer[i]==' ') i++;
600
601 if(buffer[i]==','){
602 i++;
603 continue;
604 }
605 else if(buffer[i]==')') continue;
606 else{
607 SetError(1,NULL,NowLine);
608 break;
609 }
610 }
611 pdi->ParmNum=i3;
612
613 //戻り値
614 i++;
615 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
616 if(IsFunction==0) SetError(1,NULL,NowLine);
617 i+=2;
618 pdi->ReturnType=GetTypeFixed(buffer+i,&pdi->u.ReturnIndex);
619 if(pdi->ReturnType==-1) SetError(3,buffer+i,NowLine);
620 if(pdi->ReturnType==DEF_OBJECT) SetError(40,NULL,NowLine);
621 }
622 else if(buffer[i]) SetError(1,NULL,NowLine);
623 else pdi->ReturnType=-1;
624
625 pdi->pos=NowLine;
626}
627
628BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2){
629 if(pi_num1!=pi_num2) return 1;
630
631 int i;
632 for(i=0;i<pi_num1;i++){
633 if(ppi1[i].type!=ppi2[i].type){
634
635 if(ppi1[i].bByVal==0&&ppi1[i].type==DEF_ANY&&
636 ppi2[i].bByVal==1&&IsPtrType(ppi2[i].type)||
637 ppi1[i].bByVal==1&&IsPtrType(ppi1[i].type)&&
638 ppi2[i].bByVal==0&&ppi2[i].type==DEF_ANY){
639 /* ByRef var As Any
640
641 var As VoidPtr
642 は同等
643 */
644 continue;
645 }
646
647 return 1;
648 }
649 else{
650 if(NATURAL_TYPE(ppi1[i].type)==DEF_OBJECT){
651 if(ppi1[i].u.index!=ppi2[i].u.index) return 1;
652 }
653 }
654 }
655
656 return 0;
657}
658SUBINFO *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic){
659 int i,i2,i3,sw;
660 DWORD dwType;
661 char temporary[8192],temp2[VN_SIZE];
662
663 i=1;
664 if(buffer[i]==ESC_SUB) dwType=SUBTYPE_SUB;
665 else if(buffer[i]==ESC_FUNCTION) dwType=SUBTYPE_FUNCTION;
666 else if(buffer[i]==ESC_MACRO) dwType=SUBTYPE_MACRO;
667
668 i++;
669
670 BOOL bExport=0,bCdecl=0;
671 while(1){
672 if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&&bExport==0){
673 bExport=1;
674
675 i+=2;
676 }
677 else if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&&bCdecl==0){
678 bCdecl=1;
679
680 i+=2;
681 }
682 else break;
683 }
684
685 i2=0;
686 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
687 if(!pobj_c){
688 SetError(126,NULL,NowLine);
689 return 0;
690 }
691
692 //オペレータの場合
693 temporary[i2++]=buffer[i++];
694 temporary[i2++]=buffer[i++];
695
696 int iCalcId;
697 if(buffer[i]=='='&&buffer[i+1]=='='){
698 iCalcId=CALC_EQUAL;
699 i3=2;
700 }
701 else if(buffer[i]=='='){
702 iCalcId=CALC_SUBSITUATION;
703 i3=1;
704 }
705 else if(buffer[i]=='('){
706 iCalcId=CALC_AS;
707 i3=0;
708 }
709 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){
710 iCalcId=CALC_ARRAY_SET;
711 i3=3;
712 }
713 else if(buffer[i]=='['&&buffer[i+1]==']'){
714 iCalcId=CALC_ARRAY_GET;
715 i3=2;
716 }
717 else{
718 iCalcId=GetCalcId(buffer+i,&i3);
719 i3++;
720 }
721 if(!iCalcId){
722 SetError(1,NULL,NowLine);
723 return 0;
724 }
725 temporary[i2++]=iCalcId;
726 temporary[i2]=0;
727
728 i+=i3;
729 }
730 else{
731 if(pobj_c){
732 //クラスメンバの場合、デストラクタには~が付くことを考慮
733 if(buffer[i]=='~'){
734 temporary[i2]='~';
735 i++;
736 i2++;
737 }
738 }
739
740 for(;;i++,i2++){
741 if(!IsVariableChar(buffer[i])){
742 temporary[i2]=0;
743 break;
744 }
745 temporary[i2]=buffer[i];
746 }
747 }
748
749 if(dwType==SUBTYPE_MACRO){
750 //大文字に変換
751 CharUpper(temporary);
752
753 //マクロ関数の場合は名前リストに追加
754 extern char **ppMacroNames;
755 extern int MacroNum;
756 ppMacroNames=(char **)HeapReAlloc(hHeap,0,ppMacroNames,(MacroNum+1)*sizeof(char *));
757 ppMacroNames[MacroNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
758 lstrcpy(ppMacroNames[MacroNum],temporary);
759 MacroNum++;
760 }
761
762 if(!pobj_c){
763 //クラスメンバ以外の場合のみ
764 //重複チェック
765
766 if(GetDeclareHash(temporary)){
767 SetError(15,temporary,NowLine);
768 return 0;
769 }
770 }
771
772 extern int SubNum;
773 SubNum++;
774
775 SUBINFO *psi;
776 psi=(SUBINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(SUBINFO));
777
778 //クラス名
779 psi->pobj_ParentClass=pobj_c;
780
781 //ID
782 static int id_base=0;
783 psi->id=(id_base++);
784
785 //関数名
786 psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
787 lstrcpy(psi->name,temporary);
788
789 //ソースコードの位置
790 psi->address=NowLine;
791
792 psi->bExport=bExport;
793 psi->bCdecl=bCdecl;
794 psi->bVirtual=bVirtual;
795 if(bExport) psi->bUse=1;
796 else psi->bUse=0;
797 psi->bCompile=0;
798 psi->bSystem=0;
799
800 psi->dwType=dwType;
801
802
803 if(psi->dwType==SUBTYPE_FUNCTION){
804 ///////////////////
805 // 戻り値を取得
806 ///////////////////
807
808 psi->isReturnRef = false;
809
810 if(pobj_c){
811 if(lstrcmp(psi->name,pobj_c->name)==0||
812 psi->name[0]=='~'){
813 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
814 SetError(115,NULL,NowLine);
815 }
816 }
817
818
819 i2=lstrlen(buffer)-2;
820
821 int sw_as=0;
822 for(;i2>0;i2--){
823 if(buffer[i2]==')') break;
824
825 if(buffer[i2]==1&&buffer[i2+1]==ESC_AS){
826 if( buffer[i2-2] == 1 && buffer[i2-1] == ESC_BYREF ){
827 //参照型
828 psi->isReturnRef = true;
829 }
830
831 i2+=2;
832 i3=0;
833 while(buffer[i2]=='*') temporary[i3++]=buffer[i2++];
834 for(;;i2++,i3++){
835 if(!IsVariableChar(buffer[i2])){
836 temporary[i3]=0;
837 break;
838 }
839 temporary[i3]=buffer[i2];
840 }
841 psi->ReturnType=GetTypeFixed(temporary,&psi->u.ReturnIndex);
842 if(psi->ReturnType==-1) SetError(3,temporary,NowLine);
843
844 sw_as=1;
845 break;
846 }
847 }
848
849 if(!sw_as){
850 SetError(-104,psi->name,NowLine);
851
852 psi->ReturnType=DEF_DOUBLE;
853 }
854 }
855 else{
856 //戻り値なしのSub定義
857 psi->ReturnType=-1;
858 psi->u.ReturnIndex=-1;
859 }
860
861
862
863 psi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(PARAMETER_INFO)*2);
864 psi->ParmNum=0;
865
866 //パラメータ
867 if(buffer[i]!='('){
868 SetError(1,NULL,NowLine);
869 return 0;
870 }
871 i++;
872 if(buffer[i]!=')'&&pobj_c){
873 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
874 if(psi->name[0]=='~'){
875 SetError(114,NULL,NowLine);
876 i=JumpStringInPare(buffer,i);
877 }
878 }
879 while(1){
880 if(buffer[i]==')') break;
881
882 psi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,psi->pParmInfo,(psi->ParmNum+1)*sizeof(PARAMETER_INFO));
883
884 //ByVal
885 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
886 psi->pParmInfo[psi->ParmNum].bByVal=1;
887 i+=2;
888 }
889 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
890 psi->pParmInfo[psi->ParmNum].bByVal=0;
891 i+=2;
892 }
893 else psi->pParmInfo[psi->ParmNum].bByVal=1;
894
895 //パラメータ名
896 sw=0;
897 for(i2=0;;i++,i2++){
898 if(buffer[i]=='('){
899 if(!sw) sw=1;
900
901 i3=GetStringInPare(temporary+i2,buffer+i);
902 i2+=i3-1;
903 i+=i3-1;
904 continue;
905 }
906 if(buffer[i]=='['){
907 if(!sw) sw=1;
908
909 i3=GetStringInBracket(temporary+i2,buffer+i);
910 i2+=i3-1;
911 i+=i3-1;
912 continue;
913 }
914 if(!IsVariableChar(buffer[i])){
915 temporary[i2]=0;
916 break;
917 }
918 temporary[i2]=buffer[i];
919 }
920 if(sw){
921 //配列パラメータ
922 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(29,NULL,NowLine);
923 psi->pParmInfo[psi->ParmNum].bArray=1;
924
925 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
926 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
927 psi->pParmInfo[psi->ParmNum].SubScripts[0]=LONG_MAX;
928 psi->pParmInfo[psi->ParmNum].SubScripts[1]=-1;
929
930 temporary[i2-2]=0;
931 }
932 else{
933 GetArrange(temporary,temp2,psi->pParmInfo[psi->ParmNum].SubScripts);
934 lstrcpy(temporary,temp2);
935 }
936
937 i2=lstrlen(temporary);
938 }
939 else{
940 psi->pParmInfo[psi->ParmNum].bArray=0;
941 psi->pParmInfo[psi->ParmNum].SubScripts[0]=-1;
942 }
943 psi->pParmInfo[psi->ParmNum].name=(char *)HeapAlloc(hHeap,0,i2+1);
944 lstrcpy(psi->pParmInfo[psi->ParmNum].name,temporary);
945
946 //型
947 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
948 i+=2;
949
950 i2=0;
951 while(buffer[i]=='*'){
952 temporary[i2]=buffer[i];
953 i++;
954 i2++;
955 }
956 for(;;i++,i2++){
957 if(!IsVariableChar(buffer[i])){
958 if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){
959 temporary[i2++]=buffer[i++];
960 temporary[i2]=buffer[i];
961 continue;
962 }
963 temporary[i2]=0;
964 break;
965 }
966 temporary[i2]=buffer[i];
967 }
968
969 psi->pParmInfo[psi->ParmNum].type=
970 GetTypeFixed(temporary,&psi->pParmInfo[psi->ParmNum].u.index);
971
972 if(temporary[0]=='*'&&
973 temporary[1]==1&&
974 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){
975 if(buffer[i]!='('){
976 SetError(10,temporary,NowLine);
977 return 0;
978 }
979 i3=GetStringInPare(temporary+i2,buffer+i);
980 i+=i3;
981 i2+=i3;
982
983 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){
984 temporary[i2++]=buffer[i++];
985 temporary[i2++]=buffer[i++];
986 for(;;i++,i2++){
987 if(!IsVariableChar(buffer[i])){
988 temporary[i2]=0;
989 break;
990 }
991 temporary[i2]=buffer[i];
992 }
993 }
994 }
995 else{
996 //TypeDefをする前のベース型を取得
997 GetOriginalTypeName(temporary);
998 }
999
1000 if(psi->pParmInfo[psi->ParmNum].type==-1){
1001 SetError(3,temporary,NowLine);
1002 psi->pParmInfo[psi->ParmNum].type=DEF_PTR_VOID;
1003 }
1004
1005 /*未完成(構造体パラメータを値参照として渡してよいものか!?)
1006 if(psi->pParmInfo[psi->ParmNum].type==DEF_OBJECT){
1007 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(28,temporary,NowLine);
1008 }*/
1009 }
1010 else{
1011 psi->pParmInfo[psi->ParmNum].type=GetTypeFromSimpleName(temporary);
1012 SetError(-103,temporary,NowLine);
1013 }
1014
1015 if(psi->pParmInfo[psi->ParmNum].type==DEF_PTR_PROC){
1016 //関数ポインタの場合
1017 psi->pParmInfo[psi->ParmNum].u.index=AddProcPtrInfo(temporary+3,temporary[2]);
1018 }
1019
1020 //パラメータの数を更新
1021 psi->ParmNum++;
1022
1023 if(buffer[i]==','){
1024 i++;
1025 continue;
1026 }
1027 else if(buffer[i]==')') continue;
1028 else{
1029 SetError(1,NULL,NowLine);
1030 return 0;
1031 }
1032 }
1033 psi->SecondParmNum=psi->ParmNum;
1034 i++;
1035 if(buffer[i]=='('){
1036 i++;
1037 while(1){
1038 if(buffer[i]==')') break;
1039
1040 psi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,psi->pParmInfo,(psi->ParmNum+1)*sizeof(PARAMETER_INFO));
1041
1042 //ByVal
1043 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
1044 psi->pParmInfo[psi->ParmNum].bByVal=1;
1045 i+=2;
1046 }
1047 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
1048 psi->pParmInfo[psi->ParmNum].bByVal=0;
1049 i+=2;
1050 }
1051 else psi->pParmInfo[psi->ParmNum].bByVal=1;
1052
1053 //パラメータ名
1054 sw=0;
1055 for(i2=0;;i++,i2++){
1056 if(buffer[i]=='('){
1057 if(!sw) sw=1;
1058
1059 i3=GetStringInPare(temporary+i2,buffer+i);
1060 i2+=i3-1;
1061 i+=i3-1;
1062 continue;
1063 }
1064 if(buffer[i]=='['){
1065 if(!sw) sw=1;
1066
1067 i3=GetStringInBracket(temporary+i2,buffer+i);
1068 i2+=i3-1;
1069 i+=i3-1;
1070 continue;
1071 }
1072 if(!IsVariableChar(buffer[i])){
1073 temporary[i2]=0;
1074 break;
1075 }
1076 temporary[i2]=buffer[i];
1077 }
1078 if(sw){
1079 //配列パラメータ
1080 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(29,NULL,NowLine);
1081 psi->pParmInfo[psi->ParmNum].bArray=1;
1082
1083 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
1084 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
1085 psi->pParmInfo[psi->ParmNum].SubScripts[0]=LONG_MAX;
1086 psi->pParmInfo[psi->ParmNum].SubScripts[1]=-1;
1087
1088 temporary[i2-2]=0;
1089 }
1090 else{
1091 GetArrange(temporary,temp2,psi->pParmInfo[psi->ParmNum].SubScripts);
1092 lstrcpy(temporary,temp2);
1093 }
1094
1095 i2=lstrlen(temporary);
1096 }
1097 else{
1098 psi->pParmInfo[psi->ParmNum].bArray=0;
1099 psi->pParmInfo[psi->ParmNum].SubScripts[0]=-1;
1100 }
1101 psi->pParmInfo[psi->ParmNum].name=(char *)HeapAlloc(hHeap,0,i2+1);
1102 lstrcpy(psi->pParmInfo[psi->ParmNum].name,temporary);
1103
1104 //型
1105 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1106 i+=2;
1107 i2=0;
1108 while(buffer[i]=='*'){
1109 temporary[i2]=buffer[i];
1110 i++;
1111 i2++;
1112 }
1113 for(;;i++,i2++){
1114 if(!IsVariableChar(buffer[i])){
1115 temporary[i2]=0;
1116 break;
1117 }
1118 temporary[i2]=buffer[i];
1119 }
1120 psi->pParmInfo[psi->ParmNum].type=
1121 GetTypeFixed(temporary,&psi->pParmInfo[psi->ParmNum].u.index);
1122 if(psi->pParmInfo[psi->ParmNum].type==-1) SetError(3,temporary,NowLine);
1123 }
1124 else{
1125 psi->pParmInfo[psi->ParmNum].type=GetTypeFromSimpleName(temporary);
1126 SetError(-103,temporary,NowLine);
1127 }
1128
1129 psi->ParmNum++;
1130
1131 if(buffer[i]==','){
1132 i++;
1133 continue;
1134 }
1135 else if(buffer[i]==')') continue;
1136 else{
1137 SetError(1,NULL,NowLine);
1138 return 0;
1139 }
1140 }
1141 i++;
1142 }
1143
1144 //リアルパラメータ領域を取得(_System_LocalThis、_System_ReturnValueを考慮して2つだけ多く確保する)
1145 psi->pRealParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,(psi->ParmNum+2)*sizeof(PARAMETER_INFO));
1146 psi->RealParmNum=0;
1147
1148 if(pobj_c&&bStatic==0){
1149 i = psi->RealParmNum;
1150
1151 //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用
1152 psi->pRealParmInfo[i].name = "_System_LocalThis";
1153 psi->pRealParmInfo[i].type=DEF_PTR_VOID;
1154 psi->pRealParmInfo[i].u.index=-1;
1155 psi->pRealParmInfo[i].bByVal=1;
1156 psi->pRealParmInfo[i].bArray=0;
1157 psi->pRealParmInfo[i].SubScripts[0]=-1;
1158
1159 psi->RealParmNum++;
1160 }
1161
1162 if(psi->ReturnType==DEF_OBJECT && psi->isReturnRef == false){
1163 i = psi->RealParmNum;
1164
1165 //実体オブジェクトを戻り値として持つ場合
1166 //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする
1167
1168 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR)
1169 psi->pRealParmInfo[i].name="_System_ReturnValue";
1170 else psi->pRealParmInfo[i].name=psi->name;
1171 psi->pRealParmInfo[i].type=DEF_OBJECT;
1172 psi->pRealParmInfo[i].u.index=psi->u.ReturnIndex;
1173 psi->pRealParmInfo[i].bByVal=0;
1174 psi->pRealParmInfo[i].bArray=0;
1175 psi->pRealParmInfo[i].SubScripts[0]=-1;
1176
1177 psi->RealParmNum++;
1178 }
1179
1180 //パラメータをコピー
1181 for( i = 0; i < psi->ParmNum; i++, psi->RealParmNum++ ){
1182 psi->pRealParmInfo[psi->RealParmNum]=psi->pParmInfo[i];
1183 }
1184
1185
1186 /////////////////////////////////
1187 // ハッシュデータに追加
1188 /////////////////////////////////
1189
1190 int key;
1191 key=hash_default(psi->name);
1192
1193 extern SUBINFO **ppSubHash;
1194 if(ppSubHash[key]){
1195 SUBINFO *psi2;
1196 psi2=ppSubHash[key];
1197 while(1){
1198 if(pobj_c==psi2->pobj_ParentClass){
1199 //重複エラーチェックを行う
1200 if(lstrcmp(psi2->name,psi->name)==0){
1201 if(CompareParameter(psi2->pParmInfo,psi2->ParmNum,psi->pParmInfo,psi->ParmNum)==0){
1202 SetError(15,psi->name,NowLine);
1203 return 0;
1204 }
1205 }
1206 }
1207
1208 if(psi2->pNextData==0) break;
1209 psi2=psi2->pNextData;
1210 }
1211 psi2->pNextData=psi;
1212 }
1213 else{
1214 ppSubHash[key]=psi;
1215 }
1216
1217 return psi;
1218}
1219
1220void GetSubInfo(void){ //サブルーチン情報を取得
1221 extern HANDLE hHeap;
1222 extern char *basbuf;
1223 int i,i2,i3;
1224 char temporary[8192];
1225
1226 //Declare(DLL関数)情報を初期化
1227 extern DECLAREINFO **ppDeclareHash;
1228 ppDeclareHash=(DECLAREINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DECLAREINFO *));
1229
1230 //サブルーチン(ユーザー定義)情報を初期化
1231 extern SUBINFO **ppSubHash;
1232 extern int SubNum;
1233 ppSubHash=(SUBINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SUBINFO *));
1234 SubNum=0;
1235
1236 //マクロ関数の名前リストを初期化
1237 extern char **ppMacroNames;
1238 extern int MacroNum;
1239 ppMacroNames=(char **)HeapAlloc(hHeap,0,1);
1240 MacroNum=0;
1241
1242 i=-1;
1243 while(1){
1244 i++;
1245
1246 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_INTERFACE)){
1247 /* Class ~ End Class
1248 Interface ~ End Interface
1249 を飛び越す */
1250 i3=GetEndXXXCommand(basbuf[i+1]);
1251 for(i+=2,i2=0;;i++,i2++){
1252 if(basbuf[i]=='\0') break;
1253 if(basbuf[i]==1&&basbuf[i+1]==(char)i3){
1254 i++;
1255 break;
1256 }
1257 }
1258 if(basbuf[i]=='\0') break;
1259 continue;
1260 }
1261
1262 if(basbuf[i]==1&&basbuf[i+1]==ESC_DECLARE){
1263 for(i+=2,i2=0;;i2++,i++){
1264 if(basbuf[i]=='\n'){
1265 temporary[i2]=0;
1266 break;
1267 }
1268 temporary[i2]=basbuf[i];
1269 if(basbuf[i]=='\0') break;
1270 }
1271 AddDeclareData(temporary,i);
1272
1273 continue;
1274 }
1275 if(basbuf[i]==1&&(basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION||basbuf[i+1]==ESC_MACRO)){
1276 for(i2=0;;i2++,i++){
1277 if(IsCommandDelimitation(basbuf[i])){
1278 temporary[i2]=0;
1279 break;
1280 }
1281 temporary[i2]=basbuf[i];
1282 if(basbuf[i]=='\0') break;
1283 }
1284 AddSubData(temporary,i,0,0);
1285
1286 continue;
1287 }
1288
1289 //次の行
1290 for(;;i++){
1291 if(IsCommandDelimitation(basbuf[i])) break;
1292 }
1293 if(basbuf[i]=='\0') break;
1294 }
1295
1296 ////////////
1297 // 特殊関数
1298 ////////////
1299
1300 sprintf(temporary,"%c%c_allrem()",1,ESC_SUB);
1301 AddSubData(temporary,0,0,0);
1302
1303 sprintf(temporary,"%c%c_aullrem()",1,ESC_SUB);
1304 AddSubData(temporary,0,0,0);
1305
1306 sprintf(temporary,"%c%c_allmul()",1,ESC_SUB);
1307 AddSubData(temporary,0,0,0);
1308
1309 sprintf(temporary,"%c%c_alldiv()",1,ESC_SUB);
1310 AddSubData(temporary,0,0,0);
1311
1312 sprintf(temporary,"%c%c_aulldiv()",1,ESC_SUB);
1313 AddSubData(temporary,0,0,0);
1314
1315 sprintf(temporary,"%c%c_allshl()",1,ESC_SUB);
1316 AddSubData(temporary,0,0,0);
1317
1318 sprintf(temporary,"%c%c_allshr()",1,ESC_SUB);
1319 AddSubData(temporary,0,0,0);
1320
1321 sprintf(temporary,"%c%c_aullshr()",1,ESC_SUB);
1322 AddSubData(temporary,0,0,0);
1323
1324 sprintf(temporary,"%c%c_System_InitStaticLocalVariables()",1,ESC_SUB);
1325 AddSubData(temporary,0,0,0);
1326}
1327void Delete_si(SUBINFO *psi){
1328 int i2;
1329
1330 for(i2=0;i2<psi->ParmNum;i2++){
1331 HeapDefaultFree(psi->pParmInfo[i2].name);
1332 }
1333 HeapDefaultFree(psi->pRealParmInfo);
1334 if(psi->pParmInfo) HeapDefaultFree(psi->pParmInfo);
1335 psi->pRealParmInfo=0;
1336 psi->pParmInfo=0;
1337
1338 if(psi->pNextData) Delete_si(psi->pNextData);
1339
1340 HeapDefaultFree(psi->name);
1341 HeapDefaultFree(psi);
1342}
1343void DeleteSubInfo(SUBINFO **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放
1344 int i;
1345 for(i=0;i<MAX_HASH;i++){
1346 if(!ppSubHash[i]) continue;
1347
1348 Delete_si(ppSubHash[i]);
1349 }
1350 HeapDefaultFree(ppSubHash);
1351
1352 //マクロの名前リスト
1353 if(ppMacroNames){
1354 for(i=0;i<MacroNum;i++){
1355 HeapDefaultFree(ppMacroNames[i]);
1356 }
1357 HeapDefaultFree(ppMacroNames);
1358 }
1359}
1360void Delete_di(DECLAREINFO *pdi){
1361 if(pdi->pParmInfo) HeapDefaultFree(pdi->pParmInfo);
1362
1363 HeapDefaultFree(pdi->name);
1364 if(pdi->file) HeapDefaultFree(pdi->file);
1365 if(pdi->alias) HeapDefaultFree(pdi->alias);
1366
1367 if(pdi->pNextData) Delete_di(pdi->pNextData);
1368
1369 HeapDefaultFree(pdi);
1370}
1371void DeleteDeclareInfo(void){
1372 //DLL情報を解放
1373 extern DECLAREINFO **ppDeclareHash;
1374 int i;
1375 for(i=0;i<MAX_HASH;i++){
1376 if(!ppDeclareHash[i]) continue;
1377
1378 Delete_di(ppDeclareHash[i]);
1379 }
1380 HeapDefaultFree(ppDeclareHash);
1381}
1382
1383
1384
1385///////////////////////
1386// 関数ポインタの管理
1387///////////////////////
1388
1389int AddProcPtrInfo(char *buffer,DWORD dwProcType){
1390 extern HANDLE hHeap;
1391 extern int cp;
1392 extern PROCPTRINFO *pProcPtrInfo;
1393 extern int ProcPtrInfoNum;
1394 int i,i2,i3,sw;
1395 PROCPTRINFO *pi;
1396 char temporary[VN_SIZE],temp2[VN_SIZE];
1397
1398 pProcPtrInfo=(PROCPTRINFO *)HeapReAlloc(hHeap,0,pProcPtrInfo,(ProcPtrInfoNum+1)*sizeof(PROCPTRINFO));
1399 pi=&pProcPtrInfo[ProcPtrInfoNum];
1400 ProcPtrInfoNum++;
1401
1402 pi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
1403 pi->ParmNum=0;
1404
1405 //buffer[0]は'('となっている
1406 i=1;
1407
1408 while(1){
1409 if(buffer[i]==')') break;
1410
1411 pi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pi->pParmInfo,(pi->ParmNum+1)*sizeof(PARAMETER_INFO));
1412
1413 //ByVal
1414 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
1415 pi->pParmInfo[pi->ParmNum].bByVal=1;
1416 i+=2;
1417 }
1418 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
1419 pi->pParmInfo[pi->ParmNum].bByVal=0;
1420 i+=2;
1421 }
1422 else pi->pParmInfo[pi->ParmNum].bByVal=1;
1423
1424 //パラメータ名
1425 sw=0;
1426 for(i2=0;;i++,i2++){
1427 if(buffer[i]=='('){
1428 if(!sw) sw=1;
1429
1430 i3=GetStringInPare(temporary+i2,buffer+i);
1431 i2+=i3-1;
1432 i+=i3-1;
1433 continue;
1434 }
1435 if(buffer[i]=='['){
1436 if(!sw) sw=1;
1437
1438 i3=GetStringInBracket(temporary+i2,buffer+i);
1439 i2+=i3-1;
1440 i+=i3-1;
1441 continue;
1442 }
1443 if(!IsVariableChar(buffer[i])){
1444 temporary[i2]=0;
1445 break;
1446 }
1447 temporary[i2]=buffer[i];
1448 }
1449 pi->pParmInfo[pi->ParmNum].name=0;
1450
1451 if(sw){
1452 //配列パラメータ
1453 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(29,NULL,cp);
1454 pi->pParmInfo[pi->ParmNum].bArray=1;
1455
1456 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
1457 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
1458 pi->pParmInfo[pi->ParmNum].SubScripts[0]=LONG_MAX;
1459 pi->pParmInfo[pi->ParmNum].SubScripts[1]=-1;
1460
1461 temporary[i2-2]=0;
1462 }
1463 else{
1464 GetArrange(temporary,temp2,pi->pParmInfo[pi->ParmNum].SubScripts);
1465 lstrcpy(temporary,temp2);
1466 }
1467
1468 i2=lstrlen(temporary);
1469 }
1470 else{
1471 pi->pParmInfo[pi->ParmNum].bArray=0;
1472 pi->pParmInfo[pi->ParmNum].SubScripts[0]=-1;
1473 }
1474
1475 //型
1476 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1477 i+=2;
1478
1479 i2=0;
1480 while(buffer[i]=='*'){
1481 temporary[i2]=buffer[i];
1482 i++;
1483 i2++;
1484 }
1485 for(;;i++,i2++){
1486 if(!IsVariableChar(buffer[i])){
1487 temporary[i2]=0;
1488 break;
1489 }
1490 temporary[i2]=buffer[i];
1491 }
1492
1493 pi->pParmInfo[pi->ParmNum].type=
1494 GetTypeFixed(temporary,&pi->pParmInfo[pi->ParmNum].u.index);
1495 if(pi->pParmInfo[pi->ParmNum].type==-1){
1496 SetError(3,temporary,cp);
1497 pi->pParmInfo[pi->ParmNum].type=DEF_PTR_VOID;
1498 }
1499 if(pi->pParmInfo[pi->ParmNum].type==DEF_OBJECT){
1500 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(28,temporary,cp);
1501 }
1502 }
1503 else{
1504 pi->pParmInfo[pi->ParmNum].type=GetTypeFromSimpleName(temporary);
1505 SetError(-103,temporary,cp);
1506 }
1507
1508 pi->ParmNum++;
1509
1510 if(buffer[i]==','){
1511 i++;
1512 continue;
1513 }
1514 else if(buffer[i]==')') continue;
1515 else{
1516 SetError(1,NULL,cp);
1517 return 0;
1518 }
1519 }
1520 i++;
1521
1522 //戻り値
1523 if(dwProcType==ESC_FUNCTION){
1524 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1525 i+=2;
1526 i2=0;
1527 if(buffer[i]=='*') temporary[i2++]=buffer[i++];
1528 for(;;i++,i2++){
1529 if(!IsVariableChar(buffer[i])){
1530 temporary[i2]=0;
1531 break;
1532 }
1533 temporary[i2]=buffer[i];
1534 }
1535 pi->ReturnType=GetTypeFixed(temporary,&pi->u.ReturnIndex);
1536 if(pi->ReturnType==-1) SetError(3,temporary,cp);
1537 if(pi->ReturnType==DEF_OBJECT) SetError(40,NULL,cp);
1538 }
1539 else pi->ReturnType=DEF_DOUBLE;
1540 }
1541 else pi->ReturnType=-1;
1542
1543 return ProcPtrInfoNum-1;
1544}
1545void DeleteProcPtrInfo(void){
1546 extern PROCPTRINFO *pProcPtrInfo;
1547 extern int ProcPtrInfoNum;
1548 int i;
1549
1550 for(i=0;i<ProcPtrInfoNum;i++){
1551 HeapDefaultFree(pProcPtrInfo[i].pParmInfo);
1552 }
1553
1554 HeapDefaultFree(pProcPtrInfo);
1555}
Note: See TracBrowser for help on using the repository browser.