Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/DebugMiddleFile.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/DebugMiddleFile.cpp
r201 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 3 5 #include <Compiler.h> 4 #include <Class Impl.h>5 #include <Variable Impl.h>6 #include <Class.h> 7 #include <Variable.h> 6 8 7 9 #include "../BasicCompiler_Common/common.h" 10 #include "../BasicCompiler_Common/DebugSection.h" 8 11 9 12 #ifdef _AMD64_ … … 44 47 45 48 46 CDebugSection::CDebugSection(){47 memset(this,0,sizeof(CDebugSection));48 }49 49 CDebugSection::~CDebugSection(){ 50 50 if(pobj_DBClass) DeleteDebugInfo(); … … 56 56 void CDebugSection::make(void){ 57 57 extern INCLUDEFILEINFO IncludeFileInfo; 58 int i2,i3, i5,BufferSize;58 int i2,i3,BufferSize; 59 59 60 60 if(buffer){ … … 159 159 160 160 //グローバル変数情報 161 *(long *)(buffer+i2)=(int) ::globalVars.size();162 i2+=sizeof(long); 163 BOOST_FOREACH( Variable *pVar, ::globalVars){161 *(long *)(buffer+i2)=(int)compiler.GetMeta().GetGlobalVars().size(); 162 i2+=sizeof(long); 163 BOOST_FOREACH( Variable *pVar, compiler.GetMeta().GetGlobalVars() ){ 164 164 //変数名 165 165 lstrcpy(buffer+i2,pVar->GetName().c_str()); … … 167 167 168 168 //型 169 *(long *)(buffer+i2)=pVar->Get BasicType();169 *(long *)(buffer+i2)=pVar->GetType().GetBasicType(); 170 170 i2+=sizeof(long); 171 171 172 172 //型の拡張情報 173 SetLpIndex_DebugFile(buffer,&i2, *pVar);173 SetLpIndex_DebugFile(buffer,&i2,pVar->GetType()); 174 174 175 175 buffer[i2++] = pVar->IsRef() ? 1 : 0; … … 178 178 179 179 if(pVar->IsArray()){ 180 for(i5=0;;i5++){ 181 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5]; 180 *(long *)(buffer+i2)=(int)pVar->GetSubscripts().size(); 181 i2+=sizeof(long); 182 BOOST_FOREACH( int indexMax, pVar->GetSubscripts() ) 183 { 184 *(long *)(buffer+i2)=indexMax; 182 185 i2+=sizeof(long); 183 if(pVar->GetSubScriptsPtr()[i5]==-1) break;184 186 } 185 187 } 186 188 187 189 //レキシカルスコープ情報 188 *(long *)(buffer+i2)=pVar-> ScopeStartAddress;189 i2+=sizeof(long); 190 *(long *)(buffer+i2)=pVar-> ScopeEndAddress;191 i2+=sizeof(long); 192 *(long *)(buffer+i2)=pVar-> ScopeLevel;190 *(long *)(buffer+i2)=pVar->GetScopeStartAddress(); 191 i2+=sizeof(long); 192 *(long *)(buffer+i2)=pVar->GetScopeEndAddress(); 193 i2+=sizeof(long); 194 *(long *)(buffer+i2)=pVar->GetScopeLevel(); 193 195 i2+=sizeof(long); 194 196 195 197 //メモリ位置 196 *(long *)(buffer+i2)=pVar-> offset;198 *(long *)(buffer+i2)=pVar->GetOffsetAddress(); 197 199 i2+=sizeof(long); 198 200 … … 210 212 211 213 //プロシージャ情報 212 extern GlobalProc **ppSubHash; 213 extern int SubNum; 214 GlobalProc *pUserProc; 215 *(long *)(buffer+i2)=SubNum; 216 i2+=sizeof(long); 217 for(i3=0;i3<MAX_HASH;i3++){ 218 pUserProc=ppSubHash[i3]; 219 while(pUserProc){ 220 if(pUserProc->GetParentClassPtr()){ 221 lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->GetName().c_str()); 222 i2+=lstrlen(buffer+i2)+1; 223 } 224 else{ 225 lstrcpy(buffer+i2,""); 226 i2+=lstrlen(buffer+i2)+1; 227 } 228 229 //ID 230 *(long *)(buffer+i2)=pUserProc->id; 231 i2+=sizeof(long); 232 233 //関数名 234 lstrcpy(buffer+i2,pUserProc->GetName().c_str()); 214 *(long *)(buffer+i2) = compiler.GetMeta().GetUserProcs().Iterator_GetMaxCount(); 215 i2+=sizeof(long); 216 compiler.GetMeta().GetUserProcs().Iterator_Reset(); 217 while( compiler.GetMeta().GetUserProcs().Iterator_HasNext() ) 218 { 219 UserProc *pUserProc = compiler.GetMeta().GetUserProcs().Iterator_GetNext(); 220 221 if(pUserProc->GetParentClassPtr()){ 222 lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->GetName().c_str()); 235 223 i2+=lstrlen(buffer+i2)+1; 236 237 *(long *)(buffer+i2)=pUserProc->beginOpAddress; 238 i2+=sizeof(long); 239 *(long *)(buffer+i2)=pUserProc->endOpAddress; 240 i2+=sizeof(long); 241 242 //ローカル変数情報 243 *(long *)(buffer+i2)=(int)pUserProc->localVars.size(); 244 i2+=sizeof(long); 224 } 225 else{ 226 lstrcpy(buffer+i2,""); 227 i2+=lstrlen(buffer+i2)+1; 228 } 229 230 //ID 231 *(long *)(buffer+i2)=pUserProc->GetId(); 232 i2+=sizeof(long); 233 234 //関数名 235 lstrcpy(buffer+i2,pUserProc->GetName().c_str()); 236 i2+=lstrlen(buffer+i2)+1; 237 238 *(long *)(buffer+i2)=pUserProc->GetBeginOpAddress(); 239 i2+=sizeof(long); 240 *(long *)(buffer+i2)=pUserProc->GetEndOpAddress(); 241 i2+=sizeof(long); 242 243 //ローカル変数情報 244 *(long *)(buffer+i2)=(int)pUserProc->GetLocalVars().size(); 245 i2+=sizeof(long); 246 247 //バッファが足りない場合は再確保 248 if(BufferSize<i2+32768){ 249 BufferSize+=32768; 250 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); 251 } 252 253 BOOST_FOREACH( Variable *pVar, pUserProc->GetLocalVars() ){ 254 lstrcpy(buffer+i2,pVar->GetName().c_str()); 255 i2+=lstrlen(buffer+i2)+1; 256 257 //型 258 *(long *)(buffer+i2)=pVar->GetType().GetBasicType(); 259 i2+=sizeof(long); 260 261 //型の拡張情報 262 SetLpIndex_DebugFile(buffer,&i2,pVar->GetType()); 263 264 //参照型パラメータかどうか 265 buffer[i2++] = pVar->IsRef() ? 1 : 0; 266 267 //配列かどうか 268 buffer[i2++] = pVar->IsArray() ? 1 : 0; 269 270 //配列要素 271 if(pVar->IsArray()){ 272 *(long *)(buffer+i2)=(int)pVar->GetSubscripts().size(); 273 i2+=sizeof(long); 274 BOOST_FOREACH( int indexMax, pVar->GetSubscripts() ) 275 { 276 *(long *)(buffer+i2)=indexMax; 277 i2+=sizeof(long); 278 } 279 } 280 281 //レキシカルスコープ情報 282 *(long *)(buffer+i2)=pVar->GetScopeStartAddress(); 283 i2+=sizeof(long); 284 *(long *)(buffer+i2)=pVar->GetScopeEndAddress(); 285 i2+=sizeof(long); 286 *(long *)(buffer+i2)=pVar->GetScopeLevel(); 287 i2+=sizeof(long); 288 289 //メモリ位置 290 *(long *)(buffer+i2)=pVar->GetOffsetAddress(); 291 i2+=sizeof(long); 292 293 294 245 295 246 296 //バッファが足りない場合は再確保 … … 249 299 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize); 250 300 } 251 252 BOOST_FOREACH( Variable *pVar, pUserProc->localVars ){253 lstrcpy(buffer+i2,pVar->GetName().c_str());254 i2+=lstrlen(buffer+i2)+1;255 256 //型257 *(long *)(buffer+i2)=pVar->GetBasicType();258 i2+=sizeof(long);259 260 //型の拡張情報261 SetLpIndex_DebugFile(buffer,&i2,*pVar);262 263 //参照型パラメータかどうか264 buffer[i2++] = pVar->IsRef() ? 1 : 0;265 266 //配列かどうか267 buffer[i2++] = pVar->IsArray() ? 1 : 0;268 269 //配列要素270 if(pVar->IsArray()){271 for(i5=0;;i5++){272 *(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];273 i2+=sizeof(long);274 if(pVar->GetSubScriptsPtr()[i5]==-1) break;275 }276 }277 278 //レキシカルスコープ情報279 *(long *)(buffer+i2)=pVar->ScopeStartAddress;280 i2+=sizeof(long);281 *(long *)(buffer+i2)=pVar->ScopeEndAddress;282 i2+=sizeof(long);283 *(long *)(buffer+i2)=pVar->ScopeLevel;284 i2+=sizeof(long);285 286 //メモリ位置287 *(long *)(buffer+i2)=pVar->offset;288 i2+=sizeof(long);289 290 291 292 293 //バッファが足りない場合は再確保294 if(BufferSize<i2+32768){295 BufferSize+=32768;296 buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufferSize);297 }298 }299 300 pUserProc=pUserProc->pNextData;301 301 } 302 302 } … … 328 328 i2+=sizeof(long); 329 329 330 // メンバ330 // 動的メンバ 331 331 *(long *)(buffer+i2)=(int)pobj_c->GetDynamicMembers().size(); 332 332 i2+=sizeof(long); … … 347 347 i2+=sizeof(Prototype::Accessibility); 348 348 349 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM); 350 i2+=sizeof(int)*MAX_ARRAYDIM; 349 *(long *)(buffer+i2)=(int)member->GetSubscripts().size(); 350 i2+=sizeof(long); 351 BOOST_FOREACH( int indexMax, member->GetSubscripts() ) 352 { 353 *(long *)(buffer+i2)=indexMax; 354 i2+=sizeof(long); 355 } 351 356 352 357 //バッファが足りない場合は再確保 … … 357 362 } 358 363 359 // メソッド364 // 動的メソッド 360 365 *(long *)(buffer+i2)=(long)pobj_c->GetMethods().size(); 361 366 i2+=sizeof(long); … … 371 376 i2+=lstrlen(buffer+i2)+1; 372 377 } 373 lstrcpy(buffer+i2,pMethod-> pUserProc->GetName().c_str());378 lstrcpy(buffer+i2,pMethod->GetUserProc().GetName().c_str()); 374 379 i2+=lstrlen(buffer+i2)+1; 375 380 } … … 394 399 i2+=sizeof(Prototype::Accessibility); 395 400 396 memcpy(buffer+i2,member->SubScripts,sizeof(int)*MAX_ARRAYDIM); 397 i2+=sizeof(int)*MAX_ARRAYDIM; 401 // 配列 402 *(long *)(buffer+i2)=(int)member->GetSubscripts().size(); 403 i2+=sizeof(long); 404 BOOST_FOREACH( int indexMax, member->GetSubscripts() ) 405 { 406 *(long *)(buffer+i2)=indexMax; 407 i2+=sizeof(long); 408 } 398 409 399 410 //バッファが足りない場合は再確保 … … 434 445 } 435 446 BOOL CDebugSection::__load(void){ 436 int i2,i3,i4, i5,num;447 int i2,i3,i4,num; 437 448 char temp2[MAX_PATH],*temp5; 438 449 439 Smoothie::Temp::pCompilingClass = NULL;450 compiler.pCompilingClass = NULL; 440 451 441 452 i2=0; … … 487 498 /////////////////////////////////////////// 488 499 489 this->pobj_DBClass=new Classes Impl();500 this->pobj_DBClass=new Classes(); 490 501 491 502 int iMaxClassCount; … … 524 535 //定数を取得 525 536 GetConstInfo(); 526 extern CONSTINFO **ppConstHash; 527 this->ppConstHash=ppConstHash; 528 537 this->globalConsts = compiler.GetMeta().GetGlobalConsts(); 538 this->globalConstMacros = compiler.GetMeta().GetGlobalConstMacros(); 529 539 530 540 //グローバル変数情報 531 globalVars.clear();541 compiler.GetMeta().GetGlobalVars().clear(); 532 542 int maxGlobalVars=*(long *)(buffer+i2); 533 543 i2+=sizeof(long); … … 548 558 bool isArray = (buffer[i2++]) ? true:false; 549 559 550 Variable *pVar = new Variable Impl( name, type, false, isRef);560 Variable *pVar = new Variable( name, type, false, isRef, "" ); 551 561 552 562 if(isArray){ 553 int SubScripts[MAX_ARRAYDIM]; 554 for(i4=0;;i4++){ 555 SubScripts[i4]=*(long *)(buffer+i2); 563 Subscripts subscripts; 564 int nSubScriptsNum = *(long *)(buffer+i2); 565 i2+=sizeof(long); 566 for( int i=0; i<nSubScriptsNum; i++ ) 567 { 568 subscripts.push_back( *(long *)(buffer+i2) ); 556 569 i2+=sizeof(long); 557 558 if(SubScripts[i4]==-1) break; 559 } 560 561 pVar->SetArray( SubScripts ); 570 } 571 572 pVar->SetArray( subscripts ); 562 573 } 563 574 564 575 //レキシカルスコープ情報 565 pVar->S copeStartAddress=*(long *)(buffer+i2);566 i2+=sizeof(long); 567 pVar->S copeEndAddress=*(long *)(buffer+i2);568 i2+=sizeof(long); 569 pVar->S copeLevel=*(long *)(buffer+i2);576 pVar->SetScopeStartAddress( *(long *)(buffer+i2) ); 577 i2+=sizeof(long); 578 pVar->SetScopeEndAddress( *(long *)(buffer+i2) ); 579 i2+=sizeof(long); 580 pVar->SetScopeLevel( *(long *)(buffer+i2) ); 570 581 i2+=sizeof(long); 571 582 572 583 //メモリ位置 573 pVar-> offset=*(long *)(buffer+i2);584 pVar->SetOffsetAddress( *(long *)(buffer+i2) ); 574 585 i2+=sizeof(long); 575 586 576 587 //変数を追加 577 globalVars.push_back( pVar );588 compiler.GetMeta().GetGlobalVars().push_back( pVar ); 578 589 } 579 590 … … 583 594 584 595 //プロシージャ情報 585 GlobalProc *pUserProc; 586 SubNum=*(long *)(buffer+i2); 587 i2+=sizeof(long); 588 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *)); 589 for(int i6=0;i6<SubNum;i6++){ 596 userProcs.Clear(); 597 int subNum = *(long *)(buffer+i2); 598 i2+=sizeof(long); 599 for(int i6=0;i6<subNum;i6++){ 590 600 char szParentClassName[VN_SIZE]; 591 601 lstrcpy(szParentClassName,buffer+i2); … … 607 617 // オブジェクトを生成 608 618 // TODO: 名前空間が未完成 609 pUserProc = new GlobalProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false ); 610 pUserProc->pNextData=0; 611 pUserProc->id=id; 619 UserProc *pUserProc = new UserProc( NamespaceScopes(), NamespaceScopesCollection(), name, Procedure::Function, false, false, false, id ); 612 620 pUserProc->SetParentClass( pClass ); 613 621 614 pUserProc-> beginOpAddress=*(long *)(buffer+i2);615 i2+=sizeof(long); 616 pUserProc-> endOpAddress=*(long *)(buffer+i2);622 pUserProc->SetBeginOpAddress( *(long *)(buffer+i2) ); 623 i2+=sizeof(long); 624 pUserProc->SetEndOpAddress( *(long *)(buffer+i2) ); 617 625 i2+=sizeof(long); 618 626 … … 620 628 621 629 //ローカル変数情報 622 pUserProc-> localVars.clear();630 pUserProc->GetLocalVars().clear(); 623 631 int maxLocalVar=*(long *)(buffer+i2); 624 632 i2+=sizeof(long); … … 638 646 bool isArray = (buffer[i2++]) ? true:false; 639 647 640 Variable *pVar = new Variable Impl( name, type, false, isRef);648 Variable *pVar = new Variable( name, type, false, isRef, "" ); 641 649 642 650 if(isArray){ 643 int SubScripts[MAX_ARRAYDIM]; 644 for(i4=0;;i4++){ 645 SubScripts[i4]=*(long *)(buffer+i2); 651 Subscripts subscripts; 652 int nSubScriptsNum = *(long *)(buffer+i2); 653 i2+=sizeof(long); 654 for( int i=0; i<nSubScriptsNum; i++ ) 655 { 656 subscripts.push_back( *(long *)(buffer+i2) ); 646 657 i2+=sizeof(long); 647 648 if(SubScripts[i4]==-1) break;649 658 } 650 659 651 pVar->SetArray( SubScripts );660 pVar->SetArray( subscripts ); 652 661 } 653 662 654 663 //レキシカルスコープ情報 655 pVar->S copeStartAddress=*(long *)(buffer+i2);656 i2+=sizeof(long); 657 pVar->S copeEndAddress=*(long *)(buffer+i2);658 i2+=sizeof(long); 659 pVar->S copeLevel=*(long *)(buffer+i2);664 pVar->SetScopeStartAddress( *(long *)(buffer+i2) ); 665 i2+=sizeof(long); 666 pVar->SetScopeEndAddress( *(long *)(buffer+i2) ); 667 i2+=sizeof(long); 668 pVar->SetScopeLevel( *(long *)(buffer+i2) ); 660 669 i2+=sizeof(long); 661 670 662 671 //メモリ位置 663 pVar-> offset=*(long *)(buffer+i2);672 pVar->SetOffsetAddress( *(long *)(buffer+i2) ); 664 673 i2+=sizeof(long); 665 674 666 675 //変数を追加 667 pUserProc-> localVars.push_back( pVar );676 pUserProc->GetLocalVars().push_back( pVar ); 668 677 } 669 678 … … 673 682 ///////////////////////////////// 674 683 675 i4=hash_default(pUserProc->GetName().c_str()); 676 677 GlobalProc *psi2; 678 if(ppSubHash[i4]){ 679 psi2=ppSubHash[i4]; 680 while(1){ 681 if(psi2->pNextData==0){ 682 psi2->pNextData=pUserProc; 683 break; 684 } 685 psi2=psi2->pNextData; 686 } 687 } 688 else{ 689 ppSubHash[i4]=pUserProc; 690 } 691 } 684 // ハッシュに追加 685 if( !userProcs.Insert( pUserProc, -1 ) ) 686 { 687 //return NULL; 688 } 689 } 690 userProcs.Iterator_Init(); 692 691 693 692 //クラス情報 … … 709 708 i2+=sizeof(long); 710 709 711 // 静的メンバ710 // 動的メンバ 712 711 int nDynamicMember = *(long *)(buffer+i2); 713 712 i2+=sizeof(long); … … 728 727 i2+=sizeof(Prototype::Accessibility); 729 728 730 CMember *member=new CMember( accessibility, name, type, false, "", "" ); 731 732 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM); 733 i2+=sizeof(int)*MAX_ARRAYDIM; 729 Subscripts subscripts; 730 int nSubScriptsNum = *(long *)(buffer+i2); 731 i2+=sizeof(long); 732 for( int i=0; i<nSubScriptsNum; i++ ) 733 { 734 subscripts.push_back( *(long *)(buffer+i2) ); 735 i2+=sizeof(long); 736 } 737 738 CMember *member=new CMember( accessibility, name, type, false, subscripts, "", "" ); 734 739 735 740 pobj_c->GetDynamicMembers().push_back( member ); 736 741 } 737 742 738 // メソッド743 // 動的メソッド 739 744 int nMethod = *(long *)(buffer+i2); 740 745 i2+=sizeof(long); … … 759 764 pobj_temp_c=pobj_InheritsClass; 760 765 if(pobj_temp_c==0) pobj_temp_c=pobj_c; 761 i5=hash_default(temp2); 762 pUserProc=ppSubHash[i5]; 763 while(1){ 764 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break; 765 pUserProc=pUserProc->pNextData; 766 767 UserProc *pUserProc = compiler.GetMeta().GetUserProcs().GetHashArrayElement( temp2 ); 768 while(pUserProc){ 769 if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) 770 { 771 break; 772 } 773 774 pUserProc=pUserProc->GetChainNext(); 766 775 } 767 776 … … 790 799 i2+=sizeof(Prototype::Accessibility); 791 800 792 CMember *member=new CMember( accessibility, name, type, false, "", "" ); 793 794 memcpy(member->SubScripts,buffer+i2,sizeof(int)*MAX_ARRAYDIM); 795 i2+=sizeof(int)*MAX_ARRAYDIM; 801 // 配列 802 Subscripts subscripts; 803 int nSubScriptsNum = *(long *)(buffer+i2); 804 i2+=sizeof(long); 805 for( int i=0; i<nSubScriptsNum; i++ ) 806 { 807 subscripts.push_back( *(long *)(buffer+i2) ); 808 i2+=sizeof(long); 809 } 810 811 CMember *member=new CMember( accessibility, name, type, false, subscripts, "", "" ); 796 812 797 813 pobj_c->GetStaticMembers().push_back( member ); … … 805 821 806 822 807 extern GlobalProc **ppSubHash; 808 ppSubHash=this->ppSubHash; 823 compiler.GetMeta().GetUserProcs() = userProcs; 809 824 pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc"); 810 825 … … 950 965 951 966 //定数を取得 952 extern CONSTINFO **ppConstHash;953 ppConstHash=this->ppConstHash;967 compiler.GetMeta().GetGlobalConsts() = this->globalConsts; 968 compiler.GetMeta().GetGlobalConstMacros() = this->globalConstMacros; 954 969 955 970 //グローバル実行領域のサイズ … … 958 973 959 974 //プロシージャ 960 extern char **ppMacroNames; 961 ppMacroNames=0; 962 extern GlobalProc **ppSubHash; 963 extern int SubNum; 964 ppSubHash=this->ppSubHash; 965 SubNum=this->SubNum; 966 967 extern UserProc *pSub_DebugSys_EndProc; 975 compiler.GetMeta().GetUserProcs() = userProcs; 976 977 extern const UserProc *pSub_DebugSys_EndProc; 968 978 pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc; 969 979 … … 986 996 delete this->pobj_DBClass; 987 997 this->pobj_DBClass=0; 988 989 //サブルーチン情報のメモリ解放990 DeleteSubInfo(ppSubHash,0,0);991 992 //定数に関する情報を解放993 DeleteConstInfo(ppConstHash);994 998 995 999 //コードと行番号の関係を解放
Note:
See TracChangeset
for help on using the changeset viewer.