Index: BasicCompiler32/Compile_Var.cpp
===================================================================
--- BasicCompiler32/Compile_Var.cpp	(revision 36)
+++ BasicCompiler32/Compile_Var.cpp	(revision 40)
@@ -179,8 +179,10 @@
 	}
 
+	CMember *pMember=pobj_c->ppobj_Member[i];
+
 	//アクセシビリティをチェック
 	if(pobj_c==pobj_CompilingClass){
 		//同一クラスオブジェクトの場合はプライベートアクセスを容認する
-		if(pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
+		if(pMember->dwAccess==ACCESS_NON){
 			if(isErrorEnabled) SetError(107,VarName,cp);
 			return 0;
@@ -188,10 +190,10 @@
 	}
 	else{
-		if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
-			pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
+		if((bPrivateAccess==0&&pMember->dwAccess==ACCESS_PRIVATE)||
+			pMember->dwAccess==ACCESS_NON){
 			if(isErrorEnabled) SetError(107,VarName,cp);
 			return 0;
 		}
-		else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){
+		else if(bPrivateAccess==0&&pMember->dwAccess==ACCESS_PROTECTED){
 			if(isErrorEnabled) SetError(108,VarName,cp);
 			return 0;
@@ -201,5 +203,5 @@
 	//Const定義の場合は書き込みアクセスを制限する
 	//※コンストラクタをコンパイル中の場合は例外的に許可する
-	if( pobj_c->ppobj_Member[i]->IsConst() &&		//定数メンバである
+	if( pMember->IsConst() &&		//定数メンバである
 		isWriteAccess &&							//書き込みアクセスを要求されている
 		pobj_c->IsCompilingConstructor() == false	//コンストラクタ コンパイル中を除く
@@ -209,10 +211,10 @@
 	}
 
-	*pType=pobj_c->ppobj_Member[i]->TypeInfo.type;
-	*plpNestIndex=pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex;
+	*pType=pMember->TypeInfo.type;
+	*plpNestIndex=pMember->TypeInfo.u.lpIndex;
 
 	//ポインタ変数の場合
 	if(IsPtrType(*pType)){
-		if(pobj_c->ppobj_Member[i]->SubScripts[0]==-1){
+		if(pMember->SubScripts[0]==-1){
 			lstrcpy(lpPtrOffset,array);
 			array[0]=0;
@@ -236,8 +238,8 @@
 	if(array[0]){
 		//配列オフセット
-		if(!GetArrayOffset(pobj_c->ppobj_Member[i]->SubScripts,array,*pType,pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex))
+		if(!GetArrayOffset(pMember->SubScripts,array,*pType,pMember->TypeInfo.u.lpIndex))
 			if(isErrorEnabled) SetError(14,member,cp);
 	}
-	else if(pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){
+	else if(pMember->SubScripts[0]!=-1){
 		*pType|=FLAG_PTR;
 	}
@@ -320,5 +322,5 @@
 			isErrorEnabled,
 			isWriteAccess,
-			pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
+			pMember->TypeInfo.u.pobj_Class,
 			NestMember,
 			pType,
@@ -357,5 +359,5 @@
 }
 
-BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, char *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){
+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;
@@ -907,10 +909,4 @@
 	///////////////////////////////////////
 
-	if( type == DEF_OBJECT){
-		//オブジェクトの場合はありえない
-		SetError(300,NULL,cp);
-		return 0;
-	}
-
 	if(SubScripts[0]!=-1){
 		SetError(41,0,cp);
@@ -1064,5 +1060,5 @@
 }
 
-void dim(char *Parameter,DWORD dwFlag){
+void dim(char *Parameter,DWORD dwFlags){
 	extern BOOL bCompilingGlobal;
 	extern HANDLE hHeap;
@@ -1071,9 +1067,21 @@
 
 
-	if(dwFlag & DIMFLAG_CONST){
+	//参照型かどうか
+	bool isRef = false;
+
+	i2 = 0;
+
+	if( Parameter[i2] == 1 && Parameter[i2+1] == ESC_BYREF ){
+		//参照型
+		isRef = true;
+		Parameter += 2;
+	}
+
+
+	if(dwFlags & DIMFLAG_CONST){
 		//////////////////////////////////
 		// 定数変数の場合を考慮
 		//////////////////////////////////
-		for(i2=0;;i2++){
+		for(;;i2++){
 			if(Parameter[i2] == '=' ||
 				Parameter[i2] == 1 && Parameter[i2] == ESC_AS ||
@@ -1102,5 +1110,5 @@
 	char InitBuf[8192];
 	char ConstractParameter[VN_SIZE];
-	if(!GetDimentionFormat(Parameter,VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter))
+	if(!GetDimentionFormat(Parameter, isRef, VarName,SubScripts,&TypeInfo,InitBuf,ConstractParameter))
 		return;
 
@@ -1123,5 +1131,5 @@
 	TypeSize=GetTypeSize(TypeInfo.type,TypeInfo.u.lpIndex);
 
-	if(dwFlag&DIMFLAG_STATIC){
+	if(dwFlags&DIMFLAG_STATIC){
 		if(bCompilingGlobal){
 			SetError(60,NULL,cp);
@@ -1137,5 +1145,5 @@
 		GetNowStaticVarFullName(VarName,temporary);
 
-		AddGlobalVariable(temporary,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlag);
+		AddGlobalVariable(temporary,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);
 
 		/*
@@ -1150,5 +1158,5 @@
 			/////////////////////////
 
-			AddGlobalVariable(VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlag);
+			AddGlobalVariable(VarName,SubScripts,&TypeInfo,TypeSize,InitBuf,ConstractParameter,dwFlags);
 		}
 		else{
@@ -1168,8 +1176,17 @@
 
 			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++){
 				//配列要素数
-				LocalVar[MaxLocalVarNum].SubScripts[i3]=SubScripts[i3];
+				pVar->SubScripts[i3]=SubScripts[i3];
 
 				if(SubScripts[i3]==-1) break;
@@ -1179,12 +1196,7 @@
 			if(VarSize%4) VarSize+=4-(VarSize%4);
 
-			VARIABLE *pVar = &LocalVar[MaxLocalVarNum];
-
-			MaxLocalVarNum++;
-
 			//変数データを追加
 			lstrcpy(pVar->name,VarName);
-			pVar->fRef=0;
-			if(dwFlag & DIMFLAG_CONST) pVar->bConst = true;
+			if(dwFlags & DIMFLAG_CONST) pVar->bConst = true;
 			else pVar->bConst = false;
 			if(SubScripts[0]==-1) pVar->bArray=0;
@@ -1212,8 +1224,12 @@
 
 				if(!result){
-					//動的な式だった場合は代入演算を行う
-					char temporary[8192];
-					sprintf(temporary,"%s=%s",VarName,InitBuf);
-					OpcodeCalc(temporary);
+					if( isRef ){
+						SetRefVariable( VarName, InitBuf );
+					}
+					else{
+						char temporary[8192];
+						sprintf(temporary,"%s=%s",VarName,InitBuf);
+						OpcodeCalc(temporary);
+					}
 				}
 
@@ -1252,5 +1268,5 @@
 
 		//コンストラクタ呼び出し
-		if(TypeInfo.type==DEF_OBJECT&&(dwFlag&DIMFLAG_NONCALL_CONSTRACTOR)==0){
+		if(TypeInfo.type==DEF_OBJECT&&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0&& isRef == false ){
 			CallConstractor(VarName,SubScripts,TypeInfo,ConstractParameter);
 		}
@@ -1264,5 +1280,5 @@
 	}
 }
-void OpcodeDim(char *Parameter,DWORD dwFlag){
+void OpcodeDim(char *Parameter,DWORD dwFlags){
 	int i,i2,i3,IsStr=0;
 	char temporary[8192];
@@ -1286,5 +1302,5 @@
 			temporary[i2]=0;
 
-			dim(temporary,dwFlag);
+			dim(temporary,dwFlags);
 
 			if(Parameter[i]=='\0') break;
