source: dev/BasicCompiler32/Compile_Var.cpp@ 60

Last change on this file since 60 was 56, checked in by dai_9181, 18 years ago

・[Unicode]リテラル文字列のスイッチング
・[Unicode]Char型を文字型として扱うようにする
・[Unicode]SByte型を追加する
に対応。

/unicodeコマンドオプションに対応。

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