[4] | 1 | #include "common.h"
|
---|
| 2 |
|
---|
| 3 | #ifdef _AMD64_
|
---|
| 4 | #include "../BasicCompiler64/opcode.h"
|
---|
| 5 | #else
|
---|
[5] | 6 | #include "../BasicCompiler32/opcode.h"
|
---|
[4] | 7 | #endif
|
---|
| 8 |
|
---|
[159] | 9 | Classes *pobj_DBClass;
|
---|
[4] | 10 |
|
---|
[114] | 11 | const CClass *pobj_CompilingClass;
|
---|
[4] | 12 |
|
---|
[18] | 13 | CMember *pCompilingMethod;
|
---|
| 14 |
|
---|
[4] | 15 |
|
---|
[131] | 16 | CClass::CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name )
|
---|
[140] | 17 | : isReady( false )
|
---|
| 18 | , Prototype( namespaceScopes, name )
|
---|
[108] | 19 | , importedNamespaces( importedNamespaces )
|
---|
| 20 | , ConstructorMemberSubIndex( 0 )
|
---|
| 21 | , DestructorMemberSubIndex( 0 )
|
---|
| 22 | , classType( Class )
|
---|
| 23 | , pobj_InheritsClass( NULL )
|
---|
[141] | 24 | , vtblNum( 0 )
|
---|
[108] | 25 | , iAlign( 0 )
|
---|
| 26 | , vtbl_offset( -1 )
|
---|
| 27 | , isCompilingConstructor( false )
|
---|
| 28 | , isCompilingDestructor( false )
|
---|
| 29 | , pobj_NextClass( NULL )
|
---|
[90] | 30 | {
|
---|
[4] | 31 | }
|
---|
| 32 | CClass::~CClass(){
|
---|
[140] | 33 | // 動的メンバ
|
---|
| 34 | foreach( CMember *member, dynamicMembers ){
|
---|
| 35 | delete member;
|
---|
[4] | 36 | }
|
---|
| 37 |
|
---|
[140] | 38 | // 静的メンバ
|
---|
[53] | 39 | foreach( CMember *member, staticMembers ){
|
---|
| 40 | delete member;
|
---|
[4] | 41 | }
|
---|
| 42 | }
|
---|
[64] | 43 |
|
---|
[131] | 44 | bool CClass::IsInheritsInterface( const CClass *pInterfaceClass ) const
|
---|
| 45 | {
|
---|
| 46 | BOOST_FOREACH( const InheritedInterface &objInterface, interfaces ){
|
---|
| 47 | if( pInterfaceClass == &objInterface.GetInterfaceClass() ){
|
---|
| 48 | return true;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | return false;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[90] | 54 | bool CClass::IsClass() const
|
---|
| 55 | {
|
---|
| 56 | return classType == CClass::Class;
|
---|
| 57 | }
|
---|
| 58 | bool CClass::IsInterface() const
|
---|
| 59 | {
|
---|
| 60 | return classType == CClass::Interface;
|
---|
| 61 | }
|
---|
| 62 | bool CClass::IsEnum() const
|
---|
| 63 | {
|
---|
| 64 | return classType == CClass::Enum;
|
---|
| 65 | }
|
---|
| 66 | bool CClass::IsDelegate() const
|
---|
| 67 | {
|
---|
| 68 | return classType == CClass::Delegate;
|
---|
| 69 | }
|
---|
[64] | 70 | bool CClass::IsStructure() const
|
---|
| 71 | {
|
---|
| 72 | return classType == CClass::Structure;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[131] | 75 | bool CClass::Inherits( const char *inheritNames, int nowLine ){
|
---|
| 76 | int i = 0;
|
---|
| 77 | bool isInheritsClass = false;
|
---|
| 78 | while( true ){
|
---|
[29] | 79 |
|
---|
[131] | 80 | char temporary[VN_SIZE];
|
---|
| 81 | for( int i2=0;; i++, i2++ ){
|
---|
| 82 | if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
|
---|
| 83 | temporary[i2] = 0;
|
---|
| 84 | break;
|
---|
| 85 | }
|
---|
| 86 | temporary[i2] = inheritNames[i];
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | //継承元クラスを取得
|
---|
| 90 | const CClass *pInheritsClass = pobj_DBClass->Find(temporary);
|
---|
| 91 | if( !pInheritsClass ){
|
---|
[141] | 92 | SetError(106,temporary,nowLine);
|
---|
[131] | 93 | return false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | if( pInheritsClass->IsInterface() ){
|
---|
[141] | 97 | // インターフェイスはあとで継承する
|
---|
[131] | 98 | }
|
---|
| 99 | else if( pInheritsClass->IsClass() ){
|
---|
| 100 | // クラスを継承する
|
---|
| 101 | isInheritsClass = true;
|
---|
| 102 |
|
---|
| 103 | if( !InheritsClass( *pInheritsClass, nowLine ) ){
|
---|
| 104 | return false;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | else{
|
---|
| 108 | SetError(135,NULL,nowLine);
|
---|
| 109 | return false;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | if( inheritNames[i] == '\0' ){
|
---|
| 113 | break;
|
---|
| 114 | }
|
---|
| 115 | i++;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | if( !isInheritsClass ){
|
---|
| 119 | // クラスを一つも継承していないとき
|
---|
| 120 | const CClass *pObjectClass = pobj_DBClass->Find("Object");
|
---|
| 121 | if( !pObjectClass ){
|
---|
| 122 | SetError(106,"Object",i);
|
---|
| 123 | return false;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[141] | 126 | if( !InheritsClass( *pObjectClass, nowLine ) ){
|
---|
[131] | 127 | return false;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[141] | 131 | i=0;
|
---|
| 132 | while( true ){
|
---|
| 133 |
|
---|
| 134 | char temporary[VN_SIZE];
|
---|
| 135 | for( int i2=0;; i++, i2++ ){
|
---|
| 136 | if( inheritNames[i] == '\0' || inheritNames[i] == ',' ){
|
---|
| 137 | temporary[i2] = 0;
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 | temporary[i2] = inheritNames[i];
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | //継承元クラスを取得
|
---|
| 144 | const CClass *pInheritsClass = pobj_DBClass->Find(temporary);
|
---|
| 145 | if( !pInheritsClass ){
|
---|
| 146 | SetError(106,temporary,nowLine);
|
---|
| 147 | return false;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | if( pInheritsClass->IsInterface() ){
|
---|
| 151 | // インターフェイスを継承する
|
---|
| 152 | if( !InheritsInterface( *pInheritsClass, nowLine ) ){
|
---|
| 153 | return false;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | else if( pInheritsClass->IsClass() ){
|
---|
| 157 | // クラスはさっき継承した
|
---|
| 158 | }
|
---|
| 159 | else{
|
---|
| 160 | SetError(135,NULL,nowLine);
|
---|
| 161 | return false;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | if( inheritNames[i] == '\0' ){
|
---|
| 165 | break;
|
---|
| 166 | }
|
---|
| 167 | i++;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[131] | 170 | return true;
|
---|
| 171 | }
|
---|
| 172 | bool CClass::InheritsClass( const CClass &inheritsClass, int nowLine ){
|
---|
| 173 |
|
---|
[90] | 174 | //ループ継承でないかをチェック
|
---|
| 175 | if(pobj_LoopRefCheck->check(inheritsClass)){
|
---|
[131] | 176 | SetError(123,inheritsClass.GetName(),nowLine);
|
---|
[90] | 177 | return false;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[140] | 180 | if( !inheritsClass.IsReady() ){
|
---|
[90] | 181 | //継承先が読み取られていないとき
|
---|
[131] | 182 | pobj_LoopRefCheck->add(this->GetName().c_str());
|
---|
| 183 | pobj_DBClass->GetClass_recur(inheritsClass.GetName().c_str());
|
---|
| 184 | pobj_LoopRefCheck->del(this->GetName().c_str());
|
---|
[90] | 185 | }
|
---|
| 186 |
|
---|
[29] | 187 | //メンバをコピー
|
---|
[140] | 188 | BOOST_FOREACH( CMember *inheritsClassDynamicMember, inheritsClass.dynamicMembers ){
|
---|
| 189 | CMember *pMember = new CMember( *inheritsClassDynamicMember );
|
---|
[29] | 190 |
|
---|
[137] | 191 | // アクセシビリティ
|
---|
[140] | 192 | if( inheritsClassDynamicMember->IsPrivate() ){
|
---|
| 193 | pMember->SetAccessibility( Prototype::None );
|
---|
[137] | 194 | }
|
---|
| 195 | else{
|
---|
[140] | 196 | pMember->SetAccessibility( inheritsClassDynamicMember->GetAccessibility() );
|
---|
[137] | 197 | }
|
---|
[90] | 198 |
|
---|
[140] | 199 | dynamicMembers.push_back( pMember );
|
---|
[29] | 200 | }
|
---|
| 201 |
|
---|
| 202 | //メソッドをコピー
|
---|
[135] | 203 | foreach( const CMethod *pBaseMethod, inheritsClass.methods ){
|
---|
| 204 | CMethod *pMethod = new DynamicMethod( *pBaseMethod );
|
---|
[29] | 205 |
|
---|
[137] | 206 | // アクセシビリティ
|
---|
| 207 | if(pBaseMethod->GetAccessibility() == Prototype::Private){
|
---|
| 208 | pMethod->SetAccessibility( Prototype::None );
|
---|
| 209 | }
|
---|
| 210 | else{
|
---|
| 211 | pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
|
---|
| 212 | }
|
---|
[29] | 213 |
|
---|
| 214 | //pobj_Inherits
|
---|
| 215 | // ※継承元のClassIndexをセット(入れ子継承を考慮する)
|
---|
[135] | 216 | if(pBaseMethod->GetInheritsClassPtr()==0){
|
---|
| 217 | pMethod->SetInheritsClassPtr( &inheritsClass );
|
---|
| 218 | }
|
---|
| 219 | else{
|
---|
| 220 | pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
|
---|
| 221 | }
|
---|
[51] | 222 |
|
---|
[135] | 223 | methods.push_back( pMethod );
|
---|
[29] | 224 | }
|
---|
| 225 |
|
---|
| 226 | //仮想関数の数
|
---|
[141] | 227 | AddVtblNum( inheritsClass.GetVtblNum() );
|
---|
[29] | 228 |
|
---|
| 229 | //継承先のクラスをメンバとして保持する
|
---|
[90] | 230 | pobj_InheritsClass = &inheritsClass;
|
---|
| 231 |
|
---|
| 232 | return true;
|
---|
[29] | 233 | }
|
---|
[114] | 234 | bool CClass::InheritsInterface( const CClass &inheritsInterface, int nowLine ){
|
---|
[90] | 235 |
|
---|
| 236 | //ループ継承でないかをチェック
|
---|
| 237 | if(pobj_LoopRefCheck->check(inheritsInterface)){
|
---|
[131] | 238 | SetError(123,inheritsInterface.GetName(),nowLine);
|
---|
[90] | 239 | return false;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[140] | 242 | if( !inheritsInterface.IsReady() ){
|
---|
[90] | 243 | //継承先が読み取られていないとき
|
---|
[131] | 244 | pobj_LoopRefCheck->add(this->GetName().c_str());
|
---|
| 245 | pobj_DBClass->GetClass_recur(inheritsInterface.GetName().c_str());
|
---|
| 246 | pobj_LoopRefCheck->del(this->GetName().c_str());
|
---|
[90] | 247 | }
|
---|
| 248 |
|
---|
| 249 | //メソッドをコピー
|
---|
[135] | 250 | foreach( const CMethod *pBaseMethod, inheritsInterface.methods ){
|
---|
| 251 | CMethod *pMethod = new DynamicMethod( *pBaseMethod );
|
---|
[90] | 252 |
|
---|
[137] | 253 | // アクセシビリティ
|
---|
| 254 | if(pBaseMethod->GetAccessibility() == Prototype::Private){
|
---|
| 255 | pMethod->SetAccessibility( Prototype::None );
|
---|
| 256 | }
|
---|
| 257 | else{
|
---|
| 258 | pMethod->SetAccessibility( pBaseMethod->GetAccessibility() );
|
---|
| 259 | }
|
---|
[90] | 260 |
|
---|
| 261 | //pobj_Inherits
|
---|
| 262 | // ※継承元のClassIndexをセット(入れ子継承を考慮する)
|
---|
[135] | 263 | if(pBaseMethod->GetInheritsClassPtr()==0){
|
---|
| 264 | pMethod->SetInheritsClassPtr( &inheritsInterface );
|
---|
| 265 | }
|
---|
| 266 | else{
|
---|
| 267 | pMethod->SetInheritsClassPtr( pBaseMethod->GetInheritsClassPtr() );
|
---|
| 268 | }
|
---|
[90] | 269 |
|
---|
[135] | 270 | methods.push_back( pMethod );
|
---|
[90] | 271 | }
|
---|
| 272 |
|
---|
[141] | 273 | interfaces.push_back( InheritedInterface( const_cast<CClass *>(&inheritsInterface), vtblNum ) );
|
---|
[131] | 274 |
|
---|
[90] | 275 | //仮想関数の数
|
---|
[141] | 276 | AddVtblNum( inheritsInterface.GetVtblNum() );
|
---|
[90] | 277 |
|
---|
| 278 | return true;
|
---|
| 279 | }
|
---|
[137] | 280 | void CClass::AddMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer ){
|
---|
[140] | 281 | CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer );
|
---|
| 282 | dynamicMembers.push_back( pMember );
|
---|
[4] | 283 | }
|
---|
[137] | 284 | void CClass::AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine ){
|
---|
[140] | 285 | CMember *pMember = new CMember( this, accessibility, isConst, isRef, buffer, nowLine );
|
---|
| 286 | staticMembers.push_back( pMember );
|
---|
[4] | 287 | }
|
---|
[46] | 288 | BOOL CClass::DupliCheckAll(const char *name){
|
---|
[4] | 289 | //重複チェック
|
---|
| 290 |
|
---|
| 291 | //メンバ
|
---|
| 292 | if(DupliCheckMember(name)) return 1;
|
---|
| 293 |
|
---|
| 294 | //メソッド
|
---|
[135] | 295 | foreach( const CMethod *pMethod, methods ){
|
---|
| 296 | if( lstrcmp( name, pMethod->pUserProc->GetName().c_str() ) == 0 ){
|
---|
[4] | 297 | return 1;
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | return 0;
|
---|
| 302 | }
|
---|
[46] | 303 | BOOL CClass::DupliCheckMember(const char *name){
|
---|
[4] | 304 | //重複チェック
|
---|
| 305 |
|
---|
[140] | 306 | // 動的メンバ
|
---|
| 307 | BOOST_FOREACH( CMember *pMember, dynamicMembers ){
|
---|
| 308 | if( GetName() == pMember->GetName() ){
|
---|
[4] | 309 | return 1;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[140] | 313 | // 静的メンバ
|
---|
| 314 | foreach( CMember *pMember, staticMembers ){
|
---|
| 315 | if( GetName() == pMember->GetName() ){
|
---|
[4] | 316 | return 1;
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | return 0;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[51] | 323 | //デフォルト コンストラクタ メソッドを取得
|
---|
[135] | 324 | const CMethod *CClass::GetConstructorMethod() const
|
---|
[51] | 325 | {
|
---|
| 326 | if( ConstructorMemberSubIndex == -1 ) return NULL;
|
---|
| 327 | return methods[ConstructorMemberSubIndex];
|
---|
| 328 | }
|
---|
[50] | 329 |
|
---|
[51] | 330 | //デストラクタ メソッドを取得
|
---|
[135] | 331 | const CMethod *CClass::GetDestructorMethod() const
|
---|
[51] | 332 | {
|
---|
| 333 | if( DestructorMemberSubIndex == -1 ) return NULL;
|
---|
| 334 | return methods[DestructorMemberSubIndex];
|
---|
| 335 | }
|
---|
| 336 |
|
---|
[63] | 337 | //サイズを取得
|
---|
| 338 | int CClass::GetSize() const
|
---|
| 339 | {
|
---|
| 340 | return GetMemberOffset( NULL, NULL );
|
---|
| 341 | }
|
---|
[51] | 342 |
|
---|
[63] | 343 | //メンバのオフセットを取得
|
---|
| 344 | int CClass::GetMemberOffset( const char *memberName, int *pMemberNum ) const
|
---|
| 345 | {
|
---|
[141] | 346 | int i2;
|
---|
[63] | 347 |
|
---|
| 348 | //仮想関数が存在する場合は関数リストへのポインタのサイズを追加
|
---|
[141] | 349 | int offset = IsExistVirtualFunctions() ? PTR_SIZE : 0;
|
---|
[63] | 350 |
|
---|
| 351 | int alignment;
|
---|
| 352 | if(iAlign) alignment=iAlign;
|
---|
| 353 | else alignment=1;
|
---|
| 354 |
|
---|
| 355 | int iMaxAlign=0;
|
---|
[140] | 356 | int i = -1;
|
---|
| 357 | BOOST_FOREACH( CMember *pMember, dynamicMembers ){
|
---|
| 358 | i++;
|
---|
[63] | 359 |
|
---|
[137] | 360 | i2 = pMember->GetType().GetSize();
|
---|
[63] | 361 |
|
---|
| 362 | //アラインメントを算出
|
---|
| 363 | int member_size;
|
---|
[137] | 364 | if( pMember->GetType().IsStruct() ){
|
---|
[63] | 365 | //メンバクラスのアラインメントを取得
|
---|
[137] | 366 | member_size=pMember->GetType().GetClass().GetAlignment();
|
---|
[63] | 367 | }
|
---|
| 368 | else{
|
---|
| 369 | //メンバサイズを取得
|
---|
| 370 | member_size=i2;
|
---|
| 371 | }
|
---|
| 372 | if(iMaxAlign<member_size) iMaxAlign=member_size;
|
---|
| 373 |
|
---|
| 374 | //アラインメントを考慮
|
---|
| 375 | if(iAlign&&iAlign<member_size){
|
---|
| 376 | if(offset%alignment) offset+=alignment-(offset%alignment);
|
---|
| 377 | }
|
---|
| 378 | else{
|
---|
| 379 | if(alignment<member_size) alignment=member_size;
|
---|
| 380 |
|
---|
| 381 | if(member_size==0){
|
---|
| 382 | //メンバを持たないクラス
|
---|
| 383 | //※何もしない(オフセットの計算をしない)
|
---|
| 384 | }
|
---|
| 385 | else{
|
---|
| 386 | if(offset%member_size) offset+=member_size-(offset%member_size);
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | if(memberName){
|
---|
| 391 | //メンバ指定がある場合は、オフセットを返す
|
---|
[135] | 392 | if( pMember->GetName() == memberName ){
|
---|
[63] | 393 | if(pMemberNum) *pMemberNum=i;
|
---|
| 394 | return offset;
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | //配列を考慮したメンバサイズを取得
|
---|
| 399 | member_size=i2 * JumpSubScripts(pMember->SubScripts);
|
---|
| 400 |
|
---|
| 401 | //メンバサイズを加算
|
---|
| 402 | offset+= member_size;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | if(iMaxAlign<alignment) alignment=iMaxAlign;
|
---|
| 406 |
|
---|
| 407 | //アラインメントを考慮
|
---|
| 408 | if(alignment){
|
---|
| 409 | if(offset%alignment) offset+=alignment-(offset%alignment);
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | if(pMemberNum) *pMemberNum=i;
|
---|
| 413 | return offset;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | int CClass::GetAlignment() const
|
---|
| 417 | {
|
---|
[141] | 418 | //仮想関数が存在する場合は関数リストへのポインタのサイズを追加
|
---|
| 419 | int alignment = IsExistVirtualFunctions() ? PTR_SIZE : 0;
|
---|
[63] | 420 |
|
---|
[140] | 421 | BOOST_FOREACH( CMember *pMember, dynamicMembers ){
|
---|
[141] | 422 | int member_size;
|
---|
[137] | 423 | if(pMember->GetType().IsStruct()){
|
---|
[63] | 424 | //メンバクラスのアラインメントを取得
|
---|
[137] | 425 | member_size=pMember->GetType().GetClass().GetAlignment();
|
---|
[63] | 426 | }
|
---|
| 427 | else{
|
---|
| 428 | //メンバサイズを取得
|
---|
[137] | 429 | member_size = pMember->GetType().GetSize();
|
---|
[63] | 430 | }
|
---|
| 431 |
|
---|
| 432 | //アラインメントをセット
|
---|
| 433 | if(alignment<member_size) alignment=member_size;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | if(alignment==0) return 0;
|
---|
| 437 |
|
---|
| 438 | if(iAlign) alignment=iAlign;
|
---|
| 439 |
|
---|
| 440 | return alignment;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 |
|
---|
| 444 |
|
---|
[75] | 445 | int CClass::GetFuncNumInVtbl( const UserProc *pUserProc ) const
|
---|
[51] | 446 | {
|
---|
| 447 | int n = 0;
|
---|
[135] | 448 | foreach( const CMethod *pMethod, methods ){
|
---|
| 449 | if( pMethod->pUserProc == pUserProc ) break;
|
---|
| 450 | if( pMethod->IsVirtual() ) n++;
|
---|
[51] | 451 | }
|
---|
| 452 | return n;
|
---|
| 453 | }
|
---|
[114] | 454 | LONG_PTR CClass::GetVtblGlobalOffset(void) const
|
---|
| 455 | {
|
---|
[28] | 456 |
|
---|
| 457 | //既に存在する場合はそれを返す
|
---|
[4] | 458 | if(vtbl_offset!=-1) return vtbl_offset;
|
---|
| 459 |
|
---|
[28] | 460 |
|
---|
[92] | 461 |
|
---|
[28] | 462 | //////////////////////////////////////
|
---|
| 463 | // 存在しないときは新たに生成する
|
---|
| 464 | //////////////////////////////////////
|
---|
| 465 |
|
---|
[75] | 466 | UserProc **ppsi;
|
---|
[141] | 467 | ppsi=(UserProc **)HeapAlloc(hHeap,0,GetVtblNum()*sizeof(GlobalProc *));
|
---|
[4] | 468 |
|
---|
| 469 | //関数テーブルに値をセット
|
---|
[51] | 470 | int i2 = 0;
|
---|
[135] | 471 | foreach( const CMethod *pMethod, methods ){
|
---|
| 472 | if(pMethod->IsVirtual()){
|
---|
| 473 | pMethod->pUserProc->Using();
|
---|
[4] | 474 |
|
---|
[135] | 475 | if(pMethod->IsAbstract()){
|
---|
[28] | 476 | extern int cp;
|
---|
| 477 | SetError(300,NULL,cp);
|
---|
[4] | 478 |
|
---|
[28] | 479 | ppsi[i2]=0;
|
---|
[4] | 480 | }
|
---|
[92] | 481 | else{
|
---|
[135] | 482 | ppsi[i2]=pMethod->pUserProc;
|
---|
[92] | 483 | }
|
---|
[28] | 484 | i2++;
|
---|
[4] | 485 | }
|
---|
| 486 | }
|
---|
| 487 |
|
---|
[141] | 488 | vtbl_offset=dataTable.AddBinary((void *)ppsi,GetVtblNum()*sizeof(LONG_PTR));
|
---|
[4] | 489 |
|
---|
[141] | 490 | for( int i=0; i < GetVtblNum(); i++ ){
|
---|
[4] | 491 | pobj_Reloc->AddSchedule_DataSection(vtbl_offset+i*sizeof(LONG_PTR));
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 | HeapDefaultFree(ppsi);
|
---|
| 495 |
|
---|
| 496 | return vtbl_offset;
|
---|
| 497 | }
|
---|
| 498 | void CClass::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
|
---|
| 499 | if(vtbl_offset==-1) return;
|
---|
| 500 |
|
---|
| 501 | LONG_PTR *pVtbl;
|
---|
[56] | 502 | pVtbl=(LONG_PTR *)((char *)dataTable.GetPtr()+vtbl_offset);
|
---|
[4] | 503 |
|
---|
| 504 | int i;
|
---|
[141] | 505 | for(i=0;i<GetVtblNum();i++){
|
---|
[100] | 506 | GlobalProc *pUserProc;
|
---|
| 507 | pUserProc=(GlobalProc *)pVtbl[i];
|
---|
[75] | 508 | if(!pUserProc) continue;
|
---|
| 509 | pVtbl[i]=pUserProc->beginOpAddress+ImageBase+MemPos_CodeSection;
|
---|
[4] | 510 | }
|
---|
| 511 | }
|
---|
[75] | 512 | bool CClass::IsAbstract() const
|
---|
| 513 | {
|
---|
[96] | 514 | // 未実装(abstract)の仮想関数を持つ場合はtrueを返す
|
---|
[4] | 515 |
|
---|
[135] | 516 | foreach( const CMethod *pMethod, methods ){
|
---|
| 517 | if(pMethod->IsVirtual()){
|
---|
| 518 | if(pMethod->IsAbstract()){
|
---|
[28] | 519 | return true;
|
---|
[4] | 520 | }
|
---|
| 521 | }
|
---|
| 522 | }
|
---|
| 523 |
|
---|
[28] | 524 | return false;
|
---|
[4] | 525 | }
|
---|
| 526 |
|
---|
[17] | 527 | // コンストラクタのコンパイルを開始
|
---|
[114] | 528 | void CClass::NotifyStartConstructorCompile() const
|
---|
| 529 | {
|
---|
[17] | 530 | isCompilingConstructor = true;
|
---|
| 531 | }
|
---|
[4] | 532 |
|
---|
[17] | 533 | //コンストラクタのコンパイルを終了
|
---|
[114] | 534 | void CClass::NotifyFinishConstructorCompile() const
|
---|
| 535 | {
|
---|
[17] | 536 | isCompilingConstructor = false;
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | //コンストラクタをコンパイル中かどうかを判別
|
---|
[75] | 540 | bool CClass::IsCompilingConstructor() const
|
---|
| 541 | {
|
---|
[17] | 542 | return isCompilingConstructor;
|
---|
| 543 | }
|
---|
| 544 |
|
---|
[18] | 545 | //デストラクタのコンパイルを開始
|
---|
[114] | 546 | void CClass::NotifyStartDestructorCompile() const{
|
---|
[18] | 547 | isCompilingDestructor = true;
|
---|
| 548 | }
|
---|
[17] | 549 |
|
---|
[18] | 550 | //デストラクタのコンパイルを終了
|
---|
[114] | 551 | void CClass::NotifyFinishDestructorCompile() const{
|
---|
[18] | 552 | isCompilingDestructor = false;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | //デストラクタをコンパイル中かどうかを判別
|
---|
[75] | 556 | bool CClass::IsCompilingDestructor() const
|
---|
| 557 | {
|
---|
[18] | 558 | return isCompilingDestructor;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[28] | 561 | //自身の派生クラスかどうかを確認
|
---|
[75] | 562 | bool CClass::IsSubClass( const CClass *pClass ) const
|
---|
| 563 | {
|
---|
[28] | 564 | pClass = pClass->pobj_InheritsClass;
|
---|
| 565 | while( pClass ){
|
---|
| 566 | if( this == pClass ) return true;
|
---|
| 567 | pClass = pClass->pobj_InheritsClass;
|
---|
| 568 | }
|
---|
| 569 | return false;
|
---|
| 570 | }
|
---|
| 571 |
|
---|
[59] | 572 | //自身と等しいまたは派生クラスかどうかを確認
|
---|
[75] | 573 | bool CClass::IsEqualsOrSubClass( const CClass *pClass ) const
|
---|
| 574 | {
|
---|
[59] | 575 | if( IsEquals( pClass ) ) return true;
|
---|
| 576 | return IsSubClass( pClass );
|
---|
| 577 | }
|
---|
[28] | 578 |
|
---|
[94] | 579 | // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
|
---|
| 580 | bool CClass::IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const
|
---|
| 581 | {
|
---|
| 582 | if( IsEquals( &objClass ) ) return true;
|
---|
| 583 | if( IsSubClass( &objClass ) ) return true;
|
---|
| 584 | if( objClass.IsSubClass( this ) ) return true;
|
---|
| 585 | return false;
|
---|
| 586 | }
|
---|
[28] | 587 |
|
---|
[59] | 588 |
|
---|
[94] | 589 |
|
---|
[159] | 590 | int Classes::hash(const char *name) const{
|
---|
[4] | 591 | int key;
|
---|
| 592 |
|
---|
| 593 | for(key=0;*name!='\0';name++){
|
---|
| 594 | key=((key<<8)+ *name )%MAX_CLASS_HASH;
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | return key;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[159] | 600 | void Classes::DestroyClass(CClass *pobj_c){
|
---|
[4] | 601 | if(pobj_c->pobj_NextClass){
|
---|
| 602 | DestroyClass(pobj_c->pobj_NextClass);
|
---|
| 603 | }
|
---|
| 604 |
|
---|
| 605 | delete pobj_c;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
[159] | 608 | Classes::Classes():
|
---|
[67] | 609 | pStringClass( NULL ),
|
---|
| 610 | pObjectClass( NULL ),
|
---|
| 611 | pCompilingClass( NULL ),
|
---|
| 612 | pCompilingMethod( NULL ),
|
---|
| 613 | ppobj_IteClass( NULL ),
|
---|
| 614 | iIteMaxNum( 0 ),
|
---|
| 615 | iIteNextNum( 0 )
|
---|
| 616 | {
|
---|
| 617 | memset( pobj_ClassHash, 0, MAX_CLASS_HASH * sizeof(CClass *) );
|
---|
[4] | 618 | }
|
---|
[159] | 619 | Classes::~Classes(){
|
---|
[4] | 620 | int i;
|
---|
| 621 | for(i=0;i<MAX_CLASS_HASH;i++){
|
---|
| 622 | if(pobj_ClassHash[i]) DestroyClass(pobj_ClassHash[i]);
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | if(ppobj_IteClass) HeapDefaultFree(ppobj_IteClass);
|
---|
| 626 | }
|
---|
| 627 |
|
---|
[159] | 628 | void Classes::ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection){
|
---|
[4] | 629 | int i;
|
---|
| 630 | for(i=0;i<MAX_CLASS_HASH;i++){
|
---|
| 631 | if(pobj_ClassHash[i]){
|
---|
| 632 | CClass *pobj_c;
|
---|
| 633 | pobj_c=pobj_ClassHash[i];
|
---|
| 634 | while(1){
|
---|
| 635 | pobj_c->ActionVtblSchedule(ImageBase,MemPos_CodeSection);
|
---|
| 636 |
|
---|
| 637 | if(pobj_c->pobj_NextClass==0) break;
|
---|
| 638 | pobj_c=pobj_c->pobj_NextClass;
|
---|
| 639 | }
|
---|
| 640 | }
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 |
|
---|
[159] | 644 | const CClass *Classes::Find( const NamespaceScopes &namespaceScopes, const string &name ) const
|
---|
[102] | 645 | {
|
---|
[4] | 646 | int key;
|
---|
[114] | 647 | key=hash(name.c_str());
|
---|
[4] | 648 |
|
---|
[117] | 649 | if( namespaceScopes.size() == 0 && name == "Object" ){
|
---|
| 650 | return GetObjectClassPtr();
|
---|
| 651 | }
|
---|
| 652 | else if( namespaceScopes.size() == 0 && name == "String" ){
|
---|
| 653 | return GetStringClassPtr();
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[4] | 656 | if(pobj_ClassHash[key]){
|
---|
| 657 | CClass *pobj_c;
|
---|
| 658 | pobj_c=pobj_ClassHash[key];
|
---|
| 659 | while(1){
|
---|
[114] | 660 | if( pobj_c->IsEqualSymbol( namespaceScopes, name ) ){
|
---|
[102] | 661 | //名前空間とクラス名が一致した
|
---|
[4] | 662 | return pobj_c;
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | if(pobj_c->pobj_NextClass==0) break;
|
---|
| 666 | pobj_c=pobj_c->pobj_NextClass;
|
---|
| 667 | }
|
---|
| 668 | }
|
---|
| 669 |
|
---|
[114] | 670 | // TypeDefも見る
|
---|
[159] | 671 | int index = Smoothie::meta.typeDefs.GetIndex( namespaceScopes, name );
|
---|
[114] | 672 | if( index != -1 ){
|
---|
[159] | 673 | Type type = Smoothie::meta.typeDefs[index].GetBaseType();
|
---|
[114] | 674 | if( type.IsObject() ){
|
---|
| 675 | return &type.GetClass();
|
---|
[102] | 676 | }
|
---|
| 677 | }
|
---|
[114] | 678 |
|
---|
[102] | 679 | return NULL;
|
---|
| 680 | }
|
---|
[159] | 681 | const CClass *Classes::Find( const string &fullName ) const
|
---|
[114] | 682 | {
|
---|
| 683 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
| 684 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
| 685 | bool isNest = SplitMemberName( fullName.c_str(), AreaName, NestName );
|
---|
[102] | 686 |
|
---|
[114] | 687 | return Find( NamespaceScopes( AreaName ), NestName );
|
---|
| 688 | }
|
---|
| 689 |
|
---|
[159] | 690 | CClass *Classes::AddClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine){
|
---|
[4] | 691 | //////////////////////////////////////////////////////////////////////////
|
---|
| 692 | // クラスを追加
|
---|
| 693 | // ※名前のみを登録。その他の情報はSetClassメソッドで!
|
---|
| 694 | //////////////////////////////////////////////////////////////////////////
|
---|
| 695 |
|
---|
| 696 | CClass *pobj_c;
|
---|
[108] | 697 | pobj_c=new CClass(namespaceScopes, importedNamespaces, name);
|
---|
[4] | 698 |
|
---|
| 699 | if(lstrcmp(name,"String")==0){
|
---|
| 700 | //Stringクラス
|
---|
[117] | 701 | pStringClass=pobj_c;
|
---|
[4] | 702 | }
|
---|
[67] | 703 | if( lstrcmp( name, "Object" ) == 0 ){
|
---|
| 704 | pObjectClass = pobj_c;
|
---|
| 705 | }
|
---|
[4] | 706 |
|
---|
| 707 |
|
---|
| 708 | /////////////////////////////////
|
---|
| 709 | // ハッシュデータに追加
|
---|
| 710 | /////////////////////////////////
|
---|
| 711 |
|
---|
| 712 | int key;
|
---|
| 713 | key=hash(name);
|
---|
| 714 |
|
---|
| 715 | if(pobj_ClassHash[key]){
|
---|
| 716 | CClass *pobj_c2;
|
---|
| 717 | pobj_c2=pobj_ClassHash[key];
|
---|
| 718 | while(1){
|
---|
[102] | 719 | if( pobj_c2->IsEqualSymbol( namespaceScopes, name ) ){
|
---|
| 720 | //名前空間及びクラス名が重複した場合
|
---|
[75] | 721 | SetError(15,name,nowLine);
|
---|
[4] | 722 | return 0;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | if(pobj_c2->pobj_NextClass==0) break;
|
---|
| 726 | pobj_c2=pobj_c2->pobj_NextClass;
|
---|
| 727 | }
|
---|
| 728 | pobj_c2->pobj_NextClass=pobj_c;
|
---|
| 729 | }
|
---|
| 730 | else{
|
---|
| 731 | pobj_ClassHash[key]=pobj_c;
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | return pobj_c;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[159] | 737 | void Classes::InitNames(void){
|
---|
[4] | 738 | extern char *basbuf;
|
---|
[101] | 739 | int i, i2;
|
---|
| 740 | char temporary[VN_SIZE];
|
---|
[4] | 741 |
|
---|
[128] | 742 | // Blittable型管理オブジェクトを初期化
|
---|
[159] | 743 | Smoothie::meta.blittableTypes.clear();
|
---|
[128] | 744 |
|
---|
[101] | 745 | // 名前空間管理
|
---|
| 746 | NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
|
---|
| 747 | namespaceScopes.clear();
|
---|
| 748 |
|
---|
[108] | 749 | // Importsされた名前空間の管理
|
---|
[143] | 750 | NamespaceScopesCollection &importedNamespaces = Smoothie::Temp::importedNamespaces;
|
---|
[108] | 751 | importedNamespaces.clear();
|
---|
| 752 |
|
---|
[4] | 753 | for(i=0;;i++){
|
---|
| 754 | if(basbuf[i]=='\0') break;
|
---|
| 755 |
|
---|
[101] | 756 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
|
---|
| 757 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 758 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 759 | temporary[i2]=0;
|
---|
| 760 | break;
|
---|
| 761 | }
|
---|
| 762 | temporary[i2]=basbuf[i];
|
---|
| 763 | }
|
---|
| 764 | namespaceScopes.push_back( temporary );
|
---|
| 765 |
|
---|
| 766 | continue;
|
---|
| 767 | }
|
---|
| 768 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 769 | if( namespaceScopes.size() <= 0 ){
|
---|
| 770 | SetError(12, "End Namespace", i );
|
---|
| 771 | }
|
---|
| 772 | else{
|
---|
| 773 | namespaceScopes.pop_back();
|
---|
| 774 | }
|
---|
| 775 |
|
---|
| 776 | i += 2;
|
---|
| 777 | continue;
|
---|
| 778 | }
|
---|
[108] | 779 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
|
---|
| 780 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 781 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 782 | temporary[i2]=0;
|
---|
| 783 | break;
|
---|
| 784 | }
|
---|
| 785 | temporary[i2]=basbuf[i];
|
---|
| 786 | }
|
---|
[169] | 787 | if( !importedNamespaces.Imports( temporary ) )
|
---|
| 788 | {
|
---|
| 789 | SetError(64,temporary,cp );
|
---|
| 790 | }
|
---|
[101] | 791 |
|
---|
[108] | 792 | continue;
|
---|
| 793 | }
|
---|
| 794 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 795 | importedNamespaces.clear();
|
---|
| 796 | continue;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
[4] | 799 | if(basbuf[i]==1&&(
|
---|
| 800 | basbuf[i+1]==ESC_CLASS||
|
---|
| 801 | basbuf[i+1]==ESC_TYPE||
|
---|
| 802 | basbuf[i+1]==ESC_INTERFACE
|
---|
| 803 | )){
|
---|
[75] | 804 | int nowLine;
|
---|
| 805 | nowLine=i;
|
---|
[4] | 806 |
|
---|
| 807 | i+=2;
|
---|
[128] | 808 | Type blittableType;
|
---|
[76] | 809 | if(memicmp(basbuf+i,"Align(",6)==0){
|
---|
[128] | 810 | //アラインメント修飾子
|
---|
[4] | 811 | i+=6;
|
---|
| 812 | i=JumpStringInPare(basbuf,i)+1;
|
---|
| 813 | }
|
---|
[128] | 814 | else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
|
---|
| 815 | // Blittable修飾子
|
---|
| 816 | i+=10;
|
---|
| 817 | i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
|
---|
| 818 | Type::StringToType( temporary, blittableType );
|
---|
| 819 | }
|
---|
[4] | 820 |
|
---|
[92] | 821 | bool isEnum = false;
|
---|
| 822 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM ){
|
---|
| 823 | // 列挙型の場合
|
---|
| 824 | isEnum = true;
|
---|
| 825 |
|
---|
| 826 | i+=2;
|
---|
| 827 | }
|
---|
| 828 |
|
---|
[4] | 829 | int i2;
|
---|
| 830 | char temporary[VN_SIZE];
|
---|
| 831 | for(i2=0;;i++,i2++){
|
---|
| 832 | if(!IsVariableChar(basbuf[i])){
|
---|
| 833 | temporary[i2]=0;
|
---|
| 834 | break;
|
---|
| 835 | }
|
---|
| 836 | temporary[i2]=basbuf[i];
|
---|
| 837 | }
|
---|
| 838 |
|
---|
| 839 | //クラスを追加
|
---|
[108] | 840 | CClass *pClass = pobj_DBClass->AddClass(namespaceScopes, importedNamespaces, temporary,nowLine);
|
---|
[64] | 841 | if( pClass ){
|
---|
[75] | 842 | if( basbuf[nowLine+1] == ESC_CLASS ){
|
---|
[92] | 843 | if( isEnum ){
|
---|
| 844 | pClass->classType = CClass::Enum;
|
---|
| 845 | }
|
---|
| 846 | else{
|
---|
| 847 | pClass->classType = CClass::Class;
|
---|
| 848 | }
|
---|
[64] | 849 | }
|
---|
[75] | 850 | else if( basbuf[nowLine+1] == ESC_INTERFACE ){
|
---|
[64] | 851 | pClass->classType = CClass::Interface;
|
---|
| 852 | }
|
---|
| 853 | else{
|
---|
| 854 | pClass->classType = CClass::Structure;
|
---|
| 855 | }
|
---|
| 856 | }
|
---|
[128] | 857 |
|
---|
| 858 | // Blittable型の場合
|
---|
| 859 | if( !blittableType.IsNull() ){
|
---|
| 860 | pClass->SetBlittableType( blittableType );
|
---|
| 861 |
|
---|
| 862 | // Blittable型として登録
|
---|
[159] | 863 | Smoothie::meta.blittableTypes.push_back( BlittableType( blittableType, pClass ) );
|
---|
[128] | 864 | }
|
---|
[4] | 865 | }
|
---|
| 866 | }
|
---|
| 867 | }
|
---|
| 868 |
|
---|
| 869 |
|
---|
[159] | 870 | void Classes::AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
|
---|
[135] | 871 | bool isVirtual, bool isOverride, char *buffer, int nowLine){
|
---|
[4] | 872 | int i,i2;
|
---|
| 873 | char temporary[VN_SIZE];
|
---|
| 874 |
|
---|
| 875 | i=2;
|
---|
| 876 | for(i2=0;;i++,i2++){
|
---|
| 877 | if(buffer[i]=='('||buffer[i]=='\0'){
|
---|
| 878 | temporary[i2]=0;
|
---|
| 879 | break;
|
---|
| 880 | }
|
---|
| 881 | temporary[i2]=buffer[i];
|
---|
| 882 | }
|
---|
| 883 |
|
---|
| 884 |
|
---|
| 885 | //関数ハッシュへ登録
|
---|
[100] | 886 | GlobalProc *pUserProc;
|
---|
[135] | 887 | pUserProc=AddSubData( NamespaceScopes(), NamespaceScopesCollection(), buffer,nowLine,isVirtual,pobj_c, (bStatic!=0) );
|
---|
[75] | 888 | if(!pUserProc) return;
|
---|
[4] | 889 |
|
---|
| 890 |
|
---|
| 891 | ////////////////////////////////////////////////////////////
|
---|
[18] | 892 | // コンストラクタ、デストラクタの場合の処理
|
---|
[4] | 893 | ////////////////////////////////////////////////////////////
|
---|
| 894 | BOOL fConstructor=0,bDestructor=0;
|
---|
| 895 |
|
---|
[131] | 896 | if(lstrcmp(temporary,pobj_c->GetName().c_str())==0){
|
---|
[18] | 897 | //コンストラクタの場合
|
---|
| 898 |
|
---|
| 899 | //標準コンストラクタ(引数なし)
|
---|
[75] | 900 | if(pUserProc->Params().size()==0) fConstructor=1;
|
---|
[18] | 901 |
|
---|
| 902 | //強制的にConst修飾子をつける
|
---|
| 903 | isConst = true;
|
---|
[4] | 904 | }
|
---|
| 905 | else if(temporary[0]=='~'){
|
---|
| 906 | //デストラクタの場合はその名前が正しいかチェックを行う
|
---|
[131] | 907 | if(lstrcmp(temporary+1,pobj_c->GetName().c_str())!=0)
|
---|
[75] | 908 | SetError(117,NULL,nowLine);
|
---|
[4] | 909 | else
|
---|
| 910 | bDestructor=1;
|
---|
| 911 | }
|
---|
| 912 | if(fConstructor||bDestructor){
|
---|
[18] | 913 | // コンストラクタ、デストラクタのアクセシビリティをチェック
|
---|
| 914 |
|
---|
| 915 | //強制的にConst修飾子をつける
|
---|
| 916 | isConst = true;
|
---|
[4] | 917 | }
|
---|
| 918 |
|
---|
[18] | 919 | if( fConstructor == 1 )
|
---|
[51] | 920 | pobj_c->ConstructorMemberSubIndex = (int)pobj_c->methods.size();
|
---|
[18] | 921 | else if( bDestructor )
|
---|
[51] | 922 | pobj_c->DestructorMemberSubIndex = (int)pobj_c->methods.size();
|
---|
[4] | 923 |
|
---|
| 924 |
|
---|
| 925 |
|
---|
| 926 | //////////////////
|
---|
| 927 | // 重複チェック
|
---|
| 928 | //////////////////
|
---|
| 929 |
|
---|
| 930 | if(pobj_c->DupliCheckMember(temporary)){
|
---|
[75] | 931 | SetError(15,temporary,nowLine);
|
---|
[4] | 932 | return;
|
---|
| 933 | }
|
---|
| 934 |
|
---|
[51] | 935 | //メソッド
|
---|
[135] | 936 | foreach( const CMethod *pMethod, pobj_c->methods ){
|
---|
[27] | 937 | //基底クラスと重複する場合はオーバーライドを行う
|
---|
[135] | 938 | if( pMethod->GetInheritsClassPtr() ) continue;
|
---|
[4] | 939 |
|
---|
[135] | 940 | if( pMethod->pUserProc->GetName() == temporary ){
|
---|
| 941 | if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){
|
---|
[4] | 942 | //関数名、パラメータ属性が合致したとき
|
---|
[75] | 943 | SetError(15,pUserProc->GetName().c_str(),nowLine);
|
---|
[4] | 944 | return;
|
---|
| 945 | }
|
---|
| 946 | }
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 | //仮想関数の場合
|
---|
[135] | 950 | if( isAbstract ) pUserProc->CompleteCompile();
|
---|
[4] | 951 |
|
---|
[51] | 952 | //メソッドのオーバーライド
|
---|
[135] | 953 | foreach( CMethod *pMethod, pobj_c->methods ){
|
---|
| 954 | if( pMethod->pUserProc->GetName() == temporary ){
|
---|
| 955 | if( pMethod->pUserProc->Params().Equals( pUserProc->Params() ) ){
|
---|
[4] | 956 |
|
---|
[135] | 957 | if(pMethod->IsVirtual()){
|
---|
[4] | 958 | //メンバ関数を上書き
|
---|
[135] | 959 | pMethod->pUserProc=pUserProc;
|
---|
| 960 | pMethod->Override();
|
---|
[4] | 961 |
|
---|
[135] | 962 | if( !isOverride ){
|
---|
[75] | 963 | SetError(127,NULL,nowLine);
|
---|
[4] | 964 | }
|
---|
[137] | 965 | if(pMethod->GetAccessibility() != accessibility ){
|
---|
[75] | 966 | SetError(128,NULL,nowLine);
|
---|
[4] | 967 | }
|
---|
[75] | 968 |
|
---|
[135] | 969 | pUserProc->SetMethod( pMethod );
|
---|
[4] | 970 | return;
|
---|
| 971 | }
|
---|
| 972 | }
|
---|
| 973 | }
|
---|
| 974 | }
|
---|
| 975 |
|
---|
[135] | 976 | if( isVirtual ){
|
---|
[141] | 977 | pobj_c->AddVtblNum( 1 );
|
---|
[4] | 978 | }
|
---|
| 979 |
|
---|
[135] | 980 | if( isOverride ){
|
---|
[75] | 981 | SetError(12,"Override",nowLine);
|
---|
[4] | 982 | }
|
---|
| 983 |
|
---|
| 984 | if(bStatic){
|
---|
[137] | 985 | pobj_c->staticMethods.AddStatic( pUserProc, accessibility );
|
---|
[4] | 986 | }
|
---|
| 987 | else{
|
---|
[137] | 988 | pobj_c->methods.Add(pUserProc, accessibility, isConst, isAbstract, isVirtual);
|
---|
[4] | 989 | }
|
---|
| 990 | }
|
---|
| 991 |
|
---|
[159] | 992 | BOOL Classes::MemberVar_LoopRefCheck(const CClass &objClass){
|
---|
[140] | 993 | int i2,bRet=1;
|
---|
| 994 | BOOST_FOREACH( CMember *pMember, objClass.dynamicMembers ){
|
---|
[137] | 995 | if(pMember->GetType().IsStruct()){
|
---|
[4] | 996 | //循環参照でないかをチェック
|
---|
[137] | 997 | if(pobj_LoopRefCheck->check(pMember->GetType().GetClass())){
|
---|
[4] | 998 | extern int cp;
|
---|
[137] | 999 | SetError(124,pMember->GetType().GetClass().GetName(),cp);
|
---|
[4] | 1000 | return 0;
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
[131] | 1003 | pobj_LoopRefCheck->add(objClass.GetName().c_str());
|
---|
[4] | 1004 |
|
---|
[137] | 1005 | i2=MemberVar_LoopRefCheck(pMember->GetType().GetClass());
|
---|
[4] | 1006 | if(bRet==1) bRet=i2;
|
---|
| 1007 |
|
---|
[131] | 1008 | pobj_LoopRefCheck->del(objClass.GetName().c_str());
|
---|
[4] | 1009 | }
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
| 1012 | return bRet;
|
---|
| 1013 | }
|
---|
| 1014 |
|
---|
[159] | 1015 | void Classes::GetClass_recur(const char *lpszInheritsClass){
|
---|
[4] | 1016 | extern char *basbuf;
|
---|
| 1017 | int i,i2,i3,sub_address,top_pos;
|
---|
| 1018 | char temporary[8192];
|
---|
| 1019 |
|
---|
[102] | 1020 | // 名前空間管理
|
---|
[139] | 1021 | NamespaceScopes backupNamespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
|
---|
[102] | 1022 | NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
|
---|
| 1023 | namespaceScopes.clear();
|
---|
| 1024 |
|
---|
[4] | 1025 | for(i=0;;i++){
|
---|
| 1026 | if(basbuf[i]=='\0') break;
|
---|
| 1027 |
|
---|
| 1028 |
|
---|
[102] | 1029 | // 名前空間
|
---|
| 1030 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
|
---|
| 1031 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 1032 | if( IsCommandDelimitation( basbuf[i] ) ){
|
---|
| 1033 | temporary[i2]=0;
|
---|
| 1034 | break;
|
---|
| 1035 | }
|
---|
| 1036 | temporary[i2]=basbuf[i];
|
---|
| 1037 | }
|
---|
| 1038 | namespaceScopes.push_back( temporary );
|
---|
| 1039 |
|
---|
| 1040 | continue;
|
---|
| 1041 | }
|
---|
| 1042 | else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 1043 | if( namespaceScopes.size() <= 0 ){
|
---|
| 1044 | SetError(12, "End Namespace", i );
|
---|
| 1045 | }
|
---|
| 1046 | else{
|
---|
| 1047 | namespaceScopes.pop_back();
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
| 1050 | i += 2;
|
---|
| 1051 | continue;
|
---|
| 1052 | }
|
---|
| 1053 |
|
---|
| 1054 |
|
---|
| 1055 |
|
---|
[4] | 1056 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INTERFACE){
|
---|
| 1057 | //////////////////////////
|
---|
| 1058 | // インターフェイス
|
---|
| 1059 | //////////////////////////
|
---|
| 1060 |
|
---|
| 1061 | top_pos=i;
|
---|
| 1062 |
|
---|
| 1063 | i+=2;
|
---|
| 1064 |
|
---|
| 1065 | //インターフェイス名を取得
|
---|
[17] | 1066 | GetIdentifierToken( temporary, basbuf, i );
|
---|
[4] | 1067 |
|
---|
[114] | 1068 | CClass *pobj_c = const_cast<CClass *>( pobj_DBClass->Find(namespaceScopes, temporary) );
|
---|
[4] | 1069 | if(!pobj_c) continue;
|
---|
| 1070 |
|
---|
| 1071 | if(lpszInheritsClass){
|
---|
[131] | 1072 | if(lstrcmp(lpszInheritsClass,pobj_c->GetName().c_str())!=0){
|
---|
[4] | 1073 | //継承先先読み用
|
---|
| 1074 | continue;
|
---|
| 1075 | }
|
---|
| 1076 | }
|
---|
| 1077 |
|
---|
[140] | 1078 | if(pobj_c->IsReady()){
|
---|
[4] | 1079 | //既に先読みされているとき
|
---|
| 1080 | continue;
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
[140] | 1083 | pobj_c->Readed();
|
---|
[4] | 1084 |
|
---|
| 1085 | pobj_c->ConstructorMemberSubIndex=-1;
|
---|
| 1086 | pobj_c->DestructorMemberSubIndex=-1;
|
---|
| 1087 |
|
---|
| 1088 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
|
---|
| 1089 | //継承を行う場合
|
---|
| 1090 | for(i+=3,i2=0;;i++,i2++){
|
---|
| 1091 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 1092 | temporary[i2]=0;
|
---|
| 1093 | break;
|
---|
| 1094 | }
|
---|
| 1095 | temporary[i2]=basbuf[i];
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
[131] | 1098 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
[4] | 1099 | SetError(105,temporary,i);
|
---|
| 1100 | goto Interface_InheritsError;
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | //継承元クラスを取得
|
---|
[114] | 1104 | const CClass *pInheritsClass = Find(temporary);
|
---|
[29] | 1105 | if( !pInheritsClass ){
|
---|
[4] | 1106 | SetError(106,temporary,i);
|
---|
| 1107 | goto Interface_InheritsError;
|
---|
| 1108 | }
|
---|
| 1109 |
|
---|
[90] | 1110 | //継承させる
|
---|
[131] | 1111 | if( !pobj_c->InheritsClass( *pInheritsClass, i ) ){
|
---|
[4] | 1112 | goto Interface_InheritsError;
|
---|
| 1113 | }
|
---|
| 1114 | }
|
---|
| 1115 | else{
|
---|
| 1116 | //継承無し
|
---|
| 1117 | pobj_c->pobj_InheritsClass=0;
|
---|
| 1118 |
|
---|
| 1119 | //仮想関数の数を初期化
|
---|
[141] | 1120 | pobj_c->SetVtblNum( 0 );
|
---|
[4] | 1121 | }
|
---|
| 1122 | Interface_InheritsError:
|
---|
| 1123 |
|
---|
| 1124 | //メンバ変数、関数を取得
|
---|
| 1125 | while(1){
|
---|
| 1126 | i++;
|
---|
| 1127 |
|
---|
| 1128 | //エラー
|
---|
| 1129 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE||basbuf[i+1]==ESC_INTERFACE)){
|
---|
| 1130 | SetError(22,"Interface",i);
|
---|
| 1131 | i--;
|
---|
| 1132 | break;
|
---|
| 1133 | }
|
---|
| 1134 |
|
---|
| 1135 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
| 1136 | SetError(111,NULL,i);
|
---|
| 1137 | break;
|
---|
| 1138 | }
|
---|
| 1139 |
|
---|
| 1140 | sub_address=i;
|
---|
| 1141 |
|
---|
| 1142 | for(i2=0;;i++,i2++){
|
---|
| 1143 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 1144 | temporary[i2]=0;
|
---|
| 1145 | break;
|
---|
| 1146 | }
|
---|
| 1147 | temporary[i2]=basbuf[i];
|
---|
| 1148 | }
|
---|
| 1149 | if(temporary[0]=='\0'){
|
---|
| 1150 | if(basbuf[i]=='\0'){
|
---|
| 1151 | i--;
|
---|
| 1152 | SetError(22,"Interface",top_pos);
|
---|
| 1153 | break;
|
---|
| 1154 | }
|
---|
| 1155 | continue;
|
---|
| 1156 | }
|
---|
| 1157 |
|
---|
| 1158 | //End Interface記述の場合
|
---|
| 1159 | if(temporary[0]==1&&temporary[1]==ESC_ENDINTERFACE) break;
|
---|
| 1160 |
|
---|
| 1161 | if(!(temporary[0]==1&&(
|
---|
| 1162 | temporary[1]==ESC_SUB||temporary[1]==ESC_FUNCTION
|
---|
| 1163 | ))){
|
---|
| 1164 | SetError(1,NULL,i);
|
---|
| 1165 | break;
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | //メンバ関数を追加
|
---|
[18] | 1169 | AddMethod(pobj_c,
|
---|
[137] | 1170 | Prototype::Public, //Publicアクセス権
|
---|
[18] | 1171 | 0, //Static指定なし
|
---|
| 1172 | false, //Constではない
|
---|
| 1173 | 1, //Abstract
|
---|
| 1174 | 1, //Virtual
|
---|
| 1175 | 0,
|
---|
| 1176 | temporary,
|
---|
| 1177 | sub_address
|
---|
| 1178 | );
|
---|
[4] | 1179 | }
|
---|
| 1180 | }
|
---|
| 1181 |
|
---|
| 1182 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
| 1183 | //////////////////////////
|
---|
| 1184 | // クラス
|
---|
| 1185 | //////////////////////////
|
---|
| 1186 |
|
---|
| 1187 | top_pos=i;
|
---|
| 1188 |
|
---|
[64] | 1189 | const DWORD dwClassType=basbuf[i+1];
|
---|
[4] | 1190 |
|
---|
| 1191 | i+=2;
|
---|
| 1192 |
|
---|
| 1193 | int iAlign=0;
|
---|
[76] | 1194 | if(memicmp(basbuf+i,"Align(",6)==0){
|
---|
[128] | 1195 | //アラインメント修飾子
|
---|
[4] | 1196 | i+=6;
|
---|
| 1197 | i+=GetStringInPare_RemovePare(temporary,basbuf+i)+1;
|
---|
| 1198 | iAlign=atoi(temporary);
|
---|
| 1199 |
|
---|
| 1200 | if(!(iAlign==1||iAlign==2||iAlign==4||iAlign==8||iAlign==16))
|
---|
| 1201 | SetError(51,NULL,i);
|
---|
| 1202 | }
|
---|
[128] | 1203 | else if( memicmp( basbuf + i, "Blittable(", 10 ) == 0 ){
|
---|
| 1204 | // Blittable修飾子
|
---|
| 1205 | i+=10;
|
---|
| 1206 | i=JumpStringInPare(basbuf,i)+1;
|
---|
| 1207 | }
|
---|
[4] | 1208 |
|
---|
[92] | 1209 | if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENUM ){
|
---|
| 1210 | // 列挙型の場合
|
---|
| 1211 | i+=2;
|
---|
| 1212 | }
|
---|
[4] | 1213 |
|
---|
| 1214 | //クラス名を取得
|
---|
[17] | 1215 | GetIdentifierToken( temporary, basbuf, i );
|
---|
[4] | 1216 |
|
---|
[114] | 1217 | CClass *pobj_c = const_cast<CClass *>( pobj_DBClass->Find(namespaceScopes, temporary) );
|
---|
[4] | 1218 | if(!pobj_c) continue;
|
---|
| 1219 |
|
---|
| 1220 | if(lpszInheritsClass){
|
---|
[131] | 1221 | if( pobj_c->GetName() != lpszInheritsClass ){
|
---|
[4] | 1222 | //継承先先読み用
|
---|
| 1223 | continue;
|
---|
| 1224 | }
|
---|
| 1225 | }
|
---|
| 1226 |
|
---|
[140] | 1227 | if(pobj_c->IsReady()){
|
---|
[4] | 1228 | //既に先読みされているとき
|
---|
| 1229 | continue;
|
---|
| 1230 | }
|
---|
| 1231 |
|
---|
| 1232 | pobj_c->iAlign=iAlign;
|
---|
| 1233 |
|
---|
[140] | 1234 | pobj_c->Readed();
|
---|
[4] | 1235 |
|
---|
| 1236 | pobj_c->ConstructorMemberSubIndex=-1;
|
---|
| 1237 | pobj_c->DestructorMemberSubIndex=-1;
|
---|
| 1238 |
|
---|
| 1239 | //アクセス制限の初期値をセット
|
---|
[137] | 1240 | Prototype::Accessibility accessibility;
|
---|
| 1241 | if(dwClassType==ESC_CLASS){
|
---|
| 1242 | accessibility = Prototype::Private;
|
---|
| 1243 | }
|
---|
| 1244 | else{
|
---|
| 1245 | accessibility = Prototype::Public;
|
---|
| 1246 | }
|
---|
[4] | 1247 |
|
---|
[131] | 1248 | if( pobj_c->GetName() == "Object" || dwClassType == ESC_TYPE ){
|
---|
| 1249 | // 継承無し
|
---|
| 1250 | pobj_c->pobj_InheritsClass = NULL;
|
---|
[29] | 1251 |
|
---|
[131] | 1252 | // 仮想関数の数を初期化
|
---|
[141] | 1253 | pobj_c->SetVtblNum( 0 );
|
---|
[29] | 1254 | }
|
---|
| 1255 | else{
|
---|
[127] | 1256 | bool isInherits = false;
|
---|
[29] | 1257 | if(basbuf[i+1]==1&&basbuf[i+2]==ESC_INHERITS){
|
---|
| 1258 | //継承を行う場合
|
---|
[127] | 1259 | isInherits = true;
|
---|
| 1260 |
|
---|
[29] | 1261 | for(i+=3,i2=0;;i++,i2++){
|
---|
| 1262 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 1263 | temporary[i2]=0;
|
---|
| 1264 | break;
|
---|
| 1265 | }
|
---|
| 1266 | temporary[i2]=basbuf[i];
|
---|
[4] | 1267 | }
|
---|
| 1268 |
|
---|
[131] | 1269 | if(lstrcmpi(temporary,pobj_c->GetName().c_str())==0){
|
---|
[29] | 1270 | SetError(105,temporary,i);
|
---|
| 1271 | goto InheritsError;
|
---|
| 1272 | }
|
---|
[4] | 1273 | }
|
---|
[127] | 1274 |
|
---|
| 1275 | if( !isInherits ){
|
---|
[29] | 1276 | //Objectを継承する
|
---|
| 1277 | lstrcpy( temporary, "Object" );
|
---|
| 1278 | }
|
---|
[4] | 1279 |
|
---|
[131] | 1280 | pobj_c->Inherits( temporary, i );
|
---|
[4] | 1281 | }
|
---|
| 1282 | InheritsError:
|
---|
| 1283 |
|
---|
[18] | 1284 | //メンバとメソッドを取得
|
---|
[4] | 1285 | while(1){
|
---|
| 1286 | i++;
|
---|
| 1287 |
|
---|
| 1288 | //エラー
|
---|
| 1289 | if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_TYPE)){
|
---|
| 1290 | SetError(22,"Class",i);
|
---|
| 1291 | i--;
|
---|
| 1292 | break;
|
---|
| 1293 | }
|
---|
| 1294 |
|
---|
| 1295 | if(basbuf[i]==1&&basbuf[i+1]==ESC_INHERITS){
|
---|
| 1296 | SetError(111,NULL,i);
|
---|
| 1297 | break;
|
---|
| 1298 | }
|
---|
| 1299 |
|
---|
| 1300 | //Static修飾子
|
---|
| 1301 | BOOL bStatic;
|
---|
| 1302 | if(basbuf[i]==1&&basbuf[i+1]==ESC_STATIC){
|
---|
| 1303 | bStatic=1;
|
---|
| 1304 | i+=2;
|
---|
| 1305 | }
|
---|
| 1306 | else bStatic=0;
|
---|
| 1307 |
|
---|
[17] | 1308 | //Const修飾子
|
---|
| 1309 | bool isConst = false;
|
---|
| 1310 | if( basbuf[i] == 1 && basbuf[i + 1] == ESC_CONST ){
|
---|
| 1311 | isConst = true;
|
---|
| 1312 | i += 2;
|
---|
| 1313 | }
|
---|
[40] | 1314 |
|
---|
[4] | 1315 | if(basbuf[i]==1&&(
|
---|
| 1316 | basbuf[i+1]==ESC_ABSTRACT||basbuf[i+1]==ESC_VIRTUAL||basbuf[i+1]==ESC_OVERRIDE||
|
---|
| 1317 | basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION
|
---|
| 1318 | )){
|
---|
| 1319 | i3=basbuf[i+1];
|
---|
| 1320 | sub_address=i;
|
---|
| 1321 | }
|
---|
| 1322 | else i3=0;
|
---|
| 1323 |
|
---|
[135] | 1324 | bool isVirtual = false, isAbstract = false, isOverride = false;
|
---|
[4] | 1325 | if(i3==ESC_ABSTRACT){
|
---|
[135] | 1326 | isAbstract=1;
|
---|
| 1327 | isVirtual=1;
|
---|
[4] | 1328 | i+=2;
|
---|
| 1329 |
|
---|
| 1330 | i3=basbuf[i+1];
|
---|
| 1331 | }
|
---|
| 1332 | else if(i3==ESC_VIRTUAL){
|
---|
[135] | 1333 | isAbstract=0;
|
---|
| 1334 | isVirtual=1;
|
---|
[4] | 1335 | i+=2;
|
---|
| 1336 |
|
---|
| 1337 | i3=basbuf[i+1];
|
---|
| 1338 | }
|
---|
| 1339 | else if(i3==ESC_OVERRIDE){
|
---|
[135] | 1340 | isOverride=1;
|
---|
| 1341 | isVirtual=1;
|
---|
[4] | 1342 |
|
---|
| 1343 | i+=2;
|
---|
| 1344 |
|
---|
| 1345 | i3=basbuf[i+1];
|
---|
| 1346 | }
|
---|
| 1347 |
|
---|
| 1348 | for(i2=0;;i++,i2++){
|
---|
| 1349 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 1350 | temporary[i2]=0;
|
---|
| 1351 | break;
|
---|
| 1352 | }
|
---|
| 1353 | temporary[i2]=basbuf[i];
|
---|
| 1354 | }
|
---|
| 1355 | if(temporary[0]=='\0'){
|
---|
| 1356 | if(basbuf[i]=='\0'){
|
---|
| 1357 |
|
---|
| 1358 | if(dwClassType==ESC_CLASS)
|
---|
| 1359 | SetError(22,"Class",top_pos);
|
---|
| 1360 | else
|
---|
| 1361 | SetError(22,"Type",top_pos);
|
---|
| 1362 |
|
---|
| 1363 | i--;
|
---|
| 1364 | break;
|
---|
| 1365 | }
|
---|
| 1366 | continue;
|
---|
| 1367 | }
|
---|
| 1368 |
|
---|
| 1369 | //End Class記述の場合
|
---|
| 1370 | if(temporary[0]==1&&temporary[1]==ESC_ENDCLASS&&dwClassType==ESC_CLASS) break;
|
---|
| 1371 | if(temporary[0]==1&&temporary[1]==ESC_ENDTYPE&&dwClassType==ESC_TYPE) break;
|
---|
| 1372 |
|
---|
| 1373 | //アクセスを変更
|
---|
| 1374 | if(lstrcmpi(temporary,"Private")==0){
|
---|
[137] | 1375 | accessibility = Prototype::Private;
|
---|
[4] | 1376 | continue;
|
---|
| 1377 | }
|
---|
| 1378 | if(lstrcmpi(temporary,"Public")==0){
|
---|
[137] | 1379 | accessibility = Prototype::Public;
|
---|
[4] | 1380 | continue;
|
---|
| 1381 | }
|
---|
| 1382 | if(lstrcmpi(temporary,"Protected")==0){
|
---|
[137] | 1383 | accessibility = Prototype::Protected;
|
---|
[4] | 1384 | continue;
|
---|
| 1385 | }
|
---|
| 1386 |
|
---|
| 1387 | extern int cp;
|
---|
| 1388 | if(i3==0){
|
---|
| 1389 | if(bStatic){
|
---|
| 1390 | //静的メンバを追加
|
---|
| 1391 | cp=i; //エラー用
|
---|
[137] | 1392 | pobj_c->AddStaticMember( accessibility, isConst, false, temporary, i);
|
---|
[4] | 1393 | }
|
---|
| 1394 | else{
|
---|
| 1395 | //メンバを追加
|
---|
| 1396 | cp=i; //エラー用
|
---|
[137] | 1397 | pobj_c->AddMember( accessibility, isConst, false, temporary );
|
---|
[4] | 1398 |
|
---|
| 1399 |
|
---|
[140] | 1400 | if(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().IsStruct()){
|
---|
| 1401 | if( !pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass().IsReady() ){
|
---|
[4] | 1402 | //参照先が読み取られていないとき
|
---|
[140] | 1403 | GetClass_recur(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass().GetName().c_str());
|
---|
[4] | 1404 | }
|
---|
| 1405 | }
|
---|
| 1406 |
|
---|
| 1407 |
|
---|
[140] | 1408 | if(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().IsStruct()){
|
---|
[4] | 1409 | //循環参照のチェック
|
---|
[131] | 1410 | pobj_LoopRefCheck->add(pobj_c->GetName().c_str());
|
---|
[140] | 1411 | if(!MemberVar_LoopRefCheck(pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().GetClass())){
|
---|
[4] | 1412 | //エラー回避
|
---|
[140] | 1413 | pobj_c->dynamicMembers[pobj_c->dynamicMembers.size()-1]->GetType().SetBasicType( DEF_PTR_VOID );
|
---|
[4] | 1414 | }
|
---|
[131] | 1415 | pobj_LoopRefCheck->del(pobj_c->GetName().c_str());
|
---|
[4] | 1416 | }
|
---|
| 1417 | }
|
---|
| 1418 | }
|
---|
| 1419 | else{
|
---|
| 1420 | //メソッドを追加
|
---|
| 1421 | cp=i; //エラー用
|
---|
[18] | 1422 | AddMethod(pobj_c,
|
---|
[137] | 1423 | accessibility,
|
---|
[18] | 1424 | bStatic,
|
---|
| 1425 | isConst,
|
---|
[135] | 1426 | isAbstract,
|
---|
| 1427 | isVirtual,
|
---|
| 1428 | isOverride,
|
---|
[18] | 1429 | temporary,
|
---|
| 1430 | sub_address);
|
---|
[4] | 1431 |
|
---|
[135] | 1432 | if( isAbstract ) continue;
|
---|
[4] | 1433 |
|
---|
| 1434 | for(;;i++){
|
---|
| 1435 | if(basbuf[i]=='\0'){
|
---|
| 1436 | i--;
|
---|
| 1437 | break;
|
---|
| 1438 | }
|
---|
| 1439 | if(basbuf[i-1]!='*'&&
|
---|
| 1440 | basbuf[i]==1&&(
|
---|
| 1441 | basbuf[i+1]==ESC_SUB||
|
---|
| 1442 | basbuf[i+1]==ESC_FUNCTION||
|
---|
| 1443 | basbuf[i+1]==ESC_MACRO||
|
---|
| 1444 | basbuf[i+1]==ESC_TYPE||
|
---|
| 1445 | basbuf[i+1]==ESC_CLASS||
|
---|
| 1446 | basbuf[i+1]==ESC_INTERFACE||
|
---|
| 1447 | basbuf[i+1]==ESC_ENUM)){
|
---|
| 1448 | GetDefaultNameFromES(i3,temporary);
|
---|
| 1449 | SetError(22,temporary,i);
|
---|
| 1450 | }
|
---|
| 1451 | if(basbuf[i]==1&&basbuf[i+1]==GetEndXXXCommand((char)i3)){
|
---|
| 1452 | i+=2;
|
---|
| 1453 | break;
|
---|
| 1454 | }
|
---|
| 1455 | }
|
---|
| 1456 | }
|
---|
| 1457 | }
|
---|
| 1458 | }
|
---|
| 1459 | }
|
---|
[139] | 1460 |
|
---|
| 1461 |
|
---|
| 1462 | // 名前空間を元に戻す
|
---|
| 1463 | Smoothie::Lexical::liveingNamespaceScopes = backupNamespaceScopes;
|
---|
[4] | 1464 | }
|
---|
| 1465 |
|
---|
[159] | 1466 | void Classes::GetAllClassInfo(void){
|
---|
[4] | 1467 | //ループ継承チェック用のクラス
|
---|
| 1468 | pobj_LoopRefCheck=new CLoopRefCheck();
|
---|
| 1469 |
|
---|
| 1470 | //クラスを取得
|
---|
| 1471 | GetClass_recur(0);
|
---|
| 1472 |
|
---|
| 1473 | delete pobj_LoopRefCheck;
|
---|
| 1474 | pobj_LoopRefCheck=0;
|
---|
[89] | 1475 |
|
---|
| 1476 | // イテレータ用のデータを作る
|
---|
| 1477 | pobj_DBClass->Iterator_Init();
|
---|
[4] | 1478 | }
|
---|
| 1479 |
|
---|
[159] | 1480 | void Classes::Compile_System_InitializeUserTypes(){
|
---|
[90] | 1481 | char temporary[VN_SIZE];
|
---|
[89] | 1482 |
|
---|
| 1483 | ////////////////////////////////////////////////////////////////////
|
---|
| 1484 | // クラス登録
|
---|
| 1485 | ////////////////////////////////////////////////////////////////////
|
---|
| 1486 |
|
---|
| 1487 | // イテレータをリセット
|
---|
| 1488 | Iterator_Reset();
|
---|
| 1489 |
|
---|
| 1490 | while( Iterator_HasNext() ){
|
---|
[91] | 1491 | const CClass &objClass = *Iterator_GetNext();
|
---|
[89] | 1492 |
|
---|
[91] | 1493 | if( !objClass.IsUsing() ){
|
---|
| 1494 | // 未使用のクラスは無視する
|
---|
| 1495 | continue;
|
---|
| 1496 | }
|
---|
| 1497 |
|
---|
[94] | 1498 | char referenceOffsetsBuffer[1024] = "";
|
---|
| 1499 | int numOfReference = 0;
|
---|
[140] | 1500 | BOOST_FOREACH( CMember *pMember, objClass.dynamicMembers ){
|
---|
| 1501 | if( pMember->GetType().IsObject() || pMember->GetType().IsPointer() ){
|
---|
[94] | 1502 | if( referenceOffsetsBuffer[0] ){
|
---|
| 1503 | lstrcat( referenceOffsetsBuffer, "," );
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | sprintf( referenceOffsetsBuffer + lstrlen( referenceOffsetsBuffer ),
|
---|
| 1507 | "%d",
|
---|
[140] | 1508 | objClass.GetMemberOffset( pMember->GetName().c_str() ) );
|
---|
[94] | 1509 |
|
---|
| 1510 | numOfReference++;
|
---|
| 1511 | }
|
---|
| 1512 | }
|
---|
| 1513 |
|
---|
[89] | 1514 | sprintf( temporary
|
---|
[94] | 1515 | , "Add(%c%c_System_TypeForClass(\"%s\",\"%s\",[%s],%d))"
|
---|
[89] | 1516 | , 1
|
---|
| 1517 | , ESC_NEW
|
---|
[131] | 1518 | , "" // 名前空間 (TODO: 実装)
|
---|
| 1519 | , objClass.GetName().c_str() // クラス名
|
---|
| 1520 | , referenceOffsetsBuffer // 参照メンバオフセット配列
|
---|
| 1521 | , numOfReference // 参照メンバの個数
|
---|
[89] | 1522 | );
|
---|
| 1523 |
|
---|
| 1524 | // コンパイル
|
---|
| 1525 | ChangeOpcode( temporary );
|
---|
| 1526 |
|
---|
| 1527 | // ネイティブコードバッファの再確保
|
---|
| 1528 | ReallocNativeCodeBuffer();
|
---|
| 1529 | }
|
---|
| 1530 |
|
---|
| 1531 |
|
---|
| 1532 | ////////////////////////////////////////////////////////////////////
|
---|
[90] | 1533 | // 基底クラスを登録
|
---|
| 1534 | ////////////////////////////////////////////////////////////////////
|
---|
| 1535 |
|
---|
| 1536 | sprintf(temporary, "%c%ctempType=Nothing%c%cTypeBaseImpl"
|
---|
| 1537 | , HIBYTE( COM_DIM )
|
---|
| 1538 | , LOBYTE( COM_DIM )
|
---|
| 1539 | , 1
|
---|
| 1540 | , ESC_AS
|
---|
| 1541 | );
|
---|
| 1542 | ChangeOpcode( temporary );
|
---|
| 1543 |
|
---|
| 1544 | // イテレータをリセット
|
---|
| 1545 | Iterator_Reset();
|
---|
| 1546 |
|
---|
| 1547 | while( Iterator_HasNext() ){
|
---|
[91] | 1548 | const CClass &objClass = *Iterator_GetNext();
|
---|
[90] | 1549 |
|
---|
[91] | 1550 | if( !objClass.IsUsing() ){
|
---|
| 1551 | // 未使用のクラスは無視する
|
---|
| 1552 | continue;
|
---|
| 1553 | }
|
---|
| 1554 |
|
---|
| 1555 | if( objClass.pobj_InheritsClass ){
|
---|
[90] | 1556 | sprintf( temporary
|
---|
| 1557 | , "tempType=Search(\"%s\",\"%s\")"
|
---|
[131] | 1558 | , "" // 名前空間 (TODO: 実装)
|
---|
| 1559 | , objClass.GetName().c_str() // クラス名
|
---|
[90] | 1560 | );
|
---|
| 1561 |
|
---|
| 1562 | // コンパイル
|
---|
| 1563 | ChangeOpcode( temporary );
|
---|
| 1564 |
|
---|
| 1565 | sprintf( temporary
|
---|
| 1566 | , "tempType.SetBaseType(Search(\"%s\",\"%s\"))"
|
---|
| 1567 | , "" // 名前空間 (TODO: 実装)
|
---|
[131] | 1568 | , objClass.pobj_InheritsClass->GetName().c_str() // 基底クラス名
|
---|
[90] | 1569 | );
|
---|
| 1570 |
|
---|
| 1571 | // コンパイル
|
---|
| 1572 | ChangeOpcode( temporary );
|
---|
| 1573 | }
|
---|
| 1574 |
|
---|
| 1575 | // ネイティブコードバッファの再確保
|
---|
| 1576 | ReallocNativeCodeBuffer();
|
---|
| 1577 | }
|
---|
| 1578 |
|
---|
| 1579 |
|
---|
| 1580 |
|
---|
| 1581 | ////////////////////////////////////////////////////////////////////
|
---|
[89] | 1582 | // 継承関係登録
|
---|
| 1583 | ////////////////////////////////////////////////////////////////////
|
---|
| 1584 | // TODO: 未完成
|
---|
| 1585 | /*
|
---|
| 1586 |
|
---|
| 1587 | // イテレータをリセット
|
---|
| 1588 | Iterator_Reset();
|
---|
| 1589 |
|
---|
| 1590 | while( Iterator_HasNext() ){
|
---|
| 1591 | CClass *pClass = Iterator_GetNext();
|
---|
| 1592 |
|
---|
| 1593 | sprintf( genBuffer + length
|
---|
| 1594 | , "obj.Search( \"%s\" ).SetBaseType( Search( \"%s\" ) ):"
|
---|
| 1595 | , "" // クラス名
|
---|
| 1596 | , pClass->name // クラス名
|
---|
| 1597 | );
|
---|
| 1598 | length += lstrlen( genBuffer + length );
|
---|
| 1599 |
|
---|
| 1600 | while( length + 8192 > max ){
|
---|
| 1601 | max += 8192;
|
---|
| 1602 | genBuffer = (char *)realloc( genBuffer, max );
|
---|
| 1603 | }
|
---|
| 1604 | }*/
|
---|
[87] | 1605 | }
|
---|
| 1606 |
|
---|
| 1607 |
|
---|
| 1608 |
|
---|
[159] | 1609 | CClass *Classes::GetStringClassPtr() const
|
---|
[67] | 1610 | {
|
---|
| 1611 | if( !pStringClass ){
|
---|
| 1612 | SetError();
|
---|
| 1613 | return NULL;
|
---|
| 1614 | }
|
---|
| 1615 | return pStringClass;
|
---|
| 1616 | }
|
---|
[159] | 1617 | CClass *Classes::GetObjectClassPtr() const
|
---|
[67] | 1618 | {
|
---|
| 1619 | if( !pObjectClass ){
|
---|
| 1620 | SetError();
|
---|
| 1621 | return NULL;
|
---|
| 1622 | }
|
---|
| 1623 | return pObjectClass;
|
---|
| 1624 | }
|
---|
| 1625 |
|
---|
[159] | 1626 | void Classes::StartCompile( UserProc *pUserProc ){
|
---|
[75] | 1627 | pCompilingClass = pUserProc->GetParentClassPtr();
|
---|
[18] | 1628 | if( pCompilingClass ){
|
---|
[91] | 1629 | pCompilingClass->Using();
|
---|
| 1630 |
|
---|
[135] | 1631 | pCompilingMethod = pCompilingClass->methods.GetMethodPtr( pUserProc );
|
---|
[18] | 1632 | if( !pCompilingMethod ){
|
---|
[135] | 1633 | pCompilingMethod = pCompilingClass->staticMethods.GetMethodPtr( pUserProc );
|
---|
[18] | 1634 | if( !pCompilingMethod ){
|
---|
| 1635 | SetError(300,NULL,cp);
|
---|
| 1636 | }
|
---|
| 1637 | }
|
---|
| 1638 | }
|
---|
| 1639 | else{
|
---|
| 1640 | pCompilingMethod = NULL;
|
---|
| 1641 | }
|
---|
| 1642 | }
|
---|
[159] | 1643 | const CClass *Classes::GetNowCompilingClass() const
|
---|
[114] | 1644 | {
|
---|
[18] | 1645 | return pCompilingClass;
|
---|
| 1646 | }
|
---|
[159] | 1647 | const CMethod *Classes::GetNowCompilingMethodInfo(){
|
---|
[18] | 1648 | return pCompilingMethod;
|
---|
| 1649 | }
|
---|
[4] | 1650 |
|
---|
| 1651 |
|
---|
| 1652 |
|
---|
[18] | 1653 |
|
---|
[4] | 1654 | //////////////////////
|
---|
| 1655 | // イテレータ
|
---|
| 1656 | //////////////////////
|
---|
| 1657 |
|
---|
[159] | 1658 | void Classes::Iterator_Init(void){
|
---|
[4] | 1659 | if(ppobj_IteClass) HeapDefaultFree(ppobj_IteClass);
|
---|
| 1660 |
|
---|
| 1661 | iIteMaxNum=0;
|
---|
| 1662 | iIteNextNum=0;
|
---|
| 1663 | ppobj_IteClass=(CClass **)HeapAlloc(hHeap,0,1);
|
---|
| 1664 |
|
---|
| 1665 | int i;
|
---|
| 1666 | for(i=0;i<MAX_CLASS_HASH;i++){
|
---|
| 1667 | if(pobj_ClassHash[i]){
|
---|
| 1668 | CClass *pobj_c;
|
---|
| 1669 | pobj_c=pobj_ClassHash[i];
|
---|
| 1670 | while(1){
|
---|
| 1671 | ppobj_IteClass=(CClass **)HeapReAlloc(hHeap,0,ppobj_IteClass,(iIteMaxNum+1)*sizeof(CClass *));
|
---|
| 1672 | ppobj_IteClass[iIteMaxNum]=pobj_c;
|
---|
| 1673 | iIteMaxNum++;
|
---|
| 1674 |
|
---|
| 1675 | if(pobj_c->pobj_NextClass==0) break;
|
---|
| 1676 | pobj_c=pobj_c->pobj_NextClass;
|
---|
| 1677 | }
|
---|
| 1678 | }
|
---|
| 1679 | }
|
---|
| 1680 | }
|
---|
[159] | 1681 | void Classes::Iterator_Reset(void){
|
---|
[89] | 1682 | iIteNextNum = 0;
|
---|
| 1683 | }
|
---|
[159] | 1684 | BOOL Classes::Iterator_HasNext(void){
|
---|
[4] | 1685 | if(iIteNextNum<iIteMaxNum) return 1;
|
---|
| 1686 | return 0;
|
---|
| 1687 | }
|
---|
[159] | 1688 | CClass *Classes::Iterator_GetNext(void){
|
---|
[4] | 1689 | CClass *pobj_c;
|
---|
| 1690 | pobj_c=ppobj_IteClass[iIteNextNum];
|
---|
| 1691 | iIteNextNum++;
|
---|
| 1692 | return pobj_c;
|
---|
| 1693 | }
|
---|
[159] | 1694 | int Classes::Iterator_GetMaxCount(void){
|
---|
[4] | 1695 | return iIteMaxNum;
|
---|
| 1696 | }
|
---|