[4] | 1 | #include "../BasicCompiler_Common/common.h"
|
---|
| 2 |
|
---|
| 3 | #ifdef _AMD64_
|
---|
| 4 | #include "../BasicCompiler64/opcode.h"
|
---|
| 5 | #else
|
---|
[5] | 6 | #include "../BasicCompiler32/opcode.h"
|
---|
[4] | 7 | #endif
|
---|
| 8 |
|
---|
| 9 | double dbl_stack[255];
|
---|
| 10 | _int64 i64stack[255];
|
---|
| 11 |
|
---|
[14] | 12 | bool IsNumberTopChar(char *buffer){
|
---|
| 13 | int c = buffer[0];
|
---|
| 14 | if('0' <= c && c <= '9') return true;
|
---|
| 15 | if(buffer[0] == '&' && (buffer[1] == 'h' || buffer[1] == 'H' || buffer[1] == 'o' || buffer[1] == 'O')) return true;
|
---|
| 16 |
|
---|
| 17 | return false;
|
---|
| 18 | }
|
---|
| 19 | bool IsNumberChar(char c){
|
---|
| 20 | if('0' <= c && c <= '9') return true;
|
---|
| 21 | if('a' <= c && c <= 'f') return true;
|
---|
| 22 | if('A' <= c && c <= 'F') return true;
|
---|
| 23 |
|
---|
| 24 | return false;
|
---|
| 25 | }
|
---|
[4] | 26 | BOOL IsJudgMark(char *Command,int p){
|
---|
| 27 | if(Command[p]==1){
|
---|
| 28 | if(Command[p+1]==ESC_AND) return 1;
|
---|
| 29 | if(Command[p+1]==ESC_OR) return 1;
|
---|
| 30 | if(Command[p+1]==ESC_XOR) return 1;
|
---|
| 31 | if(Command[p+1]==ESC_NOT) return 1;
|
---|
| 32 | }
|
---|
| 33 | return 0;
|
---|
| 34 | }
|
---|
| 35 | BOOL IsNumCalcMark(char *Command,int p){
|
---|
| 36 | if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'||
|
---|
| 37 | (Command[p]==1&&Command[p+1]==ESC_MOD)||Command[p]=='+'||Command[p]=='-'||
|
---|
| 38 | Command[p]=='='||Command[p]=='<'||Command[p]=='>'||
|
---|
| 39 | IsJudgMark(Command,p)||
|
---|
| 40 | (Command[p]==1&&Command[p+1]==ESC_AS)) return 1;
|
---|
| 41 | return 0;
|
---|
| 42 | }
|
---|
| 43 | BOOL IsNumCalcMark_Back(char *Command,int p){
|
---|
| 44 | if(p==0){
|
---|
| 45 | if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'||
|
---|
| 46 | Command[p]=='+'||Command[p]=='-'||
|
---|
| 47 | Command[p]=='='||Command[p]=='<'||Command[p]=='>') return 1;
|
---|
| 48 | }
|
---|
| 49 | else{
|
---|
| 50 | if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'||
|
---|
| 51 | (Command[p-1]==1&&Command[p]==ESC_MOD)||Command[p]=='+'||Command[p]=='-'||
|
---|
| 52 | Command[p]=='='||Command[p]=='<'||Command[p]=='>'||
|
---|
| 53 | IsJudgMark(Command,p-1)||
|
---|
| 54 | (Command[p-1]==1&&Command[p]==ESC_AS)) return 1;
|
---|
| 55 | }
|
---|
| 56 | return 0;
|
---|
| 57 | }
|
---|
| 58 | BOOL IsStrCalcMark(char c){
|
---|
| 59 | if(c=='+'||c=='&') return 1;
|
---|
| 60 | return 0;
|
---|
| 61 | }
|
---|
| 62 | BOOL IsExponent(char *Command,int p){
|
---|
| 63 | int i,sw;
|
---|
| 64 | for(i=p-2,sw=FALSE;i>=0;i--){
|
---|
| 65 | if(Command[i]>='0'&&Command[i]<='9') sw=TRUE;
|
---|
| 66 | if(!((Command[i]>='0'&&Command[i]<='9')||Command[i]=='.')){
|
---|
| 67 | if((IsNumCalcMark(Command,i)||Command[i]=='('||Command[i]==')')&&sw) return TRUE;
|
---|
| 68 | return FALSE;
|
---|
| 69 | }
|
---|
| 70 | if(i==0&&sw) return TRUE;
|
---|
| 71 | }
|
---|
| 72 | return FALSE;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | int CompStr(char *str1,int len1,char *str2,int len2){
|
---|
| 76 | int i,len;
|
---|
| 77 |
|
---|
| 78 | if(len1<len2) len=len1;
|
---|
| 79 | else len=len2;
|
---|
| 80 |
|
---|
| 81 | for(i=0;i<len;i++){
|
---|
| 82 | if((unsigned char *)str1[i]>(unsigned char *)str2[i]) return 1;
|
---|
| 83 | else if((unsigned char *)str1[i]<(unsigned char *)str2[i]) return -1;
|
---|
| 84 | }
|
---|
| 85 | if(len1>len2) return 1;
|
---|
| 86 | else if(len1<len2) return -1;
|
---|
| 87 | return 0;
|
---|
| 88 | }
|
---|
| 89 | void TypeErrorCheck(_int64 *stack,int sp,long calc){
|
---|
| 90 | extern int cp;
|
---|
| 91 | if(sp==0||calc==0) return;
|
---|
| 92 | if(sp==1){
|
---|
| 93 | if(stack[0]){
|
---|
| 94 | SetError(9,NULL,cp);
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
| 97 | return;
|
---|
| 98 | }
|
---|
| 99 | if(CALC_PE<=calc&&calc<=CALC_Q||calc==CALC_ADDITION){
|
---|
| 100 | //文字列演算が可能な演算子
|
---|
| 101 | if((stack[sp-2]&&stack[sp-1]==0)||(stack[sp-2]==0&&stack[sp-1])){
|
---|
| 102 | SetError(9,NULL,cp);
|
---|
| 103 | return;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | else{
|
---|
| 107 | //文字列演算ができない演算子
|
---|
| 108 | if(stack[sp-2]||stack[sp-1]){
|
---|
| 109 | SetError(9,NULL,cp);
|
---|
| 110 | return;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | int GetLiteralIndex(_int64 i64data){
|
---|
| 117 | if(i64data==0) return LITERAL_NULL;
|
---|
| 118 | else if(-128<=i64data&&i64data<0) return LITERAL_M128_0;
|
---|
| 119 | else if(0<i64data&&i64data<256) return LITERAL_0_255;
|
---|
| 120 | else if(-32768<=i64data&&i64data<0) return LITERAL_M32768_0;
|
---|
| 121 | else if(0<i64data&&i64data<65536) return LITERAL_0_65535;
|
---|
| 122 | else if(i64data<0) return LITERAL_OTHER_MINUS;
|
---|
| 123 | return LITERAL_OTHER_PLUS;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | int NeutralizationType(int type1,LONG_PTR index1,int type2,LONG_PTR index2){
|
---|
| 128 |
|
---|
| 129 | if(type1==DEF_DOUBLE||type2==DEF_DOUBLE) return DEF_DOUBLE;
|
---|
| 130 | if(type1==DEF_SINGLE||type2==DEF_SINGLE) return DEF_SINGLE;
|
---|
| 131 |
|
---|
| 132 | int size1,size2;
|
---|
| 133 | size1=GetTypeSize(type1,index1);
|
---|
| 134 | size2=GetTypeSize(type2,index2);
|
---|
| 135 | if(size1<size2){
|
---|
| 136 | size1=size2;
|
---|
| 137 | }
|
---|
| 138 | else if(type1==type2) return type1;
|
---|
| 139 |
|
---|
| 140 | if(IsPtrType(type1)||IsPtrType(type2)){
|
---|
| 141 | if(IsPtrType(type1)) return type1;
|
---|
| 142 | else return type2;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | /////////////////////////////
|
---|
| 147 | // 片方がリテラル値の場合
|
---|
| 148 | // ※柔軟に符号を除去する
|
---|
| 149 | /////////////////////////////
|
---|
| 150 | if(IsSignedType(type1)&&IS_POSITIVE_LITERAL(index1)&&
|
---|
| 151 | IsSignedType(type2)==0){
|
---|
| 152 | type1=GetUnsignedType(type1);
|
---|
| 153 | }
|
---|
| 154 | if(IsSignedType(type1)==0&&
|
---|
| 155 | IsSignedType(type2)&&IS_POSITIVE_LITERAL(index2)){
|
---|
| 156 | type2=GetUnsignedType(type2);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | if(IsSignedType(type1)||IsSignedType(type2)){
|
---|
| 161 | //符号あり
|
---|
| 162 | if(size1==sizeof(char)) return DEF_CHAR;
|
---|
| 163 | if(size1==sizeof(short)) return DEF_INTEGER;
|
---|
| 164 | if(size1==sizeof(long)) return DEF_LONG;
|
---|
| 165 | if(size1==sizeof(_int64)) return DEF_INT64;
|
---|
| 166 | }
|
---|
| 167 | else{
|
---|
| 168 | //符号なし
|
---|
| 169 | if(size1==sizeof(char)) return DEF_BYTE;
|
---|
| 170 | if(size1==sizeof(short)) return DEF_WORD;
|
---|
| 171 | if(size1==sizeof(long)) return DEF_DWORD;
|
---|
| 172 | if(size1==sizeof(_int64)) return DEF_QWORD;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | extern int cp;
|
---|
| 176 | SetError(300,NULL,cp);
|
---|
| 177 | return 0;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | void StaticTwoTerm(int idCalc,int *type_stack,LONG_PTR *index_stack,int *pStackPointer,int BaseType){
|
---|
| 181 | int sp,AnswerType;
|
---|
| 182 |
|
---|
| 183 | sp=*pStackPointer;
|
---|
| 184 |
|
---|
| 185 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
---|
| 186 |
|
---|
| 187 | if(IsRealNumberType(BaseType)&&idCalc==CALC_QUOTIENT) AnswerType=BaseType;
|
---|
| 188 |
|
---|
| 189 | if(IsRealNumberType(AnswerType)){
|
---|
| 190 | ///////////////
|
---|
| 191 | // 実数演算
|
---|
| 192 | ///////////////
|
---|
| 193 |
|
---|
| 194 | if(IsWholeNumberType(type_stack[sp-2])) dbl_stack[sp-2]=(double)i64stack[sp-2];
|
---|
| 195 | if(IsWholeNumberType(type_stack[sp-1])) dbl_stack[sp-1]=(double)i64stack[sp-1];
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | //比較演算
|
---|
| 199 | if(idCalc==CALC_PE){
|
---|
| 200 | if(dbl_stack[sp-2]<=dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 201 | else i64stack[sp-2]=0;
|
---|
| 202 | AnswerType=DEF_LONG;
|
---|
| 203 | }
|
---|
| 204 | else if(idCalc==CALC_QE){
|
---|
| 205 | if(dbl_stack[sp-2]>=dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 206 | else i64stack[sp-2]=0;
|
---|
| 207 | AnswerType=DEF_LONG;
|
---|
| 208 | }
|
---|
| 209 | else if(idCalc==CALC_P){
|
---|
| 210 | if(dbl_stack[sp-2]<dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 211 | else i64stack[sp-2]=0;
|
---|
| 212 | AnswerType=DEF_LONG;
|
---|
| 213 | }
|
---|
| 214 | else if(idCalc==CALC_Q){
|
---|
| 215 | if(dbl_stack[sp-2]>dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 216 | else i64stack[sp-2]=0;
|
---|
| 217 | AnswerType=DEF_LONG;
|
---|
| 218 | }
|
---|
| 219 | else if(idCalc==CALC_NOTEQUAL){
|
---|
| 220 | if(dbl_stack[sp-2]!=dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 221 | else i64stack[sp-2]=0;
|
---|
| 222 | AnswerType=DEF_LONG;
|
---|
| 223 | }
|
---|
| 224 | else if(idCalc==CALC_EQUAL){
|
---|
| 225 | if(dbl_stack[sp-2]==dbl_stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 226 | else i64stack[sp-2]=0;
|
---|
| 227 | AnswerType=DEF_LONG;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | //論理演算
|
---|
| 231 | else if(idCalc==CALC_XOR) dbl_stack[sp-2]=(double)((long)dbl_stack[sp-2]^(long)dbl_stack[sp-1]);
|
---|
| 232 | else if(idCalc==CALC_OR) dbl_stack[sp-2]=(double)((long)dbl_stack[sp-2]|(long)dbl_stack[sp-1]);
|
---|
| 233 | else if(idCalc==CALC_AND) dbl_stack[sp-2]=(double)((long)dbl_stack[sp-2]&(long)dbl_stack[sp-1]);
|
---|
| 234 |
|
---|
| 235 | //シフト演算
|
---|
| 236 | else if(idCalc==CALC_SHL) dbl_stack[sp-2]=(double)((DWORD)dbl_stack[sp-2]<<(DWORD)dbl_stack[sp-1]);
|
---|
| 237 | else if(idCalc==CALC_SHR) dbl_stack[sp-2]=(double)((DWORD)dbl_stack[sp-2]>>(DWORD)dbl_stack[sp-1]);
|
---|
| 238 |
|
---|
| 239 | //算術演算
|
---|
| 240 | else if(idCalc==CALC_ADDITION) dbl_stack[sp-2]+=dbl_stack[sp-1];
|
---|
| 241 | else if(idCalc==CALC_SUBTRACTION) dbl_stack[sp-2]-=dbl_stack[sp-1];
|
---|
| 242 | else if(idCalc==CALC_MOD) dbl_stack[sp-2]=(double)((long)dbl_stack[sp-2]%(long)dbl_stack[sp-1]);
|
---|
| 243 | else if(idCalc==CALC_PRODUCT) dbl_stack[sp-2]*=dbl_stack[sp-1];
|
---|
| 244 | else if(idCalc==CALC_QUOTIENT){
|
---|
| 245 | if(dbl_stack[sp-1])
|
---|
| 246 | dbl_stack[sp-2]/=dbl_stack[sp-1];
|
---|
| 247 | else{
|
---|
| 248 | //ゼロ割りエラーを検地
|
---|
| 249 | SetError(56,NULL,cp);
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 | else if(idCalc==CALC_INTQUOTIENT){
|
---|
| 253 | if(dbl_stack[sp-1])
|
---|
| 254 | dbl_stack[sp-2]=(double)(long)(dbl_stack[sp-2]/dbl_stack[sp-1]);
|
---|
| 255 | else{
|
---|
| 256 | //ゼロ割りエラーを検地
|
---|
| 257 | SetError(56,NULL,cp);
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 | else if(idCalc==CALC_POWER) dbl_stack[sp-2]=pow(dbl_stack[sp-2],dbl_stack[sp-1]);
|
---|
| 261 | }
|
---|
| 262 | else{
|
---|
| 263 | ///////////////
|
---|
| 264 | // 整数演算
|
---|
| 265 | ///////////////
|
---|
| 266 |
|
---|
| 267 | if(IsRealNumberType(type_stack[sp-2])) i64stack[sp-2]=(_int64)dbl_stack[sp-2];
|
---|
| 268 | if(IsRealNumberType(type_stack[sp-1])) i64stack[sp-1]=(_int64)dbl_stack[sp-1];
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | //比較演算
|
---|
| 272 | if(idCalc==CALC_PE){
|
---|
| 273 | if(IsSignedType(AnswerType)){
|
---|
| 274 | if(i64stack[sp-2]<=i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 275 | else i64stack[sp-2]=0;
|
---|
| 276 | }
|
---|
| 277 | else{
|
---|
| 278 | if(((unsigned _int64)i64stack[sp-2])<=((unsigned _int64)i64stack[sp-1])) i64stack[sp-2]=-1;
|
---|
| 279 | else i64stack[sp-2]=0;
|
---|
| 280 | }
|
---|
| 281 | AnswerType=DEF_LONG;
|
---|
| 282 | }
|
---|
| 283 | else if(idCalc==CALC_QE){
|
---|
| 284 | if(IsSignedType(AnswerType)){
|
---|
| 285 | if(i64stack[sp-2]>=i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 286 | else i64stack[sp-2]=0;
|
---|
| 287 | }
|
---|
| 288 | else{
|
---|
| 289 | if(((unsigned _int64)i64stack[sp-2])>=((unsigned _int64)i64stack[sp-1])) i64stack[sp-2]=-1;
|
---|
| 290 | else i64stack[sp-2]=0;
|
---|
| 291 | }
|
---|
| 292 | AnswerType=DEF_LONG;
|
---|
| 293 | }
|
---|
| 294 | else if(idCalc==CALC_P){
|
---|
| 295 | if(IsSignedType(AnswerType)){
|
---|
| 296 | if(i64stack[sp-2]<i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 297 | else i64stack[sp-2]=0;
|
---|
| 298 | }
|
---|
| 299 | else{
|
---|
| 300 | if(((unsigned _int64)i64stack[sp-2])<((unsigned _int64)i64stack[sp-1])) i64stack[sp-2]=-1;
|
---|
| 301 | else i64stack[sp-2]=0;
|
---|
| 302 | }
|
---|
| 303 | AnswerType=DEF_LONG;
|
---|
| 304 | }
|
---|
| 305 | else if(idCalc==CALC_Q){
|
---|
| 306 | if(IsSignedType(AnswerType)){
|
---|
| 307 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
---|
| 308 | if(i64stack[sp-2]>i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 309 | else i64stack[sp-2]=0;
|
---|
| 310 | }
|
---|
| 311 | else{
|
---|
| 312 | if(((unsigned _int64)i64stack[sp-2])>((unsigned _int64)i64stack[sp-1])) i64stack[sp-2]=-1;
|
---|
| 313 | else i64stack[sp-2]=0;
|
---|
| 314 | }
|
---|
| 315 | AnswerType=DEF_LONG;
|
---|
| 316 | }
|
---|
| 317 | else if(idCalc==CALC_NOTEQUAL){
|
---|
| 318 | if(i64stack[sp-2]!=i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 319 | else i64stack[sp-2]=0;
|
---|
| 320 | AnswerType=DEF_LONG;
|
---|
| 321 | }
|
---|
| 322 | else if(idCalc==CALC_EQUAL){
|
---|
| 323 | if(i64stack[sp-2]==i64stack[sp-1]) i64stack[sp-2]=-1;
|
---|
| 324 | else i64stack[sp-2]=0;
|
---|
| 325 | AnswerType=DEF_LONG;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | //論理演算
|
---|
| 329 | else if(idCalc==CALC_XOR) i64stack[sp-2]^=i64stack[sp-1];
|
---|
| 330 | else if(idCalc==CALC_OR) i64stack[sp-2]|=i64stack[sp-1];
|
---|
| 331 | else if(idCalc==CALC_AND) i64stack[sp-2]&=i64stack[sp-1];
|
---|
| 332 |
|
---|
| 333 | //シフト演算
|
---|
| 334 | else if(idCalc==CALC_SHL){
|
---|
| 335 | i64stack[sp-2]<<=(DWORD)i64stack[sp-1];
|
---|
| 336 | if(IsSignedType(AnswerType)) AnswerType=DEF_LONG;
|
---|
| 337 | else AnswerType=DEF_DWORD;
|
---|
| 338 | }
|
---|
| 339 | else if(idCalc==CALC_SHR){
|
---|
| 340 | i64stack[sp-2]>>=(DWORD)i64stack[sp-1];
|
---|
| 341 | if(IsSignedType(AnswerType)) AnswerType=DEF_LONG;
|
---|
| 342 | else AnswerType=DEF_DWORD;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | //算術演算
|
---|
| 346 | else if(idCalc==CALC_ADDITION) i64stack[sp-2]+=i64stack[sp-1];
|
---|
| 347 | else if(idCalc==CALC_SUBTRACTION) i64stack[sp-2]-=i64stack[sp-1];
|
---|
| 348 | else if(idCalc==CALC_MOD) i64stack[sp-2]%=i64stack[sp-1];
|
---|
| 349 | else if(idCalc==CALC_PRODUCT) i64stack[sp-2]*=i64stack[sp-1];
|
---|
| 350 | else if(idCalc==CALC_QUOTIENT||
|
---|
| 351 | idCalc==CALC_INTQUOTIENT){
|
---|
| 352 | if(i64stack[sp-1])
|
---|
| 353 | i64stack[sp-2]/=i64stack[sp-1];
|
---|
| 354 | else{
|
---|
| 355 | //ゼロ割りエラーを検地
|
---|
| 356 | SetError(56,NULL,cp);
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
| 359 | else if(idCalc==CALC_POWER) i64stack[sp-2]=(_int64)pow((double)i64stack[sp-2],(double)i64stack[sp-1]);
|
---|
| 360 |
|
---|
| 361 | if(IsSignedType(AnswerType)){
|
---|
| 362 | if(AnswerType==DEF_CHAR&&(i64stack[sp-2]<CHAR_MIN||CHAR_MAX<i64stack[sp-2])){
|
---|
| 363 | //符号有り8ビット値をはみ出したとき
|
---|
| 364 | AnswerType=DEF_INTEGER;
|
---|
| 365 | }
|
---|
| 366 | if(AnswerType==DEF_INTEGER&&(i64stack[sp-2]<SHRT_MIN||SHRT_MAX<i64stack[sp-2])){
|
---|
| 367 | //符号有り16ビット値をはみ出したとき
|
---|
| 368 | AnswerType=DEF_LONG;
|
---|
| 369 | }
|
---|
| 370 | if(i64stack[sp-2]<LONG_MIN||LONG_MAX<i64stack[sp-2]){
|
---|
| 371 | //符号有り32ビット値をはみ出したとき
|
---|
| 372 | AnswerType=DEF_INT64;
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 | else{
|
---|
| 376 | if(UINT_MAX<((unsigned _int64)i64stack[sp-2])){
|
---|
| 377 | //符号無し32ビット値をはみ出したとき
|
---|
| 378 | AnswerType=DEF_QWORD;
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | type_stack[sp-2]=AnswerType;
|
---|
| 384 | index_stack[sp-2]=-1;
|
---|
| 385 |
|
---|
| 386 | sp--;
|
---|
| 387 | *pStackPointer=sp;
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | int StaticCalculation(bool enableerror, char *Command,int BaseType,_int64 *pi64data,LONG_PTR *plpIndex,BOOL bDebuggingWatchList){
|
---|
| 391 | extern HANDLE hHeap;
|
---|
| 392 | extern int cp;
|
---|
| 393 | int i,i2,i3,PareNum;
|
---|
| 394 | char Parms[1024],temporary[VN_SIZE],temp2[VN_SIZE];
|
---|
| 395 |
|
---|
| 396 | _int64 i64data;
|
---|
| 397 | double nums[255];
|
---|
| 398 | _int64 i64nums[255];
|
---|
| 399 | char *StrPtr[255];
|
---|
| 400 | long calc[255];
|
---|
| 401 | _int64 stack[255];
|
---|
| 402 | int type[255];
|
---|
| 403 | LONG_PTR before_index[255];
|
---|
| 404 | int sp,pnum;
|
---|
| 405 |
|
---|
| 406 | *pi64data=0;
|
---|
| 407 | if(Command[0]=='\0') return 0;
|
---|
| 408 |
|
---|
| 409 | for(i=0,i2=0,sp=0,pnum=0,PareNum=0;;i++,i2++){
|
---|
| 410 | if(Command[i]=='\"'){
|
---|
| 411 | Parms[i2]=Command[i];
|
---|
| 412 | for(i++,i2++;;i++,i2++){
|
---|
| 413 | Parms[i2]=Command[i];
|
---|
| 414 | if(Command[i]=='\"') break;
|
---|
| 415 | }
|
---|
| 416 | continue;
|
---|
| 417 | }
|
---|
| 418 | else if(Command[i]=='['){
|
---|
| 419 | i3=GetStringInBracket(Parms+i2,Command+i);
|
---|
| 420 | i+=i3-1;
|
---|
| 421 | i2+=i3-1;
|
---|
| 422 | continue;
|
---|
| 423 | }
|
---|
| 424 | else if(Command[i]=='('){
|
---|
| 425 | if(i==0){
|
---|
| 426 | PareNum++;
|
---|
| 427 | i2=-1;
|
---|
| 428 | continue;
|
---|
| 429 | }
|
---|
| 430 | else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
|
---|
| 431 | PareNum++;
|
---|
| 432 | i2=-1;
|
---|
| 433 | continue;
|
---|
| 434 | }
|
---|
| 435 | else{
|
---|
| 436 | //配列変数の場合を考慮
|
---|
| 437 | i3=GetStringInPare(Parms+i2,Command+i);
|
---|
| 438 | i+=i3-1;
|
---|
| 439 | i2+=i3-1;
|
---|
| 440 | continue;
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | else if(Command[i]==')'){
|
---|
| 444 | PareNum--;
|
---|
| 445 | i2--;
|
---|
| 446 | continue;
|
---|
| 447 | }
|
---|
| 448 | else if(IsNumCalcMark(Command,i)||Command[i]=='\0'){
|
---|
| 449 | if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
|
---|
| 450 | if(IsExponent(Command,i)){
|
---|
| 451 | Parms[i2]=Command[i];
|
---|
| 452 | continue;
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | Parms[i2]=0;
|
---|
| 456 |
|
---|
| 457 | if(stack[sp-1]==CALC_AS&&Command[i]=='*'){
|
---|
| 458 | for(i3=0;i3<i2;i3++){
|
---|
| 459 | if(Parms[i2]!='*') break;
|
---|
| 460 | }
|
---|
| 461 | if(i3==i2){
|
---|
| 462 | //"*"をポインタ指定文字として認識する
|
---|
| 463 | Parms[i2]=Command[i];
|
---|
| 464 | continue;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | calc[pnum]=0;
|
---|
| 469 | if(i2){
|
---|
| 470 | before_index[pnum]=-1;
|
---|
| 471 |
|
---|
| 472 | i3=GetCallProcName(Parms,temporary);
|
---|
| 473 | if(Parms[i3]=='('){
|
---|
| 474 | lstrcpy(temp2,Parms+i3+1);
|
---|
| 475 | temp2[lstrlen(temp2)-1]=0;
|
---|
| 476 |
|
---|
| 477 | if(lstrcmpi(temporary,"SizeOf")==0){
|
---|
| 478 | //SizeOf関数
|
---|
| 479 |
|
---|
| 480 | type[pnum]=DEF_LONG;
|
---|
| 481 |
|
---|
| 482 | LONG_PTR lpIndex;
|
---|
| 483 | i3=GetTypeFixed(temp2,&lpIndex);
|
---|
| 484 | if(i3==-1){
|
---|
| 485 | extern int cp;
|
---|
| 486 | if(enableerror) SetError(3,temp2,cp);
|
---|
| 487 | return 0;
|
---|
| 488 | }
|
---|
| 489 | i64nums[pnum]=GetTypeSize(i3,lpIndex);
|
---|
| 490 | StrPtr[pnum]=0;
|
---|
| 491 | }
|
---|
| 492 | else{
|
---|
| 493 | //定数関数
|
---|
| 494 |
|
---|
| 495 | if(!GetConstCalcBuffer(temporary,temp2,Parms)){
|
---|
| 496 | if(enableerror) SetError(3,temporary,cp);
|
---|
| 497 | return 0;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | type[pnum]=StaticCalculation(true, Parms,BaseType,&i64data,&before_index[pnum]);
|
---|
| 501 | if(IsRealNumberType(type[pnum])){
|
---|
| 502 | //整数型
|
---|
| 503 | memcpy(&nums[pnum],&i64data,sizeof(double));
|
---|
| 504 | }
|
---|
| 505 | else{
|
---|
| 506 | //整数型
|
---|
| 507 | i64nums[pnum]=i64data;
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | StrPtr[pnum]=0;
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
| 513 | else{
|
---|
| 514 | if(Parms[0]=='\"'){
|
---|
| 515 | //文字列の場合(比較演算子を考慮)
|
---|
| 516 | RemoveStringQuotes(Parms);
|
---|
| 517 | i2=lstrlen(Parms);
|
---|
| 518 |
|
---|
| 519 | StrLiteral:
|
---|
| 520 | nums[pnum]=i2;
|
---|
| 521 | StrPtr[pnum]=(char *)HeapAlloc(hHeap,0,i2+1);
|
---|
| 522 | memcpy(StrPtr[pnum],Parms,i2);
|
---|
| 523 | StrPtr[pnum][i2]=0;
|
---|
| 524 |
|
---|
| 525 | type[pnum]=DEF_PTR_BYTE;
|
---|
| 526 | before_index[pnum]=LITERAL_STRING;
|
---|
| 527 | }
|
---|
| 528 | else if((Parms[0]=='e'||Parms[0]=='E')&&
|
---|
| 529 | (Parms[1]=='x'||Parms[1]=='X')&&
|
---|
| 530 | Parms[2]=='\"'){
|
---|
| 531 | //拡張文字列
|
---|
| 532 | RemoveStringQuotes(Parms+2);
|
---|
| 533 | i2=FormatString_EscapeSequence(Parms+2);
|
---|
| 534 | nums[pnum]=i2;
|
---|
| 535 | StrPtr[pnum]=(char *)HeapAlloc(hHeap,0,(int)i2+1);
|
---|
| 536 | memcpy(StrPtr[pnum],Parms+2,i2);
|
---|
| 537 | StrPtr[pnum][i2]=0;
|
---|
| 538 |
|
---|
| 539 | type[pnum]=DEF_PTR_BYTE;
|
---|
| 540 | before_index[pnum]=LITERAL_STRING;
|
---|
| 541 | }
|
---|
| 542 | else if(IsVariableTopChar(Parms[0])||Parms[0]=='*'){
|
---|
| 543 | if(bDebuggingWatchList){
|
---|
| 544 | //////////////////////////
|
---|
| 545 | // 変数(デバッグ時のみ)
|
---|
| 546 | //////////////////////////
|
---|
| 547 |
|
---|
| 548 | RELATIVE_VAR RelativeVar;
|
---|
| 549 | LONG_PTR lpIndex;
|
---|
| 550 | int ss[MAX_ARRAYDIM];
|
---|
| 551 | void *offset;
|
---|
| 552 | DWORD dwData;
|
---|
| 553 | SIZE_T stAccBytes;
|
---|
| 554 | float flt;
|
---|
| 555 |
|
---|
| 556 | extern HANDLE hDebugProcess;
|
---|
| 557 |
|
---|
| 558 | i3=Debugging_GetVarOffset(Parms,&i2,&RelativeVar,&lpIndex,ss);
|
---|
| 559 | if(i3==0){
|
---|
| 560 | //式エラー
|
---|
| 561 | return 0;
|
---|
| 562 | }
|
---|
| 563 | if(i3==-1){
|
---|
| 564 | //メモリにアクセスできないとき
|
---|
| 565 | return -1;
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | if(i3){
|
---|
| 569 | StrPtr[pnum]=0;
|
---|
| 570 | offset=(void *)Debugging_GetVarPtr(&RelativeVar);
|
---|
| 571 |
|
---|
| 572 | type[pnum]=i2;
|
---|
| 573 |
|
---|
| 574 | if(i2==DEF_DOUBLE){
|
---|
| 575 | i3=ReadProcessMemory(hDebugProcess,offset,&nums[pnum],sizeof(double),&stAccBytes);
|
---|
| 576 | }
|
---|
| 577 | else if(i2==DEF_SINGLE){
|
---|
| 578 | if(i3=ReadProcessMemory(hDebugProcess,offset,&flt,sizeof(float),&stAccBytes)){
|
---|
| 579 | nums[pnum]=(double)flt;
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
| 582 | else if(IsPtrType(i2)){
|
---|
| 583 | LONG_PTR lpData;
|
---|
| 584 | if(i3=ReadProcessMemory(hDebugProcess,offset,&lpData,sizeof(LONG_PTR),&stAccBytes)){
|
---|
| 585 | i64nums[pnum]=(_int64)lpData;
|
---|
| 586 | }
|
---|
| 587 | }
|
---|
| 588 | else if(Is64Type(i2)){
|
---|
| 589 | type[pnum]=DEF_INT64;
|
---|
| 590 |
|
---|
| 591 | i3=ReadProcessMemory(hDebugProcess,offset,&i64nums[pnum],sizeof(_int64),&stAccBytes);
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 | else if(i2==DEF_LONG){
|
---|
| 595 | long lData;
|
---|
| 596 | if(i3=ReadProcessMemory(hDebugProcess,offset,&lData,sizeof(long),&stAccBytes)){
|
---|
| 597 | i64nums[pnum]=(_int64)lData;
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 | else if(i2==DEF_DWORD){
|
---|
| 601 | if(i3=ReadProcessMemory(hDebugProcess,offset,&dwData,sizeof(DWORD),&stAccBytes)){
|
---|
| 602 | i64nums[pnum]=(_int64)dwData;
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 | else if(i2==DEF_INTEGER){
|
---|
| 606 | short shortData;
|
---|
| 607 | if(i3=ReadProcessMemory(hDebugProcess,offset,&shortData,sizeof(short),&stAccBytes)){
|
---|
| 608 | i64nums[pnum]=(_int64)shortData;
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 | else if(i2==DEF_WORD){
|
---|
| 612 | WORD wData;
|
---|
| 613 | if(i3=ReadProcessMemory(hDebugProcess,offset,&wData,sizeof(WORD),&stAccBytes)){
|
---|
| 614 | i64nums[pnum]=(_int64)wData;
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
| 617 | else if(i2==DEF_CHAR){
|
---|
| 618 | char charData;
|
---|
| 619 | if(i3=ReadProcessMemory(hDebugProcess,offset,&charData,sizeof(char),&stAccBytes)){
|
---|
| 620 | i64nums[pnum]=(_int64)charData;
|
---|
| 621 | }
|
---|
| 622 | }
|
---|
| 623 | else if(i2==DEF_BYTE){
|
---|
| 624 | BYTE byteData;
|
---|
| 625 | if(i3=ReadProcessMemory(hDebugProcess,offset,&byteData,sizeof(BYTE),&stAccBytes)){
|
---|
| 626 | i64nums[pnum]=(_int64)byteData;
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
| 629 | else return 0;
|
---|
| 630 |
|
---|
| 631 | if(!i3){
|
---|
| 632 | //読み込みに失敗
|
---|
| 633 | return -1;
|
---|
| 634 | }
|
---|
| 635 | goto JumpConst;
|
---|
| 636 | }
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 |
|
---|
| 640 | /////////
|
---|
| 641 | //定数
|
---|
| 642 | /////////
|
---|
| 643 | StrPtr[pnum]=0;
|
---|
[7] | 644 | type[pnum] = CDBConst::obj.GetType(Parms);
|
---|
| 645 | if(type[pnum]){
|
---|
[4] | 646 | if(IsRealNumberType(type[pnum])){
|
---|
| 647 | //実数型
|
---|
[7] | 648 | nums[pnum] = CDBConst::obj.GetDoubleData(Parms);
|
---|
[4] | 649 | }
|
---|
| 650 | else if(IsWholeNumberType(type[pnum])){
|
---|
| 651 | //整数
|
---|
[7] | 652 | i64nums[pnum] = CDBConst::obj.GetWholeData(Parms);
|
---|
[4] | 653 | }
|
---|
[7] | 654 | /* else if(type[pnum]==DEF_STRING){
|
---|
[4] | 655 | //リテラル文字列
|
---|
| 656 |
|
---|
| 657 | //バイト数
|
---|
| 658 | nums[pnum]=dbl;
|
---|
| 659 | i2=(int)dbl;
|
---|
| 660 |
|
---|
| 661 | memcpy(Parms,temporary,(int)nums[pnum]);
|
---|
| 662 | goto StrLiteral;
|
---|
[7] | 663 | }*/
|
---|
[4] | 664 | else{
|
---|
| 665 | //エラー
|
---|
| 666 | if(enableerror) SetError(300,NULL,cp);
|
---|
| 667 | return -1;
|
---|
| 668 | }
|
---|
| 669 | goto JumpConst;
|
---|
| 670 | }
|
---|
| 671 |
|
---|
| 672 |
|
---|
| 673 | //////////////
|
---|
| 674 | // 型名の場合
|
---|
| 675 | //////////////
|
---|
| 676 |
|
---|
| 677 | type[pnum]=GetTypeFixed(Parms,&before_index[pnum]);
|
---|
| 678 |
|
---|
| 679 | if(type[pnum]==-1){
|
---|
| 680 | if(bDebuggingWatchList) return -1;
|
---|
| 681 | //エラー
|
---|
[7] | 682 | if(enableerror) SetError(3,Parms,cp);
|
---|
[4] | 683 | return 0;
|
---|
| 684 | }
|
---|
| 685 | JumpConst:;
|
---|
| 686 | }
|
---|
| 687 | else{
|
---|
| 688 | //リテラル値
|
---|
| 689 | StrPtr[pnum]=0;
|
---|
| 690 | type[pnum]=GetLiteralValue(Parms,&i64data,BaseType);
|
---|
| 691 | if(IsRealNumberType(type[pnum])){
|
---|
| 692 | //実数型
|
---|
| 693 | memcpy(&nums[pnum],&i64data,sizeof(double));
|
---|
| 694 | }
|
---|
| 695 | else{
|
---|
| 696 | //整数型
|
---|
| 697 | i64nums[pnum]=i64data;
|
---|
| 698 | before_index[pnum]=GetLiteralIndex(i64data);
|
---|
| 699 | }
|
---|
| 700 | }
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | pnum++;
|
---|
| 704 | }
|
---|
| 705 | else{
|
---|
| 706 | if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
|
---|
| 707 | if(enableerror) SetError(1,NULL,cp);
|
---|
| 708 | return 0;
|
---|
| 709 | }
|
---|
| 710 | if(Command[i]=='+'){
|
---|
| 711 | i2=-1;
|
---|
| 712 | continue;
|
---|
| 713 | }
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | if(Command[i]=='\0'){
|
---|
| 717 | for(;sp>0;pnum++){
|
---|
| 718 | sp--;
|
---|
| 719 | calc[pnum]=(int)stack[sp];
|
---|
| 720 | }
|
---|
| 721 | break;
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | //論理演算子
|
---|
| 725 | if(Command[i]==1&&Command[i+1]==ESC_XOR) i3=CALC_XOR;
|
---|
| 726 | else if(Command[i]==1&&Command[i+1]==ESC_OR) i3=CALC_OR;
|
---|
| 727 | else if(Command[i]==1&&Command[i+1]==ESC_AND) i3=CALC_AND;
|
---|
| 728 | else if(Command[i]==1&&Command[i+1]==ESC_NOT) i3=CALC_NOT;
|
---|
| 729 |
|
---|
| 730 | //ビット演算子(優先順位は算術演算子の後部)
|
---|
| 731 | else if(Command[i]=='<'&&Command[i+1]=='<'){
|
---|
| 732 | i3=CALC_SHL;
|
---|
| 733 | i++;
|
---|
| 734 | }
|
---|
| 735 | else if(Command[i]=='>'&&Command[i+1]=='>'){
|
---|
| 736 | i3=CALC_SHR;
|
---|
| 737 | i++;
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | //比較演算子
|
---|
| 741 | else if(Command[i]=='<'&&Command[i+1]=='='||
|
---|
| 742 | Command[i]=='='&&Command[i+1]=='<'){
|
---|
| 743 | i3=CALC_PE;
|
---|
| 744 | i++;
|
---|
| 745 | }
|
---|
| 746 | else if(Command[i]=='>'&&Command[i+1]=='='||
|
---|
| 747 | Command[i]=='='&&Command[i+1]=='>'){
|
---|
| 748 | i3=CALC_QE;
|
---|
| 749 | i++;
|
---|
| 750 | }
|
---|
| 751 | else if(Command[i]=='<'&&Command[i+1]=='>'||
|
---|
| 752 | Command[i]=='>'&&Command[i+1]=='<'){
|
---|
| 753 | i3=CALC_NOTEQUAL;
|
---|
| 754 | i++;
|
---|
| 755 | }
|
---|
| 756 | else if(Command[i]=='=') i3=CALC_EQUAL;
|
---|
| 757 | else if(Command[i]=='<') i3=CALC_P;
|
---|
| 758 | else if(Command[i]=='>') i3=CALC_Q;
|
---|
| 759 |
|
---|
| 760 | //算術演算子
|
---|
| 761 | else if(Command[i]=='+'||Command[i]=='&') i3=CALC_ADDITION;
|
---|
| 762 | else if(Command[i]=='-'&&i2) i3=CALC_SUBTRACTION;
|
---|
| 763 | else if(Command[i]==1&&Command[i+1]==ESC_MOD) i3=CALC_MOD;
|
---|
| 764 | else if(Command[i]=='*') i3=CALC_PRODUCT;
|
---|
| 765 | else if(Command[i]=='/') i3=CALC_QUOTIENT;
|
---|
| 766 | else if(Command[i]=='\\') i3=CALC_INTQUOTIENT;
|
---|
| 767 | else if(Command[i]=='-'&&i2==0) i3=CALC_MINUSMARK;
|
---|
| 768 | else if(Command[i]=='^') i3=CALC_POWER;
|
---|
| 769 | else if(Command[i]==1&&Command[i+1]==ESC_AS) i3=CALC_AS;
|
---|
| 770 |
|
---|
| 771 | i3+=PareNum*100;
|
---|
| 772 | if(sp){
|
---|
| 773 | if(stack[sp-1]>i3-3&&
|
---|
| 774 | (!(
|
---|
| 775 | (stack[sp-1]%100==CALC_MINUSMARK||stack[sp-1]%100==CALC_NOT)&&
|
---|
| 776 | (i3%100==CALC_MINUSMARK||i3%100==CALC_NOT)
|
---|
| 777 | ))
|
---|
| 778 | ){
|
---|
| 779 | for(;sp>0;){
|
---|
| 780 | sp--;
|
---|
| 781 | calc[pnum]=(int)stack[sp];
|
---|
| 782 | pnum++;
|
---|
| 783 | if(!(stack[sp-1]>i3-3)) break;
|
---|
| 784 | }
|
---|
| 785 | }
|
---|
| 786 | }
|
---|
| 787 | stack[sp]=i3;
|
---|
| 788 | sp++;
|
---|
| 789 |
|
---|
| 790 | if(Command[i]==1) i++;
|
---|
| 791 | i2=-1;
|
---|
| 792 | continue;
|
---|
| 793 | }
|
---|
| 794 | Parms[i2]=Command[i];
|
---|
| 795 | }
|
---|
| 796 |
|
---|
| 797 | int type_stack[255];
|
---|
| 798 | LONG_PTR index_stack[255];
|
---|
| 799 | int idCalc;
|
---|
| 800 | for(i=0,sp=0;i<pnum;i++){
|
---|
| 801 |
|
---|
| 802 | //型チェック(正常でない場合はエラーにする)
|
---|
| 803 | TypeErrorCheck(stack,sp,calc[i]%100);
|
---|
| 804 |
|
---|
| 805 | idCalc=calc[i]%100;
|
---|
| 806 |
|
---|
| 807 | switch(idCalc){
|
---|
| 808 | //数値
|
---|
| 809 | case 0:
|
---|
| 810 | dbl_stack[sp]=nums[i];
|
---|
| 811 | i64stack[sp]=i64nums[i];
|
---|
| 812 | type_stack[sp]=type[i];
|
---|
| 813 | index_stack[sp]=before_index[i];
|
---|
| 814 |
|
---|
| 815 | stack[sp]=(_int64)StrPtr[i];
|
---|
| 816 | sp++;
|
---|
| 817 | break;
|
---|
| 818 |
|
---|
| 819 | //論理演算
|
---|
| 820 | case CALC_NOT:
|
---|
| 821 | if(IsRealNumberType(type_stack[sp-1])){
|
---|
| 822 | //実数演算
|
---|
| 823 | dbl_stack[sp-1]=(double)(~(long)dbl_stack[sp-1]);
|
---|
| 824 | }
|
---|
| 825 | else{
|
---|
| 826 | //整数演算
|
---|
| 827 | i64stack[sp-1]=~i64stack[sp-1];
|
---|
| 828 | }
|
---|
| 829 | break;
|
---|
| 830 |
|
---|
| 831 | //比較演算
|
---|
| 832 | case CALC_PE:
|
---|
| 833 | case CALC_QE:
|
---|
| 834 | case CALC_P:
|
---|
| 835 | case CALC_Q:
|
---|
| 836 | case CALC_NOTEQUAL:
|
---|
| 837 | case CALC_EQUAL:
|
---|
| 838 |
|
---|
| 839 | //論理演算
|
---|
| 840 | case CALC_XOR:
|
---|
| 841 | case CALC_OR:
|
---|
| 842 | case CALC_AND:
|
---|
| 843 |
|
---|
| 844 | //シフト演算
|
---|
| 845 | case CALC_SHL:
|
---|
| 846 | case CALC_SHR:
|
---|
| 847 |
|
---|
| 848 | //算術演算
|
---|
| 849 | case CALC_ADDITION:
|
---|
| 850 | case CALC_SUBTRACTION:
|
---|
| 851 | case CALC_MOD:
|
---|
| 852 | case CALC_PRODUCT:
|
---|
| 853 | case CALC_QUOTIENT:
|
---|
| 854 | case CALC_INTQUOTIENT:
|
---|
| 855 | case CALC_POWER:
|
---|
| 856 | StaticTwoTerm(idCalc,type_stack,index_stack,&sp,BaseType);
|
---|
| 857 | break;
|
---|
| 858 |
|
---|
| 859 | case CALC_MINUSMARK:
|
---|
| 860 | if(IsRealNumberType(type_stack[sp-1])){
|
---|
| 861 | //実数演算
|
---|
| 862 | dbl_stack[sp-1]=-dbl_stack[sp-1];
|
---|
| 863 | }
|
---|
| 864 | else{
|
---|
| 865 | //整数演算
|
---|
| 866 | i64stack[sp-1]=-i64stack[sp-1];
|
---|
| 867 | }
|
---|
| 868 | break;
|
---|
| 869 | case CALC_AS:
|
---|
| 870 | if(IsWholeNumberType(type_stack[sp-2])){
|
---|
| 871 | if(IsRealNumberType(type_stack[sp-1])){
|
---|
| 872 | dbl_stack[sp-2]=(double)i64stack[sp-2];
|
---|
| 873 | }
|
---|
| 874 | }
|
---|
| 875 | if(IsRealNumberType(type_stack[sp-2])){
|
---|
| 876 | if(IsWholeNumberType(type_stack[sp-1])){
|
---|
| 877 | i64stack[sp-2]=(_int64)dbl_stack[sp-2];
|
---|
| 878 | }
|
---|
| 879 | }
|
---|
| 880 | type_stack[sp-2]=type_stack[sp-1];
|
---|
| 881 | index_stack[sp-2]=index_stack[sp-1];
|
---|
| 882 | sp--;
|
---|
| 883 | break;
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
| 886 | if(stack[0]){
|
---|
| 887 | //文字列ポインタ
|
---|
| 888 | *pi64data=(_int64)stack[0];
|
---|
| 889 | *plpIndex=index_stack[0];
|
---|
| 890 | return type_stack[0];
|
---|
| 891 | }
|
---|
| 892 |
|
---|
| 893 | if(IsRealNumberType(type_stack[0])){
|
---|
| 894 | //実数
|
---|
| 895 | memcpy(pi64data,&dbl_stack[0],sizeof(double));
|
---|
| 896 | return type_stack[0];
|
---|
| 897 | }
|
---|
| 898 |
|
---|
| 899 | //整数
|
---|
| 900 | *pi64data=i64stack[0];
|
---|
| 901 |
|
---|
| 902 | if(plpIndex){
|
---|
| 903 | *plpIndex=index_stack[0];
|
---|
| 904 | if(*plpIndex==-1){
|
---|
| 905 | if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){
|
---|
| 906 | //整数(符号有り/無し)
|
---|
| 907 | i64data=*pi64data;
|
---|
| 908 |
|
---|
| 909 | *plpIndex=GetLiteralIndex(i64data);
|
---|
| 910 | }
|
---|
| 911 | }
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 | return type_stack[0];
|
---|
| 915 | }
|
---|
| 916 |
|
---|
| 917 | #pragma optimize("", off)
|
---|
| 918 | DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType){
|
---|
| 919 | extern HANDLE hHeap;
|
---|
| 920 | extern int cp;
|
---|
| 921 | int i,i2,i3,sw1,sw2,bDbl;
|
---|
| 922 | double dbl;
|
---|
| 923 | char temporary[255];
|
---|
| 924 |
|
---|
| 925 | if(value[0]=='&'){
|
---|
| 926 | _int64 i64temp;
|
---|
| 927 | lstrcpy(temporary,value);
|
---|
| 928 |
|
---|
| 929 | if(temporary[1]=='o'||temporary[1]=='O'){
|
---|
| 930 | for(i=2;;i++){
|
---|
| 931 | i3=temporary[i]-0x30;
|
---|
| 932 | if(i3<0||7<i3) break;
|
---|
| 933 | temporary[i]=i3;
|
---|
| 934 | }
|
---|
| 935 | if(temporary[i]){
|
---|
| 936 | SetError(57,NULL,cp);
|
---|
| 937 | return DEF_BYTE;
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | i64temp=1;
|
---|
| 941 | *pi64=0;
|
---|
| 942 | for(i--;i>=2;i--){
|
---|
| 943 | *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
|
---|
| 944 | i64temp*=8;
|
---|
| 945 | }
|
---|
| 946 | }
|
---|
| 947 | else if(temporary[1]=='h'||temporary[1]=='H'){
|
---|
| 948 | CharUpper(temporary+2);
|
---|
| 949 | for(i=2;;i++){
|
---|
| 950 | i3=temporary[i]-0x30;
|
---|
| 951 | if(i3<0||9<i3){
|
---|
| 952 | i3=temporary[i]-0x41+10;
|
---|
| 953 | if(i3<0xA||0xF<i3) break;
|
---|
| 954 | }
|
---|
| 955 | temporary[i]=i3;
|
---|
| 956 | }
|
---|
| 957 | if(temporary[i]){
|
---|
| 958 | SetError(58,NULL,cp);
|
---|
| 959 | return DEF_BYTE;
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | i64temp=1;
|
---|
| 963 | *pi64=0;
|
---|
| 964 | for(i--;i>=2;i--){
|
---|
| 965 | *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
|
---|
| 966 | i64temp*=0x10;
|
---|
| 967 | }
|
---|
| 968 | }
|
---|
| 969 | else{
|
---|
| 970 | SetError(12,"&",cp);
|
---|
| 971 | return DEF_BYTE;
|
---|
| 972 | }
|
---|
| 973 |
|
---|
| 974 | if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return DEF_QWORD;
|
---|
| 975 |
|
---|
| 976 | if(((unsigned _int64)*pi64)<=UCHAR_MAX){
|
---|
| 977 | //符号無し8ビット整数のリテラル値
|
---|
| 978 | return DEF_BYTE;
|
---|
| 979 | }
|
---|
| 980 | else if(((unsigned _int64)*pi64)<=USHRT_MAX){
|
---|
| 981 | //符号無し16ビット整数のリテラル値
|
---|
| 982 | return DEF_WORD;
|
---|
| 983 | }
|
---|
| 984 | else if(((unsigned _int64)*pi64)<=UINT_MAX){
|
---|
| 985 | //符号無し32ビット整数のリテラル値
|
---|
| 986 | return DEF_DWORD;
|
---|
| 987 | }
|
---|
| 988 | else{
|
---|
| 989 | //符号無し64ビット整数のリテラル値
|
---|
| 990 | return DEF_QWORD;
|
---|
| 991 | }
|
---|
| 992 | }
|
---|
| 993 | else if((value[0]>='0'&&value[0]<='9')||value[0]=='+'||value[0]=='-'||(value[0]=='.'&&(!IsVariableTopChar(value[1])))){
|
---|
| 994 | for(i=0;;i++){
|
---|
| 995 | if(value[i]!='-') break;
|
---|
| 996 | }
|
---|
| 997 | if(value[i]=='.'){
|
---|
| 998 | SlideString(value+i,1);
|
---|
| 999 | value[i]='0';
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
| 1002 | //エラーチェック
|
---|
| 1003 | bDbl=0;
|
---|
| 1004 | sw1=0;
|
---|
| 1005 | sw2=0;
|
---|
| 1006 | for(i2=i;;i2++){
|
---|
| 1007 | if(value[i2]=='\0') break;
|
---|
| 1008 | if(value[i2]=='.') bDbl=1;
|
---|
| 1009 | if(!((value[i2]>='0'&&value[i2]<='9')||value[i2]=='.')){
|
---|
| 1010 | if((value[i2]=='e'||value[i2]=='E')&&sw1==0){
|
---|
| 1011 | bDbl=1;
|
---|
| 1012 | sw1=1;
|
---|
| 1013 | }
|
---|
| 1014 | else if((value[i2]=='+'||value[i2]=='-')&&sw1==1&&sw2==0) sw2=1;
|
---|
| 1015 | else{
|
---|
| 1016 | extern BOOL bDebugRun;
|
---|
| 1017 | if(bDebugRun) return DEF_DOUBLE;
|
---|
| 1018 |
|
---|
| 1019 | SetError(3,value,cp);
|
---|
| 1020 | return DEF_DOUBLE;
|
---|
| 1021 | }
|
---|
| 1022 | }
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
| 1025 | if(bDbl){
|
---|
| 1026 | //実数のリテラル値
|
---|
| 1027 | if(i%2) dbl=-atof(value+i);
|
---|
| 1028 | else dbl=atof(value+i);
|
---|
| 1029 |
|
---|
| 1030 | memcpy(pi64,&dbl,sizeof(double));
|
---|
| 1031 |
|
---|
| 1032 | if(BaseType==DEF_SINGLE) return DEF_SINGLE;
|
---|
| 1033 |
|
---|
| 1034 | return DEF_DOUBLE;
|
---|
| 1035 | }
|
---|
| 1036 | else{
|
---|
| 1037 | *pi64=_atoi64(value+i);
|
---|
| 1038 | if(i%2) *pi64=-(*pi64);
|
---|
| 1039 |
|
---|
| 1040 | if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return BaseType;
|
---|
| 1041 |
|
---|
| 1042 | if(LONG_MIN<=*pi64&&*pi64<=LONG_MAX){
|
---|
| 1043 | //符号有り32ビット整数のリテラル値
|
---|
| 1044 | return DEF_LONG;
|
---|
| 1045 | }
|
---|
| 1046 | else if(*pi64<=UINT_MAX){
|
---|
| 1047 | //符号無し32ビット整数のリテラル値
|
---|
| 1048 | return DEF_DWORD;
|
---|
| 1049 | }
|
---|
| 1050 | else{
|
---|
| 1051 | //符号有り64ビット整数のリテラル値
|
---|
| 1052 | return DEF_INT64;
|
---|
| 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | }
|
---|
| 1056 |
|
---|
| 1057 | extern BOOL bDebugRun;
|
---|
| 1058 | if(bDebugRun) return DEF_DOUBLE;
|
---|
| 1059 |
|
---|
| 1060 | SetError(33,NULL,cp);
|
---|
| 1061 | return DEF_DOUBLE;
|
---|
| 1062 | }
|
---|
| 1063 | #pragma optimize("", on)
|
---|
| 1064 |
|
---|
| 1065 | BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer){
|
---|
| 1066 | extern HANDLE hHeap;
|
---|
| 1067 | int i2,i3,i4,num;
|
---|
| 1068 | char temporary[VN_SIZE];
|
---|
| 1069 | char *pParms[MAX_PARMS];
|
---|
| 1070 |
|
---|
| 1071 | CONSTINFO *pci;
|
---|
| 1072 | pci=GetConstHash(name);
|
---|
| 1073 | if(!pci) return 0;
|
---|
| 1074 |
|
---|
| 1075 | num=0;
|
---|
| 1076 | i2=0;
|
---|
| 1077 | while(1){
|
---|
| 1078 | i2=GetOneParameter(Parameter,i2,temporary);
|
---|
| 1079 |
|
---|
| 1080 | pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
| 1081 | lstrcpy(pParms[num],temporary);
|
---|
| 1082 |
|
---|
| 1083 | num++;
|
---|
| 1084 | if(Parameter[i2]=='\0') break;
|
---|
| 1085 | }
|
---|
| 1086 | if(num!=pci->ParmNum){
|
---|
| 1087 | extern int cp;
|
---|
| 1088 | for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
|
---|
| 1089 | SetError(10,name,cp);
|
---|
| 1090 | lstrcpy(pCalcBuffer,"0");
|
---|
| 1091 | return 1;
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
| 1094 | i2=0;
|
---|
| 1095 | i4=0;
|
---|
| 1096 | while(1){
|
---|
| 1097 |
|
---|
| 1098 | //数式内の項を取得
|
---|
| 1099 | for(i3=0;;i2++,i3++){
|
---|
| 1100 | if(!IsVariableChar(pci->StrValue[i2])){
|
---|
| 1101 | temporary[i3]=0;
|
---|
| 1102 | break;
|
---|
| 1103 | }
|
---|
| 1104 | temporary[i3]=pci->StrValue[i2];
|
---|
| 1105 | }
|
---|
| 1106 |
|
---|
| 1107 | //パラメータと照合する
|
---|
| 1108 | for(i3=0;i3<pci->ParmNum;i3++){
|
---|
| 1109 | if(lstrcmp(pci->ppParm[i3],temporary)==0) break;
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
| 1112 | if(i3==pci->ParmNum){
|
---|
| 1113 | //パラメータでないとき
|
---|
| 1114 | lstrcpy(pCalcBuffer+i4,temporary);
|
---|
| 1115 | i4+=lstrlen(temporary);
|
---|
| 1116 | }
|
---|
| 1117 | else{
|
---|
| 1118 | //パラメータのとき
|
---|
| 1119 | lstrcpy(pCalcBuffer+i4,pParms[i3]);
|
---|
| 1120 | i4+=lstrlen(pParms[i3]);
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
| 1123 | //演算子をコピー
|
---|
| 1124 | for(;;i2++,i4++){
|
---|
| 1125 | if(pci->StrValue[i2]==1){
|
---|
| 1126 | pCalcBuffer[i4++]=pci->StrValue[i2++];
|
---|
| 1127 | pCalcBuffer[i4]=pci->StrValue[i2];
|
---|
| 1128 | continue;
|
---|
| 1129 | }
|
---|
| 1130 | if(IsVariableTopChar(pci->StrValue[i2])) break;
|
---|
| 1131 | pCalcBuffer[i4]=pci->StrValue[i2];
|
---|
| 1132 | if(pci->StrValue[i2]=='\0') break;
|
---|
| 1133 | }
|
---|
| 1134 |
|
---|
| 1135 | if(pci->StrValue[i2]=='\0') break;
|
---|
| 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
|
---|
| 1139 |
|
---|
| 1140 | return 1;
|
---|
| 1141 | }
|
---|
| 1142 | DWORD GetConstValue(char *name,double *pDbl,char *buffer,LONG_PTR *plpIndex){
|
---|
| 1143 | CONSTINFO *pci;
|
---|
| 1144 | pci=GetConstHash(name);
|
---|
| 1145 | if(pci){
|
---|
| 1146 | //定数が見つかったとき
|
---|
| 1147 |
|
---|
| 1148 | if(pci->StrValue){
|
---|
| 1149 | //文字列定数
|
---|
| 1150 |
|
---|
| 1151 | //バイト数
|
---|
| 1152 | *pDbl=pci->DblValue;
|
---|
| 1153 |
|
---|
| 1154 | //データ
|
---|
| 1155 | memcpy(buffer,pci->StrValue,(int)pci->DblValue);
|
---|
| 1156 |
|
---|
| 1157 | if(plpIndex) *plpIndex=pci->lpIndex;
|
---|
| 1158 |
|
---|
| 1159 | return DEF_STRING;
|
---|
| 1160 | }
|
---|
| 1161 | else{
|
---|
| 1162 | if(pci->type==DEF_INT64){
|
---|
| 1163 | memcpy(pDbl,&pci->i64Value,sizeof(_int64));
|
---|
| 1164 | return DEF_INT64;
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
| 1167 | if(plpIndex) *plpIndex=pci->lpIndex;
|
---|
| 1168 |
|
---|
| 1169 | *pDbl=pci->DblValue;
|
---|
| 1170 | return pci->type;
|
---|
| 1171 | }
|
---|
| 1172 | }
|
---|
| 1173 |
|
---|
| 1174 | if(plpIndex) *plpIndex=-1;
|
---|
| 1175 |
|
---|
| 1176 | return -1;
|
---|
| 1177 | }
|
---|
| 1178 | BOOL IsStringObjectType(TYPEINFO *pTypeInfo){
|
---|
| 1179 | if(pTypeInfo->type==DEF_OBJECT){
|
---|
| 1180 | if(lstrcmp(pTypeInfo->u.pobj_Class->name,"String")==0){
|
---|
| 1181 | return 1;
|
---|
| 1182 | }
|
---|
| 1183 | }
|
---|
| 1184 | return 0;
|
---|
| 1185 | }
|
---|
| 1186 | BOOL IsStringSubsituation(CClass *pobj_c){
|
---|
| 1187 | //String受け入れ可能な "=" 演算子をオーバーロードしているかどうかを調べる
|
---|
| 1188 | BOOL bRet=0;
|
---|
| 1189 |
|
---|
| 1190 | SUBINFO **ppsi;
|
---|
| 1191 | int num;
|
---|
| 1192 | ppsi=pobj_c->GetOperatorSubInfo(CALC_SUBSITUATION,num);
|
---|
| 1193 | if(num==0){
|
---|
| 1194 | bRet=0;
|
---|
| 1195 | goto finish;
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
| 1198 | int i;
|
---|
| 1199 | for(i=0;i<num;i++){
|
---|
| 1200 | if(ppsi[i]->ParmNum==2){
|
---|
| 1201 | TYPEINFO TypeInfo={ppsi[i]->pParmInfo[1].type,ppsi[i]->pParmInfo[1].u.index};
|
---|
| 1202 | if(IsStringObjectType(&TypeInfo)){
|
---|
| 1203 | bRet=1;
|
---|
| 1204 | goto finish;
|
---|
| 1205 | }
|
---|
| 1206 | }
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
| 1209 | finish:
|
---|
| 1210 | HeapDefaultFree(ppsi);
|
---|
| 1211 | return bRet;
|
---|
| 1212 | }
|
---|
| 1213 | int IsStrCalculation(char *Command){
|
---|
| 1214 | int i,i2,i3,i4,type,PareNum;
|
---|
| 1215 | char temporary[VN_SIZE],temp2[8192];
|
---|
| 1216 |
|
---|
| 1217 | for(i=0,i2=0;;i++){
|
---|
| 1218 | if(Command[i]=='('){
|
---|
| 1219 | for(i++,PareNum=1;;i++){
|
---|
| 1220 | if(Command[i]=='(') PareNum++;
|
---|
| 1221 | else if(Command[i]==')'){
|
---|
| 1222 | PareNum--;
|
---|
| 1223 | if(PareNum==0) break;
|
---|
| 1224 | }
|
---|
| 1225 | }
|
---|
| 1226 | continue;
|
---|
| 1227 | }
|
---|
| 1228 | if(Command[i]=='['){
|
---|
| 1229 | for(i++,PareNum=1;;i++){
|
---|
| 1230 | if(Command[i]=='[') PareNum++;
|
---|
| 1231 | else if(Command[i]==']'){
|
---|
| 1232 | PareNum--;
|
---|
| 1233 | if(PareNum==0) break;
|
---|
| 1234 | }
|
---|
| 1235 | }
|
---|
| 1236 | continue;
|
---|
| 1237 | }
|
---|
| 1238 | if(Command[i]=='\"'){
|
---|
| 1239 | i++;
|
---|
| 1240 | while(Command[i]!='\"') i++;
|
---|
| 1241 | continue;
|
---|
| 1242 | }
|
---|
| 1243 | if(Command[i]=='\0'){
|
---|
| 1244 | if(IsVariableTopChar(Command[i2])||
|
---|
| 1245 | Command[i2]=='.'&&IsVariableTopChar(Command[i2+1])){
|
---|
| 1246 |
|
---|
| 1247 | if((Command[i2]=='e'||Command[i2]=='E')&&
|
---|
| 1248 | (Command[i2+1]=='x'||Command[i2+1]=='X')&&
|
---|
| 1249 | Command[i2+2]=='\"'){
|
---|
| 1250 | //拡張文字列
|
---|
| 1251 | return 1;
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
| 1254 | for(i3=0;;i3++){
|
---|
| 1255 | if(Command[i2+i3]=='('){
|
---|
| 1256 | temporary[i3]=0;
|
---|
| 1257 | break;
|
---|
| 1258 | }
|
---|
| 1259 | temporary[i3]=Command[i2+i3];
|
---|
| 1260 | if(Command[i2+i3]=='\0') break;
|
---|
| 1261 | }
|
---|
| 1262 | if(Command[i2+i3]=='('){
|
---|
| 1263 | TYPEINFO TypeInfo;
|
---|
| 1264 |
|
---|
| 1265 | //DLL関数の場合
|
---|
| 1266 | DECLAREINFO *pdi;
|
---|
| 1267 | pdi=GetDeclareHash(temporary);
|
---|
| 1268 | if(pdi){
|
---|
| 1269 | TypeInfo.type=pdi->ReturnType;
|
---|
| 1270 | TypeInfo.u.lpIndex=pdi->u.ReturnIndex;
|
---|
| 1271 | if(IsStringObjectType(&TypeInfo)) return 1;
|
---|
| 1272 | return 0;
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | //ユーザー定義関数
|
---|
| 1276 | SUBINFO *psi;
|
---|
| 1277 | psi=GetSubHash(temporary);
|
---|
| 1278 | if(psi){
|
---|
| 1279 | TypeInfo.type=psi->ReturnType;
|
---|
| 1280 | TypeInfo.u.lpIndex=psi->u.ReturnIndex;
|
---|
| 1281 | if(IsStringObjectType(&TypeInfo)) return 1;
|
---|
| 1282 | return 0;
|
---|
| 1283 | }
|
---|
| 1284 |
|
---|
| 1285 | //組み込み関数
|
---|
| 1286 | i4=GetFunctionFromName(temporary);
|
---|
| 1287 | if(i4){
|
---|
| 1288 | //組み込み関数は文字列を返さない
|
---|
| 1289 | return 0;
|
---|
| 1290 | }
|
---|
| 1291 |
|
---|
| 1292 | //定数
|
---|
| 1293 | CONSTINFO *pci;
|
---|
| 1294 | pci=GetConstHash(temporary);
|
---|
| 1295 | if(pci){
|
---|
| 1296 |
|
---|
| 1297 | if(pci->ParmNum){
|
---|
| 1298 | //マクロ関数の場合
|
---|
| 1299 | GetStringInPare_RemovePare(temporary,Command+i2+i3+1);
|
---|
| 1300 | GetConstCalcBuffer(pci->name,temporary,temp2);
|
---|
| 1301 | return IsStrCalculation(temp2);
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | if(pci->type==DEF_STRING) return 1;
|
---|
| 1305 | else return 0;
|
---|
| 1306 | }
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
| 1309 | //定数
|
---|
[7] | 1310 | i3 = CDBConst::obj.GetType(Command+i2);
|
---|
[4] | 1311 | if(i3==DEF_STRING) return 1; //文字列
|
---|
[7] | 1312 | if(i3) return 0; //数値
|
---|
[4] | 1313 |
|
---|
| 1314 | //変数
|
---|
| 1315 | CClass *pobj_Class;
|
---|
[11] | 1316 | type = GetVarType(Command+i2,(LONG_PTR *)&pobj_Class,1);
|
---|
| 1317 | if(type==-1 || type ==0){
|
---|
[4] | 1318 | //エラー
|
---|
| 1319 | return -1;
|
---|
| 1320 | }
|
---|
| 1321 | if(type==DEF_OBJECT){
|
---|
| 1322 | if(lstrcmp(pobj_Class->name,"String")==0){
|
---|
| 1323 | return 1;
|
---|
| 1324 | }
|
---|
| 1325 | return 0;
|
---|
| 1326 | }
|
---|
| 1327 | }
|
---|
| 1328 | else if(Command[i2]=='\"') return 1;
|
---|
| 1329 | break;
|
---|
| 1330 | }
|
---|
| 1331 | if(IsNumCalcMark(Command,i)||IsStrCalcMark(Command[i])){
|
---|
| 1332 | if(IsStrCalcMark(Command[i])){
|
---|
| 1333 |
|
---|
| 1334 | //&H、&O表記の場合を考慮
|
---|
| 1335 | if(i==0) continue;
|
---|
| 1336 | if(IsNumCalcMark(Command,i-1)) continue;
|
---|
| 1337 |
|
---|
| 1338 | if(Command[i+1]=='(') break;
|
---|
| 1339 | i2=i+1;
|
---|
| 1340 | continue;
|
---|
| 1341 | }
|
---|
| 1342 | break;
|
---|
| 1343 | }
|
---|
| 1344 | }
|
---|
| 1345 | return 0;
|
---|
| 1346 | }
|
---|
| 1347 |
|
---|
| 1348 | BYTE GetCalcId(char *Command,int *pi){
|
---|
| 1349 | *pi=0;
|
---|
| 1350 |
|
---|
| 1351 | if(Command[0]==1) *pi=1;
|
---|
| 1352 |
|
---|
| 1353 | //論理演算子
|
---|
| 1354 | if(Command[0]==1&&Command[1]==ESC_XOR) return CALC_XOR;
|
---|
| 1355 | else if(Command[0]==1&&Command[1]==ESC_OR) return CALC_OR;
|
---|
| 1356 | else if(Command[0]==1&&Command[1]==ESC_AND) return CALC_AND;
|
---|
| 1357 | else if(Command[0]==1&&Command[1]==ESC_NOT) return CALC_NOT;
|
---|
| 1358 |
|
---|
| 1359 | //ビット演算子(優先順位は算術演算子の後部)
|
---|
| 1360 | else if(Command[0]=='<'&&Command[1]=='<'){
|
---|
| 1361 | *pi=1;
|
---|
| 1362 | return CALC_SHL;
|
---|
| 1363 | }
|
---|
| 1364 | else if(Command[0]=='>'&&Command[1]=='>'){
|
---|
| 1365 | *pi=1;
|
---|
| 1366 | return CALC_SHR;
|
---|
| 1367 | }
|
---|
| 1368 |
|
---|
| 1369 | //比較演算子
|
---|
| 1370 | else if(Command[0]=='<'&&Command[1]=='='||
|
---|
| 1371 | Command[0]=='='&&Command[1]=='<'){
|
---|
| 1372 | *pi=1;
|
---|
| 1373 | return CALC_PE;
|
---|
| 1374 | }
|
---|
| 1375 | else if(Command[0]=='>'&&Command[1]=='='||
|
---|
| 1376 | Command[0]=='='&&Command[1]=='>'){
|
---|
| 1377 | *pi=1;
|
---|
| 1378 | return CALC_QE;
|
---|
| 1379 | }
|
---|
| 1380 | else if(Command[0]=='<'&&Command[1]=='>'||
|
---|
| 1381 | Command[0]=='>'&&Command[1]=='<'){
|
---|
| 1382 | *pi=1;
|
---|
| 1383 | return CALC_NOTEQUAL;
|
---|
| 1384 | }
|
---|
| 1385 | else if(Command[0]=='=') return CALC_EQUAL;
|
---|
| 1386 | else if(Command[0]=='<') return CALC_P;
|
---|
| 1387 | else if(Command[0]=='>') return CALC_Q;
|
---|
| 1388 |
|
---|
| 1389 | //算術演算子
|
---|
| 1390 | else if(Command[0]=='+') return CALC_ADDITION;
|
---|
| 1391 | else if(Command[0]=='-') return CALC_SUBTRACTION;
|
---|
| 1392 | else if(Command[0]=='&') return CALC_STRPLUS;
|
---|
| 1393 | else if(Command[0]==1&&Command[1]==ESC_MOD) return CALC_MOD;
|
---|
| 1394 | else if(Command[0]=='*') return CALC_PRODUCT;
|
---|
| 1395 | else if(Command[0]=='/') return CALC_QUOTIENT;
|
---|
| 1396 | else if(Command[0]=='\\') return CALC_INTQUOTIENT;
|
---|
| 1397 | else if(Command[0]=='^') return CALC_POWER;
|
---|
| 1398 | else if(Command[0]==1&&Command[1]==ESC_AS) return CALC_AS;
|
---|
| 1399 |
|
---|
| 1400 | return 0;
|
---|
| 1401 | }
|
---|
| 1402 | BOOL GetNumOpeElements(char *Command,int *pnum,
|
---|
| 1403 | char *values[255],long calc[255],long stack[255]){
|
---|
| 1404 | extern int cp;
|
---|
| 1405 | extern HANDLE hHeap;
|
---|
| 1406 | int i,i2,i3,i4,PareNum,sp;
|
---|
| 1407 | char temporary[1024];
|
---|
| 1408 |
|
---|
| 1409 | for(i=0,i2=0,sp=0,*pnum=0,PareNum=0;;i++,i2++){
|
---|
| 1410 | if(Command[i]=='\"'){
|
---|
| 1411 | temporary[i2]=Command[i];
|
---|
| 1412 | for(i++,i2++;;i++,i2++){
|
---|
| 1413 | temporary[i2]=Command[i];
|
---|
| 1414 | if(Command[i]=='\"') break;
|
---|
| 1415 | }
|
---|
| 1416 | continue;
|
---|
| 1417 | }
|
---|
| 1418 | else if(Command[i]=='['){
|
---|
| 1419 | i3=GetStringInBracket(temporary+i2,Command+i);
|
---|
| 1420 | i+=i3-1;
|
---|
| 1421 | i2+=i3-1;
|
---|
| 1422 | continue;
|
---|
| 1423 | }
|
---|
| 1424 | else if(Command[i]=='('){
|
---|
| 1425 | if(i==0){
|
---|
| 1426 | PareNum++;
|
---|
| 1427 | i2=-1;
|
---|
| 1428 | continue;
|
---|
| 1429 | }
|
---|
| 1430 | else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
|
---|
| 1431 | PareNum++;
|
---|
| 1432 | i2=-1;
|
---|
| 1433 | continue;
|
---|
| 1434 | }
|
---|
| 1435 | else{
|
---|
| 1436 | //配列変数の場合を考慮
|
---|
| 1437 | i3=GetStringInPare(temporary+i2,Command+i);
|
---|
| 1438 | i+=i3-1;
|
---|
| 1439 | i2+=i3-1;
|
---|
| 1440 | continue;
|
---|
| 1441 | }
|
---|
| 1442 | }
|
---|
| 1443 | else if(Command[i]==')'){
|
---|
| 1444 | PareNum--;
|
---|
| 1445 | i2--;
|
---|
| 1446 | continue;
|
---|
| 1447 | }
|
---|
| 1448 | else if(IsNumCalcMark(Command,i)||(Command[i]=='&'&&i2!=0)){
|
---|
| 1449 | if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
|
---|
| 1450 | if(IsExponent(Command,i)){
|
---|
| 1451 | temporary[i2]=Command[i];
|
---|
| 1452 | continue;
|
---|
| 1453 | }
|
---|
| 1454 | }
|
---|
| 1455 | temporary[i2]=0;
|
---|
| 1456 |
|
---|
| 1457 | if((stack[sp-1]%100)==CALC_AS&&Command[i]=='*'){
|
---|
| 1458 | for(i3=0;i3<i2;i3++){
|
---|
| 1459 | if(temporary[i2]!='*') break;
|
---|
| 1460 | }
|
---|
| 1461 | if(i3==i2){
|
---|
| 1462 | //"*"をポインタ指定文字として認識する
|
---|
| 1463 | temporary[i2]=Command[i];
|
---|
| 1464 | continue;
|
---|
| 1465 | }
|
---|
| 1466 | }
|
---|
| 1467 |
|
---|
| 1468 | calc[*pnum]=0;
|
---|
| 1469 | if(i2){
|
---|
| 1470 | values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
|
---|
| 1471 | lstrcpy(values[*pnum],temporary);
|
---|
| 1472 | (*pnum)++;
|
---|
| 1473 | }
|
---|
| 1474 | else{
|
---|
| 1475 | if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
|
---|
| 1476 | SetError(1,NULL,cp);
|
---|
| 1477 | return 0;
|
---|
| 1478 | }
|
---|
| 1479 | if(Command[i]=='+'){
|
---|
| 1480 | i2=-1;
|
---|
| 1481 | continue;
|
---|
| 1482 | }
|
---|
| 1483 | }
|
---|
| 1484 |
|
---|
| 1485 | if(Command[i]=='-'&&i2==0){
|
---|
| 1486 | i3=CALC_MINUSMARK;
|
---|
| 1487 | }
|
---|
| 1488 | else{
|
---|
| 1489 | i3=GetCalcId(Command+i,&i4);
|
---|
| 1490 | i+=i4;
|
---|
| 1491 | if(!i3){
|
---|
| 1492 | SetError(1,NULL,cp);
|
---|
| 1493 | return 0;
|
---|
| 1494 | }
|
---|
| 1495 | }
|
---|
| 1496 |
|
---|
| 1497 | i3+=PareNum*100;
|
---|
| 1498 | if(sp){
|
---|
| 1499 | if(stack[sp-1]>i3-3&&
|
---|
| 1500 | (!(
|
---|
| 1501 | (stack[sp-1]%100==CALC_MINUSMARK || stack[sp-1]%100==CALC_NOT || stack[sp-1]%100==CALC_POWER)&&
|
---|
| 1502 | (i3%100==CALC_MINUSMARK || i3%100==CALC_NOT)
|
---|
| 1503 | ))
|
---|
| 1504 | ){
|
---|
| 1505 | for(;sp>0;){
|
---|
| 1506 | sp--;
|
---|
| 1507 | calc[*pnum]=stack[sp];
|
---|
| 1508 | values[*pnum]=0;
|
---|
| 1509 | (*pnum)++;
|
---|
| 1510 | if(!(stack[sp-1]>i3-3)) break;
|
---|
| 1511 | }
|
---|
| 1512 | }
|
---|
| 1513 | }
|
---|
| 1514 | stack[sp]=i3;
|
---|
| 1515 | sp++;
|
---|
| 1516 |
|
---|
| 1517 | i2=-1;
|
---|
| 1518 | continue;
|
---|
| 1519 | }
|
---|
| 1520 | temporary[i2]=Command[i];
|
---|
| 1521 | if(Command[i]=='\0'){
|
---|
| 1522 | calc[*pnum]=0;
|
---|
| 1523 |
|
---|
| 1524 | values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
|
---|
| 1525 | lstrcpy(values[*pnum],temporary);
|
---|
| 1526 | (*pnum)++;
|
---|
| 1527 |
|
---|
| 1528 | for(;sp>0;(*pnum)++){
|
---|
| 1529 | sp--;
|
---|
| 1530 | calc[*pnum]=stack[sp];
|
---|
| 1531 | values[*pnum]=0;
|
---|
| 1532 | }
|
---|
| 1533 | break;
|
---|
| 1534 | }
|
---|
| 1535 | }
|
---|
| 1536 |
|
---|
| 1537 | return 1;
|
---|
| 1538 | }
|
---|