Index: BasicCompiler_Common/Const.cpp
===================================================================
--- BasicCompiler_Common/Const.cpp	(revision 5)
+++ BasicCompiler_Common/Const.cpp	(revision 7)
@@ -1,4 +1,8 @@
 #include "common.h"
-
+#include OPCODE_H_PATH	//opcode.h
+
+
+//シングルトンオブジェクト
+CDBConst CDBConst::obj;
 
 
@@ -12,13 +16,47 @@
 }
 
-
-
-CConst::CConst(char *Name, char *Expression):CConstBase(Name)
+char *CConstBase::GetName(){
+	return Name;
+}
+
+
+
+CConst::CConst(char *Name, int Type, _int64 i64data):CConstBase(Name)
 {
-	LONG_PTR lpIndex;
-	Type = StaticCalculation(false, Expression, 0, &i64data, &lpIndex);
+	this->Type = Type;
+	this->i64data = i64data;
+
+	//連結リストを初期化
+	pNext = 0;
+}
+CConst::CConst(char *Name, int value):CConstBase(Name)
+{
+	Type = DEF_LONG;
+	i64data = value;
+
+	//連結リストを初期化
+	pNext = 0;
 }
 CConst::~CConst(){
-}
+	//連結先のオブジェクトを破棄
+	if(pNext){
+		delete pNext;
+		pNext = 0;
+	}
+}
+
+int CConst::GetType(){
+	return Type;
+}
+_int64 CConst::GetWholeData(){
+	return i64data;
+}
+double CConst::GetDoubleData(){
+	double dbl;
+	memcpy(&dbl,&i64data,sizeof(_int64));
+	return dbl;
+}
+
+
 
 CConstMacro::CConstMacro(char *Name, char *Expression):CConstBase(Name)
@@ -30,28 +68,35 @@
 
 
+
+
 CDBConst::CDBConst(){
-	//定数管理領域を初期化
-	ppobj_Const = (CConst **)malloc(1);
-	NumOfConst = 0;
-
-	//定数マクロ管理領域を初期化
-	ppobj_Macro = (CConstMacro **)malloc(1);
-	NumOfMacro = 0;
+	memset(this,0,sizeof(CDBConst));
+
+	ppHash = (CConst **)calloc(MAX_HASH*sizeof(CConst *),1);
+	Init();
 }
 CDBConst::~CDBConst(){
+	Free();
+
+	free(ppHash);
+}
+
+//解放
+void CDBConst::Free(){
 	int i;
-	for(i=0; i<NumOfConst; i++){
-		delete ppobj_Const[i];
-	}
-	free(ppobj_Const);
-	ppobj_Const = 0;
-
-	for(i=0; i<NumOfMacro; i++){
-		delete ppobj_Macro[i];
-	}
-	free(ppobj_Macro);
-	ppobj_Macro = 0;
-}
-
+	for(i=0; i<MAX_HASH; i++){
+		if(ppHash[i]){
+			delete ppHash[i];
+			ppHash[i] = 0;
+		}
+	}
+}
+
+//初期化
+void CDBConst::Init(){
+	Free();
+}
+
+void AddConstData(char *Command);
 void CDBConst::Add(char *buffer){
 	int i;
@@ -71,8 +116,15 @@
 	}
 
+	//重複チェック
+	if(GetType(Name)){
+		SetError(15,Name,cp);
+		return;
+	}
+
 	if(buffer[i] == '('){
 		//定数マクロ
 
 		//未完成
+		AddConstData(buffer);
 	}
 	else{
@@ -84,10 +136,81 @@
 }
 
+void CDBConst::AddConst(char *Name, CConst *newconst){
+	int key = hash_default(Name);
+
+	//ハッシュリストに追加
+	if(ppHash[key]){
+		CConst *pConst = ppHash[key];
+		while(pConst->pNext){
+			pConst = pConst->pNext;
+		}
+
+		pConst->pNext = newconst;
+	}
+	else{
+		ppHash[key] = newconst;
+	}
+}
 void CDBConst::AddConst(char *Name, char *Expression){
-	CConst *newconst = new CConst(Name, Expression);
-
-	//管理クラスへ追加
-	ppobj_Const = (CConst **)realloc( ppobj_Const, (NumOfConst + 1) * sizeof(CConst) );
-	ppobj_Const[NumOfConst] = newconst;
-	NumOfConst++;
-}
+	LONG_PTR lpIndex;
+	_int64 i64data;
+	int Type = StaticCalculation(false, Expression, 0, &i64data, &lpIndex);
+
+	if(Type){
+		//リテラル値の場合
+		//登録を行う
+
+		CConst *newconst = new CConst(Name, Type, i64data);
+
+		AddConst(Name, newconst);
+	}
+	else{
+		//変数の場合
+		//何もしない（実行領域コンパイル時にdim宣言として扱う）
+	}
+}
+void CDBConst::AddConst(char *Name, int value){
+	CConst *newconst = new CConst(Name, value);
+
+	AddConst(Name, newconst);
+}
+
+CConst *CDBConst::GetObjectPtr(char *Name){
+	//ハッシュ値を取得
+	int key;
+	key=hash_default(Name);
+
+	//格納位置を取得
+	CConst *pConst;
+	pConst=ppHash[key];
+	while(pConst){
+		if(lstrcmp(pConst->GetName(),Name)==0) break;
+
+		pConst=pConst->pNext;
+	}
+
+	return pConst;
+}
+
+
+int CDBConst::GetType(char *Name){
+	CConst *pConst = GetObjectPtr(Name);
+
+	if(!pConst) return 0;
+
+	return pConst->GetType();
+}
+_int64 CDBConst::GetWholeData(char *Name){
+	CConst *pConst = GetObjectPtr(Name);
+
+	if(!pConst) return 0;
+
+	return pConst->GetWholeData();
+}
+double CDBConst::GetDoubleData(char *Name){
+	CConst *pConst = GetObjectPtr(Name);
+
+	if(!pConst) return 0;
+
+	return pConst->GetDoubleData();
+}
