Changeset 571 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/Procedure.cpp
- Timestamp:
- May 6, 2008, 9:10:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/Procedure.cpp
r537 r571 98 98 bool UserProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ){ 99 99 int i = 0; 100 int i2,i3,sw;101 char temporary[8192],temp2[VN_SIZE];102 100 103 101 //ソースコードの位置 … … 146 144 } 147 145 148 // パラメータを分割149 146 Jenga::Common::Strings parameters; 147 148 // パラメータ 150 149 SplitParameter( parametersStr1, parameters ); 151 BOOST_FOREACH( const std::string ¶mStr, parameters ) 152 { 153 int i = 0; 154 155 bool isRef = false; 156 if( paramStr[i] == 1 ) 157 { 158 if( paramStr[i+1] == ESC_BYVAL ) 159 { 160 isRef = false; 161 i += 2; 162 } 163 else if( paramStr[i+1] == ESC_BYREF ) 164 { 165 isRef = true; 166 i += 2; 167 } 168 } 169 170 //パラメータ名 171 bool isArray = false; 172 Subscripts subscripts; 173 char name[VN_SIZE]; 174 sw=0; 175 for(i2=0;;i++,i2++){ 176 if(paramStr[i]=='('){ 177 if(!sw) sw=1; 178 179 i3=GetStringInPare(name+i2,paramStr.c_str()+i); 180 i2+=i3-1; 181 i+=i3-1; 182 continue; 183 } 184 if(paramStr[i]=='['){ 185 if(!sw) sw=1; 186 187 i3=GetStringInBracket(name+i2,paramStr.c_str()+i); 188 i2+=i3-1; 189 i+=i3-1; 190 continue; 191 } 192 if(!IsVariableChar(paramStr[i])){ 193 name[i2]=0; 194 break; 195 } 196 name[i2]=paramStr[i]; 197 } 198 if(sw){ 199 //配列パラメータ 200 if( isRef == false ) 201 { 202 compiler.errorMessenger.Output(29,NULL,nowLine); 203 } 204 isArray = true; 205 206 if((name[i2-2]=='('&&name[i2-1]==')')|| 207 (name[i2-2]=='['&&name[i2-1]==']')) 208 { 209 subscripts.push_back( LONG_MAX ); 210 211 name[i2-2]=0; 212 } 213 else{ 214 GetArrange(name,temp2,subscripts); 215 lstrcpy(name,temp2); 216 } 217 218 i2=lstrlen(name); 219 } 220 221 Type type( DEF_NON ); 222 char initValue[8192] = ""; 223 if( paramStr[i] == '=' ){ 224 i++; 225 i = GetOneParameter( paramStr.c_str(), i, initValue ); 226 if( paramStr[i-1] == ',' ) 227 { 228 i--; 229 } 230 231 // TODO: エラー用 fix me!!! 232 //cp = nowLine; 233 234 NumOpe_GetType( initValue, GetStringTypeInfo(), type ); 235 236 if( IS_LITERAL(type.GetIndex()) ) 237 { 238 type.SetIndex( -1 ); 239 } 240 } 241 else if(paramStr[i]==1&¶mStr[i+1]==ESC_AS){ 242 // As指定 243 i+=2; 244 245 i2=0; 246 lstrcpy( temporary, paramStr.c_str() + i ); 247 248 compiler.StringToType( temporary, type ); 249 250 if( type.IsNull() ){ 251 compiler.errorMessenger.Output(3,temporary,nowLine); 252 type.SetBasicType( DEF_PTR_VOID ); 253 } 254 255 if( type.IsObject() ){ 256 if( type.GetClass().IsBlittableType() ){ 257 // Blittable型のときは基本型として扱う 258 type = type.GetClass().GetBlittableType(); 259 } 260 } 261 } 262 else{ 263 type.SetBasicType( Type::GetBasicTypeFromSimpleName(name) ); 264 compiler.errorMessenger.Output(-103,name,nowLine); 265 } 266 267 Parameter *pParam = new Parameter( name, type, isRef, initValue ); 268 if( isArray ){ 269 pParam->SetArray( subscripts ); 270 } 271 272 //パラメータを追加 273 this->params.push_back( pParam ); 274 } 275 150 ActiveBasic::Compiler::LexicalAnalyzer::AnalyzeParameter( params, parameters, nowLine ); 151 152 // 省略可能パラメータ(古い仕様。非推奨) 276 153 this->secondParmNum = (int)this->params.size(); 277 278 154 SplitParameter( parametersStr2, parameters ); 279 BOOST_FOREACH( const std::string ¶mStr, parameters ) 280 { 281 int i = 0; 282 283 bool isRef = false; 284 if( paramStr[i] == 1 ) 285 { 286 if( paramStr[i+1] == ESC_BYVAL ) 287 { 288 isRef = true; 289 i += 2; 290 } 291 else if( paramStr[i+1] == ESC_BYREF ) 292 { 293 isRef = false; 294 i += 2; 295 } 296 } 297 298 //パラメータ名 299 bool isArray = false; 300 Subscripts subscripts; 301 char name[VN_SIZE]; 302 sw=0; 303 for(i2=0;;i++,i2++){ 304 if(paramStr[i]=='('){ 305 if(!sw) sw=1; 306 307 i3=GetStringInPare(name+i2,paramStr.c_str()+i); 308 i2+=i3-1; 309 i+=i3-1; 310 continue; 311 } 312 if(paramStr[i]=='['){ 313 if(!sw) sw=1; 314 315 i3=GetStringInBracket(name+i2,paramStr.c_str()+i); 316 i2+=i3-1; 317 i+=i3-1; 318 continue; 319 } 320 if(!IsVariableChar(paramStr[i])){ 321 name[i2]=0; 322 break; 323 } 324 name[i2]=paramStr[i]; 325 } 326 if(sw){ 327 //配列パラメータ 328 if( isRef == false ) compiler.errorMessenger.Output(29,NULL,nowLine); 329 isArray = true; 330 331 if((name[i2-2]=='('&&name[i2-1]==')')|| 332 (name[i2-2]=='['&&name[i2-1]==']')) 333 { 334 subscripts.push_back( LONG_MAX ); 335 336 name[i2-2]=0; 337 } 338 else{ 339 GetArrange(name,temp2,subscripts); 340 lstrcpy(name,temp2); 341 } 342 343 i2=lstrlen(name); 344 } 345 346 Type type( DEF_NON ); 347 char initValue[8192] = ""; 348 if( paramStr[i] == '=' ){ 349 i++; 350 i = GetOneParameter( paramStr.c_str(), i, initValue ); 351 if( paramStr[i-1] == ',' ) 352 { 353 i--; 354 } 355 356 // TODO: エラー用 fix me!!! 357 //cp = nowLine; 358 359 NumOpe_GetType( initValue, GetStringTypeInfo(), type ); 360 361 if( IS_LITERAL(type.GetIndex()) ) 362 { 363 type.SetIndex( -1 ); 364 } 365 } 366 else if(paramStr[i]==1&¶mStr[i+1]==ESC_AS){ 367 // As指定 368 i+=2; 369 370 i2=0; 371 while(paramStr[i]=='*'){ 372 temporary[i2]=paramStr[i]; 373 i++; 374 i2++; 375 } 376 for(;;i++,i2++){ 377 if(!IsVariableChar(paramStr[i])){ 378 if(paramStr[i]==1&&(paramStr[i+1]==ESC_FUNCTION||paramStr[i+1]==ESC_SUB)){ 379 temporary[i2++]=paramStr[i++]; 380 temporary[i2]=paramStr[i]; 381 continue; 382 } 383 temporary[i2]=0; 384 break; 385 } 386 temporary[i2]=paramStr[i]; 387 } 388 389 compiler.StringToType( temporary, type ); 390 391 if( type.IsNull() ){ 392 compiler.errorMessenger.Output(3,temporary,nowLine); 393 type.SetBasicType( DEF_PTR_VOID ); 394 } 395 396 if( type.IsObject() ){ 397 if( type.GetClass().IsBlittableType() ){ 398 // Blittable型のときは基本型として扱う 399 type = type.GetClass().GetBlittableType(); 400 } 401 } 402 } 403 else{ 404 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) ); 405 compiler.errorMessenger.Output(-103,temporary,nowLine); 406 } 407 408 Parameter *pParam = new Parameter( name, type, isRef, initValue ); 409 if( isArray ){ 410 pParam->SetArray( subscripts ); 411 } 412 413 //パラメータを追加 414 this->params.push_back( pParam ); 415 } 155 ActiveBasic::Compiler::LexicalAnalyzer::AnalyzeParameter( params, parameters, nowLine ); 156 416 157 417 158 if(returnTypeStr[0]){
Note:
See TracChangeset
for help on using the changeset viewer.