Index: trunk/ab5.0/abdev/BasicCompiler_Common/src/Class_Collect.cpp
===================================================================
--- trunk/ab5.0/abdev/BasicCompiler_Common/src/Class_Collect.cpp	(revision 507)
+++ trunk/ab5.0/abdev/BasicCompiler_Common/src/Class_Collect.cpp	(revision 511)
@@ -11,4 +11,6 @@
 #include "../../compiler_x86/opcode.h"
 #endif
+
+using namespace ActiveBasic::Compiler;
 
 
@@ -70,146 +72,5 @@
 CLoopRefCheck *pobj_LoopRefCheck;
 
-
-void Classes::CollectClassesForNameOnly( const BasicSource &source )
-{
-	int i, i2;
-	char temporary[VN_SIZE];
-
-	// 名前空間管理
-	NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
-	namespaceScopes.clear();
-
-	// Importsされた名前空間の管理
-	NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
-	importedNamespaces.clear();
-
-	for(i=0;;i++){
-		if(source[i]=='\0') break;
-
-		if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			namespaceScopes.push_back( temporary );
-
-			continue;
-		}
-		else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
-			if( namespaceScopes.size() <= 0 ){
-				compiler.errorMessenger.Output(12, "End Namespace", i );
-			}
-			else{
-				namespaceScopes.pop_back();
-			}
-
-			i += 2;
-			continue;
-		}
-		else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
-			for(i+=2,i2=0;;i2++,i++){
-				if( IsCommandDelimitation( source[i] ) ){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-			if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
-			{
-				compiler.errorMessenger.Output(64,temporary,i );
-			}
-
-			continue;
-		}
-		else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
-			importedNamespaces.clear();
-			continue;
-		}
-
-		if(source[i]==1&&(
-			source[i+1]==ESC_CLASS||
-			source[i+1]==ESC_TYPE||
-			source[i+1]==ESC_INTERFACE
-			))
-		{
-			int nowLine = i;
-			i += 2;
-
-			Type blittableType;
-			if(memicmp(source.GetBuffer()+i,"Align(",6)==0){
-				//アラインメント修飾子
-				i+=6;
-				i=JumpStringInPare(source.GetBuffer(),i)+1;
-			}
-			else if( memicmp( source.GetBuffer() + i, "Blittable(", 10 ) == 0 ){
-				// Blittable修飾子
-				i+=10;
-				i+=GetStringInPare_RemovePare(temporary,source.GetBuffer()+i)+1;
-				compiler.StringToType( temporary, blittableType );
-			}
-
-			bool isEnum = false;
-			bool isDelegate = false;
-			if( source[i] == 1 && source[i+1] == ESC_ENUM ){
-				// 列挙型の場合
-				isEnum = true;
-
-				i += 2;
-			}
-			else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
-			{
-				// デリゲートの場合
-				isDelegate = true;
-
-				i += 2;
-			}
-
-			for(i2=0;;i++,i2++){
-				if(!IsVariableChar(source[i])){
-					temporary[i2]=0;
-					break;
-				}
-				temporary[i2]=source[i];
-			}
-
-			//クラスを追加
-			CClass *pClass = this->Add(namespaceScopes, importedNamespaces, temporary,nowLine);
-			if( pClass ){
-				if( source[nowLine+1] == ESC_CLASS ){
-					if( isEnum )
-					{
-						pClass->SetClassType( CClass::Enum );
-					}
-					else if( isDelegate )
-					{
-						pClass->SetClassType( CClass::Delegate );
-					}
-					else{
-						pClass->SetClassType( CClass::Class );
-					}
-				}
-				else if( source[nowLine+1] == ESC_INTERFACE ){
-					pClass->SetClassType( CClass::Interface );
-				}
-				else{
-					pClass->SetClassType( CClass::Structure );
-				}
-			}
-
-			// Blittable型の場合
-			if( !blittableType.IsNull() ){
-				pClass->SetBlittableType( blittableType );
-
-				// Blittable型として登録
-				compiler.GetObjectModule().meta.GetBlittableTypes().push_back( BlittableType( blittableType, pClass ) );
-			}
-		}
-	}
-}
-
-bool Classes::MemberVar_LoopRefCheck(const CClass &objClass){
+bool MemberVar_LoopRefCheck(const CClass &objClass){
 	if( objClass.HasSuperClass() )
 	{
@@ -246,5 +107,274 @@
 }
 
-void Classes::GetClass_recur(const char *lpszInheritsClass){
+void LexicalAnalyzer::AddMethod(CClass *pobj_c, UserProc *pUserProc, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
+	bool isVirtual, bool isOverride, const char *interfaceName, bool isAutoGeneration, int nowLine)
+{
+	if( isAutoGeneration )
+	{
+		// コード自動生成
+		pUserProc->ThisIsAutoGenerationProc();
+	}
+
+
+	////////////////////////////////////////////////////////////
+	// コンストラクタ、デストラクタの場合の処理
+	////////////////////////////////////////////////////////////
+	BOOL fConstructor=0,bDestructor=0;
+
+	if( pUserProc->GetName() == pobj_c->GetName() ){
+		//コンストラクタの場合
+
+		//標準コンストラクタ（引数なし）
+		if(pUserProc->Params().size()==0) fConstructor=1;
+
+		//強制的にConst修飾子をつける
+		isConst = true;
+	}
+	else if(pUserProc->GetName()[0]=='~'){
+		//デストラクタの場合はその名前が正しいかチェックを行う
+		if(lstrcmp(pUserProc->GetName().c_str()+1,pobj_c->GetName().c_str())!=0)
+			compiler.errorMessenger.Output(117,NULL,nowLine);
+		else
+			bDestructor=1;
+	}
+	if(fConstructor||bDestructor){
+		// コンストラクタ、デストラクタのアクセシビリティをチェック
+
+		//強制的にConst修飾子をつける
+		isConst = true;
+	}
+
+	if( fConstructor == 1 )
+		pobj_c->SetConstructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
+	else if( bDestructor )
+		pobj_c->SetDestructorMemberSubIndex( (int)pobj_c->GetDynamicMethods().size() );
+
+
+
+	//////////////////
+	// 重複チェック
+	//////////////////
+
+	if(pobj_c->DupliCheckMember( pUserProc->GetName().c_str() )){
+		compiler.errorMessenger.Output(15,pUserProc->GetName(),nowLine);
+		return;
+	}
+
+	//メソッド
+	BOOST_FOREACH( const CMethod *pMethod, pobj_c->GetDynamicMethods() )
+	{
+		//基底クラスと重複する場合はオーバーライドを行う
+		if( pMethod->GetInheritsClassPtr() ) continue;
+
+		if( pMethod->GetUserProc().IsEqualForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc ) )
+		{
+			//関数名、パラメータ、戻り値が合致したとき
+			compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);
+			return;
+		}
+	}
+
+	//仮想関数の場合
+	if( isAbstract ) pUserProc->CompleteCompile();
+
+	// メソッドのオーバーライド
+	CMethod *pMethodForOverride = pobj_c->GetDynamicMethods().FindForOverride( pobj_c->GetSuperClassActualTypeParameters(), pUserProc );
+	if( pMethodForOverride )
+	{
+		pMethodForOverride->Override( pUserProc, accessibility, isOverride );
+		pUserProc->SetMethod( pMethodForOverride );
+		return;
+	}
+	else
+	{
+		// インターフェイス メソッドのオーバーライド
+		BOOST_FOREACH( ::Interface *pInterface, pobj_c->GetInterfaces() )
+		{
+			if( interfaceName[0] )
+			{
+				if( pInterface->GetClass().GetName() != interfaceName )
+				{
+					// 指定されたインターフェイス名と整合しないとき
+					continue;
+				}
+			}
+
+			if( !pInterface->GetClass().IsReady() ){
+				// インターフェイスが未解析のとき
+				LexicalAnalyzer::LookaheadClass(
+					pInterface->GetClass().GetName().c_str(),
+					compiler.GetObjectModule().meta.GetClasses()
+				);
+			}
+
+			CMethod *pMethodForOverride = pInterface->GetDynamicMethods().FindForOverride( pInterface->GetActualTypeParameters(), pUserProc );
+			if( pMethodForOverride )
+			{
+				pMethodForOverride->Override( pUserProc, accessibility, isOverride );
+				pUserProc->SetMethod( pMethodForOverride );
+				return;
+			}
+		}
+	}
+
+	if( interfaceName[0] )
+	{
+		compiler.errorMessenger.Output(139,interfaceName,nowLine);
+	}
+
+	if( isVirtual ){
+		pobj_c->AddVtblNum( 1 );
+	}
+
+	if( isOverride ){
+		compiler.errorMessenger.Output(12,"Override",nowLine);
+	}
+
+	if(bStatic){
+		pobj_c->GetStaticMethods().AddStatic( pUserProc, accessibility );
+	}
+	else{
+		pobj_c->GetDynamicMethods().Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
+	}
+}
+
+bool LexicalAnalyzer::Inherits( CClass &currentClass, const char *inheritNames, int nowLine ){
+	int i = 0;
+	bool isInheritsClass = false;
+	while( true ){
+
+		char temporary[VN_SIZE];
+		for( int i2=0;; i++, i2++ ){
+			if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
+				temporary[i2] = 0;
+				break;
+			}
+			temporary[i2] = inheritNames[i];
+		}
+
+		// ジェネリクス構文を分解
+		char className[VN_SIZE];
+		Jenga::Common::Strings typeParameterStrings;
+		SplitGenericClassInstance( temporary, className, typeParameterStrings );
+
+		// 型パラメータ文字列から型データを取得
+		Types actualTypeParameters;
+		BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
+		{
+			Type type;
+			compiler.StringToType( typeParameterStr, type );
+			actualTypeParameters.push_back( type );
+		}
+
+		//継承元クラスを取得
+		const CClass *pInheritsClass = compiler.GetObjectModule().meta.GetClasses().Find(className);
+		if( !pInheritsClass ){
+			compiler.errorMessenger.Output(106,className,nowLine);
+			return false;
+		}
+
+		if( pInheritsClass->IsClass() ){
+			// クラスを継承する
+			isInheritsClass = true;
+
+			//ループ継承でないかをチェック
+			if( !LexicalAnalyzer::LoopRefCheck(*pInheritsClass) )
+			{
+				compiler.errorMessenger.Output(123,pInheritsClass->GetName(),nowLine);
+				return false;
+			}
+
+			if( !pInheritsClass->IsReady() ){
+				//継承先が読み取られていないとき
+				LexicalAnalyzer::LookaheadClass(
+					pInheritsClass->GetName().c_str(),
+					compiler.GetObjectModule().meta.GetClasses()
+				);
+			}
+
+			if( !currentClass.InheritsClass( *pInheritsClass, actualTypeParameters, nowLine ) ){
+				return false;
+			}
+		}
+		else{
+			compiler.errorMessenger.Output(135,pInheritsClass->GetFullName().c_str(),nowLine);
+			return false;
+		}
+
+		if( inheritNames[i] == '\0' ){
+			break;
+		}
+		i++;
+	}
+
+	if( !isInheritsClass ){
+		const CClass *pObjectClass = compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr();
+		//ループ継承でないかをチェック
+		if( !LexicalAnalyzer::LoopRefCheck( *pObjectClass ) )
+		{
+			compiler.errorMessenger.Output(123,pObjectClass->GetName(),nowLine);
+			return false;
+		}
+
+		if( !pObjectClass->IsReady() ){
+			//継承先が読み取られていないとき
+			LexicalAnalyzer::LookaheadClass(
+				pObjectClass->GetName().c_str(),
+				compiler.GetObjectModule().meta.GetClasses()
+			);
+		}
+
+		// クラスを一つも継承していないとき
+		if( !currentClass.InheritsClass( *pObjectClass, Types(), nowLine ) ){
+			return false;
+		}
+	}
+
+	return true;
+}
+
+bool LexicalAnalyzer::Implements( CClass &currentClass, const char *interfaceNames, int nowLine )
+{
+	Jenga::Common::Strings paramStrs;
+	SplitParameter( interfaceNames, paramStrs );
+	
+	BOOST_FOREACH( const std::string &paramStr, paramStrs )
+	{
+		char className[VN_SIZE];
+		Jenga::Common::Strings typeParameterStrings;
+		SplitGenericClassInstance( paramStr.c_str(), className, typeParameterStrings );
+
+		Types actualTypeParameters;
+		BOOST_FOREACH( const std::string &typeParameterStr, typeParameterStrings )
+		{
+			Type type;
+			compiler.StringToType( typeParameterStr, type );
+			actualTypeParameters.push_back( type );
+		}
+
+		//継承元クラスを取得
+		const CClass *pInterfaceClass = compiler.GetObjectModule().meta.GetClasses().Find( className );
+		if( !pInterfaceClass ){
+			compiler.errorMessenger.Output(106,paramStr.c_str(),nowLine);
+			continue;
+		}
+
+		if( !pInterfaceClass->IsReady() ){
+			// インターフェイスが未解析のとき
+			LexicalAnalyzer::LookaheadClass(
+				pInterfaceClass->GetName().c_str(),
+				compiler.GetObjectModule().meta.GetClasses()
+			);
+		}
+
+		// インターフェイスを継承する
+		currentClass.Implements( *pInterfaceClass, actualTypeParameters, nowLine );
+	}
+
+	return true;
+}
+
+void GetClass_recur( const char *lpszInheritsClass, Classes &classes )
+{
 	extern char *basbuf;
 	int i,i2,i3,sub_address,top_pos;
@@ -331,5 +461,5 @@
 			SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
 
-			CClass *pobj_c = const_cast<CClass *>( this->Find(namespaceScopes, className) );
+			CClass *pobj_c = const_cast<CClass *>( classes.Find(namespaceScopes, className) );
 			if(!pobj_c) continue;
 
@@ -352,5 +482,5 @@
 			for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
 			{
-				Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
+				Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
 				if( typeParameterBaseClassNames[i2].size() )
 				{
@@ -398,8 +528,14 @@
 
 				//継承元クラスを取得
-				const Classes &classes = *this;
 				const CClass *pInheritsClass = classes.Find(temporary);
 				if( !pInheritsClass ){
 					compiler.errorMessenger.Output(106,temporary,i);
+					goto Interface_InheritsError;
+				}
+
+				//ループ継承でないかをチェック
+				if( !LexicalAnalyzer::LoopRefCheck( *pInheritsClass ) )
+				{
+					compiler.errorMessenger.Output(123,pInheritsClass->GetName(),i);
 					goto Interface_InheritsError;
 				}
@@ -469,16 +605,25 @@
 				}
 
-				//メンバ関数を追加
-				pobj_c->AddMethod(pobj_c,
-					Prototype::Public,	//Publicアクセス権
-					0,					// bStatic
-					false,				// isConst
-					true,				// isAbstract
-					true,				// isVirtual
-					false,				// isOverride
-					false,				// isAutoGeneration
-					temporary,
-					sub_address
-					);
+				//関数ハッシュへ登録
+				char interfaceName[VN_SIZE] = "";
+				UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,true,pobj_c, false, interfaceName );
+				if( pUserProc )
+				{
+					compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, i );
+
+					//メンバ関数を追加
+					LexicalAnalyzer::AddMethod(pobj_c,
+						pUserProc,
+						Prototype::Public,	//Publicアクセス権
+						0,					// bStatic
+						false,				// isConst
+						true,				// isAbstract
+						true,				// isVirtual
+						false,				// isOverride
+						interfaceName,
+						false,				// isAutoGeneration
+						sub_address
+						);
+				}
 			}
 		}
