Index: BasicCompiler_Common/DebugMiddleFile.cpp
===================================================================
--- BasicCompiler_Common/DebugMiddleFile.cpp	(revision 73)
+++ BasicCompiler_Common/DebugMiddleFile.cpp	(revision 75)
@@ -10,11 +10,11 @@
 
 
-void SetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR lpIndex){
-	if(NATURAL_TYPE(type)==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){
-		lstrcpy(buffer+(*p),((CClass *)lpIndex)->name);
+void SetLpIndex_DebugFile(char *buffer,int *p,const Type &type){
+	if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
+		lstrcpy(buffer+(*p),type.GetClass().name);
 		(*p)+=lstrlen(buffer+(*p))+1;
 	}
 	else{
-		*(LONG_PTR *)(buffer+(*p))=lpIndex;
+		*(LONG_PTR *)(buffer+(*p))=type.GetIndex();
 		(*p)+=sizeof(LONG_PTR);
 	}
@@ -22,14 +22,14 @@
 
 
-void GetLpIndex_DebugFile(char *buffer,int *p,int type,LONG_PTR *plpIndex){
-	if(NATURAL_TYPE(type)==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){
+void GetLpIndex_DebugFile(char *buffer,int *p,Type &type){
+	if(NATURAL_TYPE(type.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(type.GetBasicType())==DEF_STRUCT){
 		char szClassName[VN_SIZE];
 		lstrcpy(szClassName,buffer+(*p));
 		(*p)+=lstrlen(buffer+(*p))+1;
 
-		*plpIndex=(LONG_PTR)pobj_DBClass->check(szClassName);
+		type.SetIndex( (LONG_PTR)pobj_DBClass->check(szClassName) );
 	}
 	else{
-		*plpIndex=*(LONG_PTR *)(buffer+(*p));
+		type.SetIndex( *(LONG_PTR *)(buffer+(*p)) );
 		(*p)+=sizeof(LONG_PTR);
 	}
@@ -49,6 +49,4 @@
 }
 void CDebugSection::make(void){
-	extern VARIABLE *GlobalVar;
-	extern int MaxGlobalVarNum;
 	extern INCLUDEFILEINFO IncludeFileInfo;
 	int i2,i3,i4,i5,BufferSize;
@@ -160,29 +158,27 @@
 
 	//グローバル変数情報
-	*(long *)(buffer+i2)=MaxGlobalVarNum;
-	i2+=sizeof(long);
-	for(i3=0;i3<MaxGlobalVarNum;i3++){
-		VARIABLE *pVar=&GlobalVar[i3];
-
+	*(long *)(buffer+i2)=(int)::globalVars.size();
+	i2+=sizeof(long);
+	foreach( Variable *pVar, ::globalVars ){
 		//変数名
-		lstrcpy(buffer+i2,pVar->name);
+		lstrcpy(buffer+i2,pVar->GetName().c_str());
 		i2+=lstrlen(buffer+i2)+1;
 
 		//型
-		*(long *)(buffer+i2)=pVar->type;
+		*(long *)(buffer+i2)=pVar->GetBasicType();
 		i2+=sizeof(long);
 
 		//型の拡張情報
-		SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
-
-		buffer[i2++]=(char)pVar->fRef;
-
-		buffer[i2++]=(char)pVar->bArray;
-
-		if(pVar->bArray){
-			for(i4=0;;i4++){
-				*(long *)(buffer+i2)=pVar->SubScripts[i4];
+		SetLpIndex_DebugFile(buffer,&i2,*pVar);
+
+		buffer[i2++] = pVar->IsRef() ? 1 : 0;
+
+		buffer[i2++] = pVar->IsArray() ? 1 : 0;
+
+		if(pVar->IsArray()){
+			for(i5=0;;i5++){
+				*(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
 				i2+=sizeof(long);
-				if(pVar->SubScripts[i4]==-1) break;
+				if(pVar->GetSubScriptsPtr()[i5]==-1) break;
 			}
 		}
@@ -213,14 +209,14 @@
 
 	//プロシージャ情報
-	extern SubInfo **ppSubHash;
+	extern UserProc **ppSubHash;
 	extern int SubNum;
-	SubInfo *psi;
+	UserProc *pUserProc;
 	*(long *)(buffer+i2)=SubNum;
 	i2+=sizeof(long);
 	for(i3=0;i3<MAX_HASH;i3++){
-		psi=ppSubHash[i3];
-		while(psi){
-			if(psi->pobj_ParentClass){
-				lstrcpy(buffer+i2,psi->pobj_ParentClass->name);
+		pUserProc=ppSubHash[i3];
+		while(pUserProc){
+			if(pUserProc->GetParentClassPtr()){
+				lstrcpy(buffer+i2,pUserProc->GetParentClassPtr()->name);
 				i2+=lstrlen(buffer+i2)+1;
 			}
@@ -231,21 +227,18 @@
 
 			//ID
-			*(long *)(buffer+i2)=psi->id;
+			*(long *)(buffer+i2)=pUserProc->id;
 			i2+=sizeof(long);
 
 			//関数名
-			lstrcpy(buffer+i2,psi->name);
+			lstrcpy(buffer+i2,pUserProc->GetName().c_str());
 			i2+=lstrlen(buffer+i2)+1;
 
-			*(long *)(buffer+i2)=psi->CompileAddress;
-			i2+=sizeof(long);
-			*(long *)(buffer+i2)=psi->EndOpAddr;
-			i2+=sizeof(long);
-
-			*(long *)(buffer+i2)=psi->bVirtual;
+			*(long *)(buffer+i2)=pUserProc->beginOpAddress;
+			i2+=sizeof(long);
+			*(long *)(buffer+i2)=pUserProc->endOpAddress;
 			i2+=sizeof(long);
 
 			//ローカル変数情報
-			*(long *)(buffer+i2)=psi->VarNum;
+			*(long *)(buffer+i2)=(int)pUserProc->localVars.size();
 			i2+=sizeof(long);
 
@@ -256,31 +249,29 @@
 			}
 
-			for(i4=0;i4<psi->VarNum;i4++){
-				VARIABLE *pVar=&psi->pVar[i4];
-				lstrcpy(buffer+i2,pVar->name);
+			foreach( Variable *pVar, pUserProc->localVars ){
+				lstrcpy(buffer+i2,pVar->GetName().c_str());
 				i2+=lstrlen(buffer+i2)+1;
 
 				//型
-				*(long *)(buffer+i2)=pVar->type;
+				*(long *)(buffer+i2)=pVar->GetBasicType();
 				i2+=sizeof(long);
 
 				//型の拡張情報
-				SetLpIndex_DebugFile(buffer,&i2,pVar->type,pVar->u.index);
+				SetLpIndex_DebugFile(buffer,&i2,*pVar);
 
 				//参照型パラメータかどうか
-				buffer[i2++]=(char)pVar->fRef;
+				buffer[i2++] = pVar->IsRef() ? 1 : 0;
 
 				//配列かどうか
-				buffer[i2++]=(char)pVar->bArray;
+				buffer[i2++] = pVar->IsArray() ? 1 : 0;
 
 				//配列要素
-				if(pVar->bArray){
+				if(pVar->IsArray()){
 					for(i5=0;;i5++){
-						*(long *)(buffer+i2)=pVar->SubScripts[i5];
+						*(long *)(buffer+i2)=pVar->GetSubScriptsPtr()[i5];
 						i2+=sizeof(long);
-						if(pVar->SubScripts[i5]==-1) break;
+						if(pVar->GetSubScriptsPtr()[i5]==-1) break;
 					}
 				}
-				else pVar->SubScripts[0]=-1;
 
 				//レキシカルスコープ情報
@@ -306,5 +297,5 @@
 			}
 
-			psi=psi->pNextData;
+			pUserProc=pUserProc->pNextData;
 		}
 	}
@@ -347,9 +338,9 @@
 
 			//型
-			*(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->TypeInfo.type;
+			*(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->GetBasicType();
 			i2+=sizeof(long);
 
 			//型の拡張情報
-			SetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
+			SetLpIndex_DebugFile(buffer,&i2,*pobj_c->ppobj_Member[i4]);
 
 			*(long *)(buffer+i2)=pobj_c->ppobj_Member[i4]->dwAccess;
@@ -377,5 +368,5 @@
 				i2+=lstrlen(buffer+i2)+1;
 			}
-			lstrcpy(buffer+i2,method->psi->name);
+			lstrcpy(buffer+i2,method->pUserProc->GetName().c_str());
 			i2+=lstrlen(buffer+i2)+1;
 		}
@@ -392,9 +383,9 @@
 
 			//型
-			*(long *)(buffer+i2)=member->TypeInfo.type;
+			*(long *)(buffer+i2)=member->GetBasicType();
 			i2+=sizeof(long);
 
 			//型の拡張情報
-			SetLpIndex_DebugFile(buffer,&i2,member->TypeInfo.type,member->TypeInfo.u.lpIndex);
+			SetLpIndex_DebugFile(buffer,&i2,*member);
 
 			*(long *)(buffer+i2)=member->dwAccess;
@@ -540,29 +531,35 @@
 
 	//グローバル変数情報
-	MaxGlobalVarNum=*(long *)(buffer+i2);
-	i2+=sizeof(long);
-	GlobalVar=(VARIABLE *)HeapAlloc(hHeap,0,MaxGlobalVarNum*sizeof(VARIABLE)+1);
-	for(i3=0;i3<MaxGlobalVarNum;i3++){
-		VARIABLE *pVar=&GlobalVar[i3];
+	globalVars.clear();
+	int maxGlobalVars=*(long *)(buffer+i2);
+	i2+=sizeof(long);
+	for(i3=0;i3<maxGlobalVars;i3++){
 
 		//変数名
-		lstrcpy(pVar->name,buffer+i2);
-		i2+=lstrlen(buffer+i2)+1;
-
-		pVar->type=*(long *)(buffer+i2);
-		i2+=sizeof(long);
-
-		GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
-
-		pVar->fRef=(long)buffer[i2++];
-
-		pVar->bArray=(long)buffer[i2++];
-		if(pVar->bArray){
+		char *name = buffer+i2;
+		i2+=lstrlen(buffer+i2)+1;
+
+		int basicType = *(long *)(buffer+i2);
+		i2+=sizeof(long);
+
+		Type type( basicType );
+		GetLpIndex_DebugFile(buffer,&i2,type);
+
+		bool isRef = (buffer[i2++]) ? true:false;
+
+		bool isArray = (buffer[i2++]) ? true:false;
+
+		Variable *pVar = new Variable( name, type, false, isRef );
+
+		if(isArray){
+			int SubScripts[MAX_ARRAYDIM];
 			for(i4=0;;i4++){
-				pVar->SubScripts[i4]=*(long *)(buffer+i2);
+				SubScripts[i4]=*(long *)(buffer+i2);
 				i2+=sizeof(long);
 
-				if(pVar->SubScripts[i4]==-1) break;
-			}
+				if(SubScripts[i4]==-1) break;
+			}
+
+			pVar->SetArray( SubScripts );
 		}
 
@@ -578,4 +575,7 @@
 		pVar->offset=*(long *)(buffer+i2);
 		i2+=sizeof(long);
+
+		//変数を追加
+		globalVars.push_back( pVar );
 	}
 
@@ -585,70 +585,69 @@
 
 	//プロシージャ情報
-	SubInfo *psi;
+	UserProc *pUserProc;
 	SubNum=*(long *)(buffer+i2);
 	i2+=sizeof(long);
-	ppSubHash=(SubInfo **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(SubInfo *));
-	for(i3=0;i3<SubNum;i3++){
-		psi = new SubInfo();
-		psi->pNextData=0;
-
+	ppSubHash=(UserProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(UserProc *));
+	for(int i6=0;i6<SubNum;i6++){
 		char szParentClassName[VN_SIZE];
 		lstrcpy(szParentClassName,buffer+i2);
 		i2+=lstrlen(buffer+i2)+1;
 
+		CClass *pClass = NULL;
 		if(szParentClassName[0])
-			psi->pobj_ParentClass=pobj_DBClass->check(szParentClassName);
-		else psi->pobj_ParentClass=0;
+			pClass=pobj_DBClass->check(szParentClassName);
 
 		//ID
-		psi->id=*(long *)(buffer+i2);
+		int id=*(long *)(buffer+i2);
 		i2+=sizeof(long);
 
 		//名前
-		psi->name=(char *)HeapAlloc(hHeap,0,lstrlen(buffer+i2)+1);
-		lstrcpy(psi->name,buffer+i2);
-		i2+=lstrlen(buffer+i2)+1;
-
-		psi->CompileAddress=*(long *)(buffer+i2);
-		i2+=sizeof(long);
-		psi->EndOpAddr=*(long *)(buffer+i2);
-		i2+=sizeof(long);
-
-		psi->bVirtual=*(long *)(buffer+i2);
-		i2+=sizeof(long);
-
-		psi->bCompile=1;
+		char *name = buffer+i2;
+		i2+=lstrlen(buffer+i2)+1;
+
+		// オブジェクトを生成
+		pUserProc = new UserProc( name, UserProc::Function, false, false, false );
+		pUserProc->pNextData=0;
+		pUserProc->id=id;
+		pUserProc->SetParentClass( pClass );
+
+		pUserProc->beginOpAddress=*(long *)(buffer+i2);
+		i2+=sizeof(long);
+		pUserProc->endOpAddress=*(long *)(buffer+i2);
+		i2+=sizeof(long);
+
+		pUserProc->CompleteCompile();
 
 		//ローカル変数情報
-		psi->VarNum=*(long *)(buffer+i2);
-		i2+=sizeof(long);
-		psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,psi->VarNum*sizeof(VARIABLE)+1);
-		for(i4=0;i4<psi->VarNum;i4++){
-			VARIABLE *pVar=&psi->pVar[i4];
-
-			//ローカル変数名
-			lstrcpy(pVar->name,buffer+i2);
+		pUserProc->localVars.clear();
+		int maxLocalVar=*(long *)(buffer+i2);
+		i2+=sizeof(long);
+		for(i3=0;i3<maxLocalVar;i3++){
+			//変数名
+			char *name = buffer+i2;
 			i2+=lstrlen(buffer+i2)+1;
 
-			//型
-			pVar->type=*(long *)(buffer+i2);
-			i2+=sizeof(long);
-
-			//型の拡張情報
-			GetLpIndex_DebugFile(buffer,&i2,pVar->type,&pVar->u.index);
-
-			//参照型パラメータかどうか
-			pVar->fRef=(long)buffer[i2++];
-
-			//配列かどうか
-			pVar->bArray=(long)buffer[i2++];
-			if(pVar->bArray){
-				for(i5=0;;i5++){
-					//配列要素
-					pVar->SubScripts[i5]=*(long *)(buffer+i2);
+			int basicType = *(long *)(buffer+i2);
+			i2+=sizeof(long);
+
+			Type type( basicType );
+			GetLpIndex_DebugFile(buffer,&i2,type);
+
+			bool isRef = (buffer[i2++]) ? true:false;
+
+			bool isArray = (buffer[i2++]) ? true:false;
+
+			Variable *pVar = new Variable( name, type, false, isRef );
+
+			if(isArray){
+				int SubScripts[MAX_ARRAYDIM];
+				for(i4=0;;i4++){
+					SubScripts[i4]=*(long *)(buffer+i2);
 					i2+=sizeof(long);
 
-					if(pVar->SubScripts[i5]==-1) break;
+					if(SubScripts[i4]==-1) break;
 				}
+
+				pVar->SetArray( SubScripts );
 			}
 
@@ -661,22 +660,25 @@
 			i2+=sizeof(long);
 
-			//メモリ上の位置
+			//メモリ位置
 			pVar->offset=*(long *)(buffer+i2);
 			i2+=sizeof(long);
+
+			//変数を追加
+			pUserProc->localVars.push_back( pVar );
 		}
 
 
 		/////////////////////////////////
-		// 格納位置を計算してpsiをセット
+		// 格納位置を計算してpUserProcをセット
 		/////////////////////////////////
 
-		i4=hash_default(psi->name);
-
-		SubInfo *psi2;
+		i4=hash_default(pUserProc->GetName().c_str());
+
+		UserProc *psi2;
 		if(ppSubHash[i4]){
 			psi2=ppSubHash[i4];
 			while(1){
 				if(psi2->pNextData==0){
-					psi2->pNextData=psi;
+					psi2->pNextData=pUserProc;
 					break;
 				}
@@ -685,5 +687,5 @@
 		}
 		else{
-			ppSubHash[i4]=psi;
+			ppSubHash[i4]=pUserProc;
 		}
 	}
@@ -723,9 +725,11 @@
 
 			//型
-			pobj_c->ppobj_Member[i4]->TypeInfo.type=*(long *)(buffer+i2);
+			Type type( *(long *)(buffer+i2) );
 			i2+=sizeof(long);
 
 			//型の拡張情報
-			GetLpIndex_DebugFile(buffer,&i2,pobj_c->ppobj_Member[i4]->TypeInfo.type,&pobj_c->ppobj_Member[i4]->TypeInfo.u.lpIndex);
+			GetLpIndex_DebugFile(buffer,&i2,type);
+
+			pobj_c->ppobj_Member[i4]->SetType( type.GetBasicType(), type.GetIndex() );
 
 			pobj_c->ppobj_Member[i4]->dwAccess=*(long *)(buffer+i2);
@@ -757,10 +761,10 @@
 			if(pobj_temp_c==0) pobj_temp_c=pobj_c;
 			i5=hash_default(temp2);
-			psi=ppSubHash[i5];
+			pUserProc=ppSubHash[i5];
 			while(1){
-				if(lstrcmp(psi->name,temp2)==0&&psi->pobj_ParentClass==pobj_temp_c) break;
-				psi=psi->pNextData;
-			}
-			method->psi=psi;
+				if( pUserProc->GetName() == temp2 &&pUserProc->GetParentClassPtr()==pobj_temp_c) break;
+				pUserProc=pUserProc->pNextData;
+			}
+			method->pUserProc=pUserProc;
 
 			pobj_c->methods.push_back( method );
@@ -781,9 +785,11 @@
 
 			//型
-			member->TypeInfo.type=*(long *)(buffer+i2);
+			Type type( *(long *)(buffer+i2) );
 			i2+=sizeof(long);
 
 			//型の拡張情報
-			GetLpIndex_DebugFile(buffer,&i2,member->TypeInfo.type,&member->TypeInfo.u.lpIndex);
+			GetLpIndex_DebugFile(buffer,&i2,type);
+
+			member->SetType( type.GetBasicType(), type.GetIndex() );
 
 			member->dwAccess=*(long *)(buffer+i2);
@@ -800,5 +806,5 @@
 
 
-	extern SubInfo **ppSubHash;
+	extern UserProc **ppSubHash;
 	ppSubHash=this->ppSubHash;
 	pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc");
@@ -956,10 +962,4 @@
 	ppConstHash=this->ppConstHash;
 
-	//グローバル変数に関する情報
-	extern VARIABLE *GlobalVar;
-	extern int MaxGlobalVarNum;
-	GlobalVar=this->GlobalVar;
-	MaxGlobalVarNum=this->MaxGlobalVarNum;
-
 	//グローバル実行領域のサイズ
 	extern int GlobalOpBufferSize;
@@ -969,10 +969,10 @@
 	extern char **ppMacroNames;
 	ppMacroNames=0;
-	extern SubInfo **ppSubHash;
+	extern UserProc **ppSubHash;
 	extern int SubNum;
 	ppSubHash=this->ppSubHash;
 	SubNum=this->SubNum;
 
-	extern SubInfo *pSub_DebugSys_EndProc;
+	extern UserProc *pSub_DebugSys_EndProc;
 	pSub_DebugSys_EndProc=this->pSub_DebugSys_EndProc;
 
@@ -989,19 +989,4 @@
 		HeapDefaultFree(IncludeFileInfo.ppFileNames[i2]);
 	HeapDefaultFree(IncludeFileInfo.ppFileNames);
-
-	//グローバル変数に関する情報を解放
-	HeapDefaultFree(GlobalVar);
-
-	//ローカル変数に関する情報を解放
-	SubInfo *psi;
-	for(i2=0;i2<MAX_HASH;i2++){
-		psi=ppSubHash[i2];
-		while(psi){
-			if(psi->bCompile)
-				HeapDefaultFree(psi->pVar);
-
-			psi=psi->pNextData;
-		}
-	}
 
 	//クラスに関するメモリを解放
