Index: BasicCompiler32/Compile_Var.cpp
===================================================================
--- BasicCompiler32/Compile_Var.cpp	(revision 63)
+++ BasicCompiler32/Compile_Var.cpp	(revision 64)
@@ -23,23 +23,10 @@
 
 	if(PTR_LEVEL(*pType)){
-		*pType=MAKE_PTR_TYPE(NATURAL_TYPE(*pType),PTR_LEVEL(*pType)-1);
-		if((*pType)==DEF_OBJECT){
-			CClass *pClass = (CClass *)lpIndex;
-			int objsize = pClass->GetSize();
-
-			//imul ebx,objsize
-			OpBuffer[obp++]=(char)0x69;
-			OpBuffer[obp++]=(char)0xDB;
-			*((long *)(OpBuffer+obp))=objsize;
-			obp+=sizeof(long);
-		}
-		else{
-			i2=GetTypeSize(*pType,-1);
-			if(i2>=2){
-				//imul ebx,i2
-				OpBuffer[obp++]=(char)0x6B;
-				OpBuffer[obp++]=(char)0xDB;
-				OpBuffer[obp++]=(char)i2;
-			}
+		*pType = PTR_LEVEL_DOWN( *pType );
+
+		i2=GetTypeSize(*pType,-1);
+		if(i2>=2){
+			//imul ebx,i2
+			op_imul_RV( REG_EBX, i2 );
 		}
 	}
@@ -56,4 +43,18 @@
 	OpBuffer[obp++]=(char)0x03;
 	OpBuffer[obp++]=(char)0xCB;
+}
+void SetRelativeOffset( RELATIVE_VAR &relativeVar ){
+	if(relativeVar.dwKind==VAR_DIRECTMEM){
+		//mov ecx,dword ptr[ecx]
+		op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE );
+	}
+	else{
+		//直接参照に切り替え
+		SetVarPtrToEax(&relativeVar);
+		relativeVar.dwKind=VAR_DIRECTMEM;
+
+		//mov ecx,dword ptr[eax]
+		op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
+	}
 }
 BOOL GetArrayOffset(int *SubScripts,char *array,int type,LONG_PTR lpIndex){
@@ -168,7 +169,7 @@
 	char lpPtrOffset[VN_SIZE];	//第2次配列
 	char NestMember[VN_SIZE];	//入れ子メンバ
-	int RefType;				//"."参照のときは0、"->"参照のときは1
+	CClass::RefType refType;
 	lstrcpy(VarName,member);
-	if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,&RefType)) return 0;
+	if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0;
 
 	////////////////////////////
@@ -251,16 +252,21 @@
 		//入れ子構造の場合
 
