source: dev/BasicCompiler_Common/calculation.cpp@ 41

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

ByVal演算子を追加

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