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

Last change on this file since 230 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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