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

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

jengaプロジェクトにプリコンパイル済みヘッダを適用した。

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