[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 |
|
---|
[117] | 79 | Operator_New( *pobj_DBClass->GetStringClassPtr(), "", parameter, Type( DEF_OBJECT, *pobj_DBClass->GetStringClassPtr() ) );
|
---|
[3] | 80 |
|
---|
[64] | 81 | free( parameter );
|
---|
[3] | 82 | }
|
---|
| 83 |
|
---|
[97] | 84 | void ExtendRegToBigType( int reg, int bigBasicType, int baseBasicType ){
|
---|
| 85 | if( reg != REG_EAX ){
|
---|
| 86 | SetError();
|
---|
| 87 | }
|
---|
| 88 | switch( Type::GetBasicSize( bigBasicType ) ){
|
---|
| 89 | case sizeof(_int64):
|
---|
| 90 | ExtendTypeTo64(baseBasicType);
|
---|
| 91 | break;
|
---|
| 92 | case sizeof(long):
|
---|
| 93 | ExtendTypeTo32(baseBasicType,reg);
|
---|
| 94 | break;
|
---|
| 95 | case sizeof(short):
|
---|
| 96 | ExtendTypeTo16(baseBasicType,reg);
|
---|
| 97 | break;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
[3] | 100 |
|
---|
[97] | 101 |
|
---|
| 102 |
|
---|
| 103 | bool VarToReg( RELATIVE_VAR &relativeVar, const Type &baseType, Type &resultType ){
|
---|
| 104 | const int useReg = REG_EAX;
|
---|
| 105 |
|
---|
| 106 | //大きな型への暗黙の変換
|
---|
| 107 | int bigType = AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
|
---|
| 108 |
|
---|
| 109 | if(resultType.GetBasicType()&FLAG_PTR){
|
---|
| 110 | //配列ポインタ
|
---|
| 111 | resultType.SetBasicType( GetPtrType(resultType.GetBasicType()^FLAG_PTR) );
|
---|
| 112 |
|
---|
| 113 | SetVarPtrToReg(useReg, &relativeVar);
|
---|
| 114 | }
|
---|
| 115 | else if( resultType.IsStruct() ){
|
---|
| 116 | //構造体ポインタをeaxへ格納(構造体は値型)
|
---|
| 117 | SetVarPtrToReg(useReg, &relativeVar);
|
---|
| 118 | }
|
---|
| 119 | else if( resultType.IsReal() ){
|
---|
| 120 | // 実数
|
---|
| 121 | SetReg_RealVariable( resultType.GetBasicType(), &relativeVar );
|
---|
| 122 | }
|
---|
| 123 | else if( resultType.IsWhole() || resultType.IsObject()){
|
---|
| 124 | //整数型
|
---|
| 125 | SetReg_WholeVariable(resultType.GetBasicType(),&relativeVar,useReg);
|
---|
| 126 | }
|
---|
| 127 | else if( resultType.IsStruct() ){
|
---|
| 128 | //構造体ポインタをUseRegへ格納(構造体は値型)
|
---|
| 129 | SetVarPtrToReg(useReg,&relativeVar);
|
---|
| 130 | }
|
---|
| 131 | else{
|
---|
| 132 | return false;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | if( resultType.GetBasicType() != bigType ){
|
---|
| 136 | // 大きな型へ変換された場合
|
---|
| 137 | // ※レジスタの値をキャストする
|
---|
| 138 | ExtendRegToBigType( useReg, bigType, resultType.GetBasicType() );
|
---|
| 139 |
|
---|
| 140 | resultType.SetBasicType( bigType );
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | return true;
|
---|
| 144 | }
|
---|
| 145 | bool TermMemberOpe( const CClass &objClass, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member ){
|
---|
| 146 | const int useReg = REG_EAX;
|
---|
| 147 |
|
---|
| 148 | if( GetMemberType( objClass, member, resultType, 0, false ) ){
|
---|
| 149 | // メンバが見つかったとき
|
---|
| 150 |
|
---|
| 151 | //オブジェクトポインタをecxにコピー
|
---|
| 152 | op_mov_RR( REG_ECX, useReg );
|
---|
| 153 |
|
---|
| 154 | RELATIVE_VAR relativeVar;
|
---|
| 155 | relativeVar.dwKind=VAR_DIRECTMEM;
|
---|
| 156 |
|
---|
| 157 | if( !_member_offset(
|
---|
| 158 | true, //エラー表示あり
|
---|
| 159 | false, //読み込み専用
|
---|
| 160 | objClass,
|
---|
| 161 | member,&relativeVar,resultType,0)){
|
---|
| 162 | return false;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | if( !VarToReg( relativeVar, baseType, resultType ) ){
|
---|
| 166 | SetError(11,termFull,cp);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | return true;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | ///////////////////////////////////////////////////////////////////
|
---|
| 174 | // 動的メソッドを検索
|
---|
| 175 | ///////////////////////////////////////////////////////////////////
|
---|
| 176 | vector<UserProc *> userProcs;
|
---|
| 177 |
|
---|
| 178 | char methodName[VN_SIZE], lpPtrOffset[VN_SIZE], parameter[VN_SIZE], dummy[1];
|
---|
| 179 | CClass::RefType refType;
|
---|
| 180 | lstrcpy( methodName, member );
|
---|
| 181 | GetVarFormatString(methodName,parameter,lpPtrOffset,dummy,refType);
|
---|
| 182 |
|
---|
| 183 | objClass.EnumMethod( methodName, userProcs );
|
---|
| 184 | UserProc *pUserProc;
|
---|
| 185 | if(userProcs.size()){
|
---|
| 186 | //オーバーロードを解決
|
---|
| 187 | pUserProc=OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
|
---|
| 188 |
|
---|
| 189 | if( pUserProc ){
|
---|
| 190 |
|
---|
| 191 | resultType = pUserProc->ReturnType();
|
---|
| 192 |
|
---|
| 193 | {
|
---|
| 194 | //オブジェクトポインタをスタックに入れておく
|
---|
| 195 | //push reg
|
---|
| 196 | op_push( useReg );
|
---|
| 197 |
|
---|
| 198 | if( !Opcode_CallProc(parameter,pUserProc,PROCFLAG_NEW,termLeft,0 ) ){
|
---|
| 199 |
|
---|
| 200 | return false;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | op_pop();
|
---|
| 204 |
|
---|
| 205 | /////////////////////
|
---|
| 206 | // 戻り値の処理
|
---|
| 207 | /////////////////////
|
---|
| 208 |
|
---|
| 209 | //大きな型への暗黙の変換
|
---|
| 210 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 211 |
|
---|
| 212 | if( resultType.GetBasicType() != bigType ){
|
---|
| 213 | // 大きな型へ変換された場合
|
---|
| 214 | // ※レジスタの値をキャストする
|
---|
| 215 | ExtendRegToBigType( REG_EAX, bigType, resultType.GetBasicType() );
|
---|
| 216 |
|
---|
| 217 | resultType.SetBasicType( bigType );
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | return true;
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | return false;
|
---|
| 228 | }
|
---|
| 229 | bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName = NULL ){
|
---|
| 230 | char parameter[VN_SIZE];
|
---|
| 231 |
|
---|
| 232 | // Withを解決
|
---|
| 233 | char termFull[VN_SIZE];
|
---|
| 234 | if(term[0]=='.'){
|
---|
| 235 | GetWithName(termFull);
|
---|
| 236 | lstrcat(termFull,term);
|
---|
| 237 | }
|
---|
| 238 | else lstrcpy(termFull,term);
|
---|
| 239 |
|
---|
| 240 | char termLeft[VN_SIZE];
|
---|
| 241 | lstrcpy(termLeft,termFull);
|
---|
| 242 |
|
---|
| 243 | // パース
|
---|
| 244 | char member[VN_SIZE];
|
---|
| 245 | CClass::RefType refType;
|
---|
| 246 | if( SplitMemberName( termFull, termLeft, member, refType ) ){
|
---|
| 247 | ///////////////////////////////////////////////////////////////////
|
---|
| 248 | // オブジェクトとメンバに分解できるとき
|
---|
| 249 | // termLeft.member
|
---|
| 250 | ///////////////////////////////////////////////////////////////////
|
---|
| 251 |
|
---|
| 252 | isLiteral = false;
|
---|
| 253 |
|
---|
| 254 | // オブジェクト側の型を取得
|
---|
| 255 | bool isClassName = false;
|
---|
| 256 | Type leftType;
|
---|
| 257 | if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){
|
---|
[103] | 258 | goto globalArea;
|
---|
[97] | 259 | }
|
---|
| 260 |
|
---|
| 261 | if( isClassName ){
|
---|
| 262 | // 静的メンバ/メソッドの場合
|
---|
| 263 | goto globalArea;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | if( !leftType.HasMember() ){
|
---|
| 267 | // メンバを持たない型の場合
|
---|
| 268 | return false;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | return TermMemberOpe( leftType.GetClass(), baseType, resultType, termFull, termLeft, member );
|
---|
| 272 | }
|
---|
[106] | 273 | globalArea:
|
---|
[97] | 274 |
|
---|
| 275 |
|
---|
| 276 | //////////////////////////////////////////////
|
---|
| 277 | // クラス名かどうかをチェック(静的メンバ用)
|
---|
| 278 | //////////////////////////////////////////////
|
---|
| 279 |
|
---|
| 280 | if( pIsClassName ){
|
---|
[102] | 281 | if( pobj_DBClass->Find( termFull ) ){
|
---|
[97] | 282 | *pIsClassName = true;
|
---|
| 283 | return true;
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /////////////////////////////////////////////////////////////////
|
---|
| 289 | // グローバル属性エリア
|
---|
| 290 | /////////////////////////////////////////////////////////////////
|
---|
| 291 |
|
---|
| 292 | const int useReg = REG_EAX;
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 | if(lstrcmpi(termFull,"This")==0){
|
---|
| 296 | //Thisオブジェクト
|
---|
| 297 | resultType.SetType( DEF_OBJECT, pobj_CompilingClass );
|
---|
| 298 |
|
---|
| 299 | SetThisPtrToReg( useReg );
|
---|
| 300 |
|
---|
| 301 | isLiteral = false;
|
---|
| 302 |
|
---|
| 303 | return true;
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 |
|
---|
| 307 | //////////////////////////////////////
|
---|
| 308 | // 関数(DLL、ユーザー定義、組み込み)
|
---|
| 309 | //////////////////////////////////////
|
---|
| 310 | char procName[VN_SIZE];
|
---|
| 311 | char temporary[8192];
|
---|
| 312 |
|
---|
| 313 | int i2=GetCallProcName(termFull,procName);
|
---|
| 314 | if(termFull[i2]=='('){
|
---|
| 315 | int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
|
---|
| 316 |
|
---|
| 317 | void *pInfo;
|
---|
| 318 | int idProc=GetProc(procName,(void **)&pInfo);
|
---|
| 319 |
|
---|
| 320 | if(idProc){
|
---|
| 321 | //閉じカッコ")"に続く文字がNULLでないとき
|
---|
| 322 | if(termFull[i2+1+i4+1]!='\0'){
|
---|
| 323 | SetError(42,NULL,cp);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | {
|
---|
| 328 | ////////////////
|
---|
| 329 | // 呼び出し
|
---|
| 330 | ////////////////
|
---|
| 331 |
|
---|
| 332 | CallProc(idProc,pInfo,procName,parameter,resultType);
|
---|
| 333 |
|
---|
| 334 |
|
---|
| 335 | /////////////////////
|
---|
| 336 | // 戻り値の処理
|
---|
| 337 | /////////////////////
|
---|
| 338 |
|
---|
| 339 | //大きな型への暗黙の変換
|
---|
| 340 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 341 |
|
---|
| 342 | /*
|
---|
| 343 | ※後でNumOpe内でプッシュする
|
---|
| 344 | //スタックへプッシュ
|
---|
| 345 | PushReturnValue( resultType.GetBasicType() );
|
---|
| 346 | */
|
---|
| 347 |
|
---|
| 348 | if( resultType.GetBasicType() != bigType ){
|
---|
| 349 | // 大きな型へ変換された場合
|
---|
| 350 | // ※レジスタの値をキャストする
|
---|
| 351 | ExtendRegToBigType( useReg, bigType, resultType.GetBasicType() );
|
---|
| 352 |
|
---|
| 353 | resultType.SetBasicType( bigType );
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | if(resultType.IsStruct()){
|
---|
| 361 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
| 362 | //※後にfreeする必要あり
|
---|
| 363 | // TODO: 解放はGCに任せる
|
---|
| 364 | *pbUseHeap = 1;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | isLiteral = false;
|
---|
| 368 |
|
---|
| 369 | return true;
|
---|
| 370 | }
|
---|
| 371 | else if(GetConstCalcBuffer(procName,parameter,temporary)){
|
---|
| 372 | /////////////////////////
|
---|
| 373 | // マクロ関数
|
---|
| 374 | /////////////////////////
|
---|
| 375 |
|
---|
| 376 | //閉じカッコ")"に続く文字がNULLでないときはエラーにする
|
---|
| 377 | if(termFull[i2+1+i4+1]!='\0') SetError(42,NULL,cp);
|
---|
| 378 |
|
---|
| 379 | //マクロ関数の場合
|
---|
| 380 | NumOpe(useReg, temporary,Type(),resultType);
|
---|
| 381 |
|
---|
| 382 | if(!IS_LITERAL(resultType.GetIndex())){
|
---|
| 383 | //リテラル値ではなかったとき
|
---|
| 384 | isLiteral = false;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | return true;
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | ////////////////////////////////
|
---|
| 393 | // インデクサ(getアクセサ)
|
---|
| 394 | ////////////////////////////////
|
---|
| 395 |
|
---|
| 396 | char VarName[VN_SIZE],ArrayElements[VN_SIZE];
|
---|
| 397 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
| 398 | if(ArrayElements[0]){
|
---|
| 399 | GetVarType(VarName,resultType,false);
|
---|
| 400 | if( resultType.IsObject() ){
|
---|
| 401 | CallIndexerGetterProc(/*UseReg,*/&resultType.GetClass(),VarName,ArrayElements,resultType);
|
---|
| 402 |
|
---|
| 403 | isLiteral = false;
|
---|
| 404 |
|
---|
| 405 | return true;
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 |
|
---|
| 410 | ////////////////////////////////
|
---|
| 411 | // 変数
|
---|
| 412 | ////////////////////////////////
|
---|
| 413 |
|
---|
| 414 | RELATIVE_VAR relativeVar;
|
---|
| 415 | if(GetVarOffset(
|
---|
| 416 | false, //エラー表示なし
|
---|
| 417 | false, //読み込み専用
|
---|
| 418 | termFull,
|
---|
| 419 | &relativeVar,resultType)){
|
---|
| 420 | //////////
|
---|
| 421 | // 変数
|
---|
| 422 | //////////
|
---|
| 423 |
|
---|
| 424 | if( !VarToReg( relativeVar, baseType, resultType ) ){
|
---|
| 425 | SetError(11,termFull,cp);
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | isLiteral = false;
|
---|
| 429 |
|
---|
| 430 | return true;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 | /////////////////////////////////
|
---|
| 435 | // プロパティ用のメソッド
|
---|
| 436 | /////////////////////////////////
|
---|
| 437 |
|
---|
| 438 | //配列要素を排除
|
---|
| 439 | GetArrayElement(termFull,VarName,ArrayElements);
|
---|
| 440 |
|
---|
| 441 | if(GetSubHash(VarName,0)){
|
---|
| 442 |
|
---|
| 443 | {
|
---|
| 444 | CallPropertyMethod(termFull,NULL,resultType);
|
---|
| 445 |
|
---|
| 446 | //大きな型への暗黙の変換
|
---|
| 447 | int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
|
---|
| 448 |
|
---|
| 449 | if( resultType.GetBasicType() != bigType ){
|
---|
| 450 | // 大きな型へ変換された場合
|
---|
| 451 | // ※レジスタの値をキャストする
|
---|
| 452 | ExtendRegToBigType( REG_EAX, bigType, resultType.GetBasicType() );
|
---|
| 453 |
|
---|
| 454 | resultType.SetBasicType( bigType );
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | //SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
|
---|
| 458 | }
|
---|
| 459 |
|
---|
| 460 |
|
---|
| 461 | if(resultType.IsStruct()){
|
---|
| 462 | //構造体が戻ったときはヒープ領域にインスタンスが格納されている
|
---|
| 463 | //※後にfreeする必要あり
|
---|
| 464 | // TODO: 解放はGCに任せる
|
---|
| 465 | *pbUseHeap = 1;
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | isLiteral = false;
|
---|
| 469 |
|
---|
| 470 | return true;
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 |
|
---|
| 474 | return false;
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 |
|
---|
| 478 | bool NumOpe( int reg,
|
---|
| 479 | const char *expression,
|
---|
| 480 | const Type &baseType,
|
---|
| 481 | Type &resultType,
|
---|
| 482 | BOOL *pbUseHeap ){
|
---|
| 483 |
|
---|
| 484 | if( !NumOpe( expression, baseType, resultType, pbUseHeap ) ){
|
---|
| 485 | return false;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | if( reg != REG_EAX ){
|
---|
| 489 | // TODO: 未実装
|
---|
| 490 | SetError();
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | if( resultType.IsReal() ){
|
---|
| 494 | //fld ptr[esp]
|
---|
| 495 | op_fld_ptr_esp( resultType.GetBasicType() );
|
---|
| 496 |
|
---|
| 497 | //add esp,size
|
---|
| 498 | op_add_esp( resultType.GetBasicSize() );
|
---|
| 499 | }
|
---|
| 500 | else{
|
---|
| 501 | //pop eax
|
---|
| 502 | op_pop(REG_EAX);
|
---|
| 503 |
|
---|
| 504 | if( resultType.Is64() ){
|
---|
| 505 | //pop edx
|
---|
| 506 | op_pop(REG_EDX);
|
---|
| 507 | }
|
---|
| 508 | }
|
---|
| 509 | return true;
|
---|
| 510 | }
|
---|
[76] | 511 | bool NumOpe( const char *expression,
|
---|
| 512 | const Type &baseType,
|
---|
| 513 | Type &resultType,
|
---|
| 514 | BOOL *pbUseHeap ){
|
---|
| 515 |
|
---|
[97] | 516 | int i,i2,i3;
|
---|
| 517 | char temporary[1024],temp2[1024];
|
---|
[3] | 518 |
|
---|
[76] | 519 | if(expression[0]=='\0'){
|
---|
[3] | 520 | SetError(1,NULL,cp);
|
---|
[76] | 521 | return false;
|
---|
[3] | 522 | }
|
---|
| 523 |
|
---|
[76] | 524 | if(expression[0]==1&& expression[1]==ESC_NEW ){
|
---|
[3] | 525 | //New演算子(オブジェクト生成)
|
---|
[64] | 526 |
|
---|
[76] | 527 | if( !Operator_New( expression+2, baseType, resultType ) ){
|
---|
| 528 | return false;
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | return true;
|
---|
[3] | 532 | }
|
---|
| 533 |
|
---|
[93] | 534 | if( !baseType.IsNull() && expression[0] == '[' ){
|
---|
| 535 | // リテラル配列の場合
|
---|
[3] | 536 |
|
---|
[93] | 537 | if( !baseType.IsPointer() ){
|
---|
| 538 | SetError(1,NULL,cp);
|
---|
| 539 | return false;
|
---|
| 540 | }
|
---|
| 541 | Type tempBaseType( baseType );
|
---|
| 542 | tempBaseType.PtrLevelDown();
|
---|
| 543 |
|
---|
| 544 | char *buffer = (char *)malloc( lstrlen( expression ) + 1 );
|
---|
| 545 | lstrcpy( buffer, expression );
|
---|
| 546 | RemoveStringBracket( buffer );
|
---|
| 547 |
|
---|
| 548 | void *binary = malloc( 1 );
|
---|
| 549 | int num = 0;
|
---|
| 550 |
|
---|
| 551 | i = 0;
|
---|
| 552 | while( buffer[i] ){
|
---|
| 553 | i = GetOneParameter( buffer, i, temporary );
|
---|
| 554 | if( buffer[i] == ',' ){
|
---|
| 555 | i++;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | Type resultType;
|
---|
| 559 | _int64 i64data;
|
---|
| 560 | if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
|
---|
| 561 | return false;
|
---|
| 562 | }
|
---|
| 563 | if( !resultType.IsWhole() ){
|
---|
| 564 | // TODO: 実数に未対応
|
---|
| 565 | SetError();
|
---|
| 566 | return false;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
|
---|
| 570 | memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
|
---|
| 571 | num++;
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | i2 = dataTable.AddBinary( binary, num * tempBaseType.GetSize() );
|
---|
| 575 |
|
---|
| 576 | //mov eax,i2
|
---|
| 577 | op_mov_RV(REG_EAX,i2);
|
---|
| 578 | obp-=sizeof(long);
|
---|
| 579 | pobj_DataTableSchedule->add();
|
---|
| 580 | obp+=sizeof(long);
|
---|
| 581 |
|
---|
| 582 | free( buffer );
|
---|
| 583 |
|
---|
| 584 | resultType = baseType;
|
---|
| 585 |
|
---|
| 586 | //push eax
|
---|
| 587 | op_push( REG_EAX );
|
---|
| 588 |
|
---|
| 589 | return true;
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 |
|
---|
[3] | 593 | /////////////////////////////////
|
---|
| 594 | // 式要素を逆ポーランド式で取得
|
---|
| 595 | /////////////////////////////////
|
---|
| 596 |
|
---|
| 597 | char *values[255];
|
---|
| 598 | long calc[255];
|
---|
| 599 | long stack[255];
|
---|
| 600 | int pnum;
|
---|
[76] | 601 | if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
|
---|
[3] | 602 | for(i=0;i<pnum;i++){
|
---|
| 603 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
| 604 | }
|
---|
[76] | 605 | return false;
|
---|
[3] | 606 | }
|
---|
| 607 |
|
---|
| 608 |
|
---|
| 609 | BOOL bError;
|
---|
| 610 | bError=0;
|
---|
| 611 |
|
---|
| 612 | //リテラル値のみの計算かどうかを判別するためのフラグ
|
---|
| 613 | BOOL bLiteralCalculation=1;
|
---|
| 614 |
|
---|
| 615 | //リテラル演算の場合を考慮した演算前のバッファ位置
|
---|
| 616 | int BeforeObp;
|
---|
| 617 | BeforeObp=obp;
|
---|
| 618 |
|
---|
| 619 | //リテラル演算の場合を考慮した演算前のプロシージャスケジュール位置
|
---|
| 620 | //※64ビットの掛け算、除算などで特殊関数が呼ばれるため
|
---|
| 621 | int Before_ProcAddrScheduleNum;
|
---|
| 622 | Before_ProcAddrScheduleNum=pobj_SubAddrSchedule->num;
|
---|
| 623 |
|
---|
| 624 | //リテラル演算の場合を考慮した演算前のデータテーブルスケジュール位置
|
---|
| 625 | int Before_DataTableScheduleNum;
|
---|
| 626 | Before_DataTableScheduleNum=pobj_DataTableSchedule->num;
|
---|
| 627 |
|
---|
| 628 | //リテラル演算の場合を考慮した演算前の再配置スケジュール
|
---|
| 629 | CReloc *pobj_BackReloc;
|
---|
| 630 | pobj_BackReloc=new CReloc();
|
---|
| 631 | pobj_BackReloc->copy(pobj_Reloc);
|
---|
| 632 |
|
---|
| 633 | double dbl;
|
---|
| 634 | int sp;
|
---|
[76] | 635 | int type_stack[255];
|
---|
[79] | 636 | bool isNothing_stack[255];
|
---|
[3] | 637 | LONG_PTR index_stack[255];
|
---|
| 638 | BOOL bUseHeap[255];
|
---|
| 639 | _int64 i64data;
|
---|
| 640 | for(i=0,sp=0;i<pnum;i++){
|
---|
| 641 | int idCalc;
|
---|
| 642 | idCalc=calc[i]%100;
|
---|
| 643 |
|
---|
| 644 | if(idCalc){
|
---|
[76] | 645 | if(type_stack[sp-2]==DEF_OBJECT){
|
---|
[79] | 646 | if( idCalc == CALC_AS
|
---|
| 647 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
| 648 | && index_stack[sp-1] == index_stack[sp-2]
|
---|
| 649 | || isNothing_stack[sp-2] ){
|
---|
| 650 | // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
|
---|
[3] | 651 | }
|
---|
[94] | 652 | else if( idCalc == CALC_AS
|
---|
| 653 | && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
|
---|
| 654 | && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
|
---|
| 655 | )){
|
---|
| 656 | // ダウンキャストを許可する
|
---|
| 657 | }
|
---|
[79] | 658 | else{
|
---|
| 659 | //オーバーロードされたオペレータを呼び出す
|
---|
| 660 | i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,bUseHeap,sp);
|
---|
| 661 | if(i2==0){
|
---|
| 662 | if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
|
---|
| 663 | else GetCalcName(idCalc,temp2);
|
---|
| 664 | sprintf(temporary,"Operator %s",temp2);
|
---|
| 665 | SetError(27,temporary,cp);
|
---|
| 666 | goto error;
|
---|
| 667 | }
|
---|
| 668 | else if(i2==-1) goto error;
|
---|
[3] | 669 |
|
---|
[79] | 670 | continue;
|
---|
| 671 | }
|
---|
[3] | 672 | }
|
---|
| 673 |
|
---|
[76] | 674 | if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
|
---|
[3] | 675 | }
|
---|
| 676 |
|
---|
| 677 | switch(idCalc){
|
---|
| 678 | //数値
|
---|
| 679 | case 0:
|
---|
| 680 | index_stack[sp]=-1;
|
---|
[79] | 681 | isNothing_stack[sp] = false;
|
---|
[3] | 682 | bUseHeap[sp]=0;
|
---|
| 683 |
|
---|
| 684 | char *term;
|
---|
| 685 | term=values[i];
|
---|
| 686 |
|
---|
[97] | 687 | if( calc[i+1]%100 == CALC_AS ){
|
---|
| 688 | // As演算子の右辺値
|
---|
| 689 | //型名
|
---|
| 690 | if( Type::StringToType( term, resultType ) ){
|
---|
| 691 | resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
|
---|
| 692 | }
|
---|
| 693 | else{
|
---|
| 694 | SetError(3, term, cp );
|
---|
| 695 | goto error;
|
---|
| 696 | }
|
---|
| 697 |
|
---|
| 698 | type_stack[sp] = resultType.GetBasicType();
|
---|
| 699 | index_stack[sp] = resultType.GetIndex();
|
---|
| 700 | sp++;
|
---|
| 701 |
|
---|
| 702 | break;
|
---|
| 703 | }
|
---|
| 704 |
|
---|
[3] | 705 | if(term[0]=='\"'){
|
---|
| 706 | //リテラル文字列
|
---|
| 707 | if(!RemoveStringQuotes(term)){
|
---|
| 708 | SetError(43,NULL,cp);
|
---|
| 709 | goto error;
|
---|
| 710 | }
|
---|
| 711 | i3=lstrlen(term);
|
---|
| 712 | StrLiteral:
|
---|
| 713 |
|
---|
[97] | 714 | if( baseType.IsObject() || baseType.IsNull() ){
|
---|
| 715 | //要求タイプがオブジェクト、または未定のとき
|
---|
[3] | 716 |
|
---|
[97] | 717 | //String型オブジェクトを生成
|
---|
| 718 | NewStringObject(term);
|
---|
[3] | 719 |
|
---|
[97] | 720 | type_stack[sp]=DEF_OBJECT;
|
---|
[117] | 721 | index_stack[sp]=(LONG_PTR)pobj_DBClass->GetStringClassPtr();
|
---|
[97] | 722 | bLiteralCalculation=0;
|
---|
[3] | 723 |
|
---|
[97] | 724 | sp++;
|
---|
| 725 | break;
|
---|
[3] | 726 | }
|
---|
| 727 |
|
---|
| 728 |
|
---|
[76] | 729 | type_stack[sp]=typeOfPtrChar;
|
---|
[3] | 730 | bLiteralCalculation=0;
|
---|
| 731 |
|
---|
[56] | 732 | i2=dataTable.AddString(term,i3);
|
---|
[3] | 733 |
|
---|
| 734 | //push DataSize
|
---|
| 735 | OpBuffer[obp++]=(char)0x68;
|
---|
| 736 | *((long *)(OpBuffer+obp))=i2;
|
---|
| 737 | pobj_DataTableSchedule->add();
|
---|
| 738 | obp+=sizeof(long);
|
---|
| 739 | }
|
---|
| 740 | else if((term[0]=='e'||term[0]=='E')&&
|
---|
| 741 | (term[1]=='x'||term[1]=='X')&&
|
---|
| 742 | term[2]=='\"'){
|
---|
| 743 | //拡張版リテラル文字列(エスケープシーケンス可能)
|
---|
| 744 | if(!RemoveStringQuotes(term+2)){
|
---|
| 745 | SetError(43,NULL,cp);
|
---|
| 746 | goto error;
|
---|
| 747 | }
|
---|
| 748 | i3=FormatString_EscapeSequence(term+2);
|
---|
| 749 | term+=2;
|
---|
| 750 |
|
---|
| 751 | goto StrLiteral;
|
---|
| 752 | }
|
---|
| 753 | else if(IsVariableTopChar(term[0])||
|
---|
| 754 | term[0]=='*'||
|
---|
| 755 | (term[0]=='.'&&IsVariableTopChar(term[1]))){
|
---|
| 756 | //////////////////
|
---|
| 757 | // 何らかの識別子
|
---|
| 758 |
|
---|
[97] | 759 | bool isLiteral;
|
---|
| 760 | if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){
|
---|
| 761 | if(resultType.IsNull()){
|
---|
| 762 | //戻り値が存在しないとき
|
---|
| 763 | for(i2=0;;i2++){
|
---|
| 764 | if(term[i2]=='('||term[i2]=='\0'){
|
---|
| 765 | term[i2]=0;
|
---|
| 766 | break;
|
---|
[49] | 767 | }
|
---|
| 768 | }
|
---|
[97] | 769 | SetError(38,term,cp);
|
---|
[3] | 770 |
|
---|
[97] | 771 | goto error;
|
---|
| 772 | }
|
---|
[3] | 773 |
|
---|
[97] | 774 | type_stack[sp] = resultType.GetBasicType();
|
---|
| 775 | index_stack[sp] = resultType.GetIndex();
|
---|
[3] | 776 |
|
---|
[97] | 777 | if( !isLiteral ){
|
---|
[3] | 778 | bLiteralCalculation=0;
|
---|
[97] | 779 | }
|
---|
[3] | 780 |
|
---|
[97] | 781 | if( resultType.GetBasicType() & FLAG_CAST ){
|
---|
| 782 | // 型名のみ
|
---|
| 783 | SetError();
|
---|
| 784 | }
|
---|
| 785 | else{
|
---|
| 786 | if( resultType.IsReal() ){
|
---|
| 787 | //sub esp,size
|
---|
| 788 | //fstp ptr[esp]
|
---|
| 789 | op_fstp_push( resultType );
|
---|
[3] | 790 | }
|
---|
[97] | 791 | else{
|
---|
| 792 | if( resultType.Is64() ){
|
---|
| 793 | //push edx
|
---|
| 794 | op_push( REG_EDX );
|
---|
| 795 | }
|
---|
| 796 | else{
|
---|
| 797 | ExtendTypeTo32( resultType.GetBasicType(), REG_EAX );
|
---|
| 798 | }
|
---|
[3] | 799 |
|
---|
[97] | 800 | //push eax
|
---|
| 801 | op_push( REG_EAX );
|
---|
[3] | 802 | }
|
---|
| 803 | }
|
---|
| 804 |
|
---|
[97] | 805 | sp++;
|
---|
| 806 | break;
|
---|
[3] | 807 | }
|
---|
| 808 |
|
---|
| 809 |
|
---|
[67] | 810 | // Nothing
|
---|
| 811 | if( lstrcmp( term, "Nothing" ) == 0 ){
|
---|
[79] | 812 | isNothing_stack[sp] = true;
|
---|
| 813 |
|
---|
[76] | 814 | type_stack[sp] = DEF_OBJECT;
|
---|
| 815 | if( baseType.IsObject() ){
|
---|
| 816 | index_stack[sp] = baseType.GetIndex();
|
---|
[67] | 817 | }
|
---|
| 818 | else{
|
---|
[117] | 819 | index_stack[sp] = (LONG_PTR)pobj_DBClass->GetObjectClassPtr();
|
---|
[67] | 820 | }
|
---|
[3] | 821 |
|
---|
[67] | 822 | bLiteralCalculation = 0;
|
---|
| 823 |
|
---|
| 824 | //push 0
|
---|
| 825 | op_push_V( 0 );
|
---|
| 826 |
|
---|
| 827 | sp++;
|
---|
| 828 | break;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
[3] | 831 |
|
---|
| 832 | //////////////
|
---|
| 833 | // 定数の場合
|
---|
| 834 | //////////////
|
---|
| 835 |
|
---|
[103] | 836 | i3 = CDBConst::obj.GetBasicType(term);
|
---|
[8] | 837 | if(i3){
|
---|
[103] | 838 | if( CDBConst::obj.IsStringPtr( term ) ){
|
---|
| 839 | //リテラル文字列
|
---|
| 840 |
|
---|
| 841 | double dbl = CDBConst::obj.GetDoubleData(term);
|
---|
| 842 | memcpy(&i64data,&dbl,sizeof(double));
|
---|
| 843 |
|
---|
| 844 | //バイト数
|
---|
| 845 | i3=lstrlen((char *)i64data);
|
---|
| 846 |
|
---|
| 847 | memcpy(term,(char *)i64data,i3);
|
---|
| 848 | term[i3]=0;
|
---|
| 849 | goto StrLiteral;
|
---|
| 850 | }
|
---|
| 851 |
|
---|
[76] | 852 | type_stack[sp]=i3;
|
---|
[3] | 853 | if(IsRealNumberType(i3)){
|
---|
| 854 | //実数
|
---|
[8] | 855 | double dbl = CDBConst::obj.GetDoubleData(term);
|
---|
[3] | 856 | memcpy(&i64data,&dbl,sizeof(double));
|
---|
| 857 | goto Literal;
|
---|
| 858 | }
|
---|
| 859 | else if(IsWholeNumberType(i3)){
|
---|
| 860 | //整数
|
---|
[8] | 861 | i64data = CDBConst::obj.GetWholeData(term);
|
---|
[3] | 862 | goto Literal;
|
---|
| 863 | }
|
---|
| 864 | else{
|
---|
| 865 | SetError(300,NULL,cp);
|
---|
| 866 | goto error;
|
---|
| 867 | }
|
---|
| 868 | }
|
---|
| 869 |
|
---|
| 870 |
|
---|
| 871 | //該当する識別子が見当たらないときはエラー扱いにする
|
---|
| 872 | bError=1;
|
---|
| 873 | SetError(3,term,cp);
|
---|
[76] | 874 | type_stack[sp]=DEF_DOUBLE;
|
---|
[3] | 875 | }
|
---|
| 876 | else{
|
---|
| 877 | //リテラル値
|
---|
[76] | 878 | type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
|
---|
[3] | 879 | Literal:
|
---|
[76] | 880 | if(type_stack[sp]==DEF_INT64||
|
---|
| 881 | type_stack[sp]==DEF_QWORD||
|
---|
| 882 | type_stack[sp]==DEF_DOUBLE){
|
---|
[3] | 883 | //64ビット(符号有り整数/実数)
|
---|
| 884 |
|
---|
| 885 | //push HILONG(dbl)
|
---|
[67] | 886 | op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
[3] | 887 |
|
---|
| 888 | //push LOLONG(dbl)
|
---|
[67] | 889 | op_push_V(*(long *)(&i64data));
|
---|
[3] | 890 | }
|
---|
[76] | 891 | else if(type_stack[sp]==DEF_SINGLE){
|
---|
[3] | 892 | //single実数
|
---|
| 893 |
|
---|
| 894 | float flt;
|
---|
| 895 | memcpy(&dbl,&i64data,sizeof(double));
|
---|
| 896 | flt=(float)dbl;
|
---|
| 897 | memcpy(&i3,&flt,sizeof(long));
|
---|
| 898 |
|
---|
| 899 | //push term
|
---|
[67] | 900 | op_push_V(i3);
|
---|
[3] | 901 | }
|
---|
| 902 | else{
|
---|
| 903 | //その他
|
---|
| 904 |
|
---|
| 905 | //push term
|
---|
[67] | 906 | op_push_V((long)i64data);
|
---|
[3] | 907 |
|
---|
| 908 | if((long)i64data==0) index_stack[sp]=LITERAL_NULL;
|
---|
| 909 | }
|
---|
| 910 |
|
---|
| 911 |
|
---|
| 912 | //リテラル値の種類
|
---|
[76] | 913 | if(Is64Type(type_stack[sp])==0&&IsRealNumberType(type_stack[sp])==0){
|
---|
[3] | 914 | //整数(符号有り/無し)
|
---|
| 915 |
|
---|
| 916 | index_stack[sp]=GetLiteralIndex(i64data);
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 | sp++;
|
---|
| 920 | break;
|
---|
| 921 |
|
---|
| 922 | //論理演算子
|
---|
| 923 | case CALC_XOR:
|
---|
| 924 | //value[sp-2] xor= value[sp-1]
|
---|
| 925 | //xor演算
|
---|
[76] | 926 | if(!Calc_Xor(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 927 | break;
|
---|
| 928 | case CALC_OR:
|
---|
| 929 | //value[sp-2] or= value[sp-1]
|
---|
| 930 | //or演算
|
---|
[76] | 931 | if(!Calc_Or(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 932 | break;
|
---|
| 933 | case CALC_AND:
|
---|
| 934 | //value[sp-2] and= value[sp-1]
|
---|
| 935 | //and演算
|
---|
[76] | 936 | if(!Calc_And(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 937 | break;
|
---|
| 938 | case CALC_NOT:
|
---|
| 939 | //value[sp-1]=Not value[sp-1]
|
---|
| 940 | //NOT演算子
|
---|
[76] | 941 | if(!Calc_Not(type_stack,sp)) goto error;
|
---|
[3] | 942 | break;
|
---|
| 943 |
|
---|
| 944 | //比較演算子
|
---|
| 945 | case CALC_PE:
|
---|
| 946 | //value[sp-2]<=value[sp-1]
|
---|
[76] | 947 | if(!Calc_Relation_PE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 948 | break;
|
---|
| 949 | case CALC_QE:
|
---|
| 950 | //value[sp-2]>=value[sp-1]
|
---|
[76] | 951 | if(!Calc_Relation_QE(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 952 | break;
|
---|
| 953 | case CALC_P:
|
---|
| 954 | //value[sp-2]<value[sp-1]
|
---|
[76] | 955 | if(!Calc_Relation_P(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 956 | break;
|
---|
| 957 | case CALC_Q:
|
---|
| 958 | //value[sp-2]>value[sp-1]
|
---|
[76] | 959 | if(!Calc_Relation_Q(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 960 | break;
|
---|
| 961 | case CALC_NOTEQUAL:
|
---|
| 962 | //value[sp-2]<>value[sp-1]
|
---|
[76] | 963 | if(!Calc_Relation_NotEqual(type_stack,&sp)) goto error;
|
---|
[3] | 964 | break;
|
---|
| 965 | case CALC_EQUAL:
|
---|
| 966 | //value[sp-2]=value[sp-1]
|
---|
[76] | 967 | if(!Calc_Relation_Equal(type_stack,&sp)) goto error;
|
---|
[3] | 968 | break;
|
---|
| 969 |
|
---|
| 970 | //ビットシフト
|
---|
| 971 | case CALC_SHL:
|
---|
| 972 | //value[sp-2]=value[sp-2]<<value[sp-1]
|
---|
[76] | 973 | if(!Calc_SHL(type_stack,&sp)) goto error;
|
---|
[3] | 974 | break;
|
---|
| 975 | case CALC_SHR:
|
---|
| 976 | //value[sp-2]=value[sp-2]>>value[sp-1]
|
---|
[76] | 977 | if(!Calc_SHR(type_stack,&sp)) goto error;
|
---|
[3] | 978 | break;
|
---|
| 979 |
|
---|
| 980 | //算術演算
|
---|
| 981 | case CALC_ADDITION:
|
---|
| 982 | case CALC_SUBTRACTION:
|
---|
| 983 | case CALC_PRODUCT:
|
---|
[76] | 984 | if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 985 | break;
|
---|
| 986 |
|
---|
| 987 | case CALC_MOD:
|
---|
| 988 | //value[sp-2]%=value[sp-1]
|
---|
| 989 | //剰余演算
|
---|
[76] | 990 | if(!Calc_Mod(type_stack,&sp)) goto error;
|
---|
[3] | 991 | break;
|
---|
| 992 | case CALC_QUOTIENT:
|
---|
| 993 | //value[sp-2]/=value[sp-1];
|
---|
| 994 | //除算
|
---|
[76] | 995 | if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
|
---|
[3] | 996 | break;
|
---|
| 997 | case CALC_INTQUOTIENT:
|
---|
| 998 | //value[sp-2]/=value[sp-1]
|
---|
| 999 | //整数除算
|
---|
[76] | 1000 | if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1001 | break;
|
---|
| 1002 | case CALC_MINUSMARK:
|
---|
| 1003 | //value[sp-1]=-value[sp-1]
|
---|
| 1004 | //符号反転
|
---|
[76] | 1005 | if(!Calc_MinusMark(type_stack,sp)) goto error;
|
---|
[3] | 1006 | index_stack[sp-1]=-1;
|
---|
| 1007 | break;
|
---|
| 1008 | case CALC_POWER:
|
---|
| 1009 | //べき乗演算(浮動小数点演算のみ)
|
---|
[76] | 1010 | if(!Calc_Power(type_stack,&sp)) goto error;
|
---|
[3] | 1011 | break;
|
---|
| 1012 | case CALC_AS:
|
---|
| 1013 | //キャスト
|
---|
[76] | 1014 | if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
|
---|
[3] | 1015 | break;
|
---|
| 1016 |
|
---|
[41] | 1017 | case CALC_BYVAL:
|
---|
| 1018 | //ポインタ型→参照型
|
---|
[76] | 1019 | if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
|
---|
[41] | 1020 | //ポインタ型ではないとき
|
---|
| 1021 | SetError( 3, NULL, cp );
|
---|
| 1022 | goto error;
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
[76] | 1025 | type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
|
---|
[41] | 1026 |
|
---|
| 1027 | break;
|
---|
| 1028 |
|
---|
[3] | 1029 | default:
|
---|
| 1030 | SetError(300,NULL,cp);
|
---|
[41] | 1031 | goto error;
|
---|
[3] | 1032 | }
|
---|
| 1033 | }
|
---|
| 1034 |
|
---|
| 1035 | if(bError) goto error;
|
---|
| 1036 |
|
---|
| 1037 | if(sp!=1){
|
---|
| 1038 | SetError(1,NULL,cp);
|
---|
| 1039 | goto error;
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
| 1042 | if(bLiteralCalculation){
|
---|
| 1043 | //右辺値が数値の定数式の場合
|
---|
[76] | 1044 | Type resultType;
|
---|
| 1045 | StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
|
---|
[3] | 1046 |
|
---|
| 1047 | obp=BeforeObp;
|
---|
| 1048 | pobj_SubAddrSchedule->num=Before_ProcAddrScheduleNum;
|
---|
| 1049 | pobj_DataTableSchedule->num=Before_DataTableScheduleNum;
|
---|
| 1050 | pobj_Reloc->copy(pobj_BackReloc);
|
---|
| 1051 |
|
---|
[76] | 1052 | if( resultType.GetBasicSize() == sizeof(_int64) ){
|
---|
[3] | 1053 | //64ビット(符号有り整数/実数)
|
---|
| 1054 |
|
---|
| 1055 | //push HILONG(i64data)
|
---|
[67] | 1056 | op_push_V((long)*(long *)(((char *)(&i64data))+4));
|
---|
[3] | 1057 |
|
---|
| 1058 | //push LOLONG(i64data)
|
---|
[67] | 1059 | op_push_V(*(long *)(&i64data));
|
---|
[3] | 1060 | }
|
---|
[76] | 1061 | else if( resultType.IsSingle() ){
|
---|
[3] | 1062 | //single実数
|
---|
| 1063 |
|
---|
| 1064 | memcpy(&dbl,&i64data,sizeof(_int64));
|
---|
| 1065 |
|
---|
| 1066 | float flt;
|
---|
| 1067 | flt=(float)dbl;
|
---|
| 1068 | memcpy(&i3,&flt,sizeof(long));
|
---|
| 1069 |
|
---|
| 1070 | //push flt
|
---|
[67] | 1071 | op_push_V(i3);
|
---|
[3] | 1072 | }
|
---|
| 1073 | else{
|
---|
| 1074 | //整数(符号有り/無し)
|
---|
| 1075 |
|
---|
| 1076 | i3=(long)i64data;
|
---|
| 1077 |
|
---|
[76] | 1078 | if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF;
|
---|
| 1079 | if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF;
|
---|
[3] | 1080 |
|
---|
| 1081 | //push term
|
---|
[67] | 1082 | op_push_V(i3);
|
---|
[3] | 1083 | }
|
---|
| 1084 |
|
---|
[76] | 1085 | type_stack[0]=resultType.GetBasicType();
|
---|
| 1086 | index_stack[0]=resultType.GetIndex();
|
---|
[3] | 1087 | }
|
---|
| 1088 | else{
|
---|
| 1089 | //右辺値が数値の定数式ではないとき
|
---|
| 1090 | if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
|
---|
| 1091 | }
|
---|
| 1092 |
|
---|
| 1093 | if(pbUseHeap) *pbUseHeap=bUseHeap[0];
|
---|
| 1094 |
|
---|
[76] | 1095 | resultType.SetType( type_stack[0], index_stack[0] );
|
---|
| 1096 |
|
---|
| 1097 | bool isSuccessful = true;
|
---|
[3] | 1098 | goto finish;
|
---|
| 1099 |
|
---|
| 1100 |
|
---|
| 1101 | error:
|
---|
[76] | 1102 | isSuccessful = false;
|
---|
[3] | 1103 | goto finish;
|
---|
| 1104 |
|
---|
| 1105 |
|
---|
| 1106 | finish:
|
---|
| 1107 |
|
---|
| 1108 | for(i=0;i<pnum;i++){
|
---|
| 1109 | if(values[i]) HeapDefaultFree(values[i]);
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
| 1112 | //再配置スケジュールバックアップ情報を解放
|
---|
| 1113 | delete pobj_BackReloc;
|
---|
| 1114 |
|
---|
[76] | 1115 | return isSuccessful;
|
---|
[3] | 1116 | }
|
---|