source: dev/BasicCompiler_Common/calculation.cpp@ 36

Last change on this file since 36 was 36, checked in by dai_9181, 17 years ago

Boolean型に対応。

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