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

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