#include #include "common.h" #include OPCODE_H_PATH //opcode.h //シングルトンオブジェクト CDBConst CDBConst::obj; bool ConstBase::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const { if( GetName() != name ){ return false; } return compiler.IsSameAreaNamespace( this->namespaceScopes, namespaceScopes ); } bool ConstBase::IsEqualSymbol( const string &fullName ) const { char AreaName[VN_SIZE] = ""; //オブジェクト変数 char NestName[VN_SIZE] = ""; //入れ子メンバ bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName ); return IsEqualSymbol( NamespaceScopes( AreaName ), NestName ); } CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, const Type &newType, _int64 i64data) : ConstBase( namespaceScopes, name ) , type( newType ) , i64data( i64data ) , pNext( NULL ) { } CConst::CConst( const NamespaceScopes &namespaceScopes, const string &name, int value) : ConstBase( namespaceScopes, name ) , type( Type(DEF_LONG) ) , i64data( value ) , pNext( NULL ) { } CConst::~CConst(){ //連結先のオブジェクトを破棄 if(pNext){ delete pNext; pNext = 0; } } Type CConst::GetType(){ return type; } _int64 CConst::GetWholeData(){ return i64data; } double CConst::GetDoubleData(){ double dbl; memcpy(&dbl,&i64data,sizeof(_int64)); return dbl; } CConstMacro::CConstMacro( const NamespaceScopes &namespaceScopes, const string &name, char *Expression) : ConstBase( namespaceScopes, 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( const NamespaceScopes &namespaceScopes, const string &name , char *Expression){ _int64 i64data; Type resultType; if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){ //変数の場合 //何もしない(実行領域コンパイル時にdim宣言として扱う) return; } //リテラル値の場合 //登録を行う CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data); AddConst( name, newconst); } void CDBConst::AddConst(const NamespaceScopes &namespaceScopes, const string &name, int value){ CConst *newconst = new CConst( namespaceScopes, name, value); AddConst(name, newconst); } CConst *CDBConst::GetObjectPtr( const string &name ){ char ObjName[VN_SIZE]; //オブジェクト変数 char NestMember[VN_SIZE]; //入れ子メンバ bool isObjectMember = CClass::SplitName( name.c_str(), ObjName, NestMember ); //ハッシュ値を取得 int key; key=hash_default( NestMember ); //格納位置を取得 CConst *pConst; pConst=ppHash[key]; while(pConst){ if( pConst->IsEqualSymbol( name ) ) break; pConst=pConst->pNext; } return pConst; } int CDBConst::GetBasicType(char *Name){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return 0; return pConst->GetType().GetBasicType(); } _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(); } bool CDBConst::IsStringPtr( char *Name ){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return false; const Type &type = pConst->GetType(); return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ); }