Index: trunk/abdev/BasicCompiler32/Compile_Var.cpp
===================================================================
--- trunk/abdev/BasicCompiler32/Compile_Var.cpp	(revision 193)
+++ trunk/abdev/BasicCompiler32/Compile_Var.cpp	(revision 206)
@@ -1,2 +1,4 @@
+#include "stdafx.h"
+
 #include <jenga/include/smoothie/Smoothie.h>
 #include <jenga/include/smoothie/LexicalAnalysis.h>
@@ -5,5 +7,5 @@
 #include <CodeGenerator.h>
 #include <Compiler.h>
-#include <VariableImpl.h>
+#include <Variable.h>
 
 #include "../BasicCompiler_Common/common.h"
@@ -11,5 +13,5 @@
 
 //変数
-Variables globalVars;
+// TODO: xml未完成
 int AllGlobalVarSize;
 int AllInitGlobalVarSize;
@@ -64,5 +66,5 @@
 	}
 }
-bool GetArrayOffset(const int *SubScripts,char *array, const Type &type){
+bool GetArrayOffset(const Subscripts &subscripts,char *array, const Type &type){
 	extern HANDLE hHeap;
 	int i,i2,i3,i4;
@@ -83,5 +85,6 @@
 		}
 		if(array[i]==','||array[i]=='\0'){
-			if(SubScripts[i3]==-1){
+			if( i3 >= (int)subscripts.size() )
+			{
 				for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
 				return 0;
@@ -96,5 +99,6 @@
 
 			if(array[i]=='\0'){
-				if(SubScripts[i3]!=-1){
+				if( i3 < (int)subscripts.size() )
+				{
 					for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
 					return 0;
@@ -131,5 +135,5 @@
 		op_pop(REG_EAX);
 
-		for(i2=i+1,i4=1;i2<i3;i2++) i4*=SubScripts[i2]+1;
+		for(i2=i+1,i4=1;i2<i3;i2++) i4*=subscripts[i2]+1;
 
 		//imul eax,i4
@@ -175,5 +179,5 @@
 	char lpPtrOffset[VN_SIZE];	//第2次配列
 	char NestMember[VN_SIZE];	//入れ子メンバ
-	CClass::RefType refType;
+	ReferenceKind refType;
 	lstrcpy(VarName,member);
 	if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false;
@@ -195,5 +199,5 @@
 
 	//アクセシビリティをチェック
-	if(&objClass==Smoothie::Temp::pCompilingClass){
+	if(&objClass==compiler.pCompilingClass){
 		//同一クラスオブジェクトの場合はプライベートアクセスを容認する
 		if(pMember->IsNoneAccess()){
@@ -228,5 +232,5 @@
 	//ポインタ変数の場合
 	if( resultType.IsPointer() ){
-		if(pMember->SubScripts[0]==-1){
+		if( pMember->GetSubscripts().size() == 0 ){
 			lstrcpy(lpPtrOffset,array);
 			array[0]=0;
@@ -250,9 +254,9 @@
 	if(array[0]){
 		//配列オフセット
-		if(!GetArrayOffset(pMember->SubScripts,array,pMember->GetType())){
+		if(!GetArrayOffset(pMember->GetSubscripts(),array,pMember->GetType())){
 			if(isErrorEnabled) SetError(14,member,cp);
 		}
 	}
-	else if(pMember->SubScripts[0]!=-1){
+	else if( pMember->GetSubscripts().size() > 0 ){
 		resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
 	}
@@ -262,5 +266,5 @@
 
 		if( resultType.IsObject() || resultType.IsStruct() ){
-			if( refType != CClass::Dot ){
+			if( refType != RefDot ){
 				if(isErrorEnabled) SetError(104,member,cp);
 				return false;
@@ -278,5 +282,5 @@
 				//pObj[n].member
 				if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
-					&& refType != CClass::Dot ){
+					&& refType != RefDot ){
 						if(isErrorEnabled) SetError(104,member,cp);
 						return false;
@@ -292,5 +296,5 @@
 				//pObj->member
 				if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
-					&& refType != CClass::Pointer ){
+					&& refType != RefPointer ){
 						if(isErrorEnabled) SetError(104,member,cp);
 						return false;
@@ -306,5 +310,5 @@
 			if(lpPtrOffset[0]){
 				//ppObj[n]->member
-				if( refType != CClass::Pointer ){
+				if( refType != RefPointer ){
 					if(isErrorEnabled) SetError(104,member,cp);
 					return false;
@@ -357,5 +361,5 @@
 }
 
-bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType,int *pss){
+bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){
 	char variable[VN_SIZE];
 
@@ -371,5 +375,5 @@
 
 	// 先頭オブジェクトまたはクラス名と入れ子メンバに分割
-	CClass::RefType refType;
+	ReferenceKind refType;
 	char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
 	GetVarFormatString(simpleName,array,lpPtrOffset,member,refType);
@@ -384,5 +388,5 @@
 	}
 
-	const int *pSubScripts;
+	const Subscripts *pSubscripts;
 	bool bConst = false;
 
@@ -393,8 +397,8 @@
 		//////////////////
 
-		const Variable *pVar = UserProc::CompilingUserProc().localVars.BackSearch( Symbol( VarName ) );
+		const Variable *pVar = UserProc::CompilingUserProc().GetLocalVars().BackSearch( Symbol( VarName ) );
 		if( pVar ){
 			//ポインタ変数の場合
-			if( pVar->IsPointer() ){
+			if( pVar->GetType().IsPointer() ){
 				if( !pVar->IsArray() ){
 					lstrcpy(lpPtrOffset,array);
@@ -410,5 +414,5 @@
 			}
 
-			pRelativeVar->offset=-pVar->offset;
+			pRelativeVar->offset=-pVar->GetOffsetAddress();
 			pRelativeVar->bOffsetOffset=0;
 			if( pVar->IsRef() ){
@@ -417,6 +421,6 @@
 			}
 			else pRelativeVar->dwKind=VAR_LOCAL;
-			resultType = *pVar;
-			pSubScripts=pVar->GetSubScriptsPtr();
+			resultType = pVar->GetType();
+			pSubscripts = &pVar->GetSubscripts();
 			bConst = pVar->IsConst();
 
@@ -425,5 +429,5 @@
 	}
 
-	if(Smoothie::Temp::pCompilingClass){
+	if(compiler.pCompilingClass){
 		//////////////////////
 		// クラスメンバの参照
@@ -438,5 +442,5 @@
 			pRelativeVar->dwKind=VAR_DIRECTMEM;
 
-			resultType.SetType( DEF_OBJECT, Smoothie::Temp::pCompilingClass );
+			resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
 			return true;
 		}
@@ -451,5 +455,5 @@
 
 			bool isFound = false;
-			BOOST_FOREACH( CMember *pMember, Smoothie::Temp::pCompilingClass->GetDynamicMembers() ){
+			BOOST_FOREACH( CMember *pMember, compiler.pCompilingClass->GetDynamicMembers() ){
 				if( pMember->GetName() == VarName ){
 					isFound = true;
@@ -465,6 +469,6 @@
 		if( isWriteAccess &&
 			pMethod->IsConst() &&
-			Smoothie::Temp::pCompilingClass->IsCompilingConstructor() == false &&
-			Smoothie::Temp::pCompilingClass->IsCompilingDestructor() == false
+			compiler.pCompilingClass->IsCompilingConstructor() == false &&
+			compiler.pCompilingClass->IsCompilingDestructor() == false
 			){
 				SetError(131, NULL, cp );
@@ -481,5 +485,5 @@
 			isErrorEnabled,
 			isWriteAccess,
-			*Smoothie::Temp::pCompilingClass,
+			*compiler.pCompilingClass,
 			variable,
 			pRelativeVar,
@@ -502,5 +506,5 @@
 			GetNowStaticVarFullName(VarName,temporary);
 
-			pVar = globalVars.Find( Symbol( temporary ) );
+			pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temporary ) );
 			if( pVar ){
 				goto GlobalOk;
@@ -521,5 +525,5 @@
 			char tempArray[VN_SIZE];
 			{
-				CClass::RefType refType;
+				ReferenceKind refType;
 				GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType );
 			}
@@ -533,5 +537,5 @@
 			char temp2[VN_SIZE];
 			sprintf(temp2,"%s.%s",VarName,temporary);
-			pVar = globalVars.Find( Symbol( temp2 ) );
+			pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) );
 			if( pVar ){
 				lstrcpy(member,tempMember);
@@ -541,9 +545,9 @@
 		}
 
-		if(Smoothie::Temp::pCompilingClass){
+		if(compiler.pCompilingClass){
 			//自身のクラスから静的メンバを参照する場合
 			char temp2[VN_SIZE];
-			sprintf(temp2,"%s.%s",Smoothie::Temp::pCompilingClass->GetName().c_str(),VarName);
-			pVar = globalVars.Find( Symbol( temp2 ) );
+			sprintf(temp2,"%s.%s",compiler.pCompilingClass->GetName().c_str(),VarName);
+			pVar = compiler.GetMeta().GetGlobalVars().Find( Symbol( temp2 ) );
 			if( pVar ){
 				goto GlobalOk;
@@ -555,5 +559,5 @@
 		/////////////////////
 
-		pVar = globalVars.BackSearch( Symbol( VarName ) );
+		pVar = compiler.GetMeta().GetGlobalVars().BackSearch( Symbol( VarName ) );
 		if( pVar ){
 			goto GlobalOk;
@@ -568,5 +572,5 @@
 GlobalOk:
 		//ポインタ変数の場合
-		if( pVar->IsPointer() ){
+		if( pVar->GetType().IsPointer() ){
 			if( !pVar->IsArray() ){
 				lstrcpy(lpPtrOffset,array);
@@ -582,5 +586,5 @@
 		}
 
-		pRelativeVar->offset=pVar->offset;
+		pRelativeVar->offset=pVar->GetOffsetAddress();
 		pRelativeVar->bOffsetOffset=0;
 		if( pVar->IsRef() ){
@@ -589,6 +593,6 @@
 		}
 		else pRelativeVar->dwKind=VAR_GLOBAL;
-		resultType = *pVar;
-		pSubScripts=pVar->GetSubScriptsPtr();
+		resultType = pVar->GetType();
+		pSubscripts=&pVar->GetSubscripts();
 		bConst = pVar->IsConst();
 	}
@@ -610,8 +614,12 @@
 	}
 
-	if(array[0]==0&&pSubScripts[0]!=-1){
+	if( array[0] == 0 && pSubscripts->size() > 0 ){
 		//配列の先頭ポインタを示す場合
 		resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
-		if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM);
+
+		if( pResultSubscripts )
+		{
+			(*pResultSubscripts) = *pSubscripts;
+		}
 		return true;
 	}
@@ -625,5 +633,5 @@
 	}
 	if(array[0]){
-		if(!GetArrayOffset(pSubScripts,array,resultType)){
+		if(!GetArrayOffset(*pSubscripts,array,resultType)){
 			SetError(14,variable,cp);
 			pRelativeVar->dwKind=NON_VAR;
@@ -634,5 +642,5 @@
 		if( resultType.IsObject() || resultType.IsStruct() ){
 			//実態オブジェクトのメンバを参照（obj.member）
-			if( refType != CClass::Dot ){
+			if( refType != RefDot ){
 				SetError(104,VarName,cp);
 				pRelativeVar->dwKind=NON_VAR;
@@ -649,5 +657,5 @@
 			if(lpPtrOffset[0]){
 				//pObj[n].member
-				if( refType != CClass::Dot ){
+				if( refType != RefDot ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -659,5 +667,5 @@
 			else{
 				//pObj->member
-				if( refType != CClass::Pointer ){
+				if( refType != RefPointer ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -677,5 +685,5 @@
 			if(lpPtrOffset[0]){
 				//ppObj[n]->member
-				if( refType != CClass::Pointer ){
+				if( refType != RefPointer ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -722,5 +730,5 @@
 }
 
-bool SetInitGlobalData(int offset,const Type &type,const int *SubScripts,const char *lpszInitBuf){
+bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
 	extern BYTE *initGlobalBuf;
 	int i2,i3;
@@ -735,21 +743,29 @@
 		int typeSize = type.GetSize();
 
-		if(SubScripts[0]!=-1){
-			typeSize*=JumpSubScripts(SubScripts+1);
-			int i=0;
-			i2=0;
-			while(1){
-				if(SubScripts[0]<i2){
-					SetError(41,0,cp);
-					return 0;
-				}
-				i=GetOneParameter(InitBuf,i,temporary);
-				if(!SetInitGlobalData(
-					offset+i2*typeSize,
-					type,
-					SubScripts+1,
-					temporary)) return false;
-				i2++;
-				if(InitBuf[i]=='\0') break;
+		if( subscripts.size() > 0 ){
+			Subscripts nestSubscripts;
+			for( int i=1; i<(int)subscripts.size(); i++ )
+			{
+				nestSubscripts.push_back( subscripts[i] );
+			}
+
+			typeSize*=JumpSubScripts( nestSubscripts );
+			{
+				int i=0;
+				i2=0;
+				while(1){
+					if( subscripts[0] < i2 ){
+						SetError(41,0,cp);
+						return 0;
+					}
+					i=GetOneParameter(InitBuf,i,temporary);
+					if(!SetInitGlobalData(
+						offset+i2*typeSize,
+						type,
+						nestSubscripts,
+						temporary)) return false;
+					i2++;
+					if(InitBuf[i]=='\0') break;
+				}
 			}
 			return true;
@@ -772,5 +788,5 @@
 				if(!SetInitGlobalData(offset+i3,
 					pMember->GetType(),
-					pMember->SubScripts,
+					pMember->GetSubscripts(),
 					temporary)) return false;
 			}
@@ -793,5 +809,5 @@
 	}
 
-	if(SubScripts[0]!=-1){
+	if( subscripts.size() > 0 ){
 		SetError(41,0,cp);
 		return false;
@@ -861,6 +877,6 @@
 	return true;
 }
-bool InitLocalVar(int offset,const Type &type,const int *SubScripts,const char *lpszInitBuf){
-	int i,i2,i3;
+bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
+	int i2,i3;
 	char temporary[VN_SIZE];
 	char InitBuf[VN_SIZE];
@@ -873,21 +889,29 @@
 		int typeSize = type.GetSize();
 
-		if(SubScripts[0]!=-1){
-			typeSize*=JumpSubScripts(SubScripts+1);
-			i=0;
-			i2=0;
-			while(1){
-				if(SubScripts[0]<i2){
-					SetError(41,0,cp);
-					return false;
-				}
-				i=GetOneParameter(InitBuf,i,temporary);
-				if(!InitLocalVar(
-					offset+i2*typeSize,
-					type,
-					SubScripts+1,
-					temporary)) return false;
-				i2++;
-				if(InitBuf[i]=='\0') break;
+		if( subscripts.size() > 0 ){
+			Subscripts nestSubscripts;
+			for( int i=1; i<(int)subscripts.size(); i++ )
+			{
+				nestSubscripts.push_back( subscripts[i] );
+			}
+
+			typeSize*=JumpSubScripts( nestSubscripts );
+			{
+				int i=0;
+				i2=0;
+				while(1){
+					if( subscripts[0] < i2 ){
+						SetError(41,0,cp);
+						return 0;
+					}
+					i=GetOneParameter(InitBuf,i,temporary);
+					if(!InitLocalVar(
+						offset+i2*typeSize,
+						type,
+						nestSubscripts,
+						temporary)) return false;
+					i2++;
+					if(InitBuf[i]=='\0') break;
+				}
 			}
 			return true;
@@ -910,5 +934,5 @@
 				if(!InitLocalVar(offset+i3,
 					pMember->GetType(),
-					pMember->SubScripts,
+					pMember->GetSubscripts(),
 					temporary)) return false;
 
@@ -927,5 +951,5 @@
 	///////////////////////////////////////
 
-	if(SubScripts[0]!=-1){
+	if( subscripts.size() > 0 ){
 		SetError(41,0,cp);
 		return false;
@@ -1075,5 +1099,5 @@
 }
 
-void dim( char *VarName,int *SubScripts,Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){
+void dim( char *VarName, const Subscripts &subscripts, Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){
 	if( UserProc::IsGlobalAreaCompiling() ){
 		/////////////////////////
@@ -1081,5 +1105,5 @@
 		/////////////////////////
 
-		AddGlobalVariable(VarName,SubScripts,type,InitBuf,ConstractParameter,dwFlags);
+		AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
 	}
 	else{
@@ -1088,5 +1112,5 @@
 		/////////////////
 
-		if( UserProc::CompilingUserProc().localVars.DuplicateCheck( Symbol( VarName ) ) ){
+		if( UserProc::CompilingUserProc().GetLocalVars().DuplicateCheck( Symbol( VarName ) ) ){
 			//２重定義のエラー
 			SetError(15,VarName,cp);
@@ -1096,17 +1120,14 @@
 		bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
 
-		Variable *pVar = new VariableImpl( VarName, type, isConst );
-
-		if( SubScripts[0] != -1 ){
+		Variable *pVar = new Variable( VarName, type, isConst, false, ConstractParameter );
+
+		if( subscripts.size() > 0 ){
 			//配列あり
-			pVar->SetArray( SubScripts );
-		}
-
-		//コンストラクタ用パラメータ
-		pVar->paramStrForConstructor = ConstractParameter;
+			pVar->SetArray( subscripts );
+		}
 
 		//レキシカルスコープ
-		pVar->ScopeLevel=GetLexicalScopes().GetNowLevel();
-		pVar->ScopeStartAddress=GetLexicalScopes().GetStartAddress();
+		pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
+		pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
 		pVar->bLiving=TRUE;
 
@@ -1115,9 +1136,9 @@
 
 		// 変数を追加
-		UserProc::CompilingUserProc().localVars.push_back( pVar );
+		UserProc::CompilingUserProc().GetLocalVars().push_back( pVar );
 
 		//アラインメントを考慮
-		if( pVar->IsStruct() ){
-			int alignment = pVar->GetClass().iAlign;
+		if( pVar->GetType().IsStruct() ){
+			int alignment = pVar->GetType().GetClass().iAlign;
 
 			if( alignment ){
@@ -1139,9 +1160,9 @@
 
 		AllLocalVarSize += pVar->GetMemorySize();
-		pVar->offset = AllLocalVarSize;
+		pVar->SetOffsetAddress( AllLocalVarSize );
 
 		//レキシカルスコープ
-		pVar->ScopeLevel=GetLexicalScopes().GetNowLevel();
-		pVar->ScopeStartAddress=GetLexicalScopes().GetStartAddress();
+		pVar->SetScopeLevel( GetLexicalScopes().GetNowLevel() );
+		pVar->SetScopeStartAddress( GetLexicalScopes().GetStartAddress() );
 		pVar->bLiving=TRUE;
 
@@ -1153,8 +1174,8 @@
 
 			int result = 0;
-			if( !pVar->IsObject() ){
-				result = InitLocalVar(-pVar->offset,
-					*pVar,
-					pVar->GetSubScriptsPtr(),
+			if( !pVar->GetType().IsObject() ){
+				result = InitLocalVar(-pVar->GetOffsetAddress(),
+					pVar->GetType(),
+					pVar->GetSubscripts(),
 					InitBuf);
 			}
@@ -1184,5 +1205,5 @@
 			//add eax,offset
 			OpBuffer[obp++]=(char)0x05;
-			*((long *)(OpBuffer+obp))=-pVar->offset;
+			*((long *)(OpBuffer+obp))=-pVar->GetOffsetAddress();
 			AddLocalVarAddrSchedule();
 			obp+=sizeof(long);
@@ -1204,12 +1225,12 @@
 	if( type.IsObject() &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){
 		char objectSize[255];
-		if( SubScripts[0] == -1 ){
+		if( subscripts.size() == 0 ){
 			objectSize[0] = 0;
 		}
 		else{
-			if( SubScripts[1] != -1 ){
+			if( subscripts.size() > 1 ){
 				SetError(300,NULL,cp);
 			}
-			sprintf( objectSize, "%d", SubScripts[0] );
+			sprintf( objectSize, "%d", subscripts[0] );
 		}
 		Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
@@ -1323,5 +1344,5 @@
 
 bool Compile_AddGlobalRootsForGc(){
-	UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
+	const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
 	if( !pUserProc_AddGlobalRootPtr ){
 		SetError(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
@@ -1329,6 +1350,6 @@
 	}
 
-	BOOST_FOREACH( const Variable *pVar, globalVars ){
-		if( pVar->IsObject() || pVar->IsPointer() || pVar->IsStruct() ){
+	BOOST_FOREACH( const Variable *pVar, compiler.GetMeta().GetGlobalVars() ){
+		if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
 			// オブジェクトまたはポインタだったとき
 			// ※構造体も含む（暫定対応）
@@ -1342,5 +1363,5 @@
 
 			//mov eax,offset
-			op_mov_RV(REG_EAX,(int)pVar->offset);
+			op_mov_RV(REG_EAX,(int)pVar->GetOffsetAddress());
 			obp-=sizeof(long);
 			pobj_GlobalVarSchedule->add();
