Index: BasicCompiler_Common/Variable.cpp
===================================================================
--- BasicCompiler_Common/Variable.cpp	(revision 63)
+++ BasicCompiler_Common/Variable.cpp	(revision 64)
@@ -157,9 +157,17 @@
 	else if(IsPtrType(type))		return PTR_SIZE;
 
-	else if(type==DEF_OBJECT){
+	else if( type == DEF_STRUCT ){
 		CClass *pobj_c;
 		pobj_c=(CClass *)lpIndex;
-		if(!pobj_c) return 0;
+		if(!pobj_c){
+			SetError(300,NULL,cp);
+			return 0;
+		}
+
 		return pobj_c->GetSize();
+	}
+
+	else if(type==DEF_OBJECT){
+		return PTR_SIZE;
 	}
 	else{
@@ -232,5 +240,11 @@
 	if(pobj_c){
 		*lpNum=(LONG_PTR)pobj_c;
-		return DEF_OBJECT;
+
+		if( pobj_c->IsStructure() ){
+			return DEF_STRUCT;
+		}
+		else{
+			return DEF_OBJECT;
+		}
 	}
 
@@ -282,5 +296,5 @@
 
 	//オブジェクト
-	else if(type==DEF_OBJECT){
+	else if(type==DEF_OBJECT || type==DEF_STRUCT){
 		if(lpIndex==0) lstrcpy(name,"non");
 		else{
@@ -296,5 +310,5 @@
 		else{
 			extern PROCPTRINFO *pProcPtrInfo;
-			if(pProcPtrInfo[lpIndex].ReturnType==-1)
+			if(pProcPtrInfo[lpIndex].ReturnType==DEF_NON)
 				lstrcpy(name,"*Sub");
 			else lstrcpy(name,"*Function");
@@ -316,5 +330,5 @@
 }
 
-bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, int &RefType, char *member ){
+bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member ){
 	int p1 = 0, p2 = 0;
 
@@ -323,4 +337,5 @@
 		if( term[i] == '[' ){
 			i = JumpStringInBracket( term, i + 1 );
+			if( term[i] == '\0' ) break;
 			continue;
 		}
@@ -328,4 +343,5 @@
 			int temp_p = i;
 			i = JumpStringInPare( term, i + 1 ) + 1;
+			if( term[i] == '\0' ) break;
 			if( term[i] == '.'
 				|| term[i] == 1 && term[i] == ESC_PSMEM ){
@@ -348,8 +364,8 @@
 	//参照タイプ
 	if( term[p2] == '.' ){
-		RefType = DEF_OBJECT;
+		refType = CClass::Dot;
 	}
 	else{
-		RefType = DEF_PTR_OBJECT;
+		refType = CClass::Pointer;
 		p2++;
 	}
@@ -361,5 +377,5 @@
 }
 
-BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,int *pRefType){
+BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember,CClass::RefType &refType){
 	extern int cp;
 	int i,i2,i3;
@@ -369,5 +385,4 @@
 	array2[0]=0;
 	NestMember[0]=0;
-	*pRefType=0;
 	for(i=0;;i++){
 		if(buffer[i]=='\"'){
@@ -428,5 +443,5 @@
 		if(buffer[i]=='.'){
 			lstrcpy(NestMember,buffer+i+1);
-			*pRefType=DEF_OBJECT;
+			refType = CClass::Dot;
 			buffer[i]=0;
 			break;
@@ -434,5 +449,5 @@
 		if(buffer[i]==1&&buffer[i+1]==ESC_PSMEM){
 			lstrcpy(NestMember,buffer+i+2);
-			*pRefType=DEF_PTR_OBJECT;
+			refType = CClass::Pointer;
 			buffer[i]=0;
 			break;
@@ -614,7 +629,7 @@
 	char lpPtrOffset[VN_SIZE];		//第2次配列
 	char NestMember[VN_SIZE];	//入れ子メンバ
-	int object_type;			//"."参照のときは0、"->"参照のときは1
+	CClass::RefType refType = CClass::Non;
 	lstrcpy(VarName,member);
-	if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,&object_type)) return 0;
+	if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return 0;
 
 	for(i=0;i<pobj_c->iMemberNum;i++){
@@ -664,5 +679,5 @@
 	}
 
-	if(object_type){
+	if( refType != CClass::Non ){
 		//入れ子構造の場合
 
@@ -704,6 +719,6 @@
 
 
-	int RefType;
-	if( FormatUseProcReturnObject( variable, VarName, array, RefType, member ) ){
+	CClass::RefType refType;
+	if( FormatUseProcReturnObject( variable, VarName, array, refType, member ) ){
 		// 戻り値オブジェクトのメンバを直接参照しているとき
 		//例: func().member
@@ -723,5 +738,5 @@
 
 	lstrcpy(VarName,variable);
-	GetVarFormatString(VarName,array,lpPtrOffset,member,&RefType);
+	GetVarFormatString(VarName,array,lpPtrOffset,member,refType);
 
 	int *pSubScripts;
@@ -825,5 +840,8 @@
 		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];
@@ -897,6 +915,8 @@
 
 	if(member[0]){
-		if(NATURAL_TYPE(type)==DEF_OBJECT)
-			return GetMemberType((CClass *)lpIndex,member,plpIndex,0,bError);
+		if( NATURAL_TYPE(type)==DEF_OBJECT
+			|| NATURAL_TYPE(type)==DEF_STRUCT){
+				return GetMemberType((CClass *)lpIndex,member,plpIndex,0,bError);
+		}
 	}
 
@@ -921,5 +941,5 @@
 }
 
-BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
+BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){
 	//読み取り専用で変数へアクセス
 	return GetVarOffset(
@@ -932,5 +952,5 @@
 		pss);
 }
-BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
+BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss ){
 	//読み書き両用で変数へアクセス
 	return GetVarOffset(
@@ -1095,4 +1115,6 @@
 	}
 
+	/*
+	TODO: 消す
 	if( pTypeInfo->type == DEF_OBJECT && InitBuf[0] != '\0' && InitBuf[0] != '[' && isRef == false ){
 		if( pTypeInfo->u.pobj_Class->GetCopyConstructorMethod() ){
@@ -1101,5 +1123,5 @@
 			InitBuf[0] = 0;
 		}
-	}
+	}*/
 
 	GetArrange(variable,VarName,SubScripts);
@@ -1191,15 +1213,4 @@
 	lstrcpy(pVar->ConstractParameter,ConstractParameter);
 
-	if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){
-		//初期バッファがあるとき
-		pVar->offset=AllInitGlobalVarSize;
-		AllInitGlobalVarSize+=VarSize;
-	}
-	else{
-		//初期バッファがないとき
-		pVar->offset=AllGlobalVarSize | 0x80000000;
-		AllGlobalVarSize+=VarSize;
-	}
-
 	//レキシカルスコープ
 	pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
@@ -1210,41 +1221,66 @@
 	pVar->source_code_address=cp;
 
-	//初期バッファにデータをセット
-	extern BYTE *initGlobalBuf;
-	initGlobalBuf=(BYTE *)HeapReAlloc(hHeap,
-		HEAP_ZERO_MEMORY,
-		initGlobalBuf,
-		AllInitGlobalVarSize);
+	//アラインメントを考慮
+	int alignment = 0;
+	if( pVar->type==DEF_STRUCT ){
+		alignment = pVar->u.pobj_c->iAlign;
+	}
+
+	if(InitBuf[0]||dwFlag==DIMFLAG_INITDEBUGVAR){
+		//初期バッファがあるとき
+
+		if( alignment ){
+			if( AllInitGlobalVarSize % alignment ){
+				AllInitGlobalVarSize += alignment - (AllInitGlobalVarSize % alignment);
+			}
+		}
+
+		pVar->offset=AllInitGlobalVarSize;
+		AllInitGlobalVarSize+=VarSize;
+	}
+	else{
+		//初期バッファがないとき
+
+		if( alignment ){
+			if( AllGlobalVarSize % alignment ){
+				AllGlobalVarSize += alignment - (AllGlobalVarSize % alignment);
+			}
+		}
+
+		pVar->offset=AllGlobalVarSize | 0x80000000;
+		AllGlobalVarSize+=VarSize;
+	}
+
 	if(InitBuf[0]){
-		if( pVar->type == DEF_OBJECT && InitBuf[0] != '[' ){
-			//単発式が初期値のオブジェクトの場合
-			//初期値をコピーコンストラクタに渡す
-
-			if( isRef ){
-				SetRefVariable( name, InitBuf );
-			}
-		}
-		else{
-			int result = SetInitGlobalData(pVar->offset,
+		int result = 0;
+		if( pVar->type != DEF_OBJECT ){
+			//初期バッファにデータをセット
+			extern BYTE *initGlobalBuf;
+			initGlobalBuf=(BYTE *)HeapReAlloc(hHeap,
+				HEAP_ZERO_MEMORY,
+				initGlobalBuf,
+				AllInitGlobalVarSize);
+
+			result = SetInitGlobalData(pVar->offset,
 				pVar->type,
 				pVar->u.index,
 				pVar->SubScripts,
 				InitBuf);
-
-			if(!result){
-				//動的な式だった場合は代入演算を行う
-
-				//初期代入時のみ、書き込みアクセスを許可する
-				bool bConstBack = pVar->bConst;
-				pVar->bConst = false;
-
-				//代入
-				char temporary[8192];
-				sprintf(temporary,"%s=%s",name,InitBuf);
-				OpcodeCalc(temporary);
-
-				//アクセス制限を元に戻す
-				pVar->bConst = bConstBack;
-			}
+		}
+
+		if(!result){
+			//動的な式だった場合は代入演算を行う
+
+			//初期代入時のみ、書き込みアクセスを許可する
+			bool bConstBack = pVar->bConst;
+			pVar->bConst = false;
+
+			//代入
+			char temporary[8192];
+			sprintf(temporary,"%s=%s",name,InitBuf);
+			OpcodeCalc(temporary);
+
+			//アクセス制限を元に戻す
+			pVar->bConst = bConstBack;
 		}
 	}
@@ -1260,4 +1296,5 @@
 
 /*
+	TODO: 消す
 	if(pTypeInfo->type==DEF_OBJECT){
 		//利用対象のクラスコンストラクタ、デストラクタに使用チェックをつける
