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

Last change on this file since 208 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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