[184] | 1 | #pragma once
|
---|
| 2 |
|
---|
[206] | 3 | #include <option.h>
|
---|
| 4 | #include <Program.h>
|
---|
| 5 | #include <Prototype.h>
|
---|
| 6 | #include <Method.h>
|
---|
| 7 | #include <Member.h>
|
---|
[266] | 8 | #include <Source.h>
|
---|
[184] | 9 |
|
---|
[206] | 10 | class UserProc;
|
---|
[290] | 11 | class CClass;
|
---|
[206] | 12 |
|
---|
| 13 | class InheritedInterface
|
---|
[184] | 14 | {
|
---|
[206] | 15 | CClass *pInterfaceClass;
|
---|
| 16 | int vtblOffset;
|
---|
[184] | 17 | public:
|
---|
[206] | 18 | InheritedInterface( CClass *pInterfaceClass, int vtblOffset )
|
---|
| 19 | : pInterfaceClass( pInterfaceClass )
|
---|
| 20 | , vtblOffset( vtblOffset )
|
---|
[184] | 21 | {
|
---|
| 22 | }
|
---|
[206] | 23 |
|
---|
| 24 | CClass &GetInterfaceClass() const{
|
---|
| 25 | return *pInterfaceClass;
|
---|
| 26 | }
|
---|
| 27 | int GetVtblOffset() const
|
---|
[191] | 28 | {
|
---|
[206] | 29 | return vtblOffset;
|
---|
[191] | 30 | }
|
---|
[206] | 31 | };
|
---|
| 32 | typedef vector<InheritedInterface> Interfaces;
|
---|
[184] | 33 |
|
---|
[270] | 34 | class CClass: public Prototype, public Jenga::Common::ObjectInHashmap<CClass>
|
---|
[206] | 35 | {
|
---|
| 36 | public:
|
---|
| 37 | // 型の種類
|
---|
| 38 | enum ClassType{
|
---|
| 39 | Class,
|
---|
| 40 | Interface,
|
---|
| 41 | Enum,
|
---|
| 42 | Delegate,
|
---|
| 43 | Structure,
|
---|
| 44 | };
|
---|
[193] | 45 |
|
---|
[206] | 46 | private:
|
---|
| 47 | ClassType classType;
|
---|
[184] | 48 |
|
---|
[206] | 49 | // importされている名前空間
|
---|
| 50 | NamespaceScopesCollection importedNamespaces;
|
---|
[290] | 51 |
|
---|
| 52 | // 型パラメータ
|
---|
| 53 | GenericTypes formalGenericTypes;
|
---|
| 54 |
|
---|
[206] | 55 | // 継承クラス
|
---|
| 56 | const CClass *pSuperClass;
|
---|
[184] | 57 |
|
---|
[206] | 58 | // Blittable型情報
|
---|
| 59 | Type blittableType;
|
---|
[184] | 60 |
|
---|
[206] | 61 | // 実装するインターフェイス
|
---|
| 62 | Interfaces interfaces;
|
---|
[191] | 63 |
|
---|
[206] | 64 | // 動的メンバ
|
---|
| 65 | Members dynamicMembers;
|
---|
[191] | 66 |
|
---|
[206] | 67 | // 静的メンバ
|
---|
| 68 | Members staticMembers;
|
---|
| 69 |
|
---|
| 70 | // 動的メソッド
|
---|
| 71 | Methods methods;
|
---|
| 72 | int ConstructorMemberSubIndex;
|
---|
| 73 | int DestructorMemberSubIndex;
|
---|
| 74 | int vtblNum; // 仮想関数の数
|
---|
| 75 |
|
---|
| 76 | // 静的メソッド
|
---|
| 77 | Methods staticMethods;
|
---|
| 78 |
|
---|
[232] | 79 | //アラインメント値
|
---|
| 80 | int fixedAlignment;
|
---|
| 81 |
|
---|
[191] | 82 | // XMLシリアライズ用
|
---|
[208] | 83 | // TODO: xml未完成
|
---|
[191] | 84 | private:
|
---|
| 85 | friend class boost::serialization::access;
|
---|
| 86 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 87 | {
|
---|
[206] | 88 | trace_for_serialize( "serializing - CClass" );
|
---|
| 89 |
|
---|
| 90 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Prototype );
|
---|
| 91 | ar & BOOST_SERIALIZATION_NVP( classType );
|
---|
| 92 | ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
|
---|
[293] | 93 | ar & BOOST_SERIALIZATION_NVP( formalGenericTypes );
|
---|
[206] | 94 | ar & boost::serialization::make_nvp( "pSuperClass", const_cast<CClass *&>(pSuperClass) );
|
---|
| 95 | ar & BOOST_SERIALIZATION_NVP( blittableType );
|
---|
| 96 | //ar & BOOST_SERIALIZATION_NVP( interfaces );
|
---|
| 97 | ar & BOOST_SERIALIZATION_NVP( dynamicMembers );
|
---|
| 98 | ar & BOOST_SERIALIZATION_NVP( staticMembers );
|
---|
| 99 | ar & BOOST_SERIALIZATION_NVP( methods );
|
---|
| 100 | ar & BOOST_SERIALIZATION_NVP( ConstructorMemberSubIndex );
|
---|
| 101 | ar & BOOST_SERIALIZATION_NVP( DestructorMemberSubIndex );
|
---|
| 102 | ar & BOOST_SERIALIZATION_NVP( vtblNum );
|
---|
| 103 | ar & BOOST_SERIALIZATION_NVP( staticMethods );
|
---|
[232] | 104 | ar & BOOST_SERIALIZATION_NVP( fixedAlignment );
|
---|
[191] | 105 | }
|
---|
[184] | 106 |
|
---|
[206] | 107 | bool isReady;
|
---|
[184] | 108 | public:
|
---|
[206] | 109 |
|
---|
| 110 | CClass( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name )
|
---|
| 111 | : Prototype( namespaceScopes, name )
|
---|
| 112 | , importedNamespaces( importedNamespaces )
|
---|
| 113 | , classType( Class )
|
---|
| 114 | , pSuperClass( NULL )
|
---|
[290] | 115 | , blittableType( Type() )
|
---|
[206] | 116 | , isReady( false )
|
---|
[232] | 117 | , fixedAlignment( 0 )
|
---|
[206] | 118 | , ConstructorMemberSubIndex( -1 )
|
---|
| 119 | , DestructorMemberSubIndex( -1 )
|
---|
| 120 | , vtblNum( 0 )
|
---|
| 121 | , vtbl_offset( -1 )
|
---|
| 122 | , isCompilingConstructor( false )
|
---|
| 123 | , isCompilingDestructor( false )
|
---|
| 124 | , pobj_NextClass( NULL )
|
---|
[191] | 125 | {
|
---|
| 126 | }
|
---|
[206] | 127 | CClass()
|
---|
| 128 | : Prototype()
|
---|
| 129 | , importedNamespaces()
|
---|
| 130 | , classType()
|
---|
| 131 | , pSuperClass( NULL )
|
---|
[290] | 132 | , blittableType( Type() )
|
---|
[206] | 133 | , isReady( false )
|
---|
[232] | 134 | , fixedAlignment( 0 )
|
---|
[206] | 135 | , ConstructorMemberSubIndex( -1 )
|
---|
| 136 | , DestructorMemberSubIndex( -1 )
|
---|
| 137 | , vtblNum( 0 )
|
---|
| 138 | , vtbl_offset( -1 )
|
---|
| 139 | , isCompilingConstructor( false )
|
---|
| 140 | , isCompilingDestructor( false )
|
---|
| 141 | , pobj_NextClass( NULL )
|
---|
| 142 | {
|
---|
| 143 | }
|
---|
| 144 | ~CClass()
|
---|
| 145 | {
|
---|
| 146 | // 動的メンバ
|
---|
| 147 | BOOST_FOREACH( CMember *member, dynamicMembers ){
|
---|
| 148 | delete member;
|
---|
| 149 | }
|
---|
[191] | 150 |
|
---|
[206] | 151 | // 静的メンバ
|
---|
| 152 | BOOST_FOREACH( CMember *member, staticMembers ){
|
---|
| 153 | delete member;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
[184] | 156 |
|
---|
[270] | 157 | virtual const std::string &GetKeyName() const
|
---|
| 158 | {
|
---|
| 159 | return GetName();
|
---|
| 160 | }
|
---|
| 161 | virtual bool IsDuplication( const CClass *pClass ) const
|
---|
| 162 | {
|
---|
| 163 | if( pClass->IsEqualSymbol( *this ) )
|
---|
| 164 | {
|
---|
| 165 | return true;
|
---|
| 166 | }
|
---|
| 167 | return false;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[206] | 170 | void Readed(){
|
---|
| 171 | isReady = true;
|
---|
| 172 | }
|
---|
| 173 | bool IsReady() const{
|
---|
| 174 | return isReady;
|
---|
| 175 | }
|
---|
[184] | 176 |
|
---|
[206] | 177 | const NamespaceScopesCollection &GetImportedNamespaces() const
|
---|
| 178 | {
|
---|
| 179 | return importedNamespaces;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[290] | 182 | // 型パラメータ
|
---|
| 183 | void AddFormalGenericType( GenericType genericType )
|
---|
| 184 | {
|
---|
| 185 | this->formalGenericTypes.push_back( genericType );
|
---|
| 186 | }
|
---|
| 187 | bool IsExistFormalGenericTypeParameter( const std::string &name ) const
|
---|
| 188 | {
|
---|
| 189 | BOOST_FOREACH( const GenericType &genericType, formalGenericTypes )
|
---|
| 190 | {
|
---|
| 191 | if( genericType.GetName() == name )
|
---|
| 192 | {
|
---|
| 193 | return true;
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | return false;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[206] | 199 | // 継承元クラス
|
---|
| 200 | bool HasSuperClass() const
|
---|
| 201 | {
|
---|
| 202 | return ( pSuperClass != NULL );
|
---|
| 203 | }
|
---|
| 204 | const CClass &GetSuperClass() const
|
---|
| 205 | {
|
---|
| 206 | return *pSuperClass;
|
---|
| 207 | }
|
---|
| 208 | void SetSuperClass( const CClass *pSuperClass )
|
---|
| 209 | {
|
---|
| 210 | this->pSuperClass = pSuperClass;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | // Blittable型
|
---|
| 214 | bool IsBlittableType() const
|
---|
| 215 | {
|
---|
| 216 | return !blittableType.IsNull();
|
---|
| 217 | }
|
---|
| 218 | const Type &GetBlittableType() const
|
---|
| 219 | {
|
---|
| 220 | return blittableType;
|
---|
| 221 | }
|
---|
| 222 | void SetBlittableType( const Type &type ){
|
---|
| 223 | blittableType = type;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | bool IsClass() const;
|
---|
| 227 | bool IsInterface() const;
|
---|
| 228 | bool IsEnum() const;
|
---|
| 229 | bool IsDelegate() const;
|
---|
| 230 | bool IsStructure() const;
|
---|
| 231 | void SetClassType( ClassType classType )
|
---|
| 232 | {
|
---|
| 233 | this->classType = classType;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 | //コンストラクタをコンパイルしているかどうかのチェックフラグ
|
---|
[184] | 238 | private:
|
---|
[206] | 239 | mutable bool isCompilingConstructor;
|
---|
[184] | 240 | public:
|
---|
[206] | 241 | void NotifyStartConstructorCompile() const;
|
---|
| 242 | void NotifyFinishConstructorCompile() const;
|
---|
| 243 | bool IsCompilingConstructor() const;
|
---|
[184] | 244 |
|
---|
[206] | 245 | //デストラクタをコンパイルしているかどうかのチェックフラグ
|
---|
| 246 | private:
|
---|
| 247 | mutable bool isCompilingDestructor;
|
---|
| 248 | public:
|
---|
| 249 | void NotifyStartDestructorCompile() const;
|
---|
| 250 | void NotifyFinishDestructorCompile() const;
|
---|
| 251 | bool IsCompilingDestructor() const;
|
---|
[191] | 252 |
|
---|
[193] | 253 |
|
---|
[206] | 254 | //自身の派生クラスかどうかを確認
|
---|
| 255 | bool IsSubClass( const CClass *pClass ) const;
|
---|
| 256 |
|
---|
| 257 | //自身と等しいまたは派生クラスかどうかを確認
|
---|
| 258 | bool IsEqualsOrSubClass( const CClass *pClass ) const;
|
---|
| 259 |
|
---|
| 260 | // 自身と等しいまたは派生クラス、基底クラスかどうかを確認
|
---|
| 261 | bool IsEqualsOrSubClassOrSuperClass( const CClass &objClass ) const;
|
---|
| 262 |
|
---|
| 263 | // インターフェイス
|
---|
| 264 | bool HasInterfaces() const
|
---|
| 265 | {
|
---|
| 266 | return ( interfaces.size() != 0 );
|
---|
| 267 | }
|
---|
| 268 | bool IsInheritsInterface( const CClass *pInterfaceClass ) const;
|
---|
| 269 |
|
---|
| 270 | //継承させる
|
---|
| 271 | bool Inherits( const char *inheritNames, int nowLine );
|
---|
| 272 | bool InheritsClass( const CClass &inheritsClass, int nowLine );
|
---|
| 273 | bool InheritsInterface( const CClass &inheritsClass, int nowLine );
|
---|
| 274 |
|
---|
| 275 | //メンバ、メソッドの追加
|
---|
| 276 | CMember *CreateMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
|
---|
| 277 | void AddMember( Prototype::Accessibility accessibility, bool idConst, bool isRef, char *buffer, int nowLine );
|
---|
| 278 | void AddStaticMember( Prototype::Accessibility accessibility, bool isConst, bool isRef, char *buffer, int nowLine );
|
---|
| 279 |
|
---|
| 280 | void AddMethod(CClass *pobj_c, Prototype::Accessibility accessibility, BOOL bStatic, bool isConst, bool isAbstract,
|
---|
| 281 | bool isVirtual, bool isOverride, char *buffer, int nowLine);
|
---|
| 282 |
|
---|
| 283 | //重複チェック
|
---|
| 284 | bool DupliCheckAll(const char *name);
|
---|
| 285 | bool DupliCheckMember(const char *name);
|
---|
| 286 |
|
---|
| 287 | const Members &GetDynamicMembers() const
|
---|
| 288 | {
|
---|
| 289 | return dynamicMembers;
|
---|
| 290 | }
|
---|
| 291 | const Members &GetStaticMembers() const
|
---|
| 292 | {
|
---|
| 293 | return staticMembers;
|
---|
| 294 | }
|
---|
| 295 | Members &GetDynamicMembers()
|
---|
| 296 | {
|
---|
| 297 | return dynamicMembers;
|
---|
| 298 | }
|
---|
| 299 | Members &GetStaticMembers()
|
---|
| 300 | {
|
---|
| 301 | return staticMembers;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | const Methods &GetMethods() const
|
---|
| 305 | {
|
---|
| 306 | return methods;
|
---|
| 307 | }
|
---|
| 308 | const Methods &GetStaticMethods() const
|
---|
| 309 | {
|
---|
| 310 | return staticMethods;
|
---|
| 311 | }
|
---|
| 312 | Methods &GetMethods()
|
---|
| 313 | {
|
---|
| 314 | return methods;
|
---|
| 315 | }
|
---|
| 316 | Methods &GetStaticMethods()
|
---|
| 317 | {
|
---|
| 318 | return staticMethods;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | //デフォルト コンストラクタ
|
---|
| 322 | const CMethod *GetConstructorMethod() const
|
---|
| 323 | {
|
---|
| 324 | if( ConstructorMemberSubIndex == -1 ) return NULL;
|
---|
| 325 | return methods[ConstructorMemberSubIndex];
|
---|
| 326 | }
|
---|
| 327 | void SetConstructorMemberSubIndex( int constructorMemberSubIndex )
|
---|
| 328 | {
|
---|
| 329 | this->ConstructorMemberSubIndex = constructorMemberSubIndex;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | //デストラクタ メソッドを取得
|
---|
| 333 | const CMethod *GetDestructorMethod() const
|
---|
| 334 | {
|
---|
| 335 | if( DestructorMemberSubIndex == -1 ) return NULL;
|
---|
| 336 | return methods[DestructorMemberSubIndex];
|
---|
| 337 | }
|
---|
| 338 | void SetDestructorMemberSubIndex( int destructorMemberSubIndex )
|
---|
| 339 | {
|
---|
| 340 | this->DestructorMemberSubIndex = destructorMemberSubIndex;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | // vtblに存在する仮想関数の数
|
---|
| 344 | int GetVtblNum() const
|
---|
| 345 | {
|
---|
| 346 | return vtblNum;
|
---|
| 347 | }
|
---|
| 348 | void SetVtblNum( int vtblNum )
|
---|
| 349 | {
|
---|
| 350 | this->vtblNum = vtblNum;
|
---|
| 351 | }
|
---|
| 352 | void AddVtblNum( int vtblNum )
|
---|
| 353 | {
|
---|
| 354 | this->vtblNum += vtblNum;
|
---|
| 355 | }
|
---|
| 356 | bool IsExistVirtualFunctions() const
|
---|
| 357 | {
|
---|
| 358 | return ( vtblNum > 0 );
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[232] | 361 | // ユーザ指定のアラインメント固定値
|
---|
| 362 | int GetFixedAlignment() const
|
---|
| 363 | {
|
---|
| 364 | return fixedAlignment;
|
---|
| 365 | }
|
---|
| 366 | void SetFixedAlignment( int fixedAlignment )
|
---|
| 367 | {
|
---|
| 368 | this->fixedAlignment = fixedAlignment;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[206] | 371 | // メンバの総合サイズを取得
|
---|
| 372 | int GetSize() const;
|
---|
| 373 |
|
---|
| 374 | // メンバのオフセットを取得
|
---|
| 375 | int GetMemberOffset( const char *memberName, int *pMemberNum = NULL ) const;
|
---|
| 376 | private:
|
---|
| 377 | // アラインメント値を取得
|
---|
| 378 | int GetAlignment() const;
|
---|
| 379 |
|
---|
| 380 | //vtbl
|
---|
| 381 | protected:
|
---|
| 382 | mutable long vtbl_offset;
|
---|
| 383 | public:
|
---|
| 384 | int GetFuncNumInVtbl( const UserProc *pUserProc ) const;
|
---|
| 385 | LONG_PTR GetVtblGlobalOffset(void) const;
|
---|
[282] | 386 | void GenerateVTables();
|
---|
[206] | 387 | void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
|
---|
| 388 | bool IsAbstract() const;
|
---|
| 389 |
|
---|
| 390 |
|
---|
| 391 | //線形リスト用
|
---|
| 392 | CClass *pobj_NextClass;
|
---|
| 393 | };
|
---|
| 394 |
|
---|
[270] | 395 | class Classes : public Jenga::Common::Hashmap<CClass>
|
---|
[206] | 396 | {
|
---|
[191] | 397 | // XMLシリアライズ用
|
---|
[206] | 398 | public:
|
---|
| 399 | Classes()
|
---|
| 400 | : pCompilingMethod( NULL )
|
---|
| 401 | , pStringClass( NULL )
|
---|
| 402 | , pObjectClass( NULL )
|
---|
| 403 | {
|
---|
| 404 | }
|
---|
| 405 | ~Classes()
|
---|
| 406 | {
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | virtual CClass *Create( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name);
|
---|
| 410 | bool Insert( CClass *pClass );
|
---|
| 411 | CClass *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const char *name,int nowLine);
|
---|
| 412 | virtual void CollectClassesForNameOnly( const BasicSource &source );
|
---|
| 413 |
|
---|
[282] | 414 | void GenerateVTables();
|
---|
[206] | 415 | void ActionVtblSchedule(LONG_PTR ImageBase, LONG_PTR MemPos_CodeSection);
|
---|
| 416 |
|
---|
| 417 | virtual void InitStaticMember();
|
---|
| 418 |
|
---|
| 419 | private:
|
---|
| 420 | bool MemberVar_LoopRefCheck(const CClass &objClass);
|
---|
| 421 | public:
|
---|
| 422 | virtual void GetClass_recur(const char *lpszInheritsClass);
|
---|
| 423 | virtual void GetAllClassInfo();
|
---|
| 424 | virtual void Compile_System_InitializeUserTypes();
|
---|
| 425 |
|
---|
| 426 | const CClass *Find( const NamespaceScopes &namespaceScopes, const string &name ) const;
|
---|
| 427 | const CClass *Find( const string &fullName ) const;
|
---|
| 428 |
|
---|
| 429 |
|
---|
| 430 | /////////////////////////////
|
---|
| 431 | // 現在コンパイル中の情報
|
---|
| 432 | /////////////////////////////
|
---|
| 433 | private:
|
---|
| 434 | const CMethod *pCompilingMethod;
|
---|
| 435 | public:
|
---|
| 436 | void StartCompile( const UserProc *pUserProc );
|
---|
| 437 |
|
---|
| 438 | //現在コンパイル中のメソッド情報を取得
|
---|
| 439 | const CMethod *GetNowCompilingMethodInfo(){
|
---|
| 440 | return pCompilingMethod;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 |
|
---|
| 444 | /////////////////////////////
|
---|
| 445 | // 特殊クラス
|
---|
| 446 | /////////////////////////////
|
---|
[272] | 447 | mutable const CClass *pStringClass;
|
---|
| 448 | mutable const CClass *pObjectClass;
|
---|
| 449 | const CClass *GetStringClassPtr() const;
|
---|
| 450 | const CClass *GetObjectClassPtr() const;
|
---|
[184] | 451 | };
|
---|