#include "stdafx.h" #include using namespace ActiveBasic::Compiler; double CConst::GetDoubleData(){ double dbl; memcpy(&dbl,&i64data,sizeof(_int64)); return dbl; } void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name , const char *Expression) { _int64 i64data; Type resultType; if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){ //変数の場合 //何もしない(実行領域コンパイル時にdim宣言として扱う) return; } //リテラル値の場合 //登録を行う CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data); //ハッシュリストに追加 Put( newconst ); } void Consts::Add(const NamespaceScopes &namespaceScopes, const std::string &name, int value){ CConst *newconst = new CConst( namespaceScopes, name, value); //ハッシュリストに追加 Put( newconst ); } CConst *Consts::GetObjectPtr( const std::string &name ){ char ObjName[VN_SIZE]; //オブジェクト変数 char NestMember[VN_SIZE]; //入れ子メンバ bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember ); CConst *pConst = GetHashArrayElement( NestMember ); while( pConst ) { if( pConst->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) ) { break; } pConst = pConst->GetChainNext(); } return pConst; } int Consts::GetBasicType(const char *Name){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return 0; return pConst->GetType().GetBasicType(); } _int64 Consts::GetWholeData(const char *Name){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return 0; return pConst->GetWholeData(); } double Consts::GetDoubleData(const char *Name){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return 0; return pConst->GetDoubleData(); } bool Consts::IsStringPtr( const char *Name ){ CConst *pConst = GetObjectPtr(Name); if(!pConst) return false; const Type &type = pConst->GetType(); return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING ); } // マクロ定数を追加するための関数 void ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr ) { std::vector parameters; int i = 0; if(parameterStr[i]!='(') { compiler.errorMessenger.OutputFatalError(); return; } char temporary[VN_SIZE]; int i2; for(i++,i2=0;;i++,i2++){ if(parameterStr[i]=='\0'){ compiler.errorMessenger.Output(1,NULL,cp); return; } if(parameterStr[i]==','||parameterStr[i]==')'){ temporary[i2]=0; parameters.push_back( temporary ); if(parameterStr[i]==')'){ i++; if(parameterStr[i]!='='){ extern int cp; compiler.errorMessenger.Output(1,NULL,cp); return; } break; } i2=-1; continue; } temporary[i2]=parameterStr[i]; } //データ lstrcpy(temporary,parameterStr+i+1); Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) ); } ConstMacro *ConstMacros::Find( const std::string &name ){ char ObjName[VN_SIZE]; //オブジェクト変数 char NestMember[VN_SIZE]; //入れ子メンバ bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember ); ConstMacro *pConstMacro = GetHashArrayElement( NestMember ); while( pConstMacro ) { if( pConstMacro->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) ) { break; } pConstMacro = pConstMacro->GetChainNext(); } return pConstMacro; }