source: dev/BasicCompiler_Common/Object.cpp@ 57

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

オーバーロード解決用の関数保持リストを "SUBINFO " ではなく、"vector<SUBINFO *>" に変更した。

File size: 4.1 KB
RevLine 
[4]1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
[5]6#include "../BasicCompiler32/opcode.h"
[4]7#endif
8
9extern HANDLE hHeap;
10
11int 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++){
[40]19 CMember *pMember = pobj_c->ppobj_Member[i];
20
21 if(pMember->TypeInfo.type==DEF_OBJECT && pMember->IsRef() == false){
[4]22 //メンバクラスのアラインメントを取得
[40]23 member_size=GetAlignment(pMember->TypeInfo.u.pobj_Class);
[4]24 }
25 else{
26 //メンバサイズを取得
[40]27 member_size = pMember->GetSize();
[4]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}
40int 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++){
[40]53 CMember *pMember = pobj_c->ppobj_Member[i];
[4]54
[40]55 i2 = pMember->GetSize();
56
[4]57 //アラインメントを算出
58 int member_size;
[40]59 if(pMember->TypeInfo.type==DEF_OBJECT){
[4]60 //メンバクラスのアラインメントを取得
[40]61 member_size=GetAlignment(pMember->TypeInfo.u.pobj_Class);
[4]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 //メンバ指定がある場合は、オフセットを返す
[40]87 if(lstrcmp(pMember->name,pMemberName)==0){
[4]88 if(pMemberNum) *pMemberNum=i;
89 return offset;
90 }
91 }
92
93 //配列を考慮したメンバサイズを取得
[40]94 member_size=i2 * JumpSubScripts(pMember->SubScripts);
[4]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}
110int GetSizeOfClass(CClass *pobj_c){
111 return GetSizeOfClassMember(pobj_c,0,0);
112}
113
114
[50]115void CallConstructor(char *ObjectName,int *SubScripts,TYPEINFO &TypeInfo,char *Parameter){
[4]116 if(TypeInfo.type!=DEF_OBJECT) return;
117
118 /////////////////////////////////////
119 // クラスオブジェクトの場合
120 // ※コンストラクタの呼び出し
121 /////////////////////////////////////
122 CClass *pobj_c;
123 pobj_c=(CClass *)TypeInfo.u.lpIndex;
124
125 SUBINFO *psi;
[5]126 psi=GetMethodHash(ObjectName,pobj_c->name,Parameter);
[4]127 if(!psi){
128 if(Parameter[0]) SetError(113,pobj_c->name,cp);
129 return;
130 }
[5]131
132
133 char temporary[VN_SIZE];
134
[4]135 if(SubScripts[0]!=-1){
136 int ss[MAX_ARRAYDIM];
137 memset(ss,0,MAX_ARRAYDIM*sizeof(int));
138 while(1){
139 int i3;
140 for(i3=0;;i3++){
141 if(SubScripts[i3]==-1) break;
142
143 if(ss[i3]>SubScripts[i3]){
144 ss[i3]=0;
145 ss[i3+1]++;
146 }
147 else break;
148 }
149 if(SubScripts[i3]==-1) break;
[5]150 sprintf(temporary,"%s[%d",ObjectName,ss[0]);
[4]151 for(i3=1;;i3++){
152 if(SubScripts[i3]==-1) break;
153
154 sprintf(temporary+lstrlen(temporary),",%d",ss[i3]);
155 }
156 lstrcat(temporary,"]");
157
158 LONG_PTR lp;
159 sprintf(temporary+lstrlen(temporary),".%s",pobj_c->name);
160 CallProc(PROC_DEFAULT,
161 psi,
162 temporary,
163 Parameter,
164 &lp);
165
166 ss[0]++;
167
168
169 //ネイティブコードバッファの再確保
170 extern int obp_AllocSize;
171 if(obp_AllocSize<obp+8192){
172 obp_AllocSize+=8192;
173 OpBuffer=(char *)HeapReAlloc(hHeap,0,OpBuffer,obp_AllocSize); //matea
174 }
175 }
176 }
177 else{
178 LONG_PTR lp;
[5]179 sprintf(temporary,"%s.%s",ObjectName,pobj_c->name);
[4]180 CallProc(PROC_DEFAULT,
181 psi,
182 temporary,
183 Parameter,
184 &lp);
185 }
186}
Note: See TracBrowser for help on using the repository browser.