source: dev/trunk/abdev/BasicCompiler32/Compile_Var.cpp@ 436

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

関数の戻り値の構造体など、一時メモリに保持された構造体のメンバに直接アクセスした場合、その一時メモリの解放が正常に行われないバグを修正(64bit版も修正した)。

File size: 34.3 KB
RevLine 
[206]1#include "stdafx.h"
2
[183]3#include <jenga/include/smoothie/Smoothie.h>
4
[248]5#include <LexicalScope.h>
[183]6#include <CodeGenerator.h>
7#include <Compiler.h>
[206]8#include <Variable.h>
[183]9
[3]10#include "../BasicCompiler_Common/common.h"
11#include "Opcode.h"
12
13//変数
[206]14// TODO: xml未完成
[3]15int AllLocalVarSize;
16
[76]17
[75]18void SetRelativeOffset( Type &resultType, RELATIVE_VAR *pRelativeVar,const char *lpPtrOffset){
[3]19 PushLongVariable(pRelativeVar);
20
[75]21 Type type;
22 NumOpe( lpPtrOffset, Type(), type );
23 ChangeTypeToLong( type.GetBasicType() );
[3]24
25 //pop ebx
[225]26 compiler.codeGenerator.op_pop(REG_EBX);
[3]27
[75]28 if( resultType.PtrLevel() ){
29 resultType.PtrLevelDown();
[63]30
[75]31 int typeSize = resultType.GetSize();
32 if(typeSize>=2){
[64]33 //imul ebx,i2
[225]34 compiler.codeGenerator.op_imul_RV( REG_EBX, typeSize );
[3]35 }
36 }
37 else{
38 //エラー
39 SetError(1,NULL,cp);
40 return;
41 }
42
43 //pop ecx
[225]44 compiler.codeGenerator.op_pop(REG_ECX);
[3]45
46 //add ecx,ebx
[225]47 compiler.codeGenerator.op_add_RR( REG_ECX, REG_EBX );
[3]48}
[64]49void SetRelativeOffset( RELATIVE_VAR &relativeVar ){
50 if(relativeVar.dwKind==VAR_DIRECTMEM){
51 //mov ecx,dword ptr[ecx]
[225]52 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE );
[64]53 }
54 else{
55 //直接参照に切り替え
56 SetVarPtrToEax(&relativeVar);
57 relativeVar.dwKind=VAR_DIRECTMEM;
58
59 //mov ecx,dword ptr[eax]
[225]60 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
[64]61 }
62}
[206]63bool GetArrayOffset(const Subscripts &subscripts,char *array, const Type &type){
[3]64 extern HANDLE hHeap;
[75]65 int i,i2,i3,i4;
[3]66 char temporary[VN_SIZE],*pParm[MAX_PARMS];
67
68 for(i=0,i2=0,i3=0;;i++,i2++){
69 if(array[i]=='('){
70 i4=GetStringInPare(temporary+i2,array+i);
71 i+=i4-1;
72 i2+=i4-1;
73 continue;
74 }
75 if(array[i]=='['){
76 i4=GetStringInBracket(temporary+i2,array+i);
77 i+=i4-1;
78 i2+=i4-1;
79 continue;
80 }
81 if(array[i]==','||array[i]=='\0'){
[206]82 if( i3 >= (int)subscripts.size() )
83 {
[3]84 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
85 return 0;
86 }
87
88 temporary[i2]=0;
89
90 pParm[i3]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
91 lstrcpy(pParm[i3],temporary);
92
93 i3++;
94
95 if(array[i]=='\0'){
[206]96 if( i3 < (int)subscripts.size() )
97 {
[3]98 for(i3--;i3>=0;i3--) HeapDefaultFree(pParm[i3]);
99 return 0;
100 }
101 break;
102 }
103
104 i2=-1;
105 continue;
106 }
107 temporary[i2]=array[i];
108 }
109
110 //push ecx
[225]111 compiler.codeGenerator.op_push(REG_ECX);
[3]112
113 //push 0
[225]114 compiler.codeGenerator.op_push_V(0);
[3]115
116 for(i=i3-1;i>=0;i--){
[75]117 Type tempType;
[436]118 bool isNeedHeapFreeStructure;
119 NumOpe( pParm[i], Type( DEF_LONG ), tempType, &isNeedHeapFreeStructure );
120 if( tempType.IsObject() )
121 {
[3]122 //キャスト演算子のオーバーロードに対応する
123 CallCastOperatorProc(
[75]124 tempType,
[436]125 isNeedHeapFreeStructure, Type(DEF_LONG) );
[75]126 tempType.SetBasicType( DEF_LONG );
[3]127 }
[75]128 ChangeTypeToLong( tempType.GetBasicType() );
[3]129
130 //pop eax
[225]131 compiler.codeGenerator.op_pop(REG_EAX);
[3]132
[436]133 for( i2=i+1, i4=1; i2<i3; i2++ )
134 {
135 i4*=subscripts[i2]+1;
136 }
[3]137
138 //imul eax,i4
[236]139 compiler.codeGenerator.op_imul_RV( REG_EAX, i4 );
[3]140
141 //add dword ptr[esp],eax
[241]142 compiler.codeGenerator.PutOld(
143 (char)0x01,
144 (char)0x04,
145 (char)0x24
146 );
[3]147
148 HeapDefaultFree(pParm[i]);
149 }
150
151 //pop eax
[225]152 compiler.codeGenerator.op_pop(REG_EAX);
[3]153
154 //imul eax,TypeSize
[236]155 compiler.codeGenerator.op_imul_RV( REG_EAX, type.GetSize() );
[3]156
157 //pop ecx
[225]158 compiler.codeGenerator.op_pop(REG_ECX);
[3]159
160 //add ecx,eax
[225]161 compiler.codeGenerator.op_add_RR( REG_ECX, REG_EAX );
[3]162
163 return 1;
164}
[290]165bool _member_offset(bool isErrorEnabled, bool isWriteAccess, const Type &classType, const char *member, RELATIVE_VAR *pRelativeVar, Type &resultType, BOOL bPrivateAccess)
166{
167 const CClass &objClass = classType.GetClass();
[3]168
[75]169 //////////////////////////////////////
170 // クラス、配列の構成要素を解析する
171 //////////////////////////////////////
172
[3]173 char VarName[VN_SIZE]; //変数名
174 char array[VN_SIZE]; //第1次配列
175 char lpPtrOffset[VN_SIZE]; //第2次配列
176 char NestMember[VN_SIZE]; //入れ子メンバ
[206]177 ReferenceKind refType;
[3]178 lstrcpy(VarName,member);
[75]179 if(!GetVarFormatString(VarName,array,lpPtrOffset,NestMember,refType)) return false;
[3]180
[75]181
[3]182 ////////////////////////////
183 // メンバオフセットを取得
184 ////////////////////////////
185
[409]186 const CMember *pMember = objClass.FindDynamicMember( VarName );
187 if( !pMember )
188 {
[17]189 if(isErrorEnabled) SetError(103,VarName,cp);
[75]190 return false;
[3]191 }
192
[409]193 int offset = objClass.GetMemberOffset( VarName );
[40]194
[75]195
[3]196 //アクセシビリティをチェック
[206]197 if(&objClass==compiler.pCompilingClass){
[3]198 //同一クラスオブジェクトの場合はプライベートアクセスを容認する
[137]199 if(pMember->IsNoneAccess()){
[17]200 if(isErrorEnabled) SetError(107,VarName,cp);
[75]201 return false;
[3]202 }
203 }
204 else{
[137]205 if((bPrivateAccess==0&&pMember->IsPrivate())||
206 pMember->IsNoneAccess()){
[17]207 if(isErrorEnabled) SetError(107,VarName,cp);
[75]208 return false;
[3]209 }
[137]210 else if(bPrivateAccess==0&&pMember->IsProtected()){
[17]211 if(isErrorEnabled) SetError(108,VarName,cp);
[75]212 return false;
[3]213 }
214 }
215
[17]216 //Const定義の場合は書き込みアクセスを制限する
217 //※コンストラクタをコンパイル中の場合は例外的に許可する
[40]218 if( pMember->IsConst() && //定数メンバである
[17]219 isWriteAccess && //書き込みアクセスを要求されている
[75]220 objClass.IsCompilingConstructor() == false //コンストラクタ コンパイル中を除く
[17]221 ){
222 //Const定義の変数に書き込みアクセスをしようとした場合
223 SetError(61,VarName,cp);
224 }
225
[137]226 resultType = pMember->GetType();
[3]227
[299]228 // 型パラメータを解決
229 ResolveFormalGenericTypeParameter( resultType, classType );
[290]230
231
[3]232 //ポインタ変数の場合
[75]233 if( resultType.IsPointer() ){
[206]234 if( pMember->GetSubscripts().size() == 0 ){
[3]235 lstrcpy(lpPtrOffset,array);
236 array[0]=0;
237 }
238 }
239 else{
240 if(lpPtrOffset[0]){
[17]241 if(isErrorEnabled) SetError(16,member,cp);
[75]242 return false;
[3]243 }
244 }
245
246 if(offset){
247 //add ecx,offset
[241]248 compiler.codeGenerator.op_add_RV( REG_ECX, offset );
[3]249 }
250
251 if(array[0]){
252 //配列オフセット
[206]253 if(!GetArrayOffset(pMember->GetSubscripts(),array,pMember->GetType())){
[17]254 if(isErrorEnabled) SetError(14,member,cp);
[334]255 return false;
[75]256 }
[3]257 }
[206]258 else if( pMember->GetSubscripts().size() > 0 ){
[75]259 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
[3]260 }
261
262 if(NestMember[0]){
263 //入れ子構造の場合
264
[75]265 if( resultType.IsObject() || resultType.IsStruct() ){
[206]266 if( refType != RefDot ){
[17]267 if(isErrorEnabled) SetError(104,member,cp);
[75]268 return false;
[3]269 }
[64]270
[75]271 if( resultType.IsObject() ){
[64]272 // 参照内容へのポインタを抽出
273 SetRelativeOffset( *pRelativeVar );
274 }
[3]275 }
[75]276 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
[3]277 //構造体ポインタ型メンバ変数
278
279 if(lpPtrOffset[0]){
280 //pObj[n].member
[75]281 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
[206]282 && refType != RefDot ){
[75]283 if(isErrorEnabled) SetError(104,member,cp);
284 return false;
[3]285 }
286
287 //直接参照に切り替え
[75]288 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]289 pRelativeVar->dwKind=VAR_DIRECTMEM;
290
291 lpPtrOffset[0]=0;
292 }
293 else{
294 //pObj->member
[75]295 if( ( resultType.IsObjectPtr() || resultType.IsStructPtr() )
[206]296 && refType != RefPointer ){
[75]297 if(isErrorEnabled) SetError(104,member,cp);
298 return false;
[3]299 }
300
[64]301 SetRelativeOffset( *pRelativeVar );
[3]302 }
303 }
[75]304 else if( resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_OBJECT,2)
305 || resultType.GetBasicType() == MAKE_PTR_TYPE(DEF_STRUCT,2)){
[3]306 //構造体ポインタのポインタ型メンバ変数
307
308 if(lpPtrOffset[0]){
309 //ppObj[n]->member
[206]310 if( refType != RefPointer ){
[17]311 if(isErrorEnabled) SetError(104,member,cp);
[75]312 return false;
[3]313 }
314
315 //直接参照に切り替え
[75]316 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]317 pRelativeVar->dwKind=VAR_DIRECTMEM;
318
319 lpPtrOffset[0]=0;
320
321 //mov ecx,dword ptr[ecx]
[241]322 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_ECX, 0, MOD_BASE );
[3]323 }
324 else{
[17]325 if(isErrorEnabled) SetError(104,member,cp);
[75]326 return false;
[3]327 }
328 }
329
[75]330 if(!_member_offset(
[17]331 isErrorEnabled,
332 isWriteAccess,
[290]333 pMember->GetType(),
[3]334 NestMember,
335 pRelativeVar,
[75]336 resultType,
337 0)) return false;
[3]338 }
339
340 if(lpPtrOffset[0]){
[75]341 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]342 pRelativeVar->dwKind=VAR_DIRECTMEM;
343 }
344
[75]345 return true;
[3]346}
347
348int LocalVar_ThisPtrOffset;
349void SetThisPtrToReg(int reg){
350 //自身のオブジェクトのThisポインタをregにコピー
351
352 RELATIVE_VAR RelativeVar;
353 RelativeVar.dwKind=VAR_LOCAL;
354 RelativeVar.bOffsetOffset=0;
355 RelativeVar.offset=-LocalVar_ThisPtrOffset;
356
[290]357 SetReg_WholeVariable(Type(DEF_PTR_VOID),&RelativeVar,reg);
[3]358}
359
[206]360bool GetVarOffset(bool isErrorEnabled,bool isWriteAccess,const char *NameBuffer,RELATIVE_VAR *pRelativeVar,Type &resultType, Subscripts *pResultSubscripts ){
[106]361 char variable[VN_SIZE];
[3]362
363 if(NameBuffer[0]=='.'){
364 GetWithName(variable);
365 lstrcat(variable,NameBuffer);
366 }
367 else lstrcpy(variable,NameBuffer);
368
[106]369 // 名前空間を分離
370 char namespaceStr[VN_SIZE]="", simpleName[VN_SIZE];
[265]371 compiler.GetObjectModule().meta.GetNamespaces().SplitNamespace( variable, namespaceStr, simpleName );
[106]372
373 // 先頭オブジェクトまたはクラス名と入れ子メンバに分割
[206]374 ReferenceKind refType;
[106]375 char member[VN_SIZE],array[VN_SIZE],lpPtrOffset[VN_SIZE];
376 GetVarFormatString(simpleName,array,lpPtrOffset,member,refType);
[49]377
[106]378 // 名前空間を分離していた場合は結合
379 char VarName[VN_SIZE];
380 if( namespaceStr[0] ){
381 sprintf( VarName, "%s.%s", namespaceStr, simpleName );
[49]382 }
[106]383 else{
384 lstrcpy( VarName, simpleName );
385 }
[49]386
[206]387 const Subscripts *pSubscripts;
[75]388 bool bConst = false;
[3]389
[75]390
391 if( UserProc::IsLocalAreaCompiling() ){
392 //////////////////
[3]393 // ローカル変数
[75]394 //////////////////
[3]395
[206]396 const Variable *pVar = UserProc::CompilingUserProc().GetLocalVars().BackSearch( Symbol( VarName ) );
[75]397 if( pVar ){
[3]398 //ポインタ変数の場合
[206]399 if( pVar->GetType().IsPointer() ){
[75]400 if( !pVar->IsArray() ){
[3]401 lstrcpy(lpPtrOffset,array);
402 array[0]=0;
403 }
404 }
405 else{
406 if(lpPtrOffset[0]){
407 SetError(16,variable,cp);
408 pRelativeVar->dwKind=NON_VAR;
[75]409 return false;
[3]410 }
411 }
412
[206]413 pRelativeVar->offset=-pVar->GetOffsetAddress();
[3]414 pRelativeVar->bOffsetOffset=0;
[75]415 if( pVar->IsRef() ){
416 // 参照型
417 pRelativeVar->dwKind = VAR_REFLOCAL;
418 }
[3]419 else pRelativeVar->dwKind=VAR_LOCAL;
[206]420 resultType = pVar->GetType();
421 pSubscripts = &pVar->GetSubscripts();
[75]422 bConst = pVar->IsConst();
[3]423
[292]424
425 /////////////////////////////////////////////////////////
426 // ☆★☆ ジェネリクスサポート ☆★☆
427
428 if( resultType.IsTypeParameter() )
429 {
430 // 型パラメータだったとき
431
432 int ptrLevel = PTR_LEVEL( resultType.GetBasicType() );
433
[424]434 // 制約クラス(指定されていないときはObjectクラス)にセットする
[292]435 resultType.SetBasicType( DEF_OBJECT );
436
437 for( int i=0; i<ptrLevel; i++ )
438 {
439 resultType.PtrLevelUp();
440 }
441 }
442
443 //
444 /////////////////////////////////////////////////////////
445
[3]446 goto ok;
447 }
448 }
449
[206]450 if(compiler.pCompilingClass){
[3]451 //////////////////////
452 // クラスメンバの参照
453 //////////////////////
454
455 if(lstrcmpi(variable,"This")==0){
456 //Thisオブジェクト
457
458 //Thisポインタをecxにコピー
459 SetThisPtrToReg(REG_ECX);
460
461 pRelativeVar->dwKind=VAR_DIRECTMEM;
462
[206]463 resultType.SetType( DEF_OBJECT, compiler.pCompilingClass );
[75]464 return true;
[3]465 }
466
[76]467 if(memicmp(variable,"This.",5)==0){
[3]468 //Thisオブジェクトのメンバを参照するとき
469 SlideString(variable+5,-5);
470 lstrcpy(VarName,variable);
471 }
472 else{
[409]473 //クラス内の動的メンバを参照するとき(通常)
[3]474
[409]475 if( !compiler.pCompilingClass->HasDynamicMember( VarName ) )
476 {
477 goto NonClassMember;
[3]478 }
479 }
480
[18]481 //Const修飾子のメソッド内でメンバ書き込みアクセスが発生したとき
482 //(コンストラクタ、デストラクタ内を除く)
[265]483 const CMethod *pMethod = compiler.GetObjectModule().meta.GetClasses().GetNowCompilingMethodInfo();
[18]484 if( isWriteAccess &&
[135]485 pMethod->IsConst() &&
[206]486 compiler.pCompilingClass->IsCompilingConstructor() == false &&
487 compiler.pCompilingClass->IsCompilingDestructor() == false
[18]488 ){
489 SetError(131, NULL, cp );
490 }
491
[3]492 /////////////////////////////
493 // thisポインタをecxにセット
494
495 //Thisポインタをecxにコピー
496 SetThisPtrToReg(REG_ECX);
497
498 pRelativeVar->dwKind=VAR_DIRECTMEM;
[75]499 if(!_member_offset(
[17]500 isErrorEnabled,
501 isWriteAccess,
[290]502 Type( DEF_OBJECT, *compiler.pCompilingClass ),
[17]503 variable,
504 pRelativeVar,
[75]505 resultType,1)) return false;
506 return true;
[3]507 }
508
509NonClassMember:
510
[75]511 {
512 const Variable *pVar;
[3]513
[75]514 //////////////////////////
515 // 静的ローカル変数
516 // ※"Static.Object.Method.Variable"
517 //////////////////////////
[3]518
[75]519 char temporary[VN_SIZE];
520 if( UserProc::IsLocalAreaCompiling() ){
521 GetNowStaticVarFullName(VarName,temporary);
522
[265]523 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( Symbol( temporary ) );
[75]524 if( pVar ){
525 goto GlobalOk;
526 }
[3]527 }
528
529
[75]530 //////////////////////////
531 // クラスの静的メンバ
532 //////////////////////////
[3]533
[75]534 if(member[0]){
535 lstrcpy(temporary,member);
[64]536
[104]537 // TODO: 名前空間を考慮したコードになっていない
538
[75]539 char tempMember[VN_SIZE];
540 char tempArray[VN_SIZE];
541 {
[206]542 ReferenceKind refType;
[75]543 GetVarFormatString(temporary,tempArray,lpPtrOffset,tempMember, refType );
544 }
[3]545
[265]546 int typeDefIndex = compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( VarName );
[116]547 if( typeDefIndex != -1 ){
548 // TypeDef後の型名だったとき
[265]549 lstrcpy( VarName, compiler.GetObjectModule().meta.GetTypeDefs()[typeDefIndex].GetBaseName().c_str() );
[116]550 }
551
[75]552 char temp2[VN_SIZE];
553 sprintf(temp2,"%s.%s",VarName,temporary);
[265]554 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( Symbol( temp2 ) );
[75]555 if( pVar ){
556 lstrcpy(member,tempMember);
557 lstrcpy(array,tempArray);
558 goto GlobalOk;
559 }
[3]560 }
561
[206]562 if(compiler.pCompilingClass){
[75]563 //自身のクラスから静的メンバを参照する場合
564 char temp2[VN_SIZE];
[206]565 sprintf(temp2,"%s.%s",compiler.pCompilingClass->GetName().c_str(),VarName);
[265]566 pVar = compiler.GetObjectModule().meta.GetGlobalVars().Find( Symbol( temp2 ) );
[75]567 if( pVar ){
568 goto GlobalOk;
569 }
[3]570 }
571
[75]572 /////////////////////
573 // グローバル変数
574 /////////////////////
[3]575
[265]576 pVar = compiler.GetObjectModule().meta.GetGlobalVars().BackSearch( Symbol( VarName ) );
[75]577 if( pVar ){
[3]578 goto GlobalOk;
579 }
580
[75]581 if(isErrorEnabled) SetError(3,variable,cp);
582 pRelativeVar->dwKind=NON_VAR;
583 return false;
[27]584
585
586
[3]587GlobalOk:
[75]588 //ポインタ変数の場合
[206]589 if( pVar->GetType().IsPointer() ){
[75]590 if( !pVar->IsArray() ){
591 lstrcpy(lpPtrOffset,array);
592 array[0]=0;
593 }
[3]594 }
[75]595 else{
596 if(lpPtrOffset[0]){
597 SetError(16,variable,cp);
598 pRelativeVar->dwKind=NON_VAR;
599 return false;
600 }
[3]601 }
602
[206]603 pRelativeVar->offset=pVar->GetOffsetAddress();
[75]604 pRelativeVar->bOffsetOffset=0;
605 if( pVar->IsRef() ){
606 // 参照型
607 pRelativeVar->dwKind = VAR_REFGLOBAL;
608 }
609 else pRelativeVar->dwKind=VAR_GLOBAL;
[206]610 resultType = pVar->GetType();
611 pSubscripts=&pVar->GetSubscripts();
[75]612 bConst = pVar->IsConst();
[62]613 }
[3]614
615
[75]616
[3]617ok:
618
[18]619 if( bConst && isWriteAccess ){
[11]620 //Const定義の変数に書き込みアクセスをしようとした場合
[75]621 if( resultType.IsObject() ){
[18]622 //オブジェクト定数
623 SetError(130, VarName, cp );
624 }
625 else{
626 //一般のConst変数
627 SetError(61,VarName,cp);
628 }
[11]629 }
[3]630
[206]631 if( array[0] == 0 && pSubscripts->size() > 0 ){
[3]632 //配列の先頭ポインタを示す場合
[75]633 resultType.SetBasicType( resultType.GetBasicType() | FLAG_PTR );
[206]634
635 if( pResultSubscripts )
636 {
637 (*pResultSubscripts) = *pSubscripts;
638 }
[75]639 return true;
[3]640 }
641
642 if(array[0]||member[0]){
643 //xor ecx,ecx(ecxを0に初期化する)
644 //※ecxは変数ベースアドレスからの相対オフセットを示す
[225]645 compiler.codeGenerator.op_zero_reg(REG_ECX);
[3]646
647 pRelativeVar->bOffsetOffset=1;
648 }
649 if(array[0]){
[206]650 if(!GetArrayOffset(*pSubscripts,array,resultType)){
[3]651 SetError(14,variable,cp);
652 pRelativeVar->dwKind=NON_VAR;
[75]653 return false;
[3]654 }
655 }
656 if(member[0]){
[75]657 if( resultType.IsObject() || resultType.IsStruct() ){
[3]658 //実態オブジェクトのメンバを参照(obj.member)
[206]659 if( refType != RefDot ){
[3]660 SetError(104,VarName,cp);
661 pRelativeVar->dwKind=NON_VAR;
[75]662 return false;
[3]663 }
[64]664
[75]665 if( resultType.IsObject() ){
[64]666 // 参照内容へのポインタを抽出
667 SetRelativeOffset( *pRelativeVar );
668 }
[3]669 }
[75]670 else if( resultType.IsObjectPtr() || resultType.IsStructPtr() ){
[3]671 //ポインタオブジェクトが示すメンバを参照
672 if(lpPtrOffset[0]){
673 //pObj[n].member
[206]674 if( refType != RefDot ){
[3]675 SetError(104,VarName,cp);
676 pRelativeVar->dwKind=NON_VAR;
[75]677 return false;
[3]678 }
[75]679 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]680 pRelativeVar->dwKind=VAR_DIRECTMEM;
681 }
682 else{
683 //pObj->member
[206]684 if( refType != RefPointer ){
[3]685 SetError(104,VarName,cp);
686 pRelativeVar->dwKind=NON_VAR;
[75]687 return false;
[3]688 }
689
690 SetVarPtrToEax(pRelativeVar);
691 pRelativeVar->dwKind=VAR_DIRECTMEM;
692
693 //mov ecx,dword ptr[eax]
[241]694 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
[3]695 }
696 }
[75]697 else if( resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_OBJECT,2) || resultType.GetBasicType()==MAKE_PTR_TYPE(DEF_STRUCT,2)){
[3]698 //ポインタオブジェクトが示すメンバを参照
699 if(lpPtrOffset[0]){
700 //ppObj[n]->member
[206]701 if( refType != RefPointer ){
[3]702 SetError(104,VarName,cp);
703 pRelativeVar->dwKind=NON_VAR;
[75]704 return false;
[3]705 }
706
[75]707 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]708 pRelativeVar->dwKind=VAR_DIRECTMEM;
709
710
711 SetVarPtrToEax(pRelativeVar);
712
713 //mov ecx,dword ptr[eax]
[241]714 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
[3]715 }
716 else{
717 SetError(104,VarName,cp);
718 pRelativeVar->dwKind=NON_VAR;
[75]719 return false;
[3]720 }
721 }
722 else{
723 SetError(102,VarName,cp);
724 pRelativeVar->dwKind=NON_VAR;
[75]725 return false;
[3]726 }
[17]727
[301]728 Type classType( resultType );
729
[75]730 if(!_member_offset(
[17]731 isErrorEnabled,
732 isWriteAccess,
[301]733 classType,
[75]734 member,pRelativeVar,resultType,0)) return false;
[17]735
[75]736 return true;
[3]737 }
738
739 if(lpPtrOffset[0]){
[75]740 SetRelativeOffset(resultType,pRelativeVar,lpPtrOffset);
[3]741 pRelativeVar->dwKind=VAR_DIRECTMEM;
742 }
743
[75]744 return true;
[3]745}
746
[206]747bool SetInitGlobalData(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
[140]748 int i2,i3;
[3]749 char temporary[VN_SIZE];
[138]750 char InitBuf[VN_SIZE];
751 lstrcpy( InitBuf, lpszInitBuf );
[3]752
753 if(InitBuf[0]=='['){
754 SlideString(InitBuf+1,-1);
755 InitBuf[lstrlen(InitBuf)-1]=0;
756
[75]757 int typeSize = type.GetSize();
[3]758
[206]759 if( subscripts.size() > 0 ){
760 Subscripts nestSubscripts;
761 for( int i=1; i<(int)subscripts.size(); i++ )
762 {
763 nestSubscripts.push_back( subscripts[i] );
764 }
765
766 typeSize*=JumpSubScripts( nestSubscripts );
767 {
768 int i=0;
769 i2=0;
770 while(1){
771 if( subscripts[0] < i2 ){
772 SetError(41,0,cp);
773 return 0;
774 }
775 i=GetOneParameter(InitBuf,i,temporary);
776 if(!SetInitGlobalData(
777 offset+i2*typeSize,
778 type,
779 nestSubscripts,
780 temporary)) return false;
781 i2++;
782 if(InitBuf[i]=='\0') break;
[3]783 }
784 }
[75]785 return true;
[3]786 }
787
[75]788 if(type.IsStruct()){
789 const CClass &objClass = type.GetClass();
[3]790
[140]791 int i = 0;
792 BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
793 if(InitBuf[i]=='\0'){
794 SetError(41,0,cp);
795 return false;
796 }
797
[3]798 i=GetOneParameter(InitBuf,i,temporary);
799
[409]800 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
[3]801
802 if(!SetInitGlobalData(offset+i3,
[140]803 pMember->GetType(),
[206]804 pMember->GetSubscripts(),
[75]805 temporary)) return false;
[3]806 }
[75]807 return true;
[3]808 }
809
810 SetError(41,0,cp);
[75]811 return false;
[3]812 }
813
[20]814
815 ///////////////////////////////////////
816 // 単発式([]で囲まれていない)
817 ///////////////////////////////////////
818
[206]819 if( subscripts.size() > 0 ){
[3]820 SetError(41,0,cp);
[75]821 return false;
[3]822 }
823
824 double dbl;
825 _int64 i64data;
[75]826 Type calcType;
827
828 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
829 //動的データだった場合
830 return false;
831 }
832 if( calcType.IsReal() ){
[3]833 memcpy(&dbl,&i64data,sizeof(double));
834 i64data=(_int64)dbl;
835 }
836 else dbl=(double)i64data;
837
838 //型チェック
839 CheckDifferentType(
840 type,
[75]841 calcType,
[3]842 0,0);
843
[75]844 if( type.IsDouble() ){
[288]845 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
846 offset,
847 (const char *)&dbl,
848 sizeof(double)
849 );
[75]850 }
851 else if( type.IsSingle() ){
[288]852 float flt = (float)dbl;
853 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
854 offset,
855 (const char *)&flt,
856 sizeof(float)
857 );
[75]858 }
859 else if( type.Is64() ){
[288]860 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
861 offset,
862 (const char *)&i64data,
863 sizeof(_int64)
864 );
[75]865 }
866 else if( type.IsLong() || type.IsDWord() || type.IsPointer() ){
[97]867 if(type.GetBasicType()==typeOfPtrChar){
[3]868 //文字列定数のとき
869
870 char *temp;
871 temp=(char *)i64data;
[265]872 i2=compiler.GetObjectModule().dataTable.AddString(temp,lstrlen(temp));
[3]873 HeapDefaultFree(temp);
874
875 //mov eax,DataPos
[237]876 compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
[3]877
878 //mov dword ptr[offset],eax
[230]879 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, 0, offset, MOD_DISP32, Schedule::GlobalVar );
[3]880 }
881 else{
[288]882 long l = (long)i64data;
883 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
884 offset,
885 (const char *)&l,
886 sizeof(long)
887 );
[3]888 }
889 }
[75]890 else if( type.IsWord() || type.IsInteger() ){
[288]891 short s = (short)i64data;
892 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
893 offset,
894 (const char *)&s,
895 sizeof(short)
896 );
[75]897 }
898 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
[288]899 char c = (char)i64data;
900 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
901 offset,
902 (const char *)&c,
903 sizeof(char)
904 );
[75]905 }
906
907 return true;
[3]908}
[206]909bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
910 int i2,i3;
[3]911 char temporary[VN_SIZE];
[138]912 char InitBuf[VN_SIZE];
913 lstrcpy( InitBuf, lpszInitBuf );
[3]914
915 if(InitBuf[0]=='['){
916 SlideString(InitBuf+1,-1);
917 InitBuf[lstrlen(InitBuf)-1]=0;
918
[75]919 int typeSize = type.GetSize();
[3]920
[206]921 if( subscripts.size() > 0 ){
922 Subscripts nestSubscripts;
923 for( int i=1; i<(int)subscripts.size(); i++ )
924 {
925 nestSubscripts.push_back( subscripts[i] );
926 }
927
928 typeSize*=JumpSubScripts( nestSubscripts );
929 {
930 int i=0;
931 i2=0;
932 while(1){
933 if( subscripts[0] < i2 ){
934 SetError(41,0,cp);
935 return 0;
936 }
937 i=GetOneParameter(InitBuf,i,temporary);
938 if(!InitLocalVar(
939 offset+i2*typeSize,
940 type,
941 nestSubscripts,
942 temporary)) return false;
943 i2++;
944 if(InitBuf[i]=='\0') break;
[3]945 }
946 }
[75]947 return true;
[3]948 }
949
[75]950 if(type.IsStruct()){
951 const CClass &objClass = type.GetClass();
[3]952
[140]953 int i = 0;
954 BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
955 if(InitBuf[i]=='\0'){
956 SetError(41,0,cp);
957 return false;
958 }
959
[3]960 i=GetOneParameter(InitBuf,i,temporary);
961
[409]962 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
[3]963
964 if(!InitLocalVar(offset+i3,
[140]965 pMember->GetType(),
[206]966 pMember->GetSubscripts(),
[75]967 temporary)) return false;
[3]968
969 if(InitBuf[i]=='\0') break;
970 }
[75]971 return true;
[3]972 }
973
974 SetError(41,0,cp);
[75]975 return false;
[3]976 }
977
[20]978
979 ///////////////////////////////////////
980 // 単発式([]で囲まれていない)
981 ///////////////////////////////////////
982
[206]983 if( subscripts.size() > 0 ){
[3]984 SetError(41,0,cp);
[75]985 return false;
[3]986 }
987
988 double dbl;
989 _int64 i64data;
[75]990 Type calcType;
991
992 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
[8]993 //動的データだった場合
[75]994 return false;
[8]995 }
[75]996 if( calcType.IsReal() ){
[3]997 memcpy(&dbl,&i64data,sizeof(double));
998 i64data=(_int64)dbl;
999 }
1000 else dbl=(double)i64data;
1001
1002 //型チェック
1003 CheckDifferentType(
1004 type,
[75]1005 calcType,
[3]1006 0,0);
1007
[75]1008 if( type.IsDouble() ){
[3]1009 //mov eax,HILONG(dbl)
[241]1010 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&dbl))+4) );
[3]1011
1012 //mov dword ptr[ebp+offset+sizeof(long)],eax
[253]1013 compiler.codeGenerator.localVarPertialSchedules.push_back(
1014 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
1015 );
[3]1016
1017 //mov eax,LOLONG(dbl)
[231]1018 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&dbl) );
[3]1019
1020 //mov dword ptr[ebp+offset],eax
[253]1021 compiler.codeGenerator.localVarPertialSchedules.push_back(
1022 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1023 );
[3]1024 }
[75]1025 else if( type.IsSingle() ){
[3]1026 float flt;
1027 flt=(float)dbl;
[231]1028
[3]1029 //mov eax,InitValue
[231]1030 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)&flt );
[3]1031
1032 //mov dword ptr[ebp+offset],eax
[253]1033 compiler.codeGenerator.localVarPertialSchedules.push_back(
1034 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1035 );
[3]1036 }
[75]1037 else if( type.Is64() ){
[3]1038 //mov eax,HILONG(i64data)
[231]1039 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&i64data))+4) );
[3]1040
1041 //mov dword ptr[ebp+offset+sizeof(long)],eax
[253]1042 compiler.codeGenerator.localVarPertialSchedules.push_back(
1043 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
1044 );
[3]1045
1046 //mov eax,LOLONG(i64data)
[231]1047 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&i64data) );
[3]1048
1049 //mov dword ptr[ebp+offset],eax
[253]1050 compiler.codeGenerator.localVarPertialSchedules.push_back(
1051 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1052 );
[3]1053 }
[75]1054 else if( type.IsDWord() || type.IsLong() || type.IsPointer() ){
[97]1055 if(type.GetBasicType()==typeOfPtrChar){
[3]1056 //文字列定数のとき
1057
1058 char *temp;
1059 temp=(char *)i64data;
[265]1060 i2=compiler.GetObjectModule().dataTable.AddString(temp,lstrlen(temp));
[3]1061 HeapDefaultFree(temp);
1062
1063 //mov eax,DataPos
[237]1064 compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
[3]1065 }
1066 else{
1067 //mov eax,InitValue
[231]1068 compiler.codeGenerator.op_mov_RV( REG_EAX, (long)i64data );
[3]1069 }
1070
1071 //mov dword ptr[ebp+offset],eax
[253]1072 compiler.codeGenerator.localVarPertialSchedules.push_back(
1073 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1074 );
[3]1075 }
[75]1076 else if( type.IsWord() || type.IsInteger() ){
[234]1077 //mov word ptr[ebp+offset],InitValue
[253]1078 compiler.codeGenerator.localVarPertialSchedules.push_back(
1079 compiler.codeGenerator.op_mov_MV( sizeof(short), REG_EBP, offset, Schedule::None, true, (long)i64data )
1080 );
[3]1081 }
[75]1082 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
[3]1083 //mov byte ptr[ebp+offset],InitValue
[253]1084 compiler.codeGenerator.localVarPertialSchedules.push_back(
1085 compiler.codeGenerator.op_mov_MV( sizeof(char), REG_EBP, offset, Schedule::None, true, (long)i64data )
1086 );
[3]1087 }
[75]1088
1089 return true;
[3]1090}
1091
[299]1092void dim( char *VarName, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){
[75]1093 if( UserProc::IsGlobalAreaCompiling() ){
[64]1094 /////////////////////////
1095 // グローバル変数
1096 /////////////////////////
1097
[206]1098 AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
[64]1099 }
1100 else{
1101 /////////////////
1102 // ローカル変数
1103 /////////////////
1104
[206]1105 if( UserProc::CompilingUserProc().GetLocalVars().DuplicateCheck( Symbol( VarName ) ) ){
[75]1106 //2重定義のエラー
1107 SetError(15,VarName,cp);
1108 return;
[64]1109 }
1110
[75]1111 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
[64]1112
[275]1113 Variable *pVar = new Variable( VarName, type, isConst, false, ConstractParameter, false );
[75]1114
[206]1115 if( subscripts.size() > 0 ){
[75]1116 //配列あり
[206]1117 pVar->SetArray( subscripts );
[64]1118 }
1119
[75]1120 //レキシカルスコープ
[248]1121 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1122 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1123 pVar->isLiving = true;
[75]1124
1125 //エラー用
1126 pVar->source_code_address=cp;
1127
1128 // 変数を追加
[206]1129 UserProc::CompilingUserProc().GetLocalVars().push_back( pVar );
[75]1130
1131 //アラインメントを考慮
[206]1132 if( pVar->GetType().IsStruct() ){
[233]1133 int alignment = pVar->GetType().GetClass().GetFixedAlignment();
[120]1134
[75]1135 if( alignment ){
1136 if( AllLocalVarSize % alignment ){
1137 AllLocalVarSize += alignment - (AllLocalVarSize % alignment);
1138 }
1139 }
[120]1140
1141 if( alignment == PTR_SIZE*2 ){
1142 // ポインタに要するサイズよりも一回り大きなアラインメントが指定されているとき
1143 // (例:CONTEXT構造体など)
1144 // 呼び出し側のオフセットズレを考慮する
1145
[288]1146 if( 0 == ( UserProc::CompilingUserProc().RealParams().GetMemorySize() + PTR_SIZE /* ret分 */ ) % alignment ){
[120]1147 AllLocalVarSize += PTR_SIZE;
1148 }
1149 }
[64]1150 }
1151
[75]1152 AllLocalVarSize += pVar->GetMemorySize();
[206]1153 pVar->SetOffsetAddress( AllLocalVarSize );
[64]1154
1155 //レキシカルスコープ
[248]1156 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1157 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1158 pVar->isLiving = true;
[64]1159
1160 if(InitBuf[0]){
1161 //初期代入時のみ、書き込みアクセスを許可する
[75]1162 if( isConst ){
1163 pVar->ConstOff();
1164 }
[64]1165
1166 int result = 0;
[206]1167 if( !pVar->GetType().IsObject() ){
1168 result = InitLocalVar(-pVar->GetOffsetAddress(),
1169 pVar->GetType(),
1170 pVar->GetSubscripts(),
[64]1171 InitBuf);
1172 }
1173
1174 if(!result){
1175 //動的な式だった場合は代入演算を行う
1176 char temporary[8192];
1177 sprintf(temporary,"%s=%s",VarName,InitBuf);
1178 OpcodeCalc(temporary);
1179 }
1180
[75]1181 if( isConst ){
1182 pVar->ConstOn();
1183 }
[64]1184 }
1185 else{
1186 //push 0
[225]1187 compiler.codeGenerator.op_push_V(0);
[64]1188
1189 //push VarSize
[225]1190 compiler.codeGenerator.op_push_V( pVar->GetMemorySize() );
[64]1191
1192 //mov eax,ebp
[241]1193 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_EBP );
[64]1194
1195 //add eax,offset
[253]1196 compiler.codeGenerator.localVarPertialSchedules.push_back(
1197 compiler.codeGenerator.op_add_RV( REG_EAX, -pVar->GetOffsetAddress(), Schedule::None, true )
1198 );
[64]1199
1200 //push eax
[225]1201 compiler.codeGenerator.op_push(REG_EAX);
[64]1202
1203 //call FillMemory
[250]1204 compiler.codeGenerator.op_call( GetDeclareHash("FillMemory") );
[64]1205 }
1206 }
1207
1208 //New呼び出し
[350]1209 if( type.IsObject()
[370]1210 && !type.IsInterface() && !type.IsComInterface()
[350]1211 &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0
1212 &&InitBuf[0]=='\0')
1213 {
[64]1214 char objectSize[255];
[206]1215 if( subscripts.size() == 0 ){
[64]1216 objectSize[0] = 0;
1217 }
1218 else{
[206]1219 if( subscripts.size() > 1 ){
[64]1220 SetError(300,NULL,cp);
1221 }
[206]1222 sprintf( objectSize, "%d", subscripts[0] );
[64]1223 }
[75]1224 Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
[64]1225
1226 //pop eax
[225]1227 compiler.codeGenerator.op_pop( REG_EAX );
[64]1228
1229 RELATIVE_VAR RelativeVar;
[75]1230 GetVarOffset( true, false, VarName, &RelativeVar, Type() );
[64]1231 if( RelativeVar.dwKind == VAR_DIRECTMEM ){
1232 SetError();
1233 }
[290]1234 SetVariableFromEax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar );
[64]1235 }
1236}
[3]1237
1238void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar){
1239 if(pRelativeVar->dwKind==VAR_GLOBAL){
1240 if(pRelativeVar->bOffsetOffset){
1241 //lea eax,dword ptr[ecx+offset]
[230]1242 compiler.codeGenerator.op_lea_RM( REG_EAX, REG_ECX, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::GlobalVar );
[3]1243 }
1244 else{
1245 //mov eax,offset
[230]1246 compiler.codeGenerator.op_mov_RV( REG_EAX, pRelativeVar->offset, Schedule::GlobalVar );
[3]1247 }
1248 }
[62]1249 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
1250 if(pRelativeVar->bOffsetOffset){
1251 //mov eax,ecx
[241]1252 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[62]1253
1254 //add eax,dword ptr[offset]
[230]1255 compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]1256 }
1257 else{
1258 //mov eax,dword ptr[offset]
[230]1259 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]1260 }
1261 }
[3]1262 else if(pRelativeVar->dwKind==VAR_LOCAL){
1263 if(pRelativeVar->bOffsetOffset){
1264 //add ecx,offset
[253]1265 compiler.codeGenerator.localVarPertialSchedules.push_back(
1266 compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::None, true )
1267 );
[3]1268
1269 //lea eax,dword ptr[ebp+ecx]
[241]1270 compiler.codeGenerator.PutOld(
1271 (char)0x8D,
1272 (char)0x44,
1273 (char)0x0D,
1274 (char)0x00
1275 );
[3]1276 }
1277 else{
[230]1278 //lea eax,dword ptr[ecx+offset]
[253]1279 compiler.codeGenerator.localVarPertialSchedules.push_back(
1280 compiler.codeGenerator.op_lea_RM( REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1281 );
[3]1282 }
1283 }
1284 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
1285 if(pRelativeVar->bOffsetOffset){
1286 //mov eax,ecx
[231]1287 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[3]1288
1289 //add eax,dword ptr[ebp+offset]
[253]1290 compiler.codeGenerator.localVarPertialSchedules.push_back(
1291 compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1292 );
[3]1293 }
1294 else{
1295 //mov eax,dword ptr[ebp+offset]
[253]1296 compiler.codeGenerator.localVarPertialSchedules.push_back(
1297 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1298 );
[3]1299 }
1300 }
1301 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
1302 //mov eax,ecx
[231]1303 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[3]1304 }
1305}
[97]1306void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){
1307 if( reg != REG_EAX ){
1308 SetError();
1309 //TODO: 未完成
1310 }
1311 SetVarPtrToEax( pRelativeVar );
1312}
[95]1313
1314bool Compile_AddGlobalRootsForGc(){
[206]1315 const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
[95]1316 if( !pUserProc_AddGlobalRootPtr ){
1317 SetError(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
1318 return false;
1319 }
1320
[265]1321 BOOST_FOREACH( const Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
[206]1322 if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
[95]1323 // オブジェクトまたはポインタだったとき
1324 // ※構造体も含む(暫定対応)
1325
1326 // 変数領域に要するLONG_PTR単位の個数を引き渡す
[225]1327 compiler.codeGenerator.op_push_V( pVar->GetMemorySize()/PTR_SIZE );
[95]1328
1329
1330 /////////////////////////////
1331 // ルートポインタを引き渡す
1332
1333 //mov eax,offset
[231]1334 compiler.codeGenerator.op_mov_RV(REG_EAX,(int)pVar->GetOffsetAddress(), Schedule::GlobalVar );
[95]1335
1336 //push eax
[225]1337 compiler.codeGenerator.op_push( REG_EAX );
[95]1338
1339 //
1340 /////////////////////////////
1341
1342
1343 /////////////////////////////
1344 // Thisポインタを引き渡す
1345
1346 SetThisPtrToReg(REG_EAX);
1347
1348 //push eax
[225]1349 compiler.codeGenerator.op_push( REG_EAX );
[95]1350
1351 //
1352 /////////////////////////////
1353
1354
1355 // call AddGlobalRootPtr
[225]1356 compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr );
[95]1357 }
1358 }
1359
1360 return true;
1361}
Note: See TracBrowser for help on using the repository browser.