Changeset 558 in dev for trunk/ab5.0/abdev
- Timestamp:
- May 5, 2008, 10:41:25 AM (17 years ago)
- Location:
- trunk/ab5.0/abdev/BasicCompiler_Common
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/include/Class.h
r557 r558 316 316 317 317 // インターフェイス実装 318 void Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine);318 void Implements( const CClass &interfaceClass, const Types &actualTypeParameters, std::vector<DynamicMethod::OverrideResult> &overrideResults ); 319 319 320 320 //メンバ、メソッドの追加 -
trunk/ab5.0/abdev/BasicCompiler_Common/include/Method.h
r523 r558 37 37 this->pUserProc = pUserProc; 38 38 } 39 40 virtual bool Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier ) = 0;41 39 42 40 virtual bool IsAbstract() const = 0; … … 54 52 class DynamicMethod : public CMethod 55 53 { 54 public: 55 struct OverrideResult 56 { 57 enum EnumType 58 { 59 Successful = 0, // オーバーライドに成功 60 NotVirtual, // 非Virtualメソッドに対してオーバーライドを行おうとした 61 NotUseOverrideModifier, // Override修飾子が無い状況で基底クラスの実体メソッドをオーバーライドしようとした 62 DifferentAccesibility, // オーバーライド元、先のアクセシビリティに相違がある 63 }; 64 65 EnumType enumType; 66 const CMethod *pMethod; 67 }; 68 69 private: 56 70 bool isAbstract; 57 71 bool isVirtual; … … 100 114 } 101 115 102 virtual boolOverride( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier );116 DynamicMethod::OverrideResult::EnumType Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier ); 103 117 104 118 virtual bool IsAbstract() const … … 250 264 pUserProc 照らし合わせる関数 251 265 */ 252 CMethod *FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc );266 DynamicMethod *FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc ); 253 267 254 268 const CMethod *GetMethodPtr( const UserProc *pUserProc ) const; -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp
r557 r558 185 185 } 186 186 187 void CClass::Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine)187 void CClass::Implements( const CClass &interfaceClass, const Types &actualTypeParameters, std::vector<DynamicMethod::OverrideResult> &overrideResults ) 188 188 { 189 189 ::Interface *pDestInterface = new ::Interface( &interfaceClass, actualTypeParameters ); … … 197 197 BOOST_FOREACH( CMethod *pMethod, GetDynamicMethods() ) 198 198 { 199 CMethod *pMethodForOverride = pDestInterface->GetDynamicMethods().FindForOverride( pDestInterface->GetActualTypeParameters(), &pMethod->GetUserProc() );199 DynamicMethod *pMethodForOverride = pDestInterface->GetDynamicMethods().FindForOverride( pDestInterface->GetActualTypeParameters(), &pMethod->GetUserProc() ); 200 200 if( pMethodForOverride ) 201 201 { 202 pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false ); 202 DynamicMethod::OverrideResult result; 203 result.enumType = pMethodForOverride->Override( &pMethod->GetUserProc(), pMethod->GetAccessibility(), false ); 204 result.pMethod = pMethod; 205 overrideResults.push_back( result ); 203 206 204 207 // 実装元になるメソッドは呼び出し不可にしておく(オーバーロードの解決から除外する) -
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Class.cpp
r557 r558 248 248 } 249 249 250 void OverrideErrorCheck( const DynamicMethod::OverrideResult &result ) 251 { 252 switch( result.enumType ) 253 { 254 case DynamicMethod::OverrideResult::Successful: 255 break; 256 case DynamicMethod::OverrideResult::NotVirtual: 257 compiler.errorMessenger.Output(136, result.pMethod->GetUserProc().GetName(), cp); 258 break; 259 case DynamicMethod::OverrideResult::NotUseOverrideModifier: 260 compiler.errorMessenger.Output(127, result.pMethod->GetUserProc().GetName(), cp); 261 break; 262 case DynamicMethod::OverrideResult::DifferentAccesibility: 263 compiler.errorMessenger.Output(128, result.pMethod->GetUserProc().GetName(), cp); 264 break; 265 default: 266 throw; 267 } 268 } 269 250 270 void LexicalAnalyzer::AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, 251 271 bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine) … … 320 340 321 341 // メソッドのオーバーライド 322 CMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );342 DynamicMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ); 323 343 if( pMethodForOverride ) 324 344 { 325 pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 345 DynamicMethod::OverrideResult result; 346 result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 347 result.pMethod = pMethodForOverride; 348 OverrideErrorCheck( result ); 349 326 350 pUserProc->SetMethod( pMethodForOverride ); 327 351 return; … … 349 373 } 350 374 351 CMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );375 DynamicMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc ); 352 376 if( pMethodForOverride ) 353 377 { 354 pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 378 DynamicMethod::OverrideResult result; 379 result.enumType = pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 380 result.pMethod = pMethodForOverride; 381 OverrideErrorCheck( result ); 382 355 383 pUserProc->SetMethod( pMethodForOverride ); 356 384 return; … … 512 540 { 513 541 // インターフェイスを継承する 514 currentClass.Implements( *pInterfaceClass, actualTypeParameters, nowLine ); 542 std::vector<DynamicMethod::OverrideResult> overrideResults; 543 currentClass.Implements( *pInterfaceClass, actualTypeParameters, overrideResults ); 544 545 // エラーチェック 546 BOOST_FOREACH( const DynamicMethod::OverrideResult result, overrideResults ) 547 { 548 OverrideErrorCheck( result ); 549 } 515 550 } 516 551 else -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Method.cpp
r523 r558 4 4 5 5 6 boolDynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier )6 DynamicMethod::OverrideResult::EnumType DynamicMethod::Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier ) 7 7 { 8 if( this->IsVirtual() 9 && !this->IsAbstract() 10 && isOverrideModifier == false ) 11 { 12 // Override修飾子が無い状況で基底クラスの実体メソッドをオーバーライドしようとした 13 compiler.errorMessenger.Output(127,NULL,cp); 14 } 8 bool isAbstractBefore = this->IsAbstract(); 15 9 16 10 //メンバ関数を上書き … … 18 12 this->SetAbstractMark( false ); 19 13 20 if( !this->IsVirtual() )14 if( this->IsVirtual() ) 21 15 { 22 // オーバーライドミス 23 compiler.errorMessenger.Output(136, pUserProc->GetName(), cp); 16 if( !isAbstractBefore && isOverrideModifier == false ) 17 { 18 return OverrideResult::NotUseOverrideModifier; 19 } 24 20 } 25 if(this->GetAccessibility() != accessibility )21 else 26 22 { 27 compiler.errorMessenger.Output(128,NULL,cp);23 return OverrideResult::NotVirtual; 28 24 } 29 25 30 return true; 26 if( this->GetAccessibility() != accessibility ) 27 { 28 return OverrideResult::DifferentAccesibility; 29 } 30 31 return OverrideResult::Successful; 31 32 } 32 33 … … 71 72 } 72 73 73 CMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc )74 DynamicMethod *Methods::FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc ) 74 75 { 75 76 //メソッドのオーバーライド … … 79 80 if( !pMethod->IsNotUse() && pMethod->GetUserProc().IsEqualForOverride( actualTypeParametersForThisMethods, pUserProc ) ) 80 81 { 81 return pMethod;82 return dynamic_cast<DynamicMethod *>(pMethod); 82 83 } 83 84 }
Note:
See TracChangeset
for help on using the changeset viewer.