source: dev/BasicCompiler32/NumOpe.cpp@ 94

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

New[]を禁止した。
一部の動的型情報が生成されないバグを修正。
As演算子によるダウンキャストを許可(プログラム的なチェックはまだ走っていない)

File size: 20.1 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4void PushReturnValue(int type){
5 //関数の戻り値をスタックへプッシュする
6 //※この処理内では、esi、ediは使用不可
7
8 if(type==DEF_OBJECT || type==DEF_STRUCT){
9 //push eax
10 op_push(REG_EAX);
11 }
12 else if(type==DEF_DOUBLE){
13 //sub esp,8
14 op_sub_esp(8);
15
16 //fstp qword ptr[esp]
17 OpBuffer[obp++]=(char)0xDD;
18 OpBuffer[obp++]=(char)0x1C;
19 OpBuffer[obp++]=(char)0x24;
20 }
21 else if(type==DEF_SINGLE){
22 //sub esp,4
23 op_sub_esp(4);
24
25 //fstp dword ptr[esp]
26 OpBuffer[obp++]=(char)0xD9;
27 OpBuffer[obp++]=(char)0x1C;
28 OpBuffer[obp++]=(char)0x24;
29 }
30 else if(type==DEF_INT64||type==DEF_QWORD){
31 //push edx
32 op_push(REG_EDX);
33
34 //push eax
35 op_push(REG_EAX);
36 }
37 else if(type==DEF_LONG){
38 //push eax
39 op_push(REG_EAX);
40 }
41 else if(type==DEF_INTEGER || (isUnicode&&type==DEF_CHAR)){
42 //movsx ebx,ax
43 OpBuffer[obp++]=(char)0x0F;
44 OpBuffer[obp++]=(char)0xBF;
45 OpBuffer[obp++]=(char)0xD8;
46
47 //push ebx
48 op_push(REG_EBX);
49 }
50 else if(type==DEF_SBYTE || (isUnicode==false&&type==DEF_CHAR)){
51 //movsx ebx,al
52 OpBuffer[obp++]=(char)0x0F;
53 OpBuffer[obp++]=(char)0xBE;
54 OpBuffer[obp++]=(char)0xD8;
55
56 //push ebx
57 op_push(REG_EBX);
58 }
59 else if(type==DEF_DWORD||type==DEF_WORD||type==DEF_BYTE||type==DEF_BOOLEAN||
60 IsPtrType(type)){
61 //push eax
62 op_push(REG_EAX);
63 }
64 else{
65 SetError();
66 }
67}
68
69void NewStringObject( const char *str ){
70 ///////////////////////////////////////////////////////
71 // lpszTextを元にStringオブジェクトを生成し、
72 // オブジェクトポインタをregに格納する
73 ///////////////////////////////////////////////////////
74
75 char *parameter = (char *)malloc( lstrlen( str ) + 32 );
76 sprintf( parameter, "\"%s\"%c%c*Char", str, 1, ESC_AS );
77 SetStringQuotes( parameter );
78
79 extern CClass *pobj_StringClass;
80 Operator_New( *pobj_StringClass, "", parameter, Type( DEF_OBJECT, *pobj_StringClass ) );
81
82 free( parameter );
83}
84
85
86bool NumOpe( const char *expression,
87 const Type &baseType,
88 Type &resultType,
89 BOOL *pbUseHeap ){
90
91 int i,i2,i3,i4;
92 char temporary[1024],temp2[1024],temp3[1024];
93
94 if(expression[0]=='\0'){
95 SetError(1,NULL,cp);
96 return false;
97 }
98
99 if(expression[0]==1&& expression[1]==ESC_NEW ){
100 //New演算子(オブジェクト生成)
101
102 if( !Operator_New( expression+2, baseType, resultType ) ){
103 return false;
104 }
105
106 return true;
107 }
108
109 if( !baseType.IsNull() && expression[0] == '[' ){
110 // リテラル配列の場合
111
112 if( !baseType.IsPointer() ){
113 SetError(1,NULL,cp);
114 return false;
115 }
116 Type tempBaseType( baseType );
117 tempBaseType.PtrLevelDown();
118
119 char *buffer = (char *)malloc( lstrlen( expression ) + 1 );
120 lstrcpy( buffer, expression );
121 RemoveStringBracket( buffer );
122
123 void *binary = malloc( 1 );
124 int num = 0;
125
126 i = 0;
127 while( buffer[i] ){
128 i = GetOneParameter( buffer, i, temporary );
129 if( buffer[i] == ',' ){
130 i++;
131 }
132
133 Type resultType;
134 _int64 i64data;
135 if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
136 return false;
137 }
138 if( !resultType.IsWhole() ){
139 // TODO: 実数に未対応
140 SetError();
141 return false;
142 }
143
144 binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
145 memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
146 num++;
147 }
148
149 i2 = dataTable.AddBinary( binary, num * tempBaseType.GetSize() );
150
151 //mov eax,i2
152 op_mov_RV(REG_EAX,i2);
153 obp-=sizeof(long);
154 pobj_DataTableSchedule->add();
155 obp+=sizeof(long);
156
157 free( buffer );
158
159 resultType = baseType;
160
161 //push eax
162 op_push( REG_EAX );
163
164 return true;
165 }
166
167
168 /////////////////////////////////
169 // 式要素を逆ポーランド式で取得
170 /////////////////////////////////
171
172 char *values[255];
173 long calc[255];
174 long stack[255];
175 int pnum;
176 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
177 for(i=0;i<pnum;i++){
178 if(values[i]) HeapDefaultFree(values[i]);
179 }
180 return false;
181 }
182
183
184 BOOL bError;
185 bError=0;
186
187 //リテラル値のみの計算かどうかを判別するためのフラグ
188 BOOL bLiteralCalculation=1;
189
190 //リテラル演算の場合を考慮した演算前のバッファ位置
191 int BeforeObp;
192 BeforeObp=obp;
193
194 //リテラル演算の場合を考慮した演算前のプロシージャスケジュール位置
195 //※64ビットの掛け算、除算などで特殊関数が呼ばれるため
196 int Before_ProcAddrScheduleNum;
197 Before_ProcAddrScheduleNum=pobj_SubAddrSchedule->num;
198
199 //リテラル演算の場合を考慮した演算前のデータテーブルスケジュール位置
200 int Before_DataTableScheduleNum;
201 Before_DataTableScheduleNum=pobj_DataTableSchedule->num;
202
203 //リテラル演算の場合を考慮した演算前の再配置スケジュール
204 CReloc *pobj_BackReloc;
205 pobj_BackReloc=new CReloc();
206 pobj_BackReloc->copy(pobj_Reloc);
207
208 double dbl;
209 int sp;
210 int type_stack[255];
211 bool isNothing_stack[255];
212 LONG_PTR index_stack[255];
213 BOOL bUseHeap[255];
214 _int64 i64data;
215 for(i=0,sp=0;i<pnum;i++){
216 int idCalc;
217 idCalc=calc[i]%100;
218
219 if(idCalc){
220 if(type_stack[sp-2]==DEF_OBJECT){
221 if( idCalc == CALC_AS
222 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
223 && index_stack[sp-1] == index_stack[sp-2]
224 || isNothing_stack[sp-2] ){
225 // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
226 }
227 else if( idCalc == CALC_AS
228 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
229 && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
230 )){
231 // ダウンキャストを許可する
232 }
233 else{
234 //オーバーロードされたオペレータを呼び出す
235 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
236 if(i2==0){
237 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
238 else GetCalcName(idCalc,temp2);
239 sprintf(temporary,"Operator %s",temp2);
240 SetError(27,temporary,cp);
241 goto error;
242 }
243 else if(i2==-1) goto error;
244
245 continue;
246 }
247 }
248
249 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
250 }
251
252 switch(idCalc){
253 //数値
254 case 0:
255 index_stack[sp]=-1;
256 isNothing_stack[sp] = false;
257 bUseHeap[sp]=0;
258
259 char *term;
260 term=values[i];
261
262 if(term[0]=='\"'){
263 //リテラル文字列
264 if(!RemoveStringQuotes(term)){
265 SetError(43,NULL,cp);
266 goto error;
267 }
268 i3=lstrlen(term);
269StrLiteral:
270
271 if( baseType.IsObject() ){
272 if( baseType.IsStringObject() ){
273 //要求タイプがStringのとき
274
275 //String型オブジェクトを生成
276 NewStringObject(term);
277
278 extern CClass *pobj_StringClass;
279 type_stack[sp]=DEF_OBJECT;
280 index_stack[sp]=(LONG_PTR)pobj_StringClass;
281 bLiteralCalculation=0;
282
283 sp++;
284 break;
285 }
286 }
287
288
289 type_stack[sp]=typeOfPtrChar;
290 bLiteralCalculation=0;
291
292 i2=dataTable.AddString(term,i3);
293
294 //push DataSize
295 OpBuffer[obp++]=(char)0x68;
296 *((long *)(OpBuffer+obp))=i2;
297 pobj_DataTableSchedule->add();
298 obp+=sizeof(long);
299 }
300 else if((term[0]=='e'||term[0]=='E')&&
301 (term[1]=='x'||term[1]=='X')&&
302 term[2]=='\"'){
303 //拡張版リテラル文字列(エスケープシーケンス可能)
304 if(!RemoveStringQuotes(term+2)){
305 SetError(43,NULL,cp);
306 goto error;
307 }
308 i3=FormatString_EscapeSequence(term+2);
309 term+=2;
310
311 goto StrLiteral;
312 }
313 else if(IsVariableTopChar(term[0])||
314 term[0]=='*'||
315 (term[0]=='.'&&IsVariableTopChar(term[1]))){
316 //////////////////
317 // 何らかの識別子
318
319 //////////////////////////////////////
320 // 関数(DLL、ユーザー定義、組み込み)
321 //////////////////////////////////////
322
323 i2=GetCallProcName(term,temporary);
324 if(term[i2]=='('){
325 i4=GetStringInPare_RemovePare(temp2,term+i2+1);
326
327 void *pInfo;
328 int idProc=GetProc(temporary,(void **)&pInfo);
329
330 Type resultType;
331 if(idProc){
332 //閉じカッコ")"に続く文字がNULLでないとき
333 if(term[i2+1+i4+1]!='\0'){
334 if( term[i2+1+i4+1] == '.'
335 || term[i2+1+i4+1] == 1 && term[i2+1+i4+2] == ESC_PSMEM ){
336 goto NonProc;
337 }
338 else{
339 SetError(42,NULL,cp);
340 }
341 }
342
343 ////////////////
344 // 呼び出し
345 ////////////////
346
347 CallProc(idProc,pInfo,temporary,temp2,resultType);
348 if(resultType.IsNull()){
349 //戻り値が存在しないとき
350 for(i2=2;;i2++){
351 if(term[i2]=='('||term[i2]=='\0'){
352 term[i2]=0;
353 break;
354 }
355 }
356 SetError(38,term,cp);
357
358 goto error;
359 }
360
361
362 /////////////////////
363 // 戻り値の処理
364 /////////////////////
365
366 //大きな型への暗黙の変換
367 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
368 index_stack[sp] = resultType.GetIndex();
369 bLiteralCalculation=0;
370
371 //スタックへプッシュ
372 PushReturnValue( resultType.GetBasicType() );
373
374 if( Is64Type(type_stack[sp])
375 && resultType.IsWhole()
376 && resultType.GetBasicSize() <= sizeof(long) ){
377 //必要に応じて64ビット拡張
378 ExtendStackTo64( resultType.GetBasicType() );
379 }
380
381 if( resultType.IsStruct() ){
382 //構造体が戻ったときはヒープ領域にインスタンスが格納されている
383 //※後にfreeする必要あり
384 bUseHeap[sp]=1;
385 }
386
387 sp++;
388 break;
389 }
390 else if(GetConstCalcBuffer(temporary,temp2,temp3)){
391 /////////////////////////
392 // マクロ関数
393 /////////////////////////
394
395 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
396 if(term[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
397
398 //マクロ関数の場合
399 NumOpe(temp3,Type(),resultType);
400
401 if(!IS_LITERAL(resultType.GetIndex())){
402 //リテラル値ではなかったとき
403 bLiteralCalculation=0;
404 }
405
406 type_stack[sp] = resultType.GetBasicType();
407 index_stack[sp] = resultType.GetIndex();
408
409 sp++;
410 break;
411 }
412 }
413NonProc:
414
415
416 //インデクサ(getアクセサ)
417 char variable[VN_SIZE],array_element[VN_SIZE];
418 GetArrayElement(term,variable,array_element);
419 if(array_element[0]){
420 Type resultType;
421 GetVarType(variable,resultType,0);
422 if( resultType.IsObject() ){
423 CallIndexerGetterProc(&resultType.GetClass(),variable,array_element,resultType);
424 type_stack[sp]=resultType.GetBasicType();
425 index_stack[sp]=resultType.GetIndex();
426 bLiteralCalculation=0;
427
428 //push eax
429 op_push(REG_EAX);
430
431 sp++;
432 break;
433 }
434 }
435
436
437 // Nothing
438 if( lstrcmp( term, "Nothing" ) == 0 ){
439 isNothing_stack[sp] = true;
440
441 type_stack[sp] = DEF_OBJECT;
442 if( baseType.IsObject() ){
443 index_stack[sp] = baseType.GetIndex();
444 }
445 else{
446 index_stack[sp] = (LONG_PTR)pobj_DBClass->GetObjectClass();
447 }
448
449 bLiteralCalculation = 0;
450
451 //push 0
452 op_push_V( 0 );
453
454 sp++;
455 break;
456 }
457
458 RELATIVE_VAR RelativeVar;
459 Type varType;
460 if(GetVarOffset(
461 false, //エラー表示あり
462 false, //読み込み専用
463 term,
464 &RelativeVar,varType)){
465 //////////
466 // 変数
467 //////////
468
469 //大きな型への暗黙の変換
470 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),varType.GetBasicType());
471 index_stack[sp] = varType.GetIndex();
472 bLiteralCalculation=0;
473
474 if(varType.GetBasicType()&FLAG_PTR){
475 //配列ポインタ
476 type_stack[sp]=GetPtrType(varType.GetBasicType()^FLAG_PTR);
477
478 SetVarPtrToEax(&RelativeVar);
479
480 //push eax
481 op_push(REG_EAX);
482 }
483 else if( varType.IsStruct() ){
484 //構造体ポインタをeaxへ格納(構造体は値型)
485 SetVarPtrToEax(&RelativeVar);
486
487 //push eax
488 op_push(REG_EAX);
489 }
490 else if( varType.GetBasicSize() == sizeof(_int64) ){
491 //64ビット型
492 PushDoubleVariable(&RelativeVar);
493 }
494 else if( varType.GetBasicSize() == sizeof(long) ){
495 //32ビット型
496 PushLongVariable(&RelativeVar);
497 }
498 else if( varType.IsInteger() ){
499 PushIntegerVariable(&RelativeVar);
500 }
501 else if( varType.IsWord() ){
502 PushWordVariable(&RelativeVar);
503 }
504 else if( varType.IsSByte() ){
505 PushCharVariable(&RelativeVar);
506 }
507 else if( varType.IsByte() || varType.IsBoolean() ){
508 PushByteVariable(&RelativeVar);
509 }
510 else SetError(11,term,cp);
511
512 if( Is64Type(type_stack[sp])
513 && varType.IsWhole()
514 && varType.GetBasicSize()<=sizeof(long)){
515 //必要に応じて64ビット拡張
516 ExtendStackTo64( varType.GetBasicType() );
517 }
518
519 sp++;
520 break;
521 }
522
523
524 //////////////
525 // 定数の場合
526 //////////////
527
528 i3 = CDBConst::obj.GetType(term);
529 if(i3){
530 type_stack[sp]=i3;
531 if(IsRealNumberType(i3)){
532 //実数
533 double dbl = CDBConst::obj.GetDoubleData(term);
534 memcpy(&i64data,&dbl,sizeof(double));
535 goto Literal;
536 }
537 else if(IsWholeNumberType(i3)){
538 //整数
539 i64data = CDBConst::obj.GetWholeData(term);
540 goto Literal;
541 }
542 /*else if(i3==DEF_STRING){
543 //リテラル文字列
544
545 //バイト数
546 i3=(int)dbl;
547
548 memcpy(term,temporary,i3);
549 goto StrLiteral;
550 }*/
551 else{
552 SetError(300,NULL,cp);
553 goto error;
554 }
555 }
556
557
558 //////////////
559 // 型名の場合
560 //////////////
561 Type tempType;
562 if( Type::StringToType( term, tempType ) ){
563 type_stack[sp] = tempType.GetBasicType() | FLAG_CAST;
564 index_stack[sp] = tempType.GetIndex();
565 sp++;
566 break;
567 }
568
569
570 /////////////////////////////////
571 // プロパティ用のメソッド
572 /////////////////////////////////
573
574 //配列要素を排除
575 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
576 GetArrayElement(term,VarName,ArrayElements);
577
578 if(GetSubHash(VarName,0)){
579 Type resultType;
580 CallPropertyMethod(term,NULL,resultType);
581
582 //大きな型への暗黙の変換
583 type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
584 index_stack[sp]=resultType.GetIndex();
585 bLiteralCalculation=0;
586
587 //スタックへプッシュ
588 PushReturnValue( resultType.GetBasicType() );
589
590 if(type_stack[sp]==DEF_STRUCT){
591 //構造体が戻ったときはヒープ領域にインスタンスが格納されている
592 //※後にfreeする必要あり
593 bUseHeap[sp]=1;
594 }
595
596 sp++;
597 break;
598 }
599
600
601
602 //該当する識別子が見当たらないときはエラー扱いにする
603 bError=1;
604 SetError(3,term,cp);
605 type_stack[sp]=DEF_DOUBLE;
606 }
607 else{
608 //リテラル値
609 type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
610Literal:
611 if(type_stack[sp]==DEF_INT64||
612 type_stack[sp]==DEF_QWORD||
613 type_stack[sp]==DEF_DOUBLE){
614 //64ビット(符号有り整数/実数)
615
616 //push HILONG(dbl)
617 op_push_V((long)*(long *)(((char *)(&i64data))+4));
618
619 //push LOLONG(dbl)
620 op_push_V(*(long *)(&i64data));
621 }
622 else if(type_stack[sp]==DEF_SINGLE){
623 //single実数
624
625 float flt;
626 memcpy(&dbl,&i64data,sizeof(double));
627 flt=(float)dbl;
628 memcpy(&i3,&flt,sizeof(long));
629
630 //push term
631 op_push_V(i3);
632 }
633 else{
634 //その他
635
636 //push term
637 op_push_V((long)i64data);
638
639 if((long)i64data==0) index_stack[sp]=LITERAL_NULL;
640 }
641
642
643 //リテラル値の種類
644 if(Is64Type(type_stack[sp])==0&&IsRealNumberType(type_stack[sp])==0){
645 //整数(符号有り/無し)
646
647 index_stack[sp]=GetLiteralIndex(i64data);
648 }
649 }
650 sp++;
651 break;
652
653 //論理演算子
654 case CALC_XOR:
655 //value[sp-2] xor= value[sp-1]
656 //xor演算
657 if(!Calc_Xor(type_stack,index_stack,&sp)) goto error;
658 break;
659 case CALC_OR:
660 //value[sp-2] or= value[sp-1]
661 //or演算
662 if(!Calc_Or(type_stack,index_stack,&sp)) goto error;
663 break;
664 case CALC_AND:
665 //value[sp-2] and= value[sp-1]
666 //and演算
667 if(!Calc_And(type_stack,index_stack,&sp)) goto error;
668 break;
669 case CALC_NOT:
670 //value[sp-1]=Not value[sp-1]
671 //NOT演算子
672 if(!Calc_Not(type_stack,sp)) goto error;
673 break;
674
675 //比較演算子
676 case CALC_PE:
677 //value[sp-2]<=value[sp-1]
678 if(!Calc_Relation_PE(type_stack,index_stack,&sp)) goto error;
679 break;
680 case CALC_QE:
681 //value[sp-2]>=value[sp-1]
682 if(!Calc_Relation_QE(type_stack,index_stack,&sp)) goto error;
683 break;
684 case CALC_P:
685 //value[sp-2]<value[sp-1]
686 if(!Calc_Relation_P(type_stack,index_stack,&sp)) goto error;
687 break;
688 case CALC_Q:
689 //value[sp-2]>value[sp-1]
690 if(!Calc_Relation_Q(type_stack,index_stack,&sp)) goto error;
691 break;
692 case CALC_NOTEQUAL:
693 //value[sp-2]<>value[sp-1]
694 if(!Calc_Relation_NotEqual(type_stack,&sp)) goto error;
695 break;
696 case CALC_EQUAL:
697 //value[sp-2]=value[sp-1]
698 if(!Calc_Relation_Equal(type_stack,&sp)) goto error;
699 break;
700
701 //ビットシフト
702 case CALC_SHL:
703 //value[sp-2]=value[sp-2]<<value[sp-1]
704 if(!Calc_SHL(type_stack,&sp)) goto error;
705 break;
706 case CALC_SHR:
707 //value[sp-2]=value[sp-2]>>value[sp-1]
708 if(!Calc_SHR(type_stack,&sp)) goto error;
709 break;
710
711 //算術演算
712 case CALC_ADDITION:
713 case CALC_SUBTRACTION:
714 case CALC_PRODUCT:
715 if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
716 break;
717
718 case CALC_MOD:
719 //value[sp-2]%=value[sp-1]
720 //剰余演算
721 if(!Calc_Mod(type_stack,&sp)) goto error;
722 break;
723 case CALC_QUOTIENT:
724 //value[sp-2]/=value[sp-1];
725 //除算
726 if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
727 break;
728 case CALC_INTQUOTIENT:
729 //value[sp-2]/=value[sp-1]
730 //整数除算
731 if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
732 break;
733 case CALC_MINUSMARK:
734 //value[sp-1]=-value[sp-1]
735 //符号反転
736 if(!Calc_MinusMark(type_stack,sp)) goto error;
737 index_stack[sp-1]=-1;
738 break;
739 case CALC_POWER:
740 //べき乗演算(浮動小数点演算のみ)
741 if(!Calc_Power(type_stack,&sp)) goto error;
742 break;
743 case CALC_AS:
744 //キャスト
745 if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
746 break;
747
748 case CALC_BYVAL:
749 //ポインタ型→参照型
750 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
751 //ポインタ型ではないとき
752 SetError( 3, NULL, cp );
753 goto error;
754 }
755
756 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
757
758 break;
759
760 default:
761 SetError(300,NULL,cp);
762 goto error;
763 }
764 }
765
766 if(bError) goto error;
767
768 if(sp!=1){
769 SetError(1,NULL,cp);
770 goto error;
771 }
772
773 if(bLiteralCalculation){
774 //右辺値が数値の定数式の場合
775 Type resultType;
776 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
777
778 obp=BeforeObp;
779 pobj_SubAddrSchedule->num=Before_ProcAddrScheduleNum;
780 pobj_DataTableSchedule->num=Before_DataTableScheduleNum;
781 pobj_Reloc->copy(pobj_BackReloc);
782
783 if( resultType.GetBasicSize() == sizeof(_int64) ){
784 //64ビット(符号有り整数/実数)
785
786 //push HILONG(i64data)
787 op_push_V((long)*(long *)(((char *)(&i64data))+4));
788
789 //push LOLONG(i64data)
790 op_push_V(*(long *)(&i64data));
791 }
792 else if( resultType.IsSingle() ){
793 //single実数
794
795 memcpy(&dbl,&i64data,sizeof(_int64));
796
797 float flt;
798 flt=(float)dbl;
799 memcpy(&i3,&flt,sizeof(long));
800
801 //push flt
802 op_push_V(i3);
803 }
804 else{
805 //整数(符号有り/無し)
806
807 i3=(long)i64data;
808
809 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF;
810 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF;
811
812 //push term
813 op_push_V(i3);
814 }
815
816 type_stack[0]=resultType.GetBasicType();
817 index_stack[0]=resultType.GetIndex();
818 }
819 else{
820 //右辺値が数値の定数式ではないとき
821 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
822 }
823
824 if(pbUseHeap) *pbUseHeap=bUseHeap[0];
825
826 resultType.SetType( type_stack[0], index_stack[0] );
827
828 bool isSuccessful = true;
829 goto finish;
830
831
832error:
833 isSuccessful = false;
834 goto finish;
835
836
837finish:
838
839 for(i=0;i<pnum;i++){
840 if(values[i]) HeapDefaultFree(values[i]);
841 }
842
843 //再配置スケジュールバックアップ情報を解放
844 delete pobj_BackReloc;
845
846 return isSuccessful;
847}
Note: See TracBrowser for help on using the repository browser.