source: dev/BasicCompiler32/Compile_Var.cpp@ 69

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

一時文字列をNewしたときに、bUseHeapフラグを立たせないようにした(bUseHeapが立つのは一時構造体のときのみ)。
DEF_PTR_CHARを廃止し、typeOfPtrCharを導入。

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