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

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