source: dev/BasicCompiler_Common/Subroutine.cpp@ 58

Last change on this file since 58 was 54, checked in by dai_9181, 18 years ago

DeclareのLib、AliasにConst定義された文字列定数を指定できるようにした。

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