source: dev/trunk/ab5.0/abdev/compiler_x64/NumOpe.cpp@ 676

Last change on this file since 676 was 676, checked in by dai_9181, 16 years ago

If/While/Doなどのステートメントに引き渡す式の戻り値がクラス型の場合はBoolean型へのキャストを試みるようにした。

File size: 37.7 KB
RevLine 
[206]1#include "stdafx.h"
2
[183]3#include <Compiler.h>
4
[3]5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
[598]8using namespace ActiveBasic::Compiler;
9
[76]10void NewStringObject(int reg, const char *str){
[3]11 ///////////////////////////////////////////////////////
12 // lpszTextを元にStringオブジェクトを生成し、
13 // オブジェクトポインタをregに格納する
14 ///////////////////////////////////////////////////////
15
16
17 //////////////////////////////////////////////////////
18 ///// レジスタ資源のバックアップ
19 { BACKUP_REGISTER_RESOURCE
20 //////////////////////////////////////////////////////
21
[76]22 char *parameter = (char *)malloc( lstrlen( str ) + 32 );
[319]23 sprintf( parameter, "%s%c%c*Char", str, 1, ESC_AS );
[64]24
[266]25 Operator_New( *compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr(), "", parameter, Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() ) );
[3]26
[64]27 free( parameter );
[3]28
[64]29 //mov reg,rax
[226]30 compiler.codeGenerator.op_mov_RR( reg, REG_RAX );
[3]31
32 /////////////////////////////////////////////
33 ////// レジスタ資源を復元
34 RESTORE_REGISTER_RESOURCE
35 }////////////////////////////////////////////
36}
37
38void SetUseRegFromRax(int type,int UseReg,int XmmReg){
39 if(IsRealNumberType(type)){
40 //実数型
41 if(XmmReg==REG_XMM4){
42 if(type==DEF_DOUBLE){
43 //movsd qword ptr[rsp+offset],xmm0 ※スタックフレームを利用
44 pobj_sf->push(REG_XMM0,sizeof(double));
45 }
46 if(type==DEF_SINGLE){
47 //movss dword ptr[rsp+offset],xmm0 ※スタックフレームを利用
48 pobj_sf->push(REG_XMM0,sizeof(float));
49 }
50 }
51 else{
52 if(type==DEF_DOUBLE){
53 //movsd xmm_reg,xmm0
[226]54 compiler.codeGenerator.op_movsd_RR(XmmReg,REG_XMM0);
[3]55 }
56 else if(type==DEF_SINGLE){
57 //movss xmm_reg,xmm0
[226]58 compiler.codeGenerator.op_movss_RR(XmmReg,REG_XMM0);
[3]59 }
60 }
61 }
62 else{
63 //整数型
64 if(UseReg==REG_R14){
65 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用
66 pobj_sf->push(REG_RAX);
67 }
68 else{
69 //mov reg,rax
[226]70 compiler.codeGenerator.op_mov_RR(UseReg,REG_RAX);
[3]71 }
72 }
73}
74
[75]75void ExtendRegToBigType( int reg, int bigBasicType, int baseBasicType ){
76 switch( Type::GetBasicSize( bigBasicType ) ){
77 case sizeof(_int64):
78 ExtendTypeTo64(baseBasicType,reg);
79 break;
80 case sizeof(long):
81 ExtendTypeTo32(baseBasicType,reg);
82 break;
83 case sizeof(short):
84 ExtendTypeTo16(baseBasicType,reg);
85 break;
86 }
87}
88
[97]89
90bool VarToReg( RELATIVE_VAR &relativeVar, const Type &baseType, Type &resultType ){
91 int UseReg=pobj_reg->GetNextReg();
92 int XmmReg=pobj_reg->GetNextXmmReg();
93
94 //大きな型への暗黙の変換
95 int bigType = AutoBigCast(baseType.GetBasicType(),resultType.GetBasicType());
96
97 if(resultType.GetBasicType()&FLAG_PTR){
98 //配列ポインタ
99 resultType.SetBasicType( GetPtrType(resultType.GetBasicType()^FLAG_PTR) );
100
101 SetVarPtrToReg(UseReg,&relativeVar);
102 }
103 else if(resultType.IsReal()){
104 //実数型
105 if( resultType.IsDouble() )
106 SetXmmReg_DoubleVariable(&relativeVar,XmmReg);
107 if( resultType.IsSingle() )
108 SetXmmReg_SingleVariable(&relativeVar,XmmReg);
109 }
110 else if( resultType.IsWhole() || resultType.IsObject()){
111 //整数型
[308]112 SetReg_WholeVariable(resultType,&relativeVar,UseReg);
[97]113 }
114 else if( resultType.IsStruct() ){
115 //構造体ポインタをUseRegへ格納(構造体は値型)
116 SetVarPtrToReg(UseReg,&relativeVar);
117 }
118 else{
119 return false;
120 }
121
122 if( resultType.GetBasicType() != bigType ){
123 // 大きな型へ変換された場合
124 // ※レジスタの値をキャストする
125 ExtendRegToBigType( UseReg, bigType, resultType.GetBasicType() );
126
127 resultType.SetBasicType( bigType );
128 }
129
130 return true;
131}
[436]132bool TermMemberOpe( const Type &leftType, bool &isNeedHeapFreeStructure, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )
[308]133{
134 const CClass &objClass = leftType.GetClass();
[97]135
[339]136 const int useReg=pobj_reg->GetNextReg();
137 const int xmmReg=pobj_reg->GetNextXmmReg();
[97]138
139
[339]140 ////////////////////////////////
141 // インデクサ(getアクセサ)
142 ////////////////////////////////
143 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
144 GetArrayElement(member,VarName,ArrayElements);
145 if(ArrayElements[0]){
146 Type classType;
[399]147 if( VarName[0] == '\0' )
148 {
149 classType = leftType;
[405]150
151 if( classType.IsObject() )
152 {
153 // 既にuseRegにオブジェクトポインタが格納されており、それに対するインデクサを呼び出す場合
154 // ※「プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す」場合にここにくる
155
156 // オブジェクトメンバのポインタは既にraxに入っている
157 }
[399]158 }
159 else
160 {
161 GetMemberType( leftType, VarName, classType, 0, false );
[339]162
[405]163 if( classType.IsObject() )
[399]164 {
[405]165 //オブジェクトポインタをr11にコピー
166 compiler.codeGenerator.op_mov_RR( REG_R11, useReg );
167
[416]168 RELATIVE_VAR tempRelativeVar;
169 tempRelativeVar.dwKind=VAR_DIRECTMEM;
[339]170
[399]171 if( !_member_offset(
172 true, //エラー表示あり
173 false, //読み込み専用
174 leftType,
[416]175 VarName,&tempRelativeVar,classType,0)){
176 return false;
[399]177 }
178
179 // オブジェクトメンバのポインタをraxにコピー
[416]180 if( !VarToReg( tempRelativeVar, baseType, resultType ) ){
[468]181 compiler.errorMessenger.Output(11,termFull,cp);
[399]182 }
183 }
[405]184 }
[339]185
[405]186 if( classType.IsObject() )
187 {
[339]188 //////////////////////////////////////////////////////
189 ///// レジスタ資源のバックアップ
190 { BACKUP_REGISTER_RESOURCE
191 //////////////////////////////////////////////////////
192
193 //オブジェクトポインタをスタックに入れておく
194 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
195 pobj_sf->push( useReg );
196
197 char objectFullName[VN_SIZE], dummyArrayElements[VN_SIZE];
198 GetArrayElement(termFull,objectFullName,dummyArrayElements);
199
200 CallIndexerGetterProc(useReg,classType,objectFullName, ArrayElements,resultType, PROCFLAG_NEW );
201
202 pobj_sf->pop();
203
204 /////////////////////////////////////////////
205 ////// レジスタ資源を復元
206 RESTORE_REGISTER_RESOURCE
207 }////////////////////////////////////////////
208
209 return true;
210 }
211 }
212
213
214 ///////////////////////////////////////////////////////////////////
215 // メンバを検索
216 ///////////////////////////////////////////////////////////////////
[308]217 if( GetMemberType( leftType, member, resultType, 0, false ) ){
[97]218 // メンバが見つかったとき
219
[436]220 if( isNeedHeapFreeStructure )
221 {
222 if( !leftType.IsStruct() )
223 {
[468]224 compiler.errorMessenger.OutputFatalError();
[436]225 }
226
227 pobj_reg->LockReg();
228
229 // 親となる構造体が一時メモリに存在していた場合、後ほど解放する必要がある
230 compiler.codeGenerator.op_AddNeedFreeTempStructure( useReg );
231 isNeedHeapFreeStructure = false;
232
233 pobj_reg->UnlockReg();
234 }
235
[97]236 //オブジェクトポインタをr11にコピー
[339]237 compiler.codeGenerator.op_mov_RR( REG_R11, useReg );
[97]238
239 relativeVar.dwKind=VAR_DIRECTMEM;
240
241 if( !_member_offset(
242 true, //エラー表示あり
243 false, //読み込み専用
[316]244 leftType,
[97]245 member,&relativeVar,resultType,0)){
246 return false;
247 }
248
[416]249 // 変数として扱う
250 isVariable = true;
[97]251
252 return true;
253 }
254
255
256 ///////////////////////////////////////////////////////////////////
257 // 動的メソッドを検索
258 ///////////////////////////////////////////////////////////////////
[528]259 std::vector<const UserProc *> userProcs;
[97]260
261 char methodName[VN_SIZE], lpPtrOffset[VN_SIZE], parameter[VN_SIZE], dummy[1];
[206]262 ReferenceKind refType;
[430]263 PareOrBracket pareOrBracket = None;
[97]264 lstrcpy( methodName, member );
[430]265 GetVarFormatString( methodName, parameter, lpPtrOffset, dummy, refType, &pareOrBracket );
[97]266
[350]267 objClass.EnumDynamicMethodsOrInterfaceMethods( methodName, userProcs );
[97]268 if(userProcs.size()){
269 //オーバーロードを解決
[206]270 const UserProc *pUserProc = OverloadSolutionWithStrParam(termFull,userProcs,parameter,termLeft);
[97]271
[399]272 if( pUserProc )
273 {
[405]274 if(
275 pUserProc->Params().size() == 0 // 仮引数の個数は0
276 && parameter[0] // 実引数は1つ以上
277 && pUserProc->ReturnType().IsObject() // 戻り値がクラス型の場合
[430]278 && pareOrBracket == Bracket ) // 実引数は[]で囲まれている
[399]279 {
[405]280 // プロパティ値として返ってきたオブジェクトインスタンスのインデクサを呼び出す
281
282 // まずはプロパティ値を取得
[416]283 bool dummyIsVariable;
284 RELATIVE_VAR dummyRelativeVar;
[436]285 TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );
[97]286
[405]287 // 戻り値のオブジェクトインスタンスのインデクサを呼び出す
[399]288 char temporary[VN_SIZE], temp2[VN_SIZE];
289 sprintf( temporary, "[%s]", parameter );
290 sprintf( temp2, "%s.%s", termLeft, methodName );
291 Type classType = resultType;
[436]292 return TermMemberOpe( classType, isNeedHeapFreeStructure, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );
[399]293 }
294
[97]295 resultType = pUserProc->ReturnType();
296
297
298 //////////////////////////////////////////////////////
299 ///// レジスタ資源のバックアップ
300 { BACKUP_REGISTER_RESOURCE
301 //////////////////////////////////////////////////////
302
303 //オブジェクトポインタをスタックに入れておく
304 //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
[339]305 pobj_sf->push( useReg );
[97]306
[308]307 if( !Opcode_CallProc(parameter,pUserProc,PROCFLAG_NEW,termLeft ) ){
[97]308 //レジスタ資源を復元
309 RESTORE_REGISTER_RESOURCE
310
311 return false;
312 }
313
314 pobj_sf->pop();
315
316 /////////////////////
317 // 戻り値の処理
318 /////////////////////
319
320 //大きな型への暗黙の変換
321 int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
322
323 if( resultType.GetBasicType() != bigType ){
324 // 大きな型へ変換された場合
325 // ※レジスタの値をキャストする
326 ExtendRegToBigType( REG_RAX, bigType, resultType.GetBasicType() );
327
328 resultType.SetBasicType( bigType );
329 }
330
[339]331 SetUseRegFromRax(resultType.GetBasicType(),useReg,xmmReg);
[97]332
[316]333 // 型パラメータを解決
334 ResolveFormalGenericTypeParameter( resultType, leftType, pUserProc );
[97]335
[316]336
[97]337 /////////////////////////////////////////////
338 ////// レジスタ資源を復元
339 RESTORE_REGISTER_RESOURCE
340 }////////////////////////////////////////////
341
342 return true;
343 }
344 }
[430]345 else if( pareOrBracket == Pare )
346 {
347 // 関数ポインタ
[468]348 compiler.errorMessenger.OutputFatalError();
[97]349
[430]350 ///////////////////////////////////////////////////////////////////
351 // メンバを検索
352 ///////////////////////////////////////////////////////////////////
353 if( GetMemberType( leftType, methodName, resultType, 0, false ) ){
354 // メンバが見つかったとき
355 }
356 }
357
[468]358 compiler.errorMessenger.OutputFatalError();
[370]359
[97]360 return false;
361}
[436]362bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )
[416]363{
[97]364 char parameter[VN_SIZE];
365
366 // Withを解決
367 char termFull[VN_SIZE];
368 if(term[0]=='.'){
369 GetWithName(termFull);
370 lstrcat(termFull,term);
371 }
372 else lstrcpy(termFull,term);
373
374 char termLeft[VN_SIZE];
375 lstrcpy(termLeft,termFull);
376
377 // パース
378 char member[VN_SIZE];
[206]379 ReferenceKind refType;
380 if( SplitMemberName( termFull, termLeft, member, refType ) ){
[97]381 ///////////////////////////////////////////////////////////////////
382 // オブジェクトとメンバに分解できるとき
383 // termLeft.member
384 ///////////////////////////////////////////////////////////////////
385
386 isLiteral = false;
387
388 // オブジェクト側の型を取得
389 bool isClassName = false;
390 Type leftType;
[331]391 if( GetTermType( termLeft, Type(), leftType, isLiteral, &isClassName ) ){
[266]392 if( isClassName == false && compiler.GetObjectModule().meta.GetBlittableTypes().IsExist( leftType ) ){
[128]393 // 左側のオブジェクト部分がBlittable型のとき
394
395 char temporary[VN_SIZE];
396 lstrcpy( temporary, termLeft );
397 sprintf( termLeft, "%s(%s)",
[266]398 compiler.GetObjectModule().meta.GetBlittableTypes().Find( leftType ).GetCreateStaticMethodFullName().c_str(),
[128]399 temporary );
400 }
401 }
402
[436]403 if( !TermOpe( termLeft, baseType, leftType, isLiteral, isNeedHeapFreeStructure, &isClassName ) ){
[103]404 goto globalArea;
[97]405 }
406
407 if( isClassName ){
408 // 静的メンバ/メソッドの場合
409 goto globalArea;
410 }
411
412 if( !leftType.HasMember() ){
413 // メンバを持たない型の場合
[370]414 if( isProcedureCallOnly )
415 {
[468]416 compiler.errorMessenger.Output(1,NULL,cp);
[370]417 }
[97]418 return false;
419 }
420
[436]421 return TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );
[97]422 }
[103]423globalArea:
[97]424
425 //////////////////////////////////////////////
426 // クラス名かどうかをチェック(静的メンバ用)
427 //////////////////////////////////////////////
428
429 if( pIsClassName ){
[598]430 if( compiler.GetObjectModule().meta.FindClassSupportedTypeDef( LexicalAnalyzer::FullNameToSymbol( termFull ) ) ){
[97]431 *pIsClassName = true;
432 return true;
433 }
434 }
435
436
437 /////////////////////////////////////////////////////////////////
438 // グローバル属性エリア
439 /////////////////////////////////////////////////////////////////
440
441 int UseReg=pobj_reg->GetNextReg();
442 int XmmReg=pobj_reg->GetNextXmmReg();
443
444
[122]445 if(lstrcmpi(termFull,"This")==0 && isProcedureCallOnly == false ){
[584]446 if( !compiler.IsCompilingClass() )
[413]447 {
[468]448 compiler.errorMessenger.Output(142,NULL,cp);
[413]449 return false;
450 }
451
[97]452 //Thisオブジェクト
[584]453 resultType.SetType( DEF_OBJECT, &compiler.GetCompilingClass() );
[97]454
455 SetThisPtrToReg( UseReg );
456
457 isLiteral = false;
458
459 return true;
460 }
461
462
463 //////////////////////////////////////
464 // 関数(DLL、ユーザー定義、組み込み)
465 //////////////////////////////////////
466 char procName[VN_SIZE];
467 char temporary[8192];
468
469 int i2=GetCallProcName(termFull,procName);
470 if(termFull[i2]=='('){
471 int i4=GetStringInPare_RemovePare(parameter,termFull+i2+1);
472
473 void *pInfo;
474 int idProc=GetProc(procName,(void **)&pInfo);
475
476 if(idProc){
477 //閉じカッコ")"に続く文字がNULLでないとき
478 if(termFull[i2+1+i4+1]!='\0'){
[468]479 compiler.errorMessenger.Output(42,NULL,cp);
[97]480 }
481
482
483 //////////////////////////////////////////////////////
484 ///// レジスタ資源のバックアップ
485 { BACKUP_REGISTER_RESOURCE
486 //////////////////////////////////////////////////////
487
488
489 ////////////////
490 // 呼び出し
491 ////////////////
492
[331]493 CallProc(idProc,pInfo,procName,parameter, baseType,resultType);
[97]494
495
496 /////////////////////
497 // 戻り値の処理
498 /////////////////////
499
500 //大きな型への暗黙の変換
501 int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
502
503 if( resultType.GetBasicType() != bigType ){
504 // 大きな型へ変換された場合
505 // ※レジスタの値をキャストする
506 ExtendRegToBigType( REG_RAX, bigType, resultType.GetBasicType() );
507
508 resultType.SetBasicType( bigType );
509 }
510
511 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
512
513 /////////////////////////////////////////////
514 ////// レジスタ資源を復元
515 RESTORE_REGISTER_RESOURCE
516 }////////////////////////////////////////////
517
[436]518 if(resultType.IsStruct())
519 {
[97]520 //構造体が戻ったときはヒープ領域にインスタンスが格納されている
521 //※後にfreeする必要あり
522 // TODO: 解放はGCに任せる
[436]523 isNeedHeapFreeStructure = true;
[97]524 }
525
526 isLiteral = false;
527
528 return true;
529 }
530
[584]531 ConstMacro *pConstMacro = compiler.GetObjectModule().meta.GetGlobalConstMacros().Find(
532 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( procName )
533 );
[206]534 if( pConstMacro )
535 {
[584]536 if( ActiveBasic::Compiler::LexicalAnalyzer::ConstMacroToExpression( *pConstMacro, parameter, temporary ) )
[206]537 {
538 /////////////////////////
539 // マクロ関数
540 /////////////////////////
[97]541
[206]542 //閉じカッコ")"に続く文字がNULLでないときはエラーにする
[468]543 if(termFull[i2+1+i4+1]!='\0') compiler.errorMessenger.Output(42,NULL,cp);
[97]544
[206]545 //マクロ関数の場合
546 NumOpe(&UseReg, temporary,Type(),resultType);
547
548 if(!IS_LITERAL(resultType.GetIndex())){
549 //リテラル値ではなかったとき
550 isLiteral = false;
551 }
552
553 return true;
[97]554 }
555 }
556 }
[122]557 else if( isProcedureCallOnly ){
558 // 関数呼び出し以外は受け付けない
559 return false;
560 }
[97]561
562
563 ////////////////////////////////
564 // インデクサ(getアクセサ)
565 ////////////////////////////////
566
567 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
568 GetArrayElement(termFull,VarName,ArrayElements);
569 if(ArrayElements[0]){
[319]570 Type classType;
571 GetVarType(VarName,classType,false);
572 if( classType.IsObject() )
573 {
574 CallIndexerGetterProc(UseReg,classType,VarName,ArrayElements,resultType);
[97]575
576 isLiteral = false;
577
578 return true;
579 }
580 }
581
582
583 ////////////////////////////////
584 // 変数
585 ////////////////////////////////
586
587 if(GetVarOffset(
588 false, //エラー表示なし
[416]589 isWriteAccess,
[97]590 termFull,
591 &relativeVar,resultType)){
592 //////////
593 // 変数
594 //////////
595
[416]596 // 変数として扱う
597 isVariable = true;
[97]598
599 isLiteral = false;
600
601 return true;
602 }
603
604/*
605 ////////////////////////////////
606 // 型名
607 ////////////////////////////////
608
[308]609 if( compiler.StringToType( termFull, resultType ) ){
[97]610 resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
611 return true;
612 }*/
613
614
615 /////////////////////////////////
616 // プロパティ用のメソッド
617 /////////////////////////////////
618
619 //配列要素を排除
620 GetArrayElement(termFull,VarName,ArrayElements);
621
622 if(GetSubHash(VarName,0)){
623
624 //////////////////////////////////////////////////////
625 ///// レジスタ資源のバックアップ
626 { BACKUP_REGISTER_RESOURCE
627 //////////////////////////////////////////////////////
628
629 CallPropertyMethod(termFull,NULL,resultType);
630
631 //大きな型への暗黙の変換
632 int bigType = AutoBigCast(baseType.GetBasicType(), resultType.GetBasicType() );
633
634 if( resultType.GetBasicType() != bigType ){
635 // 大きな型へ変換された場合
636 // ※レジスタの値をキャストする
637 ExtendRegToBigType( REG_RAX, bigType, resultType.GetBasicType() );
638
639 resultType.SetBasicType( bigType );
640 }
641
642 SetUseRegFromRax(resultType.GetBasicType(),UseReg,XmmReg);
643
644 /////////////////////////////////////////////
645 ////// レジスタ資源を復元
646 RESTORE_REGISTER_RESOURCE
647 }////////////////////////////////////////////
648
[436]649 if(resultType.IsStruct())
650 {
[97]651 //構造体が戻ったときはヒープ領域にインスタンスが格納されている
652 //※後にfreeする必要あり
653 // TODO: 解放はGCに任せる
[436]654 isNeedHeapFreeStructure = true;
[97]655 }
656
657 isLiteral = false;
658
659 return true;
660 }
661
[370]662 if( isProcedureCallOnly )
663 {
[468]664 compiler.errorMessenger.Output(3, termLeft, cp );
[370]665 }
[97]666
667 return false;
668}
669
[436]670bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )
[416]671{
[417]672 bool isInitRegSwitch = false;
673 if( !pobj_reg )
674 {
675 isInitRegSwitch = true;
676
677 //作業用レジスタを取得
678 pobj_reg = new CRegister( REG_RAX );
679 }
680
681 //エラー時の復旧用
682 CRegister objReg_Backup = *pobj_reg;
683
684
[416]685 RELATIVE_VAR relativeVar;
686 bool isVariable = false;
[436]687 bool result = _TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructure, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );
[416]688
689 if( isVariable )
690 {
691 // 変数の場合はeaxに変数ポインタを格納する
692 if( !VarToReg( relativeVar, baseType, resultType ) ){
[468]693 compiler.errorMessenger.Output(11,term,cp);
[416]694 }
695 }
696
[417]697
698 if( !result )
699 {
700 *pobj_reg = objReg_Backup;
701 }
702
703 if( isInitRegSwitch ){
704 //整合性をチェック(バグ回避)
705 if( result )
706 {
707 pobj_reg->bug_check();
708 }
709
710 //作業レジスタを解放
711 delete pobj_reg;
712 pobj_reg = NULL;
713 }
714
[416]715 return result;
716}
717bool TermOpeOnlyVariable( const char *term, Type &resultType, RELATIVE_VAR &relativeVar, bool isWriteAccess )
718{
[417]719 if( pobj_reg )
720 {
[468]721 compiler.errorMessenger.OutputFatalError();
[417]722 }
723
724 //作業用レジスタを取得
725 pobj_reg = new CRegister( REG_NON );
726
[436]727 bool isLiteral, isVariable = false, isNeedHeapFreeStructure = false;
728 bool result = _TermOpe( term, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, isVariable, relativeVar, isWriteAccess );
[416]729
730 if( !isVariable )
731 {
[468]732 compiler.errorMessenger.OutputFatalError();
[416]733 }
734
[417]735 //整合性をチェック(バグ回避)
736 if( result )
737 {
738 pobj_reg->bug_check();
739 }
740
741 //作業レジスタを解放
742 delete pobj_reg;
743 pobj_reg=0;
744
[416]745 return result;
746}
747
748
[255]749bool _numope( int *pReg,
[75]750 const char *expression,
751 const Type &baseType,
752 Type &resultType,
[436]753 bool *pbIsNeedHeapFreeStructure )
[255]754{
[97]755 int i,i2,i3;
756 char temporary[1024],temp2[1024];
[3]757
[75]758 if(expression[0]=='\0'){
[468]759 compiler.errorMessenger.Output(1,NULL,cp);
[75]760 return false;
[3]761 }
762
[93]763 if( !baseType.IsNull() && expression[0] == '[' ){
764 // リテラル配列の場合
[3]765
[355]766 int dataTableOffset;
[589]767 if( !ActiveBasic::Compiler::DataTableGenerator::MakeLiteralArrayBuffer( compiler.GetObjectModule().dataTable, expression, baseType, dataTableOffset ) )
[355]768 {
[93]769 return false;
770 }
771
772 //mov reg,i2
[355]773 compiler.codeGenerator.op_mov_RV( sizeof(_int64), *pReg, dataTableOffset, Schedule::DataTable );
[93]774
775 resultType = baseType;
776
777 return true;
778 }
779
[254]780 bool isLiteralCalculation;
[355]781 if( NumOpe_GetType( expression, baseType, resultType, &isLiteralCalculation ) )
[254]782 {
[355]783 if( isLiteralCalculation )
784 {
785 //右辺値が数値の定数式の場合
786 _int64 i64data;
787 StaticCalculation(true, expression,baseType.GetBasicType(),&i64data,resultType);
[93]788
[355]789 if(resultType.IsReal()){
790 if(baseType.IsReal()) resultType=baseType;
[254]791
[355]792 int xmmReg = pobj_reg->GetNextXmmReg();
793 *pReg = xmmReg;
[254]794
[355]795 if(resultType.IsDouble()){
[587]796 i3 = compiler.GetObjectModule().dataTable.Add( i64data );
[254]797
[355]798 //movlpd xmm_reg,qword ptr[data table offset]
799 compiler.codeGenerator.op_movlpd_RM( xmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
800 }
801 if(resultType.IsSingle()){
802 double dbl;
803 memcpy(&dbl,&i64data,sizeof(_int64));
[254]804
[355]805 float flt;
806 int i32data;
807 flt=(float)dbl;
808 memcpy(&i32data,&flt,sizeof(long));
[254]809
[587]810 i3 = compiler.GetObjectModule().dataTable.Add( i32data );
[254]811
[355]812 //movss xmm_reg,dword ptr[data table offset]
813 compiler.codeGenerator.op_movss_RM( xmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
814 }
[254]815 }
[355]816 else{
817 if(!resultType.Is64()){
818 //整数(符号有り/無し)
[254]819
[355]820 i3=(long)i64data;
[254]821
[355]822 if(resultType.GetBasicSize()==sizeof(char)) i3=i3&0x000000FF;
823 if(resultType.GetBasicSize()==sizeof(short)) i3=i3&0x0000FFFF;
[254]824
[355]825 i64data=(_int64)i3;
826 }
827
828 //mov reg,i64data
829 compiler.codeGenerator.op_mov_RV64(*pReg,i64data);
[254]830 }
[355]831 return true;
[254]832 }
833 }
834
[355]835 if( expression[0] == 1 )
836 {
837 if( expression[1]==ESC_NEW )
838 {
839 //New演算子(オブジェクト生成)
[254]840
[355]841 if( pobj_BlockReg->check(REG_RAX) ){
[468]842 compiler.errorMessenger.OutputFatalError();
[355]843 }
844
845 //////////////////////////////////////////////////////
846 ///// レジスタ資源のバックアップ
847 { BACKUP_REGISTER_RESOURCE
848 //////////////////////////////////////////////////////
849
850 if( !Operator_New( expression+2, baseType, resultType ) ){
851 return false;
852 }
853
854 /////////////////////////////////////////////
855 ////// レジスタ資源を復元
856 RESTORE_REGISTER_RESOURCE
857 }////////////////////////////////////////////
858
859 //mov reg,rax
860 compiler.codeGenerator.op_mov_RR( *pReg, REG_RAX );
861
862 return true;
[254]863 }
[355]864 else if( expression[1] == ESC_SYSTEM_STATIC_NEW )
865 {
866 // 静的領域にオブジェクトを作る
[254]867
[355]868 // 静的領域にオブジェクトを生成
869 int dataTableOffset;
[589]870 if( !ActiveBasic::Compiler::DataTableGenerator::MakeConstObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, expression + 2, resultType, dataTableOffset ) )
[355]871 {
[254]872 return false;
873 }
874
[355]875 //mov reg,i2
876 compiler.codeGenerator.op_mov_RV( sizeof(_int64), *pReg, dataTableOffset, Schedule::DataTable);
[254]877
[355]878 return true;
879 }
[254]880 }
881
882
[3]883 /////////////////////////////////
884 // 式要素を逆ポーランド式で取得
885 /////////////////////////////////
886
887 char *values[255];
888 long calc[255];
889 long stack[255];
890 int pnum;
[75]891 if(!GetNumOpeElements(expression,&pnum,values,calc,stack)){
[3]892 for(i=0;i<pnum;i++){
893 if(values[i]) HeapDefaultFree(values[i]);
894 }
895 return 0;
896 }
897
898
899 ////////////////////////////////
900 // 演算部分のコード生成を開始
901 ////////////////////////////////
902
903 BOOL bError;
904 bError=0;
905
906 //リテラル値のみの計算かどうかを判別するためのフラグ
907 BOOL bLiteralCalculation=1;
908
909 double dbl;
910 int sp;
[75]911 int type_stack[255];
[3]912 LONG_PTR index_stack[255];
[79]913 bool isNothing_stack[255];
[436]914 bool isNeedHeapFreeStructureStack[255];
[3]915 _int64 i64data;
916 int UseReg,XmmReg;
917 BOOL bXmm;
918 for(i=0,sp=0;i<pnum;i++){
919 int idCalc;
920 idCalc=calc[i]%100;
921
922 if(idCalc){
[676]923 if( sp>=2 && type_stack[sp-2]==DEF_OBJECT )
924 {
[79]925 if( idCalc == CALC_AS
926 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
927 && index_stack[sp-1] == index_stack[sp-2]
928 || isNothing_stack[sp-2] ){
929 // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
[3]930 }
[94]931 else if( idCalc == CALC_AS
932 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
933 && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
934 )){
935 // ダウンキャストを許可する
936 }
[79]937 else{
938 //オーバーロードされたオペレータを呼び出す
[436]939 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp);
[79]940 if(i2==0){
941 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
942 else GetCalcName(idCalc,temp2);
943 sprintf(temporary,"Operator %s",temp2);
[468]944 compiler.errorMessenger.Output(27,temporary,cp);
[79]945 goto error;
946 }
947 else if(i2==-1) goto error;
[3]948
[79]949 continue;
950 }
[3]951 }
952
[75]953 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
[3]954 }
955
956 switch(idCalc){
957 //数値
958 case 0:
959 index_stack[sp]=-1;
[79]960 isNothing_stack[sp] = false;
[436]961 isNeedHeapFreeStructureStack[sp] = false;
[3]962
963 UseReg=pobj_reg->GetNextReg();
964 XmmReg=pobj_reg->GetNextXmmReg();
965
966 bXmm=0;
967
968 char *term;
969 term=values[i];
970
[97]971 if( calc[i+1]%100 == CALC_AS ){
972 // As演算子の右辺値
973 //型名
[308]974 if( compiler.StringToType( term, resultType ) ){
[97]975 resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
976 }
977 else{
[468]978 compiler.errorMessenger.Output(3, term, cp );
[97]979 goto error;
980 }
981
982 type_stack[sp] = resultType.GetBasicType();
983 index_stack[sp] = resultType.GetIndex();
984 sp++;
985
986 break;
987 }
988
[319]989 if( (term[0]=='e'||term[0]=='E')
990 && (term[1]=='x'||term[1]=='X')
991 && term[2]=='\"'
992 || term[0] == '\"' )
993 {
994 bool isEx = true;
995 if( term[0] == '\"' )
996 {
997 isEx = false;
998 }
999
1000 if( isEx )
1001 {
1002 // 拡張版リテラル文字列(エスケープシーケンス可能)
1003 if(!RemoveStringQuotes(term+2)){
[468]1004 compiler.errorMessenger.Output(43,NULL,cp);
[319]1005 goto error;
1006 }
1007 i3=FormatString_EscapeSequence(term+2);
1008 term+=2;
1009 }
1010 else
1011 {
1012 // 通常文字列
1013 if(!RemoveStringQuotes(term)){
[468]1014 compiler.errorMessenger.Output(43,NULL,cp);
[319]1015 goto error;
1016 }
1017 i3=lstrlen(term);
1018 }
[355]1019
1020 if( !baseType.IsPointer() )
1021 {
1022 //要求タイプがオブジェクト、または未定のとき
1023
1024 //String型オブジェクトを生成
[589]1025 i2 = ActiveBasic::Compiler::DataTableGenerator::MakeConstStringObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, term );
[355]1026
1027 //mov reg,i2
1028 compiler.codeGenerator.op_mov_RV(sizeof(_int64),UseReg,i2, Schedule::DataTable);
1029
1030 type_stack[sp]=DEF_OBJECT;
1031 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
1032 bLiteralCalculation=0;
1033
1034 if(bXmm) pobj_reg->LockXmmReg();
1035 else pobj_reg->LockReg();
1036
1037 sp++;
1038 break;
1039 }
1040
[319]1041StrLiteral:
1042
[75]1043 type_stack[sp]=typeOfPtrChar;
[3]1044 bLiteralCalculation=0;
1045
[592]1046 if( compiler.IsUnicode() )
1047 {
1048 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( std::string( term, i3 ) ) );
1049 }
1050 else
1051 {
1052 i2 = compiler.GetObjectModule().dataTable.AddString( std::string( term, i3 ) );
1053 }
[3]1054
1055 //mov reg,i2
[242]1056 compiler.codeGenerator.op_mov_RV(sizeof(_int64),UseReg,i2, Schedule::DataTable);
[3]1057
1058 if(UseReg==REG_R14){
1059 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1060 pobj_sf->push(REG_R14);
1061 }
1062 }
1063 else if(IsVariableTopChar(term[0])||
1064 term[0]=='*'||
[319]1065 (term[0]=='.'&&IsVariableTopChar(term[1])))
1066 {
[3]1067 //////////////////
1068 // 何らかの識別子
1069
[97]1070 bool isLiteral;
[436]1071 if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){
[97]1072 if(resultType.IsNull()){
1073 //戻り値が存在しないとき
1074 for(i2=0;;i2++){
1075 if(term[i2]=='('||term[i2]=='\0'){
1076 term[i2]=0;
1077 break;
[49]1078 }
1079 }
[468]1080 compiler.errorMessenger.Output(38,term,cp);
[3]1081
[97]1082 goto error;
1083 }
[3]1084
[97]1085 type_stack[sp] = resultType.GetBasicType();
1086 index_stack[sp] = resultType.GetIndex();
[3]1087
[97]1088 if( !isLiteral ){
1089 bLiteralCalculation=0;
1090 }
[3]1091
[97]1092 if( resultType.GetBasicType() & FLAG_CAST ){
1093 // 型名のみ
[468]1094 compiler.errorMessenger.OutputFatalError();
[97]1095 }
1096 else{
1097 if( resultType.IsReal() == false && UseReg==REG_R14 ){
1098 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1099 pobj_sf->push(REG_R14);
1100 }
1101 if( resultType.IsReal() && XmmReg==REG_XMM4 ){
1102 if(resultType.IsDouble()){
1103 //movsd qword ptr[rsp+offset],xmm4 ※スタックフレームを利用
1104 pobj_sf->push(REG_XMM4,sizeof(double));
[3]1105 }
[97]1106 if(resultType.IsSingle()){
1107 //movss dword ptr[rsp+offset],xmm4 ※スタックフレームを利用
1108 pobj_sf->push(REG_XMM4,sizeof(float));
[75]1109 }
[3]1110 }
1111
[97]1112 if( resultType.IsReal() ){
1113 pobj_reg->LockXmmReg();
[3]1114 }
[97]1115 else{
1116 pobj_reg->LockReg();
1117 }
[3]1118 }
1119
[97]1120 sp++;
1121 break;
[3]1122 }
1123
1124
[67]1125 // Nothing
1126 if( lstrcmp( term, "Nothing" ) == 0 ){
[79]1127 isNothing_stack[sp] = true;
1128
[75]1129 if( baseType.IsObject() ){
[633]1130 type_stack[sp] = DEF_OBJECT;
[75]1131 index_stack[sp] = baseType.GetIndex();
[67]1132 }
1133 else{
[633]1134 type_stack[sp] = baseType.GetBasicType();
1135 index_stack[sp] = baseType.GetIndex();
[67]1136 }
1137
1138 bLiteralCalculation = 0;
1139
1140 //xor reg,reg
[226]1141 compiler.codeGenerator.op_zero_reg( UseReg );
[67]1142
1143 if(UseReg==REG_R14){
1144 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1145 pobj_sf->push(REG_R14);
1146 }
1147
1148 pobj_reg->LockReg();
1149 sp++;
1150 break;
1151 }
1152
1153
[3]1154 //////////////
1155 // 定数の場合
1156 //////////////
1157
[584]1158 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(
1159 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1160 );
[9]1161 if(i3){
[600]1162 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term ), compiler.IsUnicode() ) ){
[103]1163 //リテラル文字列
1164
[319]1165 if( baseType.IsObject() || baseType.IsNull() )
1166 {
1167 //要求タイプがオブジェクト、または未定のとき
1168
1169 //String型オブジェクトを生成
1170 NewStringObject(UseReg,term);
1171
1172 type_stack[sp]=DEF_OBJECT;
1173 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
1174 bLiteralCalculation=0;
1175
1176 if(bXmm) pobj_reg->LockXmmReg();
1177 else pobj_reg->LockReg();
1178
1179 sp++;
1180 break;
1181 }
1182
[584]1183 double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(
1184 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1185 );
[103]1186 memcpy(&i64data,&dbl,sizeof(double));
1187
1188 //バイト数
1189 i3=lstrlen((char *)i64data);
1190
1191 memcpy(term,(char *)i64data,i3);
1192 term[i3]=0;
1193 goto StrLiteral;
1194 }
1195
[75]1196 type_stack[sp] = i3;
[3]1197 if(IsRealNumberType(i3)){
1198 //実数
[584]1199 double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(
1200 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1201 );
[3]1202 memcpy(&i64data,&dbl,sizeof(double));
1203 goto Literal;
1204 }
1205 else if(IsWholeNumberType(i3)){
1206 //整数
[584]1207 i64data = compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(
1208 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1209 );
[3]1210 goto Literal;
1211 }
1212 else{
[468]1213 compiler.errorMessenger.Output(1,NULL,0);
[3]1214 goto error;
1215 }
1216 }
1217
1218
1219 //該当する識別子が見当たらないときはエラー扱いにする
1220 bError=1;
[468]1221 compiler.errorMessenger.Output(3,term,cp);
[75]1222 type_stack[sp]=DEF_DOUBLE;
[3]1223 }
1224 else{
1225 //リテラル値
[75]1226 type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
[3]1227Literal:
[75]1228 if(type_stack[sp]==DEF_DOUBLE){
[3]1229 //64ビット浮動小数型
1230 bXmm=1;
1231
1232 if(XmmReg==REG_XMM4){
1233 //mov r14,i64data
[232]1234 compiler.codeGenerator.op_mov_RV64(REG_R14,i64data);
[3]1235
1236
1237 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1238 pobj_sf->push(REG_R14);
1239 }
1240 else{
[587]1241 i3 = compiler.GetObjectModule().dataTable.Add( i64data );
[3]1242
1243 //movlpd xmm_reg,qword ptr[data table offset]
[242]1244 compiler.codeGenerator.op_movlpd_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
[3]1245 }
1246 }
[75]1247 else if(type_stack[sp]==DEF_SINGLE){
[3]1248 //32ビット浮動小数型
1249 bXmm=1;
1250
1251 float flt;
1252 int i32data;
1253 memcpy(&dbl,&i64data,sizeof(double));
1254 flt=(float)dbl;
1255 memcpy(&i32data,&flt,sizeof(long));
1256
1257 if(XmmReg==REG_XMM4){
[468]1258 compiler.errorMessenger.OutputFatalError(); // TODO: 未実装
[3]1259 //push term
[226]1260 //compiler.codeGenerator.op_push_value(i32data);
[3]1261 }
1262 else{
[587]1263 i3=compiler.GetObjectModule().dataTable.Add( i32data );
[3]1264
1265 //movss xmm_reg,dword ptr[data table offset]
[242]1266 compiler.codeGenerator.op_movss_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
[3]1267 }
1268 }
1269 else{
1270 //整数
1271
1272 index_stack[sp]=GetLiteralIndex(i64data);
1273
1274 //mov reg,i64data
[232]1275 compiler.codeGenerator.op_mov_RV64(UseReg,i64data);
[3]1276
1277 if(UseReg==REG_R14){
1278 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1279 pobj_sf->push(REG_R14);
1280 }
1281 }
1282 }
1283
1284 if(bXmm) pobj_reg->LockXmmReg();
1285 else pobj_reg->LockReg();
1286
1287 sp++;
1288 break;
1289
1290 //論理演算子
1291 case CALC_XOR:
1292 case CALC_OR:
1293 case CALC_AND:
[75]1294 if(!CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1295 break;
1296 case CALC_NOT:
1297 //value[sp-1]=Not value[sp-1]
1298 //NOT演算子
[75]1299 if(!Calc_Not(type_stack,sp)) goto error;
[3]1300 break;
1301
1302 //比較演算子
1303 case CALC_PE: //value[sp-2] <= value[sp-1]
1304 case CALC_QE: //value[sp-2] >= value[sp-1]
1305 case CALC_P: //value[sp-2] < value[sp-1]
1306 case CALC_Q: //value[sp-2] > value[sp-1]
1307 case CALC_NOTEQUAL: //value[sp-2] <> value[sp-1]
1308 case CALC_EQUAL: //value[sp-2] = value[sp-1]
[75]1309 if(!CalcTwoTerm_Relational(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1310 break;
1311
1312 //ビットシフト
1313 case CALC_SHL: //value[sp-2] << value[sp-1]
1314 case CALC_SHR: //value[sp-2] >> value[sp-1]
[75]1315 if(!Calc_Shift(idCalc,type_stack,&sp)) goto error;
[3]1316 break;
1317
1318 //算術演算
1319 case CALC_ADDITION:
1320 case CALC_SUBTRACTION:
1321 case CALC_PRODUCT:
[75]1322 if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1323 break;
1324 case CALC_MOD:
1325 //value[sp-2]%=value[sp-1]
1326 //剰余演算
[75]1327 if(!Calc_Mod(type_stack,index_stack,&sp)) goto error;
[3]1328 break;
1329 case CALC_QUOTIENT:
1330 //value[sp-2]/=value[sp-1];
1331 //除算
[75]1332 if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
[3]1333 break;
1334 case CALC_INTQUOTIENT:
1335 //value[sp-2]/=value[sp-1]
1336 //整数除算
[75]1337 if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
[3]1338 break;
1339 case CALC_MINUSMARK:
1340 //value[sp-1]=-value[sp-1]
1341 //符号反転
[75]1342 if(!Calc_MinusMark(type_stack,sp)) goto error;
[3]1343 break;
1344 case CALC_POWER:
1345 //べき乗演算(浮動小数点演算のみ)
[75]1346 if(!Calc_Power(type_stack,&sp)) goto error;
[3]1347 break;
1348 case CALC_AS:
1349 //キャスト
[75]1350 if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
[3]1351 break;
[41]1352 case CALC_BYVAL:
1353 //ポインタ型→参照型
[75]1354 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
[41]1355 //ポインタ型ではないとき
[665]1356 compiler.errorMessenger.Output( 1, NULL, cp );
[41]1357 goto error;
1358 }
[3]1359
[75]1360 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
[41]1361
1362 break;
1363
[3]1364 default:
[468]1365 compiler.errorMessenger.Output(300,NULL,cp);
[41]1366 goto error;
[3]1367 }
1368 }
1369
1370 if(bError) goto error;
1371
1372 if(sp!=1){
[468]1373 compiler.errorMessenger.Output(1,NULL,cp);
[3]1374 goto error;
1375 }
1376
1377 if(bLiteralCalculation){
[468]1378 compiler.errorMessenger.OutputFatalError();
[3]1379 }
1380 else{
1381 //右辺値が数値の定数式ではないとき
1382 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
1383 }
1384
[436]1385 if( pbIsNeedHeapFreeStructure )
1386 {
1387 *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0];
1388 }
[3]1389
[75]1390 if(IsRealNumberType(type_stack[0]))
[3]1391 *pReg=pobj_reg->UnlockXmmReg();
1392 else
1393 *pReg=pobj_reg->UnlockReg();
1394
1395
[75]1396 resultType.SetType( type_stack[0], index_stack[0] );
1397
1398 bool isSuccessful = true;
[3]1399 goto finish;
1400
1401
1402
1403 //////////////////
1404 // エラー処理
1405 //////////////////
1406
1407error:
1408
[75]1409 isSuccessful = false;
[3]1410 goto finish;
1411
1412
1413
1414
1415finish:
1416
1417 for(i=0;i<pnum;i++){
1418 if(values[i]) HeapDefaultFree(values[i]);
1419 }
1420
[75]1421 return isSuccessful;
[3]1422}
[255]1423
1424bool NumOpe( int *pReg,
1425 const char *expression,
1426 const Type &baseType,
1427 Type &resultType,
[436]1428 bool *pbIsNeedHeapFreeStructure )
[255]1429{
[417]1430 bool isInitRegSwitch = false;
1431 if( !pobj_reg )
1432 {
1433 isInitRegSwitch = true;
[255]1434
1435 //作業用レジスタを取得
[417]1436 pobj_reg = new CRegister( *pReg );
[255]1437 }
1438
1439 //エラー時の復旧用
[417]1440 CRegister objReg_Backup = *pobj_reg;
[255]1441
1442 *pReg = pobj_reg->GetNextReg();
1443
1444
[436]1445 bool result = _numope( pReg, expression, baseType, resultType, pbIsNeedHeapFreeStructure );
[255]1446
1447
1448 if( !result )
1449 {
[417]1450 *pobj_reg = objReg_Backup;
[255]1451 }
1452
[417]1453 if( isInitRegSwitch ){
[255]1454 //整合性をチェック(バグ回避)
1455 if( result )
1456 {
1457 pobj_reg->bug_check();
1458 }
1459
1460 //作業レジスタを解放
1461 delete pobj_reg;
[417]1462 pobj_reg = NULL;
[255]1463 }
1464
1465 return result;
1466}
Note: See TracBrowser for help on using the repository browser.