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