Changeset 90 in dev for BasicCompiler_Common
- Timestamp:
- Apr 7, 2007, 3:02:29 PM (18 years ago)
- Location:
- BasicCompiler_Common
- Files:
-
- 6 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 -
BasicCompiler_Common/Class.h
r89 r90 71 71 enum ClassType{ 72 72 Class, 73 Interface, 74 Enum, 75 Delegate, 73 76 Structure, 74 Interface,75 77 }; 76 78 … … 99 101 ~CClass(); 100 102 103 bool IsClass() const; 104 bool IsInterface() const; 105 bool IsEnum() const; 106 bool IsDelegate() const; 101 107 bool IsStructure() const; 102 108 103 109 //継承させる 104 void Inherits( CClass *pInheritsClass ); 110 bool Inherits( CClass &inheritsClass, int nowLine ); 111 bool InheritsInterface( CClass &inheritsClass, int nowLine ); 105 112 106 113 //メンバ、メソッドの追加 -
BasicCompiler_Common/LoopRefCheck.cpp
r4 r90 45 45 } 46 46 } 47 BOOL CLoopRefCheck::check(char *lpszInheritsClass){ 47 BOOL CLoopRefCheck::check(const CClass &inheritsClass) const 48 { 48 49 //ループ継承チェック 49 50 int i; 50 51 for(i=0;i<num;i++){ 51 if(lstrcmp(names[i], lpszInheritsClass)==0) return 1;52 if(lstrcmp(names[i],inheritsClass.name)==0) return 1; 52 53 } 53 54 return 0; -
BasicCompiler_Common/ParamImpl.cpp
r84 r90 10 10 #define OVERLOAD_MAX_LEVEL 4 11 11 #define OVERLOAD_LEVEL0 0 // 型調整なし。厳密に等しい 12 #define OVERLOAD_LEVEL1 1 // 型調整なし。整数型/実数型レベルでの同一性チェック 13 #define OVERLOAD_LEVEL2 2 // 型調整あり。厳密に等しい 14 #define OVERLOAD_LEVEL3 3 // 型調整あり。整数型/実数型レベルでの同一性チェック 15 #define OVERLOAD_LEVEL4 4 // 型調整あり。数値型/クラス型レベルでの同一性チェック 12 #define OVERLOAD_LEVEL1 1 // 型調整なし。レベル1以上はオブジェクトの場合は派生関係を考慮 13 #define OVERLOAD_LEVEL2 2 // 型調整なし。整数型/実数型レベルでの同一性チェック 14 #define OVERLOAD_LEVEL3 3 // 型調整あり。厳密に等しい 15 #define OVERLOAD_LEVEL4 4 // 型調整あり。整数型/実数型レベルでの同一性チェック 16 #define OVERLOAD_LEVEL5 5 // 型調整あり。数値型/クラス型レベルでの同一性チェック 16 17 17 18 ParamImpl::ParamImpl(const char *buffer): … … 127 128 128 129 NumOpe_GetType(Parms[i], 129 ( level==OVERLOAD_LEVEL0 || level == OVERLOAD_LEVEL1)? nullParam : param,130 ( level <= OVERLOAD_LEVEL2 )? nullParam : param, 130 131 argType); 131 132 } … … 135 136 136 137 if(argType.GetBasicType()!=param.GetBasicType()){ 137 if( level == OVERLOAD_LEVEL0 || level ==OVERLOAD_LEVEL2){138 if( level == OVERLOAD_LEVEL0 || level == OVERLOAD_LEVEL1 || level==OVERLOAD_LEVEL3 ){ 138 139 return false; 139 140 } 140 else if( level == OVERLOAD_LEVEL 1 || level==OVERLOAD_LEVEL3){141 else if( level == OVERLOAD_LEVEL2 || level==OVERLOAD_LEVEL4){ 141 142 if(!( 142 143 argType.IsWhole()&¶m.IsWhole()|| … … 146 147 } 147 148 } 148 else if(level==OVERLOAD_LEVEL 4){149 else if(level==OVERLOAD_LEVEL5){ 149 150 if(argType.IsObject()||param.IsObject()) return false; 150 151 } … … 158 159 } 159 160 else if( NATURAL_TYPE(argType.GetBasicType())==DEF_OBJECT ){ 160 if( !param.GetClass().IsEqualsOrSubClass( &argType.GetClass() ) ){ 161 return false; 161 if( level == OVERLOAD_LEVEL0 ){ 162 if( !param.GetClass().IsEquals( &argType.GetClass() ) ){ 163 return false; 164 } 165 } 166 else{ 167 if( !param.GetClass().IsEqualsOrSubClass( &argType.GetClass() ) ){ 168 return false; 169 } 162 170 } 163 171 } … … 191 199 192 200 pUserProc = pTempUserProc; 193 break;194 201 } 195 202 } -
BasicCompiler_Common/Procedure.h
r89 r90 101 101 bool isExport; 102 102 bool isSystem; 103 bool isAutoGeneration; 103 104 bool isCompiled; 104 105 … … 114 115 isExport( isExport ), 115 116 isSystem( false ), 117 isAutoGeneration( false ), 116 118 isCompiled( false ), 117 119 pNextData( NULL ) … … 176 178 { 177 179 return isSystem; 180 } 181 void ThisIsAutoGenerationProc(){ 182 isAutoGeneration = true; 183 } 184 bool IsAutoGeneration(){ 185 return isAutoGeneration; 178 186 } 179 187 void CompleteCompile(){ -
BasicCompiler_Common/common.h
r89 r90 47 47 48 48 #ifdef _AMD64_ 49 #define VER_INFO "(x64) β rev. 194"49 #define VER_INFO "(x64) β rev.206" 50 50 #else 51 #define VER_INFO "β rev. 194"51 #define VER_INFO "β rev.206" 52 52 #endif 53 53 … … 460 460 void add(char *lpszInheritsClass); 461 461 void del(char *lpszInheritsClass); 462 BOOL check(c har *lpszInheritsClass);462 BOOL check(const CClass &inheritsClass) const; 463 463 }; 464 464 extern CLoopRefCheck *pobj_LoopRefCheck;
Note:
See TracChangeset
for help on using the changeset viewer.