source: dev/trunk/ab5.0/abdev/BasicCompiler32/Compile_Var.cpp@ 453

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

"Dim a = 0 As *Char" など、Charポインタ型変数の初期値にリテラル数値を指定すると強制終了してしまうバグを修正。

File size: 34.4 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() ){
[453]867 if( type.GetBasicType() == typeOfPtrChar && calcType.GetIndex() == LITERAL_STRING )
868 {
[3]869 //文字列定数のとき
870
871 char *temp;
872 temp=(char *)i64data;
[265]873 i2=compiler.GetObjectModule().dataTable.AddString(temp,lstrlen(temp));
[3]874 HeapDefaultFree(temp);
875
876 //mov eax,DataPos
[237]877 compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
[3]878
879 //mov dword ptr[offset],eax
[230]880 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, 0, offset, MOD_DISP32, Schedule::GlobalVar );
[3]881 }
882 else{
[288]883 long l = (long)i64data;
884 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
885 offset,
886 (const char *)&l,
887 sizeof(long)
888 );
[3]889 }
890 }
[75]891 else if( type.IsWord() || type.IsInteger() ){
[288]892 short s = (short)i64data;
893 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
894 offset,
895 (const char *)&s,
896 sizeof(short)
897 );
[75]898 }
899 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
[288]900 char c = (char)i64data;
901 compiler.GetObjectModule().meta.GetGlobalVars().initAreaBuffer.Overwrite(
902 offset,
903 (const char *)&c,
904 sizeof(char)
905 );
[75]906 }
907
908 return true;
[3]909}
[206]910bool InitLocalVar(int offset,const Type &type,const Subscripts &subscripts,const char *lpszInitBuf){
911 int i2,i3;
[3]912 char temporary[VN_SIZE];
[138]913 char InitBuf[VN_SIZE];
914 lstrcpy( InitBuf, lpszInitBuf );
[3]915
916 if(InitBuf[0]=='['){
917 SlideString(InitBuf+1,-1);
918 InitBuf[lstrlen(InitBuf)-1]=0;
919
[75]920 int typeSize = type.GetSize();
[3]921
[206]922 if( subscripts.size() > 0 ){
923 Subscripts nestSubscripts;
924 for( int i=1; i<(int)subscripts.size(); i++ )
925 {
926 nestSubscripts.push_back( subscripts[i] );
927 }
928
929 typeSize*=JumpSubScripts( nestSubscripts );
930 {
931 int i=0;
932 i2=0;
933 while(1){
934 if( subscripts[0] < i2 ){
935 SetError(41,0,cp);
936 return 0;
937 }
938 i=GetOneParameter(InitBuf,i,temporary);
939 if(!InitLocalVar(
940 offset+i2*typeSize,
941 type,
942 nestSubscripts,
943 temporary)) return false;
944 i2++;
945 if(InitBuf[i]=='\0') break;
[3]946 }
947 }
[75]948 return true;
[3]949 }
950
[75]951 if(type.IsStruct()){
952 const CClass &objClass = type.GetClass();
[3]953
[140]954 int i = 0;
955 BOOST_FOREACH( CMember *pMember, objClass.GetDynamicMembers() ){
956 if(InitBuf[i]=='\0'){
957 SetError(41,0,cp);
958 return false;
959 }
960
[3]961 i=GetOneParameter(InitBuf,i,temporary);
962
[409]963 i3=objClass.GetMemberOffset( pMember->GetName().c_str() );
[3]964
965 if(!InitLocalVar(offset+i3,
[140]966 pMember->GetType(),
[206]967 pMember->GetSubscripts(),
[75]968 temporary)) return false;
[3]969
970 if(InitBuf[i]=='\0') break;
971 }
[75]972 return true;
[3]973 }
974
975 SetError(41,0,cp);
[75]976 return false;
[3]977 }
978
[20]979
980 ///////////////////////////////////////
981 // 単発式([]で囲まれていない)
982 ///////////////////////////////////////
983
[206]984 if( subscripts.size() > 0 ){
[3]985 SetError(41,0,cp);
[75]986 return false;
[3]987 }
988
989 double dbl;
990 _int64 i64data;
[75]991 Type calcType;
992
993 if( !StaticCalculation(false, InitBuf,type.GetBasicType(),&i64data,calcType) ){
[8]994 //動的データだった場合
[75]995 return false;
[8]996 }
[75]997 if( calcType.IsReal() ){
[3]998 memcpy(&dbl,&i64data,sizeof(double));
999 i64data=(_int64)dbl;
1000 }
1001 else dbl=(double)i64data;
1002
1003 //型チェック
1004 CheckDifferentType(
1005 type,
[75]1006 calcType,
[3]1007 0,0);
1008
[75]1009 if( type.IsDouble() ){
[3]1010 //mov eax,HILONG(dbl)
[241]1011 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&dbl))+4) );
[3]1012
1013 //mov dword ptr[ebp+offset+sizeof(long)],eax
[253]1014 compiler.codeGenerator.localVarPertialSchedules.push_back(
1015 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
1016 );
[3]1017
1018 //mov eax,LOLONG(dbl)
[231]1019 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&dbl) );
[3]1020
1021 //mov dword ptr[ebp+offset],eax
[253]1022 compiler.codeGenerator.localVarPertialSchedules.push_back(
1023 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1024 );
[3]1025 }
[75]1026 else if( type.IsSingle() ){
[3]1027 float flt;
1028 flt=(float)dbl;
[231]1029
[3]1030 //mov eax,InitValue
[231]1031 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)&flt );
[3]1032
1033 //mov dword ptr[ebp+offset],eax
[253]1034 compiler.codeGenerator.localVarPertialSchedules.push_back(
1035 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1036 );
[3]1037 }
[75]1038 else if( type.Is64() ){
[3]1039 //mov eax,HILONG(i64data)
[231]1040 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(((char *)(&i64data))+4) );
[3]1041
1042 //mov dword ptr[ebp+offset+sizeof(long)],eax
[253]1043 compiler.codeGenerator.localVarPertialSchedules.push_back(
1044 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset+sizeof(long), MOD_BASE_DISP32, Schedule::None, true )
1045 );
[3]1046
1047 //mov eax,LOLONG(i64data)
[231]1048 compiler.codeGenerator.op_mov_RV( REG_EAX, *(long *)(&i64data) );
[3]1049
1050 //mov dword ptr[ebp+offset],eax
[253]1051 compiler.codeGenerator.localVarPertialSchedules.push_back(
1052 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1053 );
[3]1054 }
[75]1055 else if( type.IsDWord() || type.IsLong() || type.IsPointer() ){
[453]1056 if( type.GetBasicType() == typeOfPtrChar && calcType.GetIndex() == LITERAL_STRING )
1057 {
[3]1058 //文字列定数のとき
1059
1060 char *temp;
1061 temp=(char *)i64data;
[265]1062 i2=compiler.GetObjectModule().dataTable.AddString(temp,lstrlen(temp));
[3]1063 HeapDefaultFree(temp);
1064
1065 //mov eax,DataPos
[237]1066 compiler.codeGenerator.op_mov_RV( REG_EAX, i2, Schedule::DataTable );
[3]1067 }
1068 else{
1069 //mov eax,InitValue
[231]1070 compiler.codeGenerator.op_mov_RV( REG_EAX, (long)i64data );
[3]1071 }
1072
1073 //mov dword ptr[ebp+offset],eax
[253]1074 compiler.codeGenerator.localVarPertialSchedules.push_back(
1075 compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_EBP, offset, MOD_BASE_DISP32, Schedule::None, true )
1076 );
[3]1077 }
[75]1078 else if( type.IsWord() || type.IsInteger() ){
[234]1079 //mov word ptr[ebp+offset],InitValue
[253]1080 compiler.codeGenerator.localVarPertialSchedules.push_back(
1081 compiler.codeGenerator.op_mov_MV( sizeof(short), REG_EBP, offset, Schedule::None, true, (long)i64data )
1082 );
[3]1083 }
[75]1084 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){
[3]1085 //mov byte ptr[ebp+offset],InitValue
[253]1086 compiler.codeGenerator.localVarPertialSchedules.push_back(
1087 compiler.codeGenerator.op_mov_MV( sizeof(char), REG_EBP, offset, Schedule::None, true, (long)i64data )
1088 );
[3]1089 }
[75]1090
1091 return true;
[3]1092}
1093
[299]1094void dim( char *VarName, const Subscripts &subscripts, const Type &type,const char *InitBuf,const char *ConstractParameter,DWORD dwFlags){
[75]1095 if( UserProc::IsGlobalAreaCompiling() ){
[64]1096 /////////////////////////
1097 // グローバル変数
1098 /////////////////////////
1099
[206]1100 AddGlobalVariable(VarName,subscripts,type,InitBuf,ConstractParameter,dwFlags);
[64]1101 }
1102 else{
1103 /////////////////
1104 // ローカル変数
1105 /////////////////
1106
[206]1107 if( UserProc::CompilingUserProc().GetLocalVars().DuplicateCheck( Symbol( VarName ) ) ){
[75]1108 //2重定義のエラー
1109 SetError(15,VarName,cp);
1110 return;
[64]1111 }
1112
[75]1113 bool isConst = ( dwFlags & DIMFLAG_CONST ) ? true:false;
[64]1114
[275]1115 Variable *pVar = new Variable( VarName, type, isConst, false, ConstractParameter, false );
[75]1116
[206]1117 if( subscripts.size() > 0 ){
[75]1118 //配列あり
[206]1119 pVar->SetArray( subscripts );
[64]1120 }
1121
[75]1122 //レキシカルスコープ
[248]1123 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1124 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1125 pVar->isLiving = true;
[75]1126
1127 //エラー用
1128 pVar->source_code_address=cp;
1129
1130 // 変数を追加
[206]1131 UserProc::CompilingUserProc().GetLocalVars().push_back( pVar );
[75]1132
1133 //アラインメントを考慮
[206]1134 if( pVar->GetType().IsStruct() ){
[233]1135 int alignment = pVar->GetType().GetClass().GetFixedAlignment();
[120]1136
[75]1137 if( alignment ){
1138 if( AllLocalVarSize % alignment ){
1139 AllLocalVarSize += alignment - (AllLocalVarSize % alignment);
1140 }
1141 }
[120]1142
1143 if( alignment == PTR_SIZE*2 ){
1144 // ポインタに要するサイズよりも一回り大きなアラインメントが指定されているとき
1145 // (例:CONTEXT構造体など)
1146 // 呼び出し側のオフセットズレを考慮する
1147
[288]1148 if( 0 == ( UserProc::CompilingUserProc().RealParams().GetMemorySize() + PTR_SIZE /* ret分 */ ) % alignment ){
[120]1149 AllLocalVarSize += PTR_SIZE;
1150 }
1151 }
[64]1152 }
1153
[75]1154 AllLocalVarSize += pVar->GetMemorySize();
[206]1155 pVar->SetOffsetAddress( AllLocalVarSize );
[64]1156
1157 //レキシカルスコープ
[248]1158 pVar->SetScopeLevel( compiler.codeGenerator.lexicalScopes.GetNowLevel() );
1159 pVar->SetScopeStartAddress( compiler.codeGenerator.lexicalScopes.GetStartAddress() );
[392]1160 pVar->isLiving = true;
[64]1161
1162 if(InitBuf[0]){
1163 //初期代入時のみ、書き込みアクセスを許可する
[75]1164 if( isConst ){
1165 pVar->ConstOff();
1166 }
[64]1167
1168 int result = 0;
[206]1169 if( !pVar->GetType().IsObject() ){
1170 result = InitLocalVar(-pVar->GetOffsetAddress(),
1171 pVar->GetType(),
1172 pVar->GetSubscripts(),
[64]1173 InitBuf);
1174 }
1175
1176 if(!result){
1177 //動的な式だった場合は代入演算を行う
1178 char temporary[8192];
1179 sprintf(temporary,"%s=%s",VarName,InitBuf);
1180 OpcodeCalc(temporary);
1181 }
1182
[75]1183 if( isConst ){
1184 pVar->ConstOn();
1185 }
[64]1186 }
1187 else{
1188 //push 0
[225]1189 compiler.codeGenerator.op_push_V(0);
[64]1190
1191 //push VarSize
[225]1192 compiler.codeGenerator.op_push_V( pVar->GetMemorySize() );
[64]1193
1194 //mov eax,ebp
[241]1195 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_EBP );
[64]1196
1197 //add eax,offset
[253]1198 compiler.codeGenerator.localVarPertialSchedules.push_back(
1199 compiler.codeGenerator.op_add_RV( REG_EAX, -pVar->GetOffsetAddress(), Schedule::None, true )
1200 );
[64]1201
1202 //push eax
[225]1203 compiler.codeGenerator.op_push(REG_EAX);
[64]1204
1205 //call FillMemory
[250]1206 compiler.codeGenerator.op_call( GetDeclareHash("FillMemory") );
[64]1207 }
1208 }
1209
1210 //New呼び出し
[350]1211 if( type.IsObject()
[370]1212 && !type.IsInterface() && !type.IsComInterface()
[350]1213 &&(dwFlags&DIMFLAG_NONCALL_CONSTRACTOR)==0
1214 &&InitBuf[0]=='\0')
1215 {
[64]1216 char objectSize[255];
[206]1217 if( subscripts.size() == 0 ){
[64]1218 objectSize[0] = 0;
1219 }
1220 else{
[206]1221 if( subscripts.size() > 1 ){
[64]1222 SetError(300,NULL,cp);
1223 }
[206]1224 sprintf( objectSize, "%d", subscripts[0] );
[64]1225 }
[75]1226 Operator_New( type.GetClass(), objectSize, ConstractParameter, type );
[64]1227
1228 //pop eax
[225]1229 compiler.codeGenerator.op_pop( REG_EAX );
[64]1230
1231 RELATIVE_VAR RelativeVar;
[75]1232 GetVarOffset( true, false, VarName, &RelativeVar, Type() );
[64]1233 if( RelativeVar.dwKind == VAR_DIRECTMEM ){
1234 SetError();
1235 }
[290]1236 SetVariableFromEax( Type( DEF_OBJECT, *compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() ), DEF_OBJECT, &RelativeVar );
[64]1237 }
1238}
[3]1239
1240void SetVarPtrToEax(RELATIVE_VAR *pRelativeVar){
1241 if(pRelativeVar->dwKind==VAR_GLOBAL){
1242 if(pRelativeVar->bOffsetOffset){
1243 //lea eax,dword ptr[ecx+offset]
[230]1244 compiler.codeGenerator.op_lea_RM( REG_EAX, REG_ECX, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::GlobalVar );
[3]1245 }
1246 else{
1247 //mov eax,offset
[230]1248 compiler.codeGenerator.op_mov_RV( REG_EAX, pRelativeVar->offset, Schedule::GlobalVar );
[3]1249 }
1250 }
[62]1251 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
1252 if(pRelativeVar->bOffsetOffset){
1253 //mov eax,ecx
[241]1254 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[62]1255
1256 //add eax,dword ptr[offset]
[230]1257 compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]1258 }
1259 else{
1260 //mov eax,dword ptr[offset]
[230]1261 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32, Schedule::GlobalVar );
[62]1262 }
1263 }
[3]1264 else if(pRelativeVar->dwKind==VAR_LOCAL){
1265 if(pRelativeVar->bOffsetOffset){
1266 //add ecx,offset
[253]1267 compiler.codeGenerator.localVarPertialSchedules.push_back(
1268 compiler.codeGenerator.op_add_RV( REG_ECX, pRelativeVar->offset, Schedule::None, true )
1269 );
[3]1270
1271 //lea eax,dword ptr[ebp+ecx]
[241]1272 compiler.codeGenerator.PutOld(
1273 (char)0x8D,
1274 (char)0x44,
1275 (char)0x0D,
1276 (char)0x00
1277 );
[3]1278 }
1279 else{
[230]1280 //lea eax,dword ptr[ecx+offset]
[253]1281 compiler.codeGenerator.localVarPertialSchedules.push_back(
1282 compiler.codeGenerator.op_lea_RM( REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1283 );
[3]1284 }
1285 }
1286 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
1287 if(pRelativeVar->bOffsetOffset){
1288 //mov eax,ecx
[231]1289 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[3]1290
1291 //add eax,dword ptr[ebp+offset]
[253]1292 compiler.codeGenerator.localVarPertialSchedules.push_back(
1293 compiler.codeGenerator.op_add_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1294 );
[3]1295 }
1296 else{
1297 //mov eax,dword ptr[ebp+offset]
[253]1298 compiler.codeGenerator.localVarPertialSchedules.push_back(
1299 compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_EBP, pRelativeVar->offset, MOD_BASE_DISP32, Schedule::None, true )
1300 );
[3]1301 }
1302 }
1303 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
1304 //mov eax,ecx
[231]1305 compiler.codeGenerator.op_mov_RR( REG_EAX, REG_ECX );
[3]1306 }
1307}
[97]1308void SetVarPtrToReg(int reg,RELATIVE_VAR *pRelativeVar){
1309 if( reg != REG_EAX ){
1310 SetError();
1311 //TODO: 未完成
1312 }
1313 SetVarPtrToEax( pRelativeVar );
1314}
[95]1315
1316bool Compile_AddGlobalRootsForGc(){
[206]1317 const UserProc *pUserProc_AddGlobalRootPtr = GetClassMethod( "_System_CGarbageCollection", "AddGlobalRootPtr" );
[95]1318 if( !pUserProc_AddGlobalRootPtr ){
1319 SetError(3, "_System_CGarbageCollection.AddGlobalRootPtr", -1 );
1320 return false;
1321 }
1322
[265]1323 BOOST_FOREACH( const Variable *pVar, compiler.GetObjectModule().meta.GetGlobalVars() ){
[206]1324 if( pVar->GetType().IsObject() || pVar->GetType().IsPointer() || pVar->GetType().IsStruct() ){
[95]1325 // オブジェクトまたはポインタだったとき
1326 // ※構造体も含む(暫定対応)
1327
1328 // 変数領域に要するLONG_PTR単位の個数を引き渡す
[225]1329 compiler.codeGenerator.op_push_V( pVar->GetMemorySize()/PTR_SIZE );
[95]1330
1331
1332 /////////////////////////////
1333 // ルートポインタを引き渡す
1334
1335 //mov eax,offset
[231]1336 compiler.codeGenerator.op_mov_RV(REG_EAX,(int)pVar->GetOffsetAddress(), Schedule::GlobalVar );
[95]1337
1338 //push eax
[225]1339 compiler.codeGenerator.op_push( REG_EAX );
[95]1340
1341 //
1342 /////////////////////////////
1343
1344
1345 /////////////////////////////
1346 // Thisポインタを引き渡す
1347
1348 SetThisPtrToReg(REG_EAX);
1349
1350 //push eax
[225]1351 compiler.codeGenerator.op_push( REG_EAX );
[95]1352
1353 //
1354 /////////////////////////////
1355
1356
1357 // call AddGlobalRootPtr
[225]1358 compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr );
[95]1359 }
1360 }
1361
1362 return true;
1363}
Note: See TracBrowser for help on using the repository browser.