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

Last change on this file since 391 was 379, checked in by dai_9181, 17 years ago

ジェネリクスインターフェイスをサポートした

File size: 37.2 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=Type(type1,index1).GetSize();
142 size2=Type(type2,index2).GetSize();
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.GetObjectModule().meta.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.GetObjectModule().meta.GetGlobalConsts().GetBasicType(Parms);
668 if(type[pnum]){
669 if(IsRealNumberType(type[pnum])){
670 //実数型
671 nums[pnum] = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(Parms);
672 }
673 else if(IsWholeNumberType(type[pnum])){
674 //整数
675 i64nums[pnum] = compiler.GetObjectModule().meta.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, enableerror);
729 if( type[pnum] == -1 )
730 {
731 // エラー
732 return false;
733 }
734 if(IsRealNumberType(type[pnum])){
735 //実数型
736 memcpy(&nums[pnum],&i64data,sizeof(double));
737 }
738 else{
739 //整数型
740 i64nums[pnum]=i64data;
741 before_index[pnum]=GetLiteralIndex(i64data);
742 }
743 }
744 }
745
746 pnum++;
747 }
748 else{
749 if(!(Command[i]=='+'||Command[i]=='-'||(Command[i]==1&&Command[i+1]==ESC_NOT))){
750 if(enableerror) SetError(1,NULL,cp);
751 return false;
752 }
753 if(Command[i]=='+'){
754 i2=-1;
755 continue;
756 }
757 }
758
759 if(Command[i]=='\0'){
760 for(;sp>0;pnum++){
761 sp--;
762 calc[pnum]=(int)stack[sp];
763 }
764 break;
765 }
766
767 //論理演算子
768 if(Command[i]==1&&Command[i+1]==ESC_XOR) i3=CALC_XOR;
769 else if(Command[i]==1&&Command[i+1]==ESC_OR) i3=CALC_OR;
770 else if(Command[i]==1&&Command[i+1]==ESC_AND) i3=CALC_AND;
771 else if(Command[i]==1&&Command[i+1]==ESC_NOT) i3=CALC_NOT;
772
773 //ビット演算子(優先順位は算術演算子の後部)
774 else if(Command[i]=='<'&&Command[i+1]=='<'){
775 i3=CALC_SHL;
776 i++;
777 }
778 else if(Command[i]=='>'&&Command[i+1]=='>'){
779 i3=CALC_SHR;
780 i++;
781 }
782
783 //比較演算子
784 else if(Command[i]=='<'&&Command[i+1]=='='||
785 Command[i]=='='&&Command[i+1]=='<'){
786 i3=CALC_PE;
787 i++;
788 }
789 else if(Command[i]=='>'&&Command[i+1]=='='||
790 Command[i]=='='&&Command[i+1]=='>'){
791 i3=CALC_QE;
792 i++;
793 }
794 else if(Command[i]=='<'&&Command[i+1]=='>'||
795 Command[i]=='>'&&Command[i+1]=='<'){
796 i3=CALC_NOTEQUAL;
797 i++;
798 }
799 else if(Command[i]=='=') i3=CALC_EQUAL;
800 else if(Command[i]=='<') i3=CALC_P;
801 else if(Command[i]=='>') i3=CALC_Q;
802
803 //算術演算子
804 else if(Command[i]=='+'||Command[i]=='&') i3=CALC_ADDITION;
805 else if(Command[i]=='-'&&i2) i3=CALC_SUBTRACTION;
806 else if(Command[i]==1&&Command[i+1]==ESC_MOD) i3=CALC_MOD;
807 else if(Command[i]=='*') i3=CALC_PRODUCT;
808 else if(Command[i]=='/') i3=CALC_QUOTIENT;
809 else if(Command[i]=='\\') i3=CALC_INTQUOTIENT;
810 else if(Command[i]=='-'&&i2==0) i3=CALC_MINUSMARK;
811 else if(Command[i]=='^') i3=CALC_POWER;
812 else if(Command[i]==1&&Command[i+1]==ESC_AS) i3=CALC_AS;
813 else if(Command[i]==1&&Command[i+1]==ESC_BYVAL) i3=CALC_BYVAL;
814
815 i3+=PareNum*100;
816 if(sp){
817 if(stack[sp-1]>i3-3&&
818 (!(
819 (stack[sp-1]%100==CALC_MINUSMARK||stack[sp-1]%100==CALC_NOT)&&
820 (i3%100==CALC_MINUSMARK||i3%100==CALC_NOT)
821 ))
822 ){
823 for(;sp>0;){
824 sp--;
825 calc[pnum]=(int)stack[sp];
826 pnum++;
827 if(!(stack[sp-1]>i3-3)) break;
828 }
829 }
830 }
831 stack[sp]=i3;
832 sp++;
833
834 if(Command[i]==1) i++;
835 i2=-1;
836 continue;
837 }
838 Parms[i2]=Command[i];
839 }
840
841 int type_stack[255];
842 LONG_PTR index_stack[255];
843 int idCalc;
844 for(i=0,sp=0;i<pnum;i++){
845
846 if( enableerror ){
847 //型チェック(正常でない場合はエラーにする)
848 TypeErrorCheck(stack,sp,calc[i]%100);
849 }
850
851 idCalc=calc[i]%100;
852
853 switch(idCalc){
854 //数値
855 case 0:
856 dbl_stack[sp]=nums[i];
857 i64stack[sp]=i64nums[i];
858 type_stack[sp]=type[i];
859 index_stack[sp]=before_index[i];
860
861 stack[sp]=(_int64)StrPtr[i];
862 sp++;
863 break;
864
865 //論理演算
866 case CALC_NOT:
867 if(IsRealNumberType(type_stack[sp-1])){
868 //実数演算
869 dbl_stack[sp-1]=(double)(~(long)dbl_stack[sp-1]);
870 }
871 else{
872 //整数演算
873 i64stack[sp-1]=~i64stack[sp-1];
874 }
875 break;
876
877 //比較演算
878 case CALC_PE:
879 case CALC_QE:
880 case CALC_P:
881 case CALC_Q:
882 case CALC_NOTEQUAL:
883 case CALC_EQUAL:
884
885 //論理演算
886 case CALC_XOR:
887 case CALC_OR:
888 case CALC_AND:
889
890 //シフト演算
891 case CALC_SHL:
892 case CALC_SHR:
893
894 //算術演算
895 case CALC_ADDITION:
896 case CALC_SUBTRACTION:
897 case CALC_MOD:
898 case CALC_PRODUCT:
899 case CALC_QUOTIENT:
900 case CALC_INTQUOTIENT:
901 case CALC_POWER:
902 StaticTwoTerm(idCalc,type_stack,index_stack,&sp,BaseType);
903 break;
904
905 case CALC_MINUSMARK:
906 if(IsRealNumberType(type_stack[sp-1])){
907 //実数演算
908 dbl_stack[sp-1]=-dbl_stack[sp-1];
909 }
910 else{
911 //整数演算
912 i64stack[sp-1]=-i64stack[sp-1];
913 }
914 break;
915 case CALC_AS:
916 if(IsWholeNumberType(type_stack[sp-2])){
917 if(IsRealNumberType(type_stack[sp-1])){
918 dbl_stack[sp-2]=(double)i64stack[sp-2];
919 }
920 }
921 if(IsRealNumberType(type_stack[sp-2])){
922 if(IsWholeNumberType(type_stack[sp-1])){
923 i64stack[sp-2]=(_int64)dbl_stack[sp-2];
924 }
925 }
926
927 if( type_stack[sp-1] == DEF_OBJECT || type_stack[sp-1] == DEF_STRUCT ){
928 // リテラル値ではないため抜け出す
929 return false;
930 }
931
932 type_stack[sp-2]=type_stack[sp-1];
933 index_stack[sp-2]=index_stack[sp-1];
934 sp--;
935 break;
936 case CALC_BYVAL:
937 //エラー
938 break;
939 }
940 }
941 if(stack[0]){
942 //文字列ポインタ
943 *pi64data=(_int64)stack[0];
944 resultType.SetType( type_stack[0], index_stack[0] );
945 return true;
946 }
947
948 if(IsRealNumberType(type_stack[0])){
949 //実数
950 memcpy(pi64data,&dbl_stack[0],sizeof(double));
951 resultType.SetType( type_stack[0], index_stack[0] );
952 return true;
953 }
954
955 //整数
956 *pi64data=i64stack[0];
957
958 if(index_stack[0]==-1){
959 if(Is64Type(type_stack[0])==0&&IsRealNumberType(type_stack[0])==0){
960 //整数(符号有り/無し)
961 i64data=*pi64data;
962
963 resultType.SetIndex( GetLiteralIndex(i64data) );
964 }
965 }
966 else{
967 resultType.SetIndex( index_stack[0] );
968 }
969
970 resultType.SetBasicType( type_stack[0] );
971 return true;
972}
973
974#pragma optimize("", off)
975#pragma warning(disable : 4748)
976DWORD GetLiteralValue(char *value,_int64 *pi64,int BaseType, bool isNotifyError ){
977 extern HANDLE hHeap;
978 extern int cp;
979 int i,i2,i3,sw1,sw2,bDbl;
980 double dbl;
981 char temporary[255];
982
983 if(value[0]=='&'){
984 _int64 i64temp;
985 lstrcpy(temporary,value);
986
987 if(temporary[1]=='o'||temporary[1]=='O'){
988 for(i=2;;i++){
989 i3=temporary[i]-0x30;
990 if(i3<0||7<i3) break;
991 temporary[i]=i3;
992 }
993 if(temporary[i]){
994 if( !isNotifyError )
995 {
996 return -1;
997 }
998 SetError(57,NULL,cp);
999 return DEF_BYTE;
1000 }
1001
1002 i64temp=1;
1003 *pi64=0;
1004 for(i--;i>=2;i--){
1005 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
1006 i64temp*=8;
1007 }
1008 }
1009 else if(temporary[1]=='h'||temporary[1]=='H'){
1010 CharUpper(temporary+2);
1011 for(i=2;;i++){
1012 i3=temporary[i]-0x30;
1013 if(i3<0||9<i3){
1014 i3=temporary[i]-0x41+10;
1015 if(i3<0xA||0xF<i3) break;
1016 }
1017 temporary[i]=i3;
1018 }
1019 if(temporary[i]){
1020 if( !isNotifyError )
1021 {
1022 return -1;
1023 }
1024 SetError(58,NULL,cp);
1025 return DEF_BYTE;
1026 }
1027
1028 i64temp=1;
1029 *pi64=0;
1030 for(i--;i>=2;i--){
1031 *pi64=(*pi64)+(_int64)(i64temp*temporary[i]);
1032 i64temp*=0x10;
1033 }
1034 }
1035 else{
1036 if( !isNotifyError )
1037 {
1038 return -1;
1039 }
1040 SetError(12,"&",cp);
1041 return DEF_BYTE;
1042 }
1043
1044 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return DEF_QWORD;
1045
1046 if(((unsigned _int64)*pi64)<=UCHAR_MAX){
1047 //符号無し8ビット整数のリテラル値
1048 return DEF_BYTE;
1049 }
1050 else if(((unsigned _int64)*pi64)<=USHRT_MAX){
1051 //符号無し16ビット整数のリテラル値
1052 return DEF_WORD;
1053 }
1054 else if(((unsigned _int64)*pi64)<=UINT_MAX){
1055 //符号無し32ビット整数のリテラル値
1056 return DEF_DWORD;
1057 }
1058 else{
1059 //符号無し64ビット整数のリテラル値
1060 return DEF_QWORD;
1061 }
1062 }
1063 else if((value[0]>='0'&&value[0]<='9')||value[0]=='+'||value[0]=='-'||(value[0]=='.'&&(!IsVariableTopChar(value[1])))){
1064 for(i=0;;i++){
1065 if(value[i]!='-') break;
1066 }
1067 if(value[i]=='.'){
1068 SlideString(value+i,1);
1069 value[i]='0';
1070 }
1071
1072 //エラーチェック
1073 bDbl=0;
1074 sw1=0;
1075 sw2=0;
1076 for(i2=i;;i2++){
1077 if(value[i2]=='\0') break;
1078 if(value[i2]=='.') bDbl=1;
1079 if(!((value[i2]>='0'&&value[i2]<='9')||value[i2]=='.')){
1080 if((value[i2]=='e'||value[i2]=='E')&&sw1==0){
1081 bDbl=1;
1082 sw1=1;
1083 }
1084 else if((value[i2]=='+'||value[i2]=='-')&&sw1==1&&sw2==0) sw2=1;
1085 else{
1086 extern BOOL bDebugRun;
1087 if(bDebugRun) return DEF_DOUBLE;
1088
1089 if( !isNotifyError )
1090 {
1091 return -1;
1092 }
1093
1094 SetError(3,value,cp);
1095 return DEF_DOUBLE;
1096 }
1097 }
1098 }
1099
1100 if(bDbl){
1101 //実数のリテラル値
1102 if(i%2) dbl=-atof(value+i);
1103 else dbl=atof(value+i);
1104
1105 memcpy(pi64,&dbl,sizeof(double));
1106
1107 if(BaseType==DEF_SINGLE) return DEF_SINGLE;
1108
1109 return DEF_DOUBLE;
1110 }
1111 else{
1112 *pi64=_atoi64(value+i);
1113 if(i%2) *pi64=-(*pi64);
1114
1115 if(BaseType==DEF_INT64||BaseType==DEF_QWORD) return BaseType;
1116
1117 if(LONG_MIN<=*pi64&&*pi64<=LONG_MAX){
1118 //符号有り32ビット整数のリテラル値
1119 return DEF_LONG;
1120 }
1121 else if(*pi64<=UINT_MAX){
1122 //符号無し32ビット整数のリテラル値
1123 return DEF_DWORD;
1124 }
1125 else{
1126 //符号有り64ビット整数のリテラル値
1127 return DEF_INT64;
1128 }
1129 }
1130 }
1131
1132 extern BOOL bDebugRun;
1133 if(bDebugRun) return DEF_DOUBLE;
1134
1135 if( !isNotifyError )
1136 {
1137 return -1;
1138 }
1139
1140 SetError(33,NULL,cp);
1141 return DEF_DOUBLE;
1142}
1143#pragma optimize("", on)
1144
1145int IsStrCalculation(const char *Command){
1146 int i,i2,i3,i4,PareNum;
1147 char temporary[VN_SIZE],temp2[8192];
1148
1149 for(i=0,i2=0;;i++){
1150 if(Command[i]=='('){
1151 for(i++,PareNum=1;;i++){
1152 if(Command[i]=='(') PareNum++;
1153 else if(Command[i]==')'){
1154 PareNum--;
1155 if(PareNum==0) break;
1156 }
1157 }
1158 continue;
1159 }
1160 if(Command[i]=='['){
1161 for(i++,PareNum=1;;i++){
1162 if(Command[i]=='[') PareNum++;
1163 else if(Command[i]==']'){
1164 PareNum--;
1165 if(PareNum==0) break;
1166 }
1167 }
1168 continue;
1169 }
1170 if(Command[i]=='\"'){
1171 i++;
1172 while(Command[i]!='\"') i++;
1173 continue;
1174 }
1175 if(Command[i]=='\0'){
1176 if(IsVariableTopChar(Command[i2])||
1177 Command[i2]=='.'&&IsVariableTopChar(Command[i2+1])){
1178
1179 if((Command[i2]=='e'||Command[i2]=='E')&&
1180 (Command[i2+1]=='x'||Command[i2+1]=='X')&&
1181 Command[i2+2]=='\"'){
1182 //拡張文字列
1183 return 1;
1184 }
1185
1186 for(i3=0;;i3++){
1187 if(Command[i2+i3]=='('){
1188 temporary[i3]=0;
1189 break;
1190 }
1191 temporary[i3]=Command[i2+i3];
1192 if(Command[i2+i3]=='\0') break;
1193 }
1194 if(Command[i2+i3]=='('){
1195
1196 //DLL関数の場合
1197 DllProc *pDllProc;
1198 pDllProc=GetDeclareHash(temporary);
1199 if(pDllProc){
1200 if( pDllProc->ReturnType().IsStringClass() ){
1201 return 1;
1202 }
1203 return 0;
1204 }
1205
1206 //ユーザー定義関数
1207 const UserProc *pUserProc = GetSubHash(temporary);
1208 if(pUserProc){
1209 if( pUserProc->ReturnType().IsStringClass() ){
1210 return 1;
1211 }
1212 return 0;
1213 }
1214
1215 //組み込み関数
1216 i4=GetFunctionFromName(temporary);
1217 if(i4){
1218 //組み込み関数は文字列を返さない
1219 return 0;
1220 }
1221
1222 //定数
1223 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( temporary );
1224 if(pConstMacro){
1225 //マクロ関数の場合
1226 GetStringInPare_RemovePare(temporary,Command+i2+i3+1);
1227 pConstMacro->GetCalcBuffer( temporary, temp2 );
1228 return IsStrCalculation(temp2);
1229 }
1230 }
1231
1232 //定数
1233 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(Command+i2);
1234 if(i3==DEF_STRING) return 1; //文字列
1235 if(i3) return 0; //数値
1236
1237 //変数
1238 Type varType;
1239 if( !GetVarType(Command+i2,varType,1) ){
1240 //エラー
1241 return -1;
1242 }
1243 if( varType.IsStringClass() ){
1244 return 1;
1245 }
1246 }
1247 else if(Command[i2]=='\"') return 1;
1248 break;
1249 }
1250 if(IsNumCalcMark(Command,i)||IsStrCalcMark(Command[i])){
1251 if(IsStrCalcMark(Command[i])){
1252
1253 //&H、&O表記の場合を考慮
1254 if(i==0) continue;
1255 if(IsNumCalcMark(Command,i-1)) continue;
1256
1257 if(Command[i+1]=='(') break;
1258 i2=i+1;
1259 continue;
1260 }
1261 break;
1262 }
1263 }
1264 return 0;
1265}
1266
1267BYTE GetCalcId(const char *Command,int *pi){
1268 *pi=0;
1269
1270 if(Command[0]==1) *pi=1;
1271
1272 //論理演算子
1273 if(Command[0]==1&&Command[1]==ESC_XOR) return CALC_XOR;
1274 else if(Command[0]==1&&Command[1]==ESC_OR) return CALC_OR;
1275 else if(Command[0]==1&&Command[1]==ESC_AND) return CALC_AND;
1276 else if(Command[0]==1&&Command[1]==ESC_NOT) return CALC_NOT;
1277
1278 //ビット演算子(優先順位は算術演算子の後部)
1279 else if(Command[0]=='<'&&Command[1]=='<'){
1280 *pi=1;
1281 return CALC_SHL;
1282 }
1283 else if(Command[0]=='>'&&Command[1]=='>'){
1284 *pi=1;
1285 return CALC_SHR;
1286 }
1287
1288 //比較演算子
1289 else if(Command[0]=='<'&&Command[1]=='='||
1290 Command[0]=='='&&Command[1]=='<'){
1291 *pi=1;
1292 return CALC_PE;
1293 }
1294 else if(Command[0]=='>'&&Command[1]=='='||
1295 Command[0]=='='&&Command[1]=='>'){
1296 *pi=1;
1297 return CALC_QE;
1298 }
1299 else if(Command[0]=='<'&&Command[1]=='>'||
1300 Command[0]=='>'&&Command[1]=='<'){
1301 *pi=1;
1302 return CALC_NOTEQUAL;
1303 }
1304 else if(Command[0]=='=') return CALC_EQUAL;
1305 else if(Command[0]=='<') return CALC_P;
1306 else if(Command[0]=='>') return CALC_Q;
1307
1308 //算術演算子
1309 else if(Command[0]=='+') return CALC_ADDITION;
1310 else if(Command[0]=='-') return CALC_SUBTRACTION;
1311 else if(Command[0]=='&') return CALC_STRPLUS;
1312 else if(Command[0]==1&&Command[1]==ESC_MOD) return CALC_MOD;
1313 else if(Command[0]=='*') return CALC_PRODUCT;
1314 else if(Command[0]=='/') return CALC_QUOTIENT;
1315 else if(Command[0]=='\\') return CALC_INTQUOTIENT;
1316 else if(Command[0]=='^') return CALC_POWER;
1317 else if(Command[0]==1&&Command[1]==ESC_AS) return CALC_AS;
1318 else if(Command[0]==1&&Command[1]==ESC_BYVAL) return CALC_BYVAL;
1319
1320 return 0;
1321}
1322BOOL GetNumOpeElements(const char *Command,int *pnum,
1323 char *values[255],long calc[255],long stack[255]){
1324 extern int cp;
1325 extern HANDLE hHeap;
1326 int i,i2,i3,i4,PareNum,sp;
1327 char temporary[1024];
1328
1329 for(i=0,i2=0,sp=0,*pnum=0,PareNum=0;;i++,i2++){
1330 if(Command[i]=='\"'){
1331 temporary[i2]=Command[i];
1332 for(i++,i2++;;i++,i2++){
1333 temporary[i2]=Command[i];
1334 if(Command[i]=='\"') break;
1335 }
1336 continue;
1337 }
1338 else if(Command[i]=='['){
1339 i3=GetStringInBracket(temporary+i2,Command+i);
1340 i+=i3-1;
1341 i2+=i3-1;
1342 continue;
1343 }
1344 else if(Command[i]=='('){
1345 if(i==0){
1346 PareNum++;
1347 i2=-1;
1348 continue;
1349 }
1350 else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
1351 PareNum++;
1352 i2=-1;
1353 continue;
1354 }
1355 else{
1356 //配列変数の場合を考慮
1357 i3=GetStringInPare(temporary+i2,Command+i);
1358 i+=i3-1;
1359 i2+=i3-1;
1360 continue;
1361 }
1362 }
1363 else if(Command[i]==')'){
1364 PareNum--;
1365 i2--;
1366 continue;
1367 }
1368 else if(IsNumCalcMark(Command,i)||(Command[i]=='&'&&i2!=0)){
1369 if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
1370 if(IsExponent(Command,i)){
1371 temporary[i2]=Command[i];
1372 continue;
1373 }
1374 }
1375 temporary[i2]=0;
1376
1377 if( sp > 0 && (stack[sp-1]%100) == CALC_AS )
1378 {
1379 if( Command[i] == '*' )
1380 {
1381 for(i3=0;i3<i2;i3++){
1382 if(temporary[i2]!='*') break;
1383 }
1384 if(i3==i2){
1385 //"*"をポインタ指定文字として認識する
1386 temporary[i2]=Command[i];
1387 continue;
1388 }
1389 }
1390 else if( Command[i] == '<' )
1391 {
1392 Type type;
1393 if( compiler.StringToType( temporary, type ) )
1394 {
1395 if( type.HasMember() && type.GetClass().IsGeneric() )
1396 {
1397 char temp2[1024];
1398 int i5 = 1;
1399 for( i3=i, i4=0; ; i3++, i4++ )
1400 {
1401 if( Command[i3] == '<' )
1402 {
1403 i5++;
1404 }
1405 if( Command[i3] == '>' )
1406 {
1407 i5--;
1408 if( i5 == 0 )
1409 {
1410 temp2[i4] = 0;
1411 break;
1412 }
1413 }
1414 temp2[i4] = Command[i3];
1415 if( Command[i3] == '\0' )
1416 {
1417 break;
1418 }
1419 }
1420 if( Command[i] )
1421 {
1422 i = i3;
1423 i2 += i4;
1424 lstrcat( temporary, temp2 );
1425 }
1426
1427 if( Command[i] == '\0' )
1428 {
1429 goto FinishLoop;
1430 }
1431 }
1432 }
1433 }
1434 }
1435
1436 calc[*pnum]=0;
1437 if(i2){
1438 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1439 lstrcpy(values[*pnum],temporary);
1440 (*pnum)++;
1441 }
1442 else{
1443 if(!(
1444 Command[i]=='+'||
1445 Command[i]=='-'||
1446 (Command[i]==1&&Command[i+1]==ESC_NOT)||
1447 (Command[i]==1&&Command[i+1]==ESC_BYVAL)
1448 )){
1449 SetError(1,NULL,cp);
1450 return 0;
1451 }
1452 if(Command[i]=='+'){
1453 i2=-1;
1454 continue;
1455 }
1456 }
1457
1458 if(Command[i]=='-'&&i2==0){
1459 i3=CALC_MINUSMARK;
1460 }
1461 else{
1462 i3=GetCalcId(Command+i,&i4);
1463 i+=i4;
1464 if(!i3){
1465 SetError(1,NULL,cp);
1466 return 0;
1467 }
1468 }
1469
1470 i3+=PareNum*100;
1471 if(sp){
1472 if(stack[sp-1]>i3-3&&
1473 (!(
1474 (stack[sp-1]%100==CALC_MINUSMARK || stack[sp-1]%100==CALC_NOT || stack[sp-1]%100==CALC_POWER)&&
1475 (i3%100==CALC_MINUSMARK || i3%100==CALC_NOT)
1476 ))
1477 ){
1478 for(;sp>0;){
1479 sp--;
1480 calc[*pnum]=stack[sp];
1481 values[*pnum]=0;
1482 (*pnum)++;
1483 if(!(stack[sp-1]>i3-3)) break;
1484 }
1485 }
1486 }
1487 stack[sp]=i3;
1488 sp++;
1489
1490 i2=-1;
1491 continue;
1492 }
1493 temporary[i2]=Command[i];
1494 if(Command[i]=='\0'){
1495FinishLoop:
1496 calc[*pnum]=0;
1497
1498 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1499 lstrcpy(values[*pnum],temporary);
1500 (*pnum)++;
1501
1502 for(;sp>0;(*pnum)++){
1503 sp--;
1504 calc[*pnum]=stack[sp];
1505 values[*pnum]=0;
1506 }
1507 break;
1508 }
1509 }
1510
1511 calc[*pnum]=0;
1512
1513 return 1;
1514}
Note: See TracBrowser for help on using the repository browser.