Changeset 542 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp
- Timestamp:
- May 4, 2008, 1:09:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp
r531 r542 237 237 } 238 238 239 void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string &expression, int nowLine ) 240 { 241 int i; 242 char temporary[VN_SIZE]; 243 244 for(i=0;;i++){ 245 if(expression[i]=='='||expression[i]=='\0'){ 246 temporary[i]=0; 247 break; 248 } 249 temporary[i]=expression[i]; 250 } 251 252 if(expression[i]!='='){ 253 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 254 return; 255 } 256 257 const char *pTemp=expression.c_str()+i+1; 258 259 //識別文字のエラーチェック(新しい型) 260 i=0; 261 for(;;i++){ 262 if(temporary[i]=='\0') break; 263 if( !( IsVariableChar( temporary[i], true) ) ){ 264 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 265 return; 266 } 267 } 268 269 //識別文字のエラーチェック(コピー元の型) 270 if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){ 271 //関数ポインタ 272 if(pTemp[3]!='('){ 273 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 274 return; 275 } 276 } 277 else{ 278 i=0; 279 while(pTemp[i]=='*') i++; 280 for(;;i++){ 281 if(pTemp[i]=='\0') break; 282 if( !( IsVariableChar( pTemp[i], true) ) ) 283 { 284 compiler.errorMessenger.Output(10,"TypeDef",nowLine); 285 return; 286 } 287 } 288 } 289 290 //識別子が重複している場合はエラーにする 291 if(lstrcmp(temporary,pTemp)==0){ 292 compiler.errorMessenger.Output(1,NULL,nowLine); 293 return; 294 } 295 296 297 298 ////////////////////////// 299 // TypeDef情報を追加 300 ////////////////////////// 301 302 Type baseType; 303 if( !compiler.StringToType( pTemp, baseType ) ) 304 { 305 compiler.errorMessenger.Output(3, pTemp, nowLine ); 306 return; 307 } 308 309 typeDefs.push_back( 310 TypeDef( 311 namespaceScopes, 312 temporary, 313 pTemp, 314 baseType 315 ) 316 ); 317 } 318 void LexicalAnalyzer::CollectTypeDefs( const char *source, TypeDefCollection &typeDefs ) 319 { 320 // 名前空間管理 321 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(); 322 namespaceScopes.clear(); 323 324 // Importsされた名前空間の管理 325 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces(); 326 importedNamespaces.clear(); 327 328 int i=-1, i2; 329 char temporary[VN_SIZE]; 330 while(1){ 331 extern char *basbuf; 332 333 i++; 334 335 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){ 336 for(i+=2,i2=0;;i2++,i++){ 337 if( IsCommandDelimitation( basbuf[i] ) ){ 338 temporary[i2]=0; 339 break; 340 } 341 temporary[i2]=basbuf[i]; 342 } 343 namespaceScopes.push_back( temporary ); 344 345 continue; 346 } 347 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){ 348 if( namespaceScopes.size() <= 0 ){ 349 compiler.errorMessenger.Output(12, "End Namespace", i ); 350 } 351 else{ 352 namespaceScopes.pop_back(); 353 } 354 355 i += 2; 356 continue; 357 } 358 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){ 359 for(i+=2,i2=0;;i2++,i++){ 360 if( IsCommandDelimitation( basbuf[i] ) ){ 361 temporary[i2]=0; 362 break; 363 } 364 temporary[i2]=basbuf[i]; 365 } 366 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) 367 { 368 compiler.errorMessenger.Output(64,temporary,i ); 369 } 370 371 continue; 372 } 373 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ 374 importedNamespaces.clear(); 375 continue; 376 } 377 378 if( basbuf[i]==1 ){ 379 char temporary[VN_SIZE]; 380 if(basbuf[i+1]==ESC_TYPEDEF){ 381 int i2 = 0; 382 for(i+=2;;i2++,i++){ 383 if(basbuf[i]=='\n'){ 384 temporary[i2]=0; 385 break; 386 } 387 temporary[i2]=basbuf[i]; 388 if(basbuf[i]=='\0') break; 389 } 390 AddTypeDef( typeDefs, namespaceScopes, temporary, i ); 391 392 continue; 393 } 394 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){ 395 int i2 = 0; 396 for(i+=4;;i2++,i++){ 397 if(!IsVariableChar(basbuf[i])){ 398 temporary[i2]=0; 399 break; 400 } 401 temporary[i2]=basbuf[i]; 402 if(basbuf[i]=='\0') break; 403 } 404 405 Type baseType; 406 if( !compiler.StringToType( "Long", baseType ) ) 407 { 408 throw; 409 } 410 411 typeDefs.push_back( 412 TypeDef( 413 namespaceScopes, 414 temporary, 415 "Long", 416 baseType 417 ) 418 ); 419 } 420 } 421 422 //次の行 423 for(;;i++){ 424 if(IsCommandDelimitation(basbuf[i])) break; 425 } 426 if(basbuf[i]=='\0') break; 427 } 428 } 429 239 430 UserProc* LexicalAnalyzer::ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName ) 240 431 {
Note:
See TracChangeset
for help on using the changeset viewer.