#include "stdafx.h" #include using namespace ActiveBasic::Compiler; double CConst::GetDoubleData(){ double dbl; memcpy(&dbl,&i64data,sizeof(_int64)); return dbl; } void AddConst( const NamespaceScopes &namespaceScopes, char *buffer ){ int i; //名前を取得 char name[VN_SIZE]; for(i=0;;i++){ if(buffer[i]=='\0'){ compiler.errorMessenger.Output(10,"Const",cp); return; } if(buffer[i]=='='||buffer[i]=='('){ name[i]=0; break; } name[i]=buffer[i]; } //重複チェック if( compiler.GetObjectModule().meta.GetGlobalConstMacros().IsExist( name ) || compiler.GetObjectModule().meta.GetGlobalConsts().IsExist( name ) ) { compiler.errorMessenger.Output(15,name,cp); return; } if(buffer[i] == '('){ //定数マクロ compiler.GetObjectModule().meta.GetGlobalConstMacros().Add( namespaceScopes, name, buffer + i ); } else{ //一般の定数 char *expression = buffer + i + 1; compiler.GetObjectModule().meta.GetGlobalConsts().Add( namespaceScopes, name, expression ); } } void Consts::Add( 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); //ハッシュリストに追加 Put( newconst ); } void Consts::Add(const NamespaceScopes &namespaceScopes, const string &name, int value){ CConst *newconst = new CConst( namespaceScopes, name, value); //ハッシュリストに追加 Put( newconst ); } CConst *Consts::GetObjectPtr( const 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 ); } bool ConstMacro::GetCalcBuffer( const char *parameterStr, char *dest ) const { extern HANDLE hHeap; int i2,i3,i4,num; char temporary[VN_SIZE]; char *pParms[MAX_PARMS]; num=0; i2=0; while(1){ i2=GetOneParameter(parameterStr,i2,temporary); pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); lstrcpy(pParms[num],temporary); num++; if(parameterStr[i2]=='\0') break; } if( num != this->GetParameters().size() ){ extern int cp; for(i2=0;i2GetExpression()[i2] )){ temporary[i3]=0; break; } temporary[i3] = this->GetExpression()[i2]; } //パラメータと照合する for( i3=0; i3<(int)this->GetParameters().size(); i3++ ){ if( this->GetParameters()[i3] == temporary ) break; } if( i3 == (int)this->GetParameters().size() ){ //パラメータでないとき lstrcpy(dest+i4,temporary); i4+=lstrlen(temporary); } else{ //パラメータのとき lstrcpy(dest+i4,pParms[i3]); i4+=lstrlen(pParms[i3]); } //演算子をコピー for(;;i2++,i4++){ if( this->GetExpression()[i2] == 1 ){ dest[i4++] = this->GetExpression()[i2++]; dest[i4] = this->GetExpression()[i2]; continue; } if(IsVariableTopChar( this->GetExpression()[i2] )) break; dest[i4] = this->GetExpression()[i2]; if( this->GetExpression()[i2] == '\0' ) break; } if( this->GetExpression()[i2] == '\0' ) break; } for(i2=0;i2 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; }