source: dev/BasicCompiler_Common/calculation.cpp@ 9

Last change on this file since 9 was 7, checked in by dai_9181, 18 years ago

Constステートメントで定数変数を宣言できるように改良。

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