Changeset 573 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp
- Timestamp:
- May 7, 2008, 10:27:02 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Procedure.cpp
r572 r573 275 275 BOOST_FOREACH( Parameter *pParam, userProc.GetParameters() ){ 276 276 userProc.RealParams().push_back( new Parameter( *pParam ) ); 277 } 278 279 return true; 280 } 281 282 bool 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->SetCodePos( 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 } 277 469 } 278 470 … … 549 741 // パラメータを解析 550 742 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 551 pDllProc->SetParamsAndReturnType( buffer + i, nowLine );743 LexicalAnalyzer::SetParamsAndReturnType( pDllProc, buffer + i, true, nowLine ); 552 744 553 745 // パラメータのエラーチェック
Note:
See TracChangeset
for help on using the changeset viewer.