source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/Procedure.h @ 537

Last change on this file since 537 was 537, checked in by dai_9181, 15 years ago

UserProcクラスによるコンパイル中関数管理用メソッドを除去(すべてCompilerクラス内で処理するようにした)。

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