Changeset 140 in dev for BasicCompiler_Common/Class.cpp
- Timestamp:
- Jun 15, 2007, 4:00:25 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Class.cpp
r139 r140 15 15 16 16 CClass::CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name ) 17 : Prototype( namespaceScopes, name ) 17 : isReady( false ) 18 , Prototype( namespaceScopes, name ) 18 19 , importedNamespaces( importedNamespaces ) 19 20 , ConstructorMemberSubIndex( 0 ) … … 21 22 , classType( Class ) 22 23 , pobj_InheritsClass( NULL ) 23 , ppobj_Member( NULL )24 , iMemberNum( 0 )25 24 , vtbl_num( 0 ) 26 25 , iAlign( 0 ) … … 32 31 } 33 32 CClass::~CClass(){ 34 int i; 35 36 if(ppobj_Member){ 37 //メンバ 38 for(i=0;i<iMemberNum;i++){ 39 delete ppobj_Member[i]; 40 } 41 HeapDefaultFree(ppobj_Member); 42 ppobj_Member=0; 43 } 44 45 //静的メンバ 33 // 動的メンバ 34 foreach( CMember *member, dynamicMembers ){ 35 delete member; 36 } 37 38 // 静的メンバ 46 39 foreach( CMember *member, staticMembers ){ 47 40 delete member; … … 149 142 } 150 143 151 if( inheritsClass.ppobj_Member == 0){144 if( !inheritsClass.IsReady() ){ 152 145 //継承先が読み取られていないとき 153 146 pobj_LoopRefCheck->add(this->GetName().c_str()); … … 157 150 158 151 //メンバをコピー 159 ppobj_Member=(CMember **)HeapReAlloc( 160 hHeap, 161 0, 162 ppobj_Member, 163 ( iMemberNum + inheritsClass.iMemberNum )*sizeof(CMember *)); 164 for(int i3=0;i3<inheritsClass.iMemberNum;i3++){ 165 ppobj_Member[iMemberNum]=new CMember( *inheritsClass.ppobj_Member[i3] ); 152 BOOST_FOREACH( CMember *inheritsClassDynamicMember, inheritsClass.dynamicMembers ){ 153 CMember *pMember = new CMember( *inheritsClassDynamicMember ); 166 154 167 155 // アクセシビリティ 168 if( inheritsClass .ppobj_Member[i3]->IsPrivate() ){169 p pobj_Member[iMemberNum]->SetAccessibility( Prototype::None );156 if( inheritsClassDynamicMember->IsPrivate() ){ 157 pMember->SetAccessibility( Prototype::None ); 170 158 } 171 159 else{ 172 p pobj_Member[iMemberNum]->SetAccessibility( inheritsClass.ppobj_Member[i3]->GetAccessibility() );173 } 174 175 iMemberNum++;160 pMember->SetAccessibility( inheritsClassDynamicMember->GetAccessibility() ); 161 } 162 163 dynamicMembers.push_back( pMember ); 176 164 } 177 165 … … 216 204 } 217 205 218 if( inheritsInterface.ppobj_Member == 0){206 if( !inheritsInterface.IsReady() ){ 219 207 //継承先が読み取られていないとき 220 208 pobj_LoopRefCheck->add(this->GetName().c_str()); … … 255 243 } 256 244 void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer ){ 257 ppobj_Member = (CMember **)HeapReAlloc( hHeap, 0, ppobj_Member, ( iMemberNum + 1 ) * sizeof(CMember *) ); 258 ppobj_Member[iMemberNum] = new CMember( this, accessibility, isConst, isRef, buffer ); 259 iMemberNum++; 245 CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer ); 246 dynamicMembers.push_back( pMember ); 260 247 } 261 248 void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){ 262 CMember * member = new CMember( this, accessibility, isConst, isRef, buffer, nowLine );263 staticMembers.push_back( member );249 CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer, nowLine ); 250 staticMembers.push_back( pMember ); 264 251 } 265 252 BOOL CClass::DupliCheckAll(const char *name){ … … 281 268 //重複チェック 282 269 283 // メンバ284 for( int i=0;i<iMemberNum;i++){285 if( GetName() == p pobj_Member[i]->GetName() ){270 // 動的メンバ 271 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 272 if( GetName() == pMember->GetName() ){ 286 273 return 1; 287 274 } 288 275 } 289 276 290 // 静的メンバ291 foreach( CMember * member, staticMembers ){292 if( GetName() == member->GetName() ){277 // 静的メンバ 278 foreach( CMember *pMember, staticMembers ){ 279 if( GetName() == pMember->GetName() ){ 293 280 return 1; 294 281 } … … 321 308 int CClass::GetMemberOffset( const char *memberName, int *pMemberNum ) const 322 309 { 323 int i ,i2,offset;310 int i2,offset; 324 311 325 312 //仮想関数が存在する場合は関数リストへのポインタのサイズを追加 … … 332 319 333 320 int iMaxAlign=0; 334 for(i=0;i<iMemberNum;i++){ 335 CMember *pMember = ppobj_Member[i]; 321 int i = -1; 322 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 323 i++; 336 324 337 325 i2 = pMember->GetType().GetSize(); … … 393 381 int CClass::GetAlignment() const 394 382 { 395 int i;396 383 int alignment,member_size; 397 384 … … 399 386 else alignment=0; 400 387 401 for(i=0;i<iMemberNum;i++){ 402 CMember *pMember = ppobj_Member[i]; 403 388 BOOST_FOREACH( CMember *pMember, dynamicMembers ){ 404 389 if(pMember->GetType().IsStruct()){ 405 390 //メンバクラスのアラインメントを取得 … … 969 954 970 955 BOOL CDBClass::MemberVar_LoopRefCheck(const CClass &objClass){ 971 int i,i2,bRet=1; 972 for(i=0;i<objClass.iMemberNum;i++){ 973 const CMember *pMember = objClass.ppobj_Member[i]; 956 int i2,bRet=1; 957 BOOST_FOREACH( CMember *pMember, objClass.dynamicMembers ){ 974 958 if(pMember->GetType().IsStruct()){ 975 959 //循環参照でないかをチェック … … 1055 1039 } 1056 1040 1057 if(pobj_c-> ppobj_Member){1041 if(pobj_c->IsReady()){ 1058 1042 //既に先読みされているとき 1059 1043 continue; 1060 1044 } 1061 1045 1062 //メンバ用メモリを初期化 1063 pobj_c->ppobj_Member=(CMember **)HeapAlloc(hHeap,0,1); 1064 pobj_c->iMemberNum=0; 1046 pobj_c->Readed(); 1065 1047 1066 1048 pobj_c->ConstructorMemberSubIndex=-1; … … 1206 1188 } 1207 1189 1208 if(pobj_c-> ppobj_Member){1190 if(pobj_c->IsReady()){ 1209 1191 //既に先読みされているとき 1210 1192 continue; … … 1213 1195 pobj_c->iAlign=iAlign; 1214 1196 1215 //メンバ用メモリを初期化 1216 pobj_c->ppobj_Member=(CMember **)HeapAlloc(hHeap,0,1); 1217 pobj_c->iMemberNum=0; 1197 pobj_c->Readed(); 1218 1198 1219 1199 pobj_c->ConstructorMemberSubIndex=-1; … … 1381 1361 1382 1362 1383 if(pobj_c-> ppobj_Member[pobj_c->iMemberNum-1]->GetType().IsStruct()){1384 if( pobj_c->ppobj_Member[pobj_c->iMemberNum-1]->GetType().GetClass().ppobj_Member==0){1363 if(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().IsStruct()){ 1364 if( !pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass().IsReady() ){ 1385 1365 //参照先が読み取られていないとき 1386 GetClass_recur(pobj_c-> ppobj_Member[pobj_c->iMemberNum-1]->GetType().GetClass().GetName().c_str());1366 GetClass_recur(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass().GetName().c_str()); 1387 1367 } 1388 1368 } 1389 1369 1390 1370 1391 if(pobj_c-> ppobj_Member[pobj_c->iMemberNum-1]->GetType().IsStruct()){1371 if(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().IsStruct()){ 1392 1372 //循環参照のチェック 1393 1373 pobj_LoopRefCheck->add(pobj_c->GetName().c_str()); 1394 if(!MemberVar_LoopRefCheck(pobj_c-> ppobj_Member[pobj_c->iMemberNum-1]->GetType().GetClass())){1374 if(!MemberVar_LoopRefCheck(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass())){ 1395 1375 //エラー回避 1396 pobj_c-> ppobj_Member[pobj_c->iMemberNum-1]->GetType().SetBasicType( DEF_PTR_VOID );1376 pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().SetBasicType( DEF_PTR_VOID ); 1397 1377 } 1398 1378 pobj_LoopRefCheck->del(pobj_c->GetName().c_str()); … … 1481 1461 char referenceOffsetsBuffer[1024] = ""; 1482 1462 int numOfReference = 0; 1483 for( int i=0; i<objClass.iMemberNum; i++ ){ 1484 CMember &member = *objClass.ppobj_Member[i]; 1485 1486 if( member.GetType().IsObject() || member.GetType().IsPointer() ){ 1463 BOOST_FOREACH( CMember *pMember, objClass.dynamicMembers ){ 1464 if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() ){ 1487 1465 if( referenceOffsetsBuffer[0] ){ 1488 1466 lstrcat( referenceOffsetsBuffer, "," ); … … 1491 1469 sprintf( referenceOffsetsBuffer + lstrlen( referenceOffsetsBuffer ), 1492 1470 "%d", 1493 objClass.GetMemberOffset( member.GetName().c_str() ) );1471 objClass.GetMemberOffset( pMember->GetName().c_str() ) ); 1494 1472 1495 1473 numOfReference++;
Note:
See TracChangeset
for help on using the changeset viewer.