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

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