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

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

[632]を64bit版にマージ。

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){
[75]923 if(type_stack[sp-2]==DEF_OBJECT){
[79]924 if( idCalc == CALC_AS
925 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
926 && index_stack[sp-1] == index_stack[sp-2]
927 || isNothing_stack[sp-2] ){
928 // 同一の型、またはNothingに対するAsはAs演算子を呼び出さない
[3]929 }
[94]930 else if( idCalc == CALC_AS
931 && type_stack[sp-1] == ( DEF_OBJECT | FLAG_CAST )
932 && ( ((CClass *)index_stack[sp-1])->IsEqualsOrSubClass( (CClass *)index_stack[sp-2] ) || ((CClass *)index_stack[sp-2])->IsEqualsOrSubClass( (CClass *)index_stack[sp-1] )
933 )){
934 // ダウンキャストを許可する
935 }
[79]936 else{
937 //オーバーロードされたオペレータを呼び出す
[436]938 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp);
[79]939 if(i2==0){
940 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"==");
941 else GetCalcName(idCalc,temp2);
942 sprintf(temporary,"Operator %s",temp2);
[468]943 compiler.errorMessenger.Output(27,temporary,cp);
[79]944 goto error;
945 }
946 else if(i2==-1) goto error;
[3]947
[79]948 continue;
949 }
[3]950 }
951
[75]952 if(!CheckCalcType(idCalc,type_stack,sp)) goto error;
[3]953 }
954
955 switch(idCalc){
956 //数値
957 case 0:
958 index_stack[sp]=-1;
[79]959 isNothing_stack[sp] = false;
[436]960 isNeedHeapFreeStructureStack[sp] = false;
[3]961
962 UseReg=pobj_reg->GetNextReg();
963 XmmReg=pobj_reg->GetNextXmmReg();
964
965 bXmm=0;
966
967 char *term;
968 term=values[i];
969
[97]970 if( calc[i+1]%100 == CALC_AS ){
971 // As演算子の右辺値
972 //型名
[308]973 if( compiler.StringToType( term, resultType ) ){
[97]974 resultType.SetBasicType( resultType.GetBasicType() | FLAG_CAST );
975 }
976 else{
[468]977 compiler.errorMessenger.Output(3, term, cp );
[97]978 goto error;
979 }
980
981 type_stack[sp] = resultType.GetBasicType();
982 index_stack[sp] = resultType.GetIndex();
983 sp++;
984
985 break;
986 }
987
[319]988 if( (term[0]=='e'||term[0]=='E')
989 && (term[1]=='x'||term[1]=='X')
990 && term[2]=='\"'
991 || term[0] == '\"' )
992 {
993 bool isEx = true;
994 if( term[0] == '\"' )
995 {
996 isEx = false;
997 }
998
999 if( isEx )
1000 {
1001 // 拡張版リテラル文字列(エスケープシーケンス可能)
1002 if(!RemoveStringQuotes(term+2)){
[468]1003 compiler.errorMessenger.Output(43,NULL,cp);
[319]1004 goto error;
1005 }
1006 i3=FormatString_EscapeSequence(term+2);
1007 term+=2;
1008 }
1009 else
1010 {
1011 // 通常文字列
1012 if(!RemoveStringQuotes(term)){
[468]1013 compiler.errorMessenger.Output(43,NULL,cp);
[319]1014 goto error;
1015 }
1016 i3=lstrlen(term);
1017 }
[355]1018
1019 if( !baseType.IsPointer() )
1020 {
1021 //要求タイプがオブジェクト、または未定のとき
1022
1023 //String型オブジェクトを生成
[589]1024 i2 = ActiveBasic::Compiler::DataTableGenerator::MakeConstStringObjectToProcessStaticBuffer( compiler.GetObjectModule().dataTable, term );
[355]1025
1026 //mov reg,i2
1027 compiler.codeGenerator.op_mov_RV(sizeof(_int64),UseReg,i2, Schedule::DataTable);
1028
1029 type_stack[sp]=DEF_OBJECT;
1030 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
1031 bLiteralCalculation=0;
1032
1033 if(bXmm) pobj_reg->LockXmmReg();
1034 else pobj_reg->LockReg();
1035
1036 sp++;
1037 break;
1038 }
1039
[319]1040StrLiteral:
1041
[75]1042 type_stack[sp]=typeOfPtrChar;
[3]1043 bLiteralCalculation=0;
1044
[592]1045 if( compiler.IsUnicode() )
1046 {
1047 i2 = compiler.GetObjectModule().dataTable.AddWString( Jenga::Common::ToWString( std::string( term, i3 ) ) );
1048 }
1049 else
1050 {
1051 i2 = compiler.GetObjectModule().dataTable.AddString( std::string( term, i3 ) );
1052 }
[3]1053
1054 //mov reg,i2
[242]1055 compiler.codeGenerator.op_mov_RV(sizeof(_int64),UseReg,i2, Schedule::DataTable);
[3]1056
1057 if(UseReg==REG_R14){
1058 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1059 pobj_sf->push(REG_R14);
1060 }
1061 }
1062 else if(IsVariableTopChar(term[0])||
1063 term[0]=='*'||
[319]1064 (term[0]=='.'&&IsVariableTopChar(term[1])))
1065 {
[3]1066 //////////////////
1067 // 何らかの識別子
1068
[97]1069 bool isLiteral;
[436]1070 if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){
[97]1071 if(resultType.IsNull()){
1072 //戻り値が存在しないとき
1073 for(i2=0;;i2++){
1074 if(term[i2]=='('||term[i2]=='\0'){
1075 term[i2]=0;
1076 break;
[49]1077 }
1078 }
[468]1079 compiler.errorMessenger.Output(38,term,cp);
[3]1080
[97]1081 goto error;
1082 }
[3]1083
[97]1084 type_stack[sp] = resultType.GetBasicType();
1085 index_stack[sp] = resultType.GetIndex();
[3]1086
[97]1087 if( !isLiteral ){
1088 bLiteralCalculation=0;
1089 }
[3]1090
[97]1091 if( resultType.GetBasicType() & FLAG_CAST ){
1092 // 型名のみ
[468]1093 compiler.errorMessenger.OutputFatalError();
[97]1094 }
1095 else{
1096 if( resultType.IsReal() == false && UseReg==REG_R14 ){
1097 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1098 pobj_sf->push(REG_R14);
1099 }
1100 if( resultType.IsReal() && XmmReg==REG_XMM4 ){
1101 if(resultType.IsDouble()){
1102 //movsd qword ptr[rsp+offset],xmm4 ※スタックフレームを利用
1103 pobj_sf->push(REG_XMM4,sizeof(double));
[3]1104 }
[97]1105 if(resultType.IsSingle()){
1106 //movss dword ptr[rsp+offset],xmm4 ※スタックフレームを利用
1107 pobj_sf->push(REG_XMM4,sizeof(float));
[75]1108 }
[3]1109 }
1110
[97]1111 if( resultType.IsReal() ){
1112 pobj_reg->LockXmmReg();
[3]1113 }
[97]1114 else{
1115 pobj_reg->LockReg();
1116 }
[3]1117 }
1118
[97]1119 sp++;
1120 break;
[3]1121 }
1122
1123
[67]1124 // Nothing
1125 if( lstrcmp( term, "Nothing" ) == 0 ){
[79]1126 isNothing_stack[sp] = true;
1127
[75]1128 if( baseType.IsObject() ){
[633]1129 type_stack[sp] = DEF_OBJECT;
[75]1130 index_stack[sp] = baseType.GetIndex();
[67]1131 }
1132 else{
[633]1133 type_stack[sp] = baseType.GetBasicType();
1134 index_stack[sp] = baseType.GetIndex();
[67]1135 }
1136
1137 bLiteralCalculation = 0;
1138
1139 //xor reg,reg
[226]1140 compiler.codeGenerator.op_zero_reg( UseReg );
[67]1141
1142 if(UseReg==REG_R14){
1143 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1144 pobj_sf->push(REG_R14);
1145 }
1146
1147 pobj_reg->LockReg();
1148 sp++;
1149 break;
1150 }
1151
1152
[3]1153 //////////////
1154 // 定数の場合
1155 //////////////
1156
[584]1157 i3 = compiler.GetObjectModule().meta.GetGlobalConsts().GetBasicType(
1158 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1159 );
[9]1160 if(i3){
[600]1161 if( compiler.GetObjectModule().meta.GetGlobalConsts().IsStringPtr( ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term ), compiler.IsUnicode() ) ){
[103]1162 //リテラル文字列
1163
[319]1164 if( baseType.IsObject() || baseType.IsNull() )
1165 {
1166 //要求タイプがオブジェクト、または未定のとき
1167
1168 //String型オブジェクトを生成
1169 NewStringObject(UseReg,term);
1170
1171 type_stack[sp]=DEF_OBJECT;
1172 index_stack[sp]=(LONG_PTR)compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr();
1173 bLiteralCalculation=0;
1174
1175 if(bXmm) pobj_reg->LockXmmReg();
1176 else pobj_reg->LockReg();
1177
1178 sp++;
1179 break;
1180 }
1181
[584]1182 double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(
1183 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1184 );
[103]1185 memcpy(&i64data,&dbl,sizeof(double));
1186
1187 //バイト数
1188 i3=lstrlen((char *)i64data);
1189
1190 memcpy(term,(char *)i64data,i3);
1191 term[i3]=0;
1192 goto StrLiteral;
1193 }
1194
[75]1195 type_stack[sp] = i3;
[3]1196 if(IsRealNumberType(i3)){
1197 //実数
[584]1198 double dbl = compiler.GetObjectModule().meta.GetGlobalConsts().GetDoubleData(
1199 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1200 );
[3]1201 memcpy(&i64data,&dbl,sizeof(double));
1202 goto Literal;
1203 }
1204 else if(IsWholeNumberType(i3)){
1205 //整数
[584]1206 i64data = compiler.GetObjectModule().meta.GetGlobalConsts().GetWholeData(
1207 ActiveBasic::Compiler::LexicalAnalyzer::FullNameToSymbol( term )
1208 );
[3]1209 goto Literal;
1210 }
1211 else{
[468]1212 compiler.errorMessenger.Output(1,NULL,0);
[3]1213 goto error;
1214 }
1215 }
1216
1217
1218 //該当する識別子が見当たらないときはエラー扱いにする
1219 bError=1;
[468]1220 compiler.errorMessenger.Output(3,term,cp);
[75]1221 type_stack[sp]=DEF_DOUBLE;
[3]1222 }
1223 else{
1224 //リテラル値
[75]1225 type_stack[sp]=GetLiteralValue(term,&i64data,baseType.GetBasicType());
[3]1226Literal:
[75]1227 if(type_stack[sp]==DEF_DOUBLE){
[3]1228 //64ビット浮動小数型
1229 bXmm=1;
1230
1231 if(XmmReg==REG_XMM4){
1232 //mov r14,i64data
[232]1233 compiler.codeGenerator.op_mov_RV64(REG_R14,i64data);
[3]1234
1235
1236 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1237 pobj_sf->push(REG_R14);
1238 }
1239 else{
[587]1240 i3 = compiler.GetObjectModule().dataTable.Add( i64data );
[3]1241
1242 //movlpd xmm_reg,qword ptr[data table offset]
[242]1243 compiler.codeGenerator.op_movlpd_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
[3]1244 }
1245 }
[75]1246 else if(type_stack[sp]==DEF_SINGLE){
[3]1247 //32ビット浮動小数型
1248 bXmm=1;
1249
1250 float flt;
1251 int i32data;
1252 memcpy(&dbl,&i64data,sizeof(double));
1253 flt=(float)dbl;
1254 memcpy(&i32data,&flt,sizeof(long));
1255
1256 if(XmmReg==REG_XMM4){
[468]1257 compiler.errorMessenger.OutputFatalError(); // TODO: 未実装
[3]1258 //push term
[226]1259 //compiler.codeGenerator.op_push_value(i32data);
[3]1260 }
1261 else{
[587]1262 i3=compiler.GetObjectModule().dataTable.Add( i32data );
[3]1263
1264 //movss xmm_reg,dword ptr[data table offset]
[242]1265 compiler.codeGenerator.op_movss_RM( XmmReg, 0, i3, MOD_DISP32, Schedule::DataTable );
[3]1266 }
1267 }
1268 else{
1269 //整数
1270
1271 index_stack[sp]=GetLiteralIndex(i64data);
1272
1273 //mov reg,i64data
[232]1274 compiler.codeGenerator.op_mov_RV64(UseReg,i64data);
[3]1275
1276 if(UseReg==REG_R14){
1277 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用
1278 pobj_sf->push(REG_R14);
1279 }
1280 }
1281 }
1282
1283 if(bXmm) pobj_reg->LockXmmReg();
1284 else pobj_reg->LockReg();
1285
1286 sp++;
1287 break;
1288
1289 //論理演算子
1290 case CALC_XOR:
1291 case CALC_OR:
1292 case CALC_AND:
[75]1293 if(!CalcTwoTerm_Logical(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1294 break;
1295 case CALC_NOT:
1296 //value[sp-1]=Not value[sp-1]
1297 //NOT演算子
[75]1298 if(!Calc_Not(type_stack,sp)) goto error;
[3]1299 break;
1300
1301 //比較演算子
1302 case CALC_PE: //value[sp-2] <= value[sp-1]
1303 case CALC_QE: //value[sp-2] >= value[sp-1]
1304 case CALC_P: //value[sp-2] < value[sp-1]
1305 case CALC_Q: //value[sp-2] > value[sp-1]
1306 case CALC_NOTEQUAL: //value[sp-2] <> value[sp-1]
1307 case CALC_EQUAL: //value[sp-2] = value[sp-1]
[75]1308 if(!CalcTwoTerm_Relational(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1309 break;
1310
1311 //ビットシフト
1312 case CALC_SHL: //value[sp-2] << value[sp-1]
1313 case CALC_SHR: //value[sp-2] >> value[sp-1]
[75]1314 if(!Calc_Shift(idCalc,type_stack,&sp)) goto error;
[3]1315 break;
1316
1317 //算術演算
1318 case CALC_ADDITION:
1319 case CALC_SUBTRACTION:
1320 case CALC_PRODUCT:
[75]1321 if(!CalcTwoTerm_Arithmetic(idCalc,type_stack,index_stack,&sp)) goto error;
[3]1322 break;
1323 case CALC_MOD:
1324 //value[sp-2]%=value[sp-1]
1325 //剰余演算
[75]1326 if(!Calc_Mod(type_stack,index_stack,&sp)) goto error;
[3]1327 break;
1328 case CALC_QUOTIENT:
1329 //value[sp-2]/=value[sp-1];
1330 //除算
[75]1331 if(!Calc_Divide(type_stack,&sp,baseType.GetBasicType())) goto error;
[3]1332 break;
1333 case CALC_INTQUOTIENT:
1334 //value[sp-2]/=value[sp-1]
1335 //整数除算
[75]1336 if(!Calc_IntDivide(type_stack,index_stack,&sp)) goto error;
[3]1337 break;
1338 case CALC_MINUSMARK:
1339 //value[sp-1]=-value[sp-1]
1340 //符号反転
[75]1341 if(!Calc_MinusMark(type_stack,sp)) goto error;
[3]1342 break;
1343 case CALC_POWER:
1344 //べき乗演算(浮動小数点演算のみ)
[75]1345 if(!Calc_Power(type_stack,&sp)) goto error;
[3]1346 break;
1347 case CALC_AS:
1348 //キャスト
[75]1349 if(!Calc_Cast(type_stack,index_stack,&sp)) goto error;
[3]1350 break;
[41]1351 case CALC_BYVAL:
1352 //ポインタ型→参照型
[75]1353 if( PTR_LEVEL( type_stack[sp-1] ) <= 0 ){
[41]1354 //ポインタ型ではないとき
[468]1355 compiler.errorMessenger.Output( 3, NULL, cp );
[41]1356 goto error;
1357 }
[3]1358
[75]1359 type_stack[sp-1] = PTR_LEVEL_DOWN( type_stack[sp-1] );
[41]1360
1361 break;
1362
[3]1363 default:
[468]1364 compiler.errorMessenger.Output(300,NULL,cp);
[41]1365 goto error;
[3]1366 }
1367 }
1368
1369 if(bError) goto error;
1370
1371 if(sp!=1){
[468]1372 compiler.errorMessenger.Output(1,NULL,cp);
[3]1373 goto error;
1374 }
1375
1376 if(bLiteralCalculation){
[468]1377 compiler.errorMessenger.OutputFatalError();
[3]1378 }
1379 else{
1380 //右辺値が数値の定数式ではないとき
1381 if(IS_LITERAL(index_stack[0])) index_stack[0]=-1;
1382 }
1383
[436]1384 if( pbIsNeedHeapFreeStructure )
1385 {
1386 *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0];
1387 }
[3]1388
[75]1389 if(IsRealNumberType(type_stack[0]))
[3]1390 *pReg=pobj_reg->UnlockXmmReg();
1391 else
1392 *pReg=pobj_reg->UnlockReg();
1393
1394
[75]1395 resultType.SetType( type_stack[0], index_stack[0] );
1396
1397 bool isSuccessful = true;
[3]1398 goto finish;
1399
1400
1401
1402 //////////////////
1403 // エラー処理
1404 //////////////////
1405
1406error:
1407
[75]1408 isSuccessful = false;
[3]1409 goto finish;
1410
1411
1412
1413
1414finish:
1415
1416 for(i=0;i<pnum;i++){
1417 if(values[i]) HeapDefaultFree(values[i]);
1418 }
1419
[75]1420 return isSuccessful;
[3]1421}
[255]1422
1423bool NumOpe( int *pReg,
1424 const char *expression,
1425 const Type &baseType,
1426 Type &resultType,
[436]1427 bool *pbIsNeedHeapFreeStructure )
[255]1428{
[417]1429 bool isInitRegSwitch = false;
1430 if( !pobj_reg )
1431 {
1432 isInitRegSwitch = true;
[255]1433
1434 //作業用レジスタを取得
[417]1435 pobj_reg = new CRegister( *pReg );
[255]1436 }
1437
1438 //エラー時の復旧用
[417]1439 CRegister objReg_Backup = *pobj_reg;
[255]1440
1441 *pReg = pobj_reg->GetNextReg();
1442
1443
[436]1444 bool result = _numope( pReg, expression, baseType, resultType, pbIsNeedHeapFreeStructure );
[255]1445
1446
1447 if( !result )
1448 {
[417]1449 *pobj_reg = objReg_Backup;
[255]1450 }
1451
[417]1452 if( isInitRegSwitch ){
[255]1453 //整合性をチェック(バグ回避)
1454 if( result )
1455 {
1456 pobj_reg->bug_check();
1457 }
1458
1459 //作業レジスタを解放
1460 delete pobj_reg;
[417]1461 pobj_reg = NULL;
[255]1462 }
1463
1464 return result;
1465}
Note: See TracBrowser for help on using the repository browser.