source: dev/BasicCompiler_Common/Procedure.h@ 91

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

ログ機構(Smoothie::Logger)を導入。
動的型情報生成において、未使用クラスの登録は行わないようにした。

File size: 5.3 KB
Line 
1#pragma once
2
3class Procedure{
4public:
5 // 種類
6 enum Kind{
7 Sub,
8 Function,
9 };
10
11private:
12 const string name;
13
14 Kind kind;
15
16 bool isCdecl;
17 bool isUsing;
18
19protected:
20
21 // パラメータ
22 Parameters params;
23
24 // 戻り値の型
25 Type returnType;
26
27 // ソースコードの位置
28 int codePos;
29
30public:
31 Procedure( const string &name, Kind kind, bool isCdecl ):
32 name( name ),
33 kind( kind ),
34 isCdecl( isCdecl ),
35 isUsing( false ),
36 codePos( -1 )
37 {}
38 ~Procedure(){
39 foreach( Parameter *pParam, params ){
40 delete pParam;
41 }
42 }
43
44 const string &GetName() const
45 {
46 return name;
47 }
48
49 bool IsSub() const
50 {
51 return ( kind == Sub );
52 }
53 bool IsFunction() const
54 {
55 return ( kind == Function );
56 }
57
58 bool IsCdecl() const
59 {
60 return isCdecl;
61 }
62 void Using(){
63 isUsing = true;
64 }
65 bool IsUsing() const
66 {
67 return isUsing;
68 }
69
70 int GetCodePos() const
71 {
72 return codePos;
73 }
74
75 const Parameters &Params() const
76 {
77 return params;
78 }
79 const Type &ReturnType() const
80 {
81 return returnType;
82 }
83};
84
85class UserProc : public Procedure
86{
87
88private:
89 bool isMacro;
90
91 // パラメータの追加情報
92 int secondParmNum;
93 Parameters realParams;
94 int realSecondParmNum;
95
96 // 親クラスと対応するメソッド
97 CClass *pParentClass;
98 CMethod *pMethod;
99
100 // 各種フラグ
101 bool isExport;
102 bool isSystem;
103 bool isAutoGeneration;
104 bool isCompiled;
105
106public:
107 // ハッシュリスト用
108 UserProc *pNextData;
109
110 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
111 Procedure( name, kind, isCdecl ),
112 isMacro( isMacro ),
113 pParentClass( NULL ),
114 pMethod( NULL ),
115 isExport( isExport ),
116 isSystem( false ),
117 isAutoGeneration( false ),
118 isCompiled( false ),
119 pNextData( NULL )
120 {
121 }
122 ~UserProc(){
123 foreach( Parameter *pParam, realParams ){
124 delete pParam;
125 }
126 }
127
128 string GetFullName() const
129 {
130 if( HasParentClass() ){
131 return (string)GetParentClass().name + "." + GetName();
132 }
133
134 return GetName();
135 }
136
137 bool IsMacro() const
138 {
139 return isMacro;
140 }
141
142 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
143
144 int GetSecondParmNum() const
145 {
146 return secondParmNum;
147 }
148 const Parameters &RealParams() const
149 {
150 return realParams;
151 }
152 int GetRealSecondParmNum() const
153 {
154 return realSecondParmNum;
155 }
156
157 void SetParentClass( CClass *pParentClass ){
158 this->pParentClass = pParentClass;
159 }
160 CClass *GetParentClassPtr()
161 {
162 return pParentClass;
163 }
164 const CClass &GetParentClass() const
165 {
166 return *pParentClass;
167 }
168 bool HasParentClass() const
169 {
170 return ( pParentClass != NULL );
171 }
172 void SetMethod( CMethod *pMethod ){
173 this->pMethod = pMethod;
174 }
175
176 void ExportOff(){
177 isExport = false;
178 }
179 bool IsExport() const
180 {
181 return isExport;
182 }
183 void ThisIsSystemProc(){
184 isSystem = true;
185 }
186 bool IsSystem() const
187 {
188 return isSystem;
189 }
190 void ThisIsAutoGenerationProc(){
191 isAutoGeneration = true;
192 }
193 bool IsAutoGeneration(){
194 return isAutoGeneration;
195 }
196 void CompleteCompile(){
197 isCompiled = true;
198 }
199 void KillCompileStatus(){
200 isCompiled = false;
201 }
202 bool IsCompiled() const
203 {
204 return isCompiled;
205 }
206 bool IsDestructor() const
207 {
208 return ( GetName()[0] == '~' );
209 }
210 bool IsVirtual() const
211 {
212 if( pMethod == NULL ){
213 return false;
214 }
215 return ( pMethod->bVirtual != 0 );
216 }
217
218
219 // バイナリコードの位置
220 DWORD beginOpAddress;
221 DWORD endOpAddress;
222 int GetCodeSize() const
223 {
224 return endOpAddress - beginOpAddress;
225 }
226
227 // ローカル変数
228 Variables localVars;
229
230 // TODO: 適切なコードへ直す
231 long id;
232
233
234 /////////////////////////////////////////////////////////////////
235 // コンパイル中の関数を管理
236 /////////////////////////////////////////////////////////////////
237private:
238 static UserProc *pCompilingUserProc;
239public:
240 static void CompileStartForGlobalArea(){
241 pCompilingUserProc = NULL;
242 }
243 static void CompileStartForUserProc( UserProc *pUserProc ){
244 pCompilingUserProc = pUserProc;
245 }
246 static bool IsGlobalAreaCompiling(){
247 return ( pCompilingUserProc == NULL );
248 }
249 static bool IsLocalAreaCompiling(){
250 return ( pCompilingUserProc != NULL );
251 }
252 static UserProc &CompilingUserProc(){
253 return *pCompilingUserProc;
254 }
255};
256
257class DllProc : public Procedure
258{
259 const string dllFileName;
260 const string alias;
261 int lookupAddress;
262
263public:
264 // ハッシュリスト用
265 DllProc *pNextData;
266
267 DllProc( const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
268 Procedure( name, kind, isCdecl ),
269 dllFileName( dllFileName ),
270 alias( alias ),
271 lookupAddress( 0 ),
272 pNextData( NULL )
273 {
274 }
275 ~DllProc(){}
276
277 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
278
279 const string &GetDllFileName() const
280 {
281 return dllFileName;
282 }
283 const string &GetAlias() const
284 {
285 return alias;
286 }
287
288 void SetLookupAddress( int lookupAddress ){
289 this->lookupAddress = lookupAddress;
290 }
291 int GetLookupAddress() const
292 {
293 return lookupAddress;
294 }
295
296};
297
298class ProcPointer : public Procedure
299{
300public:
301 ProcPointer( Kind kind ):
302 Procedure( "", kind, false )
303 {
304 }
305 ~ProcPointer(){}
306
307 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
308};
Note: See TracBrowser for help on using the repository browser.