source: dev/BasicCompiler_Common/Procedure.h@ 89

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

実行時型情報の生成に対応。
関数の戻り値の型に抽象クラスを指定できるようにした。

File size: 4.9 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 isCompiled;
104
105public:
106 // ハッシュリスト用
107 UserProc *pNextData;
108
109 UserProc( const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport ):
110 Procedure( name, kind, isCdecl ),
111 isMacro( isMacro ),
112 pParentClass( NULL ),
113 pMethod( NULL ),
114 isExport( isExport ),
115 isSystem( false ),
116 isCompiled( false ),
117 pNextData( NULL )
118 {
119 }
120 ~UserProc(){
121 foreach( Parameter *pParam, realParams ){
122 delete pParam;
123 }
124 }
125
126 bool IsMacro() const
127 {
128 return isMacro;
129 }
130
131 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
132
133 int GetSecondParmNum() const
134 {
135 return secondParmNum;
136 }
137 const Parameters &RealParams() const
138 {
139 return realParams;
140 }
141 int GetRealSecondParmNum() const
142 {
143 return realSecondParmNum;
144 }
145
146 void SetParentClass( CClass *pParentClass ){
147 this->pParentClass = pParentClass;
148 }
149 CClass *GetParentClassPtr()
150 {
151 return pParentClass;
152 }
153 const CClass &GetParentClass() const
154 {
155 return *pParentClass;
156 }
157 bool HasParentClass() const
158 {
159 return ( pParentClass != NULL );
160 }
161 void SetMethod( CMethod *pMethod ){
162 this->pMethod = pMethod;
163 }
164
165 void ExportOff(){
166 isExport = false;
167 }
168 bool IsExport() const
169 {
170 return isExport;
171 }
172 void ThisIsSystemProc(){
173 isSystem = true;
174 }
175 bool IsSystem() const
176 {
177 return isSystem;
178 }
179 void CompleteCompile(){
180 isCompiled = true;
181 }
182 void KillCompileStatus(){
183 isCompiled = false;
184 }
185 bool IsCompiled() const
186 {
187 return isCompiled;
188 }
189 bool IsDestructor() const
190 {
191 return ( GetName()[0] == '~' );
192 }
193 bool IsVirtual() const
194 {
195 if( pMethod == NULL ){
196 return false;
197 }
198 return ( pMethod->bVirtual != 0 );
199 }
200
201
202 // バイナリコードの位置
203 DWORD beginOpAddress;
204 DWORD endOpAddress;
205
206 // ローカル変数
207 Variables localVars;
208
209 // TODO: 適切なコードへ直す
210 long id;
211
212
213 /////////////////////////////////////////////////////////////////
214 // コンパイル中の関数を管理
215 /////////////////////////////////////////////////////////////////
216private:
217 static UserProc *pCompilingUserProc;
218public:
219 static void CompileStartForGlobalArea(){
220 pCompilingUserProc = NULL;
221 }
222 static void CompileStartForUserProc( UserProc *pUserProc ){
223 pCompilingUserProc = pUserProc;
224 }
225 static bool IsGlobalAreaCompiling(){
226 return ( pCompilingUserProc == NULL );
227 }
228 static bool IsLocalAreaCompiling(){
229 return ( pCompilingUserProc != NULL );
230 }
231 static UserProc &CompilingUserProc(){
232 return *pCompilingUserProc;
233 }
234};
235
236class DllProc : public Procedure
237{
238 const string dllFileName;
239 const string alias;
240 int lookupAddress;
241
242public:
243 // ハッシュリスト用
244 DllProc *pNextData;
245
246 DllProc( const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias ):
247 Procedure( name, kind, isCdecl ),
248 dllFileName( dllFileName ),
249 alias( alias ),
250 lookupAddress( 0 ),
251 pNextData( NULL )
252 {
253 }
254 ~DllProc(){}
255
256 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
257
258 const string &GetDllFileName() const
259 {
260 return dllFileName;
261 }
262 const string &GetAlias() const
263 {
264 return alias;
265 }
266
267 void SetLookupAddress( int lookupAddress ){
268 this->lookupAddress = lookupAddress;
269 }
270 int GetLookupAddress() const
271 {
272 return lookupAddress;
273 }
274
275};
276
277class ProcPointer : public Procedure
278{
279public:
280 ProcPointer( Kind kind ):
281 Procedure( "", kind, false )
282 {
283 }
284 ~ProcPointer(){}
285
286 virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
287};
Note: See TracBrowser for help on using the repository browser.