source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/Intermediate_Step1.cpp@ 724

Last change on this file since 724 was 465, checked in by dai_9181, 17 years ago

Messenger/ErrorMessengerクラスを導入。SetError関数によるエラー生成を廃止した。

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