source: dev/BasicCompiler_Common/Subroutine.cpp@ 65

Last change on this file since 65 was 64, checked in by dai_9181, 18 years ago

すべてのオブジェクトを参照型に切り替えた。

File size: 34.2 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 i = GetOneParameter( buffer, i, temporary );
458 int type;
459 LONG_PTR lpIndex;
460 _int64 i64data;
461 type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex );
462 if( type != DEF_PTR_CHAR ){
463 SetError(1,NULL,NowLine);
464 return;
465 }
466 lstrcpy( temporary, (char *)i64data );
467 CharUpper(temporary);
468 if(!strstr(temporary,".")){
469 if(pdi->dwType==DECLARE_STATIC) lstrcat(temporary,".LIB");
470 else{
471 lstrcat(temporary,".DLL");
472 if(lstrlen(temporary)>=16){
473 SetError(7,NULL,NowLine);
474 return;
475 }
476 }
477 }
478 pdi->file=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
479 lstrcpy(pdi->file,temporary);
480
481 //エイリアス
482 i = GetOneParameter( buffer, i, temporary );
483 if( temporary[0] ){
484 type = StaticCalculation( true, temporary, 0, &i64data, &lpIndex );
485 if( type != DEF_PTR_CHAR ){
486 SetError(1,NULL,NowLine);
487 return;
488 }
489 lstrcpy( temporary, (char *)i64data );
490
491 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
492 lstrcpy(pdi->alias,temporary);
493 }
494 else{
495 //省略されたときは関数名
496 pdi->alias=(char *)HeapAlloc(hHeap,0,lstrlen(pdi->name)+1);
497 lstrcpy(pdi->alias,pdi->name);
498 }
499
500 //パラメータの始めのカッコ
501 if(buffer[i]!='('){
502 SetError(1,NULL,NowLine);
503 return;
504 }
505 i++;
506
507 pdi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
508
509 //各パラメータ
510 for(i3=0;;i3++){
511 if(buffer[i]==')') break;
512
513 pdi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pdi->pParmInfo,(i3+1)*sizeof(PARAMETER_INFO));
514
515 //ByVal
516 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
517 pdi->pParmInfo[i3].bByVal=1;
518 i+=2;
519 }
520 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
521 pdi->pParmInfo[i3].bByVal=0;
522 i+=2;
523 }
524 else pdi->pParmInfo[i3].bByVal=1;
525
526 //変数名は無視(temporaryの変数名は型宣言文字判断のため)
527 sw=0;
528 for(i2=0;;i++,i2++){
529 if(buffer[i]=='('){
530 if(!sw) sw=1;
531
532 i4=GetStringInPare(temporary+i2,buffer+i);
533 i2+=i4-1;
534 i+=i4-1;
535 continue;
536 }
537 if(buffer[i]=='['){
538 if(!sw) sw=1;
539
540 i4=GetStringInBracket(temporary+i2,buffer+i);
541 i2+=i4-1;
542 i+=i4-1;
543 continue;
544 }
545 if(!IsVariableChar(buffer[i])){
546 temporary[i2]=0;
547 break;
548 }
549 temporary[i2]=buffer[i];
550 }
551 if(lstrcmp(temporary,"...")==0) pdi->pParmInfo[i3].type=DEF_ELLIPSE;
552 else{
553 //型
554 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
555 i+=2;
556 for(i2=0;;i++,i2++){
557 if(!(IsVariableChar(buffer[i])||buffer[i]=='*')){
558 temporary[i2]=0;
559 break;
560 }
561 temporary[i2]=buffer[i];
562 }
563 pdi->pParmInfo[i3].type=GetTypeFixed(temporary,&pdi->pParmInfo[i3].u.index);
564 }
565 else{
566 pdi->pParmInfo[i3].type=GetTypeFromSimpleName(temporary);
567 SetError(-103,temporary,NowLine);
568 }
569
570 if(sw){
571 //配列ポインタを引き渡すとき
572 pdi->pParmInfo[i3].type=GetPtrType(pdi->pParmInfo[i3].type,pdi->pParmInfo[i3].u.index);
573 }
574 }
575
576 //名前はダミー(使用しないため)
577 pdi->pParmInfo[i3].name="";
578
579 //構造体の場合はエラーチェック
580 if(pdi->pParmInfo[i3].type==-1) SetError(3,temporary,NowLine);
581 if(pdi->pParmInfo[i3].type==DEF_OBJECT){
582 if(pdi->pParmInfo[i3].bByVal) pdi->pParmInfo[i3].type=DEF_LONG;//SetError(28,temporary,NowLine);
583 }
584
585 //構造体アドレスの空白部
586 while(buffer[i]==' ') i++;
587
588 if(buffer[i]==','){
589 i++;
590 continue;
591 }
592 else if(buffer[i]==')') continue;
593 else{
594 SetError(1,NULL,NowLine);
595 break;
596 }
597 }
598 pdi->ParmNum=i3;
599
600 //戻り値
601 i++;
602 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
603 if(IsFunction==0) SetError(1,NULL,NowLine);
604 i+=2;
605 pdi->ReturnType=GetTypeFixed(buffer+i,&pdi->u.ReturnIndex);
606 if(pdi->ReturnType==DEF_NON) SetError(3,buffer+i,NowLine);
607 if(pdi->ReturnType==DEF_OBJECT) SetError(40,NULL,NowLine);
608 }
609 else if(buffer[i]) SetError(1,NULL,NowLine);
610 else pdi->ReturnType=DEF_NON;
611
612 pdi->pos=NowLine;
613}
614
615BOOL CompareParameter(PARAMETER_INFO *ppi1,int pi_num1,PARAMETER_INFO *ppi2,int pi_num2){
616 if(pi_num1!=pi_num2) return 1;
617
618 int i;
619 for(i=0;i<pi_num1;i++){
620 if(ppi1[i].type!=ppi2[i].type){
621
622 if(ppi1[i].bByVal==0&&ppi1[i].type==DEF_ANY&&
623 ppi2[i].bByVal==1&&IsPtrType(ppi2[i].type)||
624 ppi1[i].bByVal==1&&IsPtrType(ppi1[i].type)&&
625 ppi2[i].bByVal==0&&ppi2[i].type==DEF_ANY){
626 /* ByRef var As Any
627
628 var As VoidPtr
629 は同等
630 */
631 continue;
632 }
633
634 return 1;
635 }
636 else{
637 if(NATURAL_TYPE(ppi1[i].type)==DEF_OBJECT
638 || NATURAL_TYPE(ppi1[i].type)==DEF_STRUCT ){
639 if(ppi1[i].u.index!=ppi2[i].u.index) return 1;
640 }
641 }
642 }
643
644 return 0;
645}
646SUBINFO *AddSubData(char *buffer,int NowLine,BOOL bVirtual,CClass *pobj_c,BOOL bStatic){
647 int i,i2,i3,sw;
648 DWORD dwType;
649 char temporary[8192],temp2[VN_SIZE];
650
651 i=1;
652 if(buffer[i]==ESC_SUB) dwType=SUBTYPE_SUB;
653 else if(buffer[i]==ESC_FUNCTION) dwType=SUBTYPE_FUNCTION;
654 else if(buffer[i]==ESC_MACRO) dwType=SUBTYPE_MACRO;
655
656 i++;
657
658 BOOL bExport=0,bCdecl=0;
659 while(1){
660 if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&&bExport==0){
661 bExport=1;
662
663 i+=2;
664 }
665 else if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&&bCdecl==0){
666 bCdecl=1;
667
668 i+=2;
669 }
670 else break;
671 }
672
673 i2=0;
674 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
675 if(!pobj_c){
676 SetError(126,NULL,NowLine);
677 return 0;
678 }
679
680 //オペレータの場合
681 temporary[i2++]=buffer[i++];
682 temporary[i2++]=buffer[i++];
683
684 int iCalcId;
685 if(buffer[i]=='='&&buffer[i+1]=='='){
686 iCalcId=CALC_EQUAL;
687 i3=2;
688 }
689 else if(buffer[i]=='='){
690 iCalcId=CALC_SUBSITUATION;
691 i3=1;
692 }
693 else if(buffer[i]=='('){
694 iCalcId=CALC_AS;
695 i3=0;
696 }
697 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){
698 iCalcId=CALC_ARRAY_SET;
699 i3=3;
700 }
701 else if(buffer[i]=='['&&buffer[i+1]==']'){
702 iCalcId=CALC_ARRAY_GET;
703 i3=2;
704 }
705 else{
706 iCalcId=GetCalcId(buffer+i,&i3);
707 i3++;
708 }
709 if(!iCalcId){
710 SetError(1,NULL,NowLine);
711 return 0;
712 }
713 temporary[i2++]=iCalcId;
714 temporary[i2]=0;
715
716 i+=i3;
717 }
718 else{
719 if(pobj_c){
720 //クラスメンバの場合、デストラクタには~が付くことを考慮
721 if(buffer[i]=='~'){
722 temporary[i2]='~';
723 i++;
724 i2++;
725 }
726 }
727
728 for(;;i++,i2++){
729 if(!IsVariableChar(buffer[i])){
730 temporary[i2]=0;
731 break;
732 }
733 temporary[i2]=buffer[i];
734 }
735 }
736
737 if(dwType==SUBTYPE_MACRO){
738 //大文字に変換
739 CharUpper(temporary);
740
741 //マクロ関数の場合は名前リストに追加
742 extern char **ppMacroNames;
743 extern int MacroNum;
744 ppMacroNames=(char **)HeapReAlloc(hHeap,0,ppMacroNames,(MacroNum+1)*sizeof(char *));
745 ppMacroNames[MacroNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
746 lstrcpy(ppMacroNames[MacroNum],temporary);
747 MacroNum++;
748 }
749
750 if(!pobj_c){
751 //クラスメンバ以外の場合のみ
752 //重複チェック
753
754 if(GetDeclareHash(temporary)){
755 SetError(15,temporary,NowLine);
756 return 0;
757 }
758 }
759
760 extern int SubNum;
761 SubNum++;
762
763 SUBINFO *psi;
764 psi=(SUBINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(SUBINFO));
765
766 //クラス名
767 psi->pobj_ParentClass=pobj_c;
768
769 //ID
770 static int id_base=0;
771 psi->id=(id_base++);
772
773 //関数名
774 psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
775 lstrcpy(psi->name,temporary);
776
777 //ソースコードの位置
778 psi->address=NowLine;
779
780 psi->bExport=bExport;
781 psi->bCdecl=bCdecl;
782 psi->bVirtual=bVirtual;
783 if(bExport) psi->bUse=1;
784 else psi->bUse=0;
785 psi->bCompile=0;
786 psi->bSystem=0;
787
788 psi->dwType=dwType;
789
790
791 if(psi->dwType==SUBTYPE_FUNCTION){
792 ///////////////////
793 // 戻り値を取得
794 ///////////////////
795
796 psi->isReturnRef = false;
797
798 if(pobj_c){
799 if(lstrcmp(psi->name,pobj_c->name)==0||
800 psi->name[0]=='~'){
801 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
802 SetError(115,NULL,NowLine);
803 }
804 }
805
806
807 i2=lstrlen(buffer)-2;
808
809 int sw_as=0;
810 for(;i2>0;i2--){
811 if(buffer[i2]==')') break;
812
813 if(buffer[i2]==1&&buffer[i2+1]==ESC_AS){
814 if( buffer[i2-2] == 1 && buffer[i2-1] == ESC_BYREF ){
815 //参照型
816 psi->isReturnRef = true;
817 }
818
819 i2+=2;
820 i3=0;
821 while(buffer[i2]=='*') temporary[i3++]=buffer[i2++];
822 for(;;i2++,i3++){
823 if(!IsVariableChar(buffer[i2])){
824 temporary[i3]=0;
825 break;
826 }
827 temporary[i3]=buffer[i2];
828 }
829 psi->ReturnType=GetTypeFixed(temporary,&psi->u.ReturnIndex);
830 if(psi->ReturnType==DEF_NON) SetError(3,temporary,NowLine);
831
832 sw_as=1;
833 break;
834 }
835 }
836
837 if(!sw_as){
838 SetError(-104,psi->name,NowLine);
839
840 psi->ReturnType=DEF_DOUBLE;
841 }
842 }
843 else{
844 //戻り値なしのSub定義
845 psi->ReturnType=DEF_NON;
846 psi->u.ReturnIndex=-1;
847 }
848
849
850
851 psi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(PARAMETER_INFO)*2);
852 psi->ParmNum=0;
853
854 //パラメータ
855 if(buffer[i]!='('){
856 SetError(1,NULL,NowLine);
857 return 0;
858 }
859 i++;
860 if(buffer[i]!=')'&&pobj_c){
861 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
862 if(psi->name[0]=='~'){
863 SetError(114,NULL,NowLine);
864 i=JumpStringInPare(buffer,i);
865 }
866 }
867 while(1){
868 if(buffer[i]==')') break;
869
870 psi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,psi->pParmInfo,(psi->ParmNum+1)*sizeof(PARAMETER_INFO));
871
872 //ByVal
873 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
874 psi->pParmInfo[psi->ParmNum].bByVal=1;
875 i+=2;
876 }
877 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
878 psi->pParmInfo[psi->ParmNum].bByVal=0;
879 i+=2;
880 }
881 else psi->pParmInfo[psi->ParmNum].bByVal=1;
882
883 //パラメータ名
884 sw=0;
885 for(i2=0;;i++,i2++){
886 if(buffer[i]=='('){
887 if(!sw) sw=1;
888
889 i3=GetStringInPare(temporary+i2,buffer+i);
890 i2+=i3-1;
891 i+=i3-1;
892 continue;
893 }
894 if(buffer[i]=='['){
895 if(!sw) sw=1;
896
897 i3=GetStringInBracket(temporary+i2,buffer+i);
898 i2+=i3-1;
899 i+=i3-1;
900 continue;
901 }
902 if(!IsVariableChar(buffer[i])){
903 temporary[i2]=0;
904 break;
905 }
906 temporary[i2]=buffer[i];
907 }
908 if(sw){
909 //配列パラメータ
910 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(29,NULL,NowLine);
911 psi->pParmInfo[psi->ParmNum].bArray=1;
912
913 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
914 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
915 psi->pParmInfo[psi->ParmNum].SubScripts[0]=LONG_MAX;
916 psi->pParmInfo[psi->ParmNum].SubScripts[1]=-1;
917
918 temporary[i2-2]=0;
919 }
920 else{
921 GetArrange(temporary,temp2,psi->pParmInfo[psi->ParmNum].SubScripts);
922 lstrcpy(temporary,temp2);
923 }
924
925 i2=lstrlen(temporary);
926 }
927 else{
928 psi->pParmInfo[psi->ParmNum].bArray=0;
929 psi->pParmInfo[psi->ParmNum].SubScripts[0]=-1;
930 }
931 psi->pParmInfo[psi->ParmNum].name=(char *)HeapAlloc(hHeap,0,i2+1);
932 lstrcpy(psi->pParmInfo[psi->ParmNum].name,temporary);
933
934 //型
935 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
936 i+=2;
937
938 i2=0;
939 while(buffer[i]=='*'){
940 temporary[i2]=buffer[i];
941 i++;
942 i2++;
943 }
944 for(;;i++,i2++){
945 if(!IsVariableChar(buffer[i])){
946 if(buffer[i]==1&&(buffer[i+1]==ESC_FUNCTION||buffer[i+1]==ESC_SUB)){
947 temporary[i2++]=buffer[i++];
948 temporary[i2]=buffer[i];
949 continue;
950 }
951 temporary[i2]=0;
952 break;
953 }
954 temporary[i2]=buffer[i];
955 }
956
957 psi->pParmInfo[psi->ParmNum].type=
958 GetTypeFixed(temporary,&psi->pParmInfo[psi->ParmNum].u.index);
959
960 if(temporary[0]=='*'&&
961 temporary[1]==1&&
962 (temporary[2]==ESC_FUNCTION||temporary[2]==ESC_SUB)){
963 if(buffer[i]!='('){
964 SetError(10,temporary,NowLine);
965 return 0;
966 }
967 i3=GetStringInPare(temporary+i2,buffer+i);
968 i+=i3;
969 i2+=i3;
970
971 if(temporary[2]==ESC_FUNCTION&&buffer[i]==1&&buffer[i+1]==ESC_AS){
972 temporary[i2++]=buffer[i++];
973 temporary[i2++]=buffer[i++];
974 for(;;i++,i2++){
975 if(!IsVariableChar(buffer[i])){
976 temporary[i2]=0;
977 break;
978 }
979 temporary[i2]=buffer[i];
980 }
981 }
982 }
983 else{
984 //TypeDefをする前のベース型を取得
985 GetOriginalTypeName(temporary);
986 }
987
988 if(psi->pParmInfo[psi->ParmNum].type==-1){
989 SetError(3,temporary,NowLine);
990 psi->pParmInfo[psi->ParmNum].type=DEF_PTR_VOID;
991 }
992
993 /*未完成(構造体パラメータを値参照として渡してよいものか!?)
994 if(psi->pParmInfo[psi->ParmNum].type==DEF_OBJECT){
995 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(28,temporary,NowLine);
996 }*/
997 }
998 else{
999 psi->pParmInfo[psi->ParmNum].type=GetTypeFromSimpleName(temporary);
1000 SetError(-103,temporary,NowLine);
1001 }
1002
1003 if(psi->pParmInfo[psi->ParmNum].type==DEF_PTR_PROC){
1004 //関数ポインタの場合
1005 psi->pParmInfo[psi->ParmNum].u.index=AddProcPtrInfo(temporary+3,temporary[2]);
1006 }
1007
1008 //パラメータの数を更新
1009 psi->ParmNum++;
1010
1011 if(buffer[i]==','){
1012 i++;
1013 continue;
1014 }
1015 else if(buffer[i]==')') continue;
1016 else{
1017 SetError(1,NULL,NowLine);
1018 return 0;
1019 }
1020 }
1021 psi->SecondParmNum=psi->ParmNum;
1022 i++;
1023 if(buffer[i]=='('){
1024 i++;
1025 while(1){
1026 if(buffer[i]==')') break;
1027
1028 psi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,psi->pParmInfo,(psi->ParmNum+1)*sizeof(PARAMETER_INFO));
1029
1030 //ByVal
1031 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
1032 psi->pParmInfo[psi->ParmNum].bByVal=1;
1033 i+=2;
1034 }
1035 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
1036 psi->pParmInfo[psi->ParmNum].bByVal=0;
1037 i+=2;
1038 }
1039 else psi->pParmInfo[psi->ParmNum].bByVal=1;
1040
1041 //パラメータ名
1042 sw=0;
1043 for(i2=0;;i++,i2++){
1044 if(buffer[i]=='('){
1045 if(!sw) sw=1;
1046
1047 i3=GetStringInPare(temporary+i2,buffer+i);
1048 i2+=i3-1;
1049 i+=i3-1;
1050 continue;
1051 }
1052 if(buffer[i]=='['){
1053 if(!sw) sw=1;
1054
1055 i3=GetStringInBracket(temporary+i2,buffer+i);
1056 i2+=i3-1;
1057 i+=i3-1;
1058 continue;
1059 }
1060 if(!IsVariableChar(buffer[i])){
1061 temporary[i2]=0;
1062 break;
1063 }
1064 temporary[i2]=buffer[i];
1065 }
1066 if(sw){
1067 //配列パラメータ
1068 if(psi->pParmInfo[psi->ParmNum].bByVal) SetError(29,NULL,NowLine);
1069 psi->pParmInfo[psi->ParmNum].bArray=1;
1070
1071 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
1072 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
1073 psi->pParmInfo[psi->ParmNum].SubScripts[0]=LONG_MAX;
1074 psi->pParmInfo[psi->ParmNum].SubScripts[1]=-1;
1075
1076 temporary[i2-2]=0;
1077 }
1078 else{
1079 GetArrange(temporary,temp2,psi->pParmInfo[psi->ParmNum].SubScripts);
1080 lstrcpy(temporary,temp2);
1081 }
1082
1083 i2=lstrlen(temporary);
1084 }
1085 else{
1086 psi->pParmInfo[psi->ParmNum].bArray=0;
1087 psi->pParmInfo[psi->ParmNum].SubScripts[0]=-1;
1088 }
1089 psi->pParmInfo[psi->ParmNum].name=(char *)HeapAlloc(hHeap,0,i2+1);
1090 lstrcpy(psi->pParmInfo[psi->ParmNum].name,temporary);
1091
1092 //型
1093 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1094 i+=2;
1095 i2=0;
1096 while(buffer[i]=='*'){
1097 temporary[i2]=buffer[i];
1098 i++;
1099 i2++;
1100 }
1101 for(;;i++,i2++){
1102 if(!IsVariableChar(buffer[i])){
1103 temporary[i2]=0;
1104 break;
1105 }
1106 temporary[i2]=buffer[i];
1107 }
1108 psi->pParmInfo[psi->ParmNum].type=
1109 GetTypeFixed(temporary,&psi->pParmInfo[psi->ParmNum].u.index);
1110 if(psi->pParmInfo[psi->ParmNum].type==-1) SetError(3,temporary,NowLine);
1111 }
1112 else{
1113 psi->pParmInfo[psi->ParmNum].type=GetTypeFromSimpleName(temporary);
1114 SetError(-103,temporary,NowLine);
1115 }
1116
1117 psi->ParmNum++;
1118
1119 if(buffer[i]==','){
1120 i++;
1121 continue;
1122 }
1123 else if(buffer[i]==')') continue;
1124 else{
1125 SetError(1,NULL,NowLine);
1126 return 0;
1127 }
1128 }
1129 i++;
1130 }
1131
1132 //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する)
1133 psi->pRealParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,(psi->ParmNum+2)*sizeof(PARAMETER_INFO));
1134 psi->RealParmNum=0;
1135
1136 if(pobj_c&&bStatic==0){
1137 i = psi->RealParmNum;
1138
1139 //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用
1140 psi->pRealParmInfo[i].name = "_System_LocalThis";
1141 psi->pRealParmInfo[i].type=DEF_PTR_VOID;
1142 psi->pRealParmInfo[i].u.index=-1;
1143 psi->pRealParmInfo[i].bByVal=1;
1144 psi->pRealParmInfo[i].bArray=0;
1145 psi->pRealParmInfo[i].SubScripts[0]=-1;
1146
1147 psi->RealParmNum++;
1148 }
1149
1150 if(psi->ReturnType==DEF_STRUCT){
1151 i = psi->RealParmNum;
1152
1153 //構造体を戻り値として持つ場合
1154 //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする
1155
1156 if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR)
1157 psi->pRealParmInfo[i].name="_System_ReturnValue";
1158 else psi->pRealParmInfo[i].name=psi->name;
1159 psi->pRealParmInfo[i].type=DEF_STRUCT;
1160 psi->pRealParmInfo[i].u.index=psi->u.ReturnIndex;
1161 psi->pRealParmInfo[i].bByVal=0;
1162 psi->pRealParmInfo[i].bArray=0;
1163 psi->pRealParmInfo[i].SubScripts[0]=-1;
1164
1165 psi->RealParmNum++;
1166 }
1167
1168 //パラメータをコピー
1169 for( i = 0; i < psi->ParmNum; i++, psi->RealParmNum++ ){
1170 psi->pRealParmInfo[psi->RealParmNum]=psi->pParmInfo[i];
1171 }
1172
1173
1174 /////////////////////////////////
1175 // ハッシュデータに追加
1176 /////////////////////////////////
1177
1178 int key;
1179 key=hash_default(psi->name);
1180
1181 extern SUBINFO **ppSubHash;
1182 if(ppSubHash[key]){
1183 SUBINFO *psi2;
1184 psi2=ppSubHash[key];
1185 while(1){
1186 if(pobj_c==psi2->pobj_ParentClass){
1187 //重複エラーチェックを行う
1188 if(lstrcmp(psi2->name,psi->name)==0){
1189 if(CompareParameter(psi2->pParmInfo,psi2->ParmNum,psi->pParmInfo,psi->ParmNum)==0){
1190 SetError(15,psi->name,NowLine);
1191 return 0;
1192 }
1193 }
1194 }
1195
1196 if(psi2->pNextData==0) break;
1197 psi2=psi2->pNextData;
1198 }
1199 psi2->pNextData=psi;
1200 }
1201 else{
1202 ppSubHash[key]=psi;
1203 }
1204
1205 return psi;
1206}
1207
1208void GetSubInfo(void){ //サブルーチン情報を取得
1209 extern HANDLE hHeap;
1210 extern char *basbuf;
1211 int i,i2,i3;
1212 char temporary[8192];
1213
1214 //Declare(DLL関数)情報を初期化
1215 extern DECLAREINFO **ppDeclareHash;
1216 ppDeclareHash=(DECLAREINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DECLAREINFO *));
1217
1218 //サブルーチン(ユーザー定義)情報を初期化
1219 extern SUBINFO **ppSubHash;
1220 extern int SubNum;
1221 ppSubHash=(SUBINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SUBINFO *));
1222 SubNum=0;
1223
1224 //マクロ関数の名前リストを初期化
1225 extern char **ppMacroNames;
1226 extern int MacroNum;
1227 ppMacroNames=(char **)HeapAlloc(hHeap,0,1);
1228 MacroNum=0;
1229
1230 i=-1;
1231 while(1){
1232 i++;
1233
1234 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_INTERFACE)){
1235 /* Class ~ End Class
1236 Interface ~ End Interface
1237 を飛び越す */
1238 i3=GetEndXXXCommand(basbuf[i+1]);
1239 for(i+=2,i2=0;;i++,i2++){
1240 if(basbuf[i]=='\0') break;
1241 if(basbuf[i]==1&&basbuf[i+1]==(char)i3){
1242 i++;
1243 break;
1244 }
1245 }
1246 if(basbuf[i]=='\0') break;
1247 continue;
1248 }
1249
1250 if(basbuf[i]==1&&basbuf[i+1]==ESC_DECLARE){
1251 for(i+=2,i2=0;;i2++,i++){
1252 if(basbuf[i]=='\n'){
1253 temporary[i2]=0;
1254 break;
1255 }
1256 temporary[i2]=basbuf[i];
1257 if(basbuf[i]=='\0') break;
1258 }
1259 AddDeclareData(temporary,i);
1260
1261 continue;
1262 }
1263 if(basbuf[i]==1&&(basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION||basbuf[i+1]==ESC_MACRO)){
1264 for(i2=0;;i2++,i++){
1265 if(IsCommandDelimitation(basbuf[i])){
1266 temporary[i2]=0;
1267 break;
1268 }
1269 temporary[i2]=basbuf[i];
1270 if(basbuf[i]=='\0') break;
1271 }
1272 AddSubData(temporary,i,0,0);
1273
1274 continue;
1275 }
1276
1277 //次の行
1278 for(;;i++){
1279 if(IsCommandDelimitation(basbuf[i])) break;
1280 }
1281 if(basbuf[i]=='\0') break;
1282 }
1283
1284 ////////////
1285 // 特殊関数
1286 ////////////
1287
1288 sprintf(temporary,"%c%c_allrem()",1,ESC_SUB);
1289 AddSubData(temporary,0,0,0);
1290
1291 sprintf(temporary,"%c%c_aullrem()",1,ESC_SUB);
1292 AddSubData(temporary,0,0,0);
1293
1294 sprintf(temporary,"%c%c_allmul()",1,ESC_SUB);
1295 AddSubData(temporary,0,0,0);
1296
1297 sprintf(temporary,"%c%c_alldiv()",1,ESC_SUB);
1298 AddSubData(temporary,0,0,0);
1299
1300 sprintf(temporary,"%c%c_aulldiv()",1,ESC_SUB);
1301 AddSubData(temporary,0,0,0);
1302
1303 sprintf(temporary,"%c%c_allshl()",1,ESC_SUB);
1304 AddSubData(temporary,0,0,0);
1305
1306 sprintf(temporary,"%c%c_allshr()",1,ESC_SUB);
1307 AddSubData(temporary,0,0,0);
1308
1309 sprintf(temporary,"%c%c_aullshr()",1,ESC_SUB);
1310 AddSubData(temporary,0,0,0);
1311
1312 sprintf(temporary,"%c%c_System_InitStaticLocalVariables()",1,ESC_SUB);
1313 AddSubData(temporary,0,0,0);
1314}
1315void Delete_si(SUBINFO *psi){
1316 int i2;
1317
1318 for(i2=0;i2<psi->ParmNum;i2++){
1319 HeapDefaultFree(psi->pParmInfo[i2].name);
1320 }
1321 HeapDefaultFree(psi->pRealParmInfo);
1322 if(psi->pParmInfo) HeapDefaultFree(psi->pParmInfo);
1323 psi->pRealParmInfo=0;
1324 psi->pParmInfo=0;
1325
1326 if(psi->pNextData) Delete_si(psi->pNextData);
1327
1328 HeapDefaultFree(psi->name);
1329 HeapDefaultFree(psi);
1330}
1331void DeleteSubInfo(SUBINFO **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放
1332 int i;
1333 for(i=0;i<MAX_HASH;i++){
1334 if(!ppSubHash[i]) continue;
1335
1336 Delete_si(ppSubHash[i]);
1337 }
1338 HeapDefaultFree(ppSubHash);
1339
1340 //マクロの名前リスト
1341 if(ppMacroNames){
1342 for(i=0;i<MacroNum;i++){
1343 HeapDefaultFree(ppMacroNames[i]);
1344 }
1345 HeapDefaultFree(ppMacroNames);
1346 }
1347}
1348void Delete_di(DECLAREINFO *pdi){
1349 if(pdi->pParmInfo) HeapDefaultFree(pdi->pParmInfo);
1350
1351 HeapDefaultFree(pdi->name);
1352 if(pdi->file) HeapDefaultFree(pdi->file);
1353 if(pdi->alias) HeapDefaultFree(pdi->alias);
1354
1355 if(pdi->pNextData) Delete_di(pdi->pNextData);
1356
1357 HeapDefaultFree(pdi);
1358}
1359void DeleteDeclareInfo(void){
1360 //DLL情報を解放
1361 extern DECLAREINFO **ppDeclareHash;
1362 int i;
1363 for(i=0;i<MAX_HASH;i++){
1364 if(!ppDeclareHash[i]) continue;
1365
1366 Delete_di(ppDeclareHash[i]);
1367 }
1368 HeapDefaultFree(ppDeclareHash);
1369}
1370
1371
1372
1373///////////////////////
1374// 関数ポインタの管理
1375///////////////////////
1376
1377int AddProcPtrInfo(char *buffer,DWORD dwProcType){
1378 extern HANDLE hHeap;
1379 extern int cp;
1380 extern PROCPTRINFO *pProcPtrInfo;
1381 extern int ProcPtrInfoNum;
1382 int i,i2,i3,sw;
1383 PROCPTRINFO *pi;
1384 char temporary[VN_SIZE],temp2[VN_SIZE];
1385
1386 pProcPtrInfo=(PROCPTRINFO *)HeapReAlloc(hHeap,0,pProcPtrInfo,(ProcPtrInfoNum+1)*sizeof(PROCPTRINFO));
1387 pi=&pProcPtrInfo[ProcPtrInfoNum];
1388 ProcPtrInfoNum++;
1389
1390 pi->pParmInfo=(PARAMETER_INFO *)HeapAlloc(hHeap,0,1);
1391 pi->ParmNum=0;
1392
1393 //buffer[0]は'('となっている
1394 i=1;
1395
1396 while(1){
1397 if(buffer[i]==')') break;
1398
1399 pi->pParmInfo=(PARAMETER_INFO *)HeapReAlloc(hHeap,0,pi->pParmInfo,(pi->ParmNum+1)*sizeof(PARAMETER_INFO));
1400
1401 //ByVal
1402 if(buffer[i]==1&&buffer[i+1]==ESC_BYVAL){
1403 pi->pParmInfo[pi->ParmNum].bByVal=1;
1404 i+=2;
1405 }
1406 else if(buffer[i]==1&&buffer[i+1]==ESC_BYREF){
1407 pi->pParmInfo[pi->ParmNum].bByVal=0;
1408 i+=2;
1409 }
1410 else pi->pParmInfo[pi->ParmNum].bByVal=1;
1411
1412 //パラメータ名
1413 sw=0;
1414 for(i2=0;;i++,i2++){
1415 if(buffer[i]=='('){
1416 if(!sw) sw=1;
1417
1418 i3=GetStringInPare(temporary+i2,buffer+i);
1419 i2+=i3-1;
1420 i+=i3-1;
1421 continue;
1422 }
1423 if(buffer[i]=='['){
1424 if(!sw) sw=1;
1425
1426 i3=GetStringInBracket(temporary+i2,buffer+i);
1427 i2+=i3-1;
1428 i+=i3-1;
1429 continue;
1430 }
1431 if(!IsVariableChar(buffer[i])){
1432 temporary[i2]=0;
1433 break;
1434 }
1435 temporary[i2]=buffer[i];
1436 }
1437 pi->pParmInfo[pi->ParmNum].name=0;
1438
1439 if(sw){
1440 //配列パラメータ
1441 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(29,NULL,cp);
1442 pi->pParmInfo[pi->ParmNum].bArray=1;
1443
1444 if((temporary[i2-2]=='('&&temporary[i2-1]==')')||
1445 (temporary[i2-2]=='['&&temporary[i2-1]==']')){
1446 pi->pParmInfo[pi->ParmNum].SubScripts[0]=LONG_MAX;
1447 pi->pParmInfo[pi->ParmNum].SubScripts[1]=-1;
1448
1449 temporary[i2-2]=0;
1450 }
1451 else{
1452 GetArrange(temporary,temp2,pi->pParmInfo[pi->ParmNum].SubScripts);
1453 lstrcpy(temporary,temp2);
1454 }
1455
1456 i2=lstrlen(temporary);
1457 }
1458 else{
1459 pi->pParmInfo[pi->ParmNum].bArray=0;
1460 pi->pParmInfo[pi->ParmNum].SubScripts[0]=-1;
1461 }
1462
1463 //型
1464 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1465 i+=2;
1466
1467 i2=0;
1468 while(buffer[i]=='*'){
1469 temporary[i2]=buffer[i];
1470 i++;
1471 i2++;
1472 }
1473 for(;;i++,i2++){
1474 if(!IsVariableChar(buffer[i])){
1475 temporary[i2]=0;
1476 break;
1477 }
1478 temporary[i2]=buffer[i];
1479 }
1480
1481 pi->pParmInfo[pi->ParmNum].type=
1482 GetTypeFixed(temporary,&pi->pParmInfo[pi->ParmNum].u.index);
1483 if(pi->pParmInfo[pi->ParmNum].type==-1){
1484 SetError(3,temporary,cp);
1485 pi->pParmInfo[pi->ParmNum].type=DEF_PTR_VOID;
1486 }
1487 if(pi->pParmInfo[pi->ParmNum].type==DEF_OBJECT){
1488 if(pi->pParmInfo[pi->ParmNum].bByVal) SetError(28,temporary,cp);
1489 }
1490 }
1491 else{
1492 pi->pParmInfo[pi->ParmNum].type=GetTypeFromSimpleName(temporary);
1493 SetError(-103,temporary,cp);
1494 }
1495
1496 pi->ParmNum++;
1497
1498 if(buffer[i]==','){
1499 i++;
1500 continue;
1501 }
1502 else if(buffer[i]==')') continue;
1503 else{
1504 SetError(1,NULL,cp);
1505 return 0;
1506 }
1507 }
1508 i++;
1509
1510 //戻り値
1511 if(dwProcType==ESC_FUNCTION){
1512 if(buffer[i]==1&&buffer[i+1]==ESC_AS){
1513 i+=2;
1514 i2=0;
1515 if(buffer[i]=='*') temporary[i2++]=buffer[i++];
1516 for(;;i++,i2++){
1517 if(!IsVariableChar(buffer[i])){
1518 temporary[i2]=0;
1519 break;
1520 }
1521 temporary[i2]=buffer[i];
1522 }
1523 pi->ReturnType=GetTypeFixed(temporary,&pi->u.ReturnIndex);
1524 if(pi->ReturnType==DEF_NON) SetError(3,temporary,cp);
1525 }
1526 else pi->ReturnType=DEF_DOUBLE;
1527 }
1528 else pi->ReturnType=DEF_NON;
1529
1530 return ProcPtrInfoNum-1;
1531}
1532void DeleteProcPtrInfo(void){
1533 extern PROCPTRINFO *pProcPtrInfo;
1534 extern int ProcPtrInfoNum;
1535 int i;
1536
1537 for(i=0;i<ProcPtrInfoNum;i++){
1538 HeapDefaultFree(pProcPtrInfo[i].pParmInfo);
1539 }
1540
1541 HeapDefaultFree(pProcPtrInfo);
1542}
Note: See TracBrowser for help on using the repository browser.