source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/calculation.cpp@ 484

Last change on this file since 484 was 484, checked in by dai_9181, 16 years ago

プロジェクトのリネーム中

File size: 37.5 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 "../compiler_x86/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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(9,NULL,cp);
109 return;
110 }
111 }
112 else{
113 //文字列演算ができない演算子
114 if(stack[sp-2]||stack[sp-1]){
115 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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) compiler.errorMessenger.Output(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) compiler.errorMessenger.Output(3,temporary,cp);
504 return false;
505 }
506 if( !pConstMacro->GetCalcBuffer( temp2, Parms ) )
507 {
508 if(enableerror) compiler.errorMessenger.Output(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) compiler.errorMessenger.Output(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) compiler.errorMessenger.Output(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) compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 compiler.errorMessenger.Output(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 if( debugger.IsRunning() )
1085 {
1086 return DEF_DOUBLE;
1087 }
1088
1089 if( !isNotifyError )
1090 {
1091 return -1;
1092 }
1093
1094 compiler.errorMessenger.Output(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 if( debugger.IsRunning() )
1133 {
1134 return DEF_DOUBLE;
1135 }
1136
1137 if( !isNotifyError )
1138 {
1139 return -1;
1140 }
1141
1142 compiler.errorMessenger.Output(33,NULL,cp);
1143 return DEF_DOUBLE;
1144}
1145#pragma optimize("", on)
1146
1147int IsStrCalculation(const char *Command){
1148 int i,i2,i3,i4,PareNum;
1149 char temporary[VN_SIZE],temp2[8192];
1150
1151 for(i=0,i2=0;;i++){
1152 if(Command[i]=='('){
1153 for(i++,PareNum=1;;i++){
1154 if(Command[i]=='(') PareNum++;
1155 else if(Command[i]==')'){
1156 PareNum--;
1157 if(PareNum==0) break;
1158 }
1159 }
1160 continue;
1161 }
1162 if(Command[i]=='['){
1163 for(i++,PareNum=1;;i++){
1164 if(Command[i]=='[') PareNum++;
1165 else if(Command[i]==']'){
1166 PareNum--;
1167 if(PareNum==0) break;
1168 }
1169 }
1170 continue;
1171 }
1172 if(Command[i]=='\"'){
1173 i++;
1174 while(Command[i]!='\"') i++;
1175 continue;
1176 }
1177 if(Command[i]=='\0'){
1178 if(IsVariableTopChar(Command[i2])||
1179 Command[i2]=='.'&&IsVariableTopChar(Command[i2+1])){
1180
1181 if((Command[i2]=='e'||Command[i2]=='E')&&
1182 (Command[i2+1]=='x'||Command[i2+1]=='X')&&
1183 Command[i2+2]=='\"'){
1184 //拡張文字列
1185 return 1;
1186 }
1187
1188 for(i3=0;;i3++){
1189 if(Command[i2+i3]=='('){
1190 temporary[i3]=0;
1191 break;
1192 }
1193 temporary[i3]=Command[i2+i3];
1194 if(Command[i2+i3]=='\0') break;
1195 }
1196 if(Command[i2+i3]=='('){
1197
1198 //DLL関数の場合
1199 DllProc *pDllProc;
1200 pDllProc=GetDeclareHash(temporary);
1201 if(pDllProc){
1202 if( pDllProc->ReturnType().IsStringClass() ){
1203 return 1;
1204 }
1205 return 0;
1206 }
1207
1208 //ユーザー定義関数
1209 const UserProc *pUserProc = GetSubHash(temporary);
1210 if(pUserProc){
1211 if( pUserProc->ReturnType().IsStringClass() ){
1212 return 1;
1213 }
1214 return 0;
1215 }
1216
1217 //組み込み関数
1218 i4=GetFunctionFromName(temporary);
1219 if(i4){
1220 //組み込み関数は文字列を返さない
1221 return 0;
1222 }
1223
1224 //定数
1225 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find( temporary );
1226 if(pConstMacro){
1227 //マクロ関数の場合
1228 GetStringInPare_RemovePare(temporary,Command+i2+i3+1);
1229 pConstMacro->GetCalcBuffer( temporary, temp2 );
1230 return IsStrCalculation(temp2);
1231 }
1232 }
1233
1234 //定数
1235 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(Command+i2);
1236 if(i3==DEF_STRING) return 1; //文字列
1237 if(i3) return 0; //数値
1238
1239 //変数
1240 Type varType;
1241 if( !GetVarType(Command+i2,varType,1) ){
1242 //エラー
1243 return -1;
1244 }
1245 if( varType.IsStringClass() ){
1246 return 1;
1247 }
1248 }
1249 else if(Command[i2]=='\"') return 1;
1250 break;
1251 }
1252 if(IsNumCalcMark(Command,i)||IsStrCalcMark(Command[i])){
1253 if(IsStrCalcMark(Command[i])){
1254
1255 //&H、&O表記の場合を考慮
1256 if(i==0) continue;
1257 if(IsNumCalcMark(Command,i-1)) continue;
1258
1259 if(Command[i+1]=='(') break;
1260 i2=i+1;
1261 continue;
1262 }
1263 break;
1264 }
1265 }
1266 return 0;
1267}
1268
1269BYTE GetCalcId(const char *Command,int *pi){
1270 *pi=0;
1271
1272 if(Command[0]==1) *pi=1;
1273
1274 //論理演算子
1275 if(Command[0]==1&&Command[1]==ESC_XOR) return CALC_XOR;
1276 else if(Command[0]==1&&Command[1]==ESC_OR) return CALC_OR;
1277 else if(Command[0]==1&&Command[1]==ESC_AND) return CALC_AND;
1278 else if(Command[0]==1&&Command[1]==ESC_NOT) return CALC_NOT;
1279
1280 //ビット演算子(優先順位は算術演算子の後部)
1281 else if(Command[0]=='<'&&Command[1]=='<'){
1282 *pi=1;
1283 return CALC_SHL;
1284 }
1285 else if(Command[0]=='>'&&Command[1]=='>'){
1286 *pi=1;
1287 return CALC_SHR;
1288 }
1289
1290 //比較演算子
1291 else if(Command[0]=='<'&&Command[1]=='='||
1292 Command[0]=='='&&Command[1]=='<'){
1293 *pi=1;
1294 return CALC_PE;
1295 }
1296 else if(Command[0]=='>'&&Command[1]=='='||
1297 Command[0]=='='&&Command[1]=='>'){
1298 *pi=1;
1299 return CALC_QE;
1300 }
1301 else if(Command[0]=='<'&&Command[1]=='>'||
1302 Command[0]=='>'&&Command[1]=='<'){
1303 *pi=1;
1304 return CALC_NOTEQUAL;
1305 }
1306 else if(Command[0]=='=') return CALC_EQUAL;
1307 else if(Command[0]=='<') return CALC_P;
1308 else if(Command[0]=='>') return CALC_Q;
1309
1310 //算術演算子
1311 else if(Command[0]=='+') return CALC_ADDITION;
1312 else if(Command[0]=='-') return CALC_SUBTRACTION;
1313 else if(Command[0]=='&') return CALC_STRPLUS;
1314 else if(Command[0]==1&&Command[1]==ESC_MOD) return CALC_MOD;
1315 else if(Command[0]=='*') return CALC_PRODUCT;
1316 else if(Command[0]=='/') return CALC_QUOTIENT;
1317 else if(Command[0]=='\\') return CALC_INTQUOTIENT;
1318 else if(Command[0]=='^') return CALC_POWER;
1319 else if(Command[0]==1&&Command[1]==ESC_AS) return CALC_AS;
1320 else if(Command[0]==1&&Command[1]==ESC_BYVAL) return CALC_BYVAL;
1321
1322 return 0;
1323}
1324BOOL GetNumOpeElements(const char *Command,int *pnum,
1325 char *values[255],long calc[255],long stack[255]){
1326 extern int cp;
1327 extern HANDLE hHeap;
1328 int i,i2,i3,i4,PareNum,sp;
1329 char temporary[1024];
1330
1331 for(i=0,i2=0,sp=0,*pnum=0,PareNum=0;;i++,i2++){
1332 if(Command[i]=='\"'){
1333 temporary[i2]=Command[i];
1334 for(i++,i2++;;i++,i2++){
1335 temporary[i2]=Command[i];
1336 if(Command[i]=='\"') break;
1337 }
1338 continue;
1339 }
1340 else if(Command[i]=='['){
1341 i3=GetStringInBracket(temporary+i2,Command+i);
1342 i+=i3-1;
1343 i2+=i3-1;
1344 continue;
1345 }
1346 else if(Command[i]=='('){
1347 if(i==0){
1348 PareNum++;
1349 i2=-1;
1350 continue;
1351 }
1352 else if(IsNumCalcMark_Back(Command,i-1)||Command[i-1]=='('){
1353 PareNum++;
1354 i2=-1;
1355 continue;
1356 }
1357 else{
1358 //配列変数の場合を考慮
1359 i3=GetStringInPare(temporary+i2,Command+i);
1360 i+=i3-1;
1361 i2+=i3-1;
1362 continue;
1363 }
1364 }
1365 else if(Command[i]==')'){
1366 PareNum--;
1367 i2--;
1368 continue;
1369 }
1370 else if(IsNumCalcMark(Command,i)||(Command[i]=='&'&&i2!=0)){
1371 if((Command[i]=='+'||Command[i]=='-')&&(Command[i-1]=='e'||Command[i-1]=='E')){
1372 if(IsExponent(Command,i)){
1373 temporary[i2]=Command[i];
1374 continue;
1375 }
1376 }
1377 temporary[i2]=0;
1378
1379 if( sp > 0 && (stack[sp-1]%100) == CALC_AS )
1380 {
1381 if( Command[i] == '*' )
1382 {
1383 for(i3=0;i3<i2;i3++){
1384 if(temporary[i2]!='*') break;
1385 }
1386 if(i3==i2){
1387 //"*"をポインタ指定文字として認識する
1388 temporary[i2]=Command[i];
1389 continue;
1390 }
1391 }
1392 else if( Command[i] == '<' )
1393 {
1394 Type type;
1395 if( compiler.StringToType( temporary, type ) )
1396 {
1397 if( type.HasMember() && type.GetClass().IsGeneric() )
1398 {
1399 char temp2[1024];
1400 int i5 = 1;
1401 for( i3=i, i4=0; ; i3++, i4++ )
1402 {
1403 if( Command[i3] == '<' )
1404 {
1405 i5++;
1406 }
1407 if( Command[i3] == '>' )
1408 {
1409 i5--;
1410 if( i5 == 0 )
1411 {
1412 temp2[i4] = 0;
1413 break;
1414 }
1415 }
1416 temp2[i4] = Command[i3];
1417 if( Command[i3] == '\0' )
1418 {
1419 break;
1420 }
1421 }
1422 if( Command[i] )
1423 {
1424 i = i3;
1425 i2 += i4;
1426 lstrcat( temporary, temp2 );
1427 }
1428
1429 if( Command[i] == '\0' )
1430 {
1431 goto FinishLoop;
1432 }
1433 }
1434 }
1435 }
1436 }
1437
1438 calc[*pnum]=0;
1439 if(i2){
1440 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1441 lstrcpy(values[*pnum],temporary);
1442 (*pnum)++;
1443 }
1444 else{
1445 if(!(
1446 Command[i]=='+'||
1447 Command[i]=='-'||
1448 (Command[i]==1&&Command[i+1]==ESC_NOT)||
1449 (Command[i]==1&&Command[i+1]==ESC_BYVAL)
1450 )){
1451 compiler.errorMessenger.Output(1,NULL,cp);
1452 return 0;
1453 }
1454 if(Command[i]=='+'){
1455 i2=-1;
1456 continue;
1457 }
1458 }
1459
1460 if(Command[i]=='-'&&i2==0){
1461 i3=CALC_MINUSMARK;
1462 }
1463 else{
1464 i3=GetCalcId(Command+i,&i4);
1465 i+=i4;
1466 if(!i3){
1467 compiler.errorMessenger.Output(1,NULL,cp);
1468 return 0;
1469 }
1470 }
1471
1472 i3+=PareNum*100;
1473 if(sp){
1474 if(stack[sp-1]>i3-3&&
1475 (!(
1476 (stack[sp-1]%100==CALC_MINUSMARK || stack[sp-1]%100==CALC_NOT || stack[sp-1]%100==CALC_POWER)&&
1477 (i3%100==CALC_MINUSMARK || i3%100==CALC_NOT)
1478 ))
1479 ){
1480 for(;sp>0;){
1481 sp--;
1482 calc[*pnum]=stack[sp];
1483 values[*pnum]=0;
1484 (*pnum)++;
1485 if(!(stack[sp-1]>i3-3)) break;
1486 }
1487 }
1488 }
1489 stack[sp]=i3;
1490 sp++;
1491
1492 i2=-1;
1493 continue;
1494 }
1495 temporary[i2]=Command[i];
1496 if(Command[i]=='\0'){
1497FinishLoop:
1498 calc[*pnum]=0;
1499
1500 values[*pnum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+255);
1501 lstrcpy(values[*pnum],temporary);
1502 (*pnum)++;
1503
1504 for(;sp>0;(*pnum)++){
1505 sp--;
1506 calc[*pnum]=stack[sp];
1507 values[*pnum]=0;
1508 }
1509 break;
1510 }
1511 }
1512
1513 calc[*pnum]=0;
1514
1515 return 1;
1516}
Note: See TracBrowser for help on using the repository browser.