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