source: dev/BasicCompiler_Common/calculation.cpp@ 5

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