Index: BasicCompiler64/MakePeHdr.cpp
===================================================================
--- BasicCompiler64/MakePeHdr.cpp	(revision 73)
+++ BasicCompiler64/MakePeHdr.cpp	(revision 75)
@@ -6,5 +6,5 @@
 // 特殊関数の構造体ポインタ
 ////////////////////////////
-SubInfo
+UserProc
 	*pSub_System_StartupProgram,
 	*pSub_DebugSys_StartProc,
@@ -136,7 +136,7 @@
 
 	//関数ポインタ情報を初期化
-	extern PROCPTRINFO *pProcPtrInfo;
+	extern ProcPointer **ppProcPointer;
 	extern int ProcPtrInfoNum;
-	pProcPtrInfo=(PROCPTRINFO *)HeapAlloc(hHeap,0,1);
+	ppProcPointer=(ProcPointer **)HeapAlloc(hHeap,0,1);
 	ProcPtrInfoNum=0;
 
@@ -170,60 +170,60 @@
 
 	if(pSub_System_StartupProgram=GetSubHash("_System_StartupProgram",1))
-		pSub_System_StartupProgram->bUse=1;
+		pSub_System_StartupProgram->Using();
 
 	if(pSub_DebugSys_StartProc=GetSubHash("_DebugSys_StartProc",1))
-		pSub_DebugSys_StartProc->bUse=1;
+		pSub_DebugSys_StartProc->Using();
 
 	if(pSub_DebugSys_EndProc=GetSubHash("_DebugSys_EndProc",1))
-		pSub_DebugSys_EndProc->bUse=1;
+		pSub_DebugSys_EndProc->Using();
 
 	if(pSub_DebugSys_SaveContext=GetSubHash("_DebugSys_SaveContext",1))
-		pSub_DebugSys_SaveContext->bUse=1;
+		pSub_DebugSys_SaveContext->Using();
 
 	if(pSub_System_GetEip=GetSubHash("_System_GetEip",1)){
-		pSub_System_GetEip->bUse=1;
-		pSub_System_GetEip->bSystem=1;
+		pSub_System_GetEip->Using();
+		pSub_System_GetEip->ThisIsSystemProc();
 	}
 
 	if(pSub_System_InitDllGlobalVariables=GetSubHash("_System_InitDllGlobalVariables",1)){
-		pSub_System_InitDllGlobalVariables->bUse=1;
-		pSub_System_InitDllGlobalVariables->bSystem=1;
+		pSub_System_InitDllGlobalVariables->Using();
+		pSub_System_InitDllGlobalVariables->ThisIsSystemProc();
 	}
 
 	if(pSub_System_InitStaticLocalVariables=GetSubHash("_System_InitStaticLocalVariables",1)){
-		pSub_System_InitStaticLocalVariables->bUse=1;
-		pSub_System_InitStaticLocalVariables->bSystem=1;
+		pSub_System_InitStaticLocalVariables->Using();
+		pSub_System_InitStaticLocalVariables->ThisIsSystemProc();
 	}
 
 	if(pSub_System_Call_Destructor_of_GlobalObject=GetSubHash("_System_Call_Destructor_of_GlobalObject",1)){
-		pSub_System_Call_Destructor_of_GlobalObject->bUse=1;
-		pSub_System_Call_Destructor_of_GlobalObject->bSystem=1;
+		pSub_System_Call_Destructor_of_GlobalObject->Using();
+		pSub_System_Call_Destructor_of_GlobalObject->ThisIsSystemProc();
 	}
 
 	if(pSub_System_GetSp=GetSubHash("_System_GetSp",1)){
-		pSub_System_GetSp->bUse=1;
-		pSub_System_GetSp->bSystem=1;
+		pSub_System_GetSp->Using();
+		pSub_System_GetSp->ThisIsSystemProc();
 	}
 
 	if(pSub_pow=GetSubHash("pow",1))
