source: dev/BasicCompiler_Common/Intermediate_Step1.cpp@ 72

Last change on this file since 72 was 67, checked in by dai_9181, 18 years ago

[32bit Compiler]op_push_value → op_push_V
Nothingに対応。

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=0;
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 for(;;i2++){
354 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
355 }
356 SlideString(basbuf+i2,i-i2);
357
358 //型チェックを厳密に行う
359 bStrict=1;
360 }
361 else if(lstrcmpi(temporary,"struct")==0){
362 //#struct code
363 //旧機能なので、無視
364 for(;;i2++){
365 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
366 }
367 SlideString(basbuf+i2,i-i2);
368 }
369 else if(lstrcmpi(temporary,"resource")==0){
370 //#resource
371 while(basbuf[i2]==' '||basbuf[i2]=='\t') i2++;
372 if(basbuf[i2]!='\"'){
373 SetError(1,NULL,i2);
374 return;
375 }
376 for(i3=0,i2++;;i2++,i3++){
377 if(basbuf[i2]=='\"'){
378 temporary[i3]=0;
379 break;
380 }
381 temporary[i3]=basbuf[i2];
382 }
383 GetFullPath(temporary,BasicCurDir);
384
385 extern char ResourceFileName[MAX_PATH];
386 lstrcpy(ResourceFileName,temporary);
387
388 for(;;i2++){
389 if(basbuf[i2]=='\n'||basbuf[i2]=='\0') break;
390 }
391 SlideString(basbuf+i2,i-i2);
392 }
393 }
394 }
395}
396void NextCommandFormat(char *buffer){
397 int i,i2,i3;
398 char temporary[255];
399
400 //Next命令語のフォーマット
401 for(i=0;;i++){
402 if(buffer[i]=='\n'||buffer[i]==':'||i==0){
403 if(buffer[i]=='\n'||buffer[i]==':') i++;
404 while(buffer[i]==' '||buffer[i]=='\t') i++;
405 while(buffer[i]>='0'&&buffer[i]<='9') i++;
406 while(buffer[i]==' '||buffer[i]=='\t') i++;
407 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')&&
408 (buffer[i+4]==' '||buffer[i+4]=='\t')){
409 i2=i+5;
410 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
411 if(buffer[i2]!='\n'){
412 lstrcpy(temporary,"NEXT");
413 for(i3=0;;i2++){
414 if(buffer[i2]=='\n'||buffer[i2]==':'||buffer[i2]=='\0') break;
415 if(buffer[i2]==','){
416 lstrcat(temporary,":NEXT");
417 i3=1;
418 }
419 }
420 if(i3){
421 i3=lstrlen(temporary);
422 SlideString(buffer+i2,i-i2+i3);
423 memcpy(buffer+i,temporary,i3);
424 }
425 }
426 }
427 }
428 if(buffer[i]=='\0') break;
429 }
430}
431void SetEscapeSequenceFormat(char *buffer){
432 /*「MOD」「AND」「OR」
433 その他制御文字をエスケープシーケンスを使用した記号へ変換 */
434 int i,i2,i3,i4,i5,i6,sw1,IsStr;
435 char *temporary,temp2[VN_SIZE];
436
437 temporary=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,lstrlen(buffer)*2);
438 for(i=0,i2=0,IsStr=0;;i++,i2++){
439 if(buffer[i]=='\"') IsStr^=1;
440 if(buffer[i]=='-'&&buffer[i+1]=='>'&&IsStr==0){
441 buffer[i]=1;
442 buffer[i+1]=ESC_PSMEM;
443 }
444 if(IsVariableChar(buffer[i])&&IsStr==0){
445 i3=i2;
446 for(;;i++,i2++){
447 if(!IsVariableChar(buffer[i])){
448 temporary[i2]=0;
449 break;
450 }
451 temporary[i2]=buffer[i];
452 }
453 if(lstrcmpi(temporary+i3,"End")==0) i6=1;
454 else if(lstrcmpi(temporary+i3,"Exit")==0) i6=2;
455 else if(lstrcmpi(temporary+i3,"Select")==0) i6=3;
456 else if(lstrcmpi(temporary+i3,"Case")==0) i6=4;
457 else if(lstrcmpi(temporary+i3,"Else")==0) i6=5;
458 else i6=0;
459 if(i6){
460 i4=i;
461 while(buffer[i4]==' '||buffer[i4]=='\t') i4++;
462 for(i5=0;;i4++,i5++){
463 if(!IsVariableChar(buffer[i4])){
464 temp2[i5]=0;
465 break;
466 }
467 temp2[i5]=buffer[i4];
468 }
469 sw1=0;
470 if(i6==3){
471 //Select~
472 if(lstrcmpi(temp2,"Case")==0) sw1=1;
473 }
474 else if(i6==4){
475 //Case~
476 if(lstrcmpi(temp2,"Else")==0) sw1=1;
477 }
478 else if(i6==5){
479 //Else If
480 if(lstrcmpi(temp2,"If")==0) sw1=1;
481 }
482 else if(i6==1){
483 //End~
484 switch(temp2[0]){
485 case 'c':
486 case 'C':
487 if(lstrcmpi(temp2,"Class")==0) sw1=1;
488 break;
489 case 'e':
490 case 'E':
491 if(lstrcmpi(temp2,"Enum")==0) sw1=1;
492 break;
493 case 'i':
494 case 'I':
495 if(lstrcmpi(temp2,"If")==0) sw1=1;
496 else if(lstrcmpi(temp2,"Interface")==0) sw1=1;
497 break;
498 case 'f':
499 case 'F':
500 if(lstrcmpi(temp2,"Function")==0) sw1=1;
501 break;
502 case 'm':
503 case 'M':
504 if(lstrcmpi(temp2,"Macro")==0) sw1=1;
505 break;
506 case 's':
507 case 'S':
508 if(lstrcmpi(temp2,"Sub")==0) sw1=1;
509 else if(lstrcmpi(temp2,"Select")==0) sw1=1;
510 break;
511 case 't':
512 case 'T':
513 if(lstrcmpi(temp2,"Type")==0) sw1=1;
514 break;
515 case 'w':
516 case 'W':
517 if(lstrcmpi(temp2,"With")==0) sw1=1;
518 break;
519 }
520 }
521 else if(i6==2){
522 //Exit~
523 if(
524 lstrcmpi(temp2,"For")==0||
525 lstrcmpi(temp2,"While")==0||
526 lstrcmpi(temp2,"Do")==0||
527 lstrcmpi(temp2,"Function")==0||
528 lstrcmpi(temp2,"Sub")==0||
529 lstrcmpi(temp2,"Macro")==0
530 ) sw1=1;
531 }
532
533 if(sw1){
534 i=i4;
535 memcpy(temporary+i2,temp2,i5);
536 i2+=i5;
537 temporary[i2]=0;
538 }
539 }
540 i--;
541 i2--;
542
543 switch(temporary[i3]){
544 case 'a':
545 case 'A':
546 if(lstrcmpi(temporary+i3,"And")==0){
547 i2=i3;
548 temporary[i2++]=1;
549 temporary[i2]=ESC_AND;
550 }
551 else if(lstrcmpi(temporary+i3,"Abstract")==0){
552 i2=i3;
553 temporary[i2++]=1;
554 temporary[i2]=ESC_ABSTRACT;
555 }
556 else if(lstrcmpi(temporary+i3,"As")==0){
557 i2=i3;
558 temporary[i2++]=1;
559 temporary[i2]=ESC_AS;
560 }
561 break;
562 case 'b':
563 case 'B':
564 if(lstrcmpi(temporary+i3,"ByVal")==0){
565 i2=i3;
566 temporary[i2++]=1;
567 temporary[i2]=ESC_BYVAL;
568 }
569 else if(lstrcmpi(temporary+i3,"ByRef")==0){
570 i2=i3;
571 temporary[i2++]=1;
572 temporary[i2]=ESC_BYREF;
573 }
574 break;
575 case 'c':
576 case 'C':
577 if(lstrcmpi(temporary+i3,"Catch")==0){
578 i2=i3;
579 temporary[i2++]=1;
580 temporary[i2]=ESC_CATCH;
581 }
582 else if(lstrcmpi(temporary+i3,"Continue")==0){
583 i2=i3;
584 temporary[i2++]=1;
585 temporary[i2]=ESC_CONTINUE;
586 }
587 else if(lstrcmpi(temporary+i3,"cdecl")==0){
588 i2=i3;
589 temporary[i2++]=1;
590 temporary[i2]=ESC_CDECL;
591 }
592 else if(lstrcmpi(temporary+i3,"Case")==0){
593 i2=i3;
594 temporary[i2++]=1;
595 temporary[i2]=ESC_CASE;
596 }
597 else if(lstrcmpi(temporary+i3,"CaseElse")==0){
598 i2=i3;
599 temporary[i2++]=1;
600 temporary[i2]=ESC_CASEELSE;
601 }
602 else if(lstrcmpi(temporary+i3,"Const")==0){
603 i2=i3;
604 temporary[i2++]=1;
605 temporary[i2]=ESC_CONST;
606 }
607 else if(lstrcmpi(temporary+i3,"Class")==0){
608 i2=i3;
609 temporary[i2++]=1;
610 temporary[i2]=ESC_CLASS;
611 }
612 break;
613 case 'd':
614 case 'D':
615 if(lstrcmpi(temporary+i3,"Declare")==0){
616 i2=i3;
617 int i9=i2;
618 temporary[i2]=1;
619 temporary[++i2]=ESC_DECLARE;
620 i++;
621 while(buffer[i]==' '||buffer[i]=='\t') i++;
622
623 // Sub/Function
624 for(i4=0;;i++,i4++){
625 if(!IsVariableChar(buffer[i])){
626 temp2[i4]=0;
627 break;
628 }
629 temp2[i4]=buffer[i];
630 }
631 if(lstrcmpi(temp2,"Sub")==0) temporary[++i2]=ESC_SUB;
632 else if(lstrcmpi(temp2,"Function")==0) temporary[++i2]=ESC_FUNCTION;
633 while(buffer[i]==' '||buffer[i]=='\t') i++;
634
635 // 関数名
636 for(i2++;;i++,i2++){
637 if(!IsVariableChar(buffer[i])){
638 i2--;
639 break;
640 }
641 temporary[i2]=buffer[i];
642 }
643 while(buffer[i]==' '||buffer[i]=='\t') i++;
644
645 for(i4=0;;i++,i4++){
646 if(!IsVariableChar(buffer[i])){
647 temp2[i4]=0;
648 break;
649 }
650 temp2[i4]=buffer[i];
651 }
652 if(lstrcmpi(temp2,"cdecl")==0){
653 temporary[++i2]=1;
654 temporary[++i2]=ESC_CDECL;
655
656 while(buffer[i]==' '||buffer[i]=='\t') i++;
657 for(i4=0;;i++,i4++){
658 if(!IsVariableChar(buffer[i])){
659 temp2[i4]=0;
660 break;
661 }
662 temp2[i4]=buffer[i];
663 }
664 }
665 if(lstrcmpi(temp2,"Lib")==0) temporary[++i2]=',';
666 while(buffer[i]==' '||buffer[i]=='\t') i++;
667
668 if(buffer[i]=='\"'){
669 temporary[++i2]=buffer[i];
670 for(i++,i2++;;i++,i2++){
671 temporary[i2]=buffer[i];
672 if(buffer[i]=='\"'){
673 i++;
674 break;
675 }
676 if(buffer[i]=='\0') break;
677 }
678 }
679 else{
680 for(i2++;;i++,i2++){
681 if(!IsVariableChar(buffer[i])){
682 i2--;
683 break;
684 }
685 temporary[i2]=buffer[i];
686 }
687 }
688 while(buffer[i]==' '||buffer[i]=='\t') i++;
689
690 temporary[++i2]=',';
691
692 if( memicmp( buffer + i, "Alias", 5 ) ==0 ){
693 i+=5;
694 for(i++,i2++;;i++,i2++){
695 temporary[i2]=buffer[i];
696 if(buffer[i]=='('){
697 i2--;
698 break;
699 }
700 if(buffer[i]=='\0') break;
701 }
702 }
703
704 temporary[++i2]=',';
705
706 i--;
707 }
708 else if(lstrcmpi(temporary+i3,"Def")==0){
709 i2=i3;
710 temporary[i2++]=1;
711 temporary[i2]=ESC_DEF;
712 }
713 break;
714 case 'e':
715 case 'E':
716 if(lstrcmpi(temporary+i3,"ElseIf")==0){
717 i2=i3;
718 temporary[i2++]=1;
719 temporary[i2]=ESC_ELSEIF;
720 }
721 else if(lstrcmpi(temporary+i3,"Else")==0){
722 i2=i3;
723 temporary[i2++]=1;
724 temporary[i2]=ESC_ELSE;
725 }
726 else if(lstrcmpi(temporary+i3,"Export")==0){
727 i2=i3;
728 temporary[i2++]=1;
729 temporary[i2]=ESC_EXPORT;
730 }
731 else if(lstrcmpi(temporary+i3,"Enum")==0){
732 i2=i3;
733 temporary[i2++]=1;
734 temporary[i2]=ESC_ENUM;
735 }
736
737 else if(temporary[i3+1]=='n'||temporary[i3+1]=='N'){
738 //終了記述
739 if(lstrcmpi(temporary+i3,"EndIf")==0){
740 i2=i3;
741 temporary[i2++]=1;
742 temporary[i2]=ESC_ENDIF;
743 }
744 else if(lstrcmpi(temporary+i3,"EndFunction")==0){
745 i2=i3;
746 temporary[i2++]=1;
747 temporary[i2]=ESC_ENDFUNCTION;
748 }
749 else if(lstrcmpi(temporary+i3,"EndSub")==0){
750 i2=i3;
751 temporary[i2++]=1;
752 temporary[i2]=ESC_ENDSUB;
753 }
754 else if(lstrcmpi(temporary+i3,"EndMacro")==0){
755 i2=i3;
756 temporary[i2++]=1;
757 temporary[i2]=ESC_ENDMACRO;
758 }
759 else if(lstrcmpi(temporary+i3,"EndClass")==0){
760 i2=i3;
761 temporary[i2++]=1;
762 temporary[i2]=ESC_ENDCLASS;
763 }
764 else if(lstrcmpi(temporary+i3,"EndInterface")==0){
765 i2=i3;
766 temporary[i2++]=1;
767 temporary[i2]=ESC_ENDINTERFACE;
768 }
769 else if(lstrcmpi(temporary+i3,"EndTry")==0){
770 i2=i3;
771 temporary[i2++]=1;
772 temporary[i2]=ESC_ENDTRY;
773 }
774 else if(lstrcmpi(temporary+i3,"EndType")==0){
775 i2=i3;
776 temporary[i2++]=1;
777 temporary[i2]=ESC_ENDTYPE;
778 }
779 else if(lstrcmpi(temporary+i3,"EndEnum")==0){
780 i2=i3;
781 temporary[i2++]=1;
782 temporary[i2]=ESC_ENDENUM;
783 }
784 else if(lstrcmpi(temporary+i3,"EndSelect")==0){
785 i2=i3;
786 temporary[i2++]=1;
787 temporary[i2]=ESC_ENDSELECT;
788 }
789 else if(lstrcmpi(temporary+i3,"EndWith")==0){
790 i2=i3;
791 temporary[i2++]=1;
792 temporary[i2]=ESC_ENDWITH;
793 }
794 }
795 else if(temporary[i3+1]=='x'||temporary[i3+1]=='X'){
796 if(lstrcmpi(temporary+i3,"ExitFor")==0){
797 i2=i3;
798 temporary[i2++]=1;
799 temporary[i2]=ESC_EXITFOR;
800 }
801 else if(lstrcmpi(temporary+i3,"ExitWhile")==0){
802 i2=i3;
803 temporary[i2++]=1;
804 temporary[i2]=ESC_EXITWHILE;
805 }
806 else if(lstrcmpi(temporary+i3,"ExitDo")==0){
807 i2=i3;
808 temporary[i2++]=1;
809 temporary[i2]=ESC_EXITDO;
810 }
811 else if(lstrcmpi(temporary+i3,"ExitFunction")==0){
812 i2=i3;
813 temporary[i2++]=1;
814 temporary[i2]=ESC_EXITFUNCTION;
815 }
816 else if(lstrcmpi(temporary+i3,"ExitSub")==0){
817 i2=i3;
818 temporary[i2++]=1;
819 temporary[i2]=ESC_EXITSUB;
820 }
821 else if(lstrcmpi(temporary+i3,"ExitMacro")==0){
822 i2=i3;
823 temporary[i2++]=1;
824 temporary[i2]=ESC_EXITMACRO;
825 }
826 }
827 break;
828 case 'f':
829 case 'F':
830 if(lstrcmpi(temporary+i3,"Finally")==0){
831 i2=i3;
832 temporary[i2++]=1;
833 temporary[i2]=ESC_FINALLY;
834 }
835 else if(lstrcmpi(temporary+i3,"Function")==0){
836 i2=i3;
837 temporary[i2++]=1;
838 temporary[i2]=ESC_FUNCTION;
839 }
840 break;
841 case 'i':
842 case 'I':
843 if(lstrcmpi(temporary+i3,"If")==0){
844 i2=i3;
845 temporary[i2++]=1;
846 temporary[i2]=ESC_IF;
847 }
848 else if(lstrcmpi(temporary+i3,"Inherits")==0){
849 i2=i3;
850 temporary[i2++]=1;
851 temporary[i2]=ESC_INHERITS;
852 }
853 else if(lstrcmpi(temporary+i3,"Interface")==0){
854 i2=i3;
855 temporary[i2++]=1;
856 temporary[i2]=ESC_INTERFACE;
857 }
858 break;
859 case 'm':
860 case 'M':
861 if(lstrcmpi(temporary+i3,"Mod")==0){
862 i2=i3;
863 temporary[i2++]=1;
864 temporary[i2]=ESC_MOD;
865 }
866 else if(lstrcmpi(temporary+i3,"Macro")==0){
867 i2=i3;
868 temporary[i2++]=1;
869 temporary[i2]=ESC_MACRO;
870 }
871 break;
872 case 'n':
873 case 'N':
874 if(lstrcmpi(temporary+i3,"New")==0){
875 i2=i3;
876 temporary[i2++]=1;
877 temporary[i2]=ESC_NEW;
878 }
879 else if(lstrcmpi(temporary+i3,"Not")==0){
880 i2=i3;
881 temporary[i2++]=1;
882 temporary[i2]=ESC_NOT;
883 }
884 break;
885 case 'o':
886 case 'O':
887 if(lstrcmpi(temporary+i3,"Or")==0){
888 i2=i3;
889 temporary[i2++]=1;
890 temporary[i2]=ESC_OR;
891 }
892 else if(lstrcmpi(temporary+i3,"Override")==0){
893 i2=i3;
894 temporary[i2++]=1;
895 temporary[i2]=ESC_OVERRIDE;
896 }
897 else if(lstrcmpi(temporary+i3,"Operator")==0){
898 i2=i3;
899 temporary[i2++]=1;
900 temporary[i2]=ESC_OPERATOR;
901 }
902 break;
903 case 's':
904 case 'S':
905 if(lstrcmpi(temporary+i3,"Sub")==0){
906 i2=i3;
907 temporary[i2++]=1;
908 temporary[i2]=ESC_SUB;
909 }
910 else if(lstrcmpi(temporary+i3,"SelectCase")==0){
911 i2=i3;
912 temporary[i2++]=1;
913 temporary[i2]=ESC_SELECTCASE;
914 }
915 else if(lstrcmpi(temporary+i3,"Static")==0){
916 i2=i3;
917 temporary[i2++]=1;
918 temporary[i2]=ESC_STATIC;
919 }
920 break;
921 case 't':
922 case 'T':
923 if(lstrcmpi(temporary+i3,"Then")==0){
924 i2=i3;
925 temporary[i2++]=1;
926 temporary[i2]=ESC_THEN;
927 }
928 else if(lstrcmpi(temporary+i3,"Throw")==0){
929 i2=i3;
930 temporary[i2++]=1;
931 temporary[i2]=ESC_THROW;
932 }
933 else if(lstrcmpi(temporary+i3,"Try")==0){
934 i2=i3;
935 temporary[i2++]=1;
936 temporary[i2]=ESC_TRY;
937 }
938 else if(lstrcmpi(temporary+i3,"Type")==0){
939 i2=i3;
940 temporary[i2++]=1;
941 temporary[i2]=ESC_TYPE;
942 }
943 else if(lstrcmpi(temporary+i3,"TypeDef")==0){
944 i2=i3;
945 temporary[i2++]=1;
946 temporary[i2]=ESC_TYPEDEF;
947 }
948 break;
949 case 'u':
950 case 'U':
951 if(lstrcmpi(temporary+i3,"Using")==0){
952 i2=i3;
953 temporary[i2++]=1;
954 temporary[i2]=ESC_USING;
955 }
956 break;
957 case 'v':
958 case 'V':
959 if(lstrcmpi(temporary+i3,"Virtual")==0){
960 i2=i3;
961 temporary[i2++]=1;
962 temporary[i2]=ESC_VIRTUAL;
963 }
964 break;
965 case 'w':
966 case 'W':
967 if(lstrcmpi(temporary+i3,"With")==0){
968 i2=i3;
969 temporary[i2++]=1;
970 temporary[i2]=ESC_WITH;
971 }
972 break;
973 case 'x':
974 case 'X':
975 if(lstrcmpi(temporary+i3,"Xor")==0){
976 i2=i3;
977 temporary[i2++]=1;
978 temporary[i2]=ESC_XOR;
979 }
980 break;
981 }
982
983 continue;
984 }
985 temporary[i2]=buffer[i];
986 if(buffer[i]=='\0') break;
987 }
988 lstrcpy(buffer,temporary);
989 HeapDefaultFree(temporary);
990}
991void DefCommandFormat(char *buffer){
992 int i,i2,PareNum;
993 char temporary[255];
994
995 //Def命令語からFunction命令語へ
996 for(i=0;;i++){
997 if(buffer[i]==1&&buffer[i+1]==ESC_DEF){
998 buffer[i+1]=ESC_FUNCTION;
999 i+=2;
1000 while(buffer[i]==' '||buffer[i]=='\t') i++;
1001 for(i2=0;;i++,i2++){
1002 if(!IsVariableChar(buffer[i])){
1003 temporary[i2]=0;
1004 break;
1005 }
1006 temporary[i2]=buffer[i];
1007 }
1008 while(buffer[i]==' '||buffer[i]=='\t') i++;
1009 if(buffer[i]!='('){
1010 SetError(1,NULL,i);
1011 return;
1012 }
1013 i++;
1014 while(1){
1015 while(buffer[i]==' '||buffer[i]=='\t') i++;
1016 if(buffer[i]==')') break;
1017 SlideString(buffer+i,2);
1018 buffer[i]=1;
1019 buffer[i+1]=ESC_BYVAL;
1020 i+=2;
1021 PareNum=0;
1022 for(;;i++){
1023 if(buffer[i]=='(') PareNum++;
1024 if(buffer[i]==')'){
1025 PareNum--;
1026 if(PareNum<0) break;
1027 }
1028 if(buffer[i]==','&&PareNum==0) break;
1029 }
1030 if(buffer[i]==')') break;
1031 i++;
1032 }
1033 i++;
1034 while(buffer[i]==' '||buffer[i]=='\t') i++;
1035 if(buffer[i]!='='){
1036 SetError(1,NULL,i);
1037 break;
1038 }
1039 i2=lstrlen(temporary);
1040 SlideString(buffer+i,i2+1);
1041 buffer[i]=':';
1042 i++;
1043 memcpy(buffer+i,temporary,i2);
1044 i+=i2;
1045 while(!IsCommandDelimitation(buffer[i])) i++;
1046 SlideString(buffer+i,3);
1047 buffer[i]=':';
1048 buffer[i+1]=1;
1049 buffer[i+2]=ESC_ENDFUNCTION;
1050 }
1051 if(buffer[i]=='\0') break;
1052 }
1053}
1054
1055void ChangeOneIf(char *write,int &wp,char *read,int &rp){
1056 int IsStr,sw;
1057
1058 //ブロック形式でないときはThenの後に区切り文字を入れる
1059 for(IsStr=0,sw=0;;wp++,rp++){
1060 if(read[rp]=='\"') IsStr^=1;
1061
1062 write[wp]=read[rp];
1063
1064 if(IsCommandDelimitation(read[rp])&&IsStr==0) return;
1065 if(read[rp]==1&&read[rp+1]==ESC_THEN&&
1066 (read[rp+2]==' '||read[rp+2]=='\t')){
1067 write[wp+1]=read[rp+1];
1068 write[wp+2]=':';
1069 rp+=3;
1070 wp+=3;
1071 while(read[rp]==' '||read[rp]=='\t') rp++;
1072 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1073 memcpy(write+wp,"Goto ",5);
1074 wp+=5;
1075 }
1076 break;
1077 }
1078 }
1079
1080 //Elseの後に区切り文字を入れる
1081 for(IsStr=0;;wp++,rp++){
1082 if(read[rp]=='\"') IsStr^=1;
1083
1084 write[wp]=read[rp];
1085
1086 if(read[rp]=='\n'||read[rp]=='\0') break;
1087 if(read[rp]==1&&read[rp+1]==ESC_IF){
1088 write[wp+1]=read[rp+1];
1089 wp+=2;
1090 rp+=2;
1091 ChangeOneIf(write,wp,read,rp);
1092 wp--;
1093 rp--;
1094 continue;
1095 }
1096 if(read[rp]==1&&read[rp+1]==ESC_ELSE){
1097 write[wp++]=':';
1098
1099 write[wp]=read[rp];
1100 write[wp+1]=read[rp+1];
1101 wp+=2;
1102 rp+=2;
1103
1104 write[wp++]=':';
1105
1106 while(read[rp]==' '||read[rp]=='\t') rp++;
1107 if((read[rp]>='0'&&read[rp]<='9')||read[rp]=='*'){
1108 memcpy(write+wp,"Goto ",5);
1109 wp+=5;
1110 }
1111 break;
1112 }
1113 }
1114
1115 //"End If" を付加
1116 for(;;rp++,wp++){
1117 if(read[rp]=='\n'||read[rp]=='\0') break;
1118
1119 if(read[rp]==1&&read[rp+1]==ESC_IF){
1120 write[wp+1]=read[rp+1];
1121 wp+=2;
1122 rp+=2;
1123 ChangeOneIf(write,wp,read,rp);
1124 wp--;
1125 rp--;
1126 continue;
1127 }
1128 if(read[rp]==1&&read[rp+1]==ESC_ELSE) break;
1129
1130 write[wp]=read[rp];
1131 }
1132 write[wp]=':';
1133 write[wp+1]=1;
1134 write[wp+2]=ESC_ENDIF;
1135 wp+=3;
1136}
1137void OutsideIfFormat(char *write,int &wp,char *read,int &rp){
1138 int ElseCount=1;
1139
1140 for(;;rp++,wp++){
1141 if(read[rp]==1){
1142 if(read[rp+1]==ESC_IF){
1143 write[wp++]=read[rp++];
1144 write[wp++]=read[rp++];
1145 OutsideIfFormat(write,wp,read,rp);
1146 wp--,rp--;
1147 continue;
1148 }
1149 if(read[rp+1]==ESC_ENDIF){
1150 for(;ElseCount>0;wp+=3,ElseCount--){
1151 write[wp]=1;
1152 write[wp+1]=ESC_ENDIF;
1153 write[wp+2]=':';
1154 }
1155 rp+=2;
1156 break;
1157 }
1158 if(read[rp+1]==ESC_ELSEIF){
1159 write[wp]=1;
1160 write[wp+1]=ESC_ELSE;
1161 write[wp+2]=':';
1162
1163 write[wp+3]=1;
1164 write[wp+4]=ESC_IF;
1165
1166 wp+=4;
1167 rp++;
1168
1169 ElseCount++;
1170 continue;
1171 }
1172 }
1173
1174 write[wp]=read[rp];
1175 if(read[rp]=='\0') break;
1176 }
1177}
1178void IfCommandFormat(char *buffer){
1179 int i,i2;
1180
1181 char *temporary;
1182 temporary=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)*2+1024);
1183
1184 //1行Ifをブロック形式にする
1185 for(i=0,i2=0;;i++,i2++){
1186 if(buffer[i]==1&&buffer[i+1]==ESC_IF){
1187 temporary[i2++]=buffer[i++];
1188 temporary[i2++]=buffer[i++];
1189 ChangeOneIf(temporary,i2,buffer,i);
1190 i2--,i--;
1191 continue;
1192 }
1193
1194 temporary[i2]=buffer[i];
1195 if(buffer[i]=='\0') break;
1196 }
1197
1198 //ElseIfを入れ子構造に変更する
1199 for(i=0,i2=0;;i++,i2++){
1200 if(temporary[i]==1&&temporary[i+1]==ESC_IF){
1201 buffer[i2++]=temporary[i++];
1202 buffer[i2++]=temporary[i++];
1203 OutsideIfFormat(buffer,i2,temporary,i);
1204 i2--,i--;
1205 continue;
1206 }
1207
1208 buffer[i2]=temporary[i];
1209 if(temporary[i]=='\0') break;
1210 }
1211
1212 HeapDefaultFree(temporary);
1213}
1214void CheckPareCommand(void){
1215 extern char *basbuf;
1216 int i2,i3;
1217
1218 int FuncNum=0;
1219 int FuncType=0;
1220 int FuncPtr=-1;
1221 for(i2=0;;i2++){
1222 if(basbuf[i2]=='\0') break;
1223 if(IsCommandDelimitation(basbuf[i2])){
1224 if(basbuf[i2+1]==1){
1225 i2++;
1226 switch(basbuf[i2+1]){
1227 case ESC_FUNCTION:
1228 case ESC_SUB:
1229 case ESC_MACRO:
1230 if(FuncNum!=0){
1231 if(FuncType==ESC_FUNCTION)
1232 SetError(54,"End Function",FuncPtr);
1233 else if(FuncType==ESC_SUB)
1234 SetError(54,"End Sub",FuncPtr);
1235 else if(FuncType==ESC_MACRO)
1236 SetError(54,"End Macro",FuncPtr);
1237 return;
1238 }
1239 FuncType=basbuf[i2+1];
1240 FuncNum++;
1241 FuncPtr=i2;
1242 break;
1243 case ESC_ENDFUNCTION:
1244 case ESC_ENDSUB:
1245 case ESC_ENDMACRO:
1246 if(basbuf[i2+1]==ESC_ENDFUNCTION) i3=ESC_FUNCTION;
1247 else if(basbuf[i2+1]==ESC_ENDSUB) i3=ESC_SUB;
1248 else if(basbuf[i2+1]==ESC_ENDMACRO) i3=ESC_MACRO;
1249
1250 FuncNum--;
1251
1252 if(FuncNum!=0||i3!=FuncType){
1253 if(basbuf[i2+1]==ESC_ENDFUNCTION)
1254 SetError(12,"End Function",i2);
1255 else if(basbuf[i2+1]==ESC_ENDSUB)
1256 SetError(12,"End Sub",i2);
1257 else if(basbuf[i2+1]==ESC_ENDMACRO)
1258 SetError(12,"End Macro",i2);
1259 return;
1260 }
1261 break;
1262 }
1263 }
1264
1265
1266 }
1267 }
1268}
Note: See TracBrowser for help on using the repository browser.