source: dev/BasicCompiler_Common/Procedure.h@ 90

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

実行時型情報の生成にほぼ対応した。

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