-		pSub_pow->bUse=1;
+		pSub_pow->Using();
 
 	if(pSub_calloc=GetSubHash("calloc",1))
-		pSub_calloc->bUse=1;
+		pSub_calloc->Using();
 
 	if(pSub_realloc=GetSubHash("realloc",1))
-		pSub_realloc->bUse=1;
+		pSub_realloc->Using();
 
 	if(pSub_free=GetSubHash("free",1))
-		pSub_free->bUse=1;
+		pSub_free->Using();
 
 	if( pSub_System_GC_malloc_ForObject = GetSubHash( "_System_GC_malloc_ForObject",1 ) )
-		pSub_System_GC_malloc_ForObject->bUse = 1;
+		pSub_System_GC_malloc_ForObject->Using();
 
 	if( pSub_System_GC_malloc_ForObjectPtr = GetSubHash( "_System_GC_malloc_ForObjectPtr",1 ) )
-		pSub_System_GC_malloc_ForObjectPtr->bUse = 1;
+		pSub_System_GC_malloc_ForObjectPtr->Using();
 
 	if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) )
-		pSub_System_GC_free_for_SweepingDelete->bUse = 1;
+		pSub_System_GC_free_for_SweepingDelete->Using();
 
 
@@ -271,6 +271,5 @@
 
 	cp=-1;
