source: dev/BasicCompiler32/NumOpe.cpp@ 93

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

"a=[10,20,30]" などのように、リテラルバイナリデータを指定できるようにした。

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