source: dev/BasicCompiler_Common/Intermediate_Step1.cpp@ 110

Last change on this file since 110 was 107, checked in by dai_9181, 18 years ago

Importsステートメントを導入した。実装は作り途中。

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