source: dev/BasicCompiler_Common/Procedure.h@ 76

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

TYPEINFO→Typeへのリファクタリングを実施。32bitが未完成。

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