source: dev/trunk/abdev/BasicCompiler_Common/calculation.cpp@ 185

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