- Timestamp:
- May 7, 2008, 10:27:02 AM (17 years ago)
- Location:
- trunk/ab5.0/abdev/BasicCompiler_Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h
r572 r573 57 57 static bool AnalyzeParameter( Parameters ¶ms, const Jenga::Common::Strings ¶meterStrings, int nowLine ); 58 58 static bool SetParamsAndReturnTypeForUserProc( UserProc &userProc, const char *sourceOfParams, int nowLine, bool isStatic ); 59 static bool SetParamsAndReturnType( Procedure *pProc, const char *sourceOfParams, bool isSupportEllipse, int nowLine ); 59 60 static UserProc* ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName = NULL ); 60 61 static DllProc *ParseDllProc(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine); -
trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h
r572 r573 388 388 const CMethod &GetMethod() const; 389 389 390 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );391 392 390 393 391 static const UserProc *pGlobalProc; … … 486 484 return lookupAddress; 487 485 } 488 489 bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );490 486 }; 491 487 class DllProcs : public Jenga::Common::Hashmap<DllProc> … … 524 520 } 525 521 ~ProcPointer(){} 526 527 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );528 522 }; 529 523 -
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 // パラメータのエラーチェック -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Procedure.cpp
r572 r573 134 134 } 135 135 136 bool DllProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){137 int i = 0;138 int i2,i3,sw;139 char temporary[8192],temp2[VN_SIZE];140 141 //ソースコードの位置142 this->codePos = nowLine;143 144 //パラメータ145 if(sourceOfParams[i]!='('){146 compiler.errorMessenger.Output(1,NULL,nowLine);147 return 0;148 }149 i++;150 151 while(1){152 if(sourceOfParams[i]==')') break;153 154 //ByRef155 bool isRef;156 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){157 isRef = false;158 i+=2;159 }160 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){161 isRef = true;162 i+=2;163 }164 else isRef = false;165 166 //パラメータ名167 bool isArray = false;168 Subscripts subscripts;169 char name[VN_SIZE];170 sw=0;171 for(i2=0;;i++,i2++){172 if(sourceOfParams[i]=='('){173 if(!sw) sw=1;174 175 i3=GetStringInPare(name+i2,sourceOfParams+i);176 i2+=i3-1;177 i+=i3-1;178 continue;179 }180 if(sourceOfParams[i]=='['){181 if(!sw) sw=1;182 183 i3=GetStringInBracket(name+i2,sourceOfParams+i);184 i2+=i3-1;185 i+=i3-1;186 continue;187 }188 if(!IsVariableChar(sourceOfParams[i])){189 name[i2]=0;190 break;191 }192 name[i2]=sourceOfParams[i];193 }194 if(sw){195 //配列パラメータ196 if( isRef == false ) compiler.errorMessenger.Output(29,NULL,nowLine);197 isArray = true;198 199 if((name[i2-2]=='('&&name[i2-1]==')')||200 (name[i2-2]=='['&&name[i2-1]==']'))201 {202 subscripts.push_back( LONG_MAX );203 204 name[i2-2]=0;205 }206 else{207 GetArrange(name,temp2,subscripts);208 lstrcpy(name,temp2);209 }210 211 i2=lstrlen(name);212 }213 214 //型215 Type type( DEF_NON );216 if(lstrcmp(name,"...")==0) type.SetBasicType( DEF_ELLIPSE );217 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){218 i+=2;219 220 i2=0;221 while(sourceOfParams[i]=='*'){222 temporary[i2]=sourceOfParams[i];223 i++;224 i2++;225 }226 for(;;i++,i2++){227 if(!IsVariableChar(sourceOfParams[i])){228 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){229 temporary[i2++]=sourceOfParams[i++];230 temporary[i2]=sourceOfParams[i];231 continue;232 }233 temporary[i2]=0;234 break;235 }236 temporary[i2]=sourceOfParams[i];237 }238 239 compiler.StringToType( temporary, type );240 241 if( type.IsNull() ){242 compiler.errorMessenger.Output(3,temporary,nowLine);243 type.SetBasicType( DEF_PTR_VOID );244 }245 }246 else{247 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );248 compiler.errorMessenger.Output(-103,temporary,nowLine);249 }250 251 Parameter *pParam = new Parameter( name, type, isRef );252 if( isArray ){253 pParam->SetArray( subscripts );254 }255 256 //パラメータを追加257 this->GetParameters().push_back( pParam );258 259 if(sourceOfParams[i]==','){260 i++;261 continue;262 }263 else if(sourceOfParams[i]==')') continue;264 else{265 compiler.errorMessenger.Output(1,NULL,nowLine);266 break;267 }268 }269 i++;270 271 if(sourceOfParams[i]){272 ///////////////////273 // 戻り値を取得274 ///////////////////275 276 i2=lstrlen(sourceOfParams)-2;277 278 int sw_as=0;279 for(;i2>0;i2--){280 if(sourceOfParams[i2]==')') break;281 282 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){283 i2+=2;284 i3=0;285 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];286 for(;;i2++,i3++){287 if(!IsVariableChar(sourceOfParams[i2])){288 temporary[i3]=0;289 break;290 }291 temporary[i3]=sourceOfParams[i2];292 }293 compiler.StringToType( temporary, this->returnType );294 if( this->returnType.IsNull() ) compiler.errorMessenger.Output(3,temporary,nowLine);295 296 sw_as=1;297 break;298 }299 }300 }301 else{302 //戻り値なしのSub定義303 this->returnType.SetNull();304 }305 306 return true;307 }308 309 bool ProcPointer::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){310 int i = 0;311 int i2,i3,sw;312 char temporary[8192],temp2[VN_SIZE];313 314 //ソースコードの位置315 this->codePos = nowLine;316 317 //パラメータ318 if(sourceOfParams[i]!='('){319 compiler.errorMessenger.Output(1,NULL,nowLine);320 return 0;321 }322 i++;323 while(1){324 if(sourceOfParams[i]==')') break;325 326 //ByRef327 bool isRef;328 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){329 isRef = false;330 i+=2;331 }332 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){333 isRef = true;334 i+=2;335 }336 else isRef = false;337 338 //パラメータ名339 bool isArray = false;340 Subscripts subscripts;341 char name[VN_SIZE];342 sw=0;343 for(i2=0;;i++,i2++){344 if(sourceOfParams[i]=='('){345 if(!sw) sw=1;346 347 i3=GetStringInPare(name+i2,sourceOfParams+i);348 i2+=i3-1;349 i+=i3-1;350 continue;351 }352 if(sourceOfParams[i]=='['){353 if(!sw) sw=1;354 355 i3=GetStringInBracket(name+i2,sourceOfParams+i);356 i2+=i3-1;357 i+=i3-1;358 continue;359 }360 if(!IsVariableChar(sourceOfParams[i])){361 name[i2]=0;362 break;363 }364 name[i2]=sourceOfParams[i];365 }366 if(sw){367 //配列パラメータ368 if( isRef == false ) compiler.errorMessenger.Output(29,NULL,nowLine);369 isArray = true;370 371 if((name[i2-2]=='('&&name[i2-1]==')')||372 (name[i2-2]=='['&&name[i2-1]==']'))373 {374 subscripts.push_back( LONG_MAX );375 376 name[i2-2]=0;377 }378 else{379 GetArrange(name,temp2,subscripts);380 lstrcpy(name,temp2);381 }382 383 i2=lstrlen(name);384 }385 386 //型387 Type type( DEF_NON );388 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){389 i+=2;390 391 i2=0;392 while(sourceOfParams[i]=='*'){393 temporary[i2]=sourceOfParams[i];394 i++;395 i2++;396 }397 for(;;i++,i2++){398 if(!IsVariableChar(sourceOfParams[i])){399 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){400 temporary[i2++]=sourceOfParams[i++];401 temporary[i2]=sourceOfParams[i];402 continue;403 }404 temporary[i2]=0;405 break;406 }407 temporary[i2]=sourceOfParams[i];408 }409 410 compiler.StringToType( temporary, type );411 412 if( type.IsNull() ){413 compiler.errorMessenger.Output(3,temporary,nowLine);414 type.SetBasicType( DEF_PTR_VOID );415 }416 }417 else{418 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );419 compiler.errorMessenger.Output(-103,temporary,nowLine);420 }421 422 Parameter *pParam = new Parameter( name, type, isRef );423 if( isArray ){424 pParam->SetArray( subscripts );425 }426 427 //パラメータを追加428 this->GetParameters().push_back( pParam );429 430 if(sourceOfParams[i]==','){431 i++;432 continue;433 }434 else if(sourceOfParams[i]==')') continue;435 else{436 compiler.errorMessenger.Output(1,NULL,nowLine);437 break;438 }439 }440 i++;441 442 if(sourceOfParams[i]){443 ///////////////////444 // 戻り値を取得445 ///////////////////446 447 i2=lstrlen(sourceOfParams)-2;448 449 int sw_as=0;450 for(;i2>0;i2--){451 if(sourceOfParams[i2]==')') break;452 453 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){454 i2+=2;455 i3=0;456 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];457 for(;;i2++,i3++){458 if(!IsVariableChar(sourceOfParams[i2])){459 temporary[i3]=0;460 break;461 }462 temporary[i3]=sourceOfParams[i2];463 }464 compiler.StringToType( temporary, this->returnType );465 if( this->returnType.IsNull() ) compiler.errorMessenger.Output(3,temporary,nowLine);466 467 sw_as=1;468 break;469 }470 }471 }472 else{473 //戻り値なしのSub定義474 this->returnType.SetNull();475 }476 477 //戻り値のエラーチェック478 if( IsFunction() ){479 // Function定義480 481 if( this->ReturnType().IsNull() ){482 // 戻り値がない483 compiler.errorMessenger.Output(26,this->GetName(),nowLine);484 }485 }486 else{487 if( !this->ReturnType().IsNull() ){488 // Sub定義なのに、戻り値がある489 compiler.errorMessenger.Output(38,this->GetName(),nowLine);490 }491 }492 493 return true;494 }495 496 136 int ProcPointers::Add( const std::string &typeExpression ) 497 137 { … … 508 148 //buffer[0]は'('となっている 509 149 extern int cp; 510 pProcPointer->SetParamsAndReturnType( paramStr.c_str(), cp );150 LexicalAnalyzer::SetParamsAndReturnType( pProcPointer, paramStr.c_str(), false, cp ); 511 151 512 152 this->push_back( pProcPointer );
Note:
See TracChangeset
for help on using the changeset viewer.