source: dev/trunk/abdev/BasicCompiler_Common/include/Procedure.h @ 351

Last change on this file since 351 was 351, checked in by dai_9181, 16 years ago

インターフェイスメソッドはオーバーライド対象外とした

File size: 12.3 KB
Line 
1#pragma once
2
3#include <Hashmap.h>
4#include <option.h>
5#include <Program.h>
6#include <Class.h>
7#include <Method.h>
8#include <Procedure.h>
9#include <Parameter.h>
10#include <Variable.h>
11#include <CodeGenerator.h>
12#include <Source.h>
13
14class CClass;
15class CMethod;
16
17class Procedure : public Symbol
18{
19public:
20    // 種類
21    enum Kind{
22        Sub,
23        Function,
24    };
25
26private:
27    Kind kind;
28
29    bool isCdecl;
30    mutable bool isUsing;
31
32protected:
33
34    // パラメータ
35    Parameters params;
36
37    // 戻り値の型
38    Type returnType;
39
40    // ソースコードの位置
41    int codePos;
42
43    // XMLシリアライズ用
44private:
45    friend class boost::serialization::access;
46    template<class Archive> void serialize(Archive& ar, const unsigned int version)
47    {
48        trace_for_serialize( "serializing - Procedure" );
49
50        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Symbol );
51        ar & BOOST_SERIALIZATION_NVP( kind );
52        ar & BOOST_SERIALIZATION_NVP( isCdecl );
53        ar & BOOST_SERIALIZATION_NVP( isUsing );
54        ar & BOOST_SERIALIZATION_NVP( params );
55        ar & BOOST_SERIALIZATION_NVP( returnType );
56        ar & BOOST_SERIALIZATION_NVP( codePos );
57    }
58
59public:
60    Procedure( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl )
61        : Symbol( namespaceScopes, name )
62        , kind( kind )
63        , isCdecl( isCdecl )
64        , isUsing( false )
65        , codePos( -1 )
66    {
67    }
68    Procedure()
69    {
70    }
71    ~Procedure(){
72        BOOST_FOREACH( Parameter *pParam, params ){
73            delete pParam;
74        }
75    }
76
77    bool IsSub() const
78    {
79        return ( kind == Sub );
80    }
81    bool IsFunction() const
82    {
83        return ( kind == Function );
84    }
85
86    bool IsCdecl() const
87    {
88        return isCdecl;
89    }
90    void Using() const
91    {
92        isUsing = true;
93    }
94    bool IsUsing() const
95    {
96        return isUsing;
97    }
98
99    int GetCodePos() const
100    {
101        return codePos;
102    }
103
104    const Parameters &Params() const
105    {
106        return params;
107    }
108    const Type &ReturnType() const
109    {
110        return returnType;
111    }
112};
113
114class UserProc : public Procedure, public Jenga::Common::ObjectInHashmap<UserProc>
115{
116public:
117    string _paramStr;
118
119private:
120    NamespaceScopesCollection importedNamespaces;
121
122    // 親クラスと対応するメソッド
123    const CClass *pParentClass;
124    CMethod *pMethod;
125
126    bool isMacro;
127
128    // パラメータの追加情報
129    int secondParmNum;
130    Parameters realParams;
131    int realSecondParmNum;
132
133    // 各種フラグ
134    bool isExport;
135    mutable bool isSystem;
136    mutable bool isAutoGeneration;
137    mutable bool isCompiled;
138
139    mutable DWORD beginOpAddress;
140    mutable DWORD endOpAddress;
141
142    // ローカル変数
143    mutable Variables localVars;
144
145    // 識別ID
146    int id;
147
148    // ネイティブコード
149    NativeCode nativeCode;
150
151    // XMLシリアライズ用
152private:
153    friend class boost::serialization::access;
154    template<class Archive> void serialize(Archive& ar, const unsigned int version)
155    {
156        trace_for_serialize( "serializing - UserProc" );
157
158        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
159        ar & BOOST_SERIALIZATION_NVP( _paramStr );
160        ar & BOOST_SERIALIZATION_NVP( importedNamespaces );
161        ar & boost::serialization::make_nvp("pParentClass", const_cast<CClass *&>(pParentClass) );
162        ar & BOOST_SERIALIZATION_NVP( pMethod );
163        ar & BOOST_SERIALIZATION_NVP( isMacro );
164        ar & BOOST_SERIALIZATION_NVP( secondParmNum );
165        ar & BOOST_SERIALIZATION_NVP( realParams );
166        ar & BOOST_SERIALIZATION_NVP( realSecondParmNum );
167        ar & BOOST_SERIALIZATION_NVP( isExport );
168        ar & BOOST_SERIALIZATION_NVP( isSystem );
169        ar & BOOST_SERIALIZATION_NVP( isAutoGeneration );
170        ar & BOOST_SERIALIZATION_NVP( isCompiled );
171        ar & BOOST_SERIALIZATION_NVP( beginOpAddress );
172        ar & BOOST_SERIALIZATION_NVP( endOpAddress );
173        ar & BOOST_SERIALIZATION_NVP( localVars );
174        ar & BOOST_SERIALIZATION_NVP( id );
175        ar & BOOST_SERIALIZATION_NVP( nativeCode );
176    }
177
178public:
179
180    UserProc( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, const string &name, Kind kind, bool isMacro, bool isCdecl, bool isExport, int id )
181        : Procedure( namespaceScopes, name, kind, isCdecl )
182        , importedNamespaces( importedNamespaces )
183        , pParentClass( NULL )
184        , pMethod( NULL )
185        , isMacro( isMacro )
186        , isExport( isExport )
187        , isSystem( false )
188        , isAutoGeneration( false )
189        , isCompiled( false )
190        , beginOpAddress( 0 )
191        , endOpAddress( 0 )
192        , id( id )
193    {
194    }
195    UserProc()
196    {
197    }
198    ~UserProc()
199    {
200        BOOST_FOREACH( Parameter *pParam, realParams ){
201            delete pParam;
202        }
203    }
204
205    virtual const std::string &GetKeyName() const
206    {
207        return GetName();
208    }
209
210    virtual bool IsDuplication( const UserProc *pUserProc ) const
211    {
212        if( this->GetParentClassPtr() == pUserProc->GetParentClassPtr() // 親クラスが等しい
213            && pUserProc->IsEqualSymbol( *this )                        // 名前空間及び名前が等しい
214            && this->Params().Equals( pUserProc->Params() )             // パラメータが等しい
215            && this->returnType.Equals( pUserProc->returnType ) )       // 戻り値が等しい
216        {
217            return true;
218        }
219        return false;
220    }
221
222    // オーバーライド用に関数同士が等しいかどうかをチェックする
223    bool IsEqualForOverride( const UserProc *pUserProc ) const
224    {
225        if( this->GetName() == pUserProc->GetName()                     // 名前空間及び名前が等しい
226            && this->Params().Equals( pUserProc->Params() )             // パラメータが等しい
227            && this->returnType.Equals( pUserProc->returnType ) )       // 戻り値が等しい
228        {
229            return true;
230        }
231        return false;
232    }
233
234    bool IsMacro() const
235    {
236        return isMacro;
237    }
238
239    int GetSecondParmNum() const
240    {
241        return secondParmNum;
242    }
243    const Parameters &RealParams() const
244    {
245        return realParams;
246    }
247    int GetRealSecondParmNum() const
248    {
249        return realSecondParmNum;
250    }
251
252    void ExportOff(){
253        isExport = false;
254    }
255    bool IsExport() const
256    {
257        return isExport;
258    }
259    void ThisIsSystemProc() const
260    {
261        isSystem = true;
262    }
263    bool IsSystem() const
264    {
265        return isSystem;
266    }
267    void ThisIsAutoGenerationProc() const
268    {
269        isAutoGeneration = true;
270    }
271    bool IsAutoGeneration() const
272    {
273        return isAutoGeneration;
274    }
275    void CompleteCompile() const
276    {
277        isCompiled = true;
278    }
279    void KillCompileStatus() const
280    {
281        isCompiled = false;
282    }
283    bool IsCompiled() const
284    {
285        return isCompiled;
286    }
287    bool IsDestructor() const
288    {
289        return ( GetName()[0] == '~' );
290    }
291
292    // バイナリコード位置とサイズ
293    DWORD GetBeginOpAddress() const
294    {
295        return beginOpAddress;
296    }
297    void SetBeginOpAddress( DWORD beginOpAddress ) const
298    {
299        this->beginOpAddress = beginOpAddress;
300    }
301    DWORD GetEndOpAddress() const
302    {
303        return endOpAddress;
304    }
305    void SetEndOpAddress( DWORD endOpAddress ) const
306    {
307        this->endOpAddress = endOpAddress;
308    }
309    int GetCodeSize() const
310    {
311        return endOpAddress - beginOpAddress;
312    }
313
314    virtual const NamespaceScopes &GetNamespaceScopes() const;
315    const NamespaceScopesCollection &GetImportedNamespaces() const;
316
317    Variables &GetLocalVars() const
318    {
319        return localVars;
320    }
321
322    int GetId() const
323    {
324        return id;
325    }
326
327    const NativeCode &GetNativeCode() const
328    {
329        return nativeCode;
330    }
331    NativeCode &GetNativeCode()
332    {
333        return nativeCode;
334    }
335
336    std::string GetFullName() const;
337    bool IsCastOperator() const;
338
339    bool IsVirtual() const;
340
341    void SetParentClass( const CClass *pParentClass ){
342        this->pParentClass = pParentClass;
343    }
344    const CClass *GetParentClassPtr() const
345    {
346        return pParentClass;
347    }
348    const CClass &GetParentClass() const
349    {
350        return *pParentClass;
351    }
352    bool HasParentClass() const
353    {
354        return ( pParentClass != NULL );
355    }
356    bool IsGlobalProcedure() const
357    {
358        return ( pParentClass == NULL );
359    }
360    void SetMethod( CMethod *pMethod ){
361        this->pMethod = pMethod;
362    }
363    const CMethod &GetMethod() const;
364
365    bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic );
366
367
368
369    /////////////////////////////////////////////////////////////////
370    // コンパイル中の関数を管理
371    /////////////////////////////////////////////////////////////////
372private:
373    static const UserProc *pCompilingUserProc;
374public:
375    static void CompileStartForGlobalArea(){
376        pCompilingUserProc = NULL;
377    }
378    static void CompileStartForUserProc( const UserProc *pUserProc ){
379        pCompilingUserProc = pUserProc;
380    }
381    static bool IsGlobalAreaCompiling(){
382        return ( pCompilingUserProc == NULL );
383    }
384    static bool IsLocalAreaCompiling(){
385        return ( pCompilingUserProc != NULL );
386    }
387    static const UserProc &CompilingUserProc(){
388        return *pCompilingUserProc;
389    }
390};
391
392class UserProcs : public Jenga::Common::Hashmap<UserProc>
393{
394    std::vector<std::string> macroNames;
395
396    // XMLシリアライズ用
397private:
398    friend class boost::serialization::access;
399    template<class Archive> void serialize(Archive& ar, const unsigned int version)
400    {
401        trace_for_serialize( "serializing - UserProcs" );
402
403        ar & boost::serialization::make_nvp("Hashmap_UserProcImpl",
404            boost::serialization::base_object<Jenga::Common::Hashmap<UserProc>>(*this));
405        ar & BOOST_SERIALIZATION_NVP( macroNames );
406    }
407
408
409public:
410    UserProcs()
411    {
412    }
413    ~UserProcs()
414    {
415    }
416
417    bool Insert( UserProc *pUserProc, int nowLine );
418
419    UserProc *Add( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic);
420
421    void EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs );
422};
423
424class DllProc : public Procedure, public Jenga::Common::ObjectInHashmap<DllProc>
425{
426    string dllFileName;
427    string alias;
428    int lookupAddress;
429
430    // XMLシリアライズ用
431private:
432    friend class boost::serialization::access;
433    template<class Archive> void serialize(Archive& ar, const unsigned int version)
434    {
435        trace_for_serialize( "serializing - DllProc" );
436
437        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
438        ar & BOOST_SERIALIZATION_NVP( dllFileName );
439        ar & BOOST_SERIALIZATION_NVP( alias );
440        ar & BOOST_SERIALIZATION_NVP( lookupAddress );
441    }
442
443public:
444    DllProc( const NamespaceScopes &namespaceScopes, const string &name, Kind kind, bool isCdecl, const string &dllFileName, const string &alias )
445        : Procedure( namespaceScopes, name, kind, isCdecl )
446        , dllFileName( dllFileName )
447        , alias( alias )
448        , lookupAddress( 0 )
449    {
450    }
451    DllProc()
452    {
453    }
454    ~DllProc()
455    {
456    }
457
458    virtual const std::string &GetKeyName() const
459    {
460        return GetName();
461    }
462
463    virtual bool IsDuplication( const DllProc *pDllProc ) const
464    {
465        if( pDllProc->IsEqualSymbol( *this )
466            && this->Params().Equals( pDllProc->Params() ) )
467        {
468            return true;
469        }
470        return false;
471    }
472
473    const string &GetDllFileName() const
474    {
475        return dllFileName;
476    }
477    const string &GetAlias() const
478    {
479        return alias;
480    }
481
482    void SetLookupAddress( int lookupAddress ){
483        this->lookupAddress = lookupAddress;
484    }
485    int GetLookupAddress() const
486    {
487        return lookupAddress;
488    }
489
490    bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
491};
492class DllProcs : public Jenga::Common::Hashmap<DllProc>
493{
494    // XMLシリアライズ用
495private:
496    friend class boost::serialization::access;
497    template<class Archive> void serialize(Archive& ar, const unsigned int version)
498    {
499        trace_for_serialize( "serializing - DllProcs" );
500
501        ar & boost::serialization::make_nvp("Hashmap_DllProc",
502            boost::serialization::base_object<Jenga::Common::Hashmap<DllProc>>(*this));
503    }
504
505public:
506    void Add(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine);
507};
508
509void CollectProcedures( const BasicSource &source, UserProcs &userProcs, DllProcs &dllProcs );
510
511class ProcPointer : public Procedure
512{
513    // XMLシリアライズ用
514private:
515    friend class boost::serialization::access;
516    template<class Archive> void serialize(Archive& ar, const unsigned int version)
517    {
518        trace_for_serialize( "serializing - ProcPointer" );
519
520        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Procedure );
521    }
522
523public:
524    ProcPointer( Kind kind )
525        : Procedure( NamespaceScopes(), std::string(), kind, false )
526    {
527    }
528    ProcPointer()
529    {
530    }
531    ~ProcPointer(){}
532
533    virtual bool SetParamsAndReturnType( const char *sourceOfParams, int nowLine );
534};
535
536class ProcPointers : public vector<ProcPointer *>
537{
538    // XMLシリアライズ用
539private:
540    friend class boost::serialization::access;
541    template<class Archive> void serialize(Archive& ar, const unsigned int version)
542    {
543        trace_for_serialize( "serializing - ProcPointers" );
544
545        ar & boost::serialization::make_nvp("vector_ProcPointer",
546            boost::serialization::base_object<vector<ProcPointer *>>(*this));
547    }
548
549public:
550    ProcPointers()
551    {
552    }
553    ~ProcPointers()
554    {
555        Clear();
556    }
557
558    int Add( const string &typeExpression );
559    void Clear();
560    void PullOutAll()
561    {
562        clear();
563    }
564};
Note: See TracBrowser for help on using the repository browser.