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

Last change on this file since 218 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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