Changeset 63 in dev for BasicCompiler_Common/Object.cpp
- Timestamp:
- Feb 23, 2007, 2:12:26 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Object.cpp
r50 r63 8 8 9 9 extern HANDLE hHeap; 10 11 int GetAlignment(CClass *pobj_c){12 int i;13 int alignment,member_size;14 15 if(pobj_c->vtbl_num) alignment=PTR_SIZE;16 else alignment=0;17 18 for(i=0;i<pobj_c->iMemberNum;i++){19 CMember *pMember = pobj_c->ppobj_Member[i];20 21 if(pMember->TypeInfo.type==DEF_OBJECT && pMember->IsRef() == false){22 //メンバクラスのアラインメントを取得23 member_size=GetAlignment(pMember->TypeInfo.u.pobj_Class);24 }25 else{26 //メンバサイズを取得27 member_size = pMember->GetSize();28 }29 30 //アラインメントをセット31 if(alignment<member_size) alignment=member_size;32 }33 34 if(alignment==0) return 0;35 36 if(pobj_c->iAlign) alignment=pobj_c->iAlign;37 38 return alignment;39 }40 int GetSizeOfClassMember(CClass *pobj_c,char *pMemberName,int *pMemberNum){41 int i,i2,offset;42 43 //仮想関数が存在する場合は関数リストへのポインタのサイズを追加44 if(pobj_c->vtbl_num) offset=PTR_SIZE;45 else offset=0;46 47 int alignment;48 if(pobj_c->iAlign) alignment=pobj_c->iAlign;49 else alignment=1;50 51 int iMaxAlign=0;52 for(i=0;i<pobj_c->iMemberNum;i++){53 CMember *pMember = pobj_c->ppobj_Member[i];54 55 i2 = pMember->GetSize();56 57 //アラインメントを算出58 int member_size;59 if(pMember->TypeInfo.type==DEF_OBJECT){60 //メンバクラスのアラインメントを取得61 member_size=GetAlignment(pMember->TypeInfo.u.pobj_Class);62 }63 else{64 //メンバサイズを取得65 member_size=i2;66 }67 if(iMaxAlign<member_size) iMaxAlign=member_size;68 69 //アラインメントを考慮70 if(pobj_c->iAlign&&pobj_c->iAlign<member_size){71 if(offset%alignment) offset+=alignment-(offset%alignment);72 }73 else{74 if(alignment<member_size) alignment=member_size;75 76 if(member_size==0){77 //メンバを持たないクラス78 //※何もしない(オフセットの計算をしない)79 }80 else{81 if(offset%member_size) offset+=member_size-(offset%member_size);82 }83 }84 85 if(pMemberName){86 //メンバ指定がある場合は、オフセットを返す87 if(lstrcmp(pMember->name,pMemberName)==0){88 if(pMemberNum) *pMemberNum=i;89 return offset;90 }91 }92 93 //配列を考慮したメンバサイズを取得94 member_size=i2 * JumpSubScripts(pMember->SubScripts);95 96 //メンバサイズを加算97 offset+= member_size;98 }99 100 if(iMaxAlign<alignment) alignment=iMaxAlign;101 102 //アラインメントを考慮103 if(alignment){104 if(offset%alignment) offset+=alignment-(offset%alignment);105 }106 107 if(pMemberNum) *pMemberNum=i;108 return offset;109 }110 int GetSizeOfClass(CClass *pobj_c){111 return GetSizeOfClassMember(pobj_c,0,0);112 }113 114 10 115 11 void CallConstructor(char *ObjectName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter){
Note:
See TracChangeset
for help on using the changeset viewer.