[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[7] | 3 | double CConst::GetDoubleData(){
|
---|
| 4 | double dbl;
|
---|
| 5 | memcpy(&dbl,&i64data,sizeof(_int64));
|
---|
| 6 | return dbl;
|
---|
| 7 | }
|
---|
| 8 |
|
---|
[543] | 9 | void Consts::Add( const NamespaceScopes &namespaceScopes, const std::string &name , const char *Expression)
|
---|
[206] | 10 | {
|
---|
[7] | 11 | _int64 i64data;
|
---|
[75] | 12 | Type resultType;
|
---|
| 13 | if( !StaticCalculation(false, Expression, 0, &i64data, resultType) ){
|
---|
| 14 | //変数の場合
|
---|
| 15 | //何もしない(実行領域コンパイル時にdim宣言として扱う)
|
---|
| 16 | return;
|
---|
| 17 | }
|
---|
[4] | 18 |
|
---|
[75] | 19 | //リテラル値の場合
|
---|
| 20 | //登録を行う
|
---|
[7] | 21 |
|
---|
[103] | 22 | CConst *newconst = new CConst(namespaceScopes, name, resultType, i64data);
|
---|
[7] | 23 |
|
---|
[206] | 24 | //ハッシュリストに追加
|
---|
| 25 | Put( newconst );
|
---|
[4] | 26 | }
|
---|
[523] | 27 | void Consts::Add(const NamespaceScopes &namespaceScopes, const std::string &name, int value){
|
---|
[103] | 28 | CConst *newconst = new CConst( namespaceScopes, name, value);
|
---|
[7] | 29 |
|
---|
[206] | 30 | //ハッシュリストに追加
|
---|
| 31 | Put( newconst );
|
---|
[7] | 32 | }
|
---|
| 33 |
|
---|
[579] | 34 | CConst *Consts::GetObjectPtr( const Symbol &symbol )
|
---|
| 35 | {
|
---|
| 36 | CConst *pConst = GetHashArrayElement( symbol.GetName().c_str() );
|
---|
[206] | 37 | while( pConst )
|
---|
| 38 | {
|
---|
[579] | 39 | if( pConst->IsEqualSymbol( symbol ) )
|
---|
[206] | 40 | {
|
---|
| 41 | break;
|
---|
| 42 | }
|
---|
| 43 | pConst = pConst->GetChainNext();
|
---|
[7] | 44 | }
|
---|
| 45 |
|
---|
| 46 | return pConst;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
[579] | 50 | int Consts::GetBasicType( const Symbol &symbol ){
|
---|
| 51 | CConst *pConst = GetObjectPtr( symbol );
|
---|
[7] | 52 |
|
---|
| 53 | if(!pConst) return 0;
|
---|
| 54 |
|
---|
[103] | 55 | return pConst->GetType().GetBasicType();
|
---|
[7] | 56 | }
|
---|
[579] | 57 | _int64 Consts::GetWholeData( const Symbol &symbol ){
|
---|
| 58 | CConst *pConst = GetObjectPtr( symbol );
|
---|
[7] | 59 |
|
---|
| 60 | if(!pConst) return 0;
|
---|
| 61 |
|
---|
| 62 | return pConst->GetWholeData();
|
---|
| 63 | }
|
---|
[579] | 64 | double Consts::GetDoubleData( const Symbol &symbol ){
|
---|
| 65 | CConst *pConst = GetObjectPtr( symbol );
|
---|
[7] | 66 |
|
---|
| 67 | if(!pConst) return 0;
|
---|
| 68 |
|
---|
| 69 | return pConst->GetDoubleData();
|
---|
| 70 | }
|
---|
[579] | 71 | bool Consts::IsStringPtr( const Symbol &symbol ){
|
---|
| 72 | CConst *pConst = GetObjectPtr( symbol );
|
---|
[103] | 73 |
|
---|
| 74 | if(!pConst) return false;
|
---|
| 75 |
|
---|
| 76 | const Type &type = pConst->GetType();
|
---|
| 77 |
|
---|
| 78 | return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
|
---|
| 79 | }
|
---|
[206] | 80 |
|
---|
| 81 | // マクロ定数を追加するための関数
|
---|
[579] | 82 | bool ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
|
---|
[206] | 83 | {
|
---|
| 84 | std::vector<std::string> parameters;
|
---|
| 85 |
|
---|
| 86 | int i = 0;
|
---|
| 87 | if(parameterStr[i]!='(')
|
---|
| 88 | {
|
---|
[579] | 89 | return false;
|
---|
[206] | 90 | }
|
---|
| 91 |
|
---|
| 92 | char temporary[VN_SIZE];
|
---|
| 93 | int i2;
|
---|
| 94 | for(i++,i2=0;;i++,i2++){
|
---|
[579] | 95 | if(parameterStr[i]=='\0')
|
---|
| 96 | {
|
---|
| 97 | return false;
|
---|
[206] | 98 | }
|
---|
| 99 | if(parameterStr[i]==','||parameterStr[i]==')'){
|
---|
| 100 | temporary[i2]=0;
|
---|
| 101 |
|
---|
| 102 | parameters.push_back( temporary );
|
---|
| 103 |
|
---|
| 104 | if(parameterStr[i]==')'){
|
---|
| 105 | i++;
|
---|
[579] | 106 | if(parameterStr[i]!='=')
|
---|
| 107 | {
|
---|
| 108 | return false;
|
---|
[206] | 109 | }
|
---|
| 110 | break;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | i2=-1;
|
---|
| 114 | continue;
|
---|
| 115 | }
|
---|
| 116 | temporary[i2]=parameterStr[i];
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | //データ
|
---|
| 120 | lstrcpy(temporary,parameterStr+i+1);
|
---|
| 121 |
|
---|
[579] | 122 | this->Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
|
---|
| 123 |
|
---|
| 124 | return true;
|
---|
[206] | 125 | }
|
---|
[579] | 126 | ConstMacro *ConstMacros::Find( const Symbol &symbol )
|
---|
| 127 | {
|
---|
| 128 | ConstMacro *pConstMacro = GetHashArrayElement( symbol.GetName().c_str() );
|
---|
[206] | 129 | while( pConstMacro )
|
---|
| 130 | {
|
---|
[579] | 131 | if( pConstMacro->IsEqualSymbol( symbol ) )
|
---|
[206] | 132 | {
|
---|
| 133 | break;
|
---|
| 134 | }
|
---|
| 135 | pConstMacro = pConstMacro->GetChainNext();
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | return pConstMacro;
|
---|
| 139 | }
|
---|