[3] | 1 | #include "../BasicCompiler_Common/common.h"
|
---|
| 2 | #include "Opcode.h"
|
---|
| 3 |
|
---|
| 4 | void 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] | 69 | void 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] | 86 | bool 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 | }
|
---|
[94] | 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 | }
|
---|
[79] | 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;
|
---|
[3] | 244 |
|
---|
[79] | 245 | continue;
|
---|
| 246 | }
|
---|
[3] | 247 | }
|
---|
| 248 |
|
---|
[76] | 249 | if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
|
---|
[3] | 250 | }
|
---|
| 251 |
|
---|
| 252 | switch(idCalc){
|
---|
| 253 | //数値
|
---|
| 254 | case 0:
|
---|
| 255 | index_stack[sp]=-1;
|
---|
[79] | 256 | isNothing_stack[sp] = false;
|
---|
[3] | 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);
|
---|
| 269 | StrLiteral:
|
---|
| 270 |
|
---|
[76] | 271 | if( baseType.IsObject() ){
|
---|
| 272 | if( baseType.IsStringObject() ){
|
---|
| 273 | //要求タイプがStringのとき
|
---|
[3] | 274 |
|
---|
| 275 | //String型オブジェクトを生成
|
---|
| 276 | NewStringObject(term);
|
---|
| 277 |
|
---|
| 278 | extern CClass *pobj_StringClass;
|
---|
[76] | 279 | type_stack[sp]=DEF_OBJECT;
|
---|
[3] | 280 | index_stack[sp]=(LONG_PTR)pobj_StringClass;
|
---|
| 281 | bLiteralCalculation=0;
|
---|
| 282 |
|
---|
| 283 | sp++;
|
---|
| 284 | break;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 |
|
---|
[76] | 289 | type_stack[sp]=typeOfPtrChar;
|
---|
[3] | 290 | bLiteralCalculation=0;
|
---|
| 291 |
|
---|
[56] | 292 | i2=dataTable.AddString(term,i3);
|
---|
[3] | 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;
|
---|
[76] | 328 | int idProc=GetProc(temporary,(void **)&pInfo);
|
---|
[3] | 329 |
|
---|
[76] | 330 | Type resultType;
|
---|
[3] | 331 | if(idProc){
|
---|
[49] | 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 | }
|
---|
[3] | 342 |
|
---|
| 343 | ////////////////
|
---|
| 344 | // 呼び出し
|
---|
| 345 | ////////////////
|
---|
| 346 |
|
---|
[76] | 347 | CallProc(idProc,pInfo,temporary,temp2,resultType);
|
---|
| 348 | if(resultType.IsNull()){
|
---|
[3] | 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 | //大きな型への暗黙の変換
|
---|
[76] | 367 | type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
|
---|
| 368 | index_stack[sp] = resultType.GetIndex();
|
---|
[3] | 369 | bLiteralCalculation=0;
|
---|
| 370 |
|
---|
| 371 | //スタックへプッシュ
|
---|
[76] | 372 | PushReturnValue( resultType.GetBasicType() );
|
---|
[3] | 373 |
|
---|
[76] | 374 | if( Is64Type(type_stack[sp])
|
---|
| 375 | && resultType.IsWhole()
|
---|
| 376 | && resultType.GetBasicSize() <= sizeof(long) ){
|
---|
| 377 | //必要に応じて64ビット拡張
|
---|
| 378 | ExtendStackTo64( resultType.GetBasicType() );
|
---|
[3] | 379 | }
|
---|
| 380 |
|
---|
[76] | 381 | if( resultType.IsStruct() ){
|
---|
[64] | 382 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
[3] | 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 | //マクロ関数の場合
|
---|
[76] | 399 | NumOpe(temp3,Type(),resultType);
|
---|
[3] | 400 |
|
---|
[76] | 401 | if(!IS_LITERAL(resultType.GetIndex())){
|
---|
[3] | 402 | //リテラル値ではなかったとき
|
---|
| 403 | bLiteralCalculation=0;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[76] | 406 | type_stack[sp] = resultType.GetBasicType();
|
---|
| 407 | index_stack[sp] = resultType.GetIndex();
|
---|
| 408 |
|
---|
[3] | 409 | sp++;
|
---|
| 410 | break;
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
[49] | 413 | NonProc:
|
---|
[3] | 414 |
|
---|
| 415 |
|
---|
[76] | 416 | //インデクサ(getアクセサ)
|
---|
[3] | 417 | char variable[VN_SIZE],array_element[VN_SIZE];
|
---|
| 418 | GetArrayElement(term,variable,array_element);
|
---|
| 419 | if(array_element[0]){
|
---|
[76] | 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();
|
---|
[3] | 426 | bLiteralCalculation=0;
|
---|
| 427 |
|
---|
| 428 | //push eax
|
---|
| 429 | op_push(REG_EAX);
|
---|
| 430 |
|
---|
| 431 | sp++;
|
---|
| 432 | break;
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 |
|
---|
[67] | 437 | // Nothing
|
---|
| 438 | if( lstrcmp( term, "Nothing" ) == 0 ){
|
---|
[79] | 439 | isNothing_stack[sp] = true;
|
---|
| 440 |
|
---|
[76] | 441 | type_stack[sp] = DEF_OBJECT;
|
---|
| 442 | if( baseType.IsObject() ){
|
---|
| 443 | index_stack[sp] = baseType.GetIndex();
|
---|
[67] | 444 | }
|
---|
| 445 | else{
|
---|
| 446 | index_stack[sp] = (LONG_PTR)pobj_DBClass->GetObjectClass();
|
---|
| 447 | }
|
---|
[3] | 448 |
|
---|
[67] | 449 | bLiteralCalculation = 0;
|
---|
| 450 |
|
---|
| 451 | //push 0
|
---|
| 452 | op_push_V( 0 );
|
---|
| 453 |
|
---|
| 454 | sp++;
|
---|
| 455 | break;
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[3] | 458 | RELATIVE_VAR RelativeVar;
|
---|
[76] | 459 | Type varType;
|
---|
[11] | 460 | if(GetVarOffset(
|
---|
| 461 | false, //エラー表示あり
|
---|
| 462 | false, //読み込み専用
|
---|
[76] | 463 | term,
|
---|
| 464 | &RelativeVar,varType)){
|
---|
[3] | 465 | //////////
|
---|
| 466 | // 変数
|
---|
| 467 | //////////
|
---|
| 468 |
|
---|
| 469 | //大きな型への暗黙の変換
|
---|
[76] | 470 | type_stack[sp]=AutoBigCast(baseType.GetBasicType(),varType.GetBasicType());
|
---|
| 471 | index_stack[sp] = varType.GetIndex();
|
---|
[3] | 472 | bLiteralCalculation=0;
|
---|
| 473 |
|
---|
[76] | 474 | if(varType.GetBasicType()&FLAG_PTR){
|
---|
[3] | 475 | //配列ポインタ
|
---|
[76] | 476 | type_stack[sp]=GetPtrType(varType.GetBasicType()^FLAG_PTR);
|
---|
[3] | 477 |
|
---|
| 478 | SetVarPtrToEax(&RelativeVar);
|
---|
| 479 |
|
---|
| 480 | //push eax
|
---|
| 481 | op_push(REG_EAX);
|
---|
| 482 | }
|
---|
[76] | 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) ){
|
---|
[3] | 491 | //64ビット型
|
---|
| 492 | PushDoubleVariable(&RelativeVar);
|
---|
| 493 | }
|
---|
[76] | 494 | else if( varType.GetBasicSize() == sizeof(long) ){
|
---|
[3] | 495 | //32ビット型
|
---|
| 496 | PushLongVariable(&RelativeVar);
|
---|
| 497 | }
|
---|
[76] | 498 | else if( varType.IsInteger() ){
|
---|
[3] | 499 | PushIntegerVariable(&RelativeVar);
|
---|
| 500 | }
|
---|
[76] | 501 | else if( varType.IsWord() ){
|
---|
[3] | 502 | PushWordVariable(&RelativeVar);
|
---|
| 503 | }
|
---|
[76] | 504 | else if( varType.IsSByte() ){
|
---|
[3] | 505 | PushCharVariable(&RelativeVar);
|
---|
| 506 | }
|
---|
[76] | 507 | else if( varType.IsByte() || varType.IsBoolean() ){
|
---|
[3] | 508 | PushByteVariable(&RelativeVar);
|
---|
| 509 | }
|
---|
[64] | 510 | else SetError(11,term,cp);
|
---|
[3] | 511 |
|
---|
[76] | 512 | if( Is64Type(type_stack[sp])
|
---|
| 513 | && varType.IsWhole()
|
---|
| 514 | && varType.GetBasicSize()<=sizeof(long)){
|
---|
[3] | 515 | //必要に応じて64ビット拡張
|
---|
[76] | 516 | ExtendStackTo64( varType.GetBasicType() );
|
---|
[3] | 517 | }
|
---|
| 518 |
|
---|
| 519 | sp++;
|
---|
| 520 | break;
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 |
|
---|
| 524 | //////////////
|
---|
| 525 | // 定数の場合
|
---|
| 526 | //////////////
|
---|
| 527 |
|
---|
[8] | 528 | i3 = CDBConst::obj.GetType(term);
|
---|
| 529 | if(i3){
|
---|
[76] | 530 | type_stack[sp]=i3;
|
---|
[3] | 531 | if(IsRealNumberType(i3)){
|
---|
| 532 | //実数
|
---|
[8] | 533 | double dbl = CDBConst::obj.GetDoubleData(term);
|
---|
[3] | 534 | memcpy(&i64data,&dbl,sizeof(double));
|
---|
| 535 | goto Literal;
|
---|
| 536 | }
|
---|
| 537 | else if(IsWholeNumberType(i3)){
|
---|
| 538 | //整数
|
---|
[8] | 539 | i64data = CDBConst::obj.GetWholeData(term);
|
---|
[3] | 540 | goto Literal;
|
---|
| 541 | }
|
---|
[8] | 542 | /*else if(i3==DEF_STRING){
|
---|
[3] | 543 | //リテラル文字列
|
---|
| 544 |
|
---|
| 545 | //バイト数
|
---|
| 546 | i3=(int)dbl;
|
---|
| 547 |
|
---|
| 548 | memcpy(term,temporary,i3);
|
---|
| 549 | goto StrLiteral;
|
---|
[8] | 550 | }*/
|
---|
[3] | 551 | else{
|
---|
| 552 | SetError(300,NULL,cp);
|
---|
| 553 | goto error;
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 |
|
---|
| 558 | //////////////
|
---|
| 559 | // 型名の場合
|
---|
| 560 | //////////////
|
---|
[79] | 561 | Type tempType;
|
---|
| 562 | if( Type::StringToType( term, tempType ) ){
|
---|
| 563 | type_stack[sp] = tempType.GetBasicType() | FLAG_CAST;
|
---|
| 564 | index_stack[sp] = tempType.GetIndex();
|
---|
[3] | 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)){
|
---|
[76] | 579 | Type resultType;
|
---|
| 580 | CallPropertyMethod(term,NULL,resultType);
|
---|
[3] | 581 |
|
---|
| 582 | //大きな型への暗黙の変換
|
---|
[76] | 583 | type_stack[sp]=AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
|
---|
| 584 | index_stack[sp]=resultType.GetIndex();
|
---|
[3] | 585 | bLiteralCalculation=0;
|
---|
| 586 |
|
---|
| 587 | //スタックへプッシュ
|
---|
[76] | 588 | PushReturnValue( resultType.GetBasicType() );
|
---|
[3] | 589 |
|
---|
[76] | 590 | if(type_stack[sp]==DEF_STRUCT){
|
---|
[64] | 591 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
[3] | 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);
|
---|
[76] | 605 | type_stack[sp]=DEF_DOUBLE;
|
---|
[3] | 606 | }
|
---|
| 607 | else{
|
---|
| 608 | //リテラル値
|
---|
[76] | 609 | type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
|
---|
[3] | 610 | Literal:
|
---|
[76] | 611 | if(type_stack[sp]==DEF_INT64||
|
---|
| 612 | type_stack[sp]==DEF_QWORD||
|
---|
| 613 | type_stack[sp]==DEF_DOUBLE){
|
---|
[3] | 614 | //64ビット(符号有り整数/実数)
|
---|
| 615 |
|
---|
| 616 | //push HILONG(dbl)
|
---|
[67] | 617 | op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
[3] | 618 |
|
---|
| 619 | //push LOLONG(dbl)
|
---|
[67] | 620 | op_push_V(*(long *)(&i64data));
|
---|
[3] | 621 | }
|
---|
[76] | 622 | else if(type_stack[sp]==DEF_SINGLE){
|
---|
[3] | 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
|
---|
[67] | 631 | op_push_V(i3);
|
---|
[3] | 632 | }
|
---|
| 633 | else{
|
---|
| 634 | //その他
|
---|
| 635 |
|
---|
| 636 | //push term
|
---|
[67] | 637 | op_push_V((long)i64data);
|
---|
[3] | 638 |
|
---|
| 639 | if((long)i64data==0) index_stack[sp]=LITERAL_NULL;
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 |
|
---|
| 643 | //リテラル値の種類
|
---|
[76] | 644 | if(Is64Type(type_stack[sp])==0&&IsRealNumberType(type_stack[sp])==0){
|
---|
[3] | 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演算
|
---|
[76] | 657 | if(!Calc_Xor(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 658 | break;
|
---|
| 659 | case CALC_OR:
|
---|
| 660 | //value[sp-2] or= value[sp-1]
|
---|
| 661 | //or演算
|
---|
[76] | 662 | if(!Calc_Or(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 663 | break;
|
---|
| 664 | case CALC_AND:
|
---|
| 665 | //value[sp-2] and= value[sp-1]
|
---|
| 666 | //and演算
|
---|
[76] | 667 | if(!Calc_And(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 668 | break;
|
---|
| 669 | case CALC_NOT:
|
---|
| 670 | //value[sp-1]=Not value[sp-1]
|
---|
| 671 | //NOT演算子
|
---|
[76] | 672 | if(!Calc_Not(type_stack,sp)) goto error;
|
---|
[3] | 673 | break;
|
---|
| 674 |
|
---|
| 675 | //比較演算子
|
---|
| 676 | case CALC_PE:
|
---|
| 677 | //value[sp-2]<=value[sp-1]
|
---|
[76] | 678 | if(!Calc_Relation_PE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 679 | break;
|
---|
| 680 | case CALC_QE:
|
---|
| 681 | //value[sp-2]>=value[sp-1]
|
---|
[76] | 682 | if(!Calc_Relation_QE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 683 | break;
|
---|
| 684 | case CALC_P:
|
---|
| 685 | //value[sp-2]<value[sp-1]
|
---|
[76] | 686 | if(!Calc_Relation_P(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 687 | break;
|
---|
| 688 | case CALC_Q:
|
---|
| 689 | //value[sp-2]>value[sp-1]
|
---|
[76] | 690 | if(!Calc_Relation_Q(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 691 | break;
|
---|
| 692 | case CALC_NOTEQUAL:
|
---|
| 693 | //value[sp-2]<>value[sp-1]
|
---|
[76] | 694 | if(!Calc_Relation_NotEqual(type_stack,&sp)) goto error;
|
---|
[3] | 695 | break;
|
---|
| 696 | case CALC_EQUAL:
|
---|
| 697 | //value[sp-2]=value[sp-1]
|
---|
[76] | 698 | if(!Calc_Relation_Equal(type_stack,&sp)) goto error;
|
---|
[3] | 699 | break;
|
---|
| 700 |
|
---|
| 701 | //ビットシフト
|
---|
| 702 | case CALC_SHL:
|
---|
| 703 | //value[sp-2]=value[sp-2]<<value[sp-1]
|
---|
[76] | 704 | if(!Calc_SHL(type_stack,&sp)) goto error;
|
---|
[3] | 705 | break;
|
---|
| 706 | case CALC_SHR:
|
---|
| 707 | //value[sp-2]=value[sp-2]>>value[sp-1]
|
---|
[76] | 708 | if(!Calc_SHR(type_stack,&sp)) goto error;
|
---|
[3] | 709 | break;
|
---|
| 710 |
|
---|
| 711 | //算術演算
|
---|
| 712 | case CALC_ADDITION:
|
---|
| 713 | case CALC_SUBTRACTION:
|
---|
| 714 | case CALC_PRODUCT:
|
---|
[76] | 715 | if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 716 | break;
|
---|
| 717 |
|
---|
| 718 | case CALC_MOD:
|
---|
| 719 | //value[sp-2]%=value[sp-1]
|
---|
| 720 | //剰余演算
|
---|
[76] | 721 | if(!Calc_Mod(type_stack,&sp)) goto error;
|
---|
[3] | 722 | break;
|
---|
| 723 | case CALC_QUOTIENT:
|
---|
| 724 | //value[sp-2]/=value[sp-1];
|
---|
| 725 | //除算
|
---|
[76] | 726 | if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
|
---|
[3] | 727 | break;
|
---|
| 728 | case CALC_INTQUOTIENT:
|
---|
| 729 | //value[sp-2]/=value[sp-1]
|
---|
| 730 | //整数除算
|
---|
[76] | 731 | if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 732 | break;
|
---|
| 733 | case CALC_MINUSMARK:
|
---|
| 734 | //value[sp-1]=-value[sp-1]
|
---|
| 735 | //符号反転
|
---|
[76] | 736 | if(!Calc_MinusMark(type_stack,sp)) goto error;
|
---|
[3] | 737 | index_stack[sp-1]=-1;
|
---|
| 738 | break;
|
---|
| 739 | case CALC_POWER:
|
---|
| 740 | //べき乗演算(浮動小数点演算のみ)
|
---|
[76] | 741 | if(!Calc_Power(type_stack,&sp)) goto error;
|
---|
[3] | 742 | break;
|
---|
| 743 | case CALC_AS:
|
---|
| 744 | //キャスト
|
---|
[76] | 745 | if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 746 | break;
|
---|
| 747 |
|
---|
[41] | 748 | case CALC_BYVAL:
|
---|
| 749 | //ポインタ型→参照型
|
---|
[76] | 750 | if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
|
---|
[41] | 751 | //ポインタ型ではないとき
|
---|
| 752 | SetError( 3, NULL, cp );
|
---|
| 753 | goto error;
|
---|
| 754 | }
|
---|
| 755 |
|
---|
[76] | 756 | type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
|
---|
[41] | 757 |
|
---|
| 758 | break;
|
---|
| 759 |
|
---|
[3] | 760 | default:
|
---|
| 761 | SetError(300,NULL,cp);
|
---|
[41] | 762 | goto error;
|
---|
[3] | 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 | //右辺値が数値の定数式の場合
|
---|
[76] | 775 | Type resultType;
|
---|
| 776 | StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
|
---|
[3] | 777 |
|
---|
| 778 | obp=BeforeObp;
|
---|
| 779 | pobj_SubAddrSchedule->num=Before_ProcAddrScheduleNum;
|
---|
| 780 | pobj_DataTableSchedule->num=Before_DataTableScheduleNum;
|
---|
| 781 | pobj_Reloc->copy(pobj_BackReloc);
|
---|
| 782 |
|
---|
[76] | 783 | if( resultType.GetBasicSize() == sizeof(_int64) ){
|
---|
[3] | 784 | //64ビット(符号有り整数/実数)
|
---|
| 785 |
|
---|
| 786 | //push HILONG(i64data)
|
---|
[67] | 787 | op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
[3] | 788 |
|
---|
| 789 | //push LOLONG(i64data)
|
---|
[67] | 790 | op_push_V(*(long *)(&i64data));
|
---|
[3] | 791 | }
|
---|
[76] | 792 | else if( resultType.IsSingle() ){
|
---|
[3] | 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
|
---|
[67] | 802 | op_push_V(i3);
|
---|
[3] | 803 | }
|
---|
| 804 | else{
|
---|
| 805 | //整数(符号有り/無し)
|
---|
| 806 |
|
---|
| 807 | i3=(long)i64data;
|
---|
| 808 |
|
---|
[76] | 809 | if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF;
|
---|
| 810 | if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF;
|
---|
[3] | 811 |
|
---|
| 812 | //push term
|
---|
[67] | 813 | op_push_V(i3);
|
---|
[3] | 814 | }
|
---|
| 815 |
|
---|
[76] | 816 | type_stack[0]=resultType.GetBasicType();
|
---|
| 817 | index_stack[0]=resultType.GetIndex();
|
---|
[3] | 818 | }
|
---|
| 819 | else{
|
---|
| 820 | //右辺値が数値の定数式ではないとき
|
---|
| 821 | if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
|
---|
| 822 | }
|
---|
| 823 |
|
---|
| 824 | if(pbUseHeap) *pbUseHeap=bUseHeap[0];
|
---|
| 825 |
|
---|
[76] | 826 | resultType.SetType( type_stack[0], index_stack[0] );
|
---|
| 827 |
|
---|
| 828 | bool isSuccessful = true;
|
---|
[3] | 829 | goto finish;
|
---|
| 830 |
|
---|
| 831 |
|
---|
| 832 | error:
|
---|
[76] | 833 | isSuccessful = false;
|
---|
[3] | 834 | goto finish;
|
---|
| 835 |
|
---|
| 836 |
|
---|
| 837 | finish:
|
---|
| 838 |
|
---|
| 839 | for(i=0;i<pnum;i++){
|
---|
| 840 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
| 841 | }
|
---|
| 842 |
|
---|
| 843 | //再配置スケジュールバックアップ情報を解放
|
---|
| 844 | delete pobj_BackReloc;
|
---|
| 845 |
|
---|
[76] | 846 | return isSuccessful;
|
---|
[3] | 847 | }
|
---|