source: dev/BasicCompiler_Common/calculation.cpp@ 78

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

CTypeDef → TypeDef
Houseクラスを追加。
オーバーロードレベルの種類を追加(レベル1に挿入)

File size: 37.2 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
6#include "../BasicCompiler32/opcode.h"
7#endif
8
9double dbl_stack[255];
10_int64 i64stack[255];
11
12bool IsNumberTopChar(const char *buffer){
13 int c = buffer[0];
14 if('0' <= c && c <= '9') return true;
15 if(c == '&' && (buffer[1] == 'h' || buffer[1] == 'H' || buffer[1] == 'o' || buffer[1] == 'O')) return true;
16
17 return false;
18}
19bool IsNumberChar(const char c){
20 if('0' <= c && c <= '9') return true;
21 if('a' <= c && c <= 'f') return true;
22 if('A' <= c && c <= 'F') return true;
23 if(c=='.' || c=='e'||c=='E') return true;
24
25 return false;
26}
27BOOL IsJudgMark(const char *Command,int p){
28 if(Command[p]==1){
29 if(Command[p+1]==ESC_AND) return 1;
30 if(Command[p+1]==ESC_OR) return 1;
31 if(Command[p+1]==ESC_XOR) return 1;
32 if(Command[p+1]==ESC_NOT) return 1;
33 }
34 return 0;
35}
36BOOL IsNumCalcMark(const char *Command,int p){
37 if(Command[p]=='^'||Command[p]=='*'||Command[p]=='/'||Command[p]=='\\'||
38 (Command[p]==1&&Command[p+1]==ESC_MOD)||Command[p]=='+'||Command[p]=='-'||
39 Command[p]=='='||Command[p]=='<'||Command[p]=='>'||
40 IsJudgMark(Command,p)||
41 (Command[p]==1&&Command[p+1]==ESC_AS)||
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_SBYTE;
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_SBYTE&&(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
392bool StaticCalculation(bool enableerror, const char *Command,int BaseType,_int64 *pi64data,Type &resultType,BOOL bDebuggingWatchList, bool *pIsMemoryAccessError){
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 if( pIsMemoryAccessError ) *pIsMemoryAccessError = false;
408
409 *pi64data=0;
410 if(Command[0]=='\0') return false;
411
412 for(i=0,i2=0,sp=0,pnum=0,PareNum=0;;i++,i2++){
413 if(Command[i]=='\"'){
414 Parms[i2]=Command[i];
415 for(i++,i2++;;i++,i2++){
416 Parms[i2]=Command[i];
417 if(Command[i]=='\"') break;
418 }
419 continue;
420 }
421 else if(Command[i]=='['){
422 i3=GetStringInBracket(Parms+i2,Command+i);
423 i+=i3-1;
424 i2+=i3-1;
425 continue;
426 }
427 else if(Command[i]=='('){
428 if(i==0){
429 PareNum++;
430 i2=-1;
431 continue;
432 }
433 else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
434 PareNum++;
435 i2=-1;
436 continue;
437 }
438 else{
439 //配列変数の場合を考慮
440 i3=GetStringInPare(Parms+i2,Command+i);
441 i+=i3-1;
442 i2+=i3-1;
443 continue;
444 }
445 }
446 else if(Command[i]==')'){
447 PareNum--;
448 i2--;
449 continue;
450 }
451 else if(IsNumCalcMark(Command,i)||Command[i]=='\0'){
452 if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
453 if(IsExponent(Command,i)){
454 Parms[i2]=Command[i];
455 continue;
456 }
457 }
458 Parms[i2]=0;
459
460 if(stack[sp-1]==CALC_AS&&Command[i]=='*'){
461 for(i3=0;i3<i2;i3++){
462 if(Parms[i2]!='*') break;
463 }
464 if(i3==i2){
465 //"*"をポインタ指定文字として認識する
466 Parms[i2]=Command[i];
467 continue;
468 }
469 }
470
471 calc[pnum]=0;
472 if(i2){
473 before_index[pnum]=-1;
474
475 i3=GetCallProcName(Parms,temporary);
476 if(Parms[i3]=='('){
477 lstrcpy(temp2,Parms+i3+1);
478 temp2[lstrlen(temp2)-1]=0;
479
480 if(lstrcmpi(temporary,"SizeOf")==0){
481 //SizeOf関数
482
483 type[pnum]=DEF_LONG;
484
485 LONG_PTR lpIndex;
486 i3=GetTypeFixed(temp2,&lpIndex);
487 if(i3==-1){
488 extern int cp;
489 if(enableerror) SetError(3,temp2,cp);
490 return false;
491 }
492 i64nums[pnum]=GetTypeSize(i3,lpIndex);
493 StrPtr[pnum]=0;
494 }
495 else{
496 //定数関数
497
498 if(!GetConstCalcBuffer(temporary,temp2,Parms)){
499 if(enableerror) SetError(3,temporary,cp);
500 return false;
501 }
502
503 Type tempType;
504 StaticCalculation(enableerror, Parms,BaseType,&i64data,tempType);
505 type[pnum] = tempType.GetBasicType();
506 before_index[pnum] = tempType.GetIndex();
507 if(tempType.IsReal()){
508 //実数型
509 memcpy(&nums[pnum],&i64data,sizeof(double));
510 }
511 else{
512 //整数型
513 i64nums[pnum]=i64data;
514 }
515
516 StrPtr[pnum]=0;
517 }
518 }
519 else{
520 if(Parms[0]=='\"'){
521 //文字列の場合(比較演算子を考慮)
522 RemoveStringQuotes(Parms);
523 i2=lstrlen(Parms);
524
525 nums[pnum]=i2;
526 StrPtr[pnum]=(char *)HeapAlloc(hHeap,0,i2+1);
527 memcpy(StrPtr[pnum],Parms,i2);
528 StrPtr[pnum][i2]=0;
529
530 type[pnum]=typeOfPtrChar;
531 before_index[pnum]=LITERAL_STRING;
532 }
533 else if((Parms[0]=='e'||Parms[0]=='E')&&
534 (Parms[1]=='x'||Parms[1]=='X')&&
535 Parms[2]=='\"'){
536 //拡張文字列
537 RemoveStringQuotes(Parms+2);
538 i2=FormatString_EscapeSequence(Parms+2);
539 nums[pnum]=i2;
540 StrPtr[pnum]=(char *)HeapAlloc(hHeap,0,(int)i2+1);
541 memcpy(StrPtr[pnum],Parms+2,i2);
542 StrPtr[pnum][i2]=0;
543
544 type[pnum]=typeOfPtrChar;
545 before_index[pnum]=LITERAL_STRING;
546 }
547 else if(IsVariableTopChar(Parms[0])||Parms[0]=='*'||(Parms[0]=='.'&&IsVariableTopChar(Parms[1]))){
548 if(bDebuggingWatchList){
549 //////////////////////////
550 // 変数(デバッグ時のみ)
551 //////////////////////////
552
553 RELATIVE_VAR RelativeVar;
554 int ss[MAX_ARRAYDIM];
555 void *offset;
556 DWORD dwData;
557 SIZE_T accessBytes;
558 float flt;
559
560 extern HANDLE hDebugProcess;
561
562 Type tempType;
563 i3=Debugging_GetVarOffset(Parms,&RelativeVar,tempType,ss);
564 if(i3==0){
565 //式エラー
566 return false;
567 }
568 if(i3==-1){
569 //メモリにアクセスできないとき
570 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true;
571 return false;
572 }
573
574 if(i3){
575 StrPtr[pnum]=0;
576 offset=(void *)Debugging_GetVarPtr(&RelativeVar);
577
578 type[pnum]=tempType.GetBasicType();
579
580 if(tempType.IsDouble()){
581 i3=ReadProcessMemory(hDebugProcess,offset,&nums[pnum],sizeof(double),&accessBytes);
582 }
583 else if(tempType.IsSingle()){
584 if(i3=ReadProcessMemory(hDebugProcess,offset,&flt,sizeof(float),&accessBytes)){
585 nums[pnum]=(double)flt;
586 }
587 }
588 else if(tempType.IsPointer()){
589 LONG_PTR lpData;
590 if(i3=ReadProcessMemory(hDebugProcess,offset,&lpData,sizeof(LONG_PTR),&accessBytes)){
591 i64nums[pnum]=(_int64)lpData;
592 }
593 }
594 else if(tempType.Is64()){
595 type[pnum]=DEF_INT64;
596
597 i3=ReadProcessMemory(hDebugProcess,offset,&i64nums[pnum],sizeof(_int64),&accessBytes);
598 }
599
600 else if(tempType.IsLong()){
601 long lData;
602 if(i3=ReadProcessMemory(hDebugProcess,offset,&lData,sizeof(long),&accessBytes)){
603 i64nums[pnum]=(_int64)lData;
604 }
605 }
606 else if(tempType.IsDWord()){
607 if(i3=ReadProcessMemory(hDebugProcess,offset,&dwData,sizeof(DWORD),&accessBytes)){
608 i64nums[pnum]=(_int64)dwData;
609 }
610 }
611 else if(tempType.IsInteger()){
612 short shortData;
613 if(i3=ReadProcessMemory(hDebugProcess,offset,&shortData,sizeof(short),&accessBytes)){
614 i64nums[pnum]=(_int64)shortData;
615 }
616 }
617 else if(tempType.IsWord()){
618 WORD wData;
619 if(i3=ReadProcessMemory(hDebugProcess,offset,&wData,sizeof(WORD),&accessBytes)){
620 i64nums[pnum]=(_int64)wData;
621 }
622 }
623 else if(tempType.IsSByte()){
624 char charData;
625 if(i3=ReadProcessMemory(hDebugProcess,offset,&charData,sizeof(char),&accessBytes)){
626 i64nums[pnum]=(_int64)charData;
627 }
628 }
629 else if(tempType.IsByte()){
630 BYTE byteData;
631 if(i3=ReadProcessMemory(hDebugProcess,offset,&byteData,sizeof(BYTE),&accessBytes)){
632 i64nums[pnum]=(_int64)byteData;
633 }
634 }
635 else if(tempType.IsBoolean()){
636 BYTE byteData;
637 if(i3=ReadProcessMemory(hDebugProcess,offset,&byteData,sizeof(BYTE),&accessBytes)){
638 i64nums[pnum]=(_int64)byteData;
639 }
640 }
641 else return false;
642
643 if(!i3){
644 //読み込みに失敗
645 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true;
646 return false;
647 }
648 goto JumpConst;
649 }
650 }
651
652
653 /////////
654 //定数
655 /////////
656 StrPtr[pnum]=0;
657 type[pnum] = CDBConst::obj.GetType(Parms);
658 if(type[pnum]){
659 if(IsRealNumberType(type[pnum])){
660 //実数型
661 nums[pnum] = CDBConst::obj.GetDoubleData(Parms);
662 }
663 else if(IsWholeNumberType(type[pnum])){
664 //整数
665 i64nums[pnum] = CDBConst::obj.GetWholeData(Parms);
666 }
667/* else if(type[pnum]==DEF_STRING){
668 //リテラル文字列
669
670 //バイト数
671 nums[pnum]=dbl;
672 i2=(int)dbl;
673
674 memcpy(Parms,temporary,(int)nums[pnum]);
675 goto StrLiteral;
676 }*/
677 else{
678 //エラー
679 if(enableerror) SetError(300,NULL,cp);
680 return 0;
681 }
682 goto JumpConst;
683 }
684
685
686 //////////////
687 // 型名の場合
688 //////////////
689
690 type[pnum]=GetTypeFixed(Parms,&before_index[pnum]);
691
692 if(type[pnum]==-1){
693 if(bDebuggingWatchList){
694 if( pIsMemoryAccessError ) *pIsMemoryAccessError = true;
695 return false;
696 }
697 //エラー
698 if(enableerror) SetError(3,Parms,cp);
699 return false;
700 }
701JumpConst:;
702 }
703 else{
704 //リテラル値
705 StrPtr[pnum]=0;
706 type[pnum]=GetLiteralValue(Parms,&i64data,BaseType);
707 if(IsRealNumberType(type[pnum])){
708 //実数型
709 memcpy(&nums[pnum],&i64data,sizeof(double));
710 }
711 else{
712 //整数型
713 i64nums[pnum]=i64data;
714 before_index[pnum]=GetLiteralIndex(i64data);
715 }
716 }
717 }
718
719 pnum++;
720 }
721 else{
722 if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
723 if(enableerror) SetError(1,NULL,cp);
724 return false;
725 }
726 if(Command[i]=='+'){
727 i2=-1;
728 continue;
729 }
730 }
731
732 if(Command[i]=='\0'){
733 for(;sp>0;pnum++){
734 sp--;
735 calc[pnum]=(int)stack[sp];
736 }
737 break;
738 }
739
740 //論理演算子
741 if(Command[i]==1&&Command[i+1]==ESC_XOR) i3=CALC_XOR;
742 else if(Command[i]==1&&Command[i+1]==ESC_OR) i3=CALC_OR;
743 else if(Command[i]==1&&Command[i+1]==ESC_AND) i3=CALC_AND;
744 else if(Command[i]==1&&Command[i+1]==ESC_NOT) i3=CALC_NOT;
745
746 //ビット演算子(優先順位は算術演算子の後部)
747 else if(Command[i]=='<'&&Command[i+1]=='<'){
748 i3=CALC_SHL;
749 i++;
750 }
751 else if(Command[i]=='>'&&Command[i+1]=='>'){
752 i3=CALC_SHR;
753 i++;
754 }
755
756 //比較演算子
757 else if(Command[i]=='<'&&Command[i+1]=='='||
758 Command[i]=='='&&Command[i+1]=='<'){
759 i3=CALC_PE;
760 i++;
761 }
762 else if(Command[i]=='>'&&Command[i+1]=='='||
763 Command[i]=='='&&Command[i+1]=='>'){
764 i3=CALC_QE;
765 i++;
766 }
767 else if(Command[i]=='<'&&Command[i+1]=='>'||
768 Command[i]=='>'&&Command[i+1]=='<'){
769 i3=CALC_NOTEQUAL;
770 i++;
771 }
772 else if(Command[i]=='=') i3=CALC_EQUAL;
773 else if(Command[i]=='<') i3=CALC_P;
774 else if(Command[i]=='>') i3=CALC_Q;
775
776 //算術演算子
777 else if(Command[i]=='+'||Command[i]=='&') i3=CALC_ADDITION;
778 else if(Command[i]=='-'&&i2) i3=CALC_SUBTRACTION;
779 else if(Command[i]==1&&Command[i+1]==ESC_MOD) i3=CALC_MOD;
780 else if(Command[i]=='*') i3=CALC_PRODUCT;
781 else if(Command[i]=='/') i3=CALC_QUOTIENT;
782 else if(Command[i]=='\\') i3=CALC_INTQUOTIENT;
783 else if(Command[i]=='-'&&i2==0) i3=CALC_MINUSMARK;
784 else if(Command[i]=='^') i3=CALC_POWER;
785 else if(Command[i]==1&&Command[i+1]==ESC_AS) i3=CALC_AS;
786 else if(Command[i]==1&&Command[i+1]==ESC_BYVAL) i3=CALC_BYVAL;
787
788 i3+=PareNum*100;
789 if(sp){
790 if(stack[sp-1]>i3-3&&
791 (!(
792 (stack[sp-1]%100==CALC_MINUSMARK||stack[sp-1]%100==CALC_NOT)&&
793 (i3%100==CALC_MINUSMARK||i3%100==CALC_NOT)
794 ))
795 ){
796 for(;sp>0;){
797 sp--;
798 calc[pnum]=(int)stack[sp];
799 pnum++;
800 if(!(stack[sp-1]>i3-3)) break;
801 }
802 }
803 }
804 stack[sp]=i3;
805 sp++;
806
807 if(Command[i]==1) i++;
808 i2=-1;
809 continue;
810 }
811 Parms[i2]=Command[i];
812 }
813
814 int type_stack[255];
815 LONG_PTR index_stack[255];
816 int idCalc;
817 for(i=0,sp=0;i<pnum;i++){
818
819 //型チェック(正常でない場合はエラーにする)
820 TypeErrorCheck(stack,sp,calc[i]%100);
821
822 idCalc=calc[i]%100;
823
824 switch(idCalc){
825 //数値
826 case 0:
827 dbl_stack[sp]=nums[i];
828 i64stack[sp]=i64nums[i];
829 type_stack[sp]=type[i];
830 index_stack[sp]=before_index[i];
831
832 stack[sp]=(_int64)StrPtr[i];
833 sp++;
834 break;
835
836 //論理演算
837 case CALC_NOT:
838 if(IsRealNumberType(type_stack[sp-1])){
839 //実数演算
840 dbl_stack[sp-1]=(double)(~(long)dbl_stack[sp-1]);
841 }
842 else{
843 //整数演算
844 i64stack[sp-1]=~i64stack[sp-1];
845 }
846 break;
847
848 //比較演算
849 case CALC_PE:
850 case CALC_QE:
851 case CALC_P:
852 case CALC_Q:
853 case CALC_NOTEQUAL:
854 case CALC_EQUAL:
855
856 //論理演算
857 case CALC_XOR:
858 case CALC_OR:
859 case CALC_AND:
860
861 //シフト演算
862 case CALC_SHL:
863 case CALC_SHR:
864
865 //算術演算
866 case CALC_ADDITION:
867 case CALC_SUBTRACTION:
868 case CALC_MOD:
869 case CALC_PRODUCT:
870 case CALC_QUOTIENT:
871 case CALC_INTQUOTIENT:
872 case CALC_POWER:
873 StaticTwoTerm(idCalc,type_stack,index_stack,&sp,BaseType);
874 break;
875
876 case CALC_MINUSMARK:
877 if(IsRealNumberType(type_stack[sp-1])){
878 //実数演算
879 dbl_stack[sp-1]=-dbl_stack[sp-1];
880 }
881 else{
882 //整数演算
883 i64stack[sp-1]=-i64stack[sp-1];
884 }
885 break;
886 case CALC_AS:
887 if(IsWholeNumberType(type_stack[sp-2])){
888 if(IsRealNumberType(type_stack[sp-1])){
889 dbl_stack[sp-2]=(double)i64stack[sp-2];
890 }
891 }
892 if(IsRealNumberType(type_stack[sp-2])){
893 if(IsWholeNumberType(type_stack[sp-1])){
894 i64stack[sp-2]=(_int64)dbl_stack[sp-2];
895 }
896 }
897 type_stack[sp-2]=type_stack[sp-1];
898 index_stack[sp-2]=index_stack[sp-1];
899 sp--;
900 break;
901 case CALC_BYVAL:
902 //エラー
903 break;
904 }
905 }
906 if(stack[0]){
907 //文字列ポインタ
908 *pi64data=(_int64)stack[0];
909 resultType.SetType( type_stack[0], index_stack[0] );
910 return true;
911 }
912
913 if(IsRealNumberType(type_stack[0])){
914 //実数
915 memcpy(pi64data,&dbl_stack[0],sizeof(double));
916 resultType.SetType( type_stack[0], index_stack[0] );
917 return true;
918 }
919
920 //整数
921 *pi64data=i64stack[0];
922
923 if(index_stack[0]==-1){
924 if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){
925 //整数(符号有り/無し)
926 i64data=*pi64data;
927
928 resultType.SetIndex( GetLiteralIndex(i64data) );
929 }
930 }
931 else{
932 resultType.SetIndex( index_stack[0] );
933 }
934
935 resultType.SetBasicType( type_stack[0] );
936 return true;
937}
938
939#pragma optimize("", off)
940DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType){
941 extern HANDLE hHeap;
942 extern int cp;
943 int i,i2,i3,sw1,sw2,bDbl;
944 double dbl;
945 char temporary[255];
946
947 if(value[0]=='&'){
948 _int64 i64temp;
949 lstrcpy(temporary,value);
950
951 if(temporary[1]=='o'||temporary[1]=='O'){
952 for(i=2;;i++){
953 i3=temporary[i]-0x30;
954 if(i3<0||7<i3) break;
955 temporary[i]=i3;
956 }
957 if(temporary[i]){
958 SetError(57,NULL,cp);
959 return DEF_BYTE;
960 }
961
962 i64temp=1;
963 *pi64=0;
964 for(i--;i>=2;i--){
965 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
966 i64temp*=8;
967 }
968 }
969 else if(temporary[1]=='h'||temporary[1]=='H'){
970 CharUpper(temporary+2);
971 for(i=2;;i++){
972 i3=temporary[i]-0x30;
973 if(i3<0||9<i3){
974 i3=temporary[i]-0x41+10;
975 if(i3<0xA||0xF<i3) break;
976 }
977 temporary[i]=i3;
978 }
979 if(temporary[i]){
980 SetError(58,NULL,cp);
981 return DEF_BYTE;
982 }
983
984 i64temp=1;
985 *pi64=0;
986 for(i--;i>=2;i--){
987 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
988 i64temp*=0x10;
989 }
990 }
991 else{
992 SetError(12,"&",cp);
993 return DEF_BYTE;
994 }
995
996 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return DEF_QWORD;
997
998 if(((unsigned _int64)*pi64)<=UCHAR_MAX){
999 //符号無し8ビット整数のリテラル値
1000 return DEF_BYTE;
1001 }
1002 else if(((unsigned _int64)*pi64)<=USHRT_MAX){
1003 //符号無し16ビット整数のリテラル値
1004 return DEF_WORD;
1005 }
1006 else if(((unsigned _int64)*pi64)<=UINT_MAX){
1007 //符号無し32ビット整数のリテラル値
1008 return DEF_DWORD;
1009 }
1010 else{
1011 //符号無し64ビット整数のリテラル値
1012 return DEF_QWORD;
1013 }
1014 }
1015 else if((value[0]>='0'&&value[0]<='9')||value[0]=='+'||value[0]=='-'||(value[0]=='.'&&(!IsVariableTopChar(value[1])))){
1016 for(i=0;;i++){
1017 if(value[i]!='-') break;
1018 }
1019 if(value[i]=='.'){
1020 SlideString(value+i,1);
1021 value[i]='0';
1022 }
1023
1024 //エラーチェック
1025 bDbl=0;
1026 sw1=0;
1027 sw2=0;
1028 for(i2=i;;i2++){
1029 if(value[i2]=='\0') break;
1030 if(value[i2]=='.') bDbl=1;
1031 if(!((value[i2]>='0'&&value[i2]<='9')||value[i2]=='.')){
1032 if((value[i2]=='e'||value[i2]=='E')&&sw1==0){
1033 bDbl=1;
1034 sw1=1;
1035 }
1036 else if((value[i2]=='+'||value[i2]=='-')&&sw1==1&&sw2==0) sw2=1;
1037 else{
1038 extern BOOL bDebugRun;
1039 if(bDebugRun) return DEF_DOUBLE;
1040
1041 SetError(3,value,cp);
1042 return DEF_DOUBLE;
1043 }
1044 }
1045 }
1046
1047 if(bDbl){
1048 //実数のリテラル値
1049 if(i%2) dbl=-atof(value+i);
1050 else dbl=atof(value+i);
1051
1052 memcpy(pi64,&dbl,sizeof(double));
1053
1054 if(BaseType==DEF_SINGLE) return DEF_SINGLE;
1055
1056 return DEF_DOUBLE;
1057 }
1058 else{
1059 *pi64=_atoi64(value+i);
1060 if(i%2) *pi64=-(*pi64);
1061
1062 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return BaseType;
1063
1064 if(LONG_MIN<=*pi64&&*pi64<=LONG_MAX){
1065 //符号有り32ビット整数のリテラル値
1066 return DEF_LONG;
1067 }
1068 else if(*pi64<=UINT_MAX){
1069 //符号無し32ビット整数のリテラル値
1070 return DEF_DWORD;
1071 }
1072 else{
1073 //符号有り64ビット整数のリテラル値
1074 return DEF_INT64;
1075 }
1076 }
1077 }
1078
1079 extern BOOL bDebugRun;
1080 if(bDebugRun) return DEF_DOUBLE;
1081
1082 SetError(33,NULL,cp);
1083 return DEF_DOUBLE;
1084}
1085#pragma optimize("", on)
1086
1087BOOL GetConstCalcBuffer(char *name,char *Parameter,char *pCalcBuffer){
1088 extern HANDLE hHeap;
1089 int i2,i3,i4,num;
1090 char temporary[VN_SIZE];
1091 char *pParms[MAX_PARMS];
1092
1093 CONSTINFO *pci;
1094 pci=GetConstHash(name);
1095 if(!pci) return 0;
1096
1097 num=0;
1098 i2=0;
1099 while(1){
1100 i2=GetOneParameter(Parameter,i2,temporary);
1101
1102 pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
1103 lstrcpy(pParms[num],temporary);
1104
1105 num++;
1106 if(Parameter[i2]=='\0') break;
1107 }
1108 if(num!=pci->ParmNum){
1109 extern int cp;
1110 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
1111 SetError(10,name,cp);
1112 lstrcpy(pCalcBuffer,"0");
1113 return 1;
1114 }
1115
1116 i2=0;
1117 i4=0;
1118 while(1){
1119
1120 //数式内の項を取得
1121 for(i3=0;;i2++,i3++){
1122 if(!IsVariableChar(pci->StrValue[i2])){
1123 temporary[i3]=0;
1124 break;
1125 }
1126 temporary[i3]=pci->StrValue[i2];
1127 }
1128
1129 //パラメータと照合する
1130 for(i3=0;i3<pci->ParmNum;i3++){
1131 if(lstrcmp(pci->ppParm[i3],temporary)==0) break;
1132 }
1133
1134 if(i3==pci->ParmNum){
1135 //パラメータでないとき
1136 lstrcpy(pCalcBuffer+i4,temporary);
1137 i4+=lstrlen(temporary);
1138 }
1139 else{
1140 //パラメータのとき
1141 lstrcpy(pCalcBuffer+i4,pParms[i3]);
1142 i4+=lstrlen(pParms[i3]);
1143 }
1144
1145 //演算子をコピー
1146 for(;;i2++,i4++){
1147 if(pci->StrValue[i2]==1){
1148 pCalcBuffer[i4++]=pci->StrValue[i2++];
1149 pCalcBuffer[i4]=pci->StrValue[i2];
1150 continue;
1151 }
1152 if(IsVariableTopChar(pci->StrValue[i2])) break;
1153 pCalcBuffer[i4]=pci->StrValue[i2];
1154 if(pci->StrValue[i2]=='\0') break;
1155 }
1156
1157 if(pci->StrValue[i2]=='\0') break;
1158 }
1159
1160 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);
1161
1162 return 1;
1163}
1164DWORD GetConstValue(char *name,double *pDbl,char *buffer,LONG_PTR *plpIndex){
1165 CONSTINFO *pci;
1166 pci=GetConstHash(name);
1167 if(pci){
1168 //定数が見つかったとき
1169
1170 if(pci->StrValue){
1171 //文字列定数
1172
1173 //バイト数
1174 *pDbl=pci->DblValue;
1175
1176 //データ
1177 memcpy(buffer,pci->StrValue,(int)pci->DblValue);
1178
1179 if(plpIndex) *plpIndex=pci->lpIndex;
1180
1181 return DEF_STRING;
1182 }
1183 else{
1184 if(pci->type==DEF_INT64){
1185 memcpy(pDbl,&pci->i64Value,sizeof(_int64));
1186 return DEF_INT64;
1187 }
1188
1189 if(plpIndex) *plpIndex=pci->lpIndex;
1190
1191 *pDbl=pci->DblValue;
1192 return pci->type;
1193 }
1194 }
1195
1196 if(plpIndex) *plpIndex=-1;
1197
1198 return -1;
1199}
1200int IsStrCalculation(char *Command){
1201 int i,i2,i3,i4,PareNum;
1202 char temporary[VN_SIZE],temp2[8192];
1203
1204 for(i=0,i2=0;;i++){
1205 if(Command[i]=='('){
1206 for(i++,PareNum=1;;i++){
1207 if(Command[i]=='(') PareNum++;
1208 else if(Command[i]==')'){
1209 PareNum--;
1210 if(PareNum==0) break;
1211 }
1212 }
1213 continue;
1214 }
1215 if(Command[i]=='['){
1216 for(i++,PareNum=1;;i++){
1217 if(Command[i]=='[') PareNum++;
1218 else if(Command[i]==']'){
1219 PareNum--;
1220 if(PareNum==0) break;
1221 }
1222 }
1223 continue;
1224 }
1225 if(Command[i]=='\"'){
1226 i++;
1227 while(Command[i]!='\"') i++;
1228 continue;
1229 }
1230 if(Command[i]=='\0'){
1231 if(IsVariableTopChar(Command[i2])||
1232 Command[i2]=='.'&&IsVariableTopChar(Command[i2+1])){
1233
1234 if((Command[i2]=='e'||Command[i2]=='E')&&
1235 (Command[i2+1]=='x'||Command[i2+1]=='X')&&
1236 Command[i2+2]=='\"'){
1237 //拡張文字列
1238 return 1;
1239 }
1240
1241 for(i3=0;;i3++){
1242 if(Command[i2+i3]=='('){
1243 temporary[i3]=0;
1244 break;
1245 }
1246 temporary[i3]=Command[i2+i3];
1247 if(Command[i2+i3]=='\0') break;
1248 }
1249 if(Command[i2+i3]=='('){
1250
1251 //DLL関数の場合
1252 DllProc *pDllProc;
1253 pDllProc=GetDeclareHash(temporary);
1254 if(pDllProc){
1255 if( pDllProc->ReturnType().IsStringObject() ){
1256 return 1;
1257 }
1258 return 0;
1259 }
1260
1261 //ユーザー定義関数
1262 UserProc *pUserProc;
1263 pUserProc=GetSubHash(temporary);
1264 if(pUserProc){
1265 if( pUserProc->ReturnType().IsStringObject() ){
1266 return 1;
1267 }
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 Type varType;
1302 if( !GetVarType(Command+i2,varType,1) ){
1303 //エラー
1304 return -1;
1305 }
1306 if( varType.IsStringObject() ){
1307 return 1;
1308 }
1309 }
1310 else if(Command[i2]=='\"') return 1;
1311 break;
1312 }
1313 if(IsNumCalcMark(Command,i)||IsStrCalcMark(Command[i])){
1314 if(IsStrCalcMark(Command[i])){
1315
1316 //&H、&O表記の場合を考慮
1317 if(i==0) continue;
1318 if(IsNumCalcMark(Command,i-1)) continue;
1319
1320 if(Command[i+1]=='(') break;
1321 i2=i+1;
1322 continue;
1323 }
1324 break;
1325 }
1326 }
1327 return 0;
1328}
1329
1330BYTE GetCalcId(const char *Command,int *pi){
1331 *pi=0;
1332
1333 if(Command[0]==1) *pi=1;
1334
1335 //論理演算子
1336 if(Command[0]==1&&Command[1]==ESC_XOR) return CALC_XOR;
1337 else if(Command[0]==1&&Command[1]==ESC_OR) return CALC_OR;
1338 else if(Command[0]==1&&Command[1]==ESC_AND) return CALC_AND;
1339 else if(Command[0]==1&&Command[1]==ESC_NOT) return CALC_NOT;
1340
1341 //ビット演算子(優先順位は算術演算子の後部)
1342 else if(Command[0]=='<'&&Command[1]=='<'){
1343 *pi=1;
1344 return CALC_SHL;
1345 }
1346 else if(Command[0]=='>'&&Command[1]=='>'){
1347 *pi=1;
1348 return CALC_SHR;
1349 }
1350
1351 //比較演算子
1352 else if(Command[0]=='<'&&Command[1]=='='||
1353 Command[0]=='='&&Command[1]=='<'){
1354 *pi=1;
1355 return CALC_PE;
1356 }
1357 else if(Command[0]=='>'&&Command[1]=='='||
1358 Command[0]=='='&&Command[1]=='>'){
1359 *pi=1;
1360 return CALC_QE;
1361 }
1362 else if(Command[0]=='<'&&Command[1]=='>'||
1363 Command[0]=='>'&&Command[1]=='<'){
1364 *pi=1;
1365 return CALC_NOTEQUAL;
1366 }
1367 else if(Command[0]=='=') return CALC_EQUAL;
1368 else if(Command[0]=='<') return CALC_P;
1369 else if(Command[0]=='>') return CALC_Q;
1370
1371 //算術演算子
1372 else if(Command[0]=='+') return CALC_ADDITION;
1373 else if(Command[0]=='-') return CALC_SUBTRACTION;
1374 else if(Command[0]=='&') return CALC_STRPLUS;
1375 else if(Command[0]==1&&Command[1]==ESC_MOD) return CALC_MOD;
1376 else if(Command[0]=='*') return CALC_PRODUCT;
1377 else if(Command[0]=='/') return CALC_QUOTIENT;
1378 else if(Command[0]=='\\') return CALC_INTQUOTIENT;
1379 else if(Command[0]=='^') return CALC_POWER;
1380 else if(Command[0]==1&&Command[1]==ESC_AS) return CALC_AS;
1381 else if(Command[0]==1&&Command[1]==ESC_BYVAL) return CALC_BYVAL;
1382
1383 return 0;
1384}
1385BOOL GetNumOpeElements(const char *Command,int *pnum,
1386 char *values[255],long calc[255],long stack[255]){
1387 extern int cp;
1388 extern HANDLE hHeap;
1389 int i,i2,i3,i4,PareNum,sp;
1390 char temporary[1024];
1391
1392 for(i=0,i2=0,sp=0,*pnum=0,PareNum=0;;i++,i2++){
1393 if(Command[i]=='\"'){
1394 temporary[i2]=Command[i];
1395 for(i++,i2++;;i++,i2++){
1396 temporary[i2]=Command[i];
1397 if(Command[i]=='\"') break;
1398 }
1399 continue;
1400 }
1401 else if(Command[i]=='['){
1402 i3=GetStringInBracket(temporary+i2,Command+i);
1403 i+=i3-1;
1404 i2+=i3-1;
1405 continue;
1406 }
1407 else if(Command[i]=='('){
1408 if(i==0){
1409 PareNum++;
1410 i2=-1;
1411 continue;
1412 }
1413 else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
1414 PareNum++;
1415 i2=-1;
1416 continue;
1417 }
1418 else{
1419 //配列変数の場合を考慮
1420 i3=GetStringInPare(temporary+i2,Command+i);
1421 i+=i3-1;
1422 i2+=i3-1;
1423 continue;
1424 }
1425 }
1426 else if(Command[i]==')'){
1427 PareNum--;
1428 i2--;
1429 continue;
1430 }
1431 else if(IsNumCalcMark(Command,i)||(Command[i]=='&'&&i2!=0)){
1432 if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
1433 if(IsExponent(Command,i)){
1434 temporary[i2]=Command[i];
1435 continue;
1436 }
1437 }
1438 temporary[i2]=0;
1439
1440 if((stack[sp-1]%100)==CALC_AS&&Command[i]=='*'){
1441 for(i3=0;i3<i2;i3++){
1442 if(temporary[i2]!='*') break;
1443 }
1444 if(i3==i2){
1445 //"*"をポインタ指定文字として認識する
1446 temporary[i2]=Command[i];
1447 continue;
1448 }
1449 }
1450
1451 calc[*pnum]=0;
1452 if(i2){
1453 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1454 lstrcpy(values[*pnum],temporary);
1455 (*pnum)++;
1456 }
1457 else{
1458 if(!(
1459 Command[i]=='+'||
1460 Command[i]=='-'||
1461 (Command[i]==1&&Command[i+1]==ESC_NOT)||
1462 (Command[i]==1&&Command[i+1]==ESC_BYVAL)
1463 )){
1464 SetError(1,NULL,cp);
1465 return 0;
1466 }
1467 if(Command[i]=='+'){
1468 i2=-1;
1469 continue;
1470 }
1471 }
1472
1473 if(Command[i]=='-'&&i2==0){
1474 i3=CALC_MINUSMARK;
1475 }
1476 else{
1477 i3=GetCalcId(Command+i,&i4);
1478 i+=i4;
1479 if(!i3){
1480 SetError(1,NULL,cp);
1481 return 0;
1482 }
1483 }
1484
1485 i3+=PareNum*100;
1486 if(sp){
1487 if(stack[sp-1]>i3-3&&
1488 (!(
1489 (stack[sp-1]%100==CALC_MINUSMARK || stack[sp-1]%100==CALC_NOT || stack[sp-1]%100==CALC_POWER)&&
1490 (i3%100==CALC_MINUSMARK || i3%100==CALC_NOT)
1491 ))
1492 ){
1493 for(;sp>0;){
1494 sp--;
1495 calc[*pnum]=stack[sp];
1496 values[*pnum]=0;
1497 (*pnum)++;
1498 if(!(stack[sp-1]>i3-3)) break;
1499 }
1500 }
1501 }
1502 stack[sp]=i3;
1503 sp++;
1504
1505 i2=-1;
1506 continue;
1507 }
1508 temporary[i2]=Command[i];
1509 if(Command[i]=='\0'){
1510 calc[*pnum]=0;
1511
1512 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1513 lstrcpy(values[*pnum],temporary);
1514 (*pnum)++;
1515
1516 for(;sp>0;(*pnum)++){
1517 sp--;
1518 calc[*pnum]=stack[sp];
1519 values[*pnum]=0;
1520 }
1521 break;
1522 }
1523 }
1524
1525 return 1;
1526}
Note: See TracBrowser for help on using the repository browser.