source: dev/BasicCompiler_Common/Intermediate_Step1.cpp@ 98

Last change on this file since 98 was 96, checked in by dai_9181, 18 years ago

不要なソースコード(TODO: 消す)を削除

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