Changeset 511 in dev for trunk/ab5.0/abdev/BasicCompiler_Common
- Timestamp:
- Apr 30, 2008, 8:04:04 PM (17 years ago)
- Location:
- trunk/ab5.0/abdev/BasicCompiler_Common
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/Subroutine.cpp
r507 r511 321 321 322 322 return true; 323 }324 325 void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs )326 {327 extern HANDLE hHeap;328 int i,i2,i3;329 char temporary[8192];330 331 // 名前空間管理332 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();333 namespaceScopes.clear();334 335 // Importsされた名前空間の管理336 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();337 importedNamespaces.clear();338 339 i=-1;340 while(1){341 i++;342 343 if(source[i]==1&&(source[i+1]==ESC_CLASS||source[i+1]==ESC_INTERFACE)){344 /* Class ~ End Class345 Interface ~ End Interface346 を飛び越す */347 i3=GetEndXXXCommand(source[i+1]);348 for(i+=2,i2=0;;i++,i2++){349 if(source[i]=='\0') break;350 if(source[i]==1&&source[i+1]==(char)i3){351 i++;352 break;353 }354 }355 if(source[i]=='\0') break;356 continue;357 }358 359 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){360 for(i+=2,i2=0;;i2++,i++){361 if( IsCommandDelimitation( source[i] ) ){362 temporary[i2]=0;363 break;364 }365 temporary[i2]=source[i];366 }367 namespaceScopes.push_back( temporary );368 369 continue;370 }371 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){372 if( namespaceScopes.size() <= 0 ){373 compiler.errorMessenger.Output(12, "End Namespace", i );374 }375 else{376 namespaceScopes.pop_back();377 }378 379 i += 2;380 continue;381 }382 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){383 for(i+=2,i2=0;;i2++,i++){384 if( IsCommandDelimitation( source[i] ) ){385 temporary[i2]=0;386 break;387 }388 temporary[i2]=source[i];389 }390 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )391 {392 compiler.errorMessenger.Output(64,temporary,cp );393 }394 395 continue;396 }397 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){398 importedNamespaces.clear();399 continue;400 }401 402 if(source[i]==1&&source[i+1]==ESC_DECLARE){403 for(i+=2,i2=0;;i2++,i++){404 if(source[i]=='\n'){405 temporary[i2]=0;406 break;407 }408 temporary[i2]=source[i];409 if(source[i]=='\0') break;410 }411 dllProcs.Add(namespaceScopes,temporary,i);412 413 continue;414 }415 if(source[i]==1&&(source[i+1]==ESC_SUB||source[i+1]==ESC_FUNCTION||source[i+1]==ESC_MACRO)){416 char statementChar = source[i+1];417 418 for(i2=0;;i2++,i++){419 if(IsCommandDelimitation(source[i])){420 temporary[i2]=0;421 break;422 }423 temporary[i2]=source[i];424 if(source[i]=='\0') break;425 }426 userProcs.AddUserProc(namespaceScopes, importedNamespaces, temporary,i,false,NULL,false);427 428 /* Sub ~ End Sub429 Function ~ End Function430 Macro ~ End Macro431 を飛び越す */432 char endStatementChar = GetEndXXXCommand( statementChar );433 for(i2=0;;i++,i2++){434 if( source[i] == '\0' ) break;435 if( source[i] == 1 && source[i+1] == endStatementChar ){436 i++;437 break;438 }439 }440 if(source[i]=='\0') break;441 continue;442 }443 444 //次の行445 for(;;i++){446 if(IsCommandDelimitation(source[i])) break;447 }448 if(source[i]=='\0') break;449 }450 451 ////////////452 // 特殊関数453 ////////////454 namespaceScopes.clear();455 importedNamespaces.clear();456 457 compiler.globalAreaProcName = "_System_GlobalArea_" + compiler.GetModuleName();458 sprintf(temporary,"%c%c%s()",1,ESC_SUB,compiler.globalAreaProcName.c_str());459 userProcs.AddUserProc( namespaceScopes, importedNamespaces, temporary,0,false,NULL,false);460 323 } 461 324 -
trunk/ab5.0/abdev/BasicCompiler_Common/include/Class.h
r510 r511 411 411 412 412 // クラス継承 413 bool Inherits( const char *inheritNames, int nowLine );414 413 bool InheritsClass( const CClass &inheritsClass, const Types &actualTypeParameters, int nowLine ); 415 bool InheritsInterface( const CClass &inheritsClass, int nowLine );416 414 417 415 // インターフェイス実装 418 416 bool Implements( const CClass &interfaceClass, const Types &actualTypeParameters, int nowLine ); 419 bool Implements( const char *interfaceNames, int nowLine );420 417 421 418 //メンバ、メソッドの追加 … … 423 420 void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine ); 424 421 void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ); 425 426 void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,427 bool isVirtual, bool isOverride, bool isAutoGeneration, char *buffer, int nowLine);428 422 429 423 //重複チェック … … 593 587 bool Insert( CClass *pClass, int nowLine ); 594 588 CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine); 595 virtual void CollectClassesForNameOnly( const BasicSource &source );596 589 597 590 // vtblを一時的に生成 … … 603 596 virtual void InitStaticMember(); 604 597 605 private:606 bool MemberVar_LoopRefCheck(const CClass &objClass);607 public:608 virtual void GetClass_recur(const char *lpszInheritsClass);609 void LookaheadClass( const char *className );610 bool LoopRefCheck( const CClass &objClass );611 virtual void GetAllClassInfo();612 598 virtual void Compile_System_InitializeUserTypes(); 613 599 virtual void Compile_System_InitializeUserTypesForBaseType(); -
trunk/ab5.0/abdev/BasicCompiler_Common/include/LexicalAnalyzer.h
r508 r511 7 7 { 8 8 public: 9 10 // 名前空間を収集 9 11 static bool CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection ); 12 13 // フルネーム識別子をシンボルに変換する 10 14 static Symbol FullNameToSymbol( const char *fullName ); 11 15 static Symbol FullNameToSymbol( const std::string &fullName ); 16 17 // クラスの名前情報を収集する 18 static void CollectClassesForNameOnly( const char *source, Classes &classes ); 19 20 // クラスを収集する 21 static void AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, 22 bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine); 23 static bool Inherits( CClass ¤tClass, const char *inheritNames, int nowLine ); 24 static bool Implements( CClass ¤tClass, const char *interfaceNames, int nowLine ); 25 static void LookaheadClass( const char *className, Classes &classes ); 26 static bool LoopRefCheck( const CClass &objClass ); 27 static void CollectClasses( const char *source, Classes &classes ); 28 29 // グローバルプロシージャを収集する 30 static UserProc* ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName = NULL ); 31 static void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs ); 12 32 }; 13 33 -
trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h
r382 r511 180 180 public: 181 181 182 UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport , int id)182 UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ) 183 183 : Procedure( namespaceScopes, name, kind, isCdecl ) 184 184 , importedNamespaces( importedNamespaces ) … … 187 187 , pMethod( NULL ) 188 188 , isMacro( isMacro ) 189 , secondParmNum( 0 ) 190 , realSecondParmNum( 1 ) 189 191 , isExport( isExport ) 190 192 , isSystem( false ) … … 193 195 , beginOpAddress( 0 ) 194 196 , endOpAddress( 0 ) 195 , id( id ) 196 { 197 { 198 static int id_base=0; 199 id = ( id_base ++ ); 197 200 } 198 201 UserProc() … … 204 207 delete pParam; 205 208 } 209 } 210 211 void SetReturnType( const Type &newReturnType ) 212 { 213 returnType = newReturnType; 206 214 } 207 215 … … 244 252 return realParams; 245 253 } 254 void SetRealParams( const Parameters ¶ms ) 255 { 256 realParams = params; 257 } 246 258 int GetRealSecondParmNum() const 247 259 { … … 396 408 class UserProcs : public Jenga::Common::Hashmap<UserProc> 397 409 { 398 std::vector<std::string> macroNames;399 400 410 // XMLシリアライズ用 401 411 private: … … 407 417 ar & boost::serialization::make_nvp("Hashmap_UserProcImpl", 408 418 boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this)); 409 ar & BOOST_SERIALIZATION_NVP( macroNames );410 419 } 411 420 … … 420 429 421 430 bool Insert( UserProc *pUserProc, int nowLine ); 422 423 UserProc *AddUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName = NULL );424 431 425 432 void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs ); … … 511 518 }; 512 519 513 void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );514 515 520 class ProcPointer : public Procedure 516 521 { -
trunk/ab5.0/abdev/BasicCompiler_Common/include/Variable.h
r509 r511 57 57 58 58 public: 59 Variable( const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ) 60 : Symbol( ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( name ) ) 61 , type( type ) 62 , isConst( isConst ) 63 , isRef( isRef ) 64 , isArray( false ) 65 , isParameter( false) 66 , paramStrForConstructor( paramStrForConstructor ) 67 , hasInitData( hasInitData ) 68 { 69 } 70 Variable( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ) 71 : Symbol( namespaceScopes, name ) 72 , type( type ) 73 , isConst( isConst ) 74 , isRef( isRef ) 75 , isArray( false ) 76 , isParameter( false) 77 , paramStrForConstructor( paramStrForConstructor ) 78 , hasInitData( hasInitData ) 79 { 80 } 81 Variable( const Variable &var ) 82 : Symbol( var ) 83 , type( var.type ) 84 , isConst( var.isConst ) 85 , isRef( var.isRef ) 86 , isArray( var.isArray ) 87 , subscripts( var.subscripts ) 88 , isParameter( false ) 89 , paramStrForConstructor( var.paramStrForConstructor ) 90 , hasInitData( var.hasInitData ) 91 { 92 } 93 Variable() 94 { 95 } 96 ~Variable() 97 { 98 } 59 Variable( const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ); 60 Variable( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ); 61 Variable( const Variable &var ); 62 Variable(); 99 63 100 64 void SetArray( const Subscripts &subscripts ){ -
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 -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Class_Collect.cpp
r507 r511 11 11 #include "../../compiler_x86/opcode.h" 12 12 #endif 13 14 using namespace ActiveBasic::Compiler; 13 15 14 16 … … 70 72 CLoopRefCheck *pobj_LoopRefCheck; 71 73 72 73 void Classes::CollectClassesForNameOnly( const BasicSource &source ) 74 { 75 int i, i2; 76 char temporary[VN_SIZE]; 77 78 // 名前空間管理 79 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(); 80 namespaceScopes.clear(); 81 82 // Importsされた名前空間の管理 83 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces(); 84 importedNamespaces.clear(); 85 86 for(i=0;;i++){ 87 if(source[i]=='\0') break; 88 89 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 90 for(i+=2,i2=0;;i2++,i++){ 91 if( IsCommandDelimitation( source[i] ) ){ 92 temporary[i2]=0; 93 break; 94 } 95 temporary[i2]=source[i]; 96 } 97 namespaceScopes.push_back( temporary ); 98 99 continue; 100 } 101 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ 102 if( namespaceScopes.size() <= 0 ){ 103 compiler.errorMessenger.Output(12, "End Namespace", i ); 104 } 105 else{ 106 namespaceScopes.pop_back(); 107 } 108 109 i += 2; 110 continue; 111 } 112 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ 113 for(i+=2,i2=0;;i2++,i++){ 114 if( IsCommandDelimitation( source[i] ) ){ 115 temporary[i2]=0; 116 break; 117 } 118 temporary[i2]=source[i]; 119 } 120 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) 121 { 122 compiler.errorMessenger.Output(64,temporary,i ); 123 } 124 125 continue; 126 } 127 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ 128 importedNamespaces.clear(); 129 continue; 130 } 131 132 if(source[i]==1&&( 133 source[i+1]==ESC_CLASS|| 134 source[i+1]==ESC_TYPE|| 135 source[i+1]==ESC_INTERFACE 136 )) 137 { 138 int nowLine = i; 139 i += 2; 140 141 Type blittableType; 142 if(memicmp(source.GetBuffer()+i,"Align(",6)==0){ 143 //アラインメント修飾子 144 i+=6; 145 i=JumpStringInPare(source.GetBuffer(),i)+1; 146 } 147 else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){ 148 // Blittable修飾子 149 i+=10; 150 i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1; 151 compiler.StringToType( temporary, blittableType ); 152 } 153 154 bool isEnum = false; 155 bool isDelegate = false; 156 if( source[i] == 1 && source[i+1] == ESC_ENUM ){ 157 // 列挙型の場合 158 isEnum = true; 159 160 i += 2; 161 } 162 else if( source[i] == 1 && source[i+1] == ESC_DELEGATE ) 163 { 164 // デリゲートの場合 165 isDelegate = true; 166 167 i += 2; 168 } 169 170 for(i2=0;;i++,i2++){ 171 if(!IsVariableChar(source[i])){ 172 temporary[i2]=0; 173 break; 174 } 175 temporary[i2]=source[i]; 176 } 177 178 //クラスを追加 179 CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine); 180 if( pClass ){ 181 if( source[nowLine+1] == ESC_CLASS ){ 182 if( isEnum ) 183 { 184 pClass->SetClassType( CClass::Enum ); 185 } 186 else if( isDelegate ) 187 { 188 pClass->SetClassType( CClass::Delegate ); 189 } 190 else{ 191 pClass->SetClassType( CClass::Class ); 192 } 193 } 194 else if( source[nowLine+1] == ESC_INTERFACE ){ 195 pClass->SetClassType( CClass::Interface ); 196 } 197 else{ 198 pClass->SetClassType( CClass::Structure ); 199 } 200 } 201 202 // Blittable型の場合 203 if( !blittableType.IsNull() ){ 204 pClass->SetBlittableType( blittableType ); 205 206 // Blittable型として登録 207 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) ); 208 } 209 } 210 } 211 } 212 213 bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){ 74 bool MemberVar_LoopRefCheck(const CClass &objClass){ 214 75 if( objClass.HasSuperClass() ) 215 76 { … … 246 107 } 247 108 248 void Classes::GetClass_recur(const char *lpszInheritsClass){ 109 void LexicalAnalyzer::AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract, 110 bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine) 111 { 112 if( isAutoGeneration ) 113 { 114 // コード自動生成 115 pUserProc->ThisIsAutoGenerationProc(); 116 } 117 118 119 //////////////////////////////////////////////////////////// 120 // コンストラクタ、デストラクタの場合の処理 121 //////////////////////////////////////////////////////////// 122 BOOL fConstructor=0,bDestructor=0; 123 124 if( pUserProc->GetName() == pobj_c->GetName() ){ 125 //コンストラクタの場合 126 127 //標準コンストラクタ(引数なし) 128 if(pUserProc->Params().size()==0) fConstructor=1; 129 130 //強制的にConst修飾子をつける 131 isConst = true; 132 } 133 else if(pUserProc->GetName()[0]=='~'){ 134 //デストラクタの場合はその名前が正しいかチェックを行う 135 if(lstrcmp(pUserProc->GetName().c_str()+1,pobj_c->GetName().c_str())!=0) 136 compiler.errorMessenger.Output(117,NULL,nowLine); 137 else 138 bDestructor=1; 139 } 140 if(fConstructor||bDestructor){ 141 // コンストラクタ、デストラクタのアクセシビリティをチェック 142 143 //強制的にConst修飾子をつける 144 isConst = true; 145 } 146 147 if( fConstructor == 1 ) 148 pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() ); 149 else if( bDestructor ) 150 pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() ); 151 152 153 154 ////////////////// 155 // 重複チェック 156 ////////////////// 157 158 if(pobj_c->DupliCheckMember( pUserProc->GetName().c_str() )){ 159 compiler.errorMessenger.Output(15,pUserProc->GetName(),nowLine); 160 return; 161 } 162 163 //メソッド 164 BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() ) 165 { 166 //基底クラスと重複する場合はオーバーライドを行う 167 if( pMethod->GetInheritsClassPtr() ) continue; 168 169 if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) ) 170 { 171 //関数名、パラメータ、戻り値が合致したとき 172 compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine); 173 return; 174 } 175 } 176 177 //仮想関数の場合 178 if( isAbstract ) pUserProc->CompleteCompile(); 179 180 // メソッドのオーバーライド 181 CMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ); 182 if( pMethodForOverride ) 183 { 184 pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 185 pUserProc->SetMethod( pMethodForOverride ); 186 return; 187 } 188 else 189 { 190 // インターフェイス メソッドのオーバーライド 191 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() ) 192 { 193 if( interfaceName[0] ) 194 { 195 if( pInterface->GetClass().GetName() != interfaceName ) 196 { 197 // 指定されたインターフェイス名と整合しないとき 198 continue; 199 } 200 } 201 202 if( !pInterface->GetClass().IsReady() ){ 203 // インターフェイスが未解析のとき 204 LexicalAnalyzer::LookaheadClass( 205 pInterface->GetClass().GetName().c_str(), 206 compiler.GetObjectModule().meta.GetClasses() 207 ); 208 } 209 210 CMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc ); 211 if( pMethodForOverride ) 212 { 213 pMethodForOverride->Override( pUserProc, accessibility, isOverride ); 214 pUserProc->SetMethod( pMethodForOverride ); 215 return; 216 } 217 } 218 } 219 220 if( interfaceName[0] ) 221 { 222 compiler.errorMessenger.Output(139,interfaceName,nowLine); 223 } 224 225 if( isVirtual ){ 226 pobj_c->AddVtblNum( 1 ); 227 } 228 229 if( isOverride ){ 230 compiler.errorMessenger.Output(12,"Override",nowLine); 231 } 232 233 if(bStatic){ 234 pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility ); 235 } 236 else{ 237 pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual); 238 } 239 } 240 241 bool LexicalAnalyzer::Inherits( CClass ¤tClass, const char *inheritNames, int nowLine ){ 242 int i = 0; 243 bool isInheritsClass = false; 244 while( true ){ 245 246 char temporary[VN_SIZE]; 247 for( int i2=0;; i++, i2++ ){ 248 if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){ 249 temporary[i2] = 0; 250 break; 251 } 252 temporary[i2] = inheritNames[i]; 253 } 254 255 // ジェネリクス構文を分解 256 char className[VN_SIZE]; 257 Jenga::Common::Strings typeParameterStrings; 258 SplitGenericClassInstance( temporary, className, typeParameterStrings ); 259 260 // 型パラメータ文字列から型データを取得 261 Types actualTypeParameters; 262 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings ) 263 { 264 Type type; 265 compiler.StringToType( typeParameterStr, type ); 266 actualTypeParameters.push_back( type ); 267 } 268 269 //継承元クラスを取得 270 const CClass *pInheritsClass = compiler.GetObjectModule().meta.GetClasses().Find(className); 271 if( !pInheritsClass ){ 272 compiler.errorMessenger.Output(106,className,nowLine); 273 return false; 274 } 275 276 if( pInheritsClass->IsClass() ){ 277 // クラスを継承する 278 isInheritsClass = true; 279 280 //ループ継承でないかをチェック 281 if( !LexicalAnalyzer::LoopRefCheck(*pInheritsClass) ) 282 { 283 compiler.errorMessenger.Output(123,pInheritsClass->GetName(),nowLine); 284 return false; 285 } 286 287 if( !pInheritsClass->IsReady() ){ 288 //継承先が読み取られていないとき 289 LexicalAnalyzer::LookaheadClass( 290 pInheritsClass->GetName().c_str(), 291 compiler.GetObjectModule().meta.GetClasses() 292 ); 293 } 294 295 if( !currentClass.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){ 296 return false; 297 } 298 } 299 else{ 300 compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine); 301 return false; 302 } 303 304 if( inheritNames[i] == '\0' ){ 305 break; 306 } 307 i++; 308 } 309 310 if( !isInheritsClass ){ 311 const CClass *pObjectClass = compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr(); 312 //ループ継承でないかをチェック 313 if( !LexicalAnalyzer::LoopRefCheck( *pObjectClass ) ) 314 { 315 compiler.errorMessenger.Output(123,pObjectClass->GetName(),nowLine); 316 return false; 317 } 318 319 if( !pObjectClass->IsReady() ){ 320 //継承先が読み取られていないとき 321 LexicalAnalyzer::LookaheadClass( 322 pObjectClass->GetName().c_str(), 323 compiler.GetObjectModule().meta.GetClasses() 324 ); 325 } 326 327 // クラスを一つも継承していないとき 328 if( !currentClass.InheritsClass( *pObjectClass, Types(), nowLine ) ){ 329 return false; 330 } 331 } 332 333 return true; 334 } 335 336 bool LexicalAnalyzer::Implements( CClass ¤tClass, const char *interfaceNames, int nowLine ) 337 { 338 Jenga::Common::Strings paramStrs; 339 SplitParameter( interfaceNames, paramStrs ); 340 341 BOOST_FOREACH( const std::string ¶mStr, paramStrs ) 342 { 343 char className[VN_SIZE]; 344 Jenga::Common::Strings typeParameterStrings; 345 SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings ); 346 347 Types actualTypeParameters; 348 BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings ) 349 { 350 Type type; 351 compiler.StringToType( typeParameterStr, type ); 352 actualTypeParameters.push_back( type ); 353 } 354 355 //継承元クラスを取得 356 const CClass *pInterfaceClass = compiler.GetObjectModule().meta.GetClasses().Find( className ); 357 if( !pInterfaceClass ){ 358 compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine); 359 continue; 360 } 361 362 if( !pInterfaceClass->IsReady() ){ 363 // インターフェイスが未解析のとき 364 LexicalAnalyzer::LookaheadClass( 365 pInterfaceClass->GetName().c_str(), 366 compiler.GetObjectModule().meta.GetClasses() 367 ); 368 } 369 370 // インターフェイスを継承する 371 currentClass.Implements( *pInterfaceClass, actualTypeParameters, nowLine ); 372 } 373 374 return true; 375 } 376 377 void GetClass_recur( const char *lpszInheritsClass, Classes &classes ) 378 { 249 379 extern char *basbuf; 250 380 int i,i2,i3,sub_address,top_pos; … … 331 461 SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames ); 332 462 333 CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );463 CClass *pobj_c = const_cast<CClass *>( classes.Find(namespaceScopes, className) ); 334 464 if(!pobj_c) continue; 335 465 … … 352 482 for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ ) 353 483 { 354 Type baseType( DEF_OBJECT, * GetObjectClassPtr() );484 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() ); 355 485 if( typeParameterBaseClassNames[i2].size() ) 356 486 { … … 398 528 399 529 //継承元クラスを取得 400 const Classes &classes = *this;401 530 const CClass *pInheritsClass = classes.Find(temporary); 402 531 if( !pInheritsClass ){ 403 532 compiler.errorMessenger.Output(106,temporary,i); 533 goto Interface_InheritsError; 534 } 535 536 //ループ継承でないかをチェック 537 if( !LexicalAnalyzer::LoopRefCheck( *pInheritsClass ) ) 538 { 539 compiler.errorMessenger.Output(123,pInheritsClass->GetName(),i); 404 540 goto Interface_InheritsError; 405 541 } … … 469 605 } 470 606 471 //メンバ関数を追加 472 pobj_c->AddMethod(pobj_c, 473 Prototype::Public, //Publicアクセス権 474 0, // bStatic 475 false, // isConst 476 true, // isAbstract 477 true, // isVirtual 478 false, // isOverride 479 false, // isAutoGeneration 480 temporary, 481 sub_address 482 ); 607 //関数ハッシュへ登録 608 char interfaceName[VN_SIZE] = ""; 609 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,true,pobj_c, false, interfaceName ); 610 if( pUserProc ) 611 { 612 compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, i ); 613 614 //メンバ関数を追加 615 LexicalAnalyzer::AddMethod(pobj_c, 616 pUserProc, 617 Prototype::Public, //Publicアクセス権 618 0, // bStatic 619 false, // isConst 620 true, // isAbstract 621 true, // isVirtual 622 false, // isOverride 623 interfaceName, 624 false, // isAutoGeneration 625 sub_address 626 ); 627 } 483 628 } 484 629 } … … 540 685 SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames ); 541 686 542 CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );687 CClass *pobj_c = const_cast<CClass *>( classes.Find(namespaceScopes, className) ); 543 688 if(!pobj_c) continue; 544 689 … … 552 697 } 553 698 699 if( lstrcmp(className,"Control")==0) 700 { 701 int test=0; 702 } 703 554 704 if(pobj_c->IsReady()){ 555 705 //既に先読みされているとき … … 562 712 for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ ) 563 713 { 564 Type baseType( DEF_OBJECT, * GetObjectClassPtr() );714 Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() ); 565 715 if( typeParameterBaseClassNames[i2].size() ) 566 716 { … … 624 774 lstrcpy( temporary, "Object" ); 625 775 } 626 pobj_c->Inherits(temporary, i );776 LexicalAnalyzer::Inherits( *pobj_c, temporary, i ); 627 777 628 778 if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS ) … … 632 782 GetCommandToken( temporary, basbuf, i ); 633 783 634 pobj_c->Implements(temporary, i );784 LexicalAnalyzer::Implements( *pobj_c, temporary, i ); 635 785 } 636 786 } … … 761 911 if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){ 762 912 //参照先が読み取られていないとき 763 GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str());913 GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes ); 764 914 } 765 915 } … … 779 929 } 780 930 else{ 781 //メソッドを追加 782 cp=i; //エラー用 783 pobj_c->AddMethod(pobj_c, 784 accessibility, 785 bStatic, 786 isConst, 787 isAbstract, 788 isVirtual, 789 isOverride, 790 false, 791 temporary, 792 sub_address); 931 //関数ハッシュへ登録 932 char interfaceName[VN_SIZE] = ""; 933 UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,isVirtual,pobj_c, (bStatic!=0), interfaceName ); 934 if( pUserProc ) 935 { 936 compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, i ); 937 938 //メソッドを追加 939 cp=i; //エラー用 940 LexicalAnalyzer::AddMethod(pobj_c, 941 pUserProc, 942 accessibility, 943 bStatic, 944 isConst, 945 isAbstract, 946 isVirtual, 947 isOverride, 948 interfaceName, 949 false, 950 sub_address); 951 } 793 952 794 953 if( isAbstract ) continue; … … 831 990 } 832 991 833 void Classes::LookaheadClass( const char *className)992 void LexicalAnalyzer::LookaheadClass( const char *className, Classes &classes ) 834 993 { 835 994 pobj_LoopRefCheck->add( className ); 836 compiler.GetObjectModule().meta.GetClasses().GetClass_recur( className);995 GetClass_recur( className, classes ); 837 996 pobj_LoopRefCheck->del( className ); 838 997 } 839 998 840 bool Classes::LoopRefCheck( const CClass &objClass )999 bool LexicalAnalyzer::LoopRefCheck( const CClass &objClass ) 841 1000 { 842 1001 if( pobj_LoopRefCheck->check( objClass ) ) … … 848 1007 } 849 1008 850 void Classes::GetAllClassInfo(void){1009 void LexicalAnalyzer::CollectClasses( const char *source, Classes &classes ){ 851 1010 //ループ継承チェック用のクラス 852 1011 pobj_LoopRefCheck=new CLoopRefCheck(); 853 1012 854 1013 //クラスを取得 855 GetClass_recur( 0);1014 GetClass_recur( 0, classes ); 856 1015 857 1016 delete pobj_LoopRefCheck; … … 859 1018 860 1019 // イテレータの準備 861 this->Iterator_Init();1020 classes.Iterator_Init(); 862 1021 } -
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp
r508 r511 67 67 return FullNameToSymbol( fullName.c_str() ); 68 68 } 69 70 void LexicalAnalyzer::CollectClassesForNameOnly( const char *source, Classes &classes ) 71 { 72 int i, i2; 73 char temporary[VN_SIZE]; 74 75 // 名前空間管理 76 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(); 77 namespaceScopes.clear(); 78 79 // Importsされた名前空間の管理 80 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces(); 81 importedNamespaces.clear(); 82 83 for(i=0;;i++){ 84 if(source[i]=='\0') break; 85 86 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 87 for(i+=2,i2=0;;i2++,i++){ 88 if( IsCommandDelimitation( source[i] ) ){ 89 temporary[i2]=0; 90 break; 91 } 92 temporary[i2]=source[i]; 93 } 94 namespaceScopes.push_back( temporary ); 95 96 continue; 97 } 98 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ 99 if( namespaceScopes.size() <= 0 ){ 100 compiler.errorMessenger.Output(12, "End Namespace", i ); 101 } 102 else{ 103 namespaceScopes.pop_back(); 104 } 105 106 i += 2; 107 continue; 108 } 109 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ 110 for(i+=2,i2=0;;i2++,i++){ 111 if( IsCommandDelimitation( source[i] ) ){ 112 temporary[i2]=0; 113 break; 114 } 115 temporary[i2]=source[i]; 116 } 117 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) 118 { 119 compiler.errorMessenger.Output(64,temporary,i ); 120 } 121 122 continue; 123 } 124 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ 125 importedNamespaces.clear(); 126 continue; 127 } 128 129 if(source[i]==1&&( 130 source[i+1]==ESC_CLASS|| 131 source[i+1]==ESC_TYPE|| 132 source[i+1]==ESC_INTERFACE 133 )) 134 { 135 int nowLine = i; 136 i += 2; 137 138 Type blittableType; 139 if(memicmp(source+i,"Align(",6)==0){ 140 //アラインメント修飾子 141 i+=6; 142 i=JumpStringInPare(source,i)+1; 143 } 144 else if( memicmp( source + i, "Blittable(", 10 ) == 0 ){ 145 // Blittable修飾子 146 i+=10; 147 i+=GetStringInPare_RemovePare(temporary,source+i)+1; 148 compiler.StringToType( temporary, blittableType ); 149 } 150 151 bool isEnum = false; 152 bool isDelegate = false; 153 if( source[i] == 1 && source[i+1] == ESC_ENUM ){ 154 // 列挙型の場合 155 isEnum = true; 156 157 i += 2; 158 } 159 else if( source[i] == 1 && source[i+1] == ESC_DELEGATE ) 160 { 161 // デリゲートの場合 162 isDelegate = true; 163 164 i += 2; 165 } 166 167 for(i2=0;;i++,i2++){ 168 if(!IsVariableChar(source[i])){ 169 temporary[i2]=0; 170 break; 171 } 172 temporary[i2]=source[i]; 173 } 174 175 //クラスを追加 176 CClass *pClass = classes.Add(namespaceScopes, importedNamespaces, temporary,nowLine); 177 if( pClass ){ 178 if( source[nowLine+1] == ESC_CLASS ){ 179 if( isEnum ) 180 { 181 pClass->SetClassType( CClass::Enum ); 182 } 183 else if( isDelegate ) 184 { 185 pClass->SetClassType( CClass::Delegate ); 186 } 187 else{ 188 pClass->SetClassType( CClass::Class ); 189 } 190 } 191 else if( source[nowLine+1] == ESC_INTERFACE ){ 192 pClass->SetClassType( CClass::Interface ); 193 } 194 else{ 195 pClass->SetClassType( CClass::Structure ); 196 } 197 } 198 199 // Blittable型の場合 200 if( !blittableType.IsNull() ){ 201 pClass->SetBlittableType( blittableType ); 202 203 // Blittable型として登録 204 compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) ); 205 } 206 } 207 } 208 } 209 210 UserProc* LexicalAnalyzer::ParseUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName ) 211 { 212 int i2,i3; 213 char temporary[8192]; 214 215 int i=1; 216 217 Procedure::Kind kind = Procedure::Sub; 218 bool isMacro = false; 219 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function; 220 if(buffer[i]==ESC_MACRO){ 221 isMacro = true; 222 } 223 224 i++; 225 226 bool isCdecl = false; 227 bool isExport = false; 228 while(1){ 229 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){ 230 isCdecl = true; 231 232 i+=2; 233 } 234 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){ 235 isExport = true; 236 237 i+=2; 238 } 239 else break; 240 } 241 242 i2=0; 243 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){ 244 if(!pobj_c){ 245 compiler.errorMessenger.Output(126,NULL,nowLine); 246 return 0; 247 } 248 249 //オペレータの場合 250 temporary[i2++]=buffer[i++]; 251 temporary[i2++]=buffer[i++]; 252 253 int iCalcId; 254 if(buffer[i]=='='&&buffer[i+1]=='='){ 255 iCalcId=CALC_EQUAL; 256 i3=2; 257 } 258 else if(buffer[i]=='='){ 259 iCalcId=CALC_SUBSITUATION; 260 i3=1; 261 } 262 else if(buffer[i]=='('){ 263 iCalcId=CALC_AS; 264 i3=0; 265 } 266 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){ 267 iCalcId=CALC_ARRAY_SET; 268 i3=3; 269 } 270 else if(buffer[i]=='['&&buffer[i+1]==']'){ 271 iCalcId=CALC_ARRAY_GET; 272 i3=2; 273 } 274 else{ 275 iCalcId=GetCalcId(buffer+i,&i3); 276 i3++; 277 } 278 if(!iCalcId){ 279 compiler.errorMessenger.Output(1,NULL,nowLine); 280 return 0; 281 } 282 temporary[i2++]=iCalcId; 283 temporary[i2]=0; 284 285 i+=i3; 286 } 287 else{ 288 if(pobj_c){ 289 //クラスメンバの場合、デストラクタには~が付くことを考慮 290 if(buffer[i]=='~'){ 291 temporary[i2]='~'; 292 i++; 293 i2++; 294 } 295 } 296 297 for(;;i++,i2++){ 298 if(!IsVariableChar(buffer[i])){ 299 temporary[i2]=0; 300 break; 301 } 302 temporary[i2]=buffer[i]; 303 } 304 305 char parentName[VN_SIZE], memberName[VN_SIZE]; 306 ReferenceKind refKind; 307 if( SplitMemberName( temporary, parentName, memberName, refKind ) ) 308 { 309 if( pobj_c ) 310 { 311 if( interfaceName ) 312 { 313 lstrcpy( interfaceName, parentName ); 314 } 315 else 316 { 317 compiler.errorMessenger.OutputFatalError(); 318 return NULL; 319 } 320 321 char dummyMemberName[VN_SIZE]; 322 if( SplitMemberName( memberName, parentName, dummyMemberName, refKind ) ) 323 { 324 compiler.errorMessenger.Output(69,temporary,nowLine); 325 return NULL; 326 } 327 } 328 else 329 { 330 compiler.errorMessenger.Output(68,temporary,nowLine); 331 return NULL; 332 } 333 334 lstrcpy( temporary, memberName ); 335 } 336 } 337 338 if( isMacro ){ 339 //大文字に変換 340 CharUpper(temporary); 341 } 342 343 if(!pobj_c){ 344 //クラスメンバ以外の場合のみ 345 //重複チェック 346 347 if(GetDeclareHash(temporary)){ 348 compiler.errorMessenger.Output(15,temporary,nowLine); 349 return 0; 350 } 351 } 352 353 UserProc *pUserProc = new UserProc( namespaceScopes, importedNamespaces, temporary, kind, isMacro, isCdecl, isExport ); 354 pUserProc->SetParentClass( pobj_c ); 355 356 // 親インターフェイスをセット 357 if( interfaceName && interfaceName[0] ) 358 { 359 ::Interface *pTargetInterface = NULL; 360 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() ) 361 { 362 if( pInterface->GetClass().GetName() == interfaceName ) 363 { 364 pTargetInterface = pInterface; 365 break; 366 } 367 } 368 pUserProc->SetInterface( pTargetInterface ); 369 } 370 371 if(isExport){ 372 pUserProc->Using(); 373 } 374 375 // パラメータを解析 376 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 377 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic ); 378 379 pUserProc->_paramStr = buffer + i; 380 381 return pUserProc; 382 } 383 384 void LexicalAnalyzer::CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs ) 385 { 386 extern HANDLE hHeap; 387 int i,i2,i3; 388 char temporary[8192]; 389 390 // 名前空間管理 391 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes(); 392 namespaceScopes.clear(); 393 394 // Importsされた名前空間の管理 395 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces(); 396 importedNamespaces.clear(); 397 398 i=-1; 399 while(1){ 400 i++; 401 402 if(source[i]==1&&(source[i+1]==ESC_CLASS||source[i+1]==ESC_INTERFACE)){ 403 /* Class ~ End Class 404 Interface ~ End Interface 405 を飛び越す */ 406 i3=GetEndXXXCommand(source[i+1]); 407 for(i+=2,i2=0;;i++,i2++){ 408 if(source[i]=='\0') break; 409 if(source[i]==1&&source[i+1]==(char)i3){ 410 i++; 411 break; 412 } 413 } 414 if(source[i]=='\0') break; 415 continue; 416 } 417 418 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 419 for(i+=2,i2=0;;i2++,i++){ 420 if( IsCommandDelimitation( source[i] ) ){ 421 temporary[i2]=0; 422 break; 423 } 424 temporary[i2]=source[i]; 425 } 426 namespaceScopes.push_back( temporary ); 427 428 continue; 429 } 430 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){ 431 if( namespaceScopes.size() <= 0 ){ 432 compiler.errorMessenger.Output(12, "End Namespace", i ); 433 } 434 else{ 435 namespaceScopes.pop_back(); 436 } 437 438 i += 2; 439 continue; 440 } 441 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){ 442 for(i+=2,i2=0;;i2++,i++){ 443 if( IsCommandDelimitation( source[i] ) ){ 444 temporary[i2]=0; 445 break; 446 } 447 temporary[i2]=source[i]; 448 } 449 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) ) 450 { 451 compiler.errorMessenger.Output(64,temporary,cp ); 452 } 453 454 continue; 455 } 456 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){ 457 importedNamespaces.clear(); 458 continue; 459 } 460 461 if(source[i]==1&&source[i+1]==ESC_DECLARE){ 462 for(i+=2,i2=0;;i2++,i++){ 463 if(source[i]=='\n'){ 464 temporary[i2]=0; 465 break; 466 } 467 temporary[i2]=source[i]; 468 if(source[i]=='\0') break; 469 } 470 dllProcs.Add(namespaceScopes,temporary,i); 471 472 continue; 473 } 474 if(source[i]==1&&(source[i+1]==ESC_SUB||source[i+1]==ESC_FUNCTION||source[i+1]==ESC_MACRO)){ 475 char statementChar = source[i+1]; 476 477 for(i2=0;;i2++,i++){ 478 if(IsCommandDelimitation(source[i])){ 479 temporary[i2]=0; 480 break; 481 } 482 temporary[i2]=source[i]; 483 if(source[i]=='\0') break; 484 } 485 486 UserProc *pUserProc = ParseUserProc( namespaceScopes, importedNamespaces, temporary, i, false, NULL, false ); 487 userProcs.Insert( pUserProc, i ); 488 489 /* Sub ~ End Sub 490 Function ~ End Function 491 Macro ~ End Macro 492 を飛び越す */ 493 char endStatementChar = GetEndXXXCommand( statementChar ); 494 for(i2=0;;i++,i2++){ 495 if( source[i] == '\0' ) break; 496 if( source[i] == 1 && source[i+1] == endStatementChar ){ 497 i++; 498 break; 499 } 500 } 501 if(source[i]=='\0') break; 502 continue; 503 } 504 505 //次の行 506 for(;;i++){ 507 if(IsCommandDelimitation(source[i])) break; 508 } 509 if(source[i]=='\0') break; 510 } 511 512 //////////// 513 // 特殊関数 514 //////////// 515 namespaceScopes.clear(); 516 importedNamespaces.clear(); 517 518 compiler.globalAreaProcName = "_System_GlobalArea_" + compiler.GetModuleName(); 519 sprintf(temporary,"%c%c%s()",1,ESC_SUB,compiler.globalAreaProcName.c_str()); 520 UserProc *pUserProc = ParseUserProc( namespaceScopes, importedNamespaces, temporary, 0, false, NULL, false ); 521 userProcs.Insert( pUserProc, i ); 522 } -
trunk/ab5.0/abdev/BasicCompiler_Common/src/ObjectModule.cpp
r510 r511 52 52 #include <Hashmap.h> 53 53 #include <Configuration.h> 54 #include <Class.h> 55 #include <Procedure.h> 54 56 #include <LexicalAnalyzer.h> 55 57 #include <Program.h> -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Procedure.cpp
r509 r511 502 502 return true; 503 503 } 504 UserProc *UserProcs::AddUserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic, char *interfaceName ) 505 { 506 int i2,i3; 507 char temporary[8192]; 508 509 int i=1; 510 511 Procedure::Kind kind = Procedure::Sub; 512 bool isMacro = false; 513 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function; 514 if(buffer[i]==ESC_MACRO){ 515 isMacro = true; 516 } 517 518 i++; 519 520 bool isCdecl = false; 521 bool isExport = false; 522 while(1){ 523 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){ 524 isCdecl = true; 525 526 i+=2; 527 } 528 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){ 529 isExport = true; 530 531 i+=2; 532 } 533 else break; 534 } 535 536 i2=0; 537 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){ 538 if(!pobj_c){ 539 compiler.errorMessenger.Output(126,NULL,nowLine); 540 return 0; 541 } 542 543 //オペレータの場合 544 temporary[i2++]=buffer[i++]; 545 temporary[i2++]=buffer[i++]; 546 547 int iCalcId; 548 if(buffer[i]=='='&&buffer[i+1]=='='){ 549 iCalcId=CALC_EQUAL; 550 i3=2; 551 } 552 else if(buffer[i]=='='){ 553 iCalcId=CALC_SUBSITUATION; 554 i3=1; 555 } 556 else if(buffer[i]=='('){ 557 iCalcId=CALC_AS; 558 i3=0; 559 } 560 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){ 561 iCalcId=CALC_ARRAY_SET; 562 i3=3; 563 } 564 else if(buffer[i]=='['&&buffer[i+1]==']'){ 565 iCalcId=CALC_ARRAY_GET; 566 i3=2; 567 } 568 else{ 569 iCalcId=GetCalcId(buffer+i,&i3); 570 i3++; 571 } 572 if(!iCalcId){ 573 compiler.errorMessenger.Output(1,NULL,nowLine); 574 return 0; 575 } 576 temporary[i2++]=iCalcId; 577 temporary[i2]=0; 578 579 i+=i3; 580 } 581 else{ 582 if(pobj_c){ 583 //クラスメンバの場合、デストラクタには~が付くことを考慮 584 if(buffer[i]=='~'){ 585 temporary[i2]='~'; 586 i++; 587 i2++; 588 } 589 } 590 591 for(;;i++,i2++){ 592 if(!IsVariableChar(buffer[i])){ 593 temporary[i2]=0; 594 break; 595 } 596 temporary[i2]=buffer[i]; 597 } 598 599 char parentName[VN_SIZE], memberName[VN_SIZE]; 600 ReferenceKind refKind; 601 if( SplitMemberName( temporary, parentName, memberName, refKind ) ) 602 { 603 if( pobj_c ) 604 { 605 if( interfaceName ) 606 { 607 lstrcpy( interfaceName, parentName ); 608 } 609 else 610 { 611 compiler.errorMessenger.OutputFatalError(); 612 return NULL; 613 } 614 615 char dummyMemberName[VN_SIZE]; 616 if( SplitMemberName( memberName, parentName, dummyMemberName, refKind ) ) 617 { 618 compiler.errorMessenger.Output(69,temporary,nowLine); 619 return NULL; 620 } 621 } 622 else 623 { 624 compiler.errorMessenger.Output(68,temporary,nowLine); 625 return NULL; 626 } 627 628 lstrcpy( temporary, memberName ); 629 } 630 } 631 632 if( isMacro ){ 633 //大文字に変換 634 CharUpper(temporary); 635 636 //マクロ関数の場合は名前リストに追加 637 macroNames.push_back( temporary ); 638 } 639 640 if(!pobj_c){ 641 //クラスメンバ以外の場合のみ 642 //重複チェック 643 644 if(GetDeclareHash(temporary)){ 645 compiler.errorMessenger.Output(15,temporary,nowLine); 646 return 0; 647 } 648 } 649 650 // 識別ID 651 static int id_base=0; 652 653 UserProc *pUserProc = new UserProc( namespaceScopes, importedNamespaces, temporary, kind, isMacro, isCdecl, isExport, (id_base++) ); 654 pUserProc->SetParentClass( pobj_c ); 655 656 // 親インターフェイスをセット 657 if( interfaceName && interfaceName[0] ) 658 { 659 ::Interface *pTargetInterface = NULL; 660 BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() ) 661 { 662 if( pInterface->GetClass().GetName() == interfaceName ) 663 { 664 pTargetInterface = pInterface; 665 break; 666 } 667 } 668 pUserProc->SetInterface( pTargetInterface ); 669 } 670 671 if(isExport){ 672 pUserProc->Using(); 673 } 674 675 // パラメータを解析 676 // ※第1パラメータにに指定するデータの例:"( s As String ) As String" 677 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic ); 678 679 pUserProc->_paramStr = buffer + i; 680 681 // ハッシュに追加 682 if( !Insert( pUserProc, nowLine ) ) 683 { 684 return NULL; 685 } 686 687 return pUserProc; 688 } 504 689 505 void UserProcs::EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs ) 690 506 { -
trunk/ab5.0/abdev/BasicCompiler_Common/src/Variable.cpp
r461 r511 4 4 #include <Variable.h> 5 5 6 /* 7 TODO: 消す 8 bool Variable::IsEqualSymbol( const Symbol &symbol, bool isSupportStaticMember ) const 6 Variable::Variable( const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ) 7 : Symbol( ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( name ) ) 8 , type( type ) 9 , isConst( isConst ) 10 , isRef( isRef ) 11 , isArray( false ) 12 , isParameter( false) 13 , paramStrForConstructor( paramStrForConstructor ) 14 , hasInitData( hasInitData ) 9 15 { 10 if( GetName() == symbol.GetName() 11 && compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->GetNamespaceScopes(), symbol.GetNamespaceScopes() ) ) 12 { 13 return true; 14 } 15 16 if( isSupportStaticMember && symbol.GetNamespaceScopes().size() >= 1 ) 17 { 18 // 静的メンバを考慮 19 NamespaceScopes namespaceScopes( symbol.GetNamespaceScopes() ); 20 string name = namespaceScopes[namespaceScopes.size()-1] + "." + symbol.GetName(); 21 namespaceScopes.pop_back(); 22 23 return IsEqualSymbol( Symbol( namespaceScopes, name ), false ); 24 } 25 return false; 26 }*/ 16 } 17 Variable::Variable( const NamespaceScopes &namespaceScopes, const string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData ) 18 : Symbol( namespaceScopes, name ) 19 , type( type ) 20 , isConst( isConst ) 21 , isRef( isRef ) 22 , isArray( false ) 23 , isParameter( false) 24 , paramStrForConstructor( paramStrForConstructor ) 25 , hasInitData( hasInitData ) 26 { 27 } 28 Variable::Variable( const Variable &var ) 29 : Symbol( var ) 30 , type( var.type ) 31 , isConst( var.isConst ) 32 , isRef( var.isRef ) 33 , isArray( var.isArray ) 34 , subscripts( var.subscripts ) 35 , isParameter( false ) 36 , paramStrForConstructor( var.paramStrForConstructor ) 37 , hasInitData( var.hasInitData ) 38 { 39 } 40 Variable::Variable() 41 { 42 } 27 43 28 44
Note:
See TracChangeset
for help on using the changeset viewer.