[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 |
|
---|
[523] | 38 | CConst *Consts::GetObjectPtr( const std::string &name ){
|
---|
[103] | 39 | char ObjName[VN_SIZE]; //オブジェクト変数
|
---|
| 40 | char NestMember[VN_SIZE]; //入れ子メンバ
|
---|
[206] | 41 | bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember );
|
---|
[103] | 42 |
|
---|
[206] | 43 | CConst *pConst = GetHashArrayElement( NestMember );
|
---|
| 44 | while( pConst )
|
---|
| 45 | {
|
---|
[509] | 46 | if( pConst->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) )
|
---|
[206] | 47 | {
|
---|
| 48 | break;
|
---|
| 49 | }
|
---|
| 50 | pConst = pConst->GetChainNext();
|
---|
[7] | 51 | }
|
---|
| 52 |
|
---|
| 53 | return pConst;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
[254] | 57 | int Consts::GetBasicType(const char *Name){
|
---|
[7] | 58 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 59 |
|
---|
| 60 | if(!pConst) return 0;
|
---|
| 61 |
|
---|
[103] | 62 | return pConst->GetType().GetBasicType();
|
---|
[7] | 63 | }
|
---|
[254] | 64 | _int64 Consts::GetWholeData(const char *Name){
|
---|
[7] | 65 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 66 |
|
---|
| 67 | if(!pConst) return 0;
|
---|
| 68 |
|
---|
| 69 | return pConst->GetWholeData();
|
---|
| 70 | }
|
---|
[254] | 71 | double Consts::GetDoubleData(const char *Name){
|
---|
[7] | 72 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 73 |
|
---|
| 74 | if(!pConst) return 0;
|
---|
| 75 |
|
---|
| 76 | return pConst->GetDoubleData();
|
---|
| 77 | }
|
---|
[254] | 78 | bool Consts::IsStringPtr( const char *Name ){
|
---|
[103] | 79 | CConst *pConst = GetObjectPtr(Name);
|
---|
| 80 |
|
---|
| 81 | if(!pConst) return false;
|
---|
| 82 |
|
---|
| 83 | const Type &type = pConst->GetType();
|
---|
| 84 |
|
---|
| 85 | return ( type.GetBasicType() == typeOfPtrChar && type.GetIndex() == LITERAL_STRING );
|
---|
| 86 | }
|
---|
[206] | 87 |
|
---|
| 88 |
|
---|
| 89 | bool ConstMacro::GetCalcBuffer( const char *parameterStr, char *dest ) const
|
---|
| 90 | {
|
---|
| 91 | extern HANDLE hHeap;
|
---|
| 92 | int i2,i3,i4,num;
|
---|
| 93 | char temporary[VN_SIZE];
|
---|
| 94 | char *pParms[MAX_PARMS];
|
---|
| 95 | num=0;
|
---|
| 96 | i2=0;
|
---|
| 97 | while(1){
|
---|
| 98 | i2=GetOneParameter(parameterStr,i2,temporary);
|
---|
| 99 |
|
---|
| 100 | pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
| 101 | lstrcpy(pParms[num],temporary);
|
---|
| 102 |
|
---|
| 103 | num++;
|
---|
| 104 | if(parameterStr[i2]=='\0') break;
|
---|
| 105 | }
|
---|
| 106 | if( num != this->GetParameters().size() ){
|
---|
| 107 | extern int cp;
|
---|
| 108 | for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
|
---|
[465] | 109 | compiler.errorMessenger.Output(10,GetName().c_str(),cp);
|
---|
[206] | 110 | lstrcpy(dest,"0");
|
---|
| 111 | return 1;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | i2=0;
|
---|
| 115 | i4=0;
|
---|
| 116 | while(1){
|
---|
| 117 |
|
---|
| 118 | //数式内の項を取得
|
---|
| 119 | for(i3=0;;i2++,i3++){
|
---|
| 120 | if(!IsVariableChar( this->GetExpression()[i2] )){
|
---|
| 121 | temporary[i3]=0;
|
---|
| 122 | break;
|
---|
| 123 | }
|
---|
| 124 | temporary[i3] = this->GetExpression()[i2];
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | //パラメータと照合する
|
---|
| 128 | for( i3=0; i3<(int)this->GetParameters().size(); i3++ ){
|
---|
| 129 | if( this->GetParameters()[i3] == temporary ) break;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | if( i3 == (int)this->GetParameters().size() ){
|
---|
| 133 | //パラメータでないとき
|
---|
| 134 | lstrcpy(dest+i4,temporary);
|
---|
| 135 | i4+=lstrlen(temporary);
|
---|
| 136 | }
|
---|
| 137 | else{
|
---|
| 138 | //パラメータのとき
|
---|
| 139 | lstrcpy(dest+i4,pParms[i3]);
|
---|
| 140 | i4+=lstrlen(pParms[i3]);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | //演算子をコピー
|
---|
| 144 | for(;;i2++,i4++){
|
---|
| 145 | if( this->GetExpression()[i2] == 1 ){
|
---|
| 146 | dest[i4++] = this->GetExpression()[i2++];
|
---|
| 147 | dest[i4] = this->GetExpression()[i2];
|
---|
| 148 | continue;
|
---|
| 149 | }
|
---|
| 150 | if(IsVariableTopChar( this->GetExpression()[i2] )) break;
|
---|
| 151 | dest[i4] = this->GetExpression()[i2];
|
---|
| 152 | if( this->GetExpression()[i2] == '\0' ) break;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | if( this->GetExpression()[i2] == '\0' ) break;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
|
---|
| 159 |
|
---|
| 160 | return 1;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | // マクロ定数を追加するための関数
|
---|
| 164 | void ConstMacros::Add( const NamespaceScopes &namespaceScopes, const std::string &name, const char *parameterStr )
|
---|
| 165 | {
|
---|
| 166 | std::vector<std::string> parameters;
|
---|
| 167 |
|
---|
| 168 | int i = 0;
|
---|
| 169 | if(parameterStr[i]!='(')
|
---|
| 170 | {
|
---|
[465] | 171 | compiler.errorMessenger.OutputFatalError();
|
---|
[206] | 172 | return;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | char temporary[VN_SIZE];
|
---|
| 176 | int i2;
|
---|
| 177 | for(i++,i2=0;;i++,i2++){
|
---|
| 178 | if(parameterStr[i]=='\0'){
|
---|
[465] | 179 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
[206] | 180 | return;
|
---|
| 181 | }
|
---|
| 182 | if(parameterStr[i]==','||parameterStr[i]==')'){
|
---|
| 183 | temporary[i2]=0;
|
---|
| 184 |
|
---|
| 185 | parameters.push_back( temporary );
|
---|
| 186 |
|
---|
| 187 | if(parameterStr[i]==')'){
|
---|
| 188 | i++;
|
---|
| 189 | if(parameterStr[i]!='='){
|
---|
| 190 | extern int cp;
|
---|
[465] | 191 | compiler.errorMessenger.Output(1,NULL,cp);
|
---|
[206] | 192 | return;
|
---|
| 193 | }
|
---|
| 194 | break;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | i2=-1;
|
---|
| 198 | continue;
|
---|
| 199 | }
|
---|
| 200 | temporary[i2]=parameterStr[i];
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | //データ
|
---|
| 204 | lstrcpy(temporary,parameterStr+i+1);
|
---|
| 205 |
|
---|
| 206 | Put( new ConstMacro( namespaceScopes, name, parameters, temporary ) );
|
---|
| 207 | }
|
---|
| 208 | ConstMacro *ConstMacros::Find( const std::string &name ){
|
---|
| 209 | char ObjName[VN_SIZE]; //オブジェクト変数
|
---|
| 210 | char NestMember[VN_SIZE]; //入れ子メンバ
|
---|
| 211 | bool isObjectMember = SplitMemberName( name.c_str(), ObjName, NestMember );
|
---|
| 212 |
|
---|
| 213 | ConstMacro *pConstMacro = GetHashArrayElement( NestMember );
|
---|
| 214 | while( pConstMacro )
|
---|
| 215 | {
|
---|
[509] | 216 | if( pConstMacro->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( name ) ) )
|
---|
[206] | 217 | {
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
| 220 | pConstMacro = pConstMacro->GetChainNext();
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | return pConstMacro;
|
---|
| 224 | }
|
---|