source: dev/BasicCompiler_Common/calculation.cpp@ 105

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

名前空間機能をグローバル変数、定数と列挙型に適用。
一部、クラスの静的メンバと名前空間の相性が悪いコードが潜んでいるため、要改修

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