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

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

コンパイラ組み込みテンプレートエンジンを実装。
静的リンクライブラリ、デバッグ情報の内部形式をテキストからバイナリに変更した。

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