source: dev/trunk/abdev/BasicCompiler_Common/Intermediate_Step1.cpp@ 159

Last change on this file since 159 was 112, checked in by dai_9181, 18 years ago

#_fullcompileディレクティブを導入。
rev.234を刻印した。

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