@@ -540,5 +685,5 @@
 			SplitGenericClassInstance( temporary, className, typeParameters, true, &typeParameterBaseClassNames );
 
-			CClass *pobj_c =  const_cast<CClass *>( this->Find(namespaceScopes, className) );
+			CClass *pobj_c =  const_cast<CClass *>( classes.Find(namespaceScopes, className) );
 			if(!pobj_c) continue;
 
@@ -552,4 +697,9 @@
 			}
 
+			if( lstrcmp(className,"Control")==0)
+			{
+				int test=0;
+			}
+
 			if(pobj_c->IsReady()){
 				//既に先読みされているとき
@@ -562,5 +712,5 @@
 			for( i2=0; i2<static_cast<int>(typeParameters.size()); i2++ )
 			{
-				Type baseType( DEF_OBJECT, *GetObjectClassPtr() );
+				Type baseType( DEF_OBJECT, *classes.GetObjectClassPtr() );
 				if( typeParameterBaseClassNames[i2].size() )
 				{
@@ -624,5 +774,5 @@
 					lstrcpy( temporary, "Object" );
 				}
-				pobj_c->Inherits( temporary, i );
+				LexicalAnalyzer::Inherits( *pobj_c, temporary, i );
 
 				if( basbuf[i+1] == 1 && basbuf[i+2] == ESC_IMPLEMENTS )
@@ -632,5 +782,5 @@
 					GetCommandToken( temporary, basbuf, i );
 
-					pobj_c->Implements( temporary, i );
+					LexicalAnalyzer::Implements( *pobj_c, temporary, i );
 				}
 			}
