Index: BasicCompiler64/WatchList.cpp
===================================================================
--- BasicCompiler64/WatchList.cpp	(revision 73)
+++ BasicCompiler64/WatchList.cpp	(revision 75)
@@ -5,5 +5,5 @@
 #include "../BasicCompiler_Common/debug.h"
 
-int Debugging_GetArray(int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset);
+int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset);
 
 ULONG_PTR Debugging_GetVarPtr(RELATIVE_VAR *pRelativeVar){
@@ -61,12 +61,12 @@
 }
 
-BOOL Debugging_SetRelativeOffset(int *pType,LONG_PTR lpIndex,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){
+bool Debugging_SetRelativeOffset( Type &type,RELATIVE_VAR *pRelativeVar,char *lpPtrOffset){
 	int array_num;
 
 	_int64 i64data;
-	int type;
-	type=StaticCalculation(true, lpPtrOffset,0,&i64data,0,1);
-	if(!type) return 0;
-	if(IsRealNumberType(type)){
+	if( !StaticCalculation( true, lpPtrOffset, 0, &i64data, Type(), 1 ) ){
+		return false;
+	}
+	if( type.IsReal() ){
 		double dbl;
 		memcpy(&dbl,&i64data,sizeof(double));
@@ -76,11 +76,11 @@
 	array_num=(int)i64data;
 
-	if(PTR_LEVEL(*pType)){
-		*pType=MAKE_PTR_TYPE(NATURAL_TYPE(*pType),PTR_LEVEL(*pType)-1);
-		array_num *= GetTypeSize(*pType,-1);
+	if( type.PtrLevel() ){
+		type.PtrLevelDown();
+		array_num *= type.GetSize();
 	}
 	else{
 		//エラー
-		return 0;
+		return false;
 	}
 
@@ -89,12 +89,14 @@
 	SIZE_T stAccBytes;
 	lpData=Debugging_GetVarPtr(pRelativeVar);
-	if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)) return 0;
+	if(!ReadProcessMemory(hDebugProcess,(void *)lpData,&pRelativeVar->offset,sizeof(LONG_PTR),&stAccBytes)){
+		return false;
+	}
 	pRelativeVar->dwKind=VAR_DIRECTMEM;
 
 	pRelativeVar->offset+=array_num;
-	return 1;
+	return true;
 }
 
-BOOL Debugging_GetMember(CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
+int Debugging_GetMember( const CClass &objClass,char *member,RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess){
 	int i,i2;
 
@@ -117,22 +119,21 @@
 	////////////////////////////
 
-	int offset = pobj_c->GetMemberOffset( VarName, &i );
-	if(i==pobj_c->iMemberNum) return 0;
+	int offset = objClass.GetMemberOffset( VarName, &i );
+	if(i==objClass.iMemberNum) return 0;
 
 
 	//アクセシビリティをチェック
-	if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
-		pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
+	if((bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
+		objClass.ppobj_Member[i]->dwAccess==ACCESS_NON){
 		return 0;
 	}
-	else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED)
+	else if(bPrivateAccess==0&&objClass.ppobj_Member[i]->dwAccess==ACCESS_PROTECTED)
 		return 0;
 
-	*pType=pobj_c->ppobj_Member[i]->TypeInfo.type;
-	*plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex;
+	resultType = *objClass.ppobj_Member[i];
 
 	//ポインタ変数の場合
-	if(IsPtrType(*pType)){
-		if(pobj_c->ppobj_Member[i]->SubScripts[0]==-1){
+	if( resultType.IsPointer() ){
+		if(objClass.ppobj_Member[i]->SubScripts[0]==-1){
 			lstrcpy(lpPtrOffset,array);
 			array[0]=0;
@@ -148,8 +149,7 @@
 		//配列オフセット
 		i2=Debugging_GetArray(
-			pobj_c->ppobj_Member[i]->SubScripts,
+			objClass.ppobj_Member[i]->SubScripts,
 			array,
-			*pType,
-			pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex,
+			resultType,
 			&pRelativeVar->offset);
 		if(i2==0){
@@ -162,6 +162,6 @@
 		}
 	}
-	else if(pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){
-		*pType|=FLAG_PTR;
+	else if(objClass.ppobj_Member[i]->SubScripts[0]!=-1){
+		resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
 	}
 
@@ -169,8 +169,8 @@
 		//入れ子構造の場合
 
-		if(*pType==DEF_OBJECT || *pType==DEF_STRUCT){
+		if( resultType.IsObject() || resultType.IsStruct() ){
 			if( refType != CClass::Dot ) return 0;
 
-			if( *pType==DEF_OBJECT ){
+			if( resultType.IsObject() ){
 				extern HANDLE hDebugProcess;
 				LONG_PTR lpData;
@@ -181,5 +181,5 @@
 			}
 		}
-		else if(*pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){
+		else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
 			//構造体ポインタ型メンバ変数
 
@@ -188,5 +188,5 @@
 
 				//直接参照に切り替え
-				Debugging_SetRelativeOffset(pType,*plpNestIndex,pRelativeVar,lpPtrOffset);
+				Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
 
 				lpPtrOffset[0]=0;
@@ -204,9 +204,8 @@
 		}
 
-		i2=Debugging_GetMember(pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
+		i2=Debugging_GetMember(objClass.ppobj_Member[i]->GetClass(),
 			NestMember,
-			pType,
 			pRelativeVar,
-			plpNestIndex,
+			resultType,
 			0);
 		if(i2==0){
@@ -221,12 +220,12 @@
 
 	if(lpPtrOffset[0]){
-		Debugging_SetRelativeOffset(pType,*plpNestIndex,pRelativeVar,lpPtrOffset);
+		Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
 	}
 
 	return 1;
 }
-int Debugging_GetArray(int *SubScripts,char *array,int type,LONG_PTR lpIndex,LONG_PTR *plpOffset){
+int Debugging_GetArray( const int *SubScripts,char *array,const Type &type,LONG_PTR *plpOffset){
 	extern HANDLE hHeap;
-	int i,i2,i3,i4,i5,array_offset,TypeSize;
+	int i,i2,i3,i4,i5,array_offset;
 	char temporary[VN_SIZE],*pParm[MAX_PARMS];
 
@@ -275,15 +274,16 @@
 	for(i=i3-1;i>=0;i--){
 		_int64 i64data;
-		i2=StaticCalculation(true, pParm[i],0,&i64data,0,1);
-		if(i2==0){
+		Type resultType;
+		bool isMemoryAccessError;
+		if( !StaticCalculation(true, pParm[i],0,&i64data,resultType,1, &isMemoryAccessError ) ){
 			//式エラー
 			return 0;
 		}
-		if(i2==-1){
+		if(isMemoryAccessError){
 			//アクセスエラー
 			return -1;
 		}
 
-		if(IsRealNumberType(i2)){
+		if(resultType.IsReal()){
 			double dbl;
 			memcpy(&dbl,&i64data,sizeof(double));
@@ -299,7 +299,5 @@
 	}
 
-	TypeSize=GetTypeSize(type,lpIndex);
-
-	array_offset*=TypeSize;
+	array_offset *= type.GetSize();
 
 	*plpOffset+=array_offset;
@@ -308,18 +306,14 @@
 }
 ULONG_PTR Debugging_GetThisPtrOffset(LONG_PTR obp_Rip){
-	int i;
-	SubInfo *psi;
-
-	//ripからプロシージャを取得
-	psi=GetSubFromObp(obp_Rip);
-
-	for(i=0;i<psi->VarNum;i++){
-		if(lstrcmp(psi->pVar[i].name,"_System_LocalThis")==0) break;
-	}
-	if(i==psi->VarNum) return 0;
-
-	return psi->pVar[i].offset;
+	UserProc *pUserProc = GetSubFromObp(obp_Rip);
+
+	foreach( Variable *pVar, pUserProc->localVars ){
+		if( pVar->GetName() == "_System_LocalThis" ){
+			return pVar->offset;
+		}
+	}
+	return 0;
 }
-int Debugging_GetVarOffset(char *variable,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
+int Debugging_GetVarOffset( char *variable,RELATIVE_VAR *pRelativeVar, Type &resultType, int *pss){
 	extern HANDLE hDebugProcess;
 	int i,i2,i3;
@@ -332,7 +326,6 @@
 	GetVarFormatString(VarName,array,lpPtrOffset,member,refType);
 
-	LONG_PTR lpIndex;
-	int *pSubScripts;
-	BOOL bArray;
+	const int *pSubScripts;
+	bool isArray;
 
 
@@ -340,13 +333,9 @@
 	// ローカル変数
 	/////////////////
-	extern VARIABLE *LocalVar;
-	extern int MaxLocalVarNum;
-	for(i=0;i<MaxLocalVarNum;i++){
-		if(lstrcmp(VarName,LocalVar[i].name)==0) break;
-	}
-	if(i!=MaxLocalVarNum){
+	const Variable *pVar = UserProc::CompilingUserProc().localVars.Find( VarName );
+	if( pVar ){
 		//ポインタ変数の場合
-		if(IsPtrType(LocalVar[i].type)){
-			if(!LocalVar[i].bArray){
+		if( pVar->IsPointer() ){
+			if( !pVar->IsArray() ){
 				lstrcpy(lpPtrOffset,array);
 				array[0]=0;
@@ -357,12 +346,14 @@
 		}
 
-		pRelativeVar->offset=LocalVar[i].offset;
-		if(LocalVar[i].fRef) pRelativeVar->dwKind=VAR_REFLOCAL;
-		else pRelativeVar->dwKind=VAR_LOCAL;
-		*pType=LocalVar[i].type;
-		lpIndex=LocalVar[i].u.index;
-		*plpIndex=lpIndex;
-		bArray=LocalVar[i].bArray;
-		pSubScripts=LocalVar[i].SubScripts;
+		pRelativeVar->offset = pVar->offset;
+		if( pVar->IsRef() ){
+			pRelativeVar->dwKind=VAR_REFLOCAL;
+		}
+		else{
+			pRelativeVar->dwKind=VAR_LOCAL;
+		}
+		resultType = *pVar;
+		isArray = pVar->IsArray();
+		pSubScripts = pVar->GetSubScriptsPtr();
 	}
 	else{
@@ -406,6 +397,5 @@
 			pRelativeVar->dwKind=VAR_DIRECTMEM;
 
-			LONG_PTR lp2;
-			i3=Debugging_GetMember(pobj_CompilingClass,variable,pType,pRelativeVar,&lp2,1);
+			i3=Debugging_GetMember(*pobj_CompilingClass,variable,pRelativeVar,resultType,1);
 			if(i3==0){
 				//式エラー
@@ -417,5 +407,4 @@
 			}
 
-			*plpIndex=lp2;
 			return 1;
 		}
@@ -426,11 +415,7 @@
 		// グローバル変数
 		///////////////////
-		extern VARIABLE *GlobalVar;
-		extern int MaxGlobalVarNum;
-
-		for(i=0;i<MaxGlobalVarNum;i++){
-			if(lstrcmp(VarName,GlobalVar[i].name)==0) break;
-		}
-		if(i==MaxGlobalVarNum){
+
+		const Variable *pVar = globalVars.Find( VarName );
+		if( !pVar ){
 			//一致しないとき
 			return 0;
@@ -438,6 +423,6 @@
 
 		//ポインタ変数の場合
-		if(IsPtrType(GlobalVar[i].type)){
-			if(!GlobalVar[i].bArray){
+		if( pVar->IsPointer() ){
+			if( !pVar->IsArray() ){
 				lstrcpy(lpPtrOffset,array);
 				array[0]=0;
@@ -448,24 +433,22 @@
 		}
 
-		pRelativeVar->offset=GlobalVar[i].offset;
-		if(GlobalVar[i].fRef) pRelativeVar->dwKind=VAR_REFGLOBAL;
+		pRelativeVar->offset=pVar->offset;
+		if(pVar->IsRef()) pRelativeVar->dwKind=VAR_REFGLOBAL;
 		else pRelativeVar->dwKind=VAR_GLOBAL;
-		*pType=GlobalVar[i].type;
-		lpIndex=GlobalVar[i].u.index;
-		*plpIndex=lpIndex;
-		bArray=GlobalVar[i].bArray;
-		pSubScripts=GlobalVar[i].SubScripts;
-	}
-
-
-	if(array[0]==0&&bArray){
+		resultType = *pVar;
+		isArray = pVar->IsArray();
+		pSubScripts=pVar->GetSubScriptsPtr();
+	}
+
+
+	if(array[0]==0&&isArray){
 		//配列の先頭ポインタを示す場合
-		*pType|=FLAG_PTR;
-		if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM);
+		resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
+		if(pss) memcpy(pss,pSubScripts,MAX_ARRAYDIM*sizeof(int));
 		return 1;
 	}
 
 	if(array[0]){
-		i3=Debugging_GetArray(pSubScripts,array,*pType,lpIndex,&pRelativeVar->offset);
+		i3=Debugging_GetArray(pSubScripts,array,resultType,&pRelativeVar->offset);
 		if(i3==0){
 			//式エラー
@@ -478,5 +461,5 @@
 	}
 	if(member[0]){
-		if(*pType==DEF_OBJECT || *pType==DEF_STRUCT){
+		if( resultType.IsObject() || resultType.IsStruct() ){
 			//実態オブジェクトのメンバを参照（obj.member）
 			if( refType != CClass::Dot ){
@@ -484,6 +467,5 @@
 			}
 
-			LONG_PTR lp2;
-			i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
+			i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0);
 			if(i3==0){
 				//式エラー
@@ -494,16 +476,13 @@
 				return -1;
 			}
-
-			*plpIndex=lp2;
-		}
-		else if(*pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){
+		}
+		else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
 			//ポインタオブジェクトが示すメンバを参照
 			if(lpPtrOffset[0]){
 				//pObj[n].member
 				if( refType != CClass::Dot ) return 0;
-				Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset);
-
-				LONG_PTR lp2;
-				i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
+				Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
+
+				i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0);
 				if(i3==0){
 					//式エラー
@@ -514,6 +493,4 @@
 					return -1;
 				}
-
-				*plpIndex=lp2;
 			}
 			else{
@@ -527,6 +504,5 @@
 				pRelativeVar->offset=lpData;
 
-				LONG_PTR lp2;
-				i3=Debugging_GetMember((CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0);
+				i3=Debugging_GetMember(resultType.GetClass(),member,pRelativeVar,resultType,0);
 				if(i3==0){
 					//式エラー
@@ -537,6 +513,4 @@
 					return -1;
 				}
-
-				*plpIndex=lp2;
 			}
 		}
@@ -548,5 +522,5 @@
 
 	if(lpPtrOffset[0]){
-		if(!Debugging_SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset)) return 0;
+		if(!Debugging_SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset)) return 0;
 	}
 
