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

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