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

Last change on this file since 411 was 402, checked in by dai_9181, 17 years ago

UserProc::SetParamsAndReturnTypeメソッドをリファクタリング
LexicalAnalysis.hのインクルードを除去した

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