Changeset 181 in dev for trunk/jenga/src/smoothie/Class.cpp
- Timestamp:
- Jun 24, 2007, 2:05:40 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jenga/src/smoothie/Class.cpp
r180 r181 4 4 #include <jenga/include/smoothie/Class.h> 5 5 #include <jenga/include/smoothie/SmoothieException.h> 6 7 8 class CLoopRefCheck{9 char **names;10 int num;11 void init(){12 int i;13 for(i=0;i<num;i++){14 free(names[i]);15 }16 free(names);17 }18 public:19 CLoopRefCheck()20 {21 names=(char **)malloc(1);22 num=0;23 }24 ~CLoopRefCheck()25 {26 init();27 }28 void add(const char *lpszInheritsClass)29 {30 names=(char **)realloc(names,(num+1)*sizeof(char *));31 names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);32 lstrcpy(names[num],lpszInheritsClass);33 num++;34 }35 void del(const char *lpszInheritsClass)36 {37 int i;38 for(i=0;i<num;i++){39 if(lstrcmp(names[i],lpszInheritsClass)==0){40 free(names[i]);41 break;42 }43 }44 if(i!=num){45 num--;46 for(;i<num;i++){47 names[i]=names[i+1];48 }49 }50 }51 BOOL check(const CClass &inheritsClass) const52 {53 //ループ継承チェック54 int i;55 for(i=0;i<num;i++){56 if( inheritsClass.GetName() == names[i] ){57 return 1;58 }59 }60 return 0;61 }62 };63 CLoopRefCheck *pobj_LoopRefCheck;64 65 66 6 67 7 … … 125 65 } 126 66 127 bool CClass::Inherits( const char *inheritNames, int nowLine ){128 int i = 0;129 bool isInheritsClass = false;130 while( true ){131 132 char temporary[VN_SIZE];133 for( int i2=0;; i++, i2++ ){134 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){135 temporary[i2] = 0;136 break;137 }138 temporary[i2] = inheritNames[i];139 }140 141 //継承元クラスを取得142 const CClass *pInheritsClass = Smoothie::meta.GetClasses().Find(temporary);143 if( !pInheritsClass ){144 throw SmoothieException(106,temporary,nowLine);145 return false;146 }147 148 if( pInheritsClass->IsInterface() ){149 // インターフェイスはあとで継承する150 }151 else if( pInheritsClass->IsClass() ){152 // クラスを継承する153 isInheritsClass = true;154 155 if( !InheritsClass( *pInheritsClass, nowLine ) ){156 return false;157 }158 }159 else{160 throw SmoothieException(135,NULL,nowLine);161 return false;162 }163 164 if( inheritNames[i] == '\0' ){165 break;166 }167 i++;168 }169 170 if( !isInheritsClass ){171 // クラスを一つも継承していないとき172 const CClass *pObjectClass = Smoothie::meta.GetClasses().Find("Object");173 if( !pObjectClass ){174 throw SmoothieException(106,"Object",i);175 return false;176 }177 178 if( !InheritsClass( *pObjectClass, nowLine ) ){179 return false;180 }181 }182 183 i=0;184 while( true ){185 186 char temporary[VN_SIZE];187 for( int i2=0;; i++, i2++ ){188 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){189 temporary[i2] = 0;190 break;191 }192 temporary[i2] = inheritNames[i];193 }194 195 //継承元クラスを取得196 const CClass *pInheritsClass = Smoothie::meta.GetClasses().Find(temporary);197 if( !pInheritsClass ){198 throw SmoothieException(106,temporary,nowLine);199 return false;200 }201 202 if( pInheritsClass->IsInterface() ){203 // インターフェイスを継承する204 if( !InheritsInterface( *pInheritsClass, nowLine ) ){205 return false;206 }207 }208 else if( pInheritsClass->IsClass() ){209 // クラスはさっき継承した210 }211 else{212 throw SmoothieException(135,NULL,nowLine);213 return false;214 }215 216 if( inheritNames[i] == '\0' ){217 break;218 }219 i++;220 }221 222 return true;223 }224 /*225 bool CClass::InheritsClass( const CClass &inheritsClass, int nowLine ){226 227 //ループ継承でないかをチェック228 if(pobj_LoopRefCheck->check(inheritsClass)){229 throw SmoothieException(123,inheritsClass.GetName(),nowLine);230 return false;231 }232 233 if( !inheritsClass.IsReady() ){234 //継承先が読み取られていないとき235 pobj_LoopRefCheck->add(this->GetName().c_str());236 Smoothie::meta.GetClasses().GetClass_recur(inheritsClass.GetName().c_str());237 pobj_LoopRefCheck->del(this->GetName().c_str());238 }239 240 //メンバをコピー241 BOOST_FOREACH( CMember *inheritsClassDynamicMember, inheritsClass.dynamicMembers ){242 CMember *pMember = new CMember( *inheritsClassDynamicMember );243 244 // アクセシビリティ245 if( inheritsClassDynamicMember->IsPrivate() ){246 pMember->SetAccessibility( Prototype::None );247 }248 else{249 pMember->SetAccessibility( inheritsClassDynamicMember->GetAccessibility() );250 }251 252 dynamicMembers.push_back( pMember );253 }254 255 //メソッドをコピー256 BOOST_FOREACH( const CMethod *pBaseMethod, inheritsClass.methods ){257 CMethod *pMethod = new DynamicMethod( *pBaseMethod );258 259 // アクセシビリティ260 if(pBaseMethod->GetAccessibility() == Prototype::Private){261 pMethod->SetAccessibility( Prototype::None );262 }263 else{264 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );265 }266 267 //pobj_Inherits268 // ※継承元のClassIndexをセット(入れ子継承を考慮する)269 if(pBaseMethod->GetInheritsClassPtr()==0){270 pMethod->SetInheritsClassPtr( &inheritsClass );271 }272 else{273 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );274 }275 276 methods.push_back( pMethod );277 }278 279 //仮想関数の数280 AddVtblNum( inheritsClass.GetVtblNum() );281 282 //継承先のクラスをメンバとして保持する283 pobj_InheritsClass = &inheritsClass;284 285 return true;286 }287 bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){288 289 //ループ継承でないかをチェック290 if(pobj_LoopRefCheck->check(inheritsInterface)){291 throw SmoothieException(123,inheritsInterface.GetName(),nowLine);292 return false;293 }294 295 if( !inheritsInterface.IsReady() ){296 //継承先が読み取られていないとき297 pobj_LoopRefCheck->add(this->GetName().c_str());298 Smoothie::meta.GetClasses().GetClass_recur(inheritsInterface.GetName().c_str());299 pobj_LoopRefCheck->del(this->GetName().c_str());300 }301 302 //メソッドをコピー303 BOOST_FOREACH( const CMethod *pBaseMethod, inheritsInterface.methods ){304 CMethod *pMethod = new DynamicMethod( *pBaseMethod );305 306 // アクセシビリティ307 if(pBaseMethod->GetAccessibility() == Prototype::Private){308 pMethod->SetAccessibility( Prototype::None );309 }310 else{311 pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );312 }313 314 //pobj_Inherits315 // ※継承元のClassIndexをセット(入れ子継承を考慮する)316 if(pBaseMethod->GetInheritsClassPtr()==0){317 pMethod->SetInheritsClassPtr( &inheritsInterface );318 }319 else{320 pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );321 }322 323 methods.push_back( pMethod );324 }325 326 interfaces.push_back( InheritedInterface( const_cast<CClass *>(&inheritsInterface), vtblNum ) );327 328 //仮想関数の数329 AddVtblNum( inheritsInterface.GetVtblNum() );330 331 return true;332 }333 void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer ){334 CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer );335 dynamicMembers.push_back( pMember );336 }337 void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){338 CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer, nowLine );339 staticMembers.push_back( pMember );340 }*/341 67 BOOL CClass::DupliCheckAll(const char *name){ 342 68 //重複チェック … … 505 231 return n; 506 232 } 507 /* 508 LONG_PTR CClass::GetVtblGlobalOffset(void) const 509 { 510 511 //既に存在する場合はそれを返す 512 if(vtbl_offset!=-1) return vtbl_offset; 513 514 515 516 ////////////////////////////////////// 517 // 存在しないときは新たに生成する 518 ////////////////////////////////////// 519 520 UserProc **ppsi; 521 ppsi=(UserProc **)malloc(GetVtblNum()*sizeof(GlobalProc *)); 522 523 //関数テーブルに値をセット 524 int i2 = 0; 525 BOOST_FOREACH( const CMethod *pMethod, methods ){ 526 if(pMethod->IsVirtual()){ 527 pMethod->pUserProc->Using(); 528 529 if(pMethod->IsAbstract()){ 530 extern int cp; 531 throw SmoothieException(300,NULL,cp); 532 533 ppsi[i2]=0; 534 } 535 else{ 536 ppsi[i2]=pMethod->pUserProc; 537 } 538 i2++; 539 } 540 } 541 542 vtbl_offset=dataTable.AddBinary((void *)ppsi,GetVtblNum()*sizeof(LONG_PTR)); 543 544 for( int i=0; i < GetVtblNum(); i++ ){ 545 pobj_Reloc->AddSchedule_DataSection(vtbl_offset+i*sizeof(LONG_PTR)); 546 } 547 548 free(ppsi); 549 550 return vtbl_offset; 551 } 552 void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){ 553 if(vtbl_offset==-1) return; 554 555 LONG_PTR *pVtbl; 556 pVtbl=(LONG_PTR *)((char *)dataTable.GetPtr()+vtbl_offset); 557 558 int i; 559 for(i=0;i<GetVtblNum();i++){ 560 GlobalProc *pUserProc; 561 pUserProc=(GlobalProc *)pVtbl[i]; 562 if(!pUserProc) continue; 563 pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection; 564 } 565 }*/ 233 566 234 bool CClass::IsAbstract() const 567 235 { … … 669 337 iIteNextNum( 0 ) 670 338 { 339 memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) ); 671 340 Clear(); 672 341 } … … 681 350 } 682 351 683 if(ppobj_IteClass) free(ppobj_IteClass); 352 if(ppobj_IteClass) 353 { 354 free(ppobj_IteClass); 355 ppobj_IteClass = NULL; 356 } 684 357 memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) ); 685 358 } … … 728 401 729 402 // TypeDefも見る 730 int index = Smoothie:: meta.typeDefs.GetIndex( namespaceScopes, name );403 int index = Smoothie::GetMeta().typeDefs.GetIndex( namespaceScopes, name ); 731 404 if( index != -1 ){ 732 Type type = Smoothie:: meta.typeDefs[index].GetBaseType();405 Type type = Smoothie::GetMeta().typeDefs[index].GetBaseType(); 733 406 if( type.IsObject() ){ 734 407 return &type.GetClass(); … … 747 420 } 748 421 749 CClass *Classes::Add Class( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){422 CClass *Classes::Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){ 750 423 ////////////////////////////////////////////////////////////////////////// 751 424 // クラスを追加 … … 753 426 ////////////////////////////////////////////////////////////////////////// 754 427 755 CClass *pobj_c; 756 pobj_c=new CClass(namespaceScopes, importedNamespaces, name); 428 CClass *pobj_c = Create(namespaceScopes, importedNamespaces, name); 757 429 758 430 if(lstrcmp(name,"String")==0){
Note:
See TracChangeset
for help on using the changeset viewer.