source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Method.h@ 445

Last change on this file since 445 was 382, checked in by dai_9181, 17 years ago

ジェネリクスインターフェイス実装時のオーバーロード解決ロジックを改良。(型パラメータを戻り値に持つメソッドのオーバーロードをミスしてしまうバグを修正)

File size: 6.6 KB
Line 
1#pragma once
2
3using namespace std;
4
5class UserProc;
6class CClass;
7void SetError();
8
9class CMethod : public MemberPrototype
10{
11 const UserProc *pUserProc;
12
13 // XMLシリアライズ用
14private:
15 friend class boost::serialization::access;
16 template<class Archive> void serialize(Archive& ar, const unsigned int version)
17 {
18 trace_for_serialize( "serializing - CMethod" );
19
20 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( MemberPrototype );
21 ar & boost::serialization::make_nvp("pUserProc", const_cast<UserProc *&>(pUserProc));
22 }
23
24public:
25 CMethod( const UserProc *pUserProc, Prototype::Accessibility accessibility )
26 : MemberPrototype( accessibility )
27 , pUserProc( pUserProc )
28 {
29 }
30 CMethod()
31 {
32 }
33
34 const UserProc &GetUserProc() const
35 {
36 return *pUserProc;
37 }
38 void SetUserProcPtr( const UserProc *pUserProc )
39 {
40 this->pUserProc = pUserProc;
41 }
42
43 virtual bool Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier ) = 0;
44
45 virtual bool IsAbstract() const = 0;
46 virtual void SetAbstractMark( bool isAbstractMark ) = 0;
47 virtual bool IsVirtual() const = 0;
48 virtual bool IsConst() const = 0;
49 virtual bool IsDynamic() const = 0;
50 virtual bool IsStatic() const = 0;
51 virtual const CClass *GetInheritsClassPtr() const = 0;
52 virtual void SetInheritsClassPtr( const CClass *pInheritsClass ) = 0;
53 virtual bool IsNotUse() const = 0;
54 virtual void SetNotUseMark( bool isNotUse ) = 0;
55};
56
57class DynamicMethod : public CMethod
58{
59 bool isAbstract;
60 bool isVirtual;
61 bool isConst;
62 const CClass *pInheritsClass;
63
64 // 他のインターフェイスへ実装が移った場合(基底クラスメソッドのインターフェイス実装)はこのフラグをオンにする
65 bool isNotUse;
66
67 // XMLシリアライズ用
68private:
69 friend class boost::serialization::access;
70 template<class Archive> void serialize(Archive& ar, const unsigned int version)
71 {
72 trace_for_serialize( "serializing - DynamicMethod" );
73
74 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( CMethod );
75 ar & BOOST_SERIALIZATION_NVP( isAbstract );
76 ar & BOOST_SERIALIZATION_NVP( isVirtual );
77 ar & BOOST_SERIALIZATION_NVP( isConst );
78 ar & boost::serialization::make_nvp("pInheritsClass", const_cast<CClass *&>(pInheritsClass));
79 ar & BOOST_SERIALIZATION_NVP( isNotUse );
80 }
81
82public:
83 DynamicMethod( UserProc *pUserProc, Prototype::Accessibility accessibility, bool isAbstract, bool isVirtual, bool isConst, const CClass *pInheritsClass = NULL )
84 : CMethod( pUserProc, accessibility )
85 , isAbstract( isAbstract )
86 , isVirtual( isVirtual )
87 , isConst( isConst )
88 , pInheritsClass( pInheritsClass )
89 , isNotUse( false )
90 {
91 }
92 DynamicMethod( const CMethod &method )
93 : CMethod( &method.GetUserProc(), method.GetAccessibility() )
94 , isAbstract( method.IsAbstract() )
95 , isVirtual( method.IsVirtual() )
96 , isConst( method.IsConst() )
97 , pInheritsClass( method.GetInheritsClassPtr() )
98 , isNotUse( false )
99 {
100 }
101 DynamicMethod()
102 {
103 }
104
105 virtual bool Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier );
106
107 virtual bool IsAbstract() const
108 {
109 return isAbstract;
110 }
111 virtual void SetAbstractMark( bool isAbstract )
112 {
113 this->isAbstract = isAbstract;
114 }
115 virtual bool IsVirtual() const
116 {
117 return isVirtual;
118 }
119 virtual bool IsConst() const
120 {
121 return isConst;
122 }
123 virtual bool IsDynamic() const
124 {
125 return true;
126 }
127 virtual bool IsStatic() const
128 {
129 return false;
130 }
131 virtual const CClass *GetInheritsClassPtr() const
132 {
133 return pInheritsClass;
134 }
135 virtual void SetInheritsClassPtr( const CClass *pInheritsClass )
136 {
137 this->pInheritsClass = pInheritsClass;
138 }
139 virtual bool IsNotUse() const
140 {
141 return isNotUse;
142 }
143 virtual void SetNotUseMark( bool isNotUse )
144 {
145 this->isNotUse = isNotUse;
146 }
147};
148BOOST_CLASS_EXPORT( DynamicMethod );
149class StaticMethod : public CMethod
150{
151 // XMLシリアライズ用
152private:
153 friend class boost::serialization::access;
154 template<class Archive> void serialize(Archive& ar, const unsigned int version)
155 {
156 trace_for_serialize( "serializing - StaticMethod" );
157
158 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( CMethod );
159 }
160
161public:
162
163 // コンストラクタ
164 StaticMethod( UserProc *pUserProc, Prototype::Accessibility accessibility )
165 : CMethod( pUserProc, accessibility )
166 {
167 }
168
169 // コピーコンストラクタ
170 StaticMethod( const StaticMethod &staticMethod );
171
172 // デストラクタ
173 StaticMethod()
174 {
175 }
176
177 virtual bool Override( const UserProc *pUserProc, Prototype::Accessibility accessibility, bool isOverrideModifier ){SetError();return false;}
178
179 virtual bool IsAbstract() const{SetError();return false;}
180 virtual void SetAbstractMark( bool isAbstract ){SetError();}
181 virtual bool IsVirtual() const{
182 return false;
183 }
184 virtual bool IsConst() const{SetError();return false;}
185 virtual bool IsDynamic() const
186 {
187 return false;
188 }
189 virtual bool IsStatic() const
190 {
191 return true;
192 }
193 virtual const CClass *GetInheritsClassPtr() const{SetError();return NULL;}
194 virtual void SetInheritsClassPtr( const CClass *pInheritsClass ){SetError();}
195 virtual bool IsNotUse() const
196 {
197 return false;
198 }
199 virtual void SetNotUseMark( bool isNotUse )
200 {
201 SetError();
202 }
203};
204BOOST_CLASS_EXPORT( StaticMethod );
205
206class Methods : public vector<CMethod *>
207{
208 // XMLシリアライズ用
209private:
210 friend class boost::serialization::access;
211 template<class Archive> void serialize(Archive& ar, const unsigned int version)
212 {
213 trace_for_serialize( "serializing - Methods" );
214
215 ar & boost::serialization::make_nvp("vector_CMethod", boost::serialization::base_object<vector<CMethod *>>(*this));
216 }
217
218public:
219 // コンストラクタ
220 Methods();
221
222 // コピーコンストラクタ
223 Methods( const Methods &methods );
224
225 // デストラクタ
226 ~Methods();
227
228 //メンバ、メソッドの追加
229 void Add( UserProc *pUserProc, Prototype::Accessibility accessibility, bool isConst, bool isAbstract, bool isVirtual );
230 void AddStatic(UserProc *pUserProc,Prototype::Accessibility accessibility);
231
232 /*!
233 @brief オーバーライドのための検索
234 @param actualTypeParametersForThisMethods thisオブジェクトで保有するメソッド群を対象とした実型パラメータ
235 pUserProc 照らし合わせる関数
236 */
237 CMethod *FindForOverride( const Types &actualTypeParametersForThisMethods, const UserProc *pUserProc );
238
239 const CMethod *GetMethodPtr( const UserProc *pUserProc ) const;
240 bool IsExist( const char *name ) const;
241 virtual void Enum( const char *methodName, vector<const UserProc *> &subs ) const;
242 virtual void Enum( BYTE idOperatorCalc, vector<const UserProc *> &subs ) const;
243
244 // 仮想メソッドの個数を取得
245 int GetVtblNum() const;
246
247 // vtblを生成
248 void GenerateVTablePart( long &vtableDataTableOffset ) const;
249};
Note: See TracBrowser for help on using the repository browser.