Changeset 511 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp
- Timestamp:
- Apr 30, 2008, 8:04:04 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/Class.cpp
r507 r511 12 12 #endif 13 13 14 using namespace ActiveBasic::Compiler; 15 14 16 15 17 Interface::Interface( const CClass *pInterfaceClass, const Types &actualTypeParameters ) … … 167 169 } 168 170 169 bool CClass::Inherits( const char *inheritNames, int nowLine ){170 int i = 0;171 bool isInheritsClass = false;172 while( true ){173 174 char temporary[VN_SIZE];175 for( int i2=0;; i++, i2++ ){176 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){177 temporary[i2] = 0;178 break;179 }180 temporary[i2] = inheritNames[i];181 }182 183 // ジェネリクス構文を分解184 char className[VN_SIZE];185 Jenga::Common::Strings typeParameterStrings;186 SplitGenericClassInstance( temporary, className, typeParameterStrings );187 188 // 型パラメータ文字列から型データを取得189 Types actualTypeParameters;190 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )191 {192 Type type;193 compiler.StringToType( typeParameterStr, type );194 actualTypeParameters.push_back( type );195 }196 197 //継承元クラスを取得198 const CClass *pInheritsClass = compiler.GetObjectModule().meta.GetClasses().Find(className);199 if( !pInheritsClass ){200 compiler.errorMessenger.Output(106,className,nowLine);201 return false;202 }203 204 if( pInheritsClass->IsClass() ){205 // クラスを継承する206 isInheritsClass = true;207 208 if( !InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){209 return false;210 }211 }212 else{213 compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine);214 return false;215 }216 217 if( inheritNames[i] == '\0' ){218 break;219 }220 i++;221 }222 223 if( !isInheritsClass ){224 // クラスを一つも継承していないとき225 if( !InheritsClass( *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr(), Types(), nowLine ) ){226 return false;227 }228 }229 230 return true;231 }232 171 bool CClass::InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine ) 233 172 { 234 //ループ継承でないかをチェック235 if( !compiler.GetObjectModule().meta.GetClasses().LoopRefCheck(inheritsClass) )236 {237 compiler.errorMessenger.Output(123,inheritsClass.GetName(),nowLine);238 return false;239 }240 241 if( !inheritsClass.IsReady() ){242 //継承先が読み取られていないとき243 compiler.GetObjectModule().meta.GetClasses().LookaheadClass(inheritsClass.GetName().c_str());244 }245 246 173 //メソッドをコピー 247 174 BOOST_FOREACH( const CMethod *pBaseMethod, inheritsClass.GetDynamicMethods() ){ … … 299 226 } 300 227 301 if( !interfaceClass.IsReady() ){302 // インターフェイスが未解析のとき303 compiler.GetObjectModule().meta.GetClasses().LookaheadClass( interfaceClass.GetName().c_str() );304 }305 306 228 ::Interface *pDestInterface = new ::Interface( &interfaceClass, actualTypeParameters ); 307 229 … … 332 254 // Function Operator() As ITest 333 255 334 char temporary[1024]; 335 sprintf(temporary,"%c%c%c%c()%c%c%s", 336 1, ESC_FUNCTION, 337 1, ESC_OPERATOR, 338 1, ESC_AS, 339 pDestInterface->GetFullNameWithActualGenericTypeParameters().c_str() 340 ); 341 342 this->AddMethod(this, 256 char methodName[255] = { 1, ESC_OPERATOR, CALC_AS, '\0' }; 257 258 //関数ハッシュへ登録 259 UserProc *pUserProc = new UserProc( 260 NamespaceScopes(), 261 NamespaceScopesCollection(), 262 methodName, 263 Procedure::Function, 264 false, 265 false, 266 false ); 267 pUserProc->SetParentClass( this ); 268 269 Parameters params; 270 params.push_back( new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) ); 271 pUserProc->SetRealParams( params ); 272 273 pUserProc->SetReturnType( Type( DEF_OBJECT, interfaceClass ) ); 274 pUserProc->_paramStr = ""; 275 pUserProc->Using(); 276 compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, -1 ); 277 278 LexicalAnalyzer::AddMethod(this, 279 pUserProc, 343 280 Prototype::Public, 344 281 0, … … 347 284 false, // isVirtual 348 285 false, // isOverride 286 "", 349 287 true, // isAutoGeneration 350 temporary,351 288 -1 352 289 ); 353 290 } 354 291 355 356 return true;357 }358 bool CClass::Implements( const char *interfaceNames, int nowLine )359 {360 Jenga::Common::Strings paramStrs;361 SplitParameter( interfaceNames, paramStrs );362 363 BOOST_FOREACH( const std::string ¶mStr, paramStrs )364 {365 char className[VN_SIZE];366 Jenga::Common::Strings typeParameterStrings;367 SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings );368 369 Types actualTypeParameters;370 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )371 {372 Type type;373 compiler.StringToType( typeParameterStr, type );374 actualTypeParameters.push_back( type );375 }376 377 //継承元クラスを取得378 const CClass *pInterfaceClass = compiler.GetObjectModule().meta.GetClasses().Find( className );379 if( !pInterfaceClass ){380 compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine);381 continue;382 }383 384 // インターフェイスを継承する385 Implements( *pInterfaceClass, actualTypeParameters, nowLine );386 }387 292 388 293 return true; … … 419 324 CreateMember( accessibility, isConst, isRef, buffer, nowLine ) 420 325 ); 421 }422 423 void CClass::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,424 bool isVirtual, bool isOverride, bool isAutoGeneration, char *buffer, int nowLine){425 int i,i2;426 char temporary[VN_SIZE];427 428 i=2;429 for(i2=0;;i++,i2++){430 if(buffer[i]=='('||buffer[i]=='\0'){431 temporary[i2]=0;432 break;433 }434 temporary[i2]=buffer[i];435 }436 437 438 //関数ハッシュへ登録439 char interfaceName[VN_SIZE] = "";440 UserProc *pUserProc = compiler.GetObjectModule().meta.GetUserProcs().AddUserProc( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0), interfaceName );441 if(!pUserProc) return;442 443 if( isAutoGeneration )444 {445 // コード自動生成446 pUserProc->ThisIsAutoGenerationProc();447 }448 449 450 ////////////////////////////////////////////////////////////451 // コンストラクタ、デストラクタの場合の処理452 ////////////////////////////////////////////////////////////453 BOOL fConstructor=0,bDestructor=0;454 455 if(lstrcmp(temporary,pobj_c->GetName().c_str())==0){456 //コンストラクタの場合457 458 //標準コンストラクタ(引数なし)459 if(pUserProc->Params().size()==0) fConstructor=1;460 461 //強制的にConst修飾子をつける462 isConst = true;463 }464 else if(temporary[0]=='~'){465 //デストラクタの場合はその名前が正しいかチェックを行う466 if(lstrcmp(temporary+1,pobj_c->GetName().c_str())!=0)467 compiler.errorMessenger.Output(117,NULL,nowLine);468 else469 bDestructor=1;470 }471 if(fConstructor||bDestructor){472 // コンストラクタ、デストラクタのアクセシビリティをチェック473 474 //強制的にConst修飾子をつける475 isConst = true;476 }477 478 if( fConstructor == 1 )479 pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );480 else if( bDestructor )481 pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );482 483 484 485 //////////////////486 // 重複チェック487 //////////////////488 489 if(pobj_c->DupliCheckMember(temporary)){490 compiler.errorMessenger.Output(15,temporary,nowLine);491 return;492 }493 494 //メソッド495 BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() )496 {497 //基底クラスと重複する場合はオーバーライドを行う498 if( pMethod->GetInheritsClassPtr() ) continue;499 500 if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) )501 {502 //関数名、パラメータ、戻り値が合致したとき503 compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);504 return;505 }506 }507 508 //仮想関数の場合509 if( isAbstract ) pUserProc->CompleteCompile();510 511 // メソッドのオーバーライド512 CMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );513 if( pMethodForOverride )514 {515 pMethodForOverride->Override( pUserProc, accessibility, isOverride );516 pUserProc->SetMethod( pMethodForOverride );517 return;518 }519 else520 {521 // インターフェイス メソッドのオーバーライド522 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )523 {524 if( interfaceName[0] )525 {526 if( pInterface->GetClass().GetName() != interfaceName )527 {528 // 指定されたインターフェイス名と整合しないとき529 continue;530 }531 }532 533 if( !pInterface->GetClass().IsReady() ){534 // インターフェイスが未解析のとき535 compiler.GetObjectModule().meta.GetClasses().LookaheadClass( pInterface->GetClass().GetName().c_str() );536 }537 538 CMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );539 if( pMethodForOverride )540 {541 pMethodForOverride->Override( pUserProc, accessibility, isOverride );542 pUserProc->SetMethod( pMethodForOverride );543 return;544 }545 }546 }547 548 if( interfaceName[0] )549 {550 compiler.errorMessenger.Output(139,interfaceName,nowLine);551 }552 553 if( isVirtual ){554 pobj_c->AddVtblNum( 1 );555 }556 557 if( isOverride ){558 compiler.errorMessenger.Output(12,"Override",nowLine);559 }560 561 if(bStatic){562 pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility );563 }564 else{565 pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);566 }567 326 } 568 327
Note:
See TracChangeset
for help on using the changeset viewer.