Index: trunk/jenga/src/smoothie/Class.cpp
===================================================================
--- trunk/jenga/src/smoothie/Class.cpp	(revision 172)
+++ trunk/jenga/src/smoothie/Class.cpp	(revision 172)
@@ -0,0 +1,880 @@
+#include <stdlib.h>
+
+#include <jenga/include/smoothie/Smoothie.h>
+#include <jenga/include/smoothie/Class.h>
+#include <jenga/include/smoothie/SmoothieException.h>
+
+
+class CLoopRefCheck{
+	char **names;
+	int num;
+	void init(){
+		int i;
+		for(i=0;i<num;i++){
+			free(names[i]);
+		}
+		free(names);
+	}
+public:
+	CLoopRefCheck()
+	{
+		names=(char **)malloc(1);
+		num=0;
+	}
+	~CLoopRefCheck()
+	{
+		init();
+	}
+	void add(const char *lpszInheritsClass)
+	{
+		names=(char **)realloc(names,(num+1)*sizeof(char *));
+		names[num]=(char *)malloc(lstrlen(lpszInheritsClass)+1);
+		lstrcpy(names[num],lpszInheritsClass);
+		num++;
+	}
+	void del(const char *lpszInheritsClass)
+	{
+		int i;
+		for(i=0;i<num;i++){
+			if(lstrcmp(names[i],lpszInheritsClass)==0){
+				free(names[i]);
+				break;
+			}
+		}
+		if(i!=num){
+			num--;
+			for(;i<num;i++){
+				names[i]=names[i+1];
+			}
+		}
+	}
+	BOOL check(const CClass &inheritsClass) const
+	{
+		//ループ継承チェック
+		int i;
+		for(i=0;i<num;i++){
+			if( inheritsClass.GetName() == names[i] ){
+				return 1;
+			}
+		}
+		return 0;
+	}
+};
+CLoopRefCheck *pobj_LoopRefCheck;
+
+
+
+
+CClass::CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name )
+	: isReady( false )
+	, Prototype( namespaceScopes, name )
+	, importedNamespaces( importedNamespaces )
+	, ConstructorMemberSubIndex( 0 )
+	, DestructorMemberSubIndex( 0 )
+	, classType( Class )
+	, pobj_InheritsClass( NULL )
+	, vtblNum( 0 )
+	, iAlign( 0 )
+	, vtbl_offset( -1 )
+	, isCompilingConstructor( false )
+	, isCompilingDestructor( false )
+	, pobj_NextClass( NULL )
+{
+}
+CClass::~CClass(){
+	// 動的メンバ
+	BOOST_FOREACH( CMember *member, dynamicMembers ){
+		delete member;
+	}
+
+	// 静的メンバ
+	BOOST_FOREACH( CMember *member, staticMembers ){
+		delete member;
+	}
+}
+
+bool CClass::IsInheritsInterface( const CClass *pInterfaceClass ) const
+{
+	BOOST_FOREACH( const InheritedInterface &objInterface, interfaces ){
+		if( pInterfaceClass == &objInterface.GetInterfaceClass() ){
+			return true;
+		}
+	}
+	return false;
+}
+
+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
+{
+	return classType == CClass::Structure;
+}
+
+bool CClass::Inherits( 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];
+		}
+
+		//継承元クラスを取得
+		const CClass *pInheritsClass = Smoothie::meta.classes.Find(temporary);
+		if( !pInheritsClass ){
+			throw SmoothieException(106,temporary,nowLine);
+			return false;
+		}
+
+		if( pInheritsClass->IsInterface() ){
+			// インターフェイスはあとで継承する
+		}
+		else if( pInheritsClass->IsClass() ){
+			// クラスを継承する
+			isInheritsClass = true;
+
+			if( !InheritsClass( *pInheritsClass, nowLine ) ){
+				return false;
+			}
+		}
+		else{
+			throw SmoothieException(135,NULL,nowLine);
+			return false;
+		}
+
+		if( inheritNames[i] == '\0' ){
+			break;
+		}
+		i++;
+	}
+
+	if( !isInheritsClass ){
+		// クラスを一つも継承していないとき
+		const CClass *pObjectClass = Smoothie::meta.classes.Find("Object");
+		if( !pObjectClass ){
+			throw SmoothieException(106,"Object",i);
+			return false;
+		}
+
+		if( !InheritsClass( *pObjectClass, nowLine ) ){
+			return false;
+		}
+	}
+
+	i=0;
+	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];
+		}
+
+		//継承元クラスを取得
+		const CClass *pInheritsClass = Smoothie::meta.classes.Find(temporary);
+		if( !pInheritsClass ){
+			throw SmoothieException(106,temporary,nowLine);
+			return false;
+		}
+
+		if( pInheritsClass->IsInterface() ){
+			// インターフェイスを継承する
+			if( !InheritsInterface( *pInheritsClass, nowLine ) ){
+				return false;
+			}
+		}
+		else if( pInheritsClass->IsClass() ){
+			// クラスはさっき継承した
+		}
+		else{
+			throw SmoothieException(135,NULL,nowLine);
+			return false;
+		}
+
+		if( inheritNames[i] == '\0' ){
+			break;
+		}
+		i++;
+	}
+
+	return true;
+}
+/*
+bool CClass::InheritsClass( const CClass &inheritsClass, int nowLine ){
+
+	//ループ継承でないかをチェック
+	if(pobj_LoopRefCheck->check(inheritsClass)){
+		throw SmoothieException(123,inheritsClass.GetName(),nowLine);
+		return false;
+	}
+
+	if( !inheritsClass.IsReady() ){
+		//継承先が読み取られていないとき
+		pobj_LoopRefCheck->add(this->GetName().c_str());
+		Smoothie::meta.classes.GetClass_recur(inheritsClass.GetName().c_str());
+		pobj_LoopRefCheck->del(this->GetName().c_str());
+	}
+
+	//メンバをコピー
+	BOOST_FOREACH( CMember *inheritsClassDynamicMember, inheritsClass.dynamicMembers ){
+		CMember *pMember = new CMember( *inheritsClassDynamicMember );
+
+		// アクセシビリティ
+		if( inheritsClassDynamicMember->IsPrivate() ){
+			pMember->SetAccessibility( Prototype::None );
+		}
+		else{
+			pMember->SetAccessibility( inheritsClassDynamicMember->GetAccessibility() );
+		}
+
+		dynamicMembers.push_back( pMember );
+	}
+
+	//メソッドをコピー
+	BOOST_FOREACH( const CMethod *pBaseMethod, inheritsClass.methods ){
+		CMethod *pMethod = new DynamicMethod( *pBaseMethod );
+
+		// アクセシビリティ
+		if(pBaseMethod->GetAccessibility() == Prototype::Private){
+			pMethod->SetAccessibility( Prototype::None );
+		}
+		else{
+			pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
+		}
+
+		//pobj_Inherits
+		// ※継承元のClassIndexをセット（入れ子継承を考慮する）
+		if(pBaseMethod->GetInheritsClassPtr()==0){
+			pMethod->SetInheritsClassPtr( &inheritsClass );
+		}
+		else{
+			pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
+		}
+
+		methods.push_back( pMethod );
+	}
+
+	//仮想関数の数
+	AddVtblNum( inheritsClass.GetVtblNum() );
+
+	//継承先のクラスをメンバとして保持する
+	pobj_InheritsClass = &inheritsClass;
+
+	return true;
+}
+bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){
+
+	//ループ継承でないかをチェック
+	if(pobj_LoopRefCheck->check(inheritsInterface)){
+		throw SmoothieException(123,inheritsInterface.GetName(),nowLine);
+		return false;
+	}
+
+	if( !inheritsInterface.IsReady() ){
+		//継承先が読み取られていないとき
+		pobj_LoopRefCheck->add(this->GetName().c_str());
+		Smoothie::meta.classes.GetClass_recur(inheritsInterface.GetName().c_str());
+		pobj_LoopRefCheck->del(this->GetName().c_str());
+	}
+
+	//メソッドをコピー
+	BOOST_FOREACH( const CMethod *pBaseMethod, inheritsInterface.methods ){
+		CMethod *pMethod = new DynamicMethod( *pBaseMethod );
+
+		// アクセシビリティ
+		if(pBaseMethod->GetAccessibility() == Prototype::Private){
+			pMethod->SetAccessibility( Prototype::None );
+		}
+		else{
+			pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
+		}
+
+		//pobj_Inherits
+		// ※継承元のClassIndexをセット（入れ子継承を考慮する）
+		if(pBaseMethod->GetInheritsClassPtr()==0){
+			pMethod->SetInheritsClassPtr( &inheritsInterface );
+		}
+		else{
+			pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
+		}
+
+		methods.push_back( pMethod );
+	}
+
+	interfaces.push_back( InheritedInterface( const_cast<CClass *>(&inheritsInterface), vtblNum ) );
+
+	//仮想関数の数
+	AddVtblNum( inheritsInterface.GetVtblNum() );
+
+	return true;
+}
+void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer ){
+	CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer );
+	dynamicMembers.push_back( pMember );
+}
+void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
+	CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer, nowLine );
+	staticMembers.push_back( pMember );
+}*/
+BOOL CClass::DupliCheckAll(const char *name){
+	//重複チェック
+
+	//メンバ
+	if(DupliCheckMember(name)) return 1;
+
+	//メソッド
+	BOOST_FOREACH( const CMethod *pMethod, methods ){
+		if( lstrcmp( name, pMethod->pUserProc->GetName().c_str() ) == 0 ){
+			return 1;
+		}
+	}
+
+	return 0;
+}
+BOOL CClass::DupliCheckMember(const char *name){
+	//重複チェック
+
+	// 動的メンバ
+	BOOST_FOREACH( CMember *pMember, dynamicMembers ){
+		if( GetName() == pMember->GetName() ){
+			return 1;
+		}
+	}
+
+	// 静的メンバ
+	BOOST_FOREACH( CMember *pMember, staticMembers ){
+		if( GetName() == pMember->GetName() ){
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+//デフォルト コンストラクタ メソッドを取得
+const CMethod *CClass::GetConstructorMethod() const
+{
+	if( ConstructorMemberSubIndex == -1 ) return NULL;
+	return methods[ConstructorMemberSubIndex];
+}
+
+//デストラクタ メソッドを取得
+const CMethod *CClass::GetDestructorMethod() const
+{
+	if( DestructorMemberSubIndex == -1 ) return NULL;
+	return methods[DestructorMemberSubIndex];
+}
+
+//サイズを取得
+int CClass::GetSize() const
+{
+	return GetMemberOffset( NULL, NULL );
+}
+
+//メンバのオフセットを取得
+int CClass::GetMemberOffset( const char *memberName, int *pMemberNum ) const
+{
+	int i2;
+
+	//仮想関数が存在する場合は関数リストへのポインタのサイズを追加
+	int offset = IsExistVirtualFunctions() ? PTR_SIZE : 0;
+
+	int alignment;
+	if(iAlign) alignment=iAlign;
+	else alignment=1;
+
+	int iMaxAlign=0;
+	int i = -1;
+	BOOST_FOREACH( CMember *pMember, dynamicMembers ){
+		i++;
+
+		i2 = pMember->GetType().GetSize();
+
+		//アラインメントを算出
+		int member_size;
+		if( pMember->GetType().IsStruct() ){
+			//メンバクラスのアラインメントを取得
+			member_size=pMember->GetType().GetClass().GetAlignment();
+		}
+		else{
+			//メンバサイズを取得
+			member_size=i2;
+		}
+		if(iMaxAlign<member_size) iMaxAlign=member_size;
+
+		//アラインメントを考慮
+		if(iAlign&&iAlign<member_size){
+			if(offset%alignment) offset+=alignment-(offset%alignment);
+		}
+		else{
+			if(alignment<member_size) alignment=member_size;
+
+			if(member_size==0){
+				//メンバを持たないクラス
+				//※何もしない（オフセットの計算をしない）
+			}
+			else{
+				if(offset%member_size) offset+=member_size-(offset%member_size);
+			}
+		}
+
+		if(memberName){
+			//メンバ指定がある場合は、オフセットを返す
+			if( pMember->GetName() == memberName ){
+				if(pMemberNum) *pMemberNum=i;
+				return offset;
+			}
+		}
+
+		//配列を考慮したメンバサイズを取得
+		member_size=i2 * Variable::GetSubScriptCounts(pMember->SubScripts);
+
+		//メンバサイズを加算
+		offset+= member_size;
+	}
+
+	if(iMaxAlign<alignment) alignment=iMaxAlign;
+
+	//アラインメントを考慮
+	if(alignment){
+		if(offset%alignment) offset+=alignment-(offset%alignment);
+	}
+
+	if(pMemberNum) *pMemberNum=i;
+	return offset;
+}
+
+int CClass::GetAlignment() const
+{
+	//仮想関数が存在する場合は関数リストへのポインタのサイズを追加
+	int alignment = IsExistVirtualFunctions() ? PTR_SIZE : 0;
+
+	BOOST_FOREACH( CMember *pMember, dynamicMembers ){
+		int member_size;
+		if(pMember->GetType().IsStruct()){
+			//メンバクラスのアラインメントを取得
+			member_size=pMember->GetType().GetClass().GetAlignment();
+		}
+		else{
+			//メンバサイズを取得
+			member_size = pMember->GetType().GetSize();
+		}
+
+		//アラインメントをセット
+		if(alignment<member_size) alignment=member_size;
+	}
+
+	if(alignment==0) return 0;
+
+	if(iAlign) alignment=iAlign;
+
+	return alignment;
+}
+
+
+
+int CClass::GetFuncNumInVtbl( const UserProc *pUserProc ) const
+{
+	int n = 0;
+	BOOST_FOREACH( const CMethod *pMethod, methods ){
+		if( pMethod->pUserProc == pUserProc ) break;
+		if( pMethod->IsVirtual() ) n++;
+	}
+	return n;
+}
+/*
+LONG_PTR CClass::GetVtblGlobalOffset(void) const
+{
+
+	//既に存在する場合はそれを返す
+	if(vtbl_offset!=-1) return vtbl_offset;
+
+
+
+	//////////////////////////////////////
+	// 存在しないときは新たに生成する
+	//////////////////////////////////////
+
+	UserProc **ppsi;
+	ppsi=(UserProc **)malloc(GetVtblNum()*sizeof(GlobalProc *));
+
+	//関数テーブルに値をセット
+	int i2 = 0;
+	BOOST_FOREACH( const CMethod *pMethod, methods ){
+		if(pMethod->IsVirtual()){
+			pMethod->pUserProc->Using();
+
+			if(pMethod->IsAbstract()){
+				extern int cp;
+				throw SmoothieException(300,NULL,cp);
+
+				ppsi[i2]=0;
+			}
+			else{
+				ppsi[i2]=pMethod->pUserProc;
+			}
+			i2++;
+		}
+	}
+
+	vtbl_offset=dataTable.AddBinary((void *)ppsi,GetVtblNum()*sizeof(LONG_PTR));
+
+	for( int i=0; i < GetVtblNum(); i++ ){
+		pobj_Reloc->AddSchedule_DataSection(vtbl_offset+i*sizeof(LONG_PTR));
+	}
+
+	free(ppsi);
+
+	return vtbl_offset;
+}
+void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
+	if(vtbl_offset==-1) return;
+
+	LONG_PTR *pVtbl;
+	pVtbl=(LONG_PTR *)((char *)dataTable.GetPtr()+vtbl_offset);
+
+	int i;
+	for(i=0;i<GetVtblNum();i++){
+		GlobalProc *pUserProc;
+		pUserProc=(GlobalProc *)pVtbl[i];
+		if(!pUserProc) continue;
+		pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection;
+	}
+}*/
+bool CClass::IsAbstract() const
+{
+	// 未実装(abstract)の仮想関数を持つ場合はtrueを返す
+
+	BOOST_FOREACH( const CMethod *pMethod, methods ){
+		if(pMethod->IsVirtual()){
+			if(pMethod->IsAbstract()){
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
+// コンストラクタのコンパイルを開始
+void CClass::NotifyStartConstructorCompile() const
+{
+	isCompilingConstructor = true;
+}
+
+//コンストラクタのコンパイルを終了
+void CClass::NotifyFinishConstructorCompile() const
+{
+	isCompilingConstructor = false;
+}
+
+//コンストラクタをコンパイル中かどうかを判別
+bool CClass::IsCompilingConstructor() const
+{
+	return isCompilingConstructor;
+}
+
+//デストラクタのコンパイルを開始
+void CClass::NotifyStartDestructorCompile() const{
+	isCompilingDestructor = true;
+}
+
+//デストラクタのコンパイルを終了
+void CClass::NotifyFinishDestructorCompile() const{
+	isCompilingDestructor = false;
+}
+
+//デストラクタをコンパイル中かどうかを判別
+bool CClass::IsCompilingDestructor() const
+{
+	return isCompilingDestructor;
+}
+
+//自身の派生クラスかどうかを確認
+bool CClass::IsSubClass( const CClass *pClass ) const
+{
+	pClass = pClass->pobj_InheritsClass;
+	while( pClass ){
+		if( this == pClass ) return true;
+		pClass = pClass->pobj_InheritsClass;
+	}
+	return false;
+}
+
+//自身と等しいまたは派生クラスかどうかを確認
+bool CClass::IsEqualsOrSubClass( const CClass *pClass ) const
+{
+	if( IsEquals( pClass ) ) return true;
+	return IsSubClass( pClass );
+}
+
+// 自身と等しいまたは派生クラス、基底クラスかどうかを確認
+bool CClass::IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const
+{
+	if( IsEquals( &objClass ) ) return true;
+	if( IsSubClass( &objClass ) ) return true;
+	if( objClass.IsSubClass( this ) ) return true;
+	return false;
+}
+
+
+
+int Classes::hash(const char *name) const{
+	int key;
+
+	for(key=0;*name!='\0';name++){
+		key=((key<<8)+ *name )%MAX_CLASS_HASH;
+	}
+
+	return key;
+}
+
+void Classes::DestroyClass(CClass *pobj_c){
+	if(pobj_c->pobj_NextClass){
+		DestroyClass(pobj_c->pobj_NextClass);
+	}
+
+	delete pobj_c;
+}
+
+Classes::Classes():
+	pStringClass( NULL ),
+	pObjectClass( NULL ),
+	pCompilingClass( NULL ),
+	pCompilingMethod( NULL ),
+	ppobj_IteClass( NULL ),
+	iIteMaxNum( 0 ),
+	iIteNextNum( 0 )
+{
+	memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) );
+}
+Classes::~Classes(){
+	int i;
+	for(i=0;i<MAX_CLASS_HASH;i++){
+		if(pobj_ClassHash[i]) DestroyClass(pobj_ClassHash[i]);
+	}
+
+	if(ppobj_IteClass) free(ppobj_IteClass);
+}
+
+void Classes::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
+	int i;
+	for(i=0;i<MAX_CLASS_HASH;i++){
+		if(pobj_ClassHash[i]){
+			CClass *pobj_c;
+			pobj_c=pobj_ClassHash[i];
+			while(1){
+				pobj_c->ActionVtblSchedule(ImageBase,MemPos_CodeSection);
+
+				if(pobj_c->pobj_NextClass==0) break;
+				pobj_c=pobj_c->pobj_NextClass;
+			}
+		}
+	}
+}
+
+const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const string &name ) const
+{
+	int key;
+	key=hash(name.c_str());
+
+	if( namespaceScopes.size() == 0 && name == "Object" ){
+		return GetObjectClassPtr();
+	}
+	else if( namespaceScopes.size() == 0 && name == "String" ){
+		return GetStringClassPtr();
+	}
+
+	if(pobj_ClassHash[key]){
+		CClass *pobj_c;
+		pobj_c=pobj_ClassHash[key];
+		while(1){
+			if( pobj_c->IsEqualSymbol( namespaceScopes, name ) ){
+				//名前空間とクラス名が一致した
+				return pobj_c;
+			}
+
+			if(pobj_c->pobj_NextClass==0) break;
+			pobj_c=pobj_c->pobj_NextClass;
+		}
+	}
+
+	// TypeDefも見る
+	int index = Smoothie::meta.typeDefs.GetIndex( namespaceScopes, name );
+	if( index != -1 ){
+		Type type = Smoothie::meta.typeDefs[index].GetBaseType();
+		if( type.IsObject() ){
+			return &type.GetClass();
+		}
+	}
+
+	return NULL;
+}
+const CClass *Classes::Find( const string &fullName ) const
+{
+	char AreaName[VN_SIZE] = "";		//オブジェクト変数
+	char NestName[VN_SIZE] = "";		//入れ子メンバ
+	bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
+
+	return Find( NamespaceScopes( AreaName ), NestName );
+}
+
+CClass *Classes::AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
+	//////////////////////////////////////////////////////////////////////////
+	// クラスを追加
+	// ※名前のみを登録。その他の情報はSetClassメソッドで！
+	//////////////////////////////////////////////////////////////////////////
+
+	CClass *pobj_c;
+	pobj_c=new CClass(namespaceScopes, importedNamespaces, name);
+
+	if(lstrcmp(name,"String")==0){
+		//Stringクラス
+		pStringClass=pobj_c;
+	}
+	if( lstrcmp( name, "Object" ) == 0 ){
+		pObjectClass = pobj_c;
+	}
+
+
+	/////////////////////////////////
+	// ハッシュデータに追加
+	/////////////////////////////////
+
+	int key;
+	key=hash(name);
+
+	if(pobj_ClassHash[key]){
+		CClass *pobj_c2;
+		pobj_c2=pobj_ClassHash[key];
+		while(1){
+			if( pobj_c2->IsEqualSymbol( namespaceScopes, name ) ){
+				//名前空間及びクラス名が重複した場合
+				throw SmoothieException(15,name,nowLine);
+				return 0;
+			}
+
+			if(pobj_c2->pobj_NextClass==0) break;
+			pobj_c2=pobj_c2->pobj_NextClass;
+		}
+		pobj_c2->pobj_NextClass=pobj_c;
+	}
+	else{
+		pobj_ClassHash[key]=pobj_c;
+	}
+
+	return pobj_c;	
+}
+
+
+
+CClass *Classes::GetStringClassPtr() const
+{
+	if( !pStringClass ){
+		throw SmoothieException();
+		return NULL;
+	}
+	return pStringClass;
+}
+CClass *Classes::GetObjectClassPtr() const
+{
+	if( !pObjectClass ){
+		throw SmoothieException();
+		return NULL;
+	}
+	return pObjectClass;
+}
+
+void Classes::StartCompile( UserProc *pUserProc ){
+	pCompilingClass = pUserProc->GetParentClassPtr();
+	if( pCompilingClass ){
+		pCompilingClass->Using();
+
+		pCompilingMethod = pCompilingClass->GetMethods().GetMethodPtr( pUserProc );
+		if( !pCompilingMethod ){
+			pCompilingMethod = pCompilingClass->GetStaticMethods().GetMethodPtr( pUserProc );
+			if( !pCompilingMethod ){
+				throw SmoothieException(300);
+			}
+		}
+	}
+	else{
+		pCompilingMethod = NULL;
+	}
+}
+const CClass *Classes::GetNowCompilingClass() const
+{
+	return pCompilingClass;
+}
+const CMethod *Classes::GetNowCompilingMethodInfo(){
+	return pCompilingMethod;
+}
+
+
+
+
+//////////////////////
+// イテレータ
+//////////////////////
+
+void Classes::Iterator_Init(void){
+	if(ppobj_IteClass) free(ppobj_IteClass);
+
+	iIteMaxNum=0;
+	iIteNextNum=0;
+	ppobj_IteClass=(CClass **)malloc(1);
+
+	int i;
+	for(i=0;i<MAX_CLASS_HASH;i++){
+		if(pobj_ClassHash[i]){
+			CClass *pobj_c;
+			pobj_c=pobj_ClassHash[i];
+			while(1){
+				ppobj_IteClass=(CClass **)realloc(ppobj_IteClass,(iIteMaxNum+1)*sizeof(CClass *));
+				ppobj_IteClass[iIteMaxNum]=pobj_c;
+				iIteMaxNum++;
+
+				if(pobj_c->pobj_NextClass==0) break;
+				pobj_c=pobj_c->pobj_NextClass;
+			}
+		}
+	}
+}
+void Classes::Iterator_Reset(void){
+	iIteNextNum = 0;
+}
+BOOL Classes::Iterator_HasNext(void){
+	if(iIteNextNum<iIteMaxNum) return 1;
+	return 0;
+}
+CClass *Classes::Iterator_GetNext(void){
+	CClass *pobj_c;
+	pobj_c=ppobj_IteClass[iIteNextNum];
+	iIteNextNum++;
+	return pobj_c;
+}
+int Classes::Iterator_GetMaxCount(void){
+	return iIteMaxNum;
+}
Index: trunk/jenga/src/smoothie/Method.cpp
===================================================================
--- trunk/jenga/src/smoothie/Method.cpp	(revision 171)
+++ trunk/jenga/src/smoothie/Method.cpp	(revision 172)
@@ -1,3 +1,3 @@
-#include <jenga/include/smoothie/Method.h>
+#include <jenga/include/smoothie/Class.h>
 
 
Index: trunk/jenga/src/smoothie/Smoothie.cpp
===================================================================
--- trunk/jenga/src/smoothie/Smoothie.cpp	(revision 171)
+++ trunk/jenga/src/smoothie/Smoothie.cpp	(revision 172)
@@ -6,4 +6,5 @@
 Meta Smoothie::meta;
 NamespaceScopesCollection Smoothie::Temp::importedNamespaces;
+const CClass *Smoothie::Temp::pCompilingClass = NULL;
 
 bool Smoothie::isFullCompile = false;
Index: trunk/jenga/src/smoothie/Type.cpp
===================================================================
--- trunk/jenga/src/smoothie/Type.cpp	(revision 172)
+++ trunk/jenga/src/smoothie/Type.cpp	(revision 172)
@@ -0,0 +1,547 @@
+#include <jenga/include/smoothie/Class.h>
+#include <jenga/include/smoothie/SmoothieException.h>
+
+using namespace std;
+
+const int Type::basicTypeList[] = {
+	DEF_BYTE,
+	DEF_SBYTE,
+	DEF_WORD,
+	DEF_INTEGER,
+	DEF_DWORD,
+	DEF_LONG,
+	DEF_QWORD,
+	DEF_INT64,
+
+	DEF_SINGLE,
+	DEF_DOUBLE,
+
+	DEF_BOOLEAN,
+
+	DEF_PTR_VOID,
+
+	DEF_ANY,
+
+	DEF_NON
+};
+
+const string Type::basicTypeNameList[] = {
+	"Byte",
+	"SByte",
+	"Word",
+	"Integer",
+	"DWord",
+	"Long",
+	"QWord",
+	"Int64",
+
+	"Single",
+	"Double",
+
+	"Boolean",
+
+	"VoidPtr",
+
+	"Any",
+
+	""
+};
+
+bool Type::StringToBasicType( const string &typeName, int &basicType ){
+	for( int i=0; ; i++ ){
+		if( basicTypeList[i] == DEF_NON ){
+			break;
+		}
+		if( basicTypeNameList[i] == typeName ){
+			basicType = basicTypeList[i];
+			return true;
+		}
+	}
+	return false;
+}
+
+/*
+bool Type::StringToType( const string &typeName, Type &type ){
+	type.index = -1;
+
+	if( typeName[0] == '*' ){
+		if( typeName.size() >= 3
+			&& typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){
+				//関数ポインタ（*Function）
+				type.basicType = DEF_PTR_PROC;
+				type.index = AddProcPtrInfo( typeName, cp );
+				return true;
+		}
+
+		const string &nextTypeName = typeName.substr( 1 );
+
+		if( !StringToType( nextTypeName, type ) ){
+			return false;
+		}
+
+		type.PtrLevelUp();
+
+		return true;
+	}
+
+	if( StringToBasicType( typeName, type.basicType ) ){
+		// 基本型だったとき
+		return true;
+	}
+
+
+	// Object型だったとき
+	if( typeName == "Object" ){
+		type.SetType( DEF_OBJECT, pobj_DBClass->GetObjectClassPtr() );
+		return true;
+	}
+
+	// String型だったとき
+	if( typeName == "String" ){
+		type.SetType( DEF_OBJECT, pobj_DBClass->GetStringClassPtr() );
+		return true;
+	}
+
+
+	////////////////////
+	// TypeDefされた型
+	////////////////////
+	int i=Smoothie::meta.typeDefs.GetIndex( typeName );
+	if(i!=-1){
+		type = Smoothie::meta.typeDefs[i].GetBaseType();
+		return true;
+	}
+
+	//クラス
+	const CClass *pobj_c = pobj_DBClass->Find( typeName );
+	if(pobj_c){
+		type.pClass = pobj_c;
+
+		if( pobj_c->IsStructure() ){
+			type.basicType = DEF_STRUCT;
+		}
+		else{
+			type.basicType = DEF_OBJECT;
+		}
+		return true;
+	}
+
+	return false;
+}*/
+
+int Type::GetBasicSize( int basicType )
+{
+
+	// 基本型
+	switch( basicType ){
+		case DEF_SBYTE:
+		case DEF_BYTE:
+		case DEF_BOOLEAN:
+			return sizeof(BYTE);
+
+		case DEF_INTEGER:
+		case DEF_WORD:
+			return sizeof(WORD);
+
+		case DEF_LONG:
+		case DEF_DWORD:
+			return sizeof(DWORD);
+
+		case DEF_INT64:
+		case DEF_QWORD:
+			return sizeof(_int64);
+
+		case DEF_DOUBLE:
+			return sizeof(double);
+		case DEF_SINGLE:
+			return sizeof(float);
+	}
+
+	// ポインタ
+	if(IsPointer( basicType )){
+		return PTR_SIZE;
+	}
+
+	// オブジェクト
+	if(basicType==DEF_OBJECT){
+		return PTR_SIZE;
+	}
+
+	throw SmoothieException();
+
+	return 0;
+}
+
+
+bool Type::Equals( const Type &type ) const
+{
+	if( basicType == type.basicType ){
+		if( NATURAL_TYPE( basicType ) == DEF_OBJECT
+			|| NATURAL_TYPE( basicType ) == DEF_STRUCT ){
+
+				if( index == type.index ){
+					return true;
+				}
+
+		}
+		else{
+			return true;
+		}
+	}
+	return false;
+}
+
+int Type::GetBasicSize() const
+{
+	return GetBasicSize( basicType );
+}
+int Type::GetSize() const
+{
+
+	// 基本型
+	switch( basicType ){
+		case DEF_LONG:
+			if(index==LITERAL_NULL||index==LITERAL_M128_0||index==LITERAL_0_255){
+				return sizeof(BYTE);
+			}
+			else if(index==LITERAL_M32768_0||index==LITERAL_0_65535){
+				return sizeof(WORD);
+			}
+			return sizeof(DWORD);
+
+		case DEF_SBYTE:
+		case DEF_BYTE:
+		case DEF_BOOLEAN:
+			return sizeof(BYTE);
+
+		case DEF_INTEGER:
+		case DEF_WORD:
+			return sizeof(WORD);
+
+		case DEF_DWORD:
+			return sizeof(DWORD);
+
+		case DEF_INT64:
+		case DEF_QWORD:
+			return sizeof(_int64);
+
+		case DEF_DOUBLE:
+			return sizeof(double);
+		case DEF_SINGLE:
+			return sizeof(float);
+	}
+
+	// ポインタ
+	if(IsPointer()){
+		return PTR_SIZE;
+	}
+
+	// 構造体
+	if( basicType == DEF_STRUCT ){
+		if( !pClass ){
+			throw SmoothieException();
+			return 0;
+		}
+
+		return pClass->GetSize();
+	}
+
+	// オブジェクト
+	if(basicType==DEF_OBJECT){
+		if( GetClass().IsInterface() ){
+			// vtblOffsetのサイズを含める
+			return PTR_SIZE*2;
+		}
+		return PTR_SIZE;
+	}
+
+	throw SmoothieException();
+	return 0;
+}
+
+bool Type::IsNull() const{
+  if( basicType == DEF_NON ){
+	  return true;
+  }
+  return false;
+}
+
+bool Type::IsByte() const{
+  if( basicType == DEF_BYTE ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsSByte() const{
+  if( basicType == DEF_SBYTE ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsWord() const{
+  if( basicType == DEF_WORD ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsInteger() const{
+  if( basicType == DEF_INTEGER ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsDWord() const{
+  if( basicType == DEF_DWORD ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsLong() const{
+  if( basicType == DEF_LONG ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsQWord() const{
+  if( basicType == DEF_QWORD ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsInt64() const{
+  if( basicType == DEF_INT64 ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsSingle() const{
+  if( basicType == DEF_SINGLE ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsDouble() const{
+  if( basicType == DEF_DOUBLE ){
+	  return true;
+  }
+  return false;
+}
+bool Type::IsBoolean() const{
+  if( basicType == DEF_BOOLEAN ){
+	  return true;
+  }
+  return false;
+}
+
+bool Type::IsPointer( int basicType )
+{
+	if(PTR_LEVEL( basicType )|| basicType == DEF_PTR_VOID || basicType == DEF_PTR_PROC
+		|| ( basicType & FLAG_PTR ) ){
+			return true;
+	}
+
+	return false;
+}
+bool Type::IsPointer() const
+{
+	return IsPointer( basicType );
+}
+bool Type::IsSigned() const
+{
+	switch( basicType ){
+		case DEF_SBYTE:
+		case DEF_INTEGER:
+		case DEF_LONG:
+		case DEF_INT64:
+		case DEF_SINGLE:
+		case DEF_DOUBLE:
+			return true;
+		default:
+			break;
+	}
+	return false;
+}
+bool Type::IsNaturalWhole() const
+{
+	switch( basicType ){
+		case DEF_SBYTE:
+		case DEF_BYTE:
+		case DEF_INTEGER:
+		case DEF_WORD:
+		case DEF_LONG:
+		case DEF_DWORD:
+		case DEF_INT64:
+		case DEF_QWORD:
+			return true;
+		default:
+			break;
+	}
+	return false;
+}
+bool Type::IsWhole() const
+{
+	return (
+		IsNaturalWhole()
+		|| IsPointer( basicType )
+		|| basicType == DEF_BOOLEAN
+		);
+}
+bool Type::IsReal() const
+{
+	switch( basicType ){
+		case DEF_SINGLE:
+		case DEF_DOUBLE:
+			return true;
+		default:
+			break;
+	}
+	return false;
+}
+bool Type::Is64() const
+{
+	switch( basicType ){
+		case DEF_QWORD:
+		case DEF_INT64:
+			return true;
+		default:
+			break;
+	}
+	return false;
+}
+bool Type::IsProcPtr() const
+{
+	if( basicType == DEF_PTR_PROC ){
+		return true;
+	}
+	return false;
+}
+bool Type::IsStruct() const
+{
+	if( basicType == DEF_STRUCT ){
+		return true;
+	}
+	return false;
+}
+bool Type::IsStructPtr() const
+{
+	if( basicType == DEF_PTR_STRUCT ){
+		return true;
+	}
+	return false;
+}
+bool Type::IsObject() const
+{
+	if( basicType == DEF_OBJECT ){
+		return true;
+	}
+	return false;
+}
+bool Type::IsObjectPtr() const
+{
+	if( basicType == DEF_PTR_OBJECT ){
+		return true;
+	}
+	return false;
+}
+bool Type::IsObjectClass() const
+{
+	if( basicType == DEF_OBJECT ){
+		if( pClass->GetName() == "Object" ){
+			return true;
+		}
+	}
+	return false;
+}
+bool Type::IsStringClass() const
+{
+	if( basicType == DEF_OBJECT ){
+		if( pClass->GetName() == "String" ){
+			return true;
+		}
+	}
+	return false;
+}
+bool Type::IsVoidPtr() const
+{
+	if( basicType == DEF_PTR_VOID ){
+		return true;
+	}
+	return false;
+}
+
+bool Type::IsAny() const
+{
+	if( basicType == DEF_ANY ){
+		return true;
+	}
+	return false;
+}
+
+bool Type::HasMember() const
+{
+	if( NATURAL_TYPE( basicType ) == DEF_OBJECT
+		|| NATURAL_TYPE( basicType ) == DEF_STRUCT ){
+			return true;
+	}
+	return false;
+}
+
+/*
+const string Type::ToString() const
+{
+	if( PTR_LEVEL( basicType ) ){
+		//ポインタレベルが1以上の場合
+		Type type( *this );
+		type.PtrLevelDown();
+
+		return (string)"*" + type.ToString();
+	}
+	else if( IsObject() || IsStruct() ){
+		//オブジェクトまたは構造体
+
+		if( !( index == 0 || index == -1 ) ){
+			if( pClass->GetNamespaceScopes().size() >= 1 )
+			{
+				return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName();
+			}
+			return pClass->GetName();
+		}
+	}
+	else if( IsProcPtr() ){
+		if( index == 0 || index == -1 ){
+			return "VoidPtr";
+		}
+		else{
+			if( Smoothie::meta.procPointers[index]->ReturnType().IsNull() ){
+				return "*Sub";
+			}
+			return "*Function";
+		}
+	}
+	else{
+		// 基本型
+
+		for( int i=0; ; i++ ){
+			if( basicTypeList[i] == DEF_NON ){
+				break;
+			}
+			if( basicTypeList[i] == basicType ){
+				return basicTypeNameList[i];
+			}
+		}
+	}
+
+	extern int cp;
+	SetError(1,NULL,cp);
+
+	return (string)"(null)";
+}
+
+Type Type::String(){
+	return Type( DEF_OBJECT, *pobj_DBClass->GetStringClassPtr() );
+}*/
+
+const string BlittableType::GetCreateStaticMethodFullName() const
+{
+	return pClass->GetNamespaceScopes().ToString() + "." + pClass->GetName() + "._Create";
+}