@@ -761,5 +911,5 @@
 							if( !pobj_c->GetDynamicMembers().back()->GetType().GetClass().IsReady() ){
 								//参照先が読み取られていないとき
-								GetClass_recur(pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str());
+								GetClass_recur( pobj_c->GetDynamicMembers().back()->GetType().GetClass().GetName().c_str(), classes );
 							}
 						}
@@ -779,16 +929,25 @@
 				}
 				else{
-					//メソッドを追加
-					cp=i;	//エラー用
-					pobj_c->AddMethod(pobj_c,
-						accessibility,
-						bStatic,
-						isConst,
-						isAbstract,
-						isVirtual,
-						isOverride,
-						false,
-						temporary,
-						sub_address);
+					//関数ハッシュへ登録
+					char interfaceName[VN_SIZE] = "";
+					UserProc *pUserProc = LexicalAnalyzer::ParseUserProc( NamespaceScopes(), NamespaceScopesCollection(), temporary,sub_address,isVirtual,pobj_c, (bStatic!=0), interfaceName );
+					if( pUserProc )
+					{
+						compiler.GetObjectModule().meta.GetUserProcs().Insert( pUserProc, i );
+
+						//メソッドを追加
+						cp=i;	//エラー用
+						LexicalAnalyzer::AddMethod(pobj_c,
+							pUserProc,
+							accessibility,
+							bStatic,
+							isConst,
+							isAbstract,
+							isVirtual,
+							isOverride,
+							interfaceName,
+							false,
+							sub_address);
+					}
 
 					if( isAbstract ) continue;
@@ -831,12 +990,12 @@
 }
 
-void Classes::LookaheadClass( const char *className )
+void LexicalAnalyzer::LookaheadClass( const char *className, Classes &classes )
 {
 	pobj_LoopRefCheck->add( className );
-	compiler.GetObjectModule().meta.GetClasses().GetClass_recur( className );
+	GetClass_recur( className, classes );
 	pobj_LoopRefCheck->del( className );
 }
 
-bool Classes::LoopRefCheck( const CClass &objClass )
+bool LexicalAnalyzer::LoopRefCheck( const CClass &objClass )
 {
 	if( pobj_LoopRefCheck->check( objClass ) )
@@ -848,10 +1007,10 @@
 }
 
-void Classes::GetAllClassInfo(void){
+void LexicalAnalyzer::CollectClasses( const char *source, Classes &classes ){
 	//ループ継承チェック用のクラス
 	pobj_LoopRefCheck=new CLoopRefCheck();
 
 	//クラスを取得
-	GetClass_recur(0);
+	GetClass_recur( 0, classes );
 
 	delete pobj_LoopRefCheck;
@@ -859,4 +1018,4 @@
 
 	// イテレータの準備
-	this->Iterator_Init();
+	classes.Iterator_Init();
 }
