source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp@ 648

Last change on this file since 648 was 641, checked in by dai_9181, 16 years ago

・デバッグトレース時、グローバル領域の終端行でステップインまたはステップアウトしたときにデバッグ情報の取得に失敗して強制終了してしまう不具合を修正。
・グローバル領域のデバッグ実行ができなくなっている不具合を修正。

File size: 21.5 KB
Line 
1#include "stdafx.h"
2
3using namespace ActiveBasic::Compiler;
4
5bool LexicalAnalyzer::AnalyzeParameter( Parameters &params, const Jenga::Common::Strings &parameterStrings, int nowLine )
6{
7 int i2,i3,sw;
8 char temporary[8192],temp2[VN_SIZE];
9
10 //パラメータ
11 BOOST_FOREACH( const std::string &paramStr, parameterStrings )
12 {
13 int i = 0;
14
15 if( paramStr[i] == '\0' )
16 {
17 break;
18 }
19
20 //ByRef
21 bool isRef;
22 if(paramStr[i]==1&&paramStr[i+1]==ESC_BYVAL){
23 isRef = false;
24 i+=2;
25 }
26 else if(paramStr[i]==1&&paramStr[i+1]==ESC_BYREF){
27 isRef = true;
28 i+=2;
29 }
30 else isRef = false;
31
32 //パラメータ名
33 bool isArray = false;
34 Subscripts subscripts;
35 char name[VN_SIZE];
36 sw=0;
37 for(i2=0;;i++,i2++){
38 if(paramStr[i]=='('){
39 if(!sw) sw=1;
40
41 i3=GetStringInPare(name+i2,paramStr.c_str()+i);
42 i2+=i3-1;
43 i+=i3-1;
44 continue;
45 }
46 if(paramStr[i]=='['){
47 if(!sw) sw=1;
48
49 i3=GetStringInBracket(name+i2,paramStr.c_str()+i);
50 i2+=i3-1;
51 i+=i3-1;
52 continue;
53 }
54 if(!IsVariableChar(paramStr[i])){
55 name[i2]=0;
56 break;
57 }
58 name[i2]=paramStr[i];
59 }
60 if(sw){
61 //配列パラメータ
62 if( isRef == false )
63 {
64 compiler.errorMessenger.Output(29,NULL,nowLine);
65 }
66 isArray = true;
67
68 if((name[i2-2]=='('&&name[i2-1]==')')||
69 (name[i2-2]=='['&&name[i2-1]==']'))
70 {
71 subscripts.push_back( LONG_MAX );
72
73 name[i2-2]=0;
74 }
75 else{
76 GetArrange(name,temp2,subscripts);
77 lstrcpy(name,temp2);
78 }
79
80 i2=lstrlen(name);
81 }
82
83 Type type( DEF_NON );
84 char initValue[8192] = "";
85 if( paramStr[i] == '=' ){
86 i++;
87 i = GetOneParameter( paramStr.c_str(), i, initValue );
88
89 // TODO: エラー用 fix me!!!
90 //cp = nowLine;
91
92 NumOpe_GetType( initValue, GetStringTypeInfo(), type );
93
94 if( IS_LITERAL(type.GetIndex()) )
95 {
96 type.SetIndex( -1 );
97 }
98 }
99 else if(paramStr[i]==1&&paramStr[i+1]==ESC_AS){
100 // As指定
101 i+=2;
102
103 i2=0;
104 while(paramStr[i]=='*'){
105 temporary[i2]=paramStr[i];
106 i++;
107 i2++;
108 }
109 for(;;i++,i2++){
110 if(!IsVariableChar(paramStr[i])){
111 if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){
112 temporary[i2++]=paramStr[i++];
113 temporary[i2]=paramStr[i];
114 continue;
115 }
116 temporary[i2]=0;
117 break;
118 }
119 temporary[i2]=paramStr[i];
120 }
121
122 compiler.StringToType( temporary, type );
123
124 if( type.IsNull() ){
125 compiler.errorMessenger.Output(3,temporary,nowLine);
126 type.SetBasicType( DEF_PTR_VOID );
127 }
128
129 if( type.IsObject() ){
130 if( type.GetClass().IsBlittableType() ){
131 // Blittable型のときは基本型として扱う
132 type = type.GetClass().GetBlittableType();
133 }
134 }
135 }
136 else{
137 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
138 compiler.errorMessenger.Output(-103,temporary,nowLine);
139 }
140
141 Parameter *pParam = new Parameter( name, type, isRef, initValue );
142 if( isArray ){
143 pParam->SetArray( subscripts );
144 }
145
146 //パラメータを追加
147 params.push_back( pParam );
148 }
149
150 return true;
151}
152
153bool LexicalAnalyzer::SetParamsAndReturnTypeForUserProc( UserProc &userProc, const char *sourceOfParams, int nowLine, bool isStatic )
154{
155 int i = 0;
156
157 //ソースコードの位置
158 userProc.SetSourceCodePosition( SourceCodePosition( compiler.GetCurrentRelationalObjectModuleIndexForSource(), nowLine ) );
159
160 //パラメータ
161 if(sourceOfParams[i]!='('){
162 compiler.errorMessenger.Output(1,NULL,nowLine);
163 return false;
164 }
165 if(sourceOfParams[i + 1]!=')'&& userProc.HasParentClass() ){
166 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
167 if(userProc.GetName()[0]=='~'){
168 compiler.errorMessenger.Output(114,NULL,nowLine);
169 return false;
170 }
171 }
172
173 // カッコ内のパラメータ文字列を取得
174 char parametersStr1[8192];
175 char parametersStr2[8192] = "";
176 i += GetStringInPare( parametersStr1, sourceOfParams + i, true );
177 if( sourceOfParams[i] == '(' )
178 {
179 i += GetStringInPare( parametersStr2, sourceOfParams + i, true );
180 }
181
182 // 戻り値文字列を取得
183 char returnTypeStr[VN_SIZE] = "";
184 if( sourceOfParams[i] )
185 {
186 if( sourceOfParams[i] == 1 && sourceOfParams[i+1] == ESC_AS )
187 {
188 if( !userProc.IsFunction() ){
189 // Sub/Macroの場合
190 compiler.errorMessenger.Output(38,userProc.GetName(),nowLine);
191 }
192
193 lstrcpy( returnTypeStr, sourceOfParams + i + 2 );
194 }
195 else
196 {
197 compiler.errorMessenger.Output(1,NULL,nowLine);
198 return false;
199 }
200 }
201
202 Jenga::Common::Strings parameters;
203
204 // パラメータ
205 SplitParameter( parametersStr1, parameters );
206 ActiveBasic::Compiler::LexicalAnalyzer::AnalyzeParameter( userProc.GetParameters(), parameters, nowLine );
207
208 // 省略可能パラメータ(古い仕様。非推奨)
209 userProc.SetSecondParmNum( (int)userProc.GetParameters().size() );
210 SplitParameter( parametersStr2, parameters );
211 ActiveBasic::Compiler::LexicalAnalyzer::AnalyzeParameter( userProc.GetParameters(), parameters, nowLine );
212
213
214 if(returnTypeStr[0]){
215 ///////////////////
216 // 戻り値を取得
217 ///////////////////
218
219 if( !userProc.IsFunction() ){
220 // Sub/Macroの場合
221 compiler.errorMessenger.Output(38,userProc.GetName(),nowLine);
222 }
223
224 if( userProc.HasParentClass() ){
225 if( userProc.GetName() == userProc.GetParentClassPtr()->GetName() ||
226 userProc.GetName()[0]=='~'){
227 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
228 compiler.errorMessenger.Output(115,NULL,nowLine);
229 }
230 }
231
232 compiler.StringToType( returnTypeStr, userProc.ReturnType() );
233 if( userProc.ReturnType().IsNull() )
234 {
235 compiler.errorMessenger.Output(3,returnTypeStr,nowLine);
236 }
237 }
238 else{
239 if( userProc.IsFunction() )
240 {
241 // Function定義なのに、戻り値の型がセットされていない
242 compiler.errorMessenger.Output(-104,userProc.GetName().c_str(),nowLine);
243
244 userProc.ReturnType().SetBasicType( DEF_DOUBLE );
245 }
246 else
247 {
248 //戻り値なしのSub定義
249 userProc.ReturnType().SetNull();
250 }
251 }
252
253 //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する場合がある)
254
255 if( userProc.HasParentClass() && isStatic == false ){
256 //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用
257 std::string name = "_System_LocalThis";
258 Type type( DEF_PTR_VOID );
259 userProc.RealParams().push_back( new Parameter( name, type ) );
260 }
261
262 if( userProc.ReturnType().IsStruct() ){
263 //構造体を戻り値として持つ場合
264 //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする
265
266 std::string name = userProc.GetName();
267 if(name[0]==1&&name[1]==ESC_OPERATOR){
268 name="_System_ReturnValue";
269 }
270 Type type( DEF_STRUCT, userProc.ReturnType().GetIndex() );
271 userProc.RealParams().push_back( new Parameter( name, type, true ) );
272 }
273
274 //パラメータをコピー
275 BOOST_FOREACH( Parameter *pParam, userProc.GetParameters() ){
276 userProc.RealParams().push_back( new Parameter( *pParam ) );
277 }
278
279 return true;
280}
281
282bool LexicalAnalyzer::SetParamsAndReturnType( Procedure *pProc, const char *sourceOfParams, bool isSupportEllipse, int nowLine ){
283 int i = 0;
284 int i2,i3,sw;
285 char temporary[8192],temp2[VN_SIZE];
286
287 //ソースコードの位置
288 pProc->SetSourceCodePosition( SourceCodePosition( compiler.GetCurrentRelationalObjectModuleIndexForSource(), nowLine ) );
289
290 //パラメータ
291 if(sourceOfParams[i]!='('){
292 compiler.errorMessenger.Output(1,NULL,nowLine);
293 return 0;
294 }
295 i++;
296 while(1){
297 if(sourceOfParams[i]==')') break;
298
299 //ByRef
300 bool isRef;
301 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
302 isRef = false;
303 i+=2;
304 }
305 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
306 isRef = true;
307 i+=2;
308 }
309 else isRef = false;
310
311 //パラメータ名
312 bool isArray = false;
313 Subscripts subscripts;
314 char name[VN_SIZE];
315 sw=0;
316 for(i2=0;;i++,i2++){
317 if(sourceOfParams[i]=='('){
318 if(!sw) sw=1;
319
320 i3=GetStringInPare(name+i2,sourceOfParams+i);
321 i2+=i3-1;
322 i+=i3-1;
323 continue;
324 }
325 if(sourceOfParams[i]=='['){
326 if(!sw) sw=1;
327
328 i3=GetStringInBracket(name+i2,sourceOfParams+i);
329 i2+=i3-1;
330 i+=i3-1;
331 continue;
332 }
333 if(!IsVariableChar(sourceOfParams[i])){
334 name[i2]=0;
335 break;
336 }
337 name[i2]=sourceOfParams[i];
338 }
339 if(sw){
340 //配列パラメータ
341 if( isRef == false ) compiler.errorMessenger.Output(29,NULL,nowLine);
342 isArray = true;
343
344 if((name[i2-2]=='('&&name[i2-1]==')')||
345 (name[i2-2]=='['&&name[i2-1]==']'))
346 {
347 subscripts.push_back( LONG_MAX );
348
349 name[i2-2]=0;
350 }
351 else{
352 GetArrange(name,temp2,subscripts);
353 lstrcpy(name,temp2);
354 }
355
356 i2=lstrlen(name);
357 }
358
359 //型
360 Type type( DEF_NON );
361 if( isSupportEllipse && lstrcmp(name,"...")==0 )
362 {
363 type.SetBasicType( DEF_ELLIPSE );
364 }
365 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS)
366 {
367 i+=2;
368
369 i2=0;
370 while(sourceOfParams[i]=='*'){
371 temporary[i2]=sourceOfParams[i];
372 i++;
373 i2++;
374 }
375 for(;;i++,i2++){
376 if(!IsVariableChar(sourceOfParams[i])){
377 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
378 temporary[i2++]=sourceOfParams[i++];
379 temporary[i2]=sourceOfParams[i];
380 continue;
381 }
382 temporary[i2]=0;
383 break;
384 }
385 temporary[i2]=sourceOfParams[i];
386 }
387
388 compiler.StringToType( temporary, type );
389
390 if( type.IsNull() ){
391 compiler.errorMessenger.Output(3,temporary,nowLine);
392 type.SetBasicType( DEF_PTR_VOID );
393 }
394 }
395 else{
396 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
397 compiler.errorMessenger.Output(-103,temporary,nowLine);
398 }
399
400 Parameter *pParam = new Parameter( name, type, isRef );
401 if( isArray ){
402 pParam->SetArray( subscripts );
403 }
404
405 //パラメータを追加
406 pProc->GetParameters().push_back( pParam );
407
408 if(sourceOfParams[i]==','){
409 i++;
410 continue;
411 }
412 else if(sourceOfParams[i]==')') continue;
413 else{
414 compiler.errorMessenger.Output(1,NULL,nowLine);
415 break;
416 }
417 }
418 i++;
419
420 if(sourceOfParams[i]){
421 ///////////////////
422 // 戻り値を取得
423 ///////////////////
424
425 i2=lstrlen(sourceOfParams)-2;
426
427 int sw_as=0;
428 for(;i2>0;i2--){
429 if(sourceOfParams[i2]==')') break;
430
431 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){
432 i2+=2;
433 i3=0;
434 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];
435 for(;;i2++,i3++){
436 if(!IsVariableChar(sourceOfParams[i2])){
437 temporary[i3]=0;
438 break;
439 }
440 temporary[i3]=sourceOfParams[i2];
441 }
442 compiler.StringToType( temporary, pProc->ReturnType() );
443 if( pProc->ReturnType().IsNull() ) compiler.errorMessenger.Output(3,temporary,nowLine);
444
445 sw_as=1;
446 break;
447 }
448 }
449 }
450 else{
451 //戻り値なしのSub定義
452 pProc->ReturnType().SetNull();
453 }
454
455 //戻り値のエラーチェック
456 if( pProc->IsFunction() ){
457 // Function定義
458
459 if( pProc->ReturnType().IsNull() ){
460 // 戻り値がない
461 compiler.errorMessenger.Output(26,pProc->GetName(),nowLine);
462 }
463 }
464 else{
465 if( !pProc->ReturnType().IsNull() ){
466 // Sub定義なのに、戻り値がある
467 compiler.errorMessenger.Output(38,pProc->GetName(),nowLine);
468 }
469 }
470
471 return true;
472}
473
474UserProc* LexicalAnalyzer::ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName )
475{
476 int i2,i3;
477 char temporary[8192];
478
479 int i=1;
480
481 Procedure::Kind kind = Procedure::Sub;
482 bool isMacro = false;
483 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function;
484 if(buffer[i]==ESC_MACRO){
485 isMacro = true;
486 }
487
488 i++;
489
490 bool isCdecl = false;
491 bool isExport = false;
492 while(1){
493 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){
494 isCdecl = true;
495
496 i+=2;
497 }
498 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){
499 isExport = true;
500
501 i+=2;
502 }
503 else break;
504 }
505
506 i2=0;
507 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
508 if(!pobj_c){
509 compiler.errorMessenger.Output(126,NULL,nowLine);
510 return 0;
511 }
512
513 //オペレータの場合
514 temporary[i2++]=buffer[i++];
515 temporary[i2++]=buffer[i++];
516
517 int iCalcId;
518 if(buffer[i]=='='&&buffer[i+1]=='='){
519 iCalcId=CALC_EQUAL;
520 i3=2;
521 }
522 else if(buffer[i]=='='){
523 iCalcId=CALC_SUBSITUATION;
524 i3=1;
525 }
526 else if(buffer[i]=='('){
527 iCalcId=CALC_AS;
528 i3=0;
529 }
530 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){
531 iCalcId=CALC_ARRAY_SET;
532 i3=3;
533 }
534 else if(buffer[i]=='['&&buffer[i+1]==']'){
535 iCalcId=CALC_ARRAY_GET;
536 i3=2;
537 }
538 else{
539 iCalcId=GetCalcId(buffer+i,&i3);
540 i3++;
541 }
542 if(!iCalcId){
543 compiler.errorMessenger.Output(1,NULL,nowLine);
544 return 0;
545 }
546 temporary[i2++]=iCalcId;
547 temporary[i2]=0;
548
549 i+=i3;
550 }
551 else{
552 if(pobj_c){
553 //クラスメンバの場合、デストラクタには~が付くことを考慮
554 if(buffer[i]=='~'){
555 temporary[i2]='~';
556 i++;
557 i2++;
558 }
559 }
560
561 for(;;i++,i2++){
562 if(!IsVariableChar(buffer[i])){
563 temporary[i2]=0;
564 break;
565 }
566 temporary[i2]=buffer[i];
567 }
568
569 char parentName[VN_SIZE], memberName[VN_SIZE];
570 ReferenceKind refKind;
571 if( SplitMemberName( temporary, parentName, memberName, refKind ) )
572 {
573 if( pobj_c )
574 {
575 if( interfaceName )
576 {
577 lstrcpy( interfaceName, parentName );
578 }
579 else
580 {
581 compiler.errorMessenger.OutputFatalError();
582 return NULL;
583 }
584
585 char dummyMemberName[VN_SIZE];
586 if( SplitMemberName( memberName, parentName, dummyMemberName, refKind ) )
587 {
588 compiler.errorMessenger.Output(69,temporary,nowLine);
589 return NULL;
590 }
591 }
592 else
593 {
594 compiler.errorMessenger.Output(68,temporary,nowLine);
595 return NULL;
596 }
597
598 lstrcpy( temporary, memberName );
599 }
600 }
601
602 if( isMacro ){
603 //大文字に変換
604 CharUpper(temporary);
605 }
606
607 if(!pobj_c){
608 //クラスメンバ以外の場合のみ
609 //重複チェック
610
611 if(GetDeclareHash(temporary)){
612 compiler.errorMessenger.Output(15,temporary,nowLine);
613 return 0;
614 }
615 }
616
617 UserProc *pUserProc = new UserProc( Symbol( namespaceScopes, temporary ), importedNamespaces, kind, isMacro, isCdecl, isExport );
618 pUserProc->SetParentClass( pobj_c );
619
620 // 親インターフェイスをセット
621 if( interfaceName && interfaceName[0] )
622 {
623 ::Interface *pTargetInterface = NULL;
624 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )
625 {
626 if( pInterface->GetClass().GetName() == interfaceName )
627 {
628 pTargetInterface = pInterface;
629 break;
630 }
631 }
632 pUserProc->SetInterface( pTargetInterface );
633 }
634
635 if(isExport){
636 pUserProc->Using();
637 }
638
639 // パラメータを解析
640 // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
641 SetParamsAndReturnTypeForUserProc( *pUserProc, buffer + i, nowLine, isStatic );
642
643 pUserProc->_paramStr = buffer + i;
644
645 return pUserProc;
646}
647
648DllProc *LexicalAnalyzer::ParseDllProc(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine)
649{
650 int i2;
651
652 int i=0;
653
654 //Sub/Function
655 Procedure::Kind kind = Procedure::Sub;
656 if(buffer[i]==ESC_SUB){
657 }
658 else if(buffer[i]==ESC_FUNCTION){
659 kind = Procedure::Function;
660 }
661 else{
662 compiler.errorMessenger.Output(1,NULL,nowLine);
663 return NULL;
664 }
665 i++;
666
667 //プロシージャ名
668 char procName[VN_SIZE];
669 bool isCdecl = false;
670 for(i2=0;;i++,i2++){
671 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL){
672 isCdecl = true;
673
674 i+=2;
675 procName[i2]=0;
676 break;
677 }
678 if(buffer[i]==','){
679 procName[i2]=0;
680 break;
681 }
682 if(buffer[i]=='\0'){
683 compiler.errorMessenger.Output(1,NULL,nowLine);
684 return NULL;
685 }
686 procName[i2]=buffer[i];
687 }
688 i++;
689
690 //ユーザー定義関数との重複チェック
691 if(GetSubHash(procName)){
692 compiler.errorMessenger.Output(15,procName,nowLine);
693 return NULL;
694 }
695
696
697 //ライブラリ
698 char dllFileName[MAX_PATH];
699 i = GetOneParameter( buffer, i, dllFileName );
700 Type resultType;
701 _int64 i64data;
702 if( !StaticCalculation( true, dllFileName, 0, &i64data, resultType ) ){
703 return NULL;
704 }
705 if( resultType.GetBasicType() != typeOfPtrChar ){
706 compiler.errorMessenger.Output(1,NULL,nowLine);
707 return NULL;
708 }
709 lstrcpy( dllFileName, (char *)i64data );
710 CharUpper(dllFileName);
711 if(!strstr(dllFileName,".")){
712 lstrcat(dllFileName,".DLL");
713 if(lstrlen(dllFileName)>=16){
714 compiler.errorMessenger.Output(7,NULL,nowLine);
715 return NULL;
716 }
717 }
718
719 //エイリアス
720 char alias[VN_SIZE];
721 i = GetOneParameter( buffer, i, alias );
722 if( alias[0] ){
723 if( !StaticCalculation( true, alias, 0, &i64data, resultType ) ){
724 return NULL;
725 }
726 if( resultType.GetBasicType() != typeOfPtrChar ){
727 compiler.errorMessenger.Output(1,NULL,nowLine);
728 return NULL;
729 }
730 lstrcpy( alias, (char *)i64data );
731 }
732 else{
733 //省略されたときは関数名
734 lstrcpy( alias, procName );
735 }
736
737
738 // オブジェクトを生成
739 DllProc *pDllProc = new DllProc( Symbol( namespaceScopes, procName ), kind, isCdecl, dllFileName, alias );
740
741 // パラメータを解析
742 // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
743 LexicalAnalyzer::SetParamsAndReturnType( pDllProc, buffer + i, true, nowLine );
744
745 // パラメータのエラーチェック
746 BOOST_FOREACH( const Parameter *pParam, pDllProc->Params() ){
747 if( pParam->IsObject() ){
748 compiler.errorMessenger.Output(25,pParam->GetVarName(),nowLine);
749 }
750 if( !pParam->IsRef() ){
751 if( pParam->IsStruct() ){
752 compiler.errorMessenger.Output(28,pParam->GetVarName(),nowLine);
753 }
754 }
755 }
756
757 //戻り値のエラーチェック
758 if( pDllProc->IsFunction() ){
759 // Function定義
760
761 if( pDllProc->ReturnType().IsObject() ){
762 // DLL関数ではオブジェクトを戻り値にできない
763 compiler.errorMessenger.Output(40,pDllProc->GetName(),nowLine);
764 }
765 }
766
767 return pDllProc;
768}
769
770void LexicalAnalyzer::CollectProcedures( const char *source, UserProcs &userProcs, DllProcs &dllProcs )
771{
772 extern HANDLE hHeap;
773 int i,i2,i3;
774 char temporary[8192];
775
776 // 名前空間管理
777 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
778 namespaceScopes.clear();
779
780 // Importsされた名前空間の管理
781 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
782 importedNamespaces.clear();
783
784 i=-1;
785 while(1){
786 i++;
787
788 if(source[i]==1&&(source[i+1]==ESC_CLASS||source[i+1]==ESC_INTERFACE)){
789 /* Class ~ End Class
790 Interface ~ End Interface
791 を飛び越す */
792 i3=GetEndXXXCommand(source[i+1]);
793 for(i+=2,i2=0;;i++,i2++){
794 if(source[i]=='\0') break;
795 if(source[i]==1&&source[i+1]==(char)i3){
796 i++;
797 break;
798 }
799 }
800 if(source[i]=='\0') break;
801 continue;
802 }
803
804 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
805 for(i+=2,i2=0;;i2++,i++){
806 if( IsCommandDelimitation( source[i] ) ){
807 temporary[i2]=0;
808 break;
809 }
810 temporary[i2]=source[i];
811 }
812 namespaceScopes.push_back( temporary );
813
814 continue;
815 }
816 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
817 if( namespaceScopes.size() <= 0 ){
818 compiler.errorMessenger.Output(12, "End Namespace", i );
819 }
820 else{
821 namespaceScopes.pop_back();
822 }
823
824 i += 2;
825 continue;
826 }
827 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
828 for(i+=2,i2=0;;i2++,i++){
829 if( IsCommandDelimitation( source[i] ) ){
830 temporary[i2]=0;
831 break;
832 }
833 temporary[i2]=source[i];
834 }
835 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
836 {
837 compiler.errorMessenger.Output(64,temporary,cp );
838 }
839
840 continue;
841 }
842 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
843 importedNamespaces.clear();
844 continue;
845 }
846
847 if(source[i]==1&&source[i+1]==ESC_DECLARE){
848 for(i+=2,i2=0;;i2++,i++){
849 if(source[i]=='\n'){
850 temporary[i2]=0;
851 break;
852 }
853 temporary[i2]=source[i];
854 if(source[i]=='\0') break;
855 }
856 DllProc *pDllProc = ParseDllProc( namespaceScopes, temporary, i );
857 dllProcs.Put( pDllProc );
858
859 continue;
860 }
861 if(source[i]==1&&(source[i+1]==ESC_SUB||source[i+1]==ESC_FUNCTION||source[i+1]==ESC_MACRO)){
862 char statementChar = source[i+1];
863
864 for(i2=0;;i2++,i++){
865 if(IsCommandDelimitation(source[i])){
866 temporary[i2]=0;
867 break;
868 }
869 temporary[i2]=source[i];
870 if(source[i]=='\0') break;
871 }
872
873 UserProc *pUserProc = ParseUserProc( namespaceScopes, importedNamespaces, temporary, i, false, NULL, false );
874
875 // 関数を追加
876 if( userProcs.IsExist( pUserProc ) )
877 {
878 // 既に存在している
879 compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
880
881 delete pUserProc;
882 }
883 else
884 {
885 userProcs.Put( pUserProc );
886 }
887
888 /* Sub ~ End Sub
889 Function ~ End Function
890 Macro ~ End Macro
891 を飛び越す */
892 char endStatementChar = GetEndXXXCommand( statementChar );
893 for(i2=0;;i++,i2++){
894 if( source[i] == '\0' ) break;
895 if( source[i] == 1 && source[i+1] == endStatementChar ){
896 i++;
897 break;
898 }
899 }
900 if(source[i]=='\0') break;
901 continue;
902 }
903
904 //次の行
905 for(;;i++){
906 if(IsCommandDelimitation(source[i])) break;
907 }
908 if(source[i]=='\0') break;
909 }
910
911 ////////////
912 // 特殊関数
913 ////////////
914 namespaceScopes.clear();
915 importedNamespaces.clear();
916
917 compiler.globalAreaProcName = "_GlobalArea_" + compiler.GetModuleName();
918 sprintf(temporary,"%c%c%s()",1,ESC_SUB,compiler.globalAreaProcName.c_str());
919 UserProc *pUserProc = ParseUserProc( namespaceScopes, importedNamespaces, temporary, 0, false, NULL, false );
920
921 // 関数を追加
922 if( userProcs.IsExist( pUserProc ) )
923 {
924 // 既に存在している
925 compiler.errorMessenger.Output(15,pUserProc->GetName(),i);
926
927 delete pUserProc;
928 }
929 else
930 {
931 userProcs.Put( pUserProc );
932 }
933}
Note: See TracBrowser for help on using the repository browser.