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

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