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

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

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