source: dev/BasicCompiler_Common/calculation.cpp@ 17

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

LexicalAnalysisを廃止。

File size: 36.9 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 return 0;
631
632 if(!i3){
633 //読み込みに失敗
634 return -1;
635 }
636 goto JumpConst;
637 }
638 }
639
640
641 /////////
642 //定数
643 /////////
644 StrPtr[pnum]=0;
645 type[pnum] = CDBConst::obj.GetType(Parms);
646 if(type[pnum]){
647 if(IsRealNumberType(type[pnum])){
648 //実数型
649 nums[pnum] = CDBConst::obj.GetDoubleData(Parms);
650 }
651 else if(IsWholeNumberType(type[pnum])){
652 //整数
653 i64nums[pnum] = CDBConst::obj.GetWholeData(Parms);
654 }
655/* else if(type[pnum]==DEF_STRING){
656 //リテラル文字列
657
658 //バイト数
659 nums[pnum]=dbl;
660 i2=(int)dbl;
661
662 memcpy(Parms,temporary,(int)nums[pnum]);
663 goto StrLiteral;
664 }*/
665 else{
666 //エラー
667 if(enableerror) SetError(300,NULL,cp);
668 return -1;
669 }
670 goto JumpConst;
671 }
672
673
674 //////////////
675 // 型名の場合
676 //////////////
677
678 type[pnum]=GetTypeFixed(Parms,&before_index[pnum]);
679
680 if(type[pnum]==-1){
681 if(bDebuggingWatchList) return -1;
682 //エラー
683 if(enableerror) SetError(3,Parms,cp);
684 return 0;
685 }
686JumpConst:;
687 }
688 else{
689 //リテラル値
690 StrPtr[pnum]=0;
691 type[pnum]=GetLiteralValue(Parms,&i64data,BaseType);
692 if(IsRealNumberType(type[pnum])){
693 //実数型
694 memcpy(&nums[pnum],&i64data,sizeof(double));
695 }
696 else{
697 //整数型
698 i64nums[pnum]=i64data;
699 before_index[pnum]=GetLiteralIndex(i64data);
700 }
701 }
702 }
703
704 pnum++;
705 }
706 else{
707 if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
708 if(enableerror) SetError(1,NULL,cp);
709 return 0;
710 }
711 if(Command[i]=='+'){
712 i2=-1;
713 continue;
714 }
715 }
716
717 if(Command[i]=='\0'){
718 for(;sp>0;pnum++){
719 sp--;
720 calc[pnum]=(int)stack[sp];
721 }
722 break;
723 }
724
725 //論理演算子
726 if(Command[i]==1&&Command[i+1]==ESC_XOR) i3=CALC_XOR;
727 else if(Command[i]==1&&Command[i+1]==ESC_OR) i3=CALC_OR;
728 else if(Command[i]==1&&Command[i+1]==ESC_AND) i3=CALC_AND;
729 else if(Command[i]==1&&Command[i+1]==ESC_NOT) i3=CALC_NOT;
730
731 //ビット演算子(優先順位は算術演算子の後部)
732 else if(Command[i]=='<'&&Command[i+1]=='<'){
733 i3=CALC_SHL;
734 i++;
735 }
736 else if(Command[i]=='>'&&Command[i+1]=='>'){
737 i3=CALC_SHR;
738 i++;
739 }
740
741 //比較演算子
742 else if(Command[i]=='<'&&Command[i+1]=='='||
743 Command[i]=='='&&Command[i+1]=='<'){
744 i3=CALC_PE;
745 i++;
746 }
747 else if(Command[i]=='>'&&Command[i+1]=='='||
748 Command[i]=='='&&Command[i+1]=='>'){
749 i3=CALC_QE;
750 i++;
751 }
752 else if(Command[i]=='<'&&Command[i+1]=='>'||
753 Command[i]=='>'&&Command[i+1]=='<'){
754 i3=CALC_NOTEQUAL;
755 i++;
756 }
757 else if(Command[i]=='=') i3=CALC_EQUAL;
758 else if(Command[i]=='<') i3=CALC_P;
759 else if(Command[i]=='>') i3=CALC_Q;
760
761 //算術演算子
762 else if(Command[i]=='+'||Command[i]=='&') i3=CALC_ADDITION;
763 else if(Command[i]=='-'&&i2) i3=CALC_SUBTRACTION;
764 else if(Command[i]==1&&Command[i+1]==ESC_MOD) i3=CALC_MOD;
765 else if(Command[i]=='*') i3=CALC_PRODUCT;
766 else if(Command[i]=='/') i3=CALC_QUOTIENT;
767 else if(Command[i]=='\\') i3=CALC_INTQUOTIENT;
768 else if(Command[i]=='-'&&i2==0) i3=CALC_MINUSMARK;
769 else if(Command[i]=='^') i3=CALC_POWER;
770 else if(Command[i]==1&&Command[i+1]==ESC_AS) i3=CALC_AS;
771
772 i3+=PareNum*100;
773 if(sp){
774 if(stack[sp-1]>i3-3&&
775 (!(
776 (stack[sp-1]%100==CALC_MINUSMARK||stack[sp-1]%100==CALC_NOT)&&
777 (i3%100==CALC_MINUSMARK||i3%100==CALC_NOT)
778 ))
779 ){
780 for(;sp>0;){
781 sp--;
782 calc[pnum]=(int)stack[sp];
783 pnum++;
784 if(!(stack[sp-1]>i3-3)) break;
785 }
786 }
787 }
788 stack[sp]=i3;
789 sp++;
790
791 if(Command[i]==1) i++;
792 i2=-1;
793 continue;
794 }
795 Parms[i2]=Command[i];
796 }
797
798 int type_stack[255];
799 LONG_PTR index_stack[255];
800 int idCalc;
801 for(i=0,sp=0;i<pnum;i++){
802
803 //型チェック(正常でない場合はエラーにする)
804 TypeErrorCheck(stack,sp,calc[i]%100);
805
806 idCalc=calc[i]%100;
807
808 switch(idCalc){
809 //数値
810 case 0:
811 dbl_stack[sp]=nums[i];
812 i64stack[sp]=i64nums[i];
813 type_stack[sp]=type[i];
814 index_stack[sp]=before_index[i];
815
816 stack[sp]=(_int64)StrPtr[i];
817 sp++;
818 break;
819
820 //論理演算
821 case CALC_NOT:
822 if(IsRealNumberType(type_stack[sp-1])){
823 //実数演算
824 dbl_stack[sp-1]=(double)(~(long)dbl_stack[sp-1]);
825 }
826 else{
827 //整数演算
828 i64stack[sp-1]=~i64stack[sp-1];
829 }
830 break;
831
832 //比較演算
833 case CALC_PE:
834 case CALC_QE:
835 case CALC_P:
836 case CALC_Q:
837 case CALC_NOTEQUAL:
838 case CALC_EQUAL:
839
840 //論理演算
841 case CALC_XOR:
842 case CALC_OR:
843 case CALC_AND:
844
845 //シフト演算
846 case CALC_SHL:
847 case CALC_SHR:
848
849 //算術演算
850 case CALC_ADDITION:
851 case CALC_SUBTRACTION:
852 case CALC_MOD:
853 case CALC_PRODUCT:
854 case CALC_QUOTIENT:
855 case CALC_INTQUOTIENT:
856 case CALC_POWER:
857 StaticTwoTerm(idCalc,type_stack,index_stack,&sp,BaseType);
858 break;
859
860 case CALC_MINUSMARK:
861 if(IsRealNumberType(type_stack[sp-1])){
862 //実数演算
863 dbl_stack[sp-1]=-dbl_stack[sp-1];
864 }
865 else{
866 //整数演算
867 i64stack[sp-1]=-i64stack[sp-1];
868 }
869 break;
870 case CALC_AS:
871 if(IsWholeNumberType(type_stack[sp-2])){
872 if(IsRealNumberType(type_stack[sp-1])){
873 dbl_stack[sp-2]=(double)i64stack[sp-2];
874 }
875 }
876 if(IsRealNumberType(type_stack[sp-2])){
877 if(IsWholeNumberType(type_stack[sp-1])){
878 i64stack[sp-2]=(_int64)dbl_stack[sp-2];
879 }
880 }
881 type_stack[sp-2]=type_stack[sp-1];
882 index_stack[sp-2]=index_stack[sp-1];
883 sp--;
884 break;
885 }
886 }
887 if(stack[0]){
888 //文字列ポインタ
889 *pi64data=(_int64)stack[0];
890 *plpIndex=index_stack[0];
891 return type_stack[0];
892 }
893
894 if(IsRealNumberType(type_stack[0])){
895 //実数
896 memcpy(pi64data,&dbl_stack[0],sizeof(double));
897 return type_stack[0];
898 }
899
900 //整数
901 *pi64data=i64stack[0];
902
903 if(plpIndex){
904 *plpIndex=index_stack[0];
905 if(*plpIndex==-1){
906 if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){
907 //整数(符号有り/無し)
908 i64data=*pi64data;
909
910 *plpIndex=GetLiteralIndex(i64data);
911 }
912 }
913 }
914
915 return type_stack[0];
916}
917
918#pragma optimize("", off)
919DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType){
920 extern HANDLE hHeap;
921 extern int cp;
922 int i,i2,i3,sw1,sw2,bDbl;
923 double dbl;
924 char temporary[255];
925
926 if(value[0]=='&'){
927 _int64 i64temp;
928 lstrcpy(temporary,value);
929
930 if(temporary[1]=='o'||temporary[1]=='O'){
931 for(i=2;;i++){
932 i3=temporary[i]-0x30;
933 if(i3<0||7<i3) break;
934 temporary[i]=i3;
935 }
936 if(temporary[i]){
937 SetError(57,NULL,cp);
938 return DEF_BYTE;
939 }
940
941 i64temp=1;
942 *pi64=0;
943 for(i--;i>=2;i--){
944 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
945 i64temp*=8;
946 }
947 }
948 else if(temporary[1]=='h'||temporary[1]=='H'){
949 CharUpper(temporary+2);
950 for(i=2;;i++){
951 i3=temporary[i]-0x30;
952 if(i3<0||9<i3){
953 i3=temporary[i]-0x41+10;
954 if(i3<0xA||0xF<i3) break;
955 }
956 temporary[i]=i3;
957 }
958 if(temporary[i]){
959 SetError(58,NULL,cp);
960 return DEF_BYTE;
961 }
962
963 i64temp=1;
964 *pi64=0;
965 for(i--;i>=2;i--){
966 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
967 i64temp*=0x10;
968 }
969 }
970 else{
971 SetError(12,"&",cp);
972 return DEF_BYTE;
973 }
974
975 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return DEF_QWORD;
976
977 if(((unsigned _int64)*pi64)<=UCHAR_MAX){
978 //符号無し8ビット整数のリテラル値
979 return DEF_BYTE;
980 }
981 else if(((unsigned _int64)*pi64)<=USHRT_MAX){
982 //符号無し16ビット整数のリテラル値
983 return DEF_WORD;
984 }
985 else if(((unsigned _int64)*pi64)<=UINT_MAX){
986 //符号無し32ビット整数のリテラル値
987 return DEF_DWORD;
988 }
989 else{
990 //符号無し64ビット整数のリテラル値
991 return DEF_QWORD;
992 }
993 }
994 else if((value[0]>='0'&&value[0]<='9')||value[0]=='+'||value[0]=='-'||(value[0]=='.'&&(!IsVariableTopChar(value[1])))){
995 for(i=0;;i++){
996 if(value[i]!='-') break;
997 }
998 if(value[i]=='.'){
999 SlideString(value+i,1);
1000 value[i]='0';
1001 }
1002
1003 //エラーチェック
1004 bDbl=0;
1005 sw1=0;
1006 sw2=0;
1007 for(i2=i;;i2++){
1008 if(value[i2]=='\0') break;
1009 if(value[i2]=='.') bDbl=1;
1010 if(!((value[i2]>='0'&&value[i2]<='9')||value[i2]=='.')){
1011 if((value[i2]=='e'||value[i2]=='E')&&sw1==0){
1012 bDbl=1;
1013 sw1=1;
1014 }
1015 else if((value[i2]=='+'||value[i2]=='-')&&sw1==1&&sw2==0) sw2=1;
1016 else{
1017 extern BOOL bDebugRun;
1018 if(bDebugRun) return DEF_DOUBLE;
1019
1020 SetError(3,value,cp);
1021 return DEF_DOUBLE;
1022 }
1023 }
1024 }
1025
1026 if(bDbl){
1027 //実数のリテラル値
1028 if(i%2) dbl=-atof(value+i);
1029 else dbl=atof(value+i);
1030
1031 memcpy(pi64,&dbl,sizeof(double));
1032
1033 if(BaseType==DEF_SINGLE) return DEF_SINGLE;
1034
1035 return DEF_DOUBLE;
1036 }
1037 else{
1038 *pi64=_atoi64(value+i);
1039 if(i%2) *pi64=-(*pi64);
1040
1041 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return BaseType;
1042
1043 if(LONG_MIN<=*pi64&&*pi64<=LONG_MAX){
1044 //符号有り32ビット整数のリテラル値
1045 return DEF_LONG;
1046 }
1047 else if(*pi64<=UINT_MAX){
1048 //符号無し32ビット整数のリテラル値
1049 return DEF_DWORD;
1050 }
1051 else{
1052 //符号有り64ビット整数のリテラル値
1053 return DEF_INT64;
1054 }
1055 }
1056 }
1057
1058 extern BOOL bDebugRun;
1059 if(bDebugRun) return DEF_DOUBLE;
1060
1061 SetError(33,NULL,cp);
1062 return DEF_DOUBLE;
1063}
1064#pragma optimize("", on)
1065
1066BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer){
1067 extern HANDLE hHeap;
1068 int i2,i3,i4,num;
1069 char temporary[VN_SIZE];
1070 char *pParms[MAX_PARMS];
1071
1072 CONSTINFO *pci;
1073 pci=GetConstHash(name);
1074 if(!pci) return 0;
1075
1076 num=0;
1077 i2=0;
1078 while(1){
1079 i2=GetOneParameter(Parameter,i2,temporary);
1080
1081 pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
1082 lstrcpy(pParms[num],temporary);
1083
1084 num++;
1085 if(Parameter[i2]=='\0') break;
1086 }
1087 if(num!=pci->ParmNum){
1088 extern int cp;
1089 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
1090 SetError(10,name,cp);
1091 lstrcpy(pCalcBuffer,"0");
1092 return 1;
1093 }
1094
1095 i2=0;
1096 i4=0;
1097 while(1){
1098
1099 //数式内の項を取得
1100 for(i3=0;;i2++,i3++){
1101 if(!IsVariableChar(pci->StrValue[i2])){
1102 temporary[i3]=0;
1103 break;
1104 }
1105 temporary[i3]=pci->StrValue[i2];
1106 }
1107
1108 //パラメータと照合する
1109 for(i3=0;i3<pci->ParmNum;i3++){
1110 if(lstrcmp(pci->ppParm[i3],temporary)==0) break;
1111 }
1112
1113 if(i3==pci->ParmNum){
1114 //パラメータでないとき
1115 lstrcpy(pCalcBuffer+i4,temporary);
1116 i4+=lstrlen(temporary);
1117 }
1118 else{
1119 //パラメータのとき
1120 lstrcpy(pCalcBuffer+i4,pParms[i3]);
1121 i4+=lstrlen(pParms[i3]);
1122 }
1123
1124 //演算子をコピー
1125 for(;;i2++,i4++){
1126 if(pci->StrValue[i2]==1){
1127 pCalcBuffer[i4++]=pci->StrValue[i2++];
1128 pCalcBuffer[i4]=pci->StrValue[i2];
1129 continue;
1130 }
1131 if(IsVariableTopChar(pci->StrValue[i2])) break;
1132 pCalcBuffer[i4]=pci->StrValue[i2];
1133 if(pci->StrValue[i2]=='\0') break;
1134 }
1135
1136 if(pci->StrValue[i2]=='\0') break;
1137 }
1138
1139 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
1140
1141 return 1;
1142}
1143DWORD GetConstValue(char *name,double *pDbl,char *buffer,LONG_PTR *plpIndex){
1144 CONSTINFO *pci;
1145 pci=GetConstHash(name);
1146 if(pci){
1147 //定数が見つかったとき
1148
1149 if(pci->StrValue){
1150 //文字列定数
1151
1152 //バイト数
1153 *pDbl=pci->DblValue;
1154
1155 //データ
1156 memcpy(buffer,pci->StrValue,(int)pci->DblValue);
1157
1158 if(plpIndex) *plpIndex=pci->lpIndex;
1159
1160 return DEF_STRING;
1161 }
1162 else{
1163 if(pci->type==DEF_INT64){
1164 memcpy(pDbl,&pci->i64Value,sizeof(_int64));
1165 return DEF_INT64;
1166 }
1167
1168 if(plpIndex) *plpIndex=pci->lpIndex;
1169
1170 *pDbl=pci->DblValue;
1171 return pci->type;
1172 }
1173 }
1174
1175 if(plpIndex) *plpIndex=-1;
1176
1177 return -1;
1178}
1179BOOL IsStringObjectType(TYPEINFO *pTypeInfo){
1180 if(pTypeInfo->type==DEF_OBJECT){
1181 if(lstrcmp(pTypeInfo->u.pobj_Class->name,"String")==0){
1182 return 1;
1183 }
1184 }
1185 return 0;
1186}
1187BOOL IsStringSubsituation(CClass *pobj_c){
1188 //String受け入れ可能な "=" 演算子をオーバーロードしているかどうかを調べる
1189 BOOL bRet=0;
1190
1191 SUBINFO **ppsi;
1192 int num;
1193 ppsi=pobj_c->GetOperatorSubInfo(CALC_SUBSITUATION,num);
1194 if(num==0){
1195 bRet=0;
1196 goto finish;
1197 }
1198
1199 int i;
1200 for(i=0;i<num;i++){
1201 if(ppsi[i]->ParmNum==2){
1202 TYPEINFO TypeInfo={ppsi[i]->pParmInfo[1].type,ppsi[i]->pParmInfo[1].u.index};
1203 if(IsStringObjectType(&TypeInfo)){
1204 bRet=1;
1205 goto finish;
1206 }
1207 }
1208 }
1209
1210finish:
1211 HeapDefaultFree(ppsi);
1212 return bRet;
1213}
1214int IsStrCalculation(char *Command){
1215 int i,i2,i3,i4,type,PareNum;
1216 char temporary[VN_SIZE],temp2[8192];
1217
1218 for(i=0,i2=0;;i++){
1219 if(Command[i]=='('){
1220 for(i++,PareNum=1;;i++){
1221 if(Command[i]=='(') PareNum++;
1222 else if(Command[i]==')'){
1223 PareNum--;
1224 if(PareNum==0) break;
1225 }
1226 }
1227 continue;
1228 }
1229 if(Command[i]=='['){
1230 for(i++,PareNum=1;;i++){
1231 if(Command[i]=='[') PareNum++;
1232 else if(Command[i]==']'){
1233 PareNum--;
1234 if(PareNum==0) break;
1235 }
1236 }
1237 continue;
1238 }
1239 if(Command[i]=='\"'){
1240 i++;
1241 while(Command[i]!='\"') i++;
1242 continue;
1243 }
1244 if(Command[i]=='\0'){
1245 if(IsVariableTopChar(Command[i2])||
1246 Command[i2]=='.'&&IsVariableTopChar(Command[i2+1])){
1247
1248 if((Command[i2]=='e'||Command[i2]=='E')&&
1249 (Command[i2+1]=='x'||Command[i2+1]=='X')&&
1250 Command[i2+2]=='\"'){
1251 //拡張文字列
1252 return 1;
1253 }
1254
1255 for(i3=0;;i3++){
1256 if(Command[i2+i3]=='('){
1257 temporary[i3]=0;
1258 break;
1259 }
1260 temporary[i3]=Command[i2+i3];
1261 if(Command[i2+i3]=='\0') break;
1262 }
1263 if(Command[i2+i3]=='('){
1264 TYPEINFO TypeInfo;
1265
1266 //DLL関数の場合
1267 DECLAREINFO *pdi;
1268 pdi=GetDeclareHash(temporary);
1269 if(pdi){
1270 TypeInfo.type=pdi->ReturnType;
1271 TypeInfo.u.lpIndex=pdi->u.ReturnIndex;
1272 if(IsStringObjectType(&TypeInfo)) return 1;
1273 return 0;
1274 }
1275
1276 //ユーザー定義関数
1277 SUBINFO *psi;
1278 psi=GetSubHash(temporary);
1279 if(psi){
1280 TypeInfo.type=psi->ReturnType;
1281 TypeInfo.u.lpIndex=psi->u.ReturnIndex;
1282 if(IsStringObjectType(&TypeInfo)) return 1;
1283 return 0;
1284 }
1285
1286 //組み込み関数
1287 i4=GetFunctionFromName(temporary);
1288 if(i4){
1289 //組み込み関数は文字列を返さない
1290 return 0;
1291 }
1292
1293 //定数
1294 CONSTINFO *pci;
1295 pci=GetConstHash(temporary);
1296 if(pci){
1297
1298 if(pci->ParmNum){
1299 //マクロ関数の場合
1300 GetStringInPare_RemovePare(temporary,Command+i2+i3+1);
1301 GetConstCalcBuffer(pci->name,temporary,temp2);
1302 return IsStrCalculation(temp2);
1303 }
1304
1305 if(pci->type==DEF_STRING) return 1;
1306 else return 0;
1307 }
1308 }
1309
1310 //定数
1311 i3 = CDBConst::obj.GetType(Command+i2);
1312 if(i3==DEF_STRING) return 1; //文字列
1313 if(i3) return 0; //数値
1314
1315 //変数
1316 CClass *pobj_Class;
1317 type = GetVarType(Command+i2,(LONG_PTR *)&pobj_Class,1);
1318 if(type==-1 || type ==0){
1319 //エラー
1320 return -1;
1321 }
1322 if(type==DEF_OBJECT){
1323 if(lstrcmp(pobj_Class->name,"String")==0){
1324 return 1;
1325 }
1326 return 0;
1327 }
1328 }
1329 else if(Command[i2]=='\"') return 1;
1330 break;
1331 }
1332 if(IsNumCalcMark(Command,i)||IsStrCalcMark(Command[i])){
1333 if(IsStrCalcMark(Command[i])){
1334
1335 //&H、&O表記の場合を考慮
1336 if(i==0) continue;
1337 if(IsNumCalcMark(Command,i-1)) continue;
1338
1339 if(Command[i+1]=='(') break;
1340 i2=i+1;
1341 continue;
1342 }
1343 break;
1344 }
1345 }
1346 return 0;
1347}
1348
1349BYTE GetCalcId(const char *Command,int *pi){
1350 *pi=0;
1351
1352 if(Command[0]==1) *pi=1;
1353
1354 //論理演算子
1355 if(Command[0]==1&&Command[1]==ESC_XOR) return CALC_XOR;
1356 else if(Command[0]==1&&Command[1]==ESC_OR) return CALC_OR;
1357 else if(Command[0]==1&&Command[1]==ESC_AND) return CALC_AND;
1358 else if(Command[0]==1&&Command[1]==ESC_NOT) return CALC_NOT;
1359
1360 //ビット演算子(優先順位は算術演算子の後部)
1361 else if(Command[0]=='<'&&Command[1]=='<'){
1362 *pi=1;
1363 return CALC_SHL;
1364 }
1365 else if(Command[0]=='>'&&Command[1]=='>'){
1366 *pi=1;
1367 return CALC_SHR;
1368 }
1369
1370 //比較演算子
1371 else if(Command[0]=='<'&&Command[1]=='='||
1372 Command[0]=='='&&Command[1]=='<'){
1373 *pi=1;
1374 return CALC_PE;
1375 }
1376 else if(Command[0]=='>'&&Command[1]=='='||
1377 Command[0]=='='&&Command[1]=='>'){
1378 *pi=1;
1379 return CALC_QE;
1380 }
1381 else if(Command[0]=='<'&&Command[1]=='>'||
1382 Command[0]=='>'&&Command[1]=='<'){
1383 *pi=1;
1384 return CALC_NOTEQUAL;
1385 }
1386 else if(Command[0]=='=') return CALC_EQUAL;
1387 else if(Command[0]=='<') return CALC_P;
1388 else if(Command[0]=='>') return CALC_Q;
1389
1390 //算術演算子
1391 else if(Command[0]=='+') return CALC_ADDITION;
1392 else if(Command[0]=='-') return CALC_SUBTRACTION;
1393 else if(Command[0]=='&') return CALC_STRPLUS;
1394 else if(Command[0]==1&&Command[1]==ESC_MOD) return CALC_MOD;
1395 else if(Command[0]=='*') return CALC_PRODUCT;
1396 else if(Command[0]=='/') return CALC_QUOTIENT;
1397 else if(Command[0]=='\\') return CALC_INTQUOTIENT;
1398 else if(Command[0]=='^') return CALC_POWER;
1399 else if(Command[0]==1&&Command[1]==ESC_AS) return CALC_AS;
1400
1401 return 0;
1402}
1403BOOL GetNumOpeElements(const char *Command,int *pnum,
1404 char *values[255],long calc[255],long stack[255]){
1405 extern int cp;
1406 extern HANDLE hHeap;
1407 int i,i2,i3,i4,PareNum,sp;
1408 char temporary[1024];
1409
1410 for(i=0,i2=0,sp=0,*pnum=0,PareNum=0;;i++,i2++){
1411 if(Command[i]=='\"'){
1412 temporary[i2]=Command[i];
1413 for(i++,i2++;;i++,i2++){
1414 temporary[i2]=Command[i];
1415 if(Command[i]=='\"') break;
1416 }
1417 continue;
1418 }
1419 else if(Command[i]=='['){
1420 i3=GetStringInBracket(temporary+i2,Command+i);
1421 i+=i3-1;
1422 i2+=i3-1;
1423 continue;
1424 }
1425 else if(Command[i]=='('){
1426 if(i==0){
1427 PareNum++;
1428 i2=-1;
1429 continue;
1430 }
1431 else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
1432 PareNum++;
1433 i2=-1;
1434 continue;
1435 }
1436 else{
1437 //配列変数の場合を考慮
1438 i3=GetStringInPare(temporary+i2,Command+i);
1439 i+=i3-1;
1440 i2+=i3-1;
1441 continue;
1442 }
1443 }
1444 else if(Command[i]==')'){
1445 PareNum--;
1446 i2--;
1447 continue;
1448 }
1449 else if(IsNumCalcMark(Command,i)||(Command[i]=='&'&&i2!=0)){
1450 if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
1451 if(IsExponent(Command,i)){
1452 temporary[i2]=Command[i];
1453 continue;
1454 }
1455 }
1456 temporary[i2]=0;
1457
1458 if((stack[sp-1]%100)==CALC_AS&&Command[i]=='*'){
1459 for(i3=0;i3<i2;i3++){
1460 if(temporary[i2]!='*') break;
1461 }
1462 if(i3==i2){
1463 //"*"をポインタ指定文字として認識する
1464 temporary[i2]=Command[i];
1465 continue;
1466 }
1467 }
1468
1469 calc[*pnum]=0;
1470 if(i2){
1471 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1472 lstrcpy(values[*pnum],temporary);
1473 (*pnum)++;
1474 }
1475 else{
1476 if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
1477 SetError(1,NULL,cp);
1478 return 0;
1479 }
1480 if(Command[i]=='+'){
1481 i2=-1;
1482 continue;
1483 }
1484 }
1485
1486 if(Command[i]=='-'&&i2==0){
1487 i3=CALC_MINUSMARK;
1488 }
1489 else{
1490 i3=GetCalcId(Command+i,&i4);
1491 i+=i4;
1492 if(!i3){
1493 SetError(1,NULL,cp);
1494 return 0;
1495 }
1496 }
1497
1498 i3+=PareNum*100;
1499 if(sp){
1500 if(stack[sp-1]>i3-3&&
1501 (!(
1502 (stack[sp-1]%100==CALC_MINUSMARK || stack[sp-1]%100==CALC_NOT || stack[sp-1]%100==CALC_POWER)&&
1503 (i3%100==CALC_MINUSMARK || i3%100==CALC_NOT)
1504 ))
1505 ){
1506 for(;sp>0;){
1507 sp--;
1508 calc[*pnum]=stack[sp];
1509 values[*pnum]=0;
1510 (*pnum)++;
1511 if(!(stack[sp-1]>i3-3)) break;
1512 }
1513 }
1514 }
1515 stack[sp]=i3;
1516 sp++;
1517
1518 i2=-1;
1519 continue;
1520 }
1521 temporary[i2]=Command[i];
1522 if(Command[i]=='\0'){
1523 calc[*pnum]=0;
1524
1525 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1526 lstrcpy(values[*pnum],temporary);
1527 (*pnum)++;
1528
1529 for(;sp>0;(*pnum)++){
1530 sp--;
1531 calc[*pnum]=stack[sp];
1532 values[*pnum]=0;
1533 }
1534 break;
1535 }
1536 }
1537
1538 return 1;
1539}
Note: See TracBrowser for help on using the repository browser.