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

Last change on this file since 420 was 402, checked in by dai_9181, 17 years ago

UserProc::SetParamsAndReturnTypeメソッドをリファクタリング
LexicalAnalysis.hのインクルードを除去した

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