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