#include "common.h" #include OPCODE_H_PATH //opcode.h //シングルトンオブジェクト CDBConst CDBConst::obj; CConstBase::CConstBase(char *Name){ this->Name = (char *)malloc(lstrlen(Name)+1); lstrcpy(this->Name, Name); } CConstBase::~CConstBase(){ free(Name); Name=0; } char *CConstBase::GetName(){ return Name; } CConst::CConst(char *Name, int Type, _int64 i64data):CConstBase(Name) { 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) { } CConstMacro::~CConstMacro(){ } CDBConst::CDBConst(){ 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; ipNext){ pConst = pConst->pNext; } pConst->pNext = newconst; } else{ ppHash[key] = newconst; } } void CDBConst::AddConst(char *Name, char *Expression){ _int64 i64data; Type resultType; if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){ //変数の場合 //何もしない(実行領域コンパイル時にdim宣言として扱う) return; } //リテラル値の場合 //登録を行う CConst *newconst = new CConst(Name, resultType.GetBasicType(), i64data); AddConst(Name, newconst); } 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(); }