source: dev/BasicCompiler_Common/Intermediate_Step1.cpp@ 80

Last change on this file since 80 was 79, checked in by dai_9181, 18 years ago

バージョンをβ17にした。
#strictをデフォルトの状態で適用するようにした(#90)。
Dimステートメントにおいて、初期値式とAsが同時に指定されていたとき、As以降も初期値式の一部として捉えるよう、変更(#91)。
GetTypeDef関数を完全廃止。

File size: 28.3 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3void ChangeReturnCode(char *buffer){
4
5#ifdef _DEBUG
6 //改行コードの整合性チェック
7 for( int i=0; ; i++ ){
8 if( buffer[i] == '\0' ){
9 break;
10 }
11 if( buffer[i]!='\r' && buffer[i+1]=='\n'
12 || buffer[i]=='\r' && buffer[i+1]!='\n' ){
13 char temporary[255];
14 strncpy( temporary, buffer + i-100, 130 );
15 temporary[130] = 0;
16 for(int i2=0; ;i2++){
17 if(temporary[i2]=='\r') temporary[i2]='A';
18 if(temporary[i2]=='\n') temporary[i2]='B';
19 if(temporary[i2]=='\0') break;
20 }
21 MessageBox( hOwnerEditor, temporary, "改行コードの整合性チェック", MB_OK | MB_ICONEXCLAMATION );
22 }
23 }
24#endif
25
26 //改行コードのCRLFをLFに変換
27 for(int i=0,i2=0;;i++,i2++){
28 if(buffer[i]=='\r'&&buffer[i+1]=='\n') i++;
29 buffer[i2]=buffer[i];
30 if(buffer[i]=='\0') break;
31 }
32}
33void DeleteComment(char *buffer){ //注釈「'」の取り除き
34 int i,i2,i3,IsStr;
35 char *temporary;
36 temporary=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(buffer)+1);
37 for(i=0,i2=0,i3=0,IsStr=0;;i++,i2++){
38 if(buffer[i]=='\"') IsStr^=1;
39 if(buffer[i]=='\n'||buffer[i]=='\0'){
40 i2--;
41 while(temporary[i2]==' '||temporary[i2]=='\t') i2--;
42 i2++;
43
44 if(i3){
45 //複数行に渡る注釈文の中に改行が存在するとき
46 memset(temporary+i2,'\n',i3);
47 i2+=i3;
48 i3=0;
49 }
50 }
51 if(buffer[i]=='\''&&IsStr==0){
52 //注釈文
53 i2--;
54 while(temporary[i2]==' '||temporary[i2]=='\t') i2--;
55 i2++;
56 while(buffer[i]!='\n'&&buffer[i]!='\0') i++;
57 }
58 if(buffer[i]=='/'&&buffer[i+1]=='*'&&IsStr==0){
59 //注釈文(複数行)
60 i+=2;
61 i3=0;
62 while(!(buffer[i]=='*'&&buffer[i+1]=='/')){
63 if(buffer[i]=='\n') i3++;
64 if(buffer[i]=='\0') break;
65 i++;
66 }
67 if(buffer[i]){
68 i+=2;
69 }
70 i--;
71 i2--;
72 continue;
73 }
74 temporary[i2]=buffer[i];
75 if(buffer[i]=='\0') break;
76 }
77 lstrcpy(buffer,temporary);
78 GlobalFree(temporary);
79}
80int KillReturnCode_InParameter(char *buffer,int *pRnum,char cBeginPare,char cEndPare){
81 int i,i2,i3,IsStr;
82
83 //カッコ'('直下の改行
84 while(buffer[0]=='\n'){
85 SlideString(buffer+1,-1);
86 (*pRnum)++;
87 }
88
89 for(i=0,IsStr=0;;i++){
90 if(IsDBCSLeadByte(buffer[i])&&buffer[i+1]){
91 i++;
92 continue;
93 }
94
95 if(buffer[i]=='\"') IsStr^=1;
96
97 if(buffer[i]=='\0') break; //エラー
98 if(buffer[i]=='\n'){
99 i2=0;
100 i3=0;
101 while(buffer[i+i2]=='\n'){
102 i2++;
103 i3++;
104 while(buffer[i+i2]==' '||buffer[i+i2]=='\t') i2++;
105 }
106 while(buffer[i+i2]==' '||buffer[i+i2]=='\t') i2++;
107
108 if(buffer[i+i2]==cEndPare){
109 SlideString(buffer+i+i2,-i2);
110 (*pRnum)+=i3;
111 break;
112 }
113
114 //エラー
115 break;
116 }
117
118 if(buffer[i]==cBeginPare&&IsStr==0){
119 i++;
120 i2=KillReturnCode_InParameter(buffer+i,pRnum,cBeginPare,cEndPare);
121 i+=i2;
122 if(buffer[i]!=cEndPare) break;
123 continue;
124 }
125 if(buffer[i]==cEndPare&&IsStr==0) break;
126
127 if(buffer[i]==','&&buffer[i+1]=='\n'&&IsStr==0){
128 i++;
129 while(buffer[i]=='\n'){
130 SlideString(buffer+i+1,-1);
131 (*pRnum)++;
132 }
133 i--;
134 }
135 }
136 return i;
137}
138void KillReturnCode(char *buffer){
139 int i,i2;
140
141 //アンダーバーによる改行
142 for(i=0;;i++){
143 i2=0;
144 while(buffer[i]=='_'&&buffer[i+1]=='\n'){
145 i2++;
146 SlideString(buffer+i+2,-2);
147 while(buffer[i]=='\n'){
148 SlideString(buffer+i+1,-1);
149 i2++;
150 }
151 for(;;i++){
152 if(buffer[i]=='_'&&buffer[i+1]=='\n') break;
153 if(buffer[i]=='\n'||buffer[i]=='\0'){
154 SlideString(buffer+i,i2);
155 memset(buffer+i,'\n',i2);
156 break;
157 }
158 }
159 }
160 if(buffer[i]=='\0') break;
161 }
162
163 //カッコ内パラメータの改行
164 int IsStr,rnum;
165 for(i=0,IsStr=0,rnum=0;;i++){
166 if(IsDBCSLeadByte(buffer[i])&&buffer[i+1]){
167 i++;
168 continue;
169 }
170 if(buffer[i]=='\0') break;
171 if(buffer[i]=='\n'){
172 if(rnum){
173 SlideString(buffer+i+1,rnum);
174 memset(buffer+i+1,'\n',rnum);
175 rnum=0;
176 }
177 }
178 if(buffer[i]=='\"') IsStr^=1;
179 if(buffer[i]=='('&&IsStr==0){
180 i++;
181 i2=KillReturnCode_InParameter(buffer+i,&rnum,'(',')');
182 i+=i2;
183 if(buffer[i]!=')') break;
184 }
185 if(buffer[i]=='['&&IsStr==0){
186 i++;
187 i2=KillReturnCode_InParameter(buffer+i,&rnum,'[',']');
188 i+=i2;
189 if(buffer[i]!=']') break;
190 }
191 }
192}
193void CheckParenthesis(char *buffer){
194 int i,IsStr,PareNum,sw;
195 _int8 bracket[1024];
196
197 for(i=0,IsStr=0,PareNum=0,sw=0;;i++){
198 if(buffer[i]=='\"'){
199 IsStr^=1;
200 continue;
201 }
202
203 else if(buffer[i]=='('&&IsStr==0){
204 bracket[PareNum]=0;
205 PareNum++;
206 }
207 else if(buffer[i]=='['&&IsStr==0){
208 bracket[PareNum]=1;
209 PareNum++;
210 }
211
212 else if(buffer[i]==')'&&IsStr==0){
213 PareNum--;
214 if(bracket[PareNum]!=0||PareNum<0){
215 //"カッコ \'( )\'"
216 SetError(4,STRING_PARENTHESIS,i);
217 return;
218 }
219 }
220 else if(buffer[i]==']'&&IsStr==0){
221 PareNum--;
222 if(bracket[PareNum]!=1||PareNum<0){
223 //"カッコ \'( )\'"
224 SetError(4,STRING_PARENTHESIS,i);
225 return;
226 }
227 }
228
229 else if(buffer[i]=='\n'||buffer[i]=='\0'){
230
231 //"カッコ \'( )\'"
232 if(PareNum!=0) SetError(4,STRING_PARENTHESIS,i);
233
234 if(IsStr!=0) SetError(5,NULL,i);
235 if(buffer[i]=='\0') break;
236 PareNum=0;
237 IsStr=0;
238
239 sw=0;
240 }
241
242 else if((IsDBCSLeadByte(buffer[i])||buffer[i]==1)&&IsStr==0){
243 //不正な文字コード
244 if(sw==0){
245 //全角スペース
246 if(buffer[i]==(char)0x81&&buffer[i+1]==(char)0x40)
247 SetError(20,NULL,i);
248
249 //その他の全角文字
250 else SetError(8,NULL,i);
251 sw=1;
252 }
253 }
254 }
255}
256BOOL CheckParenthesis2(char *buffer){
257 int i,IsStr,PareNum,sw;
258 _int8 bracket[1024];
259
260 for(i=0,IsStr=0,PareNum=0,sw=0;;i++){
261 if(buffer[i]=='\"'){
262 IsStr^=1;
263 continue;
264 }
265
266 else if(buffer[i]=='('&&IsStr==0){
267 bracket[PareNum]=0;
268 PareNum++;
269 }
270 else if(buffer[i]=='['&&IsStr==0){
271 bracket[PareNum]=1;
272 PareNum++;
273 }
274
275 else if(buffer[i]==')'&&IsStr==0){
276 PareNum--;
277 if(bracket[PareNum]!=0||PareNum<0){
278 //"カッコ \'( )\'"
279 return 0;
280 }
281 }
282 else if(buffer[i]==']'&&IsStr==0){
283 PareNum--;
284 if(bracket[PareNum]!=1||PareNum<0){
285 //"カッコ \'( )\'"
286 return 0;
287 }
288 }
289
290 else if(buffer[i]=='\n'||buffer[i]=='\0'){
291
292 //"カッコ \'( )\'"
293 if(PareNum!=0){
294 return 0;
295 }
296
297 if(IsStr!=0){
298 return 0;
299 }
300 if(buffer[i]=='\0') break;
301 PareNum=0;
302 IsStr=0;
303
304 sw=0;
305 }
306
307 else if((IsDBCSLeadByte(buffer[i])||buffer[i]==1)&&IsStr==0){
308 //不正な文字コード
309 if(sw==0){
310 //全角スペース
311 if(buffer[i]==(char)0x81&&buffer[i+1]==(char)0x40){
312 return 0;
313 }
314
315 //その他の全角文字
316 else return 0;
317 sw=1;
318 }
319 }
320 }
321 return 1;
322}
323void DirectiveCheck(void){
324 extern char *basbuf;
325 extern char BasicCurDir[MAX_PATH];
326 int i,i2,i3;
327 char temporary[VN_SIZE];
328
329 extern BOOL bStrict;
330 bStrict=1;
331
332 for(i=0;;i++){
333 if(basbuf[i]=='\0') break;
334 if(((basbuf[i-2]==0&&basbuf[i-1]==-1)||basbuf[i-1]=='\n')&&
335 basbuf[i]=='#'){
336 for(i2=i+1,i3=0;;i2++,i3++){
337 if(!IsVariableChar(basbuf[i2])){
338 temporary[i3]=0;
339 break;
340 }
341 temporary[i3]=basbuf[i2];
342 }
343 if(lstrcmpi(temporary,"noprompt")==0){
344 //#noprompt
345 //旧機能なので、無視
346 for(;;i2++){
347 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
348 }
349 SlideString(basbuf+i2,i-i2);
350 }
351 else if(lstrcmpi(temporary,"strict")==0){
352 //#strict
353 //旧機能なので、無視
354 for(;;i2++){
355 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
356 }
357 SlideString(basbuf+i2,i-i2);
358 }
359 else if(lstrcmpi(temporary,"struct")==0){
360 //#struct code
361 //旧機能なので、無視
362 for(;;i2++){
363 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
364 }
365 SlideString(basbuf+i2,i-i2);
366 }
367 else if(lstrcmpi(temporary,"resource")==0){
368 //#resource
369 while(basbuf[i2]==' '||basbuf[i2]=='\t') i2++;
370 if(basbuf[i2]!='\"'){
371 SetError(1,NULL,i2);
372 return;
373 }
374 for(i3=0,i2++;;i2++,i3++){
375 if(basbuf[i2]=='\"'){
376 temporary[i3]=0;
377 break;
378 }
379 temporary[i3]=basbuf[i2];
380 }
381 GetFullPath(temporary,BasicCurDir);
382
383 extern char ResourceFileName[MAX_PATH];
384 lstrcpy(ResourceFileName,temporary);
385
386 for(;;i2++){
387 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
388 }
389 SlideString(basbuf+i2,i-i2);
390 }
391 }
392 }
393}
394void NextCommandFormat(char *buffer){
395 int i,i2,i3;
396 char temporary[255];
397
398 //Next命令語のフォーマット
399 for(i=0;;i++){
400 if(buffer[i]=='\n'||buffer[i]==':'||i==0){
401 if(buffer[i]=='\n'||buffer[i]==':') i++;
402 while(buffer[i]==' '||buffer[i]=='\t') i++;
403 while(buffer[i]>='0'&&buffer[i]<='9') i++;
404 while(buffer[i]==' '||buffer[i]=='\t') i++;
405 if((buffer[i]=='n'||buffer[i]=='N')&&(buffer[i+1]=='e'||buffer[i+1]=='E')&&(buffer[i+2]=='x'||buffer[i+2]=='X')&&(buffer[i+3]=='t'||buffer[i+3]=='T')&&
406 (buffer[i+4]==' '||buffer[i+4]=='\t')){
407 i2=i+5;
408 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
409 if(buffer[i2]!='\n'){
410 lstrcpy(temporary,"NEXT");
411 for(i3=0;;i2++){
412 if(buffer[i2]=='\n'||buffer[i2]==':'||buffer[i2]=='\0') break;
413 if(buffer[i2]==','){
414 lstrcat(temporary,":NEXT");
415 i3=1;
416 }
417 }
418 if(i3){
419 i3=lstrlen(temporary);
420 SlideString(buffer+i2,i-i2+i3);
421 memcpy(buffer+i,temporary,i3);
422 }
423 }
424 }
425 }
426 if(buffer[i]=='\0') break;
427 }
428}
429void SetEscapeSequenceFormat(char *buffer){
430 /*「MOD」「AND」「OR」
431 その他制御文字をエスケープシーケンスを使用した記号へ変換 */
432 int i,i2,i3,i4,i5,i6,sw1,IsStr;
433 char *temporary,temp2[VN_SIZE];
434
435 temporary=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,lstrlen(buffer)*2);
436 for(i=0,i2=0,IsStr=0;;i++,i2++){
437 if(buffer[i]=='\"') IsStr^=1;
438 if(buffer[i]=='-'&&buffer[i+1]=='>'&&IsStr==0){
439 buffer[i]=1;
440 buffer[i+1]=ESC_PSMEM;
441 }
442 if(IsVariableChar(buffer[i])&&IsStr==0){
443 i3=i2;
444 for(;;i++,i2++){
445 if(!IsVariableChar(buffer[i])){
446 temporary[i2]=0;
447 break;
448 }
449 temporary[i2]=buffer[i];
450 }
451 if(lstrcmpi(temporary+i3,"End")==0) i6=1;
452 else if(lstrcmpi(temporary+i3,"Exit")==0) i6=2;
453 else if(lstrcmpi(temporary+i3,"Select")==0) i6=3;
454 else if(lstrcmpi(temporary+i3,"Case")==0) i6=4;
455 else if(lstrcmpi(temporary+i3,"Else")==0) i6=5;
456 else i6=0;
457 if(i6){
458 i4=i;
459 while(buffer[i4]==' '||buffer[i4]=='\t') i4++;
460 for(i5=0;;i4++,i5++){
461 if(!IsVariableChar(buffer[i4])){
462 temp2[i5]=0;
463 break;
464 }
465 temp2[i5]=buffer[i4];
466 }
467 sw1=0;
468 if(i6==3){
469 //Select~
470 if(lstrcmpi(temp2,"Case")==0) sw1=1;
471 }
472 else if(i6==4){
473 //Case~
474 if(lstrcmpi(temp2,"Else")==0) sw1=1;
475 }
476 else if(i6==5){
477 //Else If
478 if(lstrcmpi(temp2,"If")==0) sw1=1;
479 }
480 else if(i6==1){
481 //End~
482 switch(temp2[0]){
483 case 'c':
484 case 'C':
485 if(lstrcmpi(temp2,"Class")==0) sw1=1;
486 break;
487 case 'e':
488 case 'E':
489 if(lstrcmpi(temp2,"Enum")==0) sw1=1;
490 break;
491 case 'i':
492 case 'I':
493 if(lstrcmpi(temp2,"If")==0) sw1=1;
494 else if(lstrcmpi(temp2,"Interface")==0) sw1=1;
495 break;
496 case 'f':
497 case 'F':
498 if(lstrcmpi(temp2,"Function")==0) sw1=1;
499 break;
500 case 'm':
501 case 'M':
502 if(lstrcmpi(temp2,"Macro")==0) sw1=1;
503 break;
504 case 's':
505 case 'S':
506 if(lstrcmpi(temp2,"Sub")==0) sw1=1;
507 else if(lstrcmpi(temp2,"Select")==0) sw1=1;
508 break;
509 case 't':
510 case 'T':
511 if(lstrcmpi(temp2,"Type")==0) sw1=1;
512 break;
513 case 'w':
514 case 'W':
515 if(lstrcmpi(temp2,"With")==0) sw1=1;
516 break;
517 }
518 }
519 else if(i6==2){
520 //Exit~
521 if(
522 lstrcmpi(temp2,"For")==0||
523 lstrcmpi(temp2,"While")==0||
524 lstrcmpi(temp2,"Do")==0||
525 lstrcmpi(temp2,"Function")==0||
526 lstrcmpi(temp2,"Sub")==0||
527 lstrcmpi(temp2,"Macro")==0
528 ) sw1=1;
529 }
530
531 if(sw1){
532 i=i4;
533 memcpy(temporary+i2,temp2,i5);
534 i2+=i5;
535 temporary[i2]=0;
536 }
537 }
538 i--;
539 i2--;
540
541 switch(temporary[i3]){
542 case 'a':
543 case 'A':
544 if(lstrcmpi(temporary+i3,"And")==0){
545 i2=i3;
546 temporary[i2++]=1;
547 temporary[i2]=ESC_AND;
548 }
549 else if(lstrcmpi(temporary+i3,"Abstract")==0){
550 i2=i3;
551 temporary[i2++]=1;
552 temporary[i2]=ESC_ABSTRACT;
553 }
554 else if(lstrcmpi(temporary+i3,"As")==0){
555 i2=i3;
556 temporary[i2++]=1;
557 temporary[i2]=ESC_AS;
558 }
559 break;
560 case 'b':
561 case 'B':
562 if(lstrcmpi(temporary+i3,"ByVal")==0){
563 i2=i3;
564 temporary[i2++]=1;
565 temporary[i2]=ESC_BYVAL;
566 }
567 else if(lstrcmpi(temporary+i3,"ByRef")==0){
568 i2=i3;
569 temporary[i2++]=1;
570 temporary[i2]=ESC_BYREF;
571 }
572 break;
573 case 'c':
574 case 'C':
575 if(lstrcmpi(temporary+i3,"Catch")==0){
576 i2=i3;
577 temporary[i2++]=1;
578 temporary[i2]=ESC_CATCH;
579 }
580 else if(lstrcmpi(temporary+i3,"Continue")==0){
581 i2=i3;
582 temporary[i2++]=1;
583 temporary[i2]=ESC_CONTINUE;
584 }
585 else if(lstrcmpi(temporary+i3,"cdecl")==0){
586 i2=i3;
587 temporary[i2++]=1;
588 temporary[i2]=ESC_CDECL;
589 }
590 else if(lstrcmpi(temporary+i3,"Case")==0){
591 i2=i3;
592 temporary[i2++]=1;
593 temporary[i2]=ESC_CASE;
594 }
595 else if(lstrcmpi(temporary+i3,"CaseElse")==0){
596 i2=i3;
597 temporary[i2++]=1;
598 temporary[i2]=ESC_CASEELSE;
599 }
600 else if(lstrcmpi(temporary+i3,"Const")==0){
601 i2=i3;
602 temporary[i2++]=1;
603 temporary[i2]=ESC_CONST;
604 }
605 else if(lstrcmpi(temporary+i3,"Class")==0){
606 i2=i3;
607 temporary[i2++]=1;
608 temporary[i2]=ESC_CLASS;
609 }
610 break;
611 case 'd':
612 case 'D':
613 if(lstrcmpi(temporary+i3,"Declare")==0){
614 i2=i3;
615 int i9=i2;
616 temporary[i2]=1;
617 temporary[++i2]=ESC_DECLARE;
618 i++;
619 while(buffer[i]==' '||buffer[i]=='\t') i++;
620
621 // Sub/Function
622 for(i4=0;;i++,i4++){
623 if(!IsVariableChar(buffer[i])){
624 temp2[i4]=0;
625 break;
626 }
627 temp2[i4]=buffer[i];
628 }
629 if(lstrcmpi(temp2,"Sub")==0) temporary[++i2]=ESC_SUB;
630 else if(lstrcmpi(temp2,"Function")==0) temporary[++i2]=ESC_FUNCTION;
631 while(buffer[i]==' '||buffer[i]=='\t') i++;
632
633 // 関数名
634 for(i2++;;i++,i2++){
635 if(!IsVariableChar(buffer[i])){
636 i2--;
637 break;
638 }
639 temporary[i2]=buffer[i];
640 }
641 while(buffer[i]==' '||buffer[i]=='\t') i++;
642
643 for(i4=0;;i++,i4++){
644 if(!IsVariableChar(buffer[i])){
645 temp2[i4]=0;
646 break;
647 }
648 temp2[i4]=buffer[i];
649 }
650 if(lstrcmpi(temp2,"cdecl")==0){
651 temporary[++i2]=1;
652 temporary[++i2]=ESC_CDECL;
653
654 while(buffer[i]==' '||buffer[i]=='\t') i++;
655 for(i4=0;;i++,i4++){
656 if(!IsVariableChar(buffer[i])){
657 temp2[i4]=0;
658 break;
659 }
660 temp2[i4]=buffer[i];
661 }
662 }
663 if(lstrcmpi(temp2,"Lib")==0) temporary[++i2]=',';
664 while(buffer[i]==' '||buffer[i]=='\t') i++;
665
666 if(buffer[i]=='\"'){
667 temporary[++i2]=buffer[i];
668 for(i++,i2++;;i++,i2++){
669 temporary[i2]=buffer[i];
670 if(buffer[i]=='\"'){
671 i++;
672 break;
673 }
674 if(buffer[i]=='\0') break;
675 }
676 }
677 else{
678 for(i2++;;i++,i2++){
679 if(!IsVariableChar(buffer[i])){
680 i2--;
681 break;
682 }
683 temporary[i2]=buffer[i];
684 }
685 }
686 while(buffer[i]==' '||buffer[i]=='\t') i++;
687
688 temporary[++i2]=',';
689
690 if( memicmp( buffer + i, "Alias", 5 ) ==0 ){
691 i+=5;
692 for(i++,i2++;;i++,i2++){
693 temporary[i2]=buffer[i];
694 if(buffer[i]=='('){
695 i2--;
696 break;
697 }
698 if(buffer[i]=='\0') break;
699 }
700 }
701
702 temporary[++i2]=',';
703
704 i--;
705 }
706 else if(lstrcmpi(temporary+i3,"Def")==0){
707 i2=i3;
708 temporary[i2++]=1;
709 temporary[i2]=ESC_DEF;
710 }
711 break;
712 case 'e':
713 case 'E':
714 if(lstrcmpi(temporary+i3,"ElseIf")==0){
715 i2=i3;
716 temporary[i2++]=1;
717 temporary[i2]=ESC_ELSEIF;
718 }
719 else if(lstrcmpi(temporary+i3,"Else")==0){
720 i2=i3;
721 temporary[i2++]=1;
722 temporary[i2]=ESC_ELSE;
723 }
724 else if(lstrcmpi(temporary+i3,"Export")==0){
725 i2=i3;
726 temporary[i2++]=1;
727 temporary[i2]=ESC_EXPORT;
728 }
729 else if(lstrcmpi(temporary+i3,"Enum")==0){
730 i2=i3;
731 temporary[i2++]=1;
732 temporary[i2]=ESC_ENUM;
733 }
734
735 else if(temporary[i3+1]=='n'||temporary[i3+1]=='N'){
736 //終了記述
737 if(lstrcmpi(temporary+i3,"EndIf")==0){
738 i2=i3;
739 temporary[i2++]=1;
740 temporary[i2]=ESC_ENDIF;
741 }
742 else if(lstrcmpi(temporary+i3,"EndFunction")==0){
743 i2=i3;
744 temporary[i2++]=1;
745 temporary[i2]=ESC_ENDFUNCTION;
746 }
747 else if(lstrcmpi(temporary+i3,"EndSub")==0){
748 i2=i3;
749 temporary[i2++]=1;
750 temporary[i2]=ESC_ENDSUB;
751 }
752 else if(lstrcmpi(temporary+i3,"EndMacro")==0){
753 i2=i3;
754 temporary[i2++]=1;
755 temporary[i2]=ESC_ENDMACRO;
756 }
757 else if(lstrcmpi(temporary+i3,"EndClass")==0){
758 i2=i3;
759 temporary[i2++]=1;
760 temporary[i2]=ESC_ENDCLASS;
761 }
762 else if(lstrcmpi(temporary+i3,"EndInterface")==0){
763 i2=i3;
764 temporary[i2++]=1;
765 temporary[i2]=ESC_ENDINTERFACE;
766 }
767 else if(lstrcmpi(temporary+i3,"EndTry")==0){
768 i2=i3;
769 temporary[i2++]=1;
770 temporary[i2]=ESC_ENDTRY;
771 }
772 else if(lstrcmpi(temporary+i3,"EndType")==0){
773 i2=i3;
774 temporary[i2++]=1;
775 temporary[i2]=ESC_ENDTYPE;
776 }
777 else if(lstrcmpi(temporary+i3,"EndEnum")==0){
778 i2=i3;
779 temporary[i2++]=1;
780 temporary[i2]=ESC_ENDENUM;
781 }
782 else if(lstrcmpi(temporary+i3,"EndSelect")==0){
783 i2=i3;
784 temporary[i2++]=1;
785 temporary[i2]=ESC_ENDSELECT;
786 }
787 else if(lstrcmpi(temporary+i3,"EndWith")==0){
788 i2=i3;
789 temporary[i2++]=1;
790 temporary[i2]=ESC_ENDWITH;
791 }
792 }
793 else if(temporary[i3+1]=='x'||temporary[i3+1]=='X'){
794 if(lstrcmpi(temporary+i3,"ExitFor")==0){
795 i2=i3;
796 temporary[i2++]=1;
797 temporary[i2]=ESC_EXITFOR;
798 }
799 else if(lstrcmpi(temporary+i3,"ExitWhile")==0){
800 i2=i3;
801 temporary[i2++]=1;
802 temporary[i2]=ESC_EXITWHILE;
803 }
804 else if(lstrcmpi(temporary+i3,"ExitDo")==0){
805 i2=i3;
806 temporary[i2++]=1;
807 temporary[i2]=ESC_EXITDO;
808 }
809 else if(lstrcmpi(temporary+i3,"ExitFunction")==0){
810 i2=i3;
811 temporary[i2++]=1;
812 temporary[i2]=ESC_EXITFUNCTION;
813 }
814 else if(lstrcmpi(temporary+i3,"ExitSub")==0){
815 i2=i3;
816 temporary[i2++]=1;
817 temporary[i2]=ESC_EXITSUB;
818 }
819 else if(lstrcmpi(temporary+i3,"ExitMacro")==0){
820 i2=i3;
821 temporary[i2++]=1;
822 temporary[i2]=ESC_EXITMACRO;
823 }
824 }
825 break;
826 case 'f':
827 case 'F':
828 if(lstrcmpi(temporary+i3,"Finally")==0){
829 i2=i3;
830 temporary[i2++]=1;
831 temporary[i2]=ESC_FINALLY;
832 }
833 else if(lstrcmpi(temporary+i3,"Function")==0){
834 i2=i3;
835 temporary[i2++]=1;
836 temporary[i2]=ESC_FUNCTION;
837 }
838 break;
839 case 'i':
840 case 'I':
841 if(lstrcmpi(temporary+i3,"If")==0){
842 i2=i3;
843 temporary[i2++]=1;
844 temporary[i2]=ESC_IF;
845 }
846 else if(lstrcmpi(temporary+i3,"Inherits")==0){
847 i2=i3;
848 temporary[i2++]=1;
849 temporary[i2]=ESC_INHERITS;
850 }
851 else if(lstrcmpi(temporary+i3,"Interface")==0){
852 i2=i3;
853 temporary[i2++]=1;
854 temporary[i2]=ESC_INTERFACE;
855 }
856 break;
857 case 'm':
858 case 'M':
859 if(lstrcmpi(temporary+i3,"Mod")==0){
860 i2=i3;
861 temporary[i2++]=1;
862 temporary[i2]=ESC_MOD;
863 }
864 else if(lstrcmpi(temporary+i3,"Macro")==0){
865 i2=i3;
866 temporary[i2++]=1;
867 temporary[i2]=ESC_MACRO;
868 }
869 break;
870 case 'n':
871 case 'N':
872 if(lstrcmpi(temporary+i3,"New")==0){
873 i2=i3;
874 temporary[i2++]=1;
875 temporary[i2]=ESC_NEW;
876 }
877 else if(lstrcmpi(temporary+i3,"Not")==0){
878 i2=i3;
879 temporary[i2++]=1;
880 temporary[i2]=ESC_NOT;
881 }
882 break;
883 case 'o':
884 case 'O':
885 if(lstrcmpi(temporary+i3,"Or")==0){
886 i2=i3;
887 temporary[i2++]=1;
888 temporary[i2]=ESC_OR;
889 }
890 else if(lstrcmpi(temporary+i3,"Override")==0){
891 i2=i3;
892 temporary[i2++]=1;
893 temporary[i2]=ESC_OVERRIDE;
894 }
895 else if(lstrcmpi(temporary+i3,"Operator")==0){
896 i2=i3;
897 temporary[i2++]=1;
898 temporary[i2]=ESC_OPERATOR;
899 }
900 break;
901 case 's':
902 case 'S':
903 if(lstrcmpi(temporary+i3,"Sub")==0){
904 i2=i3;
905 temporary[i2++]=1;
906 temporary[i2]=ESC_SUB;
907 }
908 else if(lstrcmpi(temporary+i3,"SelectCase")==0){
909 i2=i3;
910 temporary[i2++]=1;
911 temporary[i2]=ESC_SELECTCASE;
912 }
913 else if(lstrcmpi(temporary+i3,"Static")==0){
914 i2=i3;
915 temporary[i2++]=1;
916 temporary[i2]=ESC_STATIC;
917 }
918 break;
919 case 't':
920 case 'T':
921 if(lstrcmpi(temporary+i3,"Then")==0){
922 i2=i3;
923 temporary[i2++]=1;
924 temporary[i2]=ESC_THEN;
925 }
926 else if(lstrcmpi(temporary+i3,"Throw")==0){
927 i2=i3;
928 temporary[i2++]=1;
929 temporary[i2]=ESC_THROW;
930 }
931 else if(lstrcmpi(temporary+i3,"Try")==0){
932 i2=i3;
933 temporary[i2++]=1;
934 temporary[i2]=ESC_TRY;
935 }
936 else if(lstrcmpi(temporary+i3,"Type")==0){
937 i2=i3;
938 temporary[i2++]=1;
939 temporary[i2]=ESC_TYPE;
940 }
941 else if(lstrcmpi(temporary+i3,"TypeDef")==0){
942 i2=i3;
943 temporary[i2++]=1;
944 temporary[i2]=ESC_TYPEDEF;
945 }
946 break;
947 case 'u':
948 case 'U':
949 if(lstrcmpi(temporary+i3,"Using")==0){
950 i2=i3;
951 temporary[i2++]=1;
952 temporary[i2]=ESC_USING;
953 }
954 break;
955 case 'v':
956 case 'V':
957 if(lstrcmpi(temporary+i3,"Virtual")==0){
958 i2=i3;
959 temporary[i2++]=1;
960 temporary[i2]=ESC_VIRTUAL;
961 }
962 break;
963 case 'w':
964 case 'W':
965 if(lstrcmpi(temporary+i3,"With")==0){
966 i2=i3;
967 temporary[i2++]=1;
968 temporary[i2]=ESC_WITH;
969 }
970 break;
971 case 'x':
972 case 'X':
973 if(lstrcmpi(temporary+i3,"Xor")==0){
974 i2=i3;
975 temporary[i2++]=1;
976 temporary[i2]=ESC_XOR;
977 }
978 break;
979 }
980
981 continue;
982 }
983 temporary[i2]=buffer[i];
984 if(buffer[i]=='\0') break;
985 }
986 lstrcpy(buffer,temporary);
987 HeapDefaultFree(temporary);
988}
989void DefCommandFormat(char *buffer){
990 int i,i2,PareNum;
991 char temporary[255];
992
993 //Def命令語からFunction命令語へ
994 for(i=0;;i++){
995 if(buffer[i]==1&&buffer[i+1]==ESC_DEF){
996 buffer[i+1]=ESC_FUNCTION;
997 i+=2;
998 while(buffer[i]==' '||buffer[i]=='\t') i++;
999 for(i2=0;;i++,i2++){
1000 if(!IsVariableChar(buffer[i])){
1001 temporary[i2]=0;
1002 break;
1003 }
1004 temporary[i2]=buffer[i];
1005 }
1006 while(buffer[i]==' '||buffer[i]=='\t') i++;
1007 if(buffer[i]!='('){
1008 SetError(1,NULL,i);
1009 return;
1010 }
1011 i++;
1012 while(1){
1013 while(buffer[i]==' '||buffer[i]=='\t') i++;
1014 if(buffer[i]==')') break;
1015 SlideString(buffer+i,2);
1016 buffer[i]=1;
1017 buffer[i+1]=ESC_BYVAL;
1018 i+=2;
1019 PareNum=0;
1020 for(;;i++){
1021 if(buffer[i]=='(') PareNum++;
1022 if(buffer[i]==')'){
1023 PareNum--;
1024 if(PareNum<0) break;
1025 }
1026 if(buffer[i]==','&&PareNum==0) break;
1027 }
1028 if(buffer[i]==')') break;
1029 i++;
1030 }
1031 i++;
1032 while(buffer[i]==' '||buffer[i]=='\t') i++;
1033 if(buffer[i]!='='){
1034 SetError(1,NULL,i);
1035 break;
1036 }
1037 i2=lstrlen(temporary);
1038 SlideString(buffer+i,i2+1);
1039 buffer[i]=':';
1040 i++;
1041 memcpy(buffer+i,temporary,i2);
1042 i+=i2;
1043 while(!IsCommandDelimitation(buffer[i])) i++;
1044 SlideString(buffer+i,3);
1045 buffer[i]=':';
1046 buffer[i+1]=1;
1047 buffer[i+2]=ESC_ENDFUNCTION;
1048 }
1049 if(buffer[i]=='\0') break;
1050 }
1051}
1052
1053void ChangeOneIf(char *write,int &wp,char *read,int &rp){
1054 int IsStr,sw;
1055
1056 //ブロック形式でないときはThenの後に区切り文字を入れる
1057 for(IsStr=0,sw=0;;wp++,rp++){
1058 if(read[rp]=='\"') IsStr^=1;
1059
1060 write[wp]=read[rp];
1061
1062 if(IsCommandDelimitation(read[rp])&&IsStr==0) return;
1063 if(read[rp]==1&&read[rp+1]==ESC_THEN&&
1064 (read[rp+2]==' '||read[rp+2]=='\t')){
1065 write[wp+1]=read[rp+1];
1066 write[wp+2]=':';
1067 rp+=3;
1068 wp+=3;
1069 while(read[rp]==' '||read[rp]=='\t') rp++;
1070 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1071 memcpy(write+wp,"Goto ",5);
1072 wp+=5;
1073 }
1074 break;
1075 }
1076 }
1077
1078 //Elseの後に区切り文字を入れる
1079 for(IsStr=0;;wp++,rp++){
1080 if(read[rp]=='\"') IsStr^=1;
1081
1082 write[wp]=read[rp];
1083
1084 if(read[rp]=='\n'||read[rp]=='\0') break;
1085 if(read[rp]==1&&read[rp+1]==ESC_IF){
1086 write[wp+1]=read[rp+1];
1087 wp+=2;
1088 rp+=2;
1089 ChangeOneIf(write,wp,read,rp);
1090 wp--;
1091 rp--;
1092 continue;
1093 }
1094 if(read[rp]==1&&read[rp+1]==ESC_ELSE){
1095 write[wp++]=':';
1096
1097 write[wp]=read[rp];
1098 write[wp+1]=read[rp+1];
1099 wp+=2;
1100 rp+=2;
1101
1102 write[wp++]=':';
1103
1104 while(read[rp]==' '||read[rp]=='\t') rp++;
1105 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1106 memcpy(write+wp,"Goto ",5);
1107 wp+=5;
1108 }
1109 break;
1110 }
1111 }
1112
1113 //"End If" を付加
1114 for(;;rp++,wp++){
1115 if(read[rp]=='\n'||read[rp]=='\0') break;
1116
1117 if(read[rp]==1&&read[rp+1]==ESC_IF){
1118 write[wp+1]=read[rp+1];
1119 wp+=2;
1120 rp+=2;
1121 ChangeOneIf(write,wp,read,rp);
1122 wp--;
1123 rp--;
1124 continue;
1125 }
1126 if(read[rp]==1&&read[rp+1]==ESC_ELSE) break;
1127
1128 write[wp]=read[rp];
1129 }
1130 write[wp]=':';
1131 write[wp+1]=1;
1132 write[wp+2]=ESC_ENDIF;
1133 wp+=3;
1134}
1135void OutsideIfFormat(char *write,int &wp,char *read,int &rp){
1136 int ElseCount=1;
1137
1138 for(;;rp++,wp++){
1139 if(read[rp]==1){
1140 if(read[rp+1]==ESC_IF){
1141 write[wp++]=read[rp++];
1142 write[wp++]=read[rp++];
1143 OutsideIfFormat(write,wp,read,rp);
1144 wp--,rp--;
1145 continue;
1146 }
1147 if(read[rp+1]==ESC_ENDIF){
1148 for(;ElseCount>0;wp+=3,ElseCount--){
1149 write[wp]=1;
1150 write[wp+1]=ESC_ENDIF;
1151 write[wp+2]=':';
1152 }
1153 rp+=2;
1154 break;
1155 }
1156 if(read[rp+1]==ESC_ELSEIF){
1157 write[wp]=1;
1158 write[wp+1]=ESC_ELSE;
1159 write[wp+2]=':';
1160
1161 write[wp+3]=1;
1162 write[wp+4]=ESC_IF;
1163
1164 wp+=4;
1165 rp++;
1166
1167 ElseCount++;
1168 continue;
1169 }
1170 }
1171
1172 write[wp]=read[rp];
1173 if(read[rp]=='\0') break;
1174 }
1175}
1176void IfCommandFormat(char *buffer){
1177 int i,i2;
1178
1179 char *temporary;
1180 temporary=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)*2+1024);
1181
1182 //1行Ifをブロック形式にする
1183 for(i=0,i2=0;;i++,i2++){
1184 if(buffer[i]==1&&buffer[i+1]==ESC_IF){
1185 temporary[i2++]=buffer[i++];
1186 temporary[i2++]=buffer[i++];
1187 ChangeOneIf(temporary,i2,buffer,i);
1188 i2--,i--;
1189 continue;
1190 }
1191
1192 temporary[i2]=buffer[i];
1193 if(buffer[i]=='\0') break;
1194 }
1195
1196 //ElseIfを入れ子構造に変更する
1197 for(i=0,i2=0;;i++,i2++){
1198 if(temporary[i]==1&&temporary[i+1]==ESC_IF){
1199 buffer[i2++]=temporary[i++];
1200 buffer[i2++]=temporary[i++];
1201 OutsideIfFormat(buffer,i2,temporary,i);
1202 i2--,i--;
1203 continue;
1204 }
1205
1206 buffer[i2]=temporary[i];
1207 if(temporary[i]=='\0') break;
1208 }
1209
1210 HeapDefaultFree(temporary);
1211}
1212void CheckPareCommand(void){
1213 extern char *basbuf;
1214 int i2,i3;
1215
1216 int FuncNum=0;
1217 int FuncType=0;
1218 int FuncPtr=-1;
1219 for(i2=0;;i2++){
1220 if(basbuf[i2]=='\0') break;
1221 if(IsCommandDelimitation(basbuf[i2])){
1222 if(basbuf[i2+1]==1){
1223 i2++;
1224 switch(basbuf[i2+1]){
1225 case ESC_FUNCTION:
1226 case ESC_SUB:
1227 case ESC_MACRO:
1228 if(FuncNum!=0){
1229 if(FuncType==ESC_FUNCTION)
1230 SetError(54,"End Function",FuncPtr);
1231 else if(FuncType==ESC_SUB)
1232 SetError(54,"End Sub",FuncPtr);
1233 else if(FuncType==ESC_MACRO)
1234 SetError(54,"End Macro",FuncPtr);
1235 return;
1236 }
1237 FuncType=basbuf[i2+1];
1238 FuncNum++;
1239 FuncPtr=i2;
1240 break;
1241 case ESC_ENDFUNCTION:
1242 case ESC_ENDSUB:
1243 case ESC_ENDMACRO:
1244 if(basbuf[i2+1]==ESC_ENDFUNCTION) i3=ESC_FUNCTION;
1245 else if(basbuf[i2+1]==ESC_ENDSUB) i3=ESC_SUB;
1246 else if(basbuf[i2+1]==ESC_ENDMACRO) i3=ESC_MACRO;
1247
1248 FuncNum--;
1249
1250 if(FuncNum!=0||i3!=FuncType){
1251 if(basbuf[i2+1]==ESC_ENDFUNCTION)
1252 SetError(12,"End Function",i2);
1253 else if(basbuf[i2+1]==ESC_ENDSUB)
1254 SetError(12,"End Sub",i2);
1255 else if(basbuf[i2+1]==ESC_ENDMACRO)
1256 SetError(12,"End Macro",i2);
1257 return;
1258 }
1259 break;
1260 }
1261 }
1262
1263
1264 }
1265 }
1266}
Note: See TracBrowser for help on using the repository browser.