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

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

例外処理機構実装中...

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