Changeset 402 in dev for trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
- Timestamp:
- Feb 28, 2008, 7:04:35 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/src/Procedure.cpp
r400 r402 3 3 #include <jenga/include/smoothie/Smoothie.h> 4 4 #include <jenga/include/smoothie/SmoothieException.h> 5 #include <jenga/include/smoothie/LexicalAnalysis.h>6 5 7 6 #include <Compiler.h> … … 100 99 if(sourceOfParams[i]!='('){ 101 100 SetError(1,NULL,nowLine); 102 return 0; 103 } 104 i++; 105 if(sourceOfParams[i]!=')'&& this->pParentClass ){ 101 return false; 102 } 103 if(sourceOfParams[i + 1]!=')'&& this->pParentClass ){ 106 104 //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす 107 105 if(this->GetName()[0]=='~'){ 108 SmoothieException::Throw(114,NULL,nowLine); 109 i=JumpStringInPare(sourceOfParams,i); 110 } 111 } 112 113 /* 114 GetStringInPare( temporary, sourceOfParams + i ); 115 RemoveStringPare( temporary ); 116 */ 117 118 while(1){ 119 if(sourceOfParams[i]==')') break; 120 121 //ByRef 122 bool isRef; 123 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 124 isRef = false; 125 i+=2; 126 } 127 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 128 isRef = true; 129 i+=2; 130 } 131 else isRef = false; 106 SetError(114,NULL,nowLine); 107 return false; 108 } 109 } 110 111 // カッコ内のパラメータ文字列を取得 112 char parametersStr1[8192]; 113 char parametersStr2[8192] = ""; 114 i += GetStringInPare( parametersStr1, sourceOfParams + i, true ); 115 if( sourceOfParams[i] == '(' ) 116 { 117 i += GetStringInPare( parametersStr2, sourceOfParams + i, true ); 118 } 119 120 // 戻り値文字列を取得 121 char returnTypeStr[VN_SIZE] = ""; 122 if( sourceOfParams[i] ) 123 { 124 if( sourceOfParams[i] == 1 && sourceOfParams[i+1] == ESC_AS ) 125 { 126 if( !this->IsFunction() ){ 127 // Sub/Macroの場合 128 SetError(38,this->GetName(),nowLine); 129 } 130 131 lstrcpy( returnTypeStr, sourceOfParams + i + 2 ); 132 } 133 else 134 { 135 SetError(1,NULL,nowLine); 136 return false; 137 } 138 } 139 140 // パラメータを分割 141 Jenga::Common::Strings parameters; 142 SplitParameter( parametersStr1, parameters ); 143 BOOST_FOREACH( const std::string ¶mStr, parameters ) 144 { 145 int i = 0; 146 147 bool isRef = false; 148 if( paramStr[i] == 1 ) 149 { 150 if( paramStr[i+1] == ESC_BYVAL ) 151 { 152 isRef = false; 153 i += 2; 154 } 155 else if( paramStr[i+1] == ESC_BYREF ) 156 { 157 isRef = true; 158 i += 2; 159 } 160 } 132 161 133 162 //パラメータ名 … … 137 166 sw=0; 138 167 for(i2=0;;i++,i2++){ 139 if( sourceOfParams[i]=='('){168 if(paramStr[i]=='('){ 140 169 if(!sw) sw=1; 141 170 142 i3=GetStringInPare(name+i2, sourceOfParams+i);171 i3=GetStringInPare(name+i2,paramStr.c_str()+i); 143 172 i2+=i3-1; 144 173 i+=i3-1; 145 174 continue; 146 175 } 147 if( sourceOfParams[i]=='['){176 if(paramStr[i]=='['){ 148 177 if(!sw) sw=1; 149 178 150 i3=GetStringInBracket(name+i2, sourceOfParams+i);179 i3=GetStringInBracket(name+i2,paramStr.c_str()+i); 151 180 i2+=i3-1; 152 181 i+=i3-1; 153 182 continue; 154 183 } 155 if(!IsVariableChar( sourceOfParams[i])){184 if(!IsVariableChar(paramStr[i])){ 156 185 name[i2]=0; 157 186 break; 158 187 } 159 name[i2]= sourceOfParams[i];188 name[i2]=paramStr[i]; 160 189 } 161 190 if(sw){ 162 191 //配列パラメータ 163 if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine); 192 if( isRef == false ) 193 { 194 SetError(29,NULL,nowLine); 195 } 164 196 isArray = true; 165 197 … … 181 213 Type type( DEF_NON ); 182 214 char initValue[8192] = ""; 183 if( sourceOfParams[i] == '=' ){215 if( paramStr[i] == '=' ){ 184 216 i++; 185 i = GetOneParameter( sourceOfParams, i, initValue );186 if( sourceOfParams[i-1] == ',' )217 i = GetOneParameter( paramStr.c_str(), i, initValue ); 218 if( paramStr[i-1] == ',' ) 187 219 { 188 220 i--; … … 199 231 } 200 232 } 201 else if( sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){233 else if(paramStr[i]==1&¶mStr[i+1]==ESC_AS){ 202 234 // As指定 203 235 i+=2; 204 236 205 237 i2=0; 206 while( sourceOfParams[i]=='*'){207 temporary[i2]= sourceOfParams[i];238 while(paramStr[i]=='*'){ 239 temporary[i2]=paramStr[i]; 208 240 i++; 209 241 i2++; 210 242 } 211 243 for(;;i++,i2++){ 212 if(!IsVariableChar( sourceOfParams[i])){213 if( sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){214 temporary[i2++]= sourceOfParams[i++];215 temporary[i2]= sourceOfParams[i];244 if(!IsVariableChar(paramStr[i])){ 245 if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){ 246 temporary[i2++]=paramStr[i++]; 247 temporary[i2]=paramStr[i]; 216 248 continue; 217 249 } … … 219 251 break; 220 252 } 221 temporary[i2]= sourceOfParams[i];253 temporary[i2]=paramStr[i]; 222 254 } 223 255 … … 248 280 //パラメータを追加 249 281 this->params.push_back( pParam ); 250 251 if(sourceOfParams[i]==','){ 282 } 283 284 this->secondParmNum = (int)this->params.size(); 285 286 SplitParameter( parametersStr2, parameters ); 287 BOOST_FOREACH( const std::string ¶mStr, parameters ) 288 { 289 int i = 0; 290 291 bool isRef = false; 292 if( paramStr[i] == 1 ) 293 { 294 if( paramStr[i+1] == ESC_BYVAL ) 295 { 296 isRef = true; 297 i += 2; 298 } 299 else if( paramStr[i+1] == ESC_BYREF ) 300 { 301 isRef = false; 302 i += 2; 303 } 304 } 305 306 //パラメータ名 307 bool isArray = false; 308 Subscripts subscripts; 309 char name[VN_SIZE]; 310 sw=0; 311 for(i2=0;;i++,i2++){ 312 if(paramStr[i]=='('){ 313 if(!sw) sw=1; 314 315 i3=GetStringInPare(name+i2,paramStr.c_str()+i); 316 i2+=i3-1; 317 i+=i3-1; 318 continue; 319 } 320 if(paramStr[i]=='['){ 321 if(!sw) sw=1; 322 323 i3=GetStringInBracket(name+i2,paramStr.c_str()+i); 324 i2+=i3-1; 325 i+=i3-1; 326 continue; 327 } 328 if(!IsVariableChar(paramStr[i])){ 329 name[i2]=0; 330 break; 331 } 332 name[i2]=paramStr[i]; 333 } 334 if(sw){ 335 //配列パラメータ 336 if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine); 337 isArray = true; 338 339 if((name[i2-2]=='('&&name[i2-1]==')')|| 340 (name[i2-2]=='['&&name[i2-1]==']')) 341 { 342 subscripts.push_back( LONG_MAX ); 343 344 name[i2-2]=0; 345 } 346 else{ 347 GetArrange(name,temp2,subscripts); 348 lstrcpy(name,temp2); 349 } 350 351 i2=lstrlen(name); 352 } 353 354 Type type( DEF_NON ); 355 char initValue[8192] = ""; 356 if( paramStr[i] == '=' ){ 252 357 i++; 253 continue; 254 } 255 else if(sourceOfParams[i]==')') continue; 256 else{ 257 SetError(1,NULL,nowLine); 258 break; 259 } 260 } 261 this->secondParmNum = (int)this->params.size(); 262 i++; 263 if(sourceOfParams[i]=='('){ 264 i++; 265 while(1){ 266 if(sourceOfParams[i]==')') break; 267 268 //ByRef 269 bool isRef; 270 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){ 271 isRef = false; 272 i+=2; 273 } 274 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){ 275 isRef = true; 276 i+=2; 277 } 278 else isRef = false; 279 280 //パラメータ名 281 bool isArray = false; 282 Subscripts subscripts; 283 char name[VN_SIZE]; 284 sw=0; 285 for(i2=0;;i++,i2++){ 286 if(sourceOfParams[i]=='('){ 287 if(!sw) sw=1; 288 289 i3=GetStringInPare(name+i2,sourceOfParams+i); 290 i2+=i3-1; 291 i+=i3-1; 292 continue; 293 } 294 if(sourceOfParams[i]=='['){ 295 if(!sw) sw=1; 296 297 i3=GetStringInBracket(name+i2,sourceOfParams+i); 298 i2+=i3-1; 299 i+=i3-1; 300 continue; 301 } 302 if(!IsVariableChar(sourceOfParams[i])){ 303 name[i2]=0; 358 i = GetOneParameter( paramStr.c_str(), i, initValue ); 359 if( paramStr[i-1] == ',' ) 360 { 361 i--; 362 } 363 364 // TODO: エラー用 fix me!!! 365 //cp = nowLine; 366 367 NumOpe_GetType( initValue, GetStringTypeInfo(), type ); 368 369 if( IS_LITERAL(type.GetIndex()) ) 370 { 371 type.SetIndex( -1 ); 372 } 373 } 374 else if(paramStr[i]==1&¶mStr[i+1]==ESC_AS){ 375 // As指定 376 i+=2; 377 378 i2=0; 379 while(paramStr[i]=='*'){ 380 temporary[i2]=paramStr[i]; 381 i++; 382 i2++; 383 } 384 for(;;i++,i2++){ 385 if(!IsVariableChar(paramStr[i])){ 386 if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){ 387 temporary[i2++]=paramStr[i++]; 388 temporary[i2]=paramStr[i]; 389 continue; 390 } 391 temporary[i2]=0; 304 392 break; 305 393 } 306 name[i2]=sourceOfParams[i]; 307 } 308 if(sw){ 309 //配列パラメータ 310 if( isRef == false ) SmoothieException::Throw(29,NULL,nowLine); 311 isArray = true; 312 313 if((name[i2-2]=='('&&name[i2-1]==')')|| 314 (name[i2-2]=='['&&name[i2-1]==']')) 315 { 316 subscripts.push_back( LONG_MAX ); 317 318 name[i2-2]=0; 394 temporary[i2]=paramStr[i]; 395 } 396 397 compiler.StringToType( temporary, type ); 398 399 if( type.IsNull() ){ 400 SmoothieException::Throw(3,temporary,nowLine); 401 type.SetBasicType( DEF_PTR_VOID ); 402 } 403 404 if( type.IsObject() ){ 405 if( type.GetClass().IsBlittableType() ){ 406 // Blittable型のときは基本型として扱う 407 type = type.GetClass().GetBlittableType(); 319 408 } 320 else{ 321 GetArrange(name,temp2,subscripts); 322 lstrcpy(name,temp2); 323 } 324 325 i2=lstrlen(name); 326 } 327 328 //型 329 Type type( DEF_NON ); 330 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){ 331 i+=2; 332 333 i2=0; 334 while(sourceOfParams[i]=='*'){ 335 temporary[i2]=sourceOfParams[i]; 336 i++; 337 i2++; 338 } 339 for(;;i++,i2++){ 340 if(!IsVariableChar(sourceOfParams[i])){ 341 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){ 342 temporary[i2++]=sourceOfParams[i++]; 343 temporary[i2]=sourceOfParams[i]; 344 continue; 345 } 346 temporary[i2]=0; 347 break; 348 } 349 temporary[i2]=sourceOfParams[i]; 350 } 351 352 compiler.StringToType( temporary, type ); 353 354 if( type.IsNull() ){ 355 SmoothieException::Throw(3,temporary,nowLine); 356 type.SetBasicType( DEF_PTR_VOID ); 357 } 358 } 359 else{ 360 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) ); 361 SmoothieException::Throw(-103,temporary,nowLine); 362 } 363 364 Parameter *pParam = new Parameter( name, type, isRef ); 365 if( isArray ){ 366 pParam->SetArray( subscripts ); 367 } 368 369 //パラメータを追加 370 this->params.push_back( pParam ); 371 372 if(sourceOfParams[i]==','){ 373 i++; 374 continue; 375 } 376 else if(sourceOfParams[i]==')') continue; 377 else{ 378 SetError(1,NULL,nowLine); 379 break; 380 } 381 } 382 i++; 383 } 384 385 if(sourceOfParams[i]){ 409 } 410 } 411 else{ 412 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) ); 413 SmoothieException::Throw(-103,temporary,nowLine); 414 } 415 416 Parameter *pParam = new Parameter( name, type, isRef, initValue ); 417 if( isArray ){ 418 pParam->SetArray( subscripts ); 419 } 420 421 //パラメータを追加 422 this->params.push_back( pParam ); 423 } 424 425 if(returnTypeStr[0]){ 386 426 /////////////////// 387 427 // 戻り値を取得 … … 390 430 if( !this->IsFunction() ){ 391 431 // Sub/Macroの場合 392 S moothieException::Throw(38,this->GetName(),nowLine);432 SetError(38,this->GetName(),nowLine); 393 433 } 394 434 … … 397 437 this->GetName()[0]=='~'){ 398 438 //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす 399 SmoothieException::Throw(115,NULL,nowLine); 400 } 401 } 402 403 404 i2=lstrlen(sourceOfParams)-2; 405 406 int sw_as=0; 407 for(;i2>0;i2--){ 408 if(sourceOfParams[i2]==')') break; 409 410 if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){ 411 i2+=2; 412 i3=0; 413 while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++]; 414 for(;;i2++,i3++){ 415 if( IsCommandDelimitation( sourceOfParams[i2] ) ) 416 { 417 temporary[i3]=0; 418 break; 419 } 420 temporary[i3]=sourceOfParams[i2]; 421 } 422 compiler.StringToType( temporary, this->returnType ); 423 if( this->returnType.IsNull() ) SmoothieException::Throw(3,temporary,nowLine); 424 425 sw_as=1; 426 break; 427 } 428 } 429 430 if(!sw_as){ 431 SmoothieException::Throw(-104,this->GetName().c_str(),nowLine); 439 SetError(115,NULL,nowLine); 440 } 441 } 442 443 compiler.StringToType( returnTypeStr, this->returnType ); 444 if( this->returnType.IsNull() ) 445 { 446 SetError(3,returnTypeStr,nowLine); 447 } 448 } 449 else{ 450 if( this->IsFunction() ) 451 { 452 // Function定義なのに、戻り値の型がセットされていない 453 SetError(-104,this->GetName().c_str(),nowLine); 432 454 433 455 this->returnType.SetBasicType( DEF_DOUBLE ); 434 456 } 435 } 436 else{ 437 //戻り値なしのSub定義 438 this->returnType.SetNull(); 457 else 458 { 459 //戻り値なしのSub定義 460 this->returnType.SetNull(); 461 } 439 462 } 440 463
Note:
See TracChangeset
for help on using the changeset viewer.