Index: BasicCompiler_Common/Class.cpp
===================================================================
--- BasicCompiler_Common/Class.cpp	(revision 89)
+++ BasicCompiler_Common/Class.cpp	(revision 90)
@@ -146,15 +146,20 @@
 
 
-
-CClass::CClass(const char *name){
-	memset(this,0,sizeof(CClass));
-
-	vtbl_offset=-1;
-
+CClass::CClass(const char *name):
+	ConstructorMemberSubIndex( 0 ),
+	DestructorMemberSubIndex( 0 ),
+	classType( Class ),
+	pobj_InheritsClass( NULL ),
+	ppobj_Member( NULL ),
+	iMemberNum( 0 ),
+	vtbl_num( 0 ),
+	iAlign( 0 ),
+	vtbl_offset( -1 ),
+	isCompilingConstructor( false ),
+	isCompilingDestructor( false ),
+	pobj_NextClass( NULL )
+{
 	this->name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
 	lstrcpy(this->name,name);
-
-	isCompilingConstructor = false;
-	isCompilingDestructor = false;
 }
 CClass::~CClass(){
@@ -189,4 +194,20 @@
 }
 
+bool CClass::IsClass() const
+{
+	return classType == CClass::Class;
+}
+bool CClass::IsInterface() const
+{
+	return classType == CClass::Interface;
+}
+bool CClass::IsEnum() const
+{
+	return classType == CClass::Enum;
+}
+bool CClass::IsDelegate() const
+{
+	return classType == CClass::Delegate;
+}
 bool CClass::IsStructure() const
 {
@@ -194,5 +215,18 @@
 }
 
-void CClass::Inherits( CClass *pInheritsClass ){
+bool CClass::Inherits( CClass &inheritsClass, int nowLine ){
+
+	//ループ継承でないかをチェック
+	if(pobj_LoopRefCheck->check(inheritsClass)){
+		SetError(123,inheritsClass.name,nowLine);
+		return false;
+	}
+
+	if( inheritsClass.ppobj_Member == 0 ){
+		//継承先が読み取られていないとき
+		pobj_LoopRefCheck->add(this->name);
+		pobj_DBClass->GetClass_recur(inheritsClass.name);
+		pobj_LoopRefCheck->del(this->name);
+	}
 
 	//メンバをコピー
@@ -201,17 +235,18 @@
 		0,
 		ppobj_Member,
-		pInheritsClass->iMemberNum*sizeof(CMember *));
-	iMemberNum=pInheritsClass->iMemberNum;
-	for(int i3=0;i3<pInheritsClass->iMemberNum;i3++){
-		ppobj_Member[i3]=new CMember( *pInheritsClass->ppobj_Member[i3] );
+		( iMemberNum + inheritsClass.iMemberNum )*sizeof(CMember *));
+	for(int i3=0;i3<inheritsClass.iMemberNum;i3++){
+		ppobj_Member[iMemberNum]=new CMember( *inheritsClass.ppobj_Member[i3] );
 
 		//dwAccess
-		if(pInheritsClass->ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE)
-			ppobj_Member[i3]->dwAccess=ACCESS_NON;
-		else ppobj_Member[i3]->dwAccess=pInheritsClass->ppobj_Member[i3]->dwAccess;
+		if(inheritsClass.ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE)
+			ppobj_Member[iMemberNum]->dwAccess=ACCESS_NON;
+		else ppobj_Member[iMemberNum]->dwAccess=inheritsClass.ppobj_Member[i3]->dwAccess;
+
+		iMemberNum++;
 	}
 
 	//メソッドをコピー
-	foreach( CMethod *baseMethod, pInheritsClass->methods ){
+	foreach( CMethod *baseMethod, inheritsClass.methods ){
 		CMethod *method = new CMethod( baseMethod );
 
@@ -224,5 +259,5 @@
 		// ※継承元のClassIndexをセット（入れ子継承を考慮する）
 		if(baseMethod->pobj_InheritsClass==0)
-			method->pobj_InheritsClass=pInheritsClass;
+			method->pobj_InheritsClass=&inheritsClass;
 		else
 			method->pobj_InheritsClass=
@@ -233,8 +268,56 @@
 
 	//仮想関数の数
-	vtbl_num=pInheritsClass->vtbl_num;
+	vtbl_num += inheritsClass.vtbl_num;
 
 	//継承先のクラスをメンバとして保持する
-	pobj_InheritsClass = pInheritsClass;
+	pobj_InheritsClass = &inheritsClass;
+
+	return true;
+}
+bool CClass::InheritsInterface( CClass &inheritsInterface, int nowLine ){
+
+	//ループ継承でないかをチェック
+	if(pobj_LoopRefCheck->check(inheritsInterface)){
+		SetError(123,inheritsInterface.name,nowLine);
+		return false;
+	}
+
+	if( inheritsInterface.ppobj_Member == 0 ){
+		//継承先が読み取られていないとき
+		pobj_LoopRefCheck->add(this->name);
+		pobj_DBClass->GetClass_recur(inheritsInterface.name);
+		pobj_LoopRefCheck->del(this->name);
+	}
+
+	//メソッドをコピー
+	foreach( CMethod *baseMethod, inheritsInterface.methods ){
+		CMethod *method = new CMethod( baseMethod );
+
+		//dwAccess
+		if(baseMethod->dwAccess==ACCESS_PRIVATE)
+			method->dwAccess=ACCESS_NON;
+		else method->dwAccess=baseMethod->dwAccess;
+
+		//pobj_Inherits
+		// ※継承元のClassIndexをセット（入れ子継承を考慮する）
+		if(baseMethod->pobj_InheritsClass==0)
+			method->pobj_InheritsClass=&inheritsInterface;
+		else
+			method->pobj_InheritsClass=
+				baseMethod->pobj_InheritsClass;
+
+		methods.push_back( method );
+	}
+
+	//仮想関数の数
+	vtbl_num += inheritsInterface.vtbl_num;
+
+	/*
+	TODO: インターフェイス向けの機構を作る
+	//継承先のクラスをメンバとして保持する
+	pobj_InheritsClass = &inheritsInterface;
+	*/
+
+	return true;
 }
 void CClass::AddMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer ){
@@ -950,5 +1033,5 @@
 		if(pMember->IsStruct()){
 			//循環参照でないかをチェック
-			if(pobj_LoopRefCheck->check(pMember->GetClass().name)){
+			if(pobj_LoopRefCheck->check(pMember->GetClass())){
 				extern int cp;
 				SetError(124,pMember->GetClass().name,cp);
@@ -1035,19 +1118,8 @@
 				}
 
-				//ループ継承でないかをチェック
-				if(pobj_LoopRefCheck->check(temporary)){
-					SetError(123,temporary,i);
+				//継承させる
+				if( !pobj_c->InheritsInterface( *pInheritsClass, i ) ){
 					goto Interface_InheritsError;
 				}
-
-				if( pInheritsClass->ppobj_Member == 0 ){
-					//継承先が読み取られていないとき
-					pobj_LoopRefCheck->add(pobj_c->name);
-					GetClass_recur(temporary);
-					pobj_LoopRefCheck->del(pobj_c->name);
-				}
-
-				//継承させる
-				pobj_c->Inherits( pInheritsClass );
 			}
 			else{
@@ -1207,19 +1279,21 @@
 				}
 
-				//ループ継承でないかをチェック
-				if(pobj_LoopRefCheck->check(temporary)){
-					SetError(123,temporary,i);
+				if( pInheritsClass->IsInterface() ){
+					// クラスを継承していないとき
+					CClass *pObjectClass = check("Object");
+					if( !pObjectClass ){
+						SetError(106,"Object",i);
+						goto InheritsError;
+					}
+
+					if( !pobj_c->Inherits( *pObjectClass, i ) ){
+						goto InheritsError;
+					}
+				}
+
+				//継承させる
+				if( !pobj_c->Inherits( *pInheritsClass, i ) ){
 					goto InheritsError;
 				}
-
-				if( pInheritsClass->ppobj_Member == 0 ){
-					//継承先が読み取られていないとき
-					pobj_LoopRefCheck->add(pobj_c->name);
-					GetClass_recur(temporary);
-					pobj_LoopRefCheck->del(pobj_c->name);
-				}
-
-				//継承させる
-				pobj_c->Inherits( pInheritsClass );
 			}
 InheritsError:
@@ -1425,4 +1499,5 @@
 
 void CDBClass::Compile_System_InitializeUserTypes(){
+	char temporary[VN_SIZE];
 
 	////////////////////////////////////////////////////////////////////
@@ -1436,5 +1511,4 @@
 		CClass *pClass = Iterator_GetNext();
 
-		char temporary[VN_SIZE];
 		sprintf( temporary
 			, "Add(%c%c_System_TypeForClass(\"%s\",\"%s\"))"
@@ -1451,4 +1525,48 @@
 		ReallocNativeCodeBuffer();
 	}
+
+
+	////////////////////////////////////////////////////////////////////
+	// 基底クラスを登録
+	////////////////////////////////////////////////////////////////////
+
+	sprintf(temporary, "%c%ctempType=Nothing%c%cTypeBaseImpl"
+		, HIBYTE( COM_DIM )
+		, LOBYTE( COM_DIM )
+		, 1
+		, ESC_AS
+		);
+	ChangeOpcode( temporary );
+
+	// イテレータをリセット
+	Iterator_Reset();
+
+	while( Iterator_HasNext() ){
+		CClass *pClass = Iterator_GetNext();
+
+		if( pClass->pobj_InheritsClass ){
+			sprintf( temporary
+				, "tempType=Search(\"%s\",\"%s\")"
+				, ""				// 名前空間 (TODO: 実装)
+				, pClass->name		// クラス名
+				);
+
+			// コンパイル
+			ChangeOpcode( temporary );
+
+			sprintf( temporary
+				, "tempType.SetBaseType(Search(\"%s\",\"%s\"))"
+				, ""								// 名前空間 (TODO: 実装)
+				, pClass->pobj_InheritsClass->name	// 基底クラス名
+				);
+
+			// コンパイル
+			ChangeOpcode( temporary );
+		}
+
+		// ネイティブコードバッファの再確保
+		ReallocNativeCodeBuffer();
+	}
+
 
 
