source: dev/BasicCompiler_Common/Procedure.h@ 75

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

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

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