Index: BasicCompiler64/Compile_ProcOp.cpp
===================================================================
--- BasicCompiler64/Compile_ProcOp.cpp	(revision 73)
+++ BasicCompiler64/Compile_ProcOp.cpp	(revision 75)
@@ -2,5 +2,5 @@
 #include "Opcode.h"
 
-void SystemProc(char *name){
+void SystemProc( const char *name ){
 	if(lstrcmp(name,"_System_GetEip")==0){
 		//mov rax,qword ptr[rsp]
@@ -22,8 +22,7 @@
 		}
 
-		extern BOOL bCompilingGlobal;
-		BOOL bBackCompilingGlobal;
-		bBackCompilingGlobal=bCompilingGlobal;
-		bCompilingGlobal=1;
+		UserProc *pBackUserProc;
+		pBackUserProc = &UserProc::CompilingUserProc();
+		UserProc::CompileStartForGlobalArea();
 
 		int BackCp;
@@ -56,5 +55,5 @@
 		*((long *)(OpBuffer+StackFrameSchedule))=pobj_sf->GetFrameSize();
 
-		bCompilingGlobal=bBackCompilingGlobal;
+		UserProc::CompileStartForUserProc( pBackUserProc );
 		cp=BackCp;
 
@@ -70,23 +69,17 @@
 		StackFrameSchedule=obp-sizeof(long);
 
-		extern int MaxGlobalVarNum;
-		extern VARIABLE *GlobalVar;
-		int i;
-		for(i=0;i<MaxGlobalVarNum;i++){
-			if(memicmp(GlobalVar[i].name,"Static%",7)==0){
+		foreach( Variable *pVar, globalVars ){
+			if(memicmp(pVar->GetName().c_str(),"Static%",7)==0){
 				//コンストラクタ呼び出し
-				if(GlobalVar[i].type==DEF_OBJECT){
+				if( pVar->IsObject() ){
 
 					//エラー用
-					cp=GlobalVar[i].source_code_address;
-
-					TYPEINFO TypeInfo;
-					TypeInfo.type=GlobalVar[i].type;
-					TypeInfo.u.lpIndex=GlobalVar[i].u.index;
+					cp=pVar->source_code_address;
+
 					CallConstructor(
-						GlobalVar[i].name,
-						GlobalVar[i].SubScripts,
-						TypeInfo,
-						GlobalVar[i].ConstractParameter);
+						pVar->GetName().c_str(),
+						pVar->GetSubScriptsPtr(),
+						*pVar,
+						pVar->paramStrForConstructor.c_str());
 				}
 			}
@@ -107,12 +100,11 @@
 
 
-		extern BOOL bCompilingGlobal;
-		BOOL bBackCompilingGlobal;
-		bBackCompilingGlobal=bCompilingGlobal;
-		bCompilingGlobal=1;
+		UserProc *pBackUserProc;
+		pBackUserProc = &UserProc::CompilingUserProc();
+		UserProc::CompileStartForGlobalArea();
 
 		obj_LexScopes.CallDestructorsOfScopeEnd();
 
-		bCompilingGlobal=bBackCompilingGlobal;
+		UserProc::CompileStartForUserProc( pBackUserProc );
 
 
@@ -204,28 +196,26 @@
 	}
 }
-void CompileBufferInProcedure(SubInfo *psi){
+void CompileBufferInProcedure(UserProc *pUserProc){
 	extern char *basbuf;
 	extern HANDLE hHeap;
-	extern SubInfo **ppSubHash;
+	extern UserProc **ppSubHash;
 	extern BOOL bDebugCompile;
-	int i3,i4,VarSize,BufferSize;
+	int i3,i4,BufferSize;
 	char temporary[VN_SIZE];
 
 	BufferSize=128;
 
-	if(psi->bUse==0||psi->bCompile) return;
-
-
-	psi->bCompile=1;
+	if( pUserProc->IsUsing() == false || pUserProc->IsCompiled() ) return;
+
+	pUserProc->CompleteCompile();
 
 	extern BOOL bSystemProc;
-	if(memcmp(psi->name,"_System_",8)==0) bSystemProc=1;
+	if(memcmp(pUserProc->GetName().c_str(),"_System_",8)==0) bSystemProc=1;
 	else bSystemProc=0;
 
 	extern BOOL bDebugSupportProc;
-	if(memcmp(psi->name,"_DebugSys_",10)==0){
+	if(memcmp(pUserProc->GetName().c_str(),"_DebugSys_",10)==0){
 		if(!bDebugCompile){
-			psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
-			psi->VarNum=0;
+			pUserProc->localVars.clear();
 			return;
 		}
@@ -234,7 +224,7 @@
 	else bDebugSupportProc=0;
 
-	psi->CompileAddress=obp;
-
-	if(psi->bSystem){
+	pUserProc->beginOpAddress=obp;
+
+	if(pUserProc->IsSystem()){
 		////////////////////
 		// 特殊関数
@@ -250,5 +240,5 @@
 		pobj_sf=new CStackFrame();
 
-		SystemProc(psi->name);
+		SystemProc(pUserProc->GetName().c_str());
 
 		//スタックフレーム管理用オブジェクトを破棄
@@ -256,11 +246,10 @@
 		pobj_sf=0;
 
-		psi->EndOpAddr=obp;
-		psi->pVar=(VARIABLE *)HeapAlloc(hHeap,0,1);
-		psi->VarNum=0;
+		pUserProc->endOpAddress=obp;
+		pUserProc->localVars.clear();
 		return;
 	}
 
-	cp=psi->address;
+	cp=pUserProc->GetCodePos();
 	for(;;cp++){
 		if(IsCommandDelimitation(basbuf[cp])) break;
@@ -303,10 +292,7 @@
 
 	//ローカル変数に関する情報
-	extern VARIABLE *LocalVar;
-	extern int MaxLocalVarNum;
 	extern int AllLocalVarSize;
-	LocalVar=(VARIABLE *)HeapAlloc(hHeap,0,sizeof(VARIABLE));
-	MaxLocalVarNum=0;
 	AllLocalVarSize=0;
+	pUserProc->localVars.clear();
 
 	//ローカル変数アドレススケジュール
@@ -324,50 +310,37 @@
 	/////////////////////////////////////
 
-	for(i3=psi->RealParmNum-1;i3>=0;i3--){
-		//変数データを追加
-		LocalVar=(VARIABLE *)HeapReAlloc(hHeap,0,LocalVar,(MaxLocalVarNum+1)*sizeof(VARIABLE));
-
-		lstrcpy(LocalVar[MaxLocalVarNum].name,psi->realParams[i3].GetVarName.c_str());
-
-		// TODO: パラメータのConst定義の指定が未完成
-		LocalVar[MaxLocalVarNum].bConst=false;
-
-		LocalVar[MaxLocalVarNum].bArray=psi->realParams[i3].IsArray()?TRUE:FALSE;
-		memcpy(LocalVar[MaxLocalVarNum].SubScripts,psi->realParams[i3].GetSubScriptsPtr(),MAX_ARRAYDIM*sizeof(int));
-
-		LocalVar[MaxLocalVarNum].type=psi->realParams[i3].GetBasicType();
-		if(LocalVar[MaxLocalVarNum].type==DEF_OBJECT
-			||LocalVar[MaxLocalVarNum].type==DEF_STRUCT){
-				if(psi->bExport)
-					SetError(24,NULL,cp);
-		}
-
-		LocalVar[MaxLocalVarNum].u.index=psi->realParams[i3].GetIndex();
-
-		if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsStruct()){
+	//パラメータ用の変数データを考慮
+	for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
+		Parameter &param = *pUserProc->RealParams()[i3];
+
+		Variable *pVar = new Variable( param.GetVarName(), param, false, param.IsRef() );
+
+		if( param.IsArray() ){
+			pVar->SetArray( param.GetSubScriptsPtr() );
+		}
+
+		int varSize;
+		if( param.IsRef() == false && param.IsStruct() ){
 			//構造体のByValパラメータ
-			LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER | OBJECT_PARAMETER;
-			VarSize=PTR_SIZE;
+			pVar->ThisIsParameter();
+			varSize=PTR_SIZE;
 		}
 		else{
-			if(psi->realParams[i3].IsRef() == false&&psi->realParams[i3].IsArray()){
-				LocalVar[MaxLocalVarNum].fRef=0;
-				VarSize=GetTypeSize(LocalVar[MaxLocalVarNum].type,LocalVar[MaxLocalVarNum].u.index);
-				if(VarSize%PTR_SIZE) VarSize+=PTR_SIZE-(VarSize%PTR_SIZE);
+			if( param.IsArray() == false ){
+				varSize = pVar->GetMemorySize();
 			}
 			else{
-				LocalVar[MaxLocalVarNum].fRef=REF_PARAMETER;
-				VarSize=PTR_SIZE;
-			}
-		}
-		AllLocalVarSize+=VarSize;
-		LocalVar[MaxLocalVarNum].offset=AllLocalVarSize;
+				varSize=PTR_SIZE;
+			}
+		}
+		AllLocalVarSize+=varSize;
+		pVar->offset=AllLocalVarSize;
 
 		//レキシカルスコープ情報
-		LocalVar[MaxLocalVarNum].ScopeLevel=obj_LexScopes.GetNowLevel();
-		LocalVar[MaxLocalVarNum].ScopeStartAddress=obj_LexScopes.GetStartAddress();
-		LocalVar[MaxLocalVarNum].bLiving=TRUE;
-
-		MaxLocalVarNum++;
+		pVar->ScopeLevel=obj_LexScopes.GetNowLevel();
+		pVar->ScopeStartAddress=obj_LexScopes.GetStartAddress();
+		pVar->bLiving=TRUE;
+
+		pUserProc->localVars.push_back( pVar );
 	}
 
@@ -377,12 +350,11 @@
 
 	//コンパイル中の関数が属するクラス
-	pobj_CompilingClass=psi->pobj_ParentClass;
-	
+	pobj_CompilingClass=pUserProc->GetParentClassPtr();
+
 	//コンパイルスタートをクラス管理クラスに追加
-	pobj_DBClass->StartCompile( psi );
+	pobj_DBClass->StartCompile( pUserProc );
 
 	//コンパイル中の関数
-	extern SubInfo *pCompilingSubInfo;
-	pCompilingSubInfo=psi;
+	UserProc::CompileStartForUserProc( pUserProc );
 
 	//スタックフレーム管理用クラスを初期化
@@ -394,7 +366,8 @@
 	// ここからコード生成
 
-	for(i3=psi->RealParmNum-1;i3>=0;i3--){
+	for(i3=(int)pUserProc->RealParams().size()-1;i3>=0;i3--){
+		Parameter &param = *pUserProc->RealParams()[i3];
 		if(i3==3){
-			if(psi->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){
+			if(param.IsReal()&&param.IsRef() == false){
 				//movsd qword ptr[rsp+0x20],xmm3
 				op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);
@@ -406,5 +379,5 @@
 		}
 		if(i3==2){
-			if(psi->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){
+			if(param.IsReal()&&param.IsRef() == false){
 				//movsd qword ptr[rsp+0x18],xmm2
 				op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);
@@ -416,5 +389,5 @@
 		}
 		if(i3==1){
-			if(psi->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){
+			if(param.IsReal()&&param.IsRef() == false){
 				//movsd qword ptr[rsp+0x10],xmm1
 				op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);
@@ -426,5 +399,5 @@
 		}
 		if(i3==0){
-			if(psi->realParams[i3].IsReal()&&psi->realParams[i3].IsRef() == false){
+			if(param.IsReal()&&param.IsRef() == false){
 				//movsd qword ptr[rsp+0x8],xmm0
 				op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);
@@ -458,23 +431,18 @@
 	BaseLocalVar=AllLocalVarSize;
 
-	if(psi->ReturnType!=DEF_NON){
+	if( !pUserProc->ReturnType().IsNull() ){
 		//戻り値が存在するとき
 
-		char *temp;
-		if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR) temp="_System_ReturnValue";
-		else temp=psi->name;
-
-		if(psi->ReturnType==DEF_STRUCT && psi->isReturnRef == false){
+		const char *temp = pUserProc->GetName().c_str();
+		if( temp[0]==1&&temp[1]==ESC_OPERATOR ){
+			temp = "_System_ReturnValue";
+		}
+
+		if( pUserProc->ReturnType().IsStruct() ){
 			//戻り値用の構造体（値型）はパラメータで引き渡される
 		}
 		else{
 			//戻り値用の変数の定義
-			if( psi->isReturnRef ){
-				sprintf(temporary,"%c%c",1,ESC_BYREF);
-			}
-			else temporary[0]=0;
-
-			sprintf(temporary+lstrlen(temporary),"%s%c%c",temp,1,ESC_AS);
-			GetTypeName(psi->ReturnType,psi->u.ReturnIndex,temporary+lstrlen(temporary));
+			sprintf(temporary,"%s%c%c%s",temp,1,ESC_AS, pUserProc->ReturnType().ToString().c_str() );
 
 			OpcodeDim(temporary,0);
@@ -497,10 +465,10 @@
 
 		//call _DebugSys_StartProc
-		extern SubInfo *pSub_DebugSys_StartProc;
+		extern UserProc *pSub_DebugSys_StartProc;
 		op_call(pSub_DebugSys_StartProc);
 	}
 
 	if(pobj_CompilingClass){
-		if(lstrcmp(psi->name,pobj_CompilingClass->name)==0){
+		if( pUserProc->GetName() == pobj_CompilingClass->name ){
 			////////////////////////////////////
 			// コンストラクタをコンパイルするとき
@@ -550,5 +518,5 @@
 
 					Opcode_CallProc(temporary,
-						pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->psi,
+						pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc,
 						0,
 						"",
@@ -558,5 +526,5 @@
 					//基底クラスのコンストラクタを暗黙的に呼び出す
 					Opcode_CallProc("",
-						pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->psi,
+						pobj_CompilingClass->pobj_InheritsClass->GetConstructorMethod()->pUserProc,
 						0,
 						"",
@@ -568,5 +536,5 @@
 			for(i3=0;i3<pobj_CompilingClass->iMemberNum;i3++){
 				CMember *pMember = pobj_CompilingClass->ppobj_Member[i3];
-				if(pMember->TypeInfo.type==DEF_OBJECT){
+				if(pMember->IsObject()){
 					// オブジェクトメンバを発見したとき
 
@@ -574,5 +542,5 @@
 						pMember->name,
 						1, ESC_NEW,
-						pMember->TypeInfo.u.pobj_Class->name );
+						pMember->GetClass().name );
 					OpcodeCalc( temporary );
 				}
@@ -598,5 +566,5 @@
 			}
 		}
-		else if(psi->name[0]=='~'){
+		else if( pUserProc->IsDestructor() ){
 			//デストラクタをコンパイルしたとき
 
@@ -609,7 +577,9 @@
 	//////////////////////////////////////////
 	////// プロシージャ内をコンパイル ////////
-	if(psi->dwType==SUBTYPE_SUB) CompileBuffer(ESC_ENDSUB,0);
-	else if(psi->dwType==SUBTYPE_FUNCTION) CompileBuffer(ESC_ENDFUNCTION,0);
-	else if(psi->dwType==SUBTYPE_MACRO) CompileBuffer(ESC_ENDMACRO,0);
+	if(pUserProc->IsMacro()) CompileBuffer(ESC_ENDMACRO,0);
+	else{
+		if(pUserProc->IsSub()) CompileBuffer(ESC_ENDSUB,0);
+		else if(pUserProc->IsFunction()) CompileBuffer(ESC_ENDFUNCTION,0);
+	}
 	//////////////////////////////////////////
 	//////////////////////////////////////////
@@ -623,5 +593,5 @@
 			pobj_CompilingClass->NotifyFinishConstructorCompile();
 		}
-		else if(psi->name[0]=='~'){
+		else if( pUserProc->IsDestructor() ){
 			////////////////////////////////////
 			//デストラクタをコンパイルしたとき
@@ -638,5 +608,5 @@
 				if( method ){
 					Opcode_CallProc("",
-						method->psi,
+						method->pUserProc,
 						0,
 						"",
@@ -659,6 +629,6 @@
 				int offset = pobj_CompilingClass->GetMemberOffset( pMember->name, NULL );
 
-				if(pMember->TypeInfo.type==DEF_OBJECT){
-					CMethod *method = pMember->TypeInfo.u.pobj_Class->GetDestructorMethod();
+				if(pMember->IsObject()){
+					CMethod *method = pMember->GetClass().GetDestructorMethod();
 					if( method ){
 						for(i4=MemberObjectNum-1;i4>=0;i4--){
@@ -670,5 +640,5 @@
 
 							//call destructor
-							op_call(method->psi);
+							op_call(method->pUserProc);
 						}
 					}
@@ -705,8 +675,4 @@
 	HeapDefaultFree(WithInfo.pWithCp);
 
-	//重複エラー情報管理のメモリを解放
-	for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
-	HeapDefaultFree(SynonymErrorWords);
-
 	//ローカルオブジェクト（レキシカルスコープレベル=0）の解放処理
 	obj_LexScopes.CallDestructorsOfScopeEnd();
@@ -720,9 +686,9 @@
 	if(bDebugCompile&&bDebugSupportProc==0){
 		//call _DebugSys_EndProc
-		extern SubInfo *pSub_DebugSys_EndProc;
+		extern UserProc *pSub_DebugSys_EndProc;
 		op_call(pSub_DebugSys_EndProc);
 	}
 
-	if(psi->ReturnType!=DEF_NON){
+	if( !pUserProc->ReturnType().IsNull() ){
 		//////////////////////////////////
 		// 戻り値をraxまたはxmm0に設定
@@ -730,13 +696,12 @@
 
 		RELATIVE_VAR RelativeVar;
-		LONG_PTR lpIndex;
-
-		char *temp;
-		if(psi->name[0]==1&&psi->name[1]==ESC_OPERATOR)
+
+		const char *temp = pUserProc->GetName().c_str();
+		if( temp[0]==1 && temp[1]==ESC_OPERATOR ){
 			temp="_System_ReturnValue";
-		else temp=psi->name;
-		GetVarOffsetReadWrite(temp,&i3,&RelativeVar,&lpIndex);
-
-		i3=psi->ReturnType;
+		}
+		GetVarOffsetReadWrite(temp,&RelativeVar,Type());
+
+		i3=pUserProc->ReturnType().GetBasicType();
 
 		if(i3==DEF_OBJECT || i3==DEF_STRUCT){
@@ -772,7 +737,7 @@
 	}
 	HeapDefaultFree(pLocalVarAddrSchedule);
-	for(i3=0;i3<MaxLocalVarNum;i3++){
+	foreach( Variable *pVar, pUserProc->localVars ){
 		//後にデバッグで利用する
-		LocalVar[i3].offset=AllLocalVarSize+pobj_sf->GetFrameSize()-LocalVar[i3].offset;
+		pVar->offset = AllLocalVarSize + pobj_sf->GetFrameSize() - pVar->offset;
 	}
 
@@ -812,21 +777,22 @@
 
 
-	psi->EndOpAddr=obp;
-	psi->pVar=LocalVar;
-	psi->VarNum=MaxLocalVarNum;
-
-	//ローカル変数のネーム情報は後に解放する
+	pUserProc->endOpAddress=obp;
+
+
+	//重複エラー情報管理のメモリを解放
+	for(i3=0;i3<SynonymErrorNum;i3++) HeapDefaultFree(SynonymErrorWords[i3]);
+	HeapDefaultFree(SynonymErrorWords);
 }
 void CompileLocal(){
-	extern SubInfo **ppSubHash;
+	extern UserProc **ppSubHash;
 	int i2;
-	SubInfo *psi;
+	UserProc *pUserProc;
 
 	extern BOOL bDll;
 	if(bDll){
 		//DLLの場合はグローバル変数を初期化するための関数を一番初めにコンパイルする
-		psi=GetSubHash("_System_InitDllGlobalVariables");
-		if(psi){
-			CompileBufferInProcedure(psi);
+		pUserProc=GetSubHash("_System_InitDllGlobalVariables");
+		if(pUserProc){
+			CompileBufferInProcedure(pUserProc);
 		}
 		else SetError(300,NULL,cp);
@@ -835,17 +801,17 @@
 	//_System_InitStaticLocalVariablesは一番最後にコンパイル
 	//※一般関数内の静的変数オブジェクトをすべて収集しなければならない
-	extern SubInfo *pSub_System_InitStaticLocalVariables;
-	pSub_System_InitStaticLocalVariables->bCompile=1;
+	extern UserProc *pSub_System_InitStaticLocalVariables;
+	pSub_System_InitStaticLocalVariables->CompleteCompile();
 
 	//_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
-	extern SubInfo *pSub_System_Call_Destructor_of_GlobalObject;
-	pSub_System_Call_Destructor_of_GlobalObject->bCompile=1;
+	extern UserProc *pSub_System_Call_Destructor_of_GlobalObject;
+	pSub_System_Call_Destructor_of_GlobalObject->CompleteCompile();
 
 Repeat:
 	for(i2=0;i2<MAX_HASH;i2++){
-		psi=ppSubHash[i2];
-		while(psi){
-			CompileBufferInProcedure(psi);
-			psi=psi->pNextData;
+		pUserProc=ppSubHash[i2];
+		while(pUserProc){
+			CompileBufferInProcedure(pUserProc);
+			pUserProc=pUserProc->pNextData;
 		}
 	}
@@ -853,20 +819,20 @@
 	//プロシージャコンパイルによって、プロシージャコンパイルが必要になる場合
 	for(i2=0;i2<MAX_HASH;i2++){
-		psi=ppSubHash[i2];
-		while(psi){
-			if(psi->bUse&&psi->bCompile==0&&psi->bVirtual==0){
+		pUserProc=ppSubHash[i2];
+		while(pUserProc){
+			if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){
 				goto Repeat;
 			}
 
-			psi=psi->pNextData;
+			pUserProc=pUserProc->pNextData;
 		}
 	}
 
 	//_System_InitStaticLocalVariablesは一番最後にコンパイル
-	pSub_System_InitStaticLocalVariables->bCompile=0;
+	pSub_System_InitStaticLocalVariables->KillCompileStatus();
 	CompileBufferInProcedure(pSub_System_InitStaticLocalVariables);
 
 	//_System_Call_Destructor_of_GlobalObjectは一番最後にコンパイル
-	pSub_System_Call_Destructor_of_GlobalObject->bCompile=0;
+	pSub_System_Call_Destructor_of_GlobalObject->KillCompileStatus();
 	CompileBufferInProcedure(pSub_System_Call_Destructor_of_GlobalObject);
 }