-	extern BOOL bCompilingGlobal;
-	bCompilingGlobal=1;
+	UserProc::CompileStartForGlobalArea();
 
 	if(!bDll){
@@ -352,5 +351,5 @@
 
 		//call _System_Call_Destructor_of_GlobalObject
-		extern SubInfo *pSub_System_Call_Destructor_of_GlobalObject;
+		extern UserProc *pSub_System_Call_Destructor_of_GlobalObject;
 		op_call(pSub_System_Call_Destructor_of_GlobalObject);
 
@@ -405,6 +404,4 @@
 	/////////////////////
 
-	bCompilingGlobal=0;
-
 	//プロシージャをコンパイル開始
 	cp=0;
@@ -429,10 +426,9 @@
 	////////////////////////////////
 	for(i=0;i<MAX_HASH;i++){
-		extern DECLAREINFO **ppDeclareHash;
-		DECLAREINFO *pdi;
-		pdi=ppDeclareHash[i];
-		while(pdi){
-			if(pdi->bUse==0){
-				pdi=pdi->pNextData;
+		extern DllProc **ppDeclareHash;
+		const DllProc *pDllProc = ppDeclareHash[i];
+		while(pDllProc){
+			if( !pDllProc->IsUsing() ){
+				pDllProc=pDllProc->pNextData;
 				continue;
 			}
@@ -440,5 +436,5 @@
 			//エラーチェック
 			HINSTANCE hLib;
-			hLib=LoadLibrary(pdi->file);
+			hLib=LoadLibrary( pDllProc->GetDllFileName().c_str() );
 			if(!hLib){
 				extern char OutputFileName[MAX_PATH];
@@ -446,22 +442,22 @@
 				_splitpath(OutputFileName,temp2,temp3,NULL,NULL);
 				lstrcat(temp2,temp3);
-				lstrcpy(temp3,pdi->file);
+				lstrcpy(temp3,pDllProc->GetDllFileName().c_str());
 				GetFullPath(temp3,temp2);
 				hLib=LoadLibrary(temp3);
 
 				if(!hLib){
-					SetError(-106,pdi->file,pdi->pos);
+					SetError(-106,pDllProc->GetDllFileName().c_str(),pDllProc->GetCodePos());
 				}
 			}
 
 			if(hLib){
-				if(!GetProcAddress(hLib,pdi->alias)){
+				if(!GetProcAddress(hLib,pDllProc->GetAlias().c_str())){
 					FreeLibrary(hLib);
-					SetError(-107,pdi->alias,pdi->pos);
+					SetError(-107,pDllProc->GetAlias(),pDllProc->GetCodePos());
 				}
 				FreeLibrary(hLib);
 			}
 
-			pdi=pdi->pNextData;
+			pDllProc=pDllProc->pNextData;
 		}
 	}
@@ -500,40 +496,41 @@
 		ExportNamesLength=lstrlen(lpExportNames)+1;
 
-		extern SubInfo **ppSubHash;
-		SubInfo *psi,*psi2;
+		extern UserProc **ppSubHash;
+		UserProc *pUserProc,*psi2;
 		while(1){
 			//辞書順にサーチ
 			temporary[0]=0;
 			for(i=0,psi2=0;i<MAX_HASH;i++){
-				psi=ppSubHash[i];
-				while(psi){
-					if(psi->bExport){
+				pUserProc=ppSubHash[i];
+				while(pUserProc){
+					if(pUserProc->IsExport()){
 						if(temporary[0]=='\0'){
-							lstrcpy(temporary,psi->name);
-							psi2=psi;
+							lstrcpy(temporary,pUserProc->GetName().c_str());
+							psi2=pUserProc;
 						}
 						else{
 							i3=lstrlen(temporary);
-							i4=lstrlen(psi->name);
+							i4=(int)pUserProc->GetName().size();
 							if(i3<i4) i3=i4;
-							if(memcmp(temporary,psi->name,i3)>0){
-								lstrcpy(temporary,psi->name);
-								psi2=psi;
+							if(memcmp(temporary,pUserProc->GetName().c_str(),i3)>0){
+								lstrcpy(temporary,pUserProc->GetName().c_str());
+								psi2=pUserProc;
 							}
 						}
 					}
-					psi=psi->pNextData;
+					pUserProc=pUserProc->pNextData;
 				}
 			}
 			if(psi2==0) break;
-			psi=psi2;
-
-			psi->bExport=0;
-
-			if(lstrcmpi(psi->name,"DllMain")==0)
-				DllMain_EntryPoint=psi->CompileAddress;
+			pUserProc=psi2;
+
+			pUserProc->ExportOff();
+
+			if( pUserProc->GetName() == "DllMain" ){
+				DllMain_EntryPoint=pUserProc->beginOpAddress;
+			}
 
 			lpdwExportAddressTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportAddressTable,(ExportNum+1)*sizeof(DWORD));
-			lpdwExportAddressTable[ExportNum]=psi->CompileAddress;
+			lpdwExportAddressTable[ExportNum]=pUserProc->beginOpAddress;
 
 			lpdwExportNamePointerTable=(DWORD *)HeapReAlloc(hHeap,0,lpdwExportNamePointerTable,(ExportNum+1)*sizeof(DWORD));
@@ -543,5 +540,5 @@
 			lpwExportOrdinalTable[ExportNum]=ExportNum;
 
-			lstrcpy(lpExportNames+ExportNamesLength,psi->name);
+			lstrcpy(lpExportNames+ExportNamesLength,pUserProc->GetName().c_str());
 			ExportNamesLength+=lstrlen(lpExportNames+ExportNamesLength)+1;
 
@@ -576,6 +573,6 @@
 	//インポートDLL情報
 	/////////////////////
-	extern DECLAREINFO **ppDeclareHash;
-	DECLAREINFO *pdi;
+	extern DllProc **ppDeclareHash;
+	DllProc *pDllProc;
 	char **ppDllNames;
 	int ImportDllNum;
@@ -613,27 +610,28 @@
 	ImportDllNum=0;
 	for(i=0;i<MAX_HASH;i++){
-		pdi=ppDeclareHash[i];
-		while(pdi){
-			if(pdi->dwType==DECLARE_STATIC||
-				pdi->bUse==0){
-				pdi=pdi->pNextData;
+		const DllProc *pDllProc=ppDeclareHash[i];
+		while(pDllProc){
+			if( !pDllProc->IsUsing() ){
+				pDllProc=pDllProc->pNextData;
 				continue;
 			}
 
-			if(lstrlen(pdi->file)>16){
+			if( pDllProc->GetDllFileName().size() > 16 ){
 				SetError(7,NULL,cp);
 				break;
 			}
 			for(i2=0;i2<ImportDllNum;i2++){
-				if(lstrcmp(ppDllNames[i2],pdi->file)==0) break;
+				if( pDllProc->GetDllFileName() == ppDllNames[i2] ){
+					break;
+				}
 			}
 			if(i2==ImportDllNum){
 				ppDllNames=(char **)HeapReAlloc(hHeap,0,ppDllNames,(ImportDllNum+1)*sizeof(char **));
 				ppDllNames[ImportDllNum]=(char *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,16);
-				lstrcpy(ppDllNames[ImportDllNum],pdi->file);
+				lstrcpy(ppDllNames[ImportDllNum],pDllProc->GetDllFileName().c_str());
 				ImportDllNum++;
 			}
 
-			pdi=pdi->pNextData;
+			pDllProc=pDllProc->pNextData;
 		}
 	}
@@ -651,18 +649,17 @@
 		pImportDescriptor[i].Name=i*0x10;	//※すぐ下で再計算
 		for(i2=0;i2<MAX_HASH;i2++){
-			pdi=ppDeclareHash[i2];
-			while(pdi){
-				if(pdi->dwType==DECLARE_STATIC||
-					pdi->bUse==0){
-					pdi=pdi->pNextData;
+			pDllProc=ppDeclareHash[i2];
+			while(pDllProc){
+				if( !pDllProc->IsUsing() ){
+					pDllProc=pDllProc->pNextData;
 					continue;
 				}
 
-				if(lstrcmp(ppDllNames[i],pdi->file)==0){
+				if( pDllProc->GetDllFileName() == ppDllNames[i] ){
 					//ルックアップデータのサイズを追加
 					LookupSize+=sizeof(_int64);
 				}
 
-				pdi=pdi->pNextData;
+				pDllProc=pDllProc->pNextData;
 			}
 		}
@@ -691,15 +688,14 @@
 	for(i=0,i5=0;i<ImportDllNum;i++){
 		for(i2=0;i2<MAX_HASH;i2++){
-			pdi=ppDeclareHash[i2];
-			while(pdi){
-				if(pdi->dwType==DECLARE_STATIC||
-					pdi->bUse==0){
-					pdi=pdi->pNextData;
+			pDllProc=ppDeclareHash[i2];
+			while(pDllProc){
+				if( !pDllProc->IsUsing() ){
+					pDllProc=pDllProc->pNextData;
 					continue;
 				}
 
-				if(lstrcmp(ppDllNames[i],pdi->file)==0){
+				if( pDllProc->GetDllFileName() == ppDllNames[i] ){
 					//ルックアップの位置をセット（後にインポート アドレス テーブルにセットしなおされる）
-					pdi->LookupAddress=i5*sizeof(_int64);
+					pDllProc->SetLookupAddress( i5*sizeof(_int64) );
 
 					//ルックアップ テーブルの値をセット
@@ -714,6 +710,6 @@
 					pHintTable[HintSize++]=0;
 					pHintTable[HintSize++]=0;
-					lstrcpy(pHintTable+HintSize,pdi->alias);
-					i4=lstrlen(pdi->alias);
+					lstrcpy(pHintTable+HintSize,pDllProc->GetAlias().c_str());
+					i4=(int)pDllProc->GetAlias().size();
 					HintSize+=i4+1;
 					if(i4%2==0) pHintTable[HintSize++]=0;
@@ -725,5 +721,5 @@
 				}
 
-				pdi=pdi->pNextData;
+				pDllProc=pDllProc->pNextData;
 			}
 		}
@@ -742,10 +738,8 @@
 	//グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う
 	//（デバッグ情報で利用される）
-	extern int MaxGlobalVarNum;
-	extern VARIABLE *GlobalVar;
 	extern int AllInitGlobalVarSize;
-	for(i=0;i<MaxGlobalVarNum;i++){
-		if(GlobalVar[i].offset&0x80000000){
-			GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize;
+	foreach( Variable *pVar, globalVars ){
+		if(pVar->offset&0x80000000){
+			pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize;
 		}
 	}
@@ -997,17 +991,17 @@
 
 		for(i2=0;i2<MAX_HASH;i2++){
-			pdi=ppDeclareHash[i2];
-			while(pdi){
-				if(pdi->bUse==0){
-					pdi=pdi->pNextData;
+			const DllProc *pDllProc=ppDeclareHash[i2];
+			while(pDllProc){
+				if( !pDllProc->IsUsing() ){
+					pDllProc=pDllProc->pNextData;
 					continue;
 				}
 
-				if(lstrcmp(ppDllNames[i],pdi->file)==0){
+				if( pDllProc->GetDllFileName() == ppDllNames[i] ){
 					//ルックアップ テーブル
 					pLookupTable[i5++]+=MemPos_ImportSection;
 				}
 
-				pdi=pdi->pNextData;
+				pDllProc=pDllProc->pNextData;
 			}
 		}
@@ -1033,9 +1027,9 @@
 	// ※x86はRVAからのオフセット。x64はRPI（実行中アドレス）からのオフセット
 	for(i=0;i<pobj_ImportAddrSchedule->num;i++){
-		DECLAREINFO *pdi;
-		pdi=pobj_ImportAddrSchedule->ppdi[i];
+		DllProc *pDllProc;
+		pDllProc=pobj_ImportAddrSchedule->ppdi[i];
 		*((long *)(OpBuffer+pobj_ImportAddrSchedule->pObpValues[i]))=
 			MemPos_ImportSection+
-			pdi->LookupAddress
+			pDllProc->GetLookupAddress()
 			-(MemPos_CodeSection+pobj_ImportAddrSchedule->pObpValues[i]+sizeof(long));
 	}
@@ -1046,6 +1040,6 @@
 	// プロシージャポインタスケジュール
 	for(i=0;i<pobj_SubAddrSchedule->num;i++){
-		if(pobj_SubAddrSchedule->ppsi[i]->CompileAddress==0
-			&&pobj_SubAddrSchedule->ppsi[i]->EndOpAddr==0){
+		if(pobj_SubAddrSchedule->ppsi[i]->beginOpAddress==0
+			&&pobj_SubAddrSchedule->ppsi[i]->endOpAddress==0){
 			SetError(300,NULL,-1);
 		}
@@ -1053,9 +1047,9 @@
 		if(pobj_SubAddrSchedule->pbCall[i]){
 			*((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))=
-				pobj_SubAddrSchedule->ppsi[i]->CompileAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));
+				pobj_SubAddrSchedule->ppsi[i]->beginOpAddress-(pobj_SubAddrSchedule->pObpValues[i]+sizeof(long));
 		}
 		else{
 			*((long *)(OpBuffer+pobj_SubAddrSchedule->pObpValues[i]))=
-				pobj_SubAddrSchedule->ppsi[i]->CompileAddress+ImageBase+MemPos_CodeSection;
+				pobj_SubAddrSchedule->ppsi[i]->beginOpAddress+ImageBase+MemPos_CodeSection;
 		}
 	}
@@ -1098,9 +1092,7 @@
 	//グローバル変数情報を扱う構造体も初期バッファの有無による配置を行う
 	//（デバッグ情報で利用される）
-	extern int MaxGlobalVarNum;
-	extern VARIABLE *GlobalVar;
-	for(i=0;i<MaxGlobalVarNum;i++){
-		if(GlobalVar[i].offset&0x80000000){
-			GlobalVar[i].offset=(GlobalVar[i].offset&0x7FFFFFFF)+AllInitGlobalVarSize;
+	foreach( Variable *pVar, globalVars ){
+		if(pVar->offset&0x80000000){
+			pVar->offset=(pVar->offset&0x7FFFFFFF)+AllInitGlobalVarSize;
 		}
 	}