-		if(*pType==DEF_OBJECT){
-			if(RefType!=DEF_OBJECT){
+		if(*pType==DEF_OBJECT || *pType==DEF_STRUCT){
+			if( refType != CClass::Dot ){
 				if(isErrorEnabled) SetError(104,member,cp);
 				return 0;
 			}
-		}
-		else if(*pType==DEF_PTR_OBJECT){
+
+			if( *pType==DEF_OBJECT ){
+				// 参照内容へのポインタを抽出
+				SetRelativeOffset( *pRelativeVar );
+			}
+		}
+		else if(*pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT){
 			//構造体ポインタ型メンバ変数
 
 			if(lpPtrOffset[0]){
 				//pObj[n].member
-				if(RefType!=DEF_OBJECT){
+				if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Dot ){
 					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
@@ -275,31 +281,18 @@
 			else{
 				//pObj->member
-				if(RefType!=DEF_PTR_OBJECT){
+				if( ( *pType==DEF_PTR_OBJECT||*pType==DEF_PTR_STRUCT )&& refType != CClass::Pointer ){
 					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
 
-				if(pRelativeVar->dwKind==VAR_DIRECTMEM){
-					//mov ecx,dword ptr[ecx]
-					OpBuffer[obp++]=(char)0x8B;
-					OpBuffer[obp++]=(char)0x09;
-				}
-				else{
-					//直接参照に切り替え
-					SetVarPtrToEax(pRelativeVar);
-					pRelativeVar->dwKind=VAR_DIRECTMEM;
-
-					//mov ecx,dword ptr[eax]
-					OpBuffer[obp++]=(char)0x8B;
-					OpBuffer[obp++]=(char)0x08;
-				}
-			}
-		}
-		else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2)){
+				SetRelativeOffset( *pRelativeVar );
+			}
+		}
+		else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){
 			//構造体ポインタのポインタ型メンバ変数
 
 			if(lpPtrOffset[0]){
 				//ppObj[n]->member
-				if(RefType!=DEF_PTR_OBJECT){
+				if( refType != CClass::Pointer ){
 					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
@@ -364,5 +357,5 @@
 BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, const char *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){
 	extern BOOL bCompilingGlobal;
-	int i,RefType;
+	int i;
 	LONG_PTR lpIndex;
 	char variable[VN_SIZE],member[VN_SIZE],VarName[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
@@ -374,6 +367,6 @@
 	else lstrcpy(variable,NameBuffer);
 
-
-	if( FormatUseProcReturnObject( variable, VarName, array, RefType, member ) ){
+	CClass::RefType refType;
+	if( FormatUseProcReturnObject( variable, VarName, array, refType, member ) ){
 		// 戻り値オブジェクトのメンバを直接参照しているとき
 		//例: func().member
@@ -410,5 +403,5 @@
 
 	lstrcpy(VarName,variable);
-	GetVarFormatString(VarName,array,lpPtrOffset,member,&RefType);
+	GetVarFormatString(VarName,array,lpPtrOffset,member,refType);
 
 	int *pSubScripts;
@@ -546,7 +539,11 @@
 	if(member[0]){
 		lstrcpy(temporary,member);
+
 		char tempMember[VN_SIZE];
 		char tempArray[VN_SIZE];
-		GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember,&i);
+		{
+			CClass::RefType refType;
+			GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType );
+		}
 
 		char temp2[VN_SIZE];
@@ -665,17 +662,22 @@
 	}
 	if(member[0]){
-		if(*pType==DEF_OBJECT){
+		if(*pType==DEF_OBJECT || *pType==DEF_STRUCT){
 			//実態オブジェクトのメンバを参照（obj.member）
-			if(RefType!=DEF_OBJECT){
+			if( refType != CClass::Dot ){
 				SetError(104,VarName,cp);
 				pRelativeVar->dwKind=NON_VAR;
 				return 0;
 			}
-		}
-		else if(*pType==DEF_PTR_OBJECT){
+
+			if( *pType==DEF_OBJECT ){
+				// 参照内容へのポインタを抽出
+				SetRelativeOffset( *pRelativeVar );
+			}
+		}
+		else if(*pType==DEF_PTR_OBJECT || *pType==DEF_PTR_STRUCT){
 			//ポインタオブジェクトが示すメンバを参照
 			if(lpPtrOffset[0]){
 				//pObj[n].member
-				if(RefType!=DEF_OBJECT){
+				if( refType != CClass::Dot ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -687,5 +689,5 @@
 			else{
 				//pObj->member
-				if(RefType!=DEF_PTR_OBJECT){
+				if( refType != CClass::Pointer ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -701,9 +703,9 @@
 			}
 		}
-		else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2)){
+		else if(*pType==MAKE_PTR_TYPE(DEF_OBJECT,2) || *pType==MAKE_PTR_TYPE(DEF_STRUCT,2)){
 			//ポインタオブジェクトが示すメンバを参照
 			if(lpPtrOffset[0]){
 				//ppObj[n]->member
-				if(RefType!=DEF_PTR_OBJECT){
+				if( refType != CClass::Pointer ){
 					SetError(104,VarName,cp);
 					pRelativeVar->dwKind=NON_VAR;
@@ -785,5 +787,5 @@
 		}
 
-		if(type==DEF_OBJECT){
+		if(type==DEF_STRUCT){
 			CClass *pobj_c;
 			pobj_c=(CClass *)lpIndex;
@@ -818,6 +820,6 @@
 	///////////////////////////////////////
 
-	if( type == DEF_OBJECT){
-		//オブジェクトの場合はありえない
+	if( type == DEF_OBJECT || type == DEF_STRUCT ){
+		//オブジェクトまたは構造体の場合はありえない
 		SetError(300,NULL,cp);
 		return 0;
@@ -855,5 +857,5 @@
 		*(_int64 *)(initGlobalBuf+offset)=i64data;
 	else if(type==DEF_LONG||type==DEF_DWORD||IsPtrType(type)){
-		if(type==DEF_PTR_BYTE&&lpCalcIndex==LITERAL_STRING){
+		if(type==DEF_PTR_CHAR&&lpCalcIndex==LITERAL_STRING){
 			//文字列定数のとき
 
@@ -918,5 +920,5 @@
 		}
 
-		if(type==DEF_OBJECT){
+		if(type==DEF_STRUCT){
 			CClass *pobj_c;
 			pobj_c=(CClass *)lpIndex;
@@ -1045,5 +1047,5 @@
 	}
 	else if(type==DEF_LONG||type==DEF_DWORD||IsPtrType(type)){
-		if(type==DEF_PTR_BYTE&&lpCalcIndex==LITERAL_STRING){
+		if(type==DEF_PTR_CHAR&&lpCalcIndex==LITERAL_STRING){
 			//文字列定数のとき
 
@@ -1102,8 +1104,159 @@
 }
 
+void dim(bool isRef, char *VarName,int *SubScripts,TYPEINFO &TypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlags){
+	extern BOOL bCompilingGlobal;
+	if(bCompilingGlobal){
+		/////////////////////////
+		// グローバル変数
+		/////////////////////////
+
+		AddGlobalVariable(isRef,VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);
+	}
+	else{
+		/////////////////
+		// ローカル変数
+		/////////////////
+
+		int i2,i3;
+
+		for(i2=0;i2<MaxLocalVarNum;i2++){
+			if(LocalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==LocalVar[i2].ScopeLevel){
+				if(lstrcmp(LocalVar[i2].name,VarName)==0){
+					//２重定義のエラー
+					SetError(15,VarName,cp);
+					return;
+				}
+			}
+		}
+
+		LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE));
+		VARIABLE *pVar = &LocalVar[MaxLocalVarNum];
+		MaxLocalVarNum++;
+
+		if( isRef ){
+			//参照型
+			pVar->fRef = REF_VARIABLE;
+			TypeSize = PTR_SIZE;
+		}
+		else pVar->fRef=0;
+
+		for(i2=1,i3=0;i3<255;i3++){
+			//配列要素数
+			pVar->SubScripts[i3]=SubScripts[i3];
+
+			if(SubScripts[i3]==-1) break;
+			i2*=SubScripts[i3]+1;
+		}
+		int VarSize=TypeSize*i2;
+		if(VarSize%4) VarSize+=4-(VarSize%4);
+
+		//変数データを追加
+		lstrcpy(pVar->name,VarName);
+		if(dwFlags & DIMFLAG_CONST) pVar->bConst = true;
+		else pVar->bConst = false;
+		if(SubScripts[0]==-1) pVar->bArray=0;
+		else pVar->bArray=1;
+		pVar->type=TypeInfo.type;
+		pVar->u.index=TypeInfo.u.lpIndex;
+		AllLocalVarSize+=VarSize;
+		pVar->offset=AllLocalVarSize;
+
+		//レキシカルスコープ
+		pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
+		pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();
+		pVar->bLiving=TRUE;
+
+		if(InitBuf[0]){
+			//初期代入時のみ、書き込みアクセスを許可する
+			bool bConstBack = pVar->bConst;
+			pVar->bConst = false;
+
+			int result = 0;
+			if( pVar->type != DEF_OBJECT ){
+				result = InitLocalVar(-pVar->offset,
+					pVar->type,
+					pVar->u.index,
+					pVar->SubScripts,
+					InitBuf);
+			}
+
+			if(!result){
+				//動的な式だった場合は代入演算を行う
+				char temporary[8192];
+				sprintf(temporary,"%s=%s",VarName,InitBuf);
+				OpcodeCalc(temporary);
+			}
+
+			pVar->bConst = bConstBack;
+		}
+		else{
+			//push 0
+			op_push_value(0);
+
+			//push VarSize
+			op_push_value(VarSize);
+
+			//mov eax,ebp
+			OpBuffer[obp++]=(char)0x8B;
+			OpBuffer[obp++]=(char)0xC5;
+
+			//add eax,offset
+			OpBuffer[obp++]=(char)0x05;
+			*((long *)(OpBuffer+obp))=-pVar->offset;
+			AddLocalVarAddrSchedule();
+			obp+=sizeof(long);
+
+			//push eax
+			op_push(REG_EAX);
+
+			//call FillMemory
+			OpBuffer[obp++]=(char)0xFF;
+			OpBuffer[obp++]=(char)0x15;
+			DECLAREINFO *pdi;
+			pdi=GetDeclareHash("FillMemory");
+			pdi->bUse=1;
+			pobj_ImportAddrSchedule->add(pdi);
+			obp+=sizeof(long);
+		}
+	}
+
+	//New呼び出し
+	if(TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&&InitBuf[0]=='\0'){
+		char objectSize[255];
+		if( SubScripts[0] == -1 ){
+			objectSize[0] = 0;
+		}
+		else{
+			if( SubScripts[1] != -1 ){
+				SetError(300,NULL,cp);
+			}
+			sprintf( objectSize, "%d", SubScripts[0] );
+		}
+		Operator_New( *TypeInfo.u.pobj_Class, objectSize, ConstractParameter, TypeInfo );
+
+		//pop eax
+		op_pop( REG_EAX );
+
+		int type;
+		LONG_PTR lpIndex;
+		RELATIVE_VAR RelativeVar;
+		GetVarOffset( true, false, VarName, &type, &RelativeVar, &lpIndex );
+		if( RelativeVar.dwKind == VAR_DIRECTMEM ){
+			SetError();
+		}
+		SetVariableFromEax( DEF_OBJECT, DEF_OBJECT, &RelativeVar );
+	}
+
+	if(TypeInfo.type==DEF_OBJECT){
+		if(TypeInfo.u.pobj_Class->IsAbstract()){
+			//抽象クラスだったとき
+			SetError(125,TypeInfo.u.pobj_Class->name,cp);
+		}
+	}
+}
 void dim(char *Parameter,DWORD dwFlags){
 	extern BOOL bCompilingGlobal;
 	extern HANDLE hHeap;
-	int i2,i3,VarSize;
+	int i2;
 	char VarName[VN_SIZE];
 
@@ -1187,5 +1340,5 @@
 		GetNowStaticVarFullName(VarName,temporary);
 
-		AddGlobalVariable(isRef, temporary,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);
+		dim( isRef,temporary,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );
 
 		/*
@@ -1195,129 +1348,5 @@
 	}
 	else{
-		if(bCompilingGlobal){
-			/////////////////////////
-			// グローバル変数
-			/////////////////////////
-
-			AddGlobalVariable(isRef, VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);
-		}
-		else{
-			/////////////////
-			// ローカル変数
-			/////////////////
-
-			for(i2=0;i2<MaxLocalVarNum;i2++){
-				if(LocalVar[i2].bLiving&&obj_LexScopes.GetNowLevel()==LocalVar[i2].ScopeLevel){
-					if(lstrcmp(LocalVar[i2].name,VarName)==0){
-						//２重定義のエラー
-						SetError(15,VarName,cp);
-						return;
-					}
-				}
-			}
-
-			LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE));
-			VARIABLE *pVar = &LocalVar[MaxLocalVarNum];
-			MaxLocalVarNum++;
-
-			if( isRef ){
-				//参照型
-				pVar->fRef = REF_VARIABLE;
-				TypeSize = PTR_SIZE;
-			}
-			else pVar->fRef=0;
-
-			for(i2=1,i3=0;i3<255;i3++){
-				//配列要素数
-				pVar->SubScripts[i3]=SubScripts[i3];
-
-				if(SubScripts[i3]==-1) break;
-				i2*=SubScripts[i3]+1;
-			}
-			VarSize=TypeSize*i2;
-			if(VarSize%4) VarSize+=4-(VarSize%4);
-
-			//変数データを追加
-			lstrcpy(pVar->name,VarName);
-			if(dwFlags & DIMFLAG_CONST) pVar->bConst = true;
-			else pVar->bConst = false;
-			if(SubScripts[0]==-1) pVar->bArray=0;
-			else pVar->bArray=1;
-			pVar->type=TypeInfo.type;
-			pVar->u.index=TypeInfo.u.lpIndex;
-			AllLocalVarSize+=VarSize;
-			pVar->offset=AllLocalVarSize;
-
-			//レキシカルスコープ
-			pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
-			pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();
-			pVar->bLiving=TRUE;
-
-			if(InitBuf[0]){
-				//初期代入時のみ、書き込みアクセスを許可する
-				bool bConstBack = pVar->bConst;
-				pVar->bConst = false;
-
-				int result = InitLocalVar(-pVar->offset,
-					pVar->type,
-					pVar->u.index,
-					pVar->SubScripts,
-					InitBuf);
-
-				if(!result){
-					if( isRef ){
-						SetRefVariable( VarName, InitBuf );
-					}
-					else{
-						char temporary[8192];
-						sprintf(temporary,"%s=%s",VarName,InitBuf);
-						OpcodeCalc(temporary);
-					}
-				}
-
-				pVar->bConst = bConstBack;
-			}
-			else{
-				//push 0
-				op_push_value(0);
-
-				//push VarSize
-				op_push_value(VarSize);
-
-				//mov eax,ebp
-				OpBuffer[obp++]=(char)0x8B;
-				OpBuffer[obp++]=(char)0xC5;
-
-				//add eax,offset
-				OpBuffer[obp++]=(char)0x05;
-				*((long *)(OpBuffer+obp))=-pVar->offset;
-				AddLocalVarAddrSchedule();
-				obp+=sizeof(long);
-
-				//push eax
-				op_push(REG_EAX);
-
-				//call FillMemory
-				OpBuffer[obp++]=(char)0xFF;
-				OpBuffer[obp++]=(char)0x15;
-				DECLAREINFO *pdi;
-				pdi=GetDeclareHash("FillMemory");
-				pdi->bUse=1;
-				pobj_ImportAddrSchedule->add(pdi);
-				obp+=sizeof(long);
-			}
-		}
-
-		//コンストラクタ呼び出し
-		if(TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&& isRef == false ){
-			CallConstructor(VarName,SubScripts,TypeInfo,ConstractParameter);
-		}
-	}
-
-	if(TypeInfo.type==DEF_OBJECT){
-		if(TypeInfo.u.pobj_Class->IsAbstract()){
-			//抽象クラスだったとき
-			SetError(125,TypeInfo.u.pobj_Class->name,cp);
-		}
+		dim( isRef,VarName,SubScripts,TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags );
 	}
 }
