Changeset 90 in dev for BasicCompiler_Common/Class.cpp
- Timestamp:
- Apr 7, 2007, 3:02:29 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/Class.cpp
r89 r90 146 146 147 147 148 149 CClass::CClass(const char *name){ 150 memset(this,0,sizeof(CClass)); 151 152 vtbl_offset=-1; 153 148 CClass::CClass(const char *name): 149 ConstructorMemberSubIndex( 0 ), 150 DestructorMemberSubIndex( 0 ), 151 classType( Class ), 152 pobj_InheritsClass( NULL ), 153 ppobj_Member( NULL ), 154 iMemberNum( 0 ), 155 vtbl_num( 0 ), 156 iAlign( 0 ), 157 vtbl_offset( -1 ), 158 isCompilingConstructor( false ), 159 isCompilingDestructor( false ), 160 pobj_NextClass( NULL ) 161 { 154 162 this->name=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1); 155 163 lstrcpy(this->name,name); 156 157 isCompilingConstructor = false;158 isCompilingDestructor = false;159 164 } 160 165 CClass::~CClass(){ … … 189 194 } 190 195 196 bool CClass::IsClass() const 197 { 198 return classType == CClass::Class; 199 } 200 bool CClass::IsInterface() const 201 { 202 return classType == CClass::Interface; 203 } 204 bool CClass::IsEnum() const 205 { 206 return classType == CClass::Enum; 207 } 208 bool CClass::IsDelegate() const 209 { 210 return classType == CClass::Delegate; 211 } 191 212 bool CClass::IsStructure() const 192 213 { … … 194 215 } 195 216 196 void CClass::Inherits( CClass *pInheritsClass ){ 217 bool CClass::Inherits( CClass &inheritsClass, int nowLine ){ 218 219 //ループ継承でないかをチェック 220 if(pobj_LoopRefCheck->check(inheritsClass)){ 221 SetError(123,inheritsClass.name,nowLine); 222 return false; 223 } 224 225 if( inheritsClass.ppobj_Member == 0 ){ 226 //継承先が読み取られていないとき 227 pobj_LoopRefCheck->add(this->name); 228 pobj_DBClass->GetClass_recur(inheritsClass.name); 229 pobj_LoopRefCheck->del(this->name); 230 } 197 231 198 232 //メンバをコピー … … 201 235 0, 202 236 ppobj_Member, 203 pInheritsClass->iMemberNum*sizeof(CMember *)); 204 iMemberNum=pInheritsClass->iMemberNum; 205 for(int i3=0;i3<pInheritsClass->iMemberNum;i3++){ 206 ppobj_Member[i3]=new CMember( *pInheritsClass->ppobj_Member[i3] ); 237 ( iMemberNum + inheritsClass.iMemberNum )*sizeof(CMember *)); 238 for(int i3=0;i3<inheritsClass.iMemberNum;i3++){ 239 ppobj_Member[iMemberNum]=new CMember( *inheritsClass.ppobj_Member[i3] ); 207 240 208 241 //dwAccess 209 if(pInheritsClass->ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE) 210 ppobj_Member[i3]->dwAccess=ACCESS_NON; 211 else ppobj_Member[i3]->dwAccess=pInheritsClass->ppobj_Member[i3]->dwAccess; 242 if(inheritsClass.ppobj_Member[i3]->dwAccess==ACCESS_PRIVATE) 243 ppobj_Member[iMemberNum]->dwAccess=ACCESS_NON; 244 else ppobj_Member[iMemberNum]->dwAccess=inheritsClass.ppobj_Member[i3]->dwAccess; 245 246 iMemberNum++; 212 247 } 213 248 214 249 //メソッドをコピー 215 foreach( CMethod *baseMethod, pInheritsClass->methods ){250 foreach( CMethod *baseMethod, inheritsClass.methods ){ 216 251 CMethod *method = new CMethod( baseMethod ); 217 252 … … 224 259 // ※継承元のClassIndexをセット(入れ子継承を考慮する) 225 260 if(baseMethod->pobj_InheritsClass==0) 226 method->pobj_InheritsClass= pInheritsClass;261 method->pobj_InheritsClass=&inheritsClass; 227 262 else 228 263 method->pobj_InheritsClass= … … 233 268 234 269 //仮想関数の数 235 vtbl_num =pInheritsClass->vtbl_num;270 vtbl_num += inheritsClass.vtbl_num; 236 271 237 272 //継承先のクラスをメンバとして保持する 238 pobj_InheritsClass = pInheritsClass; 273 pobj_InheritsClass = &inheritsClass; 274 275 return true; 276 } 277 bool CClass::InheritsInterface( CClass &inheritsInterface, int nowLine ){ 278 279 //ループ継承でないかをチェック 280 if(pobj_LoopRefCheck->check(inheritsInterface)){ 281 SetError(123,inheritsInterface.name,nowLine); 282 return false; 283 } 284 285 if( inheritsInterface.ppobj_Member == 0 ){ 286 //継承先が読み取られていないとき 287 pobj_LoopRefCheck->add(this->name); 288 pobj_DBClass->GetClass_recur(inheritsInterface.name); 289 pobj_LoopRefCheck->del(this->name); 290 } 291 292 //メソッドをコピー 293 foreach( CMethod *baseMethod, inheritsInterface.methods ){ 294 CMethod *method = new CMethod( baseMethod ); 295 296 //dwAccess 297 if(baseMethod->dwAccess==ACCESS_PRIVATE) 298 method->dwAccess=ACCESS_NON; 299 else method->dwAccess=baseMethod->dwAccess; 300 301 //pobj_Inherits 302 // ※継承元のClassIndexをセット(入れ子継承を考慮する) 303 if(baseMethod->pobj_InheritsClass==0) 304 method->pobj_InheritsClass=&inheritsInterface; 305 else 306 method->pobj_InheritsClass= 307 baseMethod->pobj_InheritsClass; 308 309 methods.push_back( method ); 310 } 311 312 //仮想関数の数 313 vtbl_num += inheritsInterface.vtbl_num; 314 315 /* 316 TODO: インターフェイス向けの機構を作る 317 //継承先のクラスをメンバとして保持する 318 pobj_InheritsClass = &inheritsInterface; 319 */ 320 321 return true; 239 322 } 240 323 void CClass::AddMember( DWORD dwAccess, bool isConst, bool isRef, char *buffer ){ … … 950 1033 if(pMember->IsStruct()){ 951 1034 //循環参照でないかをチェック 952 if(pobj_LoopRefCheck->check(pMember->GetClass() .name)){1035 if(pobj_LoopRefCheck->check(pMember->GetClass())){ 953 1036 extern int cp; 954 1037 SetError(124,pMember->GetClass().name,cp); … … 1035 1118 } 1036 1119 1037 //ループ継承でないかをチェック 1038 if(pobj_LoopRefCheck->check(temporary)){ 1039 SetError(123,temporary,i); 1120 //継承させる 1121 if( !pobj_c->InheritsInterface( *pInheritsClass, i ) ){ 1040 1122 goto Interface_InheritsError; 1041 1123 } 1042 1043 if( pInheritsClass->ppobj_Member == 0 ){1044 //継承先が読み取られていないとき1045 pobj_LoopRefCheck->add(pobj_c->name);1046 GetClass_recur(temporary);1047 pobj_LoopRefCheck->del(pobj_c->name);1048 }1049 1050 //継承させる1051 pobj_c->Inherits( pInheritsClass );1052 1124 } 1053 1125 else{ … … 1207 1279 } 1208 1280 1209 //ループ継承でないかをチェック 1210 if(pobj_LoopRefCheck->check(temporary)){ 1211 SetError(123,temporary,i); 1281 if( pInheritsClass->IsInterface() ){ 1282 // クラスを継承していないとき 1283 CClass *pObjectClass = check("Object"); 1284 if( !pObjectClass ){ 1285 SetError(106,"Object",i); 1286 goto InheritsError; 1287 } 1288 1289 if( !pobj_c->Inherits( *pObjectClass, i ) ){ 1290 goto InheritsError; 1291 } 1292 } 1293 1294 //継承させる 1295 if( !pobj_c->Inherits( *pInheritsClass, i ) ){ 1212 1296 goto InheritsError; 1213 1297 } 1214 1215 if( pInheritsClass->ppobj_Member == 0 ){1216 //継承先が読み取られていないとき1217 pobj_LoopRefCheck->add(pobj_c->name);1218 GetClass_recur(temporary);1219 pobj_LoopRefCheck->del(pobj_c->name);1220 }1221 1222 //継承させる1223 pobj_c->Inherits( pInheritsClass );1224 1298 } 1225 1299 InheritsError: … … 1425 1499 1426 1500 void CDBClass::Compile_System_InitializeUserTypes(){ 1501 char temporary[VN_SIZE]; 1427 1502 1428 1503 //////////////////////////////////////////////////////////////////// … … 1436 1511 CClass *pClass = Iterator_GetNext(); 1437 1512 1438 char temporary[VN_SIZE];1439 1513 sprintf( temporary 1440 1514 , "Add(%c%c_System_TypeForClass(\"%s\",\"%s\"))" … … 1451 1525 ReallocNativeCodeBuffer(); 1452 1526 } 1527 1528 1529 //////////////////////////////////////////////////////////////////// 1530 // 基底クラスを登録 1531 //////////////////////////////////////////////////////////////////// 1532 1533 sprintf(temporary, "%c%ctempType=Nothing%c%cTypeBaseImpl" 1534 , HIBYTE( COM_DIM ) 1535 , LOBYTE( COM_DIM ) 1536 , 1 1537 , ESC_AS 1538 ); 1539 ChangeOpcode( temporary ); 1540 1541 // イテレータをリセット 1542 Iterator_Reset(); 1543 1544 while( Iterator_HasNext() ){ 1545 CClass *pClass = Iterator_GetNext(); 1546 1547 if( pClass->pobj_InheritsClass ){ 1548 sprintf( temporary 1549 , "tempType=Search(\"%s\",\"%s\")" 1550 , "" // 名前空間 (TODO: 実装) 1551 , pClass->name // クラス名 1552 ); 1553 1554 // コンパイル 1555 ChangeOpcode( temporary ); 1556 1557 sprintf( temporary 1558 , "tempType.SetBaseType(Search(\"%s\",\"%s\"))" 1559 , "" // 名前空間 (TODO: 実装) 1560 , pClass->pobj_InheritsClass->name // 基底クラス名 1561 ); 1562 1563 // コンパイル 1564 ChangeOpcode( temporary ); 1565 } 1566 1567 // ネイティブコードバッファの再確保 1568 ReallocNativeCodeBuffer(); 1569 } 1570 1453 1571 1454 1572
Note:
See TracChangeset
for help on using the changeset viewer.