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

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

[585][586]をリバース。NativeCodeクラスとMetaクラスは依存関係があるので分離しない方針とする。